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: "); |
Bert Frees | de85e65 | 2021-08-24 16:59:16 +0200 | [diff] [blame^] | 147 | printf("value=%s, ", print_chars(&thisChar->value, 1)); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 148 | } else |
Bert Frees | de85e65 | 2021-08-24 16:59:16 +0200 | [diff] [blame^] | 149 | printf("Dots: value=%s, ", _lou_showDots(&thisChar->value, 1)); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 150 | printf("attr=%s, ", _lou_showAttributes(thisChar->attributes)); |
| 151 | nextRule = thisChar->otherRules; |
| 152 | while (nextRule) { |
| 153 | thisRule = (TranslationTableRule *)&table->ruleArea[nextRule]; |
| 154 | if (nextRule == thisChar->definitionRule) printf("definition "); |
| 155 | printRule(thisRule, mode); |
| 156 | printf("\n"); |
| 157 | if (mode == 0) |
| 158 | nextRule = thisRule->charsnext; |
| 159 | else |
| 160 | nextRule = thisRule->dotsnext; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 161 | } |
Bert Frees | 1171cf8 | 2021-07-24 12:27:08 +0200 | [diff] [blame] | 162 | if (mode == 0 && thisChar->compRule) { |
| 163 | TranslationTableRule *compRule = |
| 164 | (TranslationTableRule *)&table->ruleArea[thisChar->compRule]; |
| 165 | printf("comp6 "); |
| 166 | printRule(compRule, 0); |
| 167 | printf("\n"); |
| 168 | } |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 169 | return 1; |
| 170 | } |
| 171 | |
| 172 | static int |
| 173 | show_characters(int startHash) { |
| 174 | int k; |
| 175 | TranslationTableCharacter *thisChar; |
| 176 | TranslationTableOffset nextChar; |
| 177 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 178 | if (startHash < 0) |
| 179 | k = 0; |
| 180 | else |
| 181 | k = startHash; |
| 182 | for (; k < HASHNUM; k++) |
| 183 | if (table->characters[k]) { |
| 184 | printf("Hash=%d\n", k); |
| 185 | nextChar = table->characters[k]; |
| 186 | while (nextChar) { |
| 187 | thisChar = (TranslationTableCharacter *)&table->ruleArea[nextChar]; |
| 188 | printCharacter(thisChar, 0); |
| 189 | printf("=> "); |
| 190 | getInput(); |
| 191 | if (*inputBuffer == 'h') break; |
| 192 | if (*inputBuffer == 'e') return 1; |
| 193 | nextChar = thisChar->next; |
| 194 | } |
| 195 | } |
| 196 | return 1; |
| 197 | } |
| 198 | |
| 199 | static int |
| 200 | show_dots(int startHash) { |
| 201 | int k; |
| 202 | TranslationTableCharacter *thisDots; |
| 203 | TranslationTableOffset nextDots; |
| 204 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 205 | if (startHash < 0) |
| 206 | k = 0; |
| 207 | else |
| 208 | k = startHash; |
| 209 | for (; k < HASHNUM; k++) |
| 210 | if (table->dots[k]) { |
| 211 | printf("Hash=%d\n", k); |
| 212 | nextDots = table->dots[k]; |
| 213 | while (nextDots) { |
| 214 | thisDots = (TranslationTableCharacter *)&table->ruleArea[nextDots]; |
| 215 | printCharacter(thisDots, 1); |
| 216 | printf("=> "); |
| 217 | getInput(); |
| 218 | if (*inputBuffer == 'h') break; |
| 219 | if (*inputBuffer == 'e') return 1; |
| 220 | nextDots = thisDots->next; |
| 221 | } |
| 222 | } |
| 223 | return 1; |
| 224 | } |
| 225 | |
| 226 | static int |
| 227 | show_forRules(int startHash) { |
| 228 | int k; |
| 229 | TranslationTableRule *thisRule; |
| 230 | TranslationTableOffset nextRule; |
| 231 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 232 | if (startHash < 0) |
| 233 | k = 0; |
| 234 | else |
| 235 | k = startHash; |
| 236 | for (; k < HASHNUM; k++) |
| 237 | if (table->forRules[k]) { |
| 238 | printf("Hash=%d\n", k); |
| 239 | nextRule = table->forRules[k]; |
| 240 | while (nextRule) { |
| 241 | thisRule = (TranslationTableRule *)&table->ruleArea[nextRule]; |
| 242 | printRule(thisRule, 0); |
| 243 | printf("=> "); |
| 244 | getInput(); |
| 245 | if (*inputBuffer == 'h') break; |
| 246 | if (*inputBuffer == 'e') return 1; |
| 247 | nextRule = thisRule->charsnext; |
| 248 | } |
| 249 | } |
| 250 | return 1; |
| 251 | } |
| 252 | |
| 253 | static int |
| 254 | show_backRules(int startHash) { |
| 255 | int k; |
| 256 | TranslationTableRule *thisRule; |
| 257 | TranslationTableOffset nextRule; |
| 258 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 259 | if (startHash < 0) |
| 260 | k = 0; |
| 261 | else |
| 262 | k = startHash; |
| 263 | for (; k < HASHNUM; k++) |
| 264 | if (table->backRules[k]) { |
| 265 | printf("Hash=%d\n", k); |
| 266 | nextRule = table->backRules[k]; |
| 267 | while (nextRule) { |
| 268 | thisRule = (TranslationTableRule *)&table->ruleArea[nextRule]; |
| 269 | printRule(thisRule, 1); |
| 270 | printf("=> "); |
| 271 | getInput(); |
| 272 | if (*inputBuffer == 'h') break; |
| 273 | if (*inputBuffer == 'e') return 1; |
| 274 | nextRule = thisRule->dotsnext; |
| 275 | } |
| 276 | } |
| 277 | return 1; |
| 278 | } |
| 279 | |
| 280 | static int |
Christian Egli | 0cfcd19 | 2018-05-08 11:22:46 +0200 | [diff] [blame] | 281 | print_brailleIndicator(TranslationTableOffset offset, const char *opcode) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 282 | TranslationTableRule *thisRule; |
| 283 | if (!offset) return 0; |
| 284 | thisRule = (TranslationTableRule *)&table->ruleArea[offset]; |
| 285 | printf("%s %s\n", opcode, _lou_showDots(&thisRule->charsdots[0], thisRule->dotslen)); |
| 286 | return 1; |
| 287 | } |
| 288 | |
| 289 | static int |
Christian Egli | 0cfcd19 | 2018-05-08 11:22:46 +0200 | [diff] [blame] | 290 | print_phraseLength(TranslationTableOffset offset, const char *opcode) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 291 | if (!offset) return 0; |
Christian Egli | da0d2eb | 2018-05-07 13:41:57 +0200 | [diff] [blame] | 292 | printf("%s %u\n", opcode, offset); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 293 | return 1; |
| 294 | } |
| 295 | |
| 296 | static int |
| 297 | show_brailleIndicators(void) { |
| 298 | char name[BUFSIZE]; |
Christian Egli | 0cfcd19 | 2018-05-08 11:22:46 +0200 | [diff] [blame] | 299 | const char *emphNames[] = { "begemphphrase %s", "endemphphrase %s before", |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 300 | "endemphphrase %s after", "begemphword %s", "endemphword %s", "emphletter %s", |
| 301 | "begemph %s", "endemph %s", NULL }; |
Christian Egli | d92cec1 | 2018-05-08 11:51:17 +0200 | [diff] [blame] | 302 | const char *capsNames[] = { "firstwordcaps", "lastwordcapsbefore", |
| 303 | "lastwordcapsafter", "begcaps", "endcaps", "capsletter", "capsword", |
| 304 | "capswordstop", NULL }; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 305 | |
| 306 | // FIXME: update to include all UEB opcodes. |
| 307 | |
| 308 | for (EmphCodeOffset offset = 0; capsNames[offset]; offset++) { |
| 309 | print_brailleIndicator(table->emphRules[capsRule][offset], capsNames[offset]); |
| 310 | } |
| 311 | print_phraseLength(table->emphRules[capsRule][lenPhraseOffset], "lencapsphrase"); |
| 312 | print_brailleIndicator(table->letterSign, "letsign"); |
| 313 | print_brailleIndicator(table->numberSign, "numsign"); |
| 314 | |
| 315 | for (int i = 0; table->emphClasses[i]; i++) { |
| 316 | for (EmphCodeOffset offset = 0; emphNames[offset]; offset++) { |
| 317 | snprintf(name, BUFSIZE, emphNames[offset], table->emphClasses[i]); |
| 318 | print_brailleIndicator(table->emphRules[emph1Rule][offset], name); |
| 319 | } |
| 320 | snprintf(name, BUFSIZE, "lenemphphrase %s", table->emphClasses[i]); |
| 321 | print_phraseLength(table->emphRules[emph1Rule][lenPhraseOffset], name); |
| 322 | } |
| 323 | print_brailleIndicator(table->begComp, "begcomp"); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 324 | print_brailleIndicator(table->endComp, "endcomp"); |
| 325 | return 1; |
| 326 | } |
| 327 | |
Christian Egli | 0cfcd19 | 2018-05-08 11:22:46 +0200 | [diff] [blame] | 328 | static const char * |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 329 | pickYN(int a) { |
| 330 | if (!a) return "no"; |
| 331 | return "yes"; |
| 332 | } |
| 333 | |
| 334 | static int |
| 335 | show_misc(void) { |
Christian Egli | da0d2eb | 2018-05-07 13:41:57 +0200 | [diff] [blame] | 336 | printf("Table size: %u\n", table->tableSize); |
| 337 | printf("Bytes used: %u\n", table->bytesUsed); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 338 | printf("Number of passes: %d\n", table->numPasses); |
| 339 | printf("'correct' opcodes: %s\n", pickYN(table->corrections)); |
| 340 | printf("'syllable' opcodes: %s\n", pickYN(table->syllables)); |
| 341 | printf("'capsnocont' opcode: %s\n", pickYN(table->capsNoCont)); |
| 342 | printf("Hyphenation table: %s\n", pickYN(table->hyphenStatesArray)); |
| 343 | printf("noletsignbefore %s\n", |
| 344 | print_chars(&table->noLetsignBefore[0], table->noLetsignBeforeCount)); |
| 345 | printf("noletsign %s\n", print_chars(&table->noLetsign[0], table->noLetsignCount)); |
| 346 | printf("noletsignafter %s\n", |
| 347 | print_chars(&table->noLetsignAfter[0], table->noLetsignAfterCount)); |
| 348 | return 1; |
| 349 | } |
| 350 | |
| 351 | static int |
| 352 | show_charMap(int startHash) { |
| 353 | int k; |
Bert Frees | b2b6742 | 2020-03-08 22:31:58 +0100 | [diff] [blame] | 354 | CharDotsMapping *thisChar; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 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++) |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 362 | if (displayTable->charToDots[k]) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 363 | printf("Hash=%d\n", k); |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 364 | nextChar = displayTable->charToDots[k]; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 365 | while (nextChar) { |
Bert Frees | b2b6742 | 2020-03-08 22:31:58 +0100 | [diff] [blame] | 366 | thisChar = (CharDotsMapping *)&displayTable->ruleArea[nextChar]; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 367 | printf("Char: %s ", print_chars(&thisChar->lookFor, 1)); |
| 368 | printf("dots=%s\n", _lou_showDots(&thisChar->found, 1)); |
| 369 | printf("=> "); |
| 370 | getInput(); |
| 371 | if (*inputBuffer == 'h') break; |
| 372 | if (*inputBuffer == 'e') return 1; |
| 373 | nextChar = thisChar->next; |
| 374 | } |
| 375 | } |
| 376 | return 1; |
| 377 | } |
| 378 | |
| 379 | static int |
| 380 | show_dotsMap(int startHash) { |
| 381 | int k; |
Bert Frees | b2b6742 | 2020-03-08 22:31:58 +0100 | [diff] [blame] | 382 | CharDotsMapping *thisDots; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 383 | TranslationTableOffset nextDots; |
| 384 | printf("Press enter for next or (e)xit, next-(h)ash, then enter\n"); |
| 385 | if (startHash < 0) |
| 386 | k = 0; |
| 387 | else |
| 388 | k = startHash; |
| 389 | for (; k < HASHNUM; k++) |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 390 | if (displayTable->dotsToChar[k]) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 391 | printf("Hash=%d\n", k); |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 392 | nextDots = displayTable->dotsToChar[k]; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 393 | while (nextDots) { |
Bert Frees | b2b6742 | 2020-03-08 22:31:58 +0100 | [diff] [blame] | 394 | thisDots = (CharDotsMapping *)&displayTable->ruleArea[nextDots]; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 395 | printf("Dots: %s ", _lou_showDots(&thisDots->lookFor, 1)); |
| 396 | printf("char=%s\n", print_chars(&thisDots->found, 1)); |
| 397 | printf("=> "); |
| 398 | getInput(); |
| 399 | if (*inputBuffer == 'h') break; |
| 400 | if (*inputBuffer == 'e') return 1; |
| 401 | nextDots = thisDots->next; |
| 402 | } |
| 403 | } |
| 404 | return 1; |
| 405 | } |
| 406 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 407 | static void |
| 408 | part_paramLetters(void) { |
| 409 | printf("show particular hash chains.\n"); |
| 410 | printf("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n"); |
| 411 | 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] | 412 | printf("(h)elp, e(x)it\n"); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | static void |
| 416 | particularHelp(void) { |
| 417 | part_paramLetters(); |
| 418 | } |
| 419 | |
| 420 | static int |
| 421 | particular(void) { |
| 422 | int startHash; |
| 423 | widechar parsed[BUFSIZE]; |
| 424 | part_paramLetters(); |
| 425 | do { |
| 426 | printf("particular: "); |
| 427 | getInput(); |
| 428 | switch (inputBuffer[0]) { |
| 429 | case 0: |
| 430 | break; |
| 431 | case 'h': |
| 432 | particularHelp(); |
| 433 | break; |
| 434 | case 'c': |
| 435 | printf("-> "); |
| 436 | getInput(); |
| 437 | if (!_lou_extParseChars(inputBuffer, parsed)) break; |
| 438 | startHash = _lou_charHash(*parsed); |
| 439 | if (table->characters[startHash] == 0) { |
| 440 | printf("Character not in table.\n"); |
| 441 | break; |
| 442 | } |
| 443 | show_characters(startHash); |
| 444 | break; |
| 445 | case 'd': |
| 446 | printf("-> "); |
| 447 | getInput(); |
| 448 | if (!_lou_extParseDots(inputBuffer, parsed)) break; |
| 449 | startHash = _lou_charHash(*parsed); |
| 450 | if (table->dots[startHash] == 0) { |
| 451 | printf("Dot pattern not in table.\n"); |
| 452 | break; |
| 453 | } |
| 454 | show_dots(startHash); |
| 455 | break; |
| 456 | case 'C': |
| 457 | printf("-> "); |
| 458 | getInput(); |
| 459 | if (!_lou_extParseChars(inputBuffer, parsed)) break; |
| 460 | startHash = _lou_charHash(*parsed); |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 461 | if (displayTable->charToDots[startHash] == 0) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 462 | printf("Character not in table.\n"); |
| 463 | break; |
| 464 | } |
| 465 | show_charMap(startHash); |
| 466 | break; |
| 467 | case 'D': |
| 468 | printf("-> "); |
| 469 | getInput(); |
| 470 | if (!_lou_extParseDots(inputBuffer, parsed)) break; |
| 471 | startHash = _lou_charHash(*parsed); |
Bert Frees | c322368 | 2019-07-09 23:18:43 +0200 | [diff] [blame] | 472 | if (displayTable->dotsToChar[startHash] == 0) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 473 | printf("Dot pattern not in table.\n"); |
| 474 | break; |
| 475 | } |
| 476 | show_dotsMap(startHash); |
| 477 | break; |
| 478 | case 'f': |
| 479 | printf("-> "); |
| 480 | getInput(); |
| 481 | if (!_lou_extParseChars(inputBuffer, parsed)) break; |
Bert Frees | d4b7a8e | 2019-06-04 13:56:07 +0200 | [diff] [blame] | 482 | startHash = _lou_stringHash(parsed, 0, NULL); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 483 | if (table->forRules[startHash] == 0) { |
| 484 | printf("Character string not in table.\n"); |
| 485 | break; |
| 486 | } |
| 487 | show_forRules(startHash); |
| 488 | break; |
| 489 | case 'b': |
| 490 | printf("-> "); |
| 491 | getInput(); |
| 492 | if (!_lou_extParseDots(inputBuffer, parsed)) break; |
Bert Frees | d4b7a8e | 2019-06-04 13:56:07 +0200 | [diff] [blame] | 493 | startHash = _lou_stringHash(parsed, 0, NULL); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 494 | if (table->backRules[startHash] == 0) { |
| 495 | printf("Dot pattern not in table.\n"); |
| 496 | break; |
| 497 | } |
| 498 | show_backRules(startHash); |
| 499 | break; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 500 | case 'x': |
| 501 | return 1; |
| 502 | default: |
| 503 | printf("Bad choice.\n"); |
| 504 | break; |
| 505 | } |
| 506 | } while (inputBuffer[0] != 'x'); |
| 507 | return 1; |
| 508 | } |
| 509 | |
| 510 | static void |
| 511 | paramLetters(void) { |
| 512 | printf("Press one of the letters in parentheses, then enter.\n"); |
| 513 | printf("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n"); |
| 514 | 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] | 515 | printf("show-(m)isc, show-braille(i)ndicators, show-(p)articulars\n"); |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 516 | printf("(h)elp, (q)uit\n"); |
| 517 | } |
| 518 | |
| 519 | static void |
| 520 | commandHelp(void) { |
| 521 | paramLetters(); |
| 522 | } |
| 523 | |
| 524 | static int |
| 525 | getCommands(void) { |
| 526 | paramLetters(); |
| 527 | do { |
| 528 | printf("Command: "); |
| 529 | getInput(); |
| 530 | switch (inputBuffer[0]) { |
| 531 | case 0: |
| 532 | break; |
| 533 | case 'h': |
| 534 | commandHelp(); |
| 535 | break; |
| 536 | case 'C': |
| 537 | show_charMap(-1); |
| 538 | break; |
| 539 | case 'D': |
| 540 | show_dotsMap(-1); |
| 541 | break; |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 542 | case 'c': |
| 543 | show_characters(-1); |
| 544 | break; |
| 545 | case 'd': |
| 546 | show_dots(-1); |
| 547 | break; |
| 548 | case 'f': |
| 549 | show_forRules(-1); |
| 550 | break; |
| 551 | case 'b': |
| 552 | show_backRules(-1); |
| 553 | break; |
| 554 | case 'i': |
| 555 | show_brailleIndicators(); |
| 556 | break; |
| 557 | case 'm': |
| 558 | show_misc(); |
| 559 | break; |
| 560 | case 'p': |
| 561 | particular(); |
| 562 | break; |
| 563 | case 'q': |
| 564 | return 1; |
| 565 | default: |
| 566 | printf("Bad choice.\n"); |
| 567 | break; |
| 568 | } |
| 569 | } while (inputBuffer[0] != 'q'); |
| 570 | return 1; |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 571 | } |
| 572 | |
| 573 | int |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 574 | main(int argc, char **argv) { |
| 575 | int optc; |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 576 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 577 | set_program_name(argv[0]); |
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 | while ((optc = getopt_long(argc, argv, "hv", longopts, NULL)) != -1) switch (optc) { |
| 580 | /* --help and --version exit immediately, per GNU coding standards. */ |
| 581 | case 'v': |
| 582 | version_etc( |
| 583 | stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *)NULL); |
| 584 | exit(EXIT_SUCCESS); |
| 585 | break; |
| 586 | case 'h': |
| 587 | print_help(); |
| 588 | exit(EXIT_SUCCESS); |
| 589 | break; |
| 590 | default: |
| 591 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); |
| 592 | exit(EXIT_FAILURE); |
| 593 | break; |
| 594 | } |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 595 | |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 596 | if (optind != argc - 1) { |
| 597 | /* Print error message and exit. */ |
| 598 | if (optind < argc - 1) |
| 599 | fprintf(stderr, "%s: extra operand: %s\n", program_name, argv[optind + 1]); |
| 600 | else |
| 601 | fprintf(stderr, "%s: no table specified\n", program_name); |
| 602 | fprintf(stderr, "Try `%s --help' for more information.\n", program_name); |
| 603 | exit(EXIT_FAILURE); |
| 604 | } |
Christian Egli | be14900 | 2009-10-09 09:09:07 +0000 | [diff] [blame] | 605 | |
Bert Frees | 47e6911 | 2019-08-22 13:09:36 +0200 | [diff] [blame] | 606 | _lou_getTable(argv[optind], argv[optind], &table, &displayTable); |
| 607 | if (!table) { |
Bert Frees | 92a8035 | 2017-09-30 23:01:02 +0200 | [diff] [blame] | 608 | lou_free(); |
| 609 | exit(EXIT_FAILURE); |
| 610 | } |
| 611 | getCommands(); |
| 612 | lou_free(); |
| 613 | exit(EXIT_SUCCESS); |
Eitan Isaacson | 109996e | 2008-12-20 14:52:53 +0000 | [diff] [blame] | 614 | } |