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. |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 14 | |
Christian Egli | 08d96a7 | 2009-10-08 08:49:13 +0000 | [diff] [blame] | 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. |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 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 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +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 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 34 | static const struct option longopts[] = { |
Christian Egli | 585c676 | 2019-06-05 15:19:10 +0200 | [diff] [blame] | 35 | { "help", no_argument, NULL, 'h' }, |
| 36 | { "version", no_argument, NULL, 'v' }, |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 37 | { NULL, 0, NULL, 0 }, |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 38 | }; |
| 39 | |
| 40 | const char version_etc_copyright[] = |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 41 | "Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc."; |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 42 | |
| 43 | #define AUTHORS "John J. Boyer" |
| 44 | |
| 45 | static void |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 46 | print_help(void) { |
| 47 | printf("\ |
| 48 | Usage: %s [OPTIONS] TABLE[,TABLE,...]\n", |
| 49 | program_name); |
| 50 | |
| 51 | fputs("\ |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 52 | Examine and debug Braille translation tables. This program allows you\n\ |
| 53 | to inspect liblouis translation tables and gather information about\n\ |
| 54 | them, such as forward and backward rules, characters and dot patterns,\n\ |
| 55 | specific opcodes, the size of a table, whether a hyphenation\n\ |
| 56 | table is used, how many passes the translation takes and much\n\ |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 57 | more.\n\n", |
| 58 | stdout); |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 59 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 60 | fputs("\ |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 61 | -h, --help display this help and exit\n\ |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 62 | -v, --version display version information and exit\n", |
| 63 | stdout); |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 64 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 65 | printf("\n"); |
| 66 | printf("Report bugs to %s.\n", PACKAGE_BUGREPORT); |
Christian Egli | dc50af9 | 2012-09-27 13:10:51 +0000 | [diff] [blame] | 67 | |
| 68 | #ifdef PACKAGE_PACKAGER_BUG_REPORTS |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 69 | printf("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS); |
Christian Egli | dc50af9 | 2012-09-27 13:10:51 +0000 | [diff] [blame] | 70 | #endif |
| 71 | #ifdef PACKAGE_URL |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 72 | printf("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL); |
Christian Egli | dc50af9 | 2012-09-27 13:10:51 +0000 | [diff] [blame] | 73 | #endif |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 74 | } |
| 75 | |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 76 | #define BUFSIZE 256 |
| 77 | |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 78 | static const TranslationTableHeader *table; |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 79 | static const DisplayTableHeader *displayTable; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 80 | static char inputBuffer[BUFSIZE]; |
| 81 | |
| 82 | static int |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 83 | getInput(void) { |
| 84 | int inputLength; |
| 85 | inputBuffer[0] = 0; |
| 86 | if (!fgets(inputBuffer, sizeof(inputBuffer), stdin)) exit(EXIT_FAILURE); |
| 87 | inputLength = strlen(inputBuffer) - 1; |
| 88 | if (inputLength < 0) /* EOF on script */ |
| 89 | exit(EXIT_FAILURE); |
| 90 | inputBuffer[inputLength] = 0; |
| 91 | return inputLength; |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static char * |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 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 |
| 99 | u32_to_u8(buffer, length, result_buf, &result_len); |
| 100 | #else |
| 101 | u16_to_u8(buffer, length, result_buf, &result_len); |
| 102 | #endif |
| 103 | result_buf[result_len] = 0; |
| 104 | return result_buf; |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static int |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 108 | printRule(TranslationTableRule *thisRule, int mode) { |
| 109 | printf("Rule: "); |
| 110 | printf("opcode=%s, ", _lou_findOpcodeName(thisRule->opcode)); |
| 111 | if (thisRule->before) printf("before=%x, ", thisRule->before); |
| 112 | if (thisRule->after) printf("after=%x, ", thisRule->after); |
| 113 | switch (thisRule->opcode) { |
| 114 | case CTO_Context: |
| 115 | case CTO_Correct: |
| 116 | case CTO_SwapCd: |
| 117 | case CTO_SwapDd: |
| 118 | case CTO_Pass2: |
| 119 | case CTO_Pass3: |
| 120 | case CTO_Pass4: |
| 121 | printf("code=%s ", |
| 122 | print_chars(thisRule->charsdots, thisRule->charslen + thisRule->dotslen)); |
| 123 | break; |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 124 | default: |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 125 | if (mode == 0) { |
| 126 | printf("chars=%s, ", print_chars(thisRule->charsdots, thisRule->charslen)); |
Christian Egli | 585c676 | 2019-06-05 15:19:10 +0200 | [diff] [blame] | 127 | printf("dots=%s, ", |
| 128 | _lou_showDots( |
| 129 | &thisRule->charsdots[thisRule->charslen], thisRule->dotslen)); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 130 | } else { |
Christian Egli | 585c676 | 2019-06-05 15:19:10 +0200 | [diff] [blame] | 131 | printf("dots=%s, ", |
| 132 | _lou_showDots( |
| 133 | &thisRule->charsdots[thisRule->charslen], thisRule->dotslen)); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 134 | printf("chars=%s, ", print_chars(thisRule->charsdots, thisRule->charslen)); |
| 135 | } |
| 136 | break; |
John Boyer | 16689ac | 2009-01-12 15:11:39 +0000 | [diff] [blame] | 137 | } |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 138 | return 1; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | static int |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 142 | printCharacter(TranslationTableCharacter *thisChar, int mode) { |
| 143 | TranslationTableRule *thisRule; |
| 144 | TranslationTableOffset nextRule; |
| 145 | if (mode == 0) { |
| 146 | printf("Char: "); |
| 147 | printf("real=%s, ", print_chars(&thisChar->realchar, 1)); |
| 148 | printf("upper=%s, ", print_chars(&thisChar->uppercase, 1)); |
| 149 | printf("lower=%s, ", print_chars(&thisChar->lowercase, 1)); |
| 150 | } else |
| 151 | printf("Dots: real=%s, ", _lou_showDots(&thisChar->realchar, 1)); |
| 152 | printf("attr=%s, ", _lou_showAttributes(thisChar->attributes)); |
| 153 | nextRule = thisChar->otherRules; |
| 154 | while (nextRule) { |
| 155 | thisRule = (TranslationTableRule *)&table->ruleArea[nextRule]; |
| 156 | if (nextRule == thisChar->definitionRule) printf("definition "); |
| 157 | printRule(thisRule, mode); |
| 158 | printf("\n"); |
| 159 | if (mode == 0) |
| 160 | nextRule = thisRule->charsnext; |
| 161 | else |
| 162 | nextRule = thisRule->dotsnext; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 163 | } |
Bert Frees | 1171cf8 | 2021-07-24 12:27:08 +0200 | [diff] [blame] | 164 | if (mode == 0 && thisChar->compRule) { |
| 165 | TranslationTableRule *compRule = |
| 166 | (TranslationTableRule *)&table->ruleArea[thisChar->compRule]; |
| 167 | printf("comp6 "); |
| 168 | printRule(compRule, 0); |
| 169 | printf("\n"); |
| 170 | } |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 171 | return 1; |
| 172 | } |
| 173 | |
| 174 | static int |
| 175 | show_characters(int startHash) { |
| 176 | int k; |
| 177 | TranslationTableCharacter *thisChar; |
| 178 | TranslationTableOffset nextChar; |
| 179 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 180 | if (startHash < 0) |
| 181 | k = 0; |
| 182 | else |
| 183 | k = startHash; |
| 184 | for (; k < HASHNUM; k++) |
| 185 | if (table->characters[k]) { |
| 186 | printf("Hash=%d\n", k); |
| 187 | nextChar = table->characters[k]; |
| 188 | while (nextChar) { |
| 189 | thisChar = (TranslationTableCharacter *)&table->ruleArea[nextChar]; |
| 190 | printCharacter(thisChar, 0); |
| 191 | printf("=> "); |
| 192 | getInput(); |
| 193 | if (*inputBuffer == 'h') break; |
| 194 | if (*inputBuffer == 'e') return 1; |
| 195 | nextChar = thisChar->next; |
| 196 | } |
| 197 | } |
| 198 | return 1; |
| 199 | } |
| 200 | |
| 201 | static int |
| 202 | show_dots(int startHash) { |
| 203 | int k; |
| 204 | TranslationTableCharacter *thisDots; |
| 205 | TranslationTableOffset nextDots; |
| 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->dots[k]) { |
| 213 | printf("Hash=%d\n", k); |
| 214 | nextDots = table->dots[k]; |
| 215 | while (nextDots) { |
| 216 | thisDots = (TranslationTableCharacter *)&table->ruleArea[nextDots]; |
| 217 | printCharacter(thisDots, 1); |
| 218 | printf("=> "); |
| 219 | getInput(); |
| 220 | if (*inputBuffer == 'h') break; |
| 221 | if (*inputBuffer == 'e') return 1; |
| 222 | nextDots = thisDots->next; |
| 223 | } |
| 224 | } |
| 225 | return 1; |
| 226 | } |
| 227 | |
| 228 | static int |
| 229 | show_forRules(int startHash) { |
| 230 | int k; |
| 231 | TranslationTableRule *thisRule; |
| 232 | TranslationTableOffset nextRule; |
| 233 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 234 | if (startHash < 0) |
| 235 | k = 0; |
| 236 | else |
| 237 | k = startHash; |
| 238 | for (; k < HASHNUM; k++) |
| 239 | if (table->forRules[k]) { |
| 240 | printf("Hash=%d\n", k); |
| 241 | nextRule = table->forRules[k]; |
| 242 | while (nextRule) { |
| 243 | thisRule = (TranslationTableRule *)&table->ruleArea[nextRule]; |
| 244 | printRule(thisRule, 0); |
| 245 | printf("=> "); |
| 246 | getInput(); |
| 247 | if (*inputBuffer == 'h') break; |
| 248 | if (*inputBuffer == 'e') return 1; |
| 249 | nextRule = thisRule->charsnext; |
| 250 | } |
| 251 | } |
| 252 | return 1; |
| 253 | } |
| 254 | |
| 255 | static int |
| 256 | show_backRules(int startHash) { |
| 257 | int k; |
| 258 | TranslationTableRule *thisRule; |
| 259 | TranslationTableOffset nextRule; |
| 260 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 261 | if (startHash < 0) |
| 262 | k = 0; |
| 263 | else |
| 264 | k = startHash; |
| 265 | for (; k < HASHNUM; k++) |
| 266 | if (table->backRules[k]) { |
| 267 | printf("Hash=%d\n", k); |
| 268 | nextRule = table->backRules[k]; |
| 269 | while (nextRule) { |
| 270 | thisRule = (TranslationTableRule *)&table->ruleArea[nextRule]; |
| 271 | printRule(thisRule, 1); |
| 272 | printf("=> "); |
| 273 | getInput(); |
| 274 | if (*inputBuffer == 'h') break; |
| 275 | if (*inputBuffer == 'e') return 1; |
| 276 | nextRule = thisRule->dotsnext; |
| 277 | } |
| 278 | } |
| 279 | return 1; |
| 280 | } |
| 281 | |
| 282 | static int |
Christian Egli | 0cfcd19 | 2018-05-08 11:22:46 +0200 | [diff] [blame] | 283 | print_brailleIndicator(TranslationTableOffset offset, const char *opcode) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 284 | TranslationTableRule *thisRule; |
| 285 | if (!offset) return 0; |
| 286 | thisRule = (TranslationTableRule *)&table->ruleArea[offset]; |
| 287 | printf("%s %s\n", opcode, _lou_showDots(&thisRule->charsdots[0], thisRule->dotslen)); |
| 288 | return 1; |
| 289 | } |
| 290 | |
| 291 | static int |
Christian Egli | 0cfcd19 | 2018-05-08 11:22:46 +0200 | [diff] [blame] | 292 | print_phraseLength(TranslationTableOffset offset, const char *opcode) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 293 | if (!offset) return 0; |
Christian Egli | da0d2eb | 2018-05-07 13:41:57 +0200 | [diff] [blame] | 294 | printf("%s %u\n", opcode, offset); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 295 | return 1; |
| 296 | } |
| 297 | |
| 298 | static int |
| 299 | show_brailleIndicators(void) { |
| 300 | char name[BUFSIZE]; |
Christian Egli | 0cfcd19 | 2018-05-08 11:22:46 +0200 | [diff] [blame] | 301 | const char *emphNames[] = { "begemphphrase %s", "endemphphrase %s before", |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 302 | "endemphphrase %s after", "begemphword %s", "endemphword %s", "emphletter %s", |
| 303 | "begemph %s", "endemph %s", NULL }; |
Christian Egli | d92cec1 | 2018-05-08 11:51:17 +0200 | [diff] [blame] | 304 | const char *capsNames[] = { "firstwordcaps", "lastwordcapsbefore", |
| 305 | "lastwordcapsafter", "begcaps", "endcaps", "capsletter", "capsword", |
| 306 | "capswordstop", NULL }; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 307 | |
| 308 | // FIXME: update to include all UEB opcodes. |
| 309 | |
| 310 | for (EmphCodeOffset offset = 0; capsNames[offset]; offset++) { |
| 311 | print_brailleIndicator(table->emphRules[capsRule][offset], capsNames[offset]); |
| 312 | } |
| 313 | print_phraseLength(table->emphRules[capsRule][lenPhraseOffset], "lencapsphrase"); |
| 314 | print_brailleIndicator(table->letterSign, "letsign"); |
| 315 | print_brailleIndicator(table->numberSign, "numsign"); |
| 316 | |
| 317 | for (int i = 0; table->emphClasses[i]; i++) { |
| 318 | for (EmphCodeOffset offset = 0; emphNames[offset]; offset++) { |
| 319 | snprintf(name, BUFSIZE, emphNames[offset], table->emphClasses[i]); |
| 320 | print_brailleIndicator(table->emphRules[emph1Rule][offset], name); |
| 321 | } |
| 322 | snprintf(name, BUFSIZE, "lenemphphrase %s", table->emphClasses[i]); |
| 323 | print_phraseLength(table->emphRules[emph1Rule][lenPhraseOffset], name); |
| 324 | } |
| 325 | print_brailleIndicator(table->begComp, "begcomp"); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 326 | print_brailleIndicator(table->endComp, "endcomp"); |
| 327 | return 1; |
| 328 | } |
| 329 | |
Christian Egli | 0cfcd19 | 2018-05-08 11:22:46 +0200 | [diff] [blame] | 330 | static const char * |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 331 | pickYN(int a) { |
| 332 | if (!a) return "no"; |
| 333 | return "yes"; |
| 334 | } |
| 335 | |
| 336 | static int |
| 337 | show_misc(void) { |
Christian Egli | da0d2eb | 2018-05-07 13:41:57 +0200 | [diff] [blame] | 338 | printf("Table size: %u\n", table->tableSize); |
| 339 | printf("Bytes used: %u\n", table->bytesUsed); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 340 | printf("Number of passes: %d\n", table->numPasses); |
| 341 | printf("'correct' opcodes: %s\n", pickYN(table->corrections)); |
| 342 | printf("'syllable' opcodes: %s\n", pickYN(table->syllables)); |
| 343 | printf("'capsnocont' opcode: %s\n", pickYN(table->capsNoCont)); |
| 344 | printf("Hyphenation table: %s\n", pickYN(table->hyphenStatesArray)); |
| 345 | printf("noletsignbefore %s\n", |
| 346 | print_chars(&table->noLetsignBefore[0], table->noLetsignBeforeCount)); |
| 347 | printf("noletsign %s\n", print_chars(&table->noLetsign[0], table->noLetsignCount)); |
| 348 | printf("noletsignafter %s\n", |
| 349 | print_chars(&table->noLetsignAfter[0], table->noLetsignAfterCount)); |
| 350 | return 1; |
| 351 | } |
| 352 | |
| 353 | static int |
| 354 | show_charMap(int startHash) { |
| 355 | int k; |
Bert Frees | b2b6742 | 2020-03-08 22:31:58 +0100 | [diff] [blame] | 356 | CharDotsMapping *thisChar; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 357 | TranslationTableOffset nextChar; |
| 358 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 359 | if (startHash < 0) |
| 360 | k = 0; |
| 361 | else |
| 362 | k = startHash; |
| 363 | for (; k < HASHNUM; k++) |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 364 | if (displayTable->charToDots[k]) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 365 | printf("Hash=%d\n", k); |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 366 | nextChar = displayTable->charToDots[k]; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 367 | while (nextChar) { |
Bert Frees | b2b6742 | 2020-03-08 22:31:58 +0100 | [diff] [blame] | 368 | thisChar = (CharDotsMapping *)&displayTable->ruleArea[nextChar]; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 369 | printf("Char: %s ", print_chars(&thisChar->lookFor, 1)); |
| 370 | printf("dots=%s\n", _lou_showDots(&thisChar->found, 1)); |
| 371 | printf("=> "); |
| 372 | getInput(); |
| 373 | if (*inputBuffer == 'h') break; |
| 374 | if (*inputBuffer == 'e') return 1; |
| 375 | nextChar = thisChar->next; |
| 376 | } |
| 377 | } |
| 378 | return 1; |
| 379 | } |
| 380 | |
| 381 | static int |
| 382 | show_dotsMap(int startHash) { |
| 383 | int k; |
Bert Frees | b2b6742 | 2020-03-08 22:31:58 +0100 | [diff] [blame] | 384 | CharDotsMapping *thisDots; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 385 | TranslationTableOffset nextDots; |
| 386 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 387 | if (startHash < 0) |
| 388 | k = 0; |
| 389 | else |
| 390 | k = startHash; |
| 391 | for (; k < HASHNUM; k++) |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 392 | if (displayTable->dotsToChar[k]) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 393 | printf("Hash=%d\n", k); |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 394 | nextDots = displayTable->dotsToChar[k]; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 395 | while (nextDots) { |
Bert Frees | b2b6742 | 2020-03-08 22:31:58 +0100 | [diff] [blame] | 396 | thisDots = (CharDotsMapping *)&displayTable->ruleArea[nextDots]; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 397 | printf("Dots: %s ", _lou_showDots(&thisDots->lookFor, 1)); |
| 398 | printf("char=%s\n", print_chars(&thisDots->found, 1)); |
| 399 | printf("=> "); |
| 400 | getInput(); |
| 401 | if (*inputBuffer == 'h') break; |
| 402 | if (*inputBuffer == 'e') return 1; |
| 403 | nextDots = thisDots->next; |
| 404 | } |
| 405 | } |
| 406 | return 1; |
| 407 | } |
| 408 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 409 | static void |
| 410 | part_paramLetters(void) { |
| 411 | printf("show particular hash chains.\n"); |
| 412 | printf("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n"); |
| 413 | printf("show-(d)ot-patterns, show-(C)har-to-dots, show-(D)ots-tochar\n"); |
Bert Frees | 1171cf8 | 2021-07-24 12:27:08 +0200 | [diff] [blame] | 414 | printf("(h)elp, e(x)it\n"); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static void |
| 418 | particularHelp(void) { |
| 419 | part_paramLetters(); |
| 420 | } |
| 421 | |
| 422 | static int |
| 423 | particular(void) { |
| 424 | int startHash; |
| 425 | widechar parsed[BUFSIZE]; |
| 426 | part_paramLetters(); |
| 427 | do { |
| 428 | printf("particular: "); |
| 429 | getInput(); |
| 430 | switch (inputBuffer[0]) { |
| 431 | case 0: |
| 432 | break; |
| 433 | case 'h': |
| 434 | particularHelp(); |
| 435 | break; |
| 436 | case 'c': |
| 437 | printf("-> "); |
| 438 | getInput(); |
| 439 | if (!_lou_extParseChars(inputBuffer, parsed)) break; |
| 440 | startHash = _lou_charHash(*parsed); |
| 441 | if (table->characters[startHash] == 0) { |
| 442 | printf("Character not in table.\n"); |
| 443 | break; |
| 444 | } |
| 445 | show_characters(startHash); |
| 446 | break; |
| 447 | case 'd': |
| 448 | printf("-> "); |
| 449 | getInput(); |
| 450 | if (!_lou_extParseDots(inputBuffer, parsed)) break; |
| 451 | startHash = _lou_charHash(*parsed); |
| 452 | if (table->dots[startHash] == 0) { |
| 453 | printf("Dot pattern not in table.\n"); |
| 454 | break; |
| 455 | } |
| 456 | show_dots(startHash); |
| 457 | break; |
| 458 | case 'C': |
| 459 | printf("-> "); |
| 460 | getInput(); |
| 461 | if (!_lou_extParseChars(inputBuffer, parsed)) break; |
| 462 | startHash = _lou_charHash(*parsed); |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 463 | if (displayTable->charToDots[startHash] == 0) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 464 | printf("Character not in table.\n"); |
| 465 | break; |
| 466 | } |
| 467 | show_charMap(startHash); |
| 468 | break; |
| 469 | case 'D': |
| 470 | printf("-> "); |
| 471 | getInput(); |
| 472 | if (!_lou_extParseDots(inputBuffer, parsed)) break; |
| 473 | startHash = _lou_charHash(*parsed); |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 474 | if (displayTable->dotsToChar[startHash] == 0) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 475 | printf("Dot pattern not in table.\n"); |
| 476 | break; |
| 477 | } |
| 478 | show_dotsMap(startHash); |
| 479 | break; |
| 480 | case 'f': |
| 481 | printf("-> "); |
| 482 | getInput(); |
| 483 | if (!_lou_extParseChars(inputBuffer, parsed)) break; |
Bert Frees | d4b7a8e | 2019-06-04 13:56:07 +0200 | [diff] [blame] | 484 | startHash = _lou_stringHash(parsed, 0, NULL); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 485 | if (table->forRules[startHash] == 0) { |
| 486 | printf("Character string not in table.\n"); |
| 487 | break; |
| 488 | } |
| 489 | show_forRules(startHash); |
| 490 | break; |
| 491 | case 'b': |
| 492 | printf("-> "); |
| 493 | getInput(); |
| 494 | if (!_lou_extParseDots(inputBuffer, parsed)) break; |
Bert Frees | d4b7a8e | 2019-06-04 13:56:07 +0200 | [diff] [blame] | 495 | startHash = _lou_stringHash(parsed, 0, NULL); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 496 | if (table->backRules[startHash] == 0) { |
| 497 | printf("Dot pattern not in table.\n"); |
| 498 | break; |
| 499 | } |
| 500 | show_backRules(startHash); |
| 501 | break; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 502 | case 'x': |
| 503 | return 1; |
| 504 | default: |
| 505 | printf("Bad choice.\n"); |
| 506 | break; |
| 507 | } |
| 508 | } while (inputBuffer[0] != 'x'); |
| 509 | return 1; |
| 510 | } |
| 511 | |
| 512 | static void |
| 513 | paramLetters(void) { |
| 514 | printf("Press one of the letters in parentheses, then enter.\n"); |
| 515 | printf("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n"); |
| 516 | printf("show-(d)ot-patterns, show-(C)har-to-dots, show-(D)ots-tochar\n"); |
Bert Frees | 1171cf8 | 2021-07-24 12:27:08 +0200 | [diff] [blame] | 517 | printf("show-(m)isc, show-braille(i)ndicators, show-(p)articulars\n"); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 518 | printf("(h)elp, (q)uit\n"); |
| 519 | } |
| 520 | |
| 521 | static void |
| 522 | commandHelp(void) { |
| 523 | paramLetters(); |
| 524 | } |
| 525 | |
| 526 | static int |
| 527 | getCommands(void) { |
| 528 | paramLetters(); |
| 529 | do { |
| 530 | printf("Command: "); |
| 531 | getInput(); |
| 532 | switch (inputBuffer[0]) { |
| 533 | case 0: |
| 534 | break; |
| 535 | case 'h': |
| 536 | commandHelp(); |
| 537 | break; |
| 538 | case 'C': |
| 539 | show_charMap(-1); |
| 540 | break; |
| 541 | case 'D': |
| 542 | show_dotsMap(-1); |
| 543 | break; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 544 | case 'c': |
| 545 | show_characters(-1); |
| 546 | break; |
| 547 | case 'd': |
| 548 | show_dots(-1); |
| 549 | break; |
| 550 | case 'f': |
| 551 | show_forRules(-1); |
| 552 | break; |
| 553 | case 'b': |
| 554 | show_backRules(-1); |
| 555 | break; |
| 556 | case 'i': |
| 557 | show_brailleIndicators(); |
| 558 | break; |
| 559 | case 'm': |
| 560 | show_misc(); |
| 561 | break; |
| 562 | case 'p': |
| 563 | particular(); |
| 564 | break; |
| 565 | case 'q': |
| 566 | return 1; |
| 567 | default: |
| 568 | printf("Bad choice.\n"); |
| 569 | break; |
| 570 | } |
| 571 | } while (inputBuffer[0] != 'q'); |
| 572 | return 1; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | int |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 576 | main(int argc, char **argv) { |
| 577 | int optc; |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 578 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 579 | set_program_name(argv[0]); |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 580 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 581 | while ((optc = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) switch (optc) { |
| 582 | /* --help and --version exit immediately, per GNU coding standards. */ |
| 583 | case 'v': |
| 584 | version_etc( |
| 585 | stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *)NULL); |
| 586 | exit(EXIT_SUCCESS); |
| 587 | break; |
| 588 | case 'h': |
| 589 | print_help(); |
| 590 | exit(EXIT_SUCCESS); |
| 591 | break; |
| 592 | default: |
| 593 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); |
| 594 | exit(EXIT_FAILURE); |
| 595 | break; |
| 596 | } |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 597 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 598 | if (optind != argc - 1) { |
| 599 | /* Print error message and exit. */ |
| 600 | if (optind < argc - 1) |
| 601 | fprintf(stderr, "%s: extra operand: %s\n", program_name, argv[optind + 1]); |
| 602 | else |
| 603 | fprintf(stderr, "%s: no table specified\n", program_name); |
| 604 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); |
| 605 | exit(EXIT_FAILURE); |
| 606 | } |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 607 | |
Bert Frees | 47e6911 | 2019-08-22 13:09:36 +0200 | [diff] [blame] | 608 | _lou_getTable(argv[optind], argv[optind], &table, &displayTable); |
| 609 | if (!table) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 610 | lou_free(); |
| 611 | exit(EXIT_FAILURE); |
| 612 | } |
| 613 | getCommands(); |
| 614 | lou_free(); |
| 615 | exit(EXIT_SUCCESS); |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 616 | } |