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