1
/* liblouis Braille Translation and Back-Translation
1
/* liblouis Braille Translation and Back-Translation Library
4
3
Based on the Linux screenreader BRLTTY, copyright (C) 1999-2006 by
7
Copyright (C) 2004, 2005, 2006
8
ViewPlus Technologies, Inc. www.viewplus.com
6
Copyright (C) 2004, 2005, 2006, 2009
7
ViewPlus Technologies, Inc. www.viewplus.com and
10
8
JJB Software, Inc. www.jjb-software.com
13
This file is free software; you can redistribute it and/or modify it
14
under the terms of the Lesser or Library GNU General Public License
16
Free Software Foundation; either version 3, or (at your option) any
19
This file is distributed in the hope that it will be useful, but
20
WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
Library GNU General Public License for more details.
24
You should have received a copy of the Library GNU General Public
25
License along with this program; see the file COPYING. If not, write to
26
the Free Software Foundation, 51 Franklin Street, Fifth Floor,
27
Boston, MA 02110-1301, USA.
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/>.
29
23
Maintained by John J. Boyer john.boyer@jjb-software.com
33
31
#include <string.h>
34
32
#include <stdlib.h>
35
34
#include "liblouis.h"
36
#include "version-etc.h"
36
38
#define BUFSIZE 2048
39
main (int argc, char **argv)
40
static int forward_flag = 0;
41
static int backward_flag = 0;
43
static const struct option longopts[] =
45
{ "help", no_argument, NULL, 'h' },
46
{ "version", no_argument, NULL, 'v' },
47
{ "forward", no_argument, NULL, 'f' },
48
{ "backward", no_argument, NULL, 'b' },
52
const char version_etc_copyright[] =
53
"Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc.";
55
#define AUTHORS "John J. Boyer"
58
translate_input (int forward_translation, char *table_name)
41
60
widechar inbuf[BUFSIZE];
42
61
widechar transbuf[BUFSIZE];
43
widechar outbuf[BUFSIZE];
51
fprintf (stderr, "Usage: translate -f|-b tablename\n");
54
if (!(argv[1][0] == '-' && (argv[1][1] == 'f' || argv[1][1] == 'b')))
56
fprintf (stderr, "The first argument must be -f or -b.\n");
59
if (argv[1][1] == 'f')
64
while ((ch = getchar ()) != '\n' && inlen < BUFSIZE)
69
if (!lou_translateString (argv[2], inbuf, &inlen,
70
transbuf, &translen, NULL, NULL, 0))
72
transbuf[translen] = 0;
73
for (k = 0; k < translen; k++)
74
printf ("%c", transbuf[k]);
82
while ((ch = getchar ()) != '\n' && translen < BUFSIZE)
83
transbuf[translen++] = ch;
86
transbuf[translen] = 0;
87
if (!lou_backTranslateString (argv[2], transbuf, &translen,
88
outbuf, &outlen, NULL, NULL, 0))
90
for (k = 0; k < outlen; k++)
91
printf ("%c", outbuf[k]);
72
while ((ch = getchar ()) != '\n' && inlen < BUFSIZE)
77
if (forward_translation)
79
result = lou_translateString (table_name, inbuf, &inlen,
80
transbuf, &translen, NULL, NULL, 0);
83
result = lou_backTranslateString (table_name, inbuf, &inlen,
84
transbuf, &translen, NULL, NULL, 0);
87
transbuf[translen] = 0;
88
for (k = 0; k < translen; k++)
89
printf ("%c", transbuf[k]);
99
Usage: %s [OPTION] TABLE\n", program_name);
102
Translate whatever is on standard input and print it on standard\n\
103
output. It is intended for large-scale testing of the accuracy of\n\
104
Braille translation and back-translation.\n\n", stdout);
107
-h, --help display this help and exit\n\
108
-v, --version display version information and exit\n\
109
-f, --forward forward translation using the given table\n\
110
-b, --backward backward translation using the given table\n\
111
If neither -f nor -b are specified forward translation\n\
112
is assumed\n", stdout);
115
Report bugs to <%s>.\n", PACKAGE_BUGREPORT);
119
main (int argc, char **argv)
123
set_program_name (argv[0]);
125
while ((optc = getopt_long (argc, argv, "hvfb", longopts, NULL)) != -1)
128
/* --help and --version exit immediately, per GNU coding standards. */
130
version_etc (stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *) NULL);
144
fprintf (stderr, "Try `%s --help' for more information.\n",
150
if (forward_flag && backward_flag)
152
fprintf (stderr, "%s: specify either -f or -b but not both\n",
154
fprintf (stderr, "Try `%s --help' for more information.\n",
159
if (optind != argc - 1)
161
/* Print error message and exit. */
162
if (optind < argc - 1)
163
fprintf (stderr, "%s: extra operand: %s\n",
164
program_name, argv[optind + 1]);
166
fprintf (stderr, "%s: no table specified\n",
168
fprintf (stderr, "Try `%s --help' for more information.\n",
173
/* assume forward translation by default */
174
translate_input (!backward_flag, argv[optind]);