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