Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 1 | /* liblouis Braille Translation and Back-Translation Library |
| 2 | |
| 3 | Based on BRLTTY, copyright (C) 1999-2006 by |
| 4 | The BRLTTY Team |
| 5 | |
Christian Egli | 08d96a7 | 2009-10-08 08:49:13 +0000 | [diff] [blame] | 6 | Copyright (C) 2004, 2005, 2006, 2009 |
| 7 | ViewPlus Technologies, Inc. www.viewplus.com and |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 8 | JJB Software, Inc. www.jjb-software.com |
| 9 | |
Christian Egli | 08d96a7 | 2009-10-08 08:49:13 +0000 | [diff] [blame] | 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. |
| 14 | |
| 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. |
| 19 | |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 20 | You should have received a copy of the GNU General Public License |
Christian Egli | 08d96a7 | 2009-10-08 08:49:13 +0000 | [diff] [blame] | 21 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 22 | |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 23 | */ |
| 24 | |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 25 | #ifdef HAVE_CONFIG_H |
| 26 | # include "config.h" |
| 27 | #endif |
| 28 | |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | #include <string.h> |
| 31 | #include <stdlib.h> |
| 32 | #include "louis.h" |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 33 | #include <getopt.h> |
| 34 | #include "progname.h" |
| 35 | #include "version-etc.h" |
| 36 | |
| 37 | static const struct option longopts[] = |
| 38 | { |
| 39 | { "help", no_argument, NULL, 'h' }, |
| 40 | { "version", no_argument, NULL, 'v' }, |
| 41 | { NULL, 0, NULL, 0 } |
| 42 | }; |
| 43 | |
| 44 | const char version_etc_copyright[] = |
| 45 | "Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc."; |
| 46 | |
| 47 | #define AUTHORS "John J. Boyer" |
| 48 | |
| 49 | static void |
| 50 | print_help (void) |
| 51 | { |
| 52 | printf ("\ |
Christian Egli | baefdb2 | 2012-12-19 09:48:54 +0000 | [diff] [blame] | 53 | Usage: %s [OPTIONS] TABLE[,TABLE,...]\n", program_name); |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 54 | |
| 55 | fputs ("\ |
| 56 | Examine and debug Braille translation tables. This program allows you\n\ |
| 57 | to inspect liblouis translation tables and gather information about\n\ |
| 58 | them, such as forward and backward rules, characters and dot patterns,\n\ |
| 59 | specific opcodes, the size of a table, whether a hyphenation\n\ |
| 60 | table is used, how many passes the translation takes and much\n\ |
| 61 | more.\n\n", stdout); |
| 62 | |
| 63 | fputs ("\ |
| 64 | -h, --help display this help and exit\n\ |
| 65 | -v, --version display version information and exit\n", stdout); |
| 66 | |
| 67 | printf ("\n"); |
Christian Egli | dc50af9 | 2012-09-27 13:10:51 +0000 | [diff] [blame] | 68 | printf ("Report bugs to %s.\n", PACKAGE_BUGREPORT); |
| 69 | |
| 70 | #ifdef PACKAGE_PACKAGER_BUG_REPORTS |
| 71 | printf ("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS); |
| 72 | #endif |
| 73 | #ifdef PACKAGE_URL |
| 74 | printf ("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL); |
| 75 | #endif |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 76 | } |
| 77 | |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 78 | #define BUFSIZE 256 |
| 79 | |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 80 | static const TranslationTableHeader *table; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 81 | static char inputBuffer[BUFSIZE]; |
| 82 | |
| 83 | static int |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 84 | getInput (void) |
| 85 | { |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 86 | int inputLength; |
| 87 | inputBuffer[0] = 0; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 88 | fgets (inputBuffer, sizeof (inputBuffer), stdin); |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 89 | inputLength = strlen (inputBuffer) - 1; |
| 90 | if (inputLength < 0) /*EOF on script */ |
| 91 | exit (0); |
| 92 | inputBuffer[inputLength] = 0; |
| 93 | return inputLength; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | static int |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 97 | printRule (TranslationTableRule * thisRule, int mode) |
| 98 | { |
| 99 | printf ("Rule: "); |
| 100 | printf ("opcode=%s, ", findOpcodeName (thisRule->opcode)); |
| 101 | if (thisRule->before) |
| 102 | printf ("before=%x, ", thisRule->before); |
| 103 | if (thisRule->after) |
| 104 | printf ("after=%x, ", thisRule->after); |
| 105 | switch (thisRule->opcode) |
| 106 | { |
| 107 | case CTO_Context: |
| 108 | case CTO_Correct: |
| 109 | case CTO_SwapCd: |
| 110 | case CTO_SwapDd: |
| 111 | case CTO_Pass2: |
| 112 | case CTO_Pass3: |
| 113 | case CTO_Pass4: |
| 114 | printf ("code=%s ", showString (thisRule->charsdots, thisRule->charslen |
| 115 | + thisRule->dotslen)); |
| 116 | break; |
| 117 | default: |
| 118 | if (mode == 0) |
| 119 | { |
| 120 | printf ("chars=%s, ", showString (thisRule->charsdots, |
| 121 | thisRule->charslen)); |
| 122 | printf ("dots=%s, ", |
| 123 | showDots (&thisRule->charsdots[thisRule->charslen], |
| 124 | thisRule->dotslen)); |
| 125 | } |
| 126 | else |
| 127 | { |
| 128 | printf ("dots=%s, ", |
| 129 | showDots (&thisRule->charsdots[thisRule->charslen], |
| 130 | thisRule->dotslen)); |
| 131 | printf ("chars=%s, ", showString (thisRule->charsdots, |
| 132 | thisRule->charslen)); |
| 133 | } |
| 134 | break; |
| 135 | } |
| 136 | return 1; |
| 137 | } |
| 138 | |
| 139 | static int |
| 140 | printCharacter (TranslationTableCharacter * thisChar, int mode) |
| 141 | { |
| 142 | TranslationTableRule *thisRule; |
| 143 | TranslationTableOffset nextRule; |
| 144 | if (mode == 0) |
| 145 | { |
| 146 | printf ("Char: "); |
| 147 | printf ("real=%s, ", showString (&thisChar->realchar, 1)); |
| 148 | printf ("upper=%s, ", showString (&thisChar->uppercase, 1)); |
| 149 | printf ("lower=%s, ", showString (&thisChar->lowercase, 1)); |
| 150 | } |
| 151 | else |
| 152 | printf ("Dots: real=%s, ", showDots (&thisChar->realchar, 1)); |
| 153 | printf ("attr=%s, ", showAttributes (thisChar->attributes)); |
| 154 | nextRule = thisChar->otherRules; |
| 155 | while (nextRule) |
| 156 | { |
| 157 | thisRule = (TranslationTableRule *) & table->ruleArea[nextRule]; |
John Boyer | c675d7a | 2009-01-15 14:32:20 +0000 | [diff] [blame] | 158 | if (nextRule == thisChar->definitionRule) |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 159 | printf ("definition "); |
| 160 | printRule (thisRule, mode); |
| 161 | printf ("\n"); |
| 162 | if (mode == 0) |
| 163 | nextRule = thisRule->charsnext; |
| 164 | else |
| 165 | nextRule = thisRule->dotsnext; |
| 166 | } |
| 167 | return 1; |
| 168 | } |
| 169 | |
| 170 | static int |
| 171 | show_characters (int startHash) |
| 172 | { |
| 173 | int k; |
| 174 | TranslationTableCharacter *thisChar; |
| 175 | TranslationTableOffset nextChar; |
| 176 | printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 177 | if (startHash < 0) |
| 178 | k = 0; |
| 179 | else |
| 180 | k = startHash; |
| 181 | for (; k < HASHNUM; k++) |
| 182 | if (table->characters[k]) |
| 183 | { |
| 184 | printf ("Hash=%d\n", k); |
| 185 | nextChar = table->characters[k]; |
| 186 | while (nextChar) |
| 187 | { |
| 188 | thisChar = |
| 189 | (TranslationTableCharacter *) & table->ruleArea[nextChar]; |
| 190 | printCharacter (thisChar, 0); |
| 191 | printf ("=> "); |
| 192 | getInput (); |
| 193 | if (*inputBuffer == 'h') |
| 194 | break; |
| 195 | if (*inputBuffer == 'e') |
| 196 | return 1; |
| 197 | nextChar = thisChar->next; |
| 198 | } |
| 199 | } |
| 200 | return 1; |
| 201 | } |
| 202 | |
| 203 | static int |
| 204 | show_dots (int startHash) |
| 205 | { |
| 206 | int k; |
| 207 | TranslationTableCharacter *thisDots; |
| 208 | TranslationTableOffset nextDots; |
| 209 | printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 210 | if (startHash < 0) |
| 211 | k = 0; |
| 212 | else |
| 213 | k = startHash; |
| 214 | for (; k < HASHNUM; k++) |
| 215 | if (table->dots[k]) |
| 216 | { |
| 217 | printf ("Hash=%d\n", k); |
| 218 | nextDots = table->dots[k]; |
| 219 | while (nextDots) |
| 220 | { |
| 221 | thisDots = |
| 222 | (TranslationTableCharacter *) & table->ruleArea[nextDots]; |
| 223 | printCharacter (thisDots, 1); |
| 224 | printf ("=> "); |
| 225 | getInput (); |
| 226 | if (*inputBuffer == 'h') |
| 227 | break; |
| 228 | if (*inputBuffer == 'e') |
| 229 | return 1; |
| 230 | nextDots = thisDots->next; |
| 231 | } |
| 232 | } |
| 233 | return 1; |
| 234 | } |
| 235 | |
| 236 | static int |
| 237 | show_forRules (int startHash) |
| 238 | { |
| 239 | int k; |
| 240 | TranslationTableRule *thisRule; |
| 241 | TranslationTableOffset nextRule; |
| 242 | printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 243 | if (startHash < 0) |
| 244 | k = 0; |
| 245 | else |
| 246 | k = startHash; |
| 247 | for (; k < HASHNUM; k++) |
| 248 | if (table->forRules[k]) |
| 249 | { |
| 250 | printf ("Hash=%d\n", k); |
| 251 | nextRule = table->forRules[k]; |
| 252 | while (nextRule) |
| 253 | { |
| 254 | thisRule = (TranslationTableRule *) & table->ruleArea[nextRule]; |
| 255 | printRule (thisRule, 0); |
| 256 | printf ("=> "); |
| 257 | getInput (); |
| 258 | if (*inputBuffer == 'h') |
| 259 | break; |
| 260 | if (*inputBuffer == 'e') |
| 261 | return 1; |
| 262 | nextRule = thisRule->charsnext; |
| 263 | } |
| 264 | } |
| 265 | return 1; |
| 266 | } |
| 267 | |
| 268 | static int |
| 269 | show_backRules (int startHash) |
| 270 | { |
| 271 | int k; |
| 272 | TranslationTableRule *thisRule; |
| 273 | TranslationTableOffset nextRule; |
| 274 | printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 275 | if (startHash < 0) |
| 276 | k = 0; |
| 277 | else |
| 278 | k = startHash; |
| 279 | for (; k < HASHNUM; k++) |
| 280 | if (table->backRules[k]) |
| 281 | { |
| 282 | printf ("Hash=%d\n", k); |
| 283 | nextRule = table->backRules[k]; |
| 284 | while (nextRule) |
| 285 | { |
| 286 | thisRule = (TranslationTableRule *) & table->ruleArea[nextRule]; |
| 287 | printRule (thisRule, 1); |
| 288 | printf ("=> "); |
| 289 | getInput (); |
| 290 | if (*inputBuffer == 'h') |
| 291 | break; |
| 292 | if (*inputBuffer == 'e') |
| 293 | return 1; |
| 294 | nextRule = thisRule->dotsnext; |
| 295 | } |
| 296 | } |
| 297 | return 1; |
| 298 | } |
| 299 | |
| 300 | static int |
| 301 | print_brailleIndicator (TranslationTableOffset offset, char *opcode) |
| 302 | { |
| 303 | TranslationTableRule *thisRule; |
| 304 | if (!offset) |
| 305 | return 0; |
| 306 | thisRule = (TranslationTableRule *) & table->ruleArea[offset]; |
| 307 | printf ("%s %s\n", opcode, |
| 308 | showDots (&thisRule->charsdots[0], thisRule->dotslen)); |
| 309 | return 1; |
| 310 | } |
| 311 | |
| 312 | static int |
| 313 | print_phraseLength (TranslationTableOffset offset, char *opcode) |
| 314 | { |
| 315 | if (!offset) |
| 316 | return 0; |
| 317 | printf ("%s %d\n", opcode, offset); |
Christian Egli | fbfea8b | 2009-08-11 11:24:40 +0000 | [diff] [blame] | 318 | return 1; |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | static int |
| 322 | show_brailleIndicators (void) |
| 323 | { |
| 324 | print_brailleIndicator (table->capitalSign, "capsign"); |
| 325 | print_brailleIndicator (table->beginCapitalSign, "begcaps"); |
| 326 | print_phraseLength (table->lenBeginCaps, "lenbegcaps"); |
| 327 | print_brailleIndicator (table->endCapitalSign, "endcaps"); |
| 328 | print_brailleIndicator (table->firstWordCaps, "firstwordcaps"); |
| 329 | print_brailleIndicator (table->lastWordCapsAfter, "lastwordaftercaps"); |
| 330 | print_phraseLength (table->lenCapsPhrase, "lencapsphrase"); |
| 331 | print_brailleIndicator (table->letterSign, "letsign"); |
| 332 | print_brailleIndicator (table->numberSign, "numsign"); |
| 333 | print_brailleIndicator (table->firstWordItal, "firstwordital"); |
| 334 | print_brailleIndicator (table->lastWordItalBefore, "lastworditalbefore"); |
| 335 | print_brailleIndicator (table->lastWordItalAfter, "lastworditalafter"); |
| 336 | print_brailleIndicator (table->firstLetterItal, "firstletterital"); |
| 337 | print_brailleIndicator (table->lastLetterItal, "lastletterital"); |
| 338 | print_brailleIndicator (table->singleLetterItal, "singleletterital"); |
| 339 | print_brailleIndicator (table->italWord, "italword"); |
| 340 | print_phraseLength (table->lenItalPhrase, "lenitalphrase"); |
| 341 | print_brailleIndicator (table->firstWordBold, "firstwordbold"); |
| 342 | print_brailleIndicator (table->lastWordBoldBefore, "lastwordboldbefore"); |
| 343 | print_brailleIndicator (table->lastWordBoldAfter, "lastwordboldafter"); |
| 344 | print_brailleIndicator (table->firstLetterBold, "firstletterbold"); |
| 345 | print_brailleIndicator (table->lastLetterBold, "lastletterbold"); |
| 346 | print_brailleIndicator (table->singleLetterBold, "singleletterbold"); |
| 347 | print_brailleIndicator (table->boldWord, "boldword"); |
| 348 | print_phraseLength (table->lenBoldPhrase, "lenboldphrase"); |
| 349 | print_brailleIndicator (table->firstWordUnder, "firstwordunder"); |
| 350 | print_brailleIndicator (table->lastWordUnderBefore, "lastwordunderbefore"); |
| 351 | print_brailleIndicator (table->lastWordUnderAfter, "lastwordunderafter"); |
| 352 | print_brailleIndicator (table->firstLetterUnder, "firstletterunder"); |
| 353 | print_brailleIndicator (table->lastLetterUnder, "lastletterunder"); |
| 354 | print_brailleIndicator (table->singleLetterUnder, "singleletterunder"); |
| 355 | print_brailleIndicator (table->underWord, "underword"); |
| 356 | print_phraseLength (table->lenUnderPhrase, "lenunderphrase"); |
| 357 | print_brailleIndicator (table->begComp, "begcomp"); |
| 358 | print_brailleIndicator (table->compBegEmph1, "compbegemph1"); |
| 359 | print_brailleIndicator (table->compEndEmph1, "compendemph1"); |
| 360 | print_brailleIndicator (table->compBegEmph2, "compbegemph2"); |
| 361 | print_brailleIndicator (table->compEndEmph2, "compendemph2"); |
| 362 | print_brailleIndicator (table->compBegEmph3, "compbegemph3"); |
| 363 | print_brailleIndicator (table->compEndEmph3, "compendemph3"); |
| 364 | print_brailleIndicator (table->compCapSign, "compcapsign"); |
| 365 | print_brailleIndicator (table->compBegCaps, "compbegcaps"); |
| 366 | print_brailleIndicator (table->compEndCaps, "compendcaps"); |
| 367 | print_brailleIndicator (table->endComp, "endcomp"); |
| 368 | return 1; |
| 369 | } |
| 370 | |
| 371 | static char * |
| 372 | pickYN (int a) |
| 373 | { |
| 374 | if (!a) |
| 375 | return "no"; |
| 376 | return "yes"; |
| 377 | } |
| 378 | |
| 379 | static int |
| 380 | show_misc (void) |
| 381 | { |
| 382 | printf ("Table size: %d\n", table->tableSize); |
| 383 | printf ("Bytes used: %d\n", table->bytesUsed); |
| 384 | printf ("Number of passes: %d\n", table->numPasses); |
Christian Egli | 5e8c389 | 2009-01-15 16:30:59 +0000 | [diff] [blame] | 385 | printf ("'correct' opcodes: %s\n", pickYN (table->corrections)); |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 386 | printf ("'syllable' opcodes: %s\n", pickYN (table->syllables)); |
| 387 | printf ("'capsnocont' opcode: %s\n", pickYN (table->capsNoCont)); |
| 388 | printf ("Hyphenation table: %s\n", pickYN (table->hyphenStatesArray)); |
| 389 | printf ("noletsignbefore %s\n", showString (&table->noLetsignBefore[0], |
| 390 | table->noLetsignBeforeCount)); |
| 391 | printf ("noletsign %s\n", showString (&table->noLetsign[0], |
| 392 | table->noLetsignCount)); |
| 393 | printf ("noletsignafter %s\n", showString (&table->noLetsignAfter[0], |
| 394 | table->noLetsignAfterCount)); |
Christian Egli | fbfea8b | 2009-08-11 11:24:40 +0000 | [diff] [blame] | 395 | return 1; |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | static int |
| 399 | show_charMap (int startHash) |
| 400 | { |
| 401 | int k; |
| 402 | CharOrDots *thisChar; |
| 403 | TranslationTableOffset nextChar; |
| 404 | printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 405 | if (startHash < 0) |
| 406 | k = 0; |
| 407 | else |
| 408 | k = startHash; |
| 409 | for (; k < HASHNUM; k++) |
| 410 | if (table->charToDots[k]) |
| 411 | { |
| 412 | printf ("Hash=%d\n", k); |
| 413 | nextChar = table->charToDots[k]; |
| 414 | while (nextChar) |
| 415 | { |
| 416 | thisChar = (CharOrDots *) & table->ruleArea[nextChar]; |
| 417 | printf ("Char: %s ", showString (&thisChar->lookFor, 1)); |
| 418 | printf ("dots=%s\n", showDots (&thisChar->found, 1)); |
| 419 | printf ("=> "); |
| 420 | getInput (); |
| 421 | if (*inputBuffer == 'h') |
| 422 | break; |
| 423 | if (*inputBuffer == 'e') |
| 424 | return 1; |
| 425 | nextChar = thisChar->next; |
| 426 | } |
| 427 | } |
| 428 | return 1; |
| 429 | } |
| 430 | |
| 431 | static int |
| 432 | show_dotsMap (int startHash) |
| 433 | { |
| 434 | int k; |
| 435 | CharOrDots *thisDots; |
| 436 | TranslationTableOffset nextDots; |
| 437 | printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 438 | if (startHash < 0) |
| 439 | k = 0; |
| 440 | else |
| 441 | k = startHash; |
| 442 | for (; k < HASHNUM; k++) |
| 443 | if (table->dotsToChar[k]) |
| 444 | { |
| 445 | printf ("Hash=%d\n", k); |
| 446 | nextDots = table->dotsToChar[k]; |
| 447 | while (nextDots) |
| 448 | { |
| 449 | thisDots = (CharOrDots *) & table->ruleArea[nextDots]; |
| 450 | printf ("Dots: %s ", showDots (&thisDots->lookFor, 1)); |
| 451 | printf ("char=%s\n", showString (&thisDots->found, 1)); |
| 452 | printf ("=> "); |
| 453 | getInput (); |
| 454 | if (*inputBuffer == 'h') |
| 455 | break; |
| 456 | if (*inputBuffer == 'e') |
| 457 | return 1; |
| 458 | nextDots = thisDots->next; |
| 459 | } |
| 460 | } |
| 461 | return 1; |
| 462 | } |
| 463 | |
| 464 | static int |
| 465 | show_compDots (int startChar) |
| 466 | { |
| 467 | widechar k; |
| 468 | printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 469 | if (startChar < 0) |
| 470 | k = 0; |
| 471 | else |
| 472 | k = startChar; |
| 473 | for (; k < 256; k++) |
| 474 | if (table->compdotsPattern[k]) |
| 475 | { |
| 476 | TranslationTableRule *thisRule = (TranslationTableRule *) |
| 477 | & table->ruleArea[table->compdotsPattern[k]]; |
| 478 | printf ("Char: %s ", showString (&k, 1)); |
| 479 | printf ("dots=%s\n", |
| 480 | showDots (&thisRule->charsdots[1], thisRule->dotslen)); |
| 481 | printf ("=> "); |
| 482 | getInput (); |
| 483 | if (*inputBuffer == 'e') |
| 484 | return 1; |
| 485 | } |
| 486 | return 1; |
| 487 | } |
| 488 | |
| 489 | static void |
| 490 | part_paramLetters () |
| 491 | { |
| 492 | printf ("show particular hash chains.\n"); |
| 493 | printf |
| 494 | ("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n"); |
| 495 | printf ("show-(d)ot-patterns, show-(C)har-to-dots, show-(D)ots-tochar\n"); |
| 496 | printf ("(z)-compdots, (h)elp, e(x)it\n"); |
| 497 | } |
| 498 | |
| 499 | static void |
| 500 | particularHelp (void) |
| 501 | { |
| 502 | part_paramLetters (); |
| 503 | } |
| 504 | |
| 505 | static int |
| 506 | particular (void) |
| 507 | { |
| 508 | int startHash; |
| 509 | widechar parsed[BUFSIZE]; |
| 510 | part_paramLetters (); |
| 511 | do |
| 512 | { |
| 513 | printf ("particular: "); |
| 514 | getInput (); |
| 515 | switch (inputBuffer[0]) |
| 516 | { |
| 517 | case 0: |
| 518 | break; |
| 519 | case 'h': |
| 520 | particularHelp (); |
| 521 | break; |
| 522 | case 'c': |
| 523 | printf ("-> "); |
| 524 | getInput (); |
| 525 | if (!extParseChars (inputBuffer, parsed)) |
| 526 | break; |
| 527 | startHash = charHash (*parsed); |
| 528 | if (table->characters[startHash] == 0) |
| 529 | { |
| 530 | printf ("Character not in table.\n"); |
| 531 | break; |
| 532 | } |
| 533 | show_characters (startHash); |
| 534 | break; |
| 535 | case 'd': |
| 536 | printf ("-> "); |
| 537 | getInput (); |
| 538 | if (!extParseDots (inputBuffer, parsed)) |
| 539 | break; |
| 540 | startHash = charHash (*parsed); |
| 541 | if (table->dots[startHash] == 0) |
| 542 | { |
| 543 | printf ("Dot pattern not in table.\n"); |
| 544 | break; |
| 545 | } |
| 546 | show_dots (startHash); |
| 547 | break; |
| 548 | case 'C': |
| 549 | printf ("-> "); |
| 550 | getInput (); |
| 551 | if (!extParseChars (inputBuffer, parsed)) |
| 552 | break; |
| 553 | startHash = charHash (*parsed); |
| 554 | if (table->charToDots[startHash] == 0) |
| 555 | { |
| 556 | printf ("Character not in table.\n"); |
| 557 | break; |
| 558 | } |
| 559 | show_charMap (startHash); |
| 560 | break; |
| 561 | case 'D': |
| 562 | printf ("-> "); |
| 563 | getInput (); |
| 564 | if (!extParseDots (inputBuffer, parsed)) |
| 565 | break; |
| 566 | startHash = charHash (*parsed); |
| 567 | if (table->dotsToChar[startHash] == 0) |
| 568 | { |
| 569 | printf ("Dot pattern not in table.\n"); |
| 570 | break; |
| 571 | } |
| 572 | show_dotsMap (startHash); |
| 573 | break; |
| 574 | case 'f': |
| 575 | printf ("-> "); |
| 576 | getInput (); |
| 577 | if (!extParseChars (inputBuffer, parsed)) |
| 578 | break; |
| 579 | startHash = stringHash (parsed); |
| 580 | if (table->forRules[startHash] == 0) |
| 581 | { |
| 582 | printf ("Character string not in table.\n"); |
| 583 | break; |
| 584 | } |
| 585 | show_forRules (startHash); |
| 586 | break; |
| 587 | case 'b': |
| 588 | printf ("-> "); |
| 589 | getInput (); |
| 590 | if (!extParseDots (inputBuffer, parsed)) |
| 591 | break; |
| 592 | startHash = stringHash (parsed); |
| 593 | if (table->backRules[startHash] == 0) |
| 594 | { |
| 595 | printf ("Dot pattern not in table.\n"); |
| 596 | break; |
| 597 | } |
| 598 | show_backRules (startHash); |
| 599 | break; |
| 600 | case 'z': |
| 601 | printf ("-> "); |
| 602 | getInput (); |
| 603 | if (!extParseChars (inputBuffer, parsed)) |
| 604 | break; |
| 605 | startHash = charHash (*parsed); |
| 606 | if (*parsed > 255 || table->compdotsPattern[startHash] == 0) |
| 607 | { |
| 608 | printf ("Character not in table.\n"); |
| 609 | break; |
| 610 | } |
| 611 | show_compDots (startHash); |
| 612 | break; |
| 613 | case 'x': |
| 614 | return 1; |
| 615 | default: |
| 616 | printf ("Bad choice.\n"); |
| 617 | break; |
| 618 | } |
| 619 | } |
| 620 | while (inputBuffer[0] != 'x'); |
| 621 | return 1; |
| 622 | } |
| 623 | |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 624 | static void |
| 625 | paramLetters (void) |
| 626 | { |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 627 | printf ("Press one of the letters in parentheses, then enter.\n"); |
| 628 | printf |
| 629 | ("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n"); |
| 630 | printf ("show-(d)ot-patterns, show-(C)har-to-dots, show-(D)ots-tochar\n"); |
| 631 | printf ("show-(m)isc, show-(z)-compdots\n"); |
| 632 | printf ("show-(p)articulars, (h)elp, (q)uit\n"); |
| 633 | } |
| 634 | |
| 635 | static void |
| 636 | commandHelp (void) |
| 637 | { |
| 638 | paramLetters (); |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | static int |
| 642 | getCommands (void) |
| 643 | { |
| 644 | paramLetters (); |
| 645 | do |
| 646 | { |
| 647 | printf ("Command: "); |
| 648 | getInput (); |
| 649 | switch (inputBuffer[0]) |
| 650 | { |
| 651 | case 0: |
| 652 | break; |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 653 | case 'h': |
| 654 | commandHelp (); |
| 655 | break; |
| 656 | case 'C': |
| 657 | show_charMap (-1); |
| 658 | break; |
| 659 | case 'D': |
| 660 | show_dotsMap (-1); |
| 661 | break; |
| 662 | case 'z': |
| 663 | show_compDots (-1); |
| 664 | break; |
| 665 | case 'c': |
| 666 | show_characters (-1); |
| 667 | break; |
| 668 | case 'd': |
| 669 | show_dots (-1); |
| 670 | break; |
| 671 | case 'f': |
| 672 | show_forRules (-1); |
| 673 | break; |
| 674 | case 'b': |
| 675 | show_backRules (-1); |
| 676 | break; |
| 677 | case 'i': |
| 678 | show_brailleIndicators (); |
| 679 | break; |
| 680 | case 'm': |
| 681 | show_misc (); |
| 682 | break; |
| 683 | case 'p': |
| 684 | particular (); |
| 685 | break; |
| 686 | case 'q': |
| 687 | return 1; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 688 | default: |
| 689 | printf ("Bad choice.\n"); |
| 690 | break; |
| 691 | } |
| 692 | } |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 693 | while (inputBuffer[0] != 'q'); |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 694 | return 1; |
| 695 | } |
| 696 | |
| 697 | int |
| 698 | main (int argc, char **argv) |
| 699 | { |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 700 | int optc; |
| 701 | |
| 702 | set_program_name (argv[0]); |
| 703 | |
| 704 | while ((optc = getopt_long (argc, argv, "hv", longopts, NULL)) != -1) |
| 705 | switch (optc) |
| 706 | { |
| 707 | /* --help and --version exit immediately, per GNU coding standards. */ |
| 708 | case 'v': |
| 709 | version_etc (stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *) NULL); |
| 710 | exit (EXIT_SUCCESS); |
| 711 | break; |
| 712 | case 'h': |
| 713 | print_help (); |
| 714 | exit (EXIT_SUCCESS); |
| 715 | break; |
| 716 | default: |
| 717 | fprintf (stderr, "Try `%s --help' for more information.\n", |
| 718 | program_name); |
| 719 | exit (EXIT_FAILURE); |
| 720 | break; |
| 721 | } |
| 722 | |
| 723 | if (optind != argc - 1) |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 724 | { |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 725 | /* Print error message and exit. */ |
| 726 | if (optind < argc - 1) |
| 727 | fprintf (stderr, "%s: extra operand: %s\n", |
| 728 | program_name, argv[optind + 1]); |
| 729 | else |
| 730 | fprintf (stderr, "%s: no table specified\n", |
| 731 | program_name); |
| 732 | fprintf (stderr, "Try `%s --help' for more information.\n", |
| 733 | program_name); |
| 734 | exit (EXIT_FAILURE); |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 735 | } |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 736 | |
| 737 | if (!(table = lou_getTable (argv[optind]))) |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 738 | { |
| 739 | lou_free (); |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 740 | exit (EXIT_FAILURE); |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 741 | } |
| 742 | getCommands (); |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 743 | lou_free (); |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 744 | exit (EXIT_SUCCESS); |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 745 | } |