1
/* liblouis Braille Translation and Back-Translation Library
3
Based on BRLTTY, copyright (C) 1999-2006 by
6
Copyright (C) 2004, 2005, 2006, 2009
7
ViewPlus Technologies, Inc. www.viewplus.com and
8
JJB Software, Inc. www.jjb-software.com
10
This program is free software: you can redistribute it and/or modify
11
it under the terms of the GNU General Public License as published by
12
the Free Software Foundation, either version 3 of the License, or
13
(at your option) any later version.
15
This program is distributed in the hope that it will be useful,
16
but WITHOUT ANY WARRANTY; without even the implied warranty of
17
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
GNU General Public License for more details.
20
You should have received a copy of the GNU General Public License
21
along with this program. If not, see <http://www.gnu.org/licenses/>.
23
Maintained by John J. Boyer john.boyer@jjb-software.com
36
#include "version-etc.h"
38
static const struct option longopts[] =
40
{ "help", no_argument, NULL, 'h' },
41
{ "version", no_argument, NULL, 'v' },
45
const char version_etc_copyright[] =
46
"Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc.";
48
#define AUTHORS "John J. Boyer"
54
Usage: %s [OPTION] TABLE\n", program_name);
57
Examine and debug Braille translation tables. This program allows you\n\
58
to inspect liblouis translation tables and gather information about\n\
59
them, such as forward and backward rules, characters and dot patterns,\n\
60
specific opcodes, the size of a table, whether a hyphenation\n\
61
table is used, how many passes the translation takes and much\n\
65
-h, --help display this help and exit\n\
66
-v, --version display version information and exit\n", stdout);
70
Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
75
static const TranslationTableHeader *table;
76
static char inputBuffer[BUFSIZE];
83
fgets (inputBuffer, sizeof (inputBuffer), stdin);
84
inputLength = strlen (inputBuffer) - 1;
85
if (inputLength < 0) /*EOF on script */
87
inputBuffer[inputLength] = 0;
92
printRule (TranslationTableRule * thisRule, int mode)
95
printf ("opcode=%s, ", findOpcodeName (thisRule->opcode));
97
printf ("before=%x, ", thisRule->before);
99
printf ("after=%x, ", thisRule->after);
100
switch (thisRule->opcode)
109
printf ("code=%s ", showString (thisRule->charsdots, thisRule->charslen
110
+ thisRule->dotslen));
115
printf ("chars=%s, ", showString (thisRule->charsdots,
116
thisRule->charslen));
118
showDots (&thisRule->charsdots[thisRule->charslen],
124
showDots (&thisRule->charsdots[thisRule->charslen],
126
printf ("chars=%s, ", showString (thisRule->charsdots,
127
thisRule->charslen));
135
printCharacter (TranslationTableCharacter * thisChar, int mode)
137
TranslationTableRule *thisRule;
138
TranslationTableOffset nextRule;
142
printf ("real=%s, ", showString (&thisChar->realchar, 1));
143
printf ("upper=%s, ", showString (&thisChar->uppercase, 1));
144
printf ("lower=%s, ", showString (&thisChar->lowercase, 1));
147
printf ("Dots: real=%s, ", showDots (&thisChar->realchar, 1));
148
printf ("attr=%s, ", showAttributes (thisChar->attributes));
149
nextRule = thisChar->otherRules;
152
thisRule = (TranslationTableRule *) & table->ruleArea[nextRule];
153
if (nextRule == thisChar->definitionRule)
154
printf ("definition ");
155
printRule (thisRule, mode);
158
nextRule = thisRule->charsnext;
160
nextRule = thisRule->dotsnext;
166
show_characters (int startHash)
169
TranslationTableCharacter *thisChar;
170
TranslationTableOffset nextChar;
171
printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
176
for (; k < HASHNUM; k++)
177
if (table->characters[k])
179
printf ("Hash=%d\n", k);
180
nextChar = table->characters[k];
184
(TranslationTableCharacter *) & table->ruleArea[nextChar];
185
printCharacter (thisChar, 0);
188
if (*inputBuffer == 'h')
190
if (*inputBuffer == 'e')
192
nextChar = thisChar->next;
199
show_dots (int startHash)
202
TranslationTableCharacter *thisDots;
203
TranslationTableOffset nextDots;
204
printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
209
for (; k < HASHNUM; k++)
212
printf ("Hash=%d\n", k);
213
nextDots = table->dots[k];
217
(TranslationTableCharacter *) & table->ruleArea[nextDots];
218
printCharacter (thisDots, 1);
221
if (*inputBuffer == 'h')
223
if (*inputBuffer == 'e')
225
nextDots = thisDots->next;
232
show_forRules (int startHash)
235
TranslationTableRule *thisRule;
236
TranslationTableOffset nextRule;
237
printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
242
for (; k < HASHNUM; k++)
243
if (table->forRules[k])
245
printf ("Hash=%d\n", k);
246
nextRule = table->forRules[k];
249
thisRule = (TranslationTableRule *) & table->ruleArea[nextRule];
250
printRule (thisRule, 0);
253
if (*inputBuffer == 'h')
255
if (*inputBuffer == 'e')
257
nextRule = thisRule->charsnext;
264
show_backRules (int startHash)
267
TranslationTableRule *thisRule;
268
TranslationTableOffset nextRule;
269
printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
274
for (; k < HASHNUM; k++)
275
if (table->backRules[k])
277
printf ("Hash=%d\n", k);
278
nextRule = table->backRules[k];
281
thisRule = (TranslationTableRule *) & table->ruleArea[nextRule];
282
printRule (thisRule, 1);
285
if (*inputBuffer == 'h')
287
if (*inputBuffer == 'e')
289
nextRule = thisRule->dotsnext;
296
print_brailleIndicator (TranslationTableOffset offset, char *opcode)
298
TranslationTableRule *thisRule;
301
thisRule = (TranslationTableRule *) & table->ruleArea[offset];
302
printf ("%s %s\n", opcode,
303
showDots (&thisRule->charsdots[0], thisRule->dotslen));
308
print_phraseLength (TranslationTableOffset offset, char *opcode)
312
printf ("%s %d\n", opcode, offset);
317
show_brailleIndicators (void)
319
print_brailleIndicator (table->capitalSign, "capsign");
320
print_brailleIndicator (table->beginCapitalSign, "begcaps");
321
print_phraseLength (table->lenBeginCaps, "lenbegcaps");
322
print_brailleIndicator (table->endCapitalSign, "endcaps");
323
print_brailleIndicator (table->firstWordCaps, "firstwordcaps");
324
print_brailleIndicator (table->lastWordCapsAfter, "lastwordaftercaps");
325
print_phraseLength (table->lenCapsPhrase, "lencapsphrase");
326
print_brailleIndicator (table->letterSign, "letsign");
327
print_brailleIndicator (table->numberSign, "numsign");
328
print_brailleIndicator (table->firstWordItal, "firstwordital");
329
print_brailleIndicator (table->lastWordItalBefore, "lastworditalbefore");
330
print_brailleIndicator (table->lastWordItalAfter, "lastworditalafter");
331
print_brailleIndicator (table->firstLetterItal, "firstletterital");
332
print_brailleIndicator (table->lastLetterItal, "lastletterital");
333
print_brailleIndicator (table->singleLetterItal, "singleletterital");
334
print_brailleIndicator (table->italWord, "italword");
335
print_phraseLength (table->lenItalPhrase, "lenitalphrase");
336
print_brailleIndicator (table->firstWordBold, "firstwordbold");
337
print_brailleIndicator (table->lastWordBoldBefore, "lastwordboldbefore");
338
print_brailleIndicator (table->lastWordBoldAfter, "lastwordboldafter");
339
print_brailleIndicator (table->firstLetterBold, "firstletterbold");
340
print_brailleIndicator (table->lastLetterBold, "lastletterbold");
341
print_brailleIndicator (table->singleLetterBold, "singleletterbold");
342
print_brailleIndicator (table->boldWord, "boldword");
343
print_phraseLength (table->lenBoldPhrase, "lenboldphrase");
344
print_brailleIndicator (table->firstWordUnder, "firstwordunder");
345
print_brailleIndicator (table->lastWordUnderBefore, "lastwordunderbefore");
346
print_brailleIndicator (table->lastWordUnderAfter, "lastwordunderafter");
347
print_brailleIndicator (table->firstLetterUnder, "firstletterunder");
348
print_brailleIndicator (table->lastLetterUnder, "lastletterunder");
349
print_brailleIndicator (table->singleLetterUnder, "singleletterunder");
350
print_brailleIndicator (table->underWord, "underword");
351
print_phraseLength (table->lenUnderPhrase, "lenunderphrase");
352
print_brailleIndicator (table->begComp, "begcomp");
353
print_brailleIndicator (table->compBegEmph1, "compbegemph1");
354
print_brailleIndicator (table->compEndEmph1, "compendemph1");
355
print_brailleIndicator (table->compBegEmph2, "compbegemph2");
356
print_brailleIndicator (table->compEndEmph2, "compendemph2");
357
print_brailleIndicator (table->compBegEmph3, "compbegemph3");
358
print_brailleIndicator (table->compEndEmph3, "compendemph3");
359
print_brailleIndicator (table->compCapSign, "compcapsign");
360
print_brailleIndicator (table->compBegCaps, "compbegcaps");
361
print_brailleIndicator (table->compEndCaps, "compendcaps");
362
print_brailleIndicator (table->endComp, "endcomp");
377
printf ("Table size: %d\n", table->tableSize);
378
printf ("Bytes used: %d\n", table->bytesUsed);
379
printf ("Number of passes: %d\n", table->numPasses);
380
printf ("'correct' opcodes: %s\n", pickYN (table->corrections));
381
printf ("'syllable' opcodes: %s\n", pickYN (table->syllables));
382
printf ("'capsnocont' opcode: %s\n", pickYN (table->capsNoCont));
383
printf ("Hyphenation table: %s\n", pickYN (table->hyphenStatesArray));
384
printf ("noletsignbefore %s\n", showString (&table->noLetsignBefore[0],
385
table->noLetsignBeforeCount));
386
printf ("noletsign %s\n", showString (&table->noLetsign[0],
387
table->noLetsignCount));
388
printf ("noletsignafter %s\n", showString (&table->noLetsignAfter[0],
389
table->noLetsignAfterCount));
394
show_charMap (int startHash)
397
CharOrDots *thisChar;
398
TranslationTableOffset nextChar;
399
printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
404
for (; k < HASHNUM; k++)
405
if (table->charToDots[k])
407
printf ("Hash=%d\n", k);
408
nextChar = table->charToDots[k];
411
thisChar = (CharOrDots *) & table->ruleArea[nextChar];
412
printf ("Char: %s ", showString (&thisChar->lookFor, 1));
413
printf ("dots=%s\n", showDots (&thisChar->found, 1));
416
if (*inputBuffer == 'h')
418
if (*inputBuffer == 'e')
420
nextChar = thisChar->next;
427
show_dotsMap (int startHash)
430
CharOrDots *thisDots;
431
TranslationTableOffset nextDots;
432
printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
437
for (; k < HASHNUM; k++)
438
if (table->dotsToChar[k])
440
printf ("Hash=%d\n", k);
441
nextDots = table->dotsToChar[k];
444
thisDots = (CharOrDots *) & table->ruleArea[nextDots];
445
printf ("Dots: %s ", showDots (&thisDots->lookFor, 1));
446
printf ("char=%s\n", showString (&thisDots->found, 1));
449
if (*inputBuffer == 'h')
451
if (*inputBuffer == 'e')
453
nextDots = thisDots->next;
460
show_compDots (int startChar)
463
printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
469
if (table->compdotsPattern[k])
471
TranslationTableRule *thisRule = (TranslationTableRule *)
472
& table->ruleArea[table->compdotsPattern[k]];
473
printf ("Char: %s ", showString (&k, 1));
475
showDots (&thisRule->charsdots[1], thisRule->dotslen));
478
if (*inputBuffer == 'e')
487
printf ("show particular hash chains.\n");
489
("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n");
490
printf ("show-(d)ot-patterns, show-(C)har-to-dots, show-(D)ots-tochar\n");
491
printf ("(z)-compdots, (h)elp, e(x)it\n");
495
particularHelp (void)
497
part_paramLetters ();
504
widechar parsed[BUFSIZE];
505
part_paramLetters ();
508
printf ("particular: ");
510
switch (inputBuffer[0])
520
if (!extParseChars (inputBuffer, parsed))
522
startHash = charHash (*parsed);
523
if (table->characters[startHash] == 0)
525
printf ("Character not in table.\n");
528
show_characters (startHash);
533
if (!extParseDots (inputBuffer, parsed))
535
startHash = charHash (*parsed);
536
if (table->dots[startHash] == 0)
538
printf ("Dot pattern not in table.\n");
541
show_dots (startHash);
546
if (!extParseChars (inputBuffer, parsed))
548
startHash = charHash (*parsed);
549
if (table->charToDots[startHash] == 0)
551
printf ("Character not in table.\n");
554
show_charMap (startHash);
559
if (!extParseDots (inputBuffer, parsed))
561
startHash = charHash (*parsed);
562
if (table->dotsToChar[startHash] == 0)
564
printf ("Dot pattern not in table.\n");
567
show_dotsMap (startHash);
572
if (!extParseChars (inputBuffer, parsed))
574
startHash = stringHash (parsed);
575
if (table->forRules[startHash] == 0)
577
printf ("Character string not in table.\n");
580
show_forRules (startHash);
585
if (!extParseDots (inputBuffer, parsed))
587
startHash = stringHash (parsed);
588
if (table->backRules[startHash] == 0)
590
printf ("Dot pattern not in table.\n");
593
show_backRules (startHash);
598
if (!extParseChars (inputBuffer, parsed))
600
startHash = charHash (*parsed);
601
if (*parsed > 255 || table->compdotsPattern[startHash] == 0)
603
printf ("Character not in table.\n");
606
show_compDots (startHash);
611
printf ("Bad choice.\n");
615
while (inputBuffer[0] != 'x');
622
printf ("Press one of the letters in parentheses, then enter.\n");
624
("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n");
625
printf ("show-(d)ot-patterns, show-(C)har-to-dots, show-(D)ots-tochar\n");
626
printf ("show-(m)isc, show-(z)-compdots\n");
627
printf ("show-(p)articulars, (h)elp, (q)uit\n");
642
printf ("Command: ");
644
switch (inputBuffer[0])
661
show_characters (-1);
673
show_brailleIndicators ();
684
printf ("Bad choice.\n");
688
while (inputBuffer[0] != 'q');
693
main (int argc, char **argv)
697
set_program_name (argv[0]);
699
while ((optc = getopt_long (argc, argv, "hv", longopts, NULL)) != -1)
702
/* --help and --version exit immediately, per GNU coding standards. */
704
version_etc (stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *) NULL);
712
fprintf (stderr, "Try `%s --help' for more information.\n",
718
if (optind != argc - 1)
720
/* Print error message and exit. */
721
if (optind < argc - 1)
722
fprintf (stderr, "%s: extra operand: %s\n",
723
program_name, argv[optind + 1]);
725
fprintf (stderr, "%s: no table specified\n",
727
fprintf (stderr, "Try `%s --help' for more information.\n",
732
if (!(table = lou_getTable (argv[optind])))