blob: 02e413252cd555177e2ea18e8c21024f7ce95bce [file] [log] [blame]
Eitan Isaacson109996e2008-12-20 14:52:53 +00001/* liblouis Braille Translation and Back-Translation Library
2
3 Based on BRLTTY, copyright (C) 1999-2006 by
4 The BRLTTY Team
5
Christian Egli08d96a72009-10-08 08:49:13 +00006 Copyright (C) 2004, 2005, 2006, 2009
7 ViewPlus Technologies, Inc. www.viewplus.com and
Eitan Isaacson109996e2008-12-20 14:52:53 +00008 JJB Software, Inc. www.jjb-software.com
9
Christian Egli08d96a72009-10-08 08:49:13 +000010 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 Isaacson109996e2008-12-20 14:52:53 +000020 You should have received a copy of the GNU General Public License
Christian Egli08d96a72009-10-08 08:49:13 +000021 along with this program. If not, see <http://www.gnu.org/licenses/>.
Eitan Isaacson109996e2008-12-20 14:52:53 +000022
23 Maintained by John J. Boyer john.boyer@jjb-software.com
24 */
25
Christian Eglibe149002009-10-09 09:09:07 +000026#ifdef HAVE_CONFIG_H
27# include "config.h"
28#endif
29
Eitan Isaacson109996e2008-12-20 14:52:53 +000030#include <stdio.h>
31#include <string.h>
32#include <stdlib.h>
33#include "louis.h"
Christian Eglibe149002009-10-09 09:09:07 +000034#include <getopt.h>
35#include "progname.h"
36#include "version-etc.h"
37
38static const struct option longopts[] =
39{
40 { "help", no_argument, NULL, 'h' },
41 { "version", no_argument, NULL, 'v' },
42 { NULL, 0, NULL, 0 }
43};
44
45const char version_etc_copyright[] =
46 "Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc.";
47
48#define AUTHORS "John J. Boyer"
49
50static void
51print_help (void)
52{
53 printf ("\
Christian Eglibaefdb22012-12-19 09:48:54 +000054Usage: %s [OPTIONS] TABLE[,TABLE,...]\n", program_name);
Christian Eglibe149002009-10-09 09:09:07 +000055
56 fputs ("\
57Examine and debug Braille translation tables. This program allows you\n\
58to inspect liblouis translation tables and gather information about\n\
59them, such as forward and backward rules, characters and dot patterns,\n\
60specific opcodes, the size of a table, whether a hyphenation\n\
61table is used, how many passes the translation takes and much\n\
62more.\n\n", stdout);
63
64 fputs ("\
65 -h, --help display this help and exit\n\
66 -v, --version display version information and exit\n", stdout);
67
68 printf ("\n");
Christian Eglidc50af92012-09-27 13:10:51 +000069 printf ("Report bugs to %s.\n", PACKAGE_BUGREPORT);
70
71#ifdef PACKAGE_PACKAGER_BUG_REPORTS
72 printf ("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
73#endif
74#ifdef PACKAGE_URL
75 printf ("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
76#endif
Christian Eglibe149002009-10-09 09:09:07 +000077}
78
Eitan Isaacson109996e2008-12-20 14:52:53 +000079#define BUFSIZE 256
80
John Boyer16689ac2009-01-12 15:11:39 +000081static const TranslationTableHeader *table;
Eitan Isaacson109996e2008-12-20 14:52:53 +000082static char inputBuffer[BUFSIZE];
83
84static int
Eitan Isaacson109996e2008-12-20 14:52:53 +000085getInput (void)
86{
John Boyer16689ac2009-01-12 15:11:39 +000087 int inputLength;
88 inputBuffer[0] = 0;
Eitan Isaacson109996e2008-12-20 14:52:53 +000089 fgets (inputBuffer, sizeof (inputBuffer), stdin);
John Boyer16689ac2009-01-12 15:11:39 +000090 inputLength = strlen (inputBuffer) - 1;
91 if (inputLength < 0) /*EOF on script */
92 exit (0);
93 inputBuffer[inputLength] = 0;
94 return inputLength;
Eitan Isaacson109996e2008-12-20 14:52:53 +000095}
96
97static int
John Boyer16689ac2009-01-12 15:11:39 +000098printRule (TranslationTableRule * thisRule, int mode)
99{
100 printf ("Rule: ");
101 printf ("opcode=%s, ", findOpcodeName (thisRule->opcode));
102 if (thisRule->before)
103 printf ("before=%x, ", thisRule->before);
104 if (thisRule->after)
105 printf ("after=%x, ", thisRule->after);
106 switch (thisRule->opcode)
107 {
108 case CTO_Context:
109 case CTO_Correct:
110 case CTO_SwapCd:
111 case CTO_SwapDd:
112 case CTO_Pass2:
113 case CTO_Pass3:
114 case CTO_Pass4:
115 printf ("code=%s ", showString (thisRule->charsdots, thisRule->charslen
116 + thisRule->dotslen));
117 break;
118 default:
119 if (mode == 0)
120 {
121 printf ("chars=%s, ", showString (thisRule->charsdots,
122 thisRule->charslen));
123 printf ("dots=%s, ",
124 showDots (&thisRule->charsdots[thisRule->charslen],
125 thisRule->dotslen));
126 }
127 else
128 {
129 printf ("dots=%s, ",
130 showDots (&thisRule->charsdots[thisRule->charslen],
131 thisRule->dotslen));
132 printf ("chars=%s, ", showString (thisRule->charsdots,
133 thisRule->charslen));
134 }
135 break;
136 }
137 return 1;
138}
139
140static int
141printCharacter (TranslationTableCharacter * thisChar, int mode)
142{
143 TranslationTableRule *thisRule;
144 TranslationTableOffset nextRule;
145 if (mode == 0)
146 {
147 printf ("Char: ");
148 printf ("real=%s, ", showString (&thisChar->realchar, 1));
149 printf ("upper=%s, ", showString (&thisChar->uppercase, 1));
150 printf ("lower=%s, ", showString (&thisChar->lowercase, 1));
151 }
152 else
153 printf ("Dots: real=%s, ", showDots (&thisChar->realchar, 1));
154 printf ("attr=%s, ", showAttributes (thisChar->attributes));
155 nextRule = thisChar->otherRules;
156 while (nextRule)
157 {
158 thisRule = (TranslationTableRule *) & table->ruleArea[nextRule];
John Boyerc675d7a2009-01-15 14:32:20 +0000159 if (nextRule == thisChar->definitionRule)
John Boyer16689ac2009-01-12 15:11:39 +0000160 printf ("definition ");
161 printRule (thisRule, mode);
162 printf ("\n");
163 if (mode == 0)
164 nextRule = thisRule->charsnext;
165 else
166 nextRule = thisRule->dotsnext;
167 }
168 return 1;
169}
170
171static int
172show_characters (int startHash)
173{
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 {
185 printf ("Hash=%d\n", k);
186 nextChar = table->characters[k];
187 while (nextChar)
188 {
189 thisChar =
190 (TranslationTableCharacter *) & table->ruleArea[nextChar];
191 printCharacter (thisChar, 0);
192 printf ("=> ");
193 getInput ();
194 if (*inputBuffer == 'h')
195 break;
196 if (*inputBuffer == 'e')
197 return 1;
198 nextChar = thisChar->next;
199 }
200 }
201 return 1;
202}
203
204static int
205show_dots (int startHash)
206{
207 int k;
208 TranslationTableCharacter *thisDots;
209 TranslationTableOffset nextDots;
210 printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
211 if (startHash < 0)
212 k = 0;
213 else
214 k = startHash;
215 for (; k < HASHNUM; k++)
216 if (table->dots[k])
217 {
218 printf ("Hash=%d\n", k);
219 nextDots = table->dots[k];
220 while (nextDots)
221 {
222 thisDots =
223 (TranslationTableCharacter *) & table->ruleArea[nextDots];
224 printCharacter (thisDots, 1);
225 printf ("=> ");
226 getInput ();
227 if (*inputBuffer == 'h')
228 break;
229 if (*inputBuffer == 'e')
230 return 1;
231 nextDots = thisDots->next;
232 }
233 }
234 return 1;
235}
236
237static int
238show_forRules (int startHash)
239{
240 int k;
241 TranslationTableRule *thisRule;
242 TranslationTableOffset nextRule;
243 printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
244 if (startHash < 0)
245 k = 0;
246 else
247 k = startHash;
248 for (; k < HASHNUM; k++)
249 if (table->forRules[k])
250 {
251 printf ("Hash=%d\n", k);
252 nextRule = table->forRules[k];
253 while (nextRule)
254 {
255 thisRule = (TranslationTableRule *) & table->ruleArea[nextRule];
256 printRule (thisRule, 0);
257 printf ("=> ");
258 getInput ();
259 if (*inputBuffer == 'h')
260 break;
261 if (*inputBuffer == 'e')
262 return 1;
263 nextRule = thisRule->charsnext;
264 }
265 }
266 return 1;
267}
268
269static int
270show_backRules (int startHash)
271{
272 int k;
273 TranslationTableRule *thisRule;
274 TranslationTableOffset nextRule;
275 printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
276 if (startHash < 0)
277 k = 0;
278 else
279 k = startHash;
280 for (; k < HASHNUM; k++)
281 if (table->backRules[k])
282 {
283 printf ("Hash=%d\n", k);
284 nextRule = table->backRules[k];
285 while (nextRule)
286 {
287 thisRule = (TranslationTableRule *) & table->ruleArea[nextRule];
288 printRule (thisRule, 1);
289 printf ("=> ");
290 getInput ();
291 if (*inputBuffer == 'h')
292 break;
293 if (*inputBuffer == 'e')
294 return 1;
295 nextRule = thisRule->dotsnext;
296 }
297 }
298 return 1;
299}
300
301static int
302print_brailleIndicator (TranslationTableOffset offset, char *opcode)
303{
304 TranslationTableRule *thisRule;
305 if (!offset)
306 return 0;
307 thisRule = (TranslationTableRule *) & table->ruleArea[offset];
308 printf ("%s %s\n", opcode,
309 showDots (&thisRule->charsdots[0], thisRule->dotslen));
310 return 1;
311}
312
313static int
314print_phraseLength (TranslationTableOffset offset, char *opcode)
315{
316 if (!offset)
317 return 0;
318 printf ("%s %d\n", opcode, offset);
Christian Eglifbfea8b2009-08-11 11:24:40 +0000319 return 1;
John Boyer16689ac2009-01-12 15:11:39 +0000320}
321
322static int
323show_brailleIndicators (void)
324{
325 print_brailleIndicator (table->capitalSign, "capsign");
326 print_brailleIndicator (table->beginCapitalSign, "begcaps");
327 print_phraseLength (table->lenBeginCaps, "lenbegcaps");
328 print_brailleIndicator (table->endCapitalSign, "endcaps");
329 print_brailleIndicator (table->firstWordCaps, "firstwordcaps");
330 print_brailleIndicator (table->lastWordCapsAfter, "lastwordaftercaps");
331 print_phraseLength (table->lenCapsPhrase, "lencapsphrase");
332 print_brailleIndicator (table->letterSign, "letsign");
333 print_brailleIndicator (table->numberSign, "numsign");
334 print_brailleIndicator (table->firstWordItal, "firstwordital");
335 print_brailleIndicator (table->lastWordItalBefore, "lastworditalbefore");
336 print_brailleIndicator (table->lastWordItalAfter, "lastworditalafter");
337 print_brailleIndicator (table->firstLetterItal, "firstletterital");
338 print_brailleIndicator (table->lastLetterItal, "lastletterital");
339 print_brailleIndicator (table->singleLetterItal, "singleletterital");
340 print_brailleIndicator (table->italWord, "italword");
341 print_phraseLength (table->lenItalPhrase, "lenitalphrase");
342 print_brailleIndicator (table->firstWordBold, "firstwordbold");
343 print_brailleIndicator (table->lastWordBoldBefore, "lastwordboldbefore");
344 print_brailleIndicator (table->lastWordBoldAfter, "lastwordboldafter");
345 print_brailleIndicator (table->firstLetterBold, "firstletterbold");
346 print_brailleIndicator (table->lastLetterBold, "lastletterbold");
347 print_brailleIndicator (table->singleLetterBold, "singleletterbold");
348 print_brailleIndicator (table->boldWord, "boldword");
349 print_phraseLength (table->lenBoldPhrase, "lenboldphrase");
350 print_brailleIndicator (table->firstWordUnder, "firstwordunder");
351 print_brailleIndicator (table->lastWordUnderBefore, "lastwordunderbefore");
352 print_brailleIndicator (table->lastWordUnderAfter, "lastwordunderafter");
353 print_brailleIndicator (table->firstLetterUnder, "firstletterunder");
354 print_brailleIndicator (table->lastLetterUnder, "lastletterunder");
355 print_brailleIndicator (table->singleLetterUnder, "singleletterunder");
356 print_brailleIndicator (table->underWord, "underword");
357 print_phraseLength (table->lenUnderPhrase, "lenunderphrase");
358 print_brailleIndicator (table->begComp, "begcomp");
359 print_brailleIndicator (table->compBegEmph1, "compbegemph1");
360 print_brailleIndicator (table->compEndEmph1, "compendemph1");
361 print_brailleIndicator (table->compBegEmph2, "compbegemph2");
362 print_brailleIndicator (table->compEndEmph2, "compendemph2");
363 print_brailleIndicator (table->compBegEmph3, "compbegemph3");
364 print_brailleIndicator (table->compEndEmph3, "compendemph3");
365 print_brailleIndicator (table->compCapSign, "compcapsign");
366 print_brailleIndicator (table->compBegCaps, "compbegcaps");
367 print_brailleIndicator (table->compEndCaps, "compendcaps");
368 print_brailleIndicator (table->endComp, "endcomp");
369 return 1;
370}
371
372static char *
373pickYN (int a)
374{
375 if (!a)
376 return "no";
377 return "yes";
378}
379
380static int
381show_misc (void)
382{
383 printf ("Table size: %d\n", table->tableSize);
384 printf ("Bytes used: %d\n", table->bytesUsed);
385 printf ("Number of passes: %d\n", table->numPasses);
Christian Egli5e8c3892009-01-15 16:30:59 +0000386 printf ("'correct' opcodes: %s\n", pickYN (table->corrections));
John Boyer16689ac2009-01-12 15:11:39 +0000387 printf ("'syllable' opcodes: %s\n", pickYN (table->syllables));
388 printf ("'capsnocont' opcode: %s\n", pickYN (table->capsNoCont));
389 printf ("Hyphenation table: %s\n", pickYN (table->hyphenStatesArray));
390 printf ("noletsignbefore %s\n", showString (&table->noLetsignBefore[0],
391 table->noLetsignBeforeCount));
392 printf ("noletsign %s\n", showString (&table->noLetsign[0],
393 table->noLetsignCount));
394 printf ("noletsignafter %s\n", showString (&table->noLetsignAfter[0],
395 table->noLetsignAfterCount));
Christian Eglifbfea8b2009-08-11 11:24:40 +0000396 return 1;
John Boyer16689ac2009-01-12 15:11:39 +0000397}
398
399static int
400show_charMap (int startHash)
401{
402 int k;
403 CharOrDots *thisChar;
404 TranslationTableOffset nextChar;
405 printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
406 if (startHash < 0)
407 k = 0;
408 else
409 k = startHash;
410 for (; k < HASHNUM; k++)
411 if (table->charToDots[k])
412 {
413 printf ("Hash=%d\n", k);
414 nextChar = table->charToDots[k];
415 while (nextChar)
416 {
417 thisChar = (CharOrDots *) & table->ruleArea[nextChar];
418 printf ("Char: %s ", showString (&thisChar->lookFor, 1));
419 printf ("dots=%s\n", showDots (&thisChar->found, 1));
420 printf ("=> ");
421 getInput ();
422 if (*inputBuffer == 'h')
423 break;
424 if (*inputBuffer == 'e')
425 return 1;
426 nextChar = thisChar->next;
427 }
428 }
429 return 1;
430}
431
432static int
433show_dotsMap (int startHash)
434{
435 int k;
436 CharOrDots *thisDots;
437 TranslationTableOffset nextDots;
438 printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
439 if (startHash < 0)
440 k = 0;
441 else
442 k = startHash;
443 for (; k < HASHNUM; k++)
444 if (table->dotsToChar[k])
445 {
446 printf ("Hash=%d\n", k);
447 nextDots = table->dotsToChar[k];
448 while (nextDots)
449 {
450 thisDots = (CharOrDots *) & table->ruleArea[nextDots];
451 printf ("Dots: %s ", showDots (&thisDots->lookFor, 1));
452 printf ("char=%s\n", showString (&thisDots->found, 1));
453 printf ("=> ");
454 getInput ();
455 if (*inputBuffer == 'h')
456 break;
457 if (*inputBuffer == 'e')
458 return 1;
459 nextDots = thisDots->next;
460 }
461 }
462 return 1;
463}
464
465static int
466show_compDots (int startChar)
467{
468 widechar k;
469 printf ("Press enter for next or (e)xit, next-(h)ash, then enter\n");
470 if (startChar < 0)
471 k = 0;
472 else
473 k = startChar;
474 for (; k < 256; k++)
475 if (table->compdotsPattern[k])
476 {
477 TranslationTableRule *thisRule = (TranslationTableRule *)
478 & table->ruleArea[table->compdotsPattern[k]];
479 printf ("Char: %s ", showString (&k, 1));
480 printf ("dots=%s\n",
481 showDots (&thisRule->charsdots[1], thisRule->dotslen));
482 printf ("=> ");
483 getInput ();
484 if (*inputBuffer == 'e')
485 return 1;
486 }
487 return 1;
488}
489
490static void
491part_paramLetters ()
492{
493 printf ("show particular hash chains.\n");
494 printf
495 ("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n");
496 printf ("show-(d)ot-patterns, show-(C)har-to-dots, show-(D)ots-tochar\n");
497 printf ("(z)-compdots, (h)elp, e(x)it\n");
498}
499
500static void
501particularHelp (void)
502{
503 part_paramLetters ();
504}
505
506static int
507particular (void)
508{
509 int startHash;
510 widechar parsed[BUFSIZE];
511 part_paramLetters ();
512 do
513 {
514 printf ("particular: ");
515 getInput ();
516 switch (inputBuffer[0])
517 {
518 case 0:
519 break;
520 case 'h':
521 particularHelp ();
522 break;
523 case 'c':
524 printf ("-> ");
525 getInput ();
526 if (!extParseChars (inputBuffer, parsed))
527 break;
528 startHash = charHash (*parsed);
529 if (table->characters[startHash] == 0)
530 {
531 printf ("Character not in table.\n");
532 break;
533 }
534 show_characters (startHash);
535 break;
536 case 'd':
537 printf ("-> ");
538 getInput ();
539 if (!extParseDots (inputBuffer, parsed))
540 break;
541 startHash = charHash (*parsed);
542 if (table->dots[startHash] == 0)
543 {
544 printf ("Dot pattern not in table.\n");
545 break;
546 }
547 show_dots (startHash);
548 break;
549 case 'C':
550 printf ("-> ");
551 getInput ();
552 if (!extParseChars (inputBuffer, parsed))
553 break;
554 startHash = charHash (*parsed);
555 if (table->charToDots[startHash] == 0)
556 {
557 printf ("Character not in table.\n");
558 break;
559 }
560 show_charMap (startHash);
561 break;
562 case 'D':
563 printf ("-> ");
564 getInput ();
565 if (!extParseDots (inputBuffer, parsed))
566 break;
567 startHash = charHash (*parsed);
568 if (table->dotsToChar[startHash] == 0)
569 {
570 printf ("Dot pattern not in table.\n");
571 break;
572 }
573 show_dotsMap (startHash);
574 break;
575 case 'f':
576 printf ("-> ");
577 getInput ();
578 if (!extParseChars (inputBuffer, parsed))
579 break;
580 startHash = stringHash (parsed);
581 if (table->forRules[startHash] == 0)
582 {
583 printf ("Character string not in table.\n");
584 break;
585 }
586 show_forRules (startHash);
587 break;
588 case 'b':
589 printf ("-> ");
590 getInput ();
591 if (!extParseDots (inputBuffer, parsed))
592 break;
593 startHash = stringHash (parsed);
594 if (table->backRules[startHash] == 0)
595 {
596 printf ("Dot pattern not in table.\n");
597 break;
598 }
599 show_backRules (startHash);
600 break;
601 case 'z':
602 printf ("-> ");
603 getInput ();
604 if (!extParseChars (inputBuffer, parsed))
605 break;
606 startHash = charHash (*parsed);
607 if (*parsed > 255 || table->compdotsPattern[startHash] == 0)
608 {
609 printf ("Character not in table.\n");
610 break;
611 }
612 show_compDots (startHash);
613 break;
614 case 'x':
615 return 1;
616 default:
617 printf ("Bad choice.\n");
618 break;
619 }
620 }
621 while (inputBuffer[0] != 'x');
622 return 1;
623}
624
Eitan Isaacson109996e2008-12-20 14:52:53 +0000625static void
626paramLetters (void)
627{
John Boyer16689ac2009-01-12 15:11:39 +0000628 printf ("Press one of the letters in parentheses, then enter.\n");
629 printf
630 ("show-(f)orward-rules, show-(b)ackward-rules, show-(c)haracters, \n");
631 printf ("show-(d)ot-patterns, show-(C)har-to-dots, show-(D)ots-tochar\n");
632 printf ("show-(m)isc, show-(z)-compdots\n");
633 printf ("show-(p)articulars, (h)elp, (q)uit\n");
634}
635
636static void
637commandHelp (void)
638{
639 paramLetters ();
Eitan Isaacson109996e2008-12-20 14:52:53 +0000640}
641
642static int
643getCommands (void)
644{
645 paramLetters ();
646 do
647 {
648 printf ("Command: ");
649 getInput ();
650 switch (inputBuffer[0])
651 {
652 case 0:
653 break;
John Boyer16689ac2009-01-12 15:11:39 +0000654 case 'h':
655 commandHelp ();
656 break;
657 case 'C':
658 show_charMap (-1);
659 break;
660 case 'D':
661 show_dotsMap (-1);
662 break;
663 case 'z':
664 show_compDots (-1);
665 break;
666 case 'c':
667 show_characters (-1);
668 break;
669 case 'd':
670 show_dots (-1);
671 break;
672 case 'f':
673 show_forRules (-1);
674 break;
675 case 'b':
676 show_backRules (-1);
677 break;
678 case 'i':
679 show_brailleIndicators ();
680 break;
681 case 'm':
682 show_misc ();
683 break;
684 case 'p':
685 particular ();
686 break;
687 case 'q':
688 return 1;
Eitan Isaacson109996e2008-12-20 14:52:53 +0000689 default:
690 printf ("Bad choice.\n");
691 break;
692 }
693 }
John Boyer16689ac2009-01-12 15:11:39 +0000694 while (inputBuffer[0] != 'q');
Eitan Isaacson109996e2008-12-20 14:52:53 +0000695 return 1;
696}
697
698int
699main (int argc, char **argv)
700{
Christian Eglibe149002009-10-09 09:09:07 +0000701 int optc;
702
703 set_program_name (argv[0]);
704
705 while ((optc = getopt_long (argc, argv, "hv", longopts, NULL)) != -1)
706 switch (optc)
707 {
708 /* --help and --version exit immediately, per GNU coding standards. */
709 case 'v':
710 version_etc (stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *) NULL);
711 exit (EXIT_SUCCESS);
712 break;
713 case 'h':
714 print_help ();
715 exit (EXIT_SUCCESS);
716 break;
717 default:
718 fprintf (stderr, "Try `%s --help' for more information.\n",
719 program_name);
720 exit (EXIT_FAILURE);
721 break;
722 }
723
724 if (optind != argc - 1)
Eitan Isaacson109996e2008-12-20 14:52:53 +0000725 {
Christian Eglibe149002009-10-09 09:09:07 +0000726 /* Print error message and exit. */
727 if (optind < argc - 1)
728 fprintf (stderr, "%s: extra operand: %s\n",
729 program_name, argv[optind + 1]);
730 else
731 fprintf (stderr, "%s: no table specified\n",
732 program_name);
733 fprintf (stderr, "Try `%s --help' for more information.\n",
734 program_name);
735 exit (EXIT_FAILURE);
Eitan Isaacson109996e2008-12-20 14:52:53 +0000736 }
Christian Eglibe149002009-10-09 09:09:07 +0000737
738 if (!(table = lou_getTable (argv[optind])))
John Boyer16689ac2009-01-12 15:11:39 +0000739 {
740 lou_free ();
Christian Eglibe149002009-10-09 09:09:07 +0000741 exit (EXIT_FAILURE);
John Boyer16689ac2009-01-12 15:11:39 +0000742 }
743 getCommands ();
Eitan Isaacson109996e2008-12-20 14:52:53 +0000744 lou_free ();
Christian Eglibe149002009-10-09 09:09:07 +0000745 exit (EXIT_SUCCESS);
Eitan Isaacson109996e2008-12-20 14:52:53 +0000746}