Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / liblouis / src / tools / lou_checkhyphens.c
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    Maintained by John J. Boyer john.boyer@jjb-software.com
24    */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <stdio.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include "liblouis.h"
34 #include "louis.h"
35 #include <getopt.h>
36 #include "progname.h"
37 #include "version-etc.h"
38
39 static const struct option longopts[] =
40 {
41   { "help", no_argument, NULL, 'h' },
42   { "version", no_argument, NULL, 'v' },
43   { NULL, 0, NULL, 0 }
44 };
45
46 const char version_etc_copyright[] =
47   "Copyright %s %d ViewPlus Technologies, Inc. and JJB Software, Inc.";
48
49 #define AUTHORS "John J. Boyer"
50
51 static void
52 print_help (void)
53 {
54   printf ("\
55 Usage: %s [OPTIONS]\n", program_name);
56   
57   fputs ("\
58 Check the accuracy of hyphenation in Braille translation for both\n\
59 translated and untranslated words.\n\n", stdout);
60
61   fputs ("\
62   -h, --help          display this help and exit\n\
63   -v, --version       display version information and exit\n", stdout);
64
65   printf ("\n");
66   printf ("Report bugs to %s.\n", PACKAGE_BUGREPORT);
67
68 #ifdef PACKAGE_PACKAGER_BUG_REPORTS
69   printf ("Report %s bugs to: %s\n", PACKAGE_PACKAGER, PACKAGE_PACKAGER_BUG_REPORTS);
70 #endif
71 #ifdef PACKAGE_URL
72   printf ("%s home page: <%s>\n", PACKAGE_NAME, PACKAGE_URL);
73 #endif
74 }
75
76 #define BUFSIZE 256
77
78 static char inputBuffer[BUFSIZE];
79 static const TranslationTableHeader *validTable = NULL;
80 static unsigned int mode;
81 static char table[BUFSIZE];
82
83 static int
84 getInput (void)
85 {
86   int inputLength;
87   inputBuffer[0] = 0;
88   fgets (inputBuffer, sizeof (inputBuffer), stdin);
89   inputLength = strlen (inputBuffer) - 1;
90   if (inputLength < 0)          /*EOF on script */
91     exit (0);
92   inputBuffer[inputLength] = 0;
93   return inputLength;
94 }
95
96 static void
97 paramLetters (void)
98 {
99   printf ("Press one of the letters in parentheses, then enter.\n");
100   printf ("(t)able, tr(a)nslated, (u)ntranslated, (r)un, (h)elp, (q)uit\n");
101 }
102
103 static int
104 getCommands (void)
105 {
106   paramLetters ();
107   do
108     {
109       printf ("Command: ");
110       getInput ();
111       switch (inputBuffer[0])
112         {
113         case 0:
114           break;
115         case 't':
116           do
117             {
118               printf ("Enter the name of a table or a list: ");
119               getInput ();
120               strcpy (table, inputBuffer);
121               validTable = lou_getTable (table);
122               if (validTable != NULL && validTable->hyphenStatesArray == 0)
123                 {
124                   printf ("No hyphenation table.\n");
125                   validTable = NULL;
126                 }
127             }
128           while (validTable == NULL);
129           break;
130         case 'a':
131           mode = 1;
132           break;
133         case 'u':
134           mode = 0;
135           break;
136         case 'r':
137           if (validTable == NULL)
138             {
139               printf ("You must enter a valid table name or list.\n");
140               inputBuffer[0] = 0;
141             }
142           break;
143         case 'h':
144           printf ("Commands: action\n");
145           printf ("(t)able: Enter a table name or list\n");
146           printf ("(r)un: run the hyphenation test loop\n");
147           printf ("tr(a)nslated: translated input\n");
148           printf ("(u)ntranslated: untranslated input\n");
149           printf ("(h)elp: print this page\n");
150           printf ("(q)uit: leave the program\n");
151           printf ("\n");
152           paramLetters ();
153           break;
154         case 'q':
155           exit (0);
156         default:
157           printf ("Bad choice.\n");
158           break;
159         }
160     }
161   while (inputBuffer[0] != 'r');
162   return 1;
163 }
164
165 int
166 main (int argc, char **argv)
167 {
168   widechar inbuf[BUFSIZE];
169   char hyphens[BUFSIZE];
170   int inlen;
171   int k;
172   int optc;
173
174   set_program_name (argv[0]);
175
176   while ((optc = getopt_long (argc, argv, "hv", longopts, NULL)) != -1)
177     switch (optc)
178       {
179       /* --help and --version exit immediately, per GNU coding standards.  */
180       case 'v':
181         version_etc (stdout, program_name, PACKAGE_NAME, VERSION, AUTHORS, (char *) NULL);
182         exit (EXIT_SUCCESS);
183         break;
184       case 'h':
185         print_help ();
186         exit (EXIT_SUCCESS);
187         break;
188       default:
189         fprintf (stderr, "Try `%s --help' for more information.\n",
190                  program_name);
191         exit (EXIT_FAILURE);
192         break;
193       }
194
195   if (optind < argc)
196     {
197       /* Print error message and exit.  */
198       fprintf (stderr, "%s: extra operand: %s\n",
199                program_name, argv[optind]);
200       fprintf (stderr, "Try `%s --help' for more information.\n",
201                program_name);
202       exit (EXIT_FAILURE);
203     }
204
205   validTable = NULL;
206   mode = 0;
207
208   while (1)
209     {
210       getCommands ();
211       printf ("Type something, press enter, and view the results.\n");
212       printf ("A blank line returns to command entry.\n");
213       while (1)
214         {
215           inlen = getInput ();
216           if (inlen == 0)
217             break;
218           for (k = 0; k < inlen; k++)
219             inbuf[k] = inputBuffer[k];
220           if (!lou_hyphenate (table, inbuf, inlen, hyphens, mode))
221             {
222               printf ("Hyphenation error\n");
223               continue;
224             }
225           printf ("Hyphenation mask: %s\n", hyphens);
226           printf ("Hyphenated word: ");
227           for (k = 0; k < inlen; k++)
228             {
229               if (hyphens[k] == '1')
230                 printf ("-");
231               printf ("%c", inbuf[k]);
232             }
233           printf ("\n");
234         }
235     }
236   lou_free ();
237   return 0;
238 }