1 /* liblouis Braille Translation and Back-Translation Library
3 Based on the Linux screenreader BRLTTY, copyright (C) 1999-2006 by
6 Copyright (C) 2004, 2005, 2006, 2009
7 ViewPlus Technologies, Inc. www.viewplus.com and
8 JJB Software, Inc. www.jjb-software.com
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.
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.
20 You should have received a copy of the GNU General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 Maintained by John J. Boyer john.boyer@jjb-software.com
37 #include "version-etc.h"
39 #define BUFSIZE MAXSTRING - 4
41 static int forward_flag = 0;
42 static int backward_flag = 0;
44 static const struct option longopts[] =
46 { "help", no_argument, NULL, 'h' },
47 { "version", no_argument, NULL, 'v' },
48 { "forward", no_argument, NULL, 'f' },
49 { "backward", no_argument, NULL, 'b' },
53 const char version_etc_copyright[] =
54 "Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc.";
56 #define AUTHORS "John J. Boyer"
59 translate_input (int forward_translation, char *table_name)
61 char charbuf[BUFSIZE];
63 widechar inbuf[BUFSIZE];
64 widechar transbuf[BUFSIZE];
74 while ((ch = getchar ()) != '\n' && ch != EOF && k < BUFSIZE)
76 if (ch == EOF && k == 0)
79 inlen = extParseChars (charbuf, inbuf);
80 if (forward_translation)
81 result = lou_translateString (table_name, inbuf, &inlen,
82 transbuf, &translen, NULL, NULL, 0);
84 result = lou_backTranslateString (table_name, inbuf, &inlen,
85 transbuf, &translen, NULL, NULL, 0);
88 outputbuf = showString (transbuf, translen);
89 k = strlen (outputbuf) - 1;
91 printf ("%s\n", &outputbuf[1]);
100 Usage: %s [OPTIONS] TABLE[,TABLE,...]\n", program_name);
103 Translate whatever is on standard input and print it on standard\n\
104 output. It is intended for large-scale testing of the accuracy of\n\
105 Braille translation and back-translation.\n\n", stdout);
108 -h, --help display this help and exit\n\
109 -v, --version display version information and exit\n\
110 -f, --forward forward translation using the given table\n\
111 -b, --backward backward translation using the given table\n\
112 If neither -f nor -b are specified forward translation\n\
113 is assumed\n", stdout);
115 printf ("Report bugs to %s.\n", PACKAGE_BUGREPORT);
117 #ifdef PACKAGE_PACKAGER_BUG_REPORTS
118 printf ("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
121 printf ("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
126 main (int argc, char **argv)
130 set_program_name (argv[0]);
132 while ((optc = getopt_long (argc, argv, "hvfb", longopts, NULL)) != -1)
135 /* --help and --version exit immediately, per GNU coding standards. */
137 version_etc (stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *) NULL);
151 fprintf (stderr, "Try `%s --help' for more information.\n",
157 if (forward_flag && backward_flag)
159 fprintf (stderr, "%s: specify either -f or -b but not both\n",
161 fprintf (stderr, "Try `%s --help' for more information.\n",
166 if (optind != argc - 1)
168 /* Print error message and exit. */
169 if (optind < argc - 1)
170 fprintf (stderr, "%s: extra operand: %s\n",
171 program_name, argv[optind + 1]);
173 fprintf (stderr, "%s: no table specified\n",
175 fprintf (stderr, "Try `%s --help' for more information.\n",
180 /* assume forward translation by default */
181 translate_input (!backward_flag, argv[optind]);