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