Debian Codegraph @

tools/lou_checkhyphens.c

raw symbols SCIP
1 /* liblouis Braille Translation and Back-Translation Library
2
3 Based on the Linux screenreader BRLTTY, copyright (C) 1999-2006 by
4 The BRLTTY Team
5
6 Copyright (C) 2004, 2005, 2006, 2009
7 ViewPlus Technologies, Inc. www.viewplus.com and
8 JJB Software, Inc. www.jjb-software.com
9
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.
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
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/>.
22 */
23
24 #include <config.h>cxx . . $ `<file>/liblouis/config.h`/
25
26 #include <stdio.h>cxx . . $ `<file>/tools/gnulib/stdio.h`/
27 #include <string.h>cxx . . $ `<file>/gnulib/string.h`/
28 #include <stdlib.h>cxx . . $ `<file>/gnulib/stdlib.h`/
29 #include "liblouis.h"cxx . . $ `<file>/liblouis/liblouis.h`/
30 #include "internal.h"cxx . . $ `<file>/liblouis/internal.h`/
31 #include <getopt.h>
32 #include "progname.h"cxx . . $ `<file>/tools/gnulib/progname.h`/
33 #include "version-etc.h"cxx . . $ `<file>/tools/gnulib/version-etc.h`/
34
35 static const struct optioncxx . . $ option# longoptscxx . . $ longopts.[] = {
36 { "help", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, 'h' },
37 { "version", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, 'v' },
38 { NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, 0, NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!, 0 },
39 };
40
41 const char version_etc_copyrightcxx . . $ version_etc_copyright.[] =
42 "Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc.";
43
44 #define AUTHORScxx . . $ `tools/lou_checkhyphens.c:44:9`! "John J. Boyer"
45
46 static void
47 print_helpcxx . . $ print_help(49f6e7a06ebc5aa8).(void) {
48 printfcxx . . $ printf(581fddd72a8db8fc).("\
49 Usage: %s [OPTIONS]\n",
50 program_namecxx . . $ program_name.);
51
52 fputscxx . . $ fputs(874fa6a5e59ab9bd).("\
53 Check the accuracy of hyphenation in Braille translation for both\n\
54 translated and untranslated words.\n\n",
55 stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!);
56
57 fputscxx . . $ fputs(874fa6a5e59ab9bd).("\
58 -h, --help display this help and exit\n\
59 -v, --version display version information and exit\n",
60 stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!);
61
62 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
63 printfcxx . . $ printf(581fddd72a8db8fc).("Report bugs to %s.\n", PACKAGE_BUGREPORTcxx . . $ `liblouis/config.h:628:9`!);
64
65 #ifdef PACKAGE_PACKAGER_BUG_REPORTS
66 printf("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
67 #endif
68 #ifdef PACKAGE_URLcxx . . $ `liblouis/config.h:649:9`!
69 printfcxx . . $ printf(581fddd72a8db8fc).("%s home page: <%s>\n", PACKAGE_NAMEcxx . . $ `liblouis/config.h:631:9`!, PACKAGE_URLcxx . . $ `liblouis/config.h:649:9`!);
70 #endif
71 }
72
73 #define BUFSIZEcxx . . $ `tools/lou_checkhyphens.c:73:9`! 256
74
75 static char inputBuffercxx . . $ inputBuffer.[BUFSIZEcxx . . $ `tools/lou_checkhyphens.c:73:9`!];
76 static const TranslationTableHeadercxx . . $ TranslationTableHeader# *validTablecxx . . $ validTable. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
77 static unsigned int modecxx . . $ mode.;
78 static char tablecxx . . $ table.[BUFSIZEcxx . . $ `tools/lou_checkhyphens.c:73:9`!];
79
80 static int
81 getInputcxx . . $ getInput(b126dc7c1de90089).(void) {
82 int inputLength;
83 inputBuffercxx . . $ inputBuffer.[0] = 0;
84 if (!fgetscxx . . $ fgets(efb0aaba7ac866ae).(inputBuffercxx . . $ inputBuffer., sizeof(inputBuffercxx . . $ inputBuffer.), stdincxx . . $ `<external>/232824719582829767/stdio.h:157:9`!)) exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!);
85 inputLength = strlencxx . . $ strlen(751346f8406fd082).(inputBuffercxx . . $ inputBuffer.) - 1;
86 if (inputLength < 0) /* EOF on script */
87 exitcxx . . $ exit(3ca292c338df9bb3).(0);
88 inputBuffercxx . . $ inputBuffer.[inputLength] = 0;
89 return inputLength;
90 }
91
92 static void
93 paramLetterscxx . . $ paramLetters(49f6e7a06ebc5aa8).(void) {
94 printfcxx . . $ printf(581fddd72a8db8fc).("Press one of the letters in parentheses, then enter.\n");
95 printfcxx . . $ printf(581fddd72a8db8fc).("(t)able, tr(a)nslated, (u)ntranslated, (r)un, (h)elp, (q)uit\n");
96 }
97
98 static int
99 getCommandscxx . . $ getCommands(b126dc7c1de90089).(void) {
100 paramLetterscxx . . $ paramLetters(49f6e7a06ebc5aa8).();
101 do {
102 printfcxx . . $ printf(581fddd72a8db8fc).("Command: ");
103 getInputcxx . . $ getInput(b126dc7c1de90089).();
104 switch (inputBuffercxx . . $ inputBuffer.[0]) {
105 case 0:
106 break;
107 case 't':
108 do {
109 printfcxx . . $ printf(581fddd72a8db8fc).("Enter the name of a table or a list: ");
110 getInputcxx . . $ getInput(b126dc7c1de90089).();
111 strcpycxx . . $ strcpy(b7b3a83273496486).(tablecxx . . $ table., inputBuffercxx . . $ inputBuffer.);
112 validTablecxx . . $ validTable. = lou_getTablecxx . . $ lou_getTable(fb668cd7b4a39b42).(tablecxx . . $ table.);
113 if (validTablecxx . . $ validTable. != NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`! && validTablecxx . . $ validTable.->hyphenStatesArraycxx . . $ $anonymous_type_11b10485cb0df85e_11#hyphenStatesArray. == 0) {
114 printfcxx . . $ printf(581fddd72a8db8fc).("No hyphenation table.\n");
115 validTablecxx . . $ validTable. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
116 }
117 } while (validTablecxx . . $ validTable. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
118 break;
119 case 'a':
120 modecxx . . $ mode. = 1;
121 break;
122 case 'u':
123 modecxx . . $ mode. = 0;
124 break;
125 case 'r':
126 if (validTablecxx . . $ validTable. == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!) {
127 printfcxx . . $ printf(581fddd72a8db8fc).("You must enter a valid table name or list.\n");
128 inputBuffercxx . . $ inputBuffer.[0] = 0;
129 }
130 break;
131 case 'h':
132 printfcxx . . $ printf(581fddd72a8db8fc).("Commands: action\n");
133 printfcxx . . $ printf(581fddd72a8db8fc).("(t)able: Enter a table name or list\n");
134 printfcxx . . $ printf(581fddd72a8db8fc).("(r)un: run the hyphenation test loop\n");
135 printfcxx . . $ printf(581fddd72a8db8fc).("tr(a)nslated: translated input\n");
136 printfcxx . . $ printf(581fddd72a8db8fc).("(u)ntranslated: untranslated input\n");
137 printfcxx . . $ printf(581fddd72a8db8fc).("(h)elp: print this page\n");
138 printfcxx . . $ printf(581fddd72a8db8fc).("(q)uit: leave the program\n");
139 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
140 paramLetterscxx . . $ paramLetters(49f6e7a06ebc5aa8).();
141 break;
142 case 'q':
143 exitcxx . . $ exit(3ca292c338df9bb3).(0);
144 default:
145 printfcxx . . $ printf(581fddd72a8db8fc).("Bad choice.\n");
146 break;
147 }
148 } while (inputBuffercxx . . $ inputBuffer.[0] != 'r');
149 return 1;
150 }
151
152 int
153 maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) {
154 widecharcxx . . $ widechar# inbuf[BUFSIZEcxx . . $ `tools/lou_checkhyphens.c:73:9`!];
155 char hyphens[BUFSIZEcxx . . $ `tools/lou_checkhyphens.c:73:9`!];
156 int inlen;
157 int k;
158 int optc;
159
160 set_program_namecxx . . $ set_program_name(85c52e162fed56f9).(argv[0]);
161
162 while ((optc = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "hv", longoptscxx . . $ longopts., NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!)) != -1) switch (optc) {
163 /* --help and --version exit immediately, per GNU coding standards. */
164 case 'v':
165 version_etccxx . . $ version_etc(b5fd392babfe1cc5).(
166 stdoutcxx . . $ `<external>/232824719582829767/stdio.h:158:9`!, program_namecxx . . $ program_name., PACKAGE_NAMEcxx . . $ `liblouis/config.h:631:9`!, VERSIONcxx . . $ `liblouis/config.h:804:9`!, AUTHORScxx . . $ `tools/lou_checkhyphens.c:44:9`!, (char *)NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!);
167 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:97:9`!);
168 break;
169 case 'h':
170 print_helpcxx . . $ print_help(49f6e7a06ebc5aa8).();
171 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:97:9`!);
172 break;
173 default:
174 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Try `%s --help' for more information.\n", program_namecxx . . $ program_name.);
175 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!);
176 break;
177 }
178
179 if (optindcxx . . $ optind. < argc) {
180 /* Print error message and exit. */
181 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: extra operand: %s\n", program_namecxx . . $ program_name., argv[optindcxx . . $ optind.]);
182 fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "Try `%s --help' for more information.\n", program_namecxx . . $ program_name.);
183 exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!);
184 }
185
186 validTablecxx . . $ validTable. = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
187 modecxx . . $ mode. = 0;
188
189 while (1) {
190 getCommandscxx . . $ getCommands(b126dc7c1de90089).();
191 printfcxx . . $ printf(581fddd72a8db8fc).("Type something, press enter, and view the results.\n");
192 printfcxx . . $ printf(581fddd72a8db8fc).("A blank line returns to command entry.\n");
193 while (1) {
194 inlen = getInputcxx . . $ getInput(b126dc7c1de90089).();
195 if (inlen == 0) break;
196 for (k = 0; k < inlen; k++) inbuf[k] = inputBuffercxx . . $ inputBuffer.[k];
197 if (!lou_hyphenatecxx . . $ lou_hyphenate(c64cec7022e3b116).(tablecxx . . $ table., inbuf, inlen, hyphens, modecxx . . $ mode.)) {
198 printfcxx . . $ printf(581fddd72a8db8fc).("Hyphenation error\n");
199 continue;
200 }
201 printfcxx . . $ printf(581fddd72a8db8fc).("Hyphenation mask: %s\n", hyphens);
202 printfcxx . . $ printf(581fddd72a8db8fc).("Hyphenated word: ");
203 for (k = 0; k < inlen; k++) {
204 if (hyphens[k] == '1') printfcxx . . $ printf(581fddd72a8db8fc).("-");
205 printfcxx . . $ printf(581fddd72a8db8fc).("%c", inbuf[k]);
206 }
207 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
208 }
209 }
210 lou_freecxx . . $ lou_free(49f6e7a06ebc5aa8).();
211 return 0;
212 }