Debian Codegraph @

src/clients/say/options.c

raw
1 /*
2 * options.c - Parse and process possible command line options
3 *
4 * Copyright (C) 2003 Brailcom, o.p.s.
5 *
6 * This is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
9 * any later version.
10 *
11 * This software is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 *
19 * $Id: options.c,v 1.9 2006-07-11 16:12:26 hanke Exp $
20 */
21
22 /* NOTE: Be careful not to include options.h, we would
23 get repetitive initializations warnings */
24
25 #ifdef HAVE_CONFIG_H
26 #include <config.h>
27 #endif
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <assert.h>
33 #include "options.h"
34 #include <i18n.h>
35
36 signed int rate;
37 signed int pitch;
38 signed int pitch_range;
39 signed int volume;
40
41 int list_output_modules;
42 char *output_module;
43 char *sound_icon;
44 char *language;
45 char *voice_type;
46 char *punctuation_mode;
47 char *priority;
48 int pipe_mode;
49 int character;
50 int key;
51 SPDDataMode ssml_mode;
52 int spelling;
53 int wait_till_end;
54 int stop_previous;
55 int cancel_previous;
56 int list_synthesis_voices;
57 char *synthesis_voice;
58
59 char *application_name;
60 char *connection_name;
61
62 void options_print_help(char *argv[])
63 {
64 assert(argv);
65 assert(argv[0]);
66
67 printf(_("send text-to-speech output request to speech-dispatcher\n\n"));
68 printf(_("Usage: %s [options] \"some text\"\n\n"), argv[0]);
69
70 printf(_("Options:\n"));
71 printf(" -r, --rate ");
72 printf(_("Set the rate of the speech\n"));
73 printf(" ");
74 printf(_("(between %+d and %+d, default: %d)\n"), -100, 100, 0);
75
76 printf(" -p, --pitch ");
77 printf(_("Set the pitch of the speech\n"));
78 printf(" ");
79 printf(_("(between %+d and %+d, default: %d)\n"), -100, 100, 0);
80
81 printf(" -R, --pitch-range ");
82 printf(_("Set the pitch range of the speech\n"));
83 printf(" ");
84 printf(_("(between %+d and %+d, default: %d)\n"), -100, 100, 0);
85
86 printf(" -i, --volume ");
87 printf(_("Set the volume (intensity) of the speech\n"));
88 printf(" ");
89 printf(_("(between %+d and %+d, default: %d)\n"), -100, 100, 0);
90
91 printf(" -o, --output-module ");
92 printf(_("Set the output module\n"));
93
94 printf(" -O, --list-output-modules ");
95 printf(_("Get the list of output modules\n"));
96
97 printf(" -I, --sound-icon ");
98 printf(_("Play the sound icon\n"));
99
100 printf(" -l, --language ");
101 printf(_("Set the language (ISO code)\n"));
102
103 printf(" -t, --voice-type ");
104 printf(_("Set the preferred voice type\n"));
105 printf(" (male1, male2, male3, female1, female2\n"
106 " female3, child_male, child_female)\n");
107
108 printf(" -L, --list-synthesis-voices ");
109 printf(_("Get the list of synthesis voices\n"));
110
111 printf(" -y, --synthesis-voice ");
112 printf(_("Set the synthesis voice\n"));
113
114 printf(" -c, --character ");
115 printf(_("Speak the character\n"));
116
117 printf(" -k, --key ");
118 printf(_("Speak the key\n"));
119
120 printf(" -m, --punctuation-mode ");
121 printf(_("Set the punctuation mode\n"));
122 printf(" (none, some, most, all)\n");
123
124 printf(" -s, --spelling ");
125 printf(_("Spell the message\n"));
126
127 printf(" -x, --ssml ");
128 printf(_("Set SSML mode on (default: off)\n"));
129 printf("\n");
130
131 printf(" -e, --pipe-mode ");
132 printf(_("Read text to be spoken on stdin, write it on stdout unchanged, and the\n"
133 "corresponding speech through Speech Dispatcher.\n"));
134
135 printf(" -P, --priority ");
136 printf(_("Set priority of the message "));
137 printf("(important, message,\n"
138 "%stext, notification, progress;",
139 " ");
140 printf(_("default: %s)\n"), "text");
141
142 printf(" -N, --application-name ");
143 printf(_("Set the application name used to establish\n"
144 "%1$sthe connection to specified string value\n"),
145 " ");
146 printf(" ");
147 printf(_("(default: %s)\n"), "spd-say");
148
149 printf(" -n, --connection-name ");
150 printf(_("Set the connection name used to establish\n"
151 "%1$sthe connection to specified string value\n"),
152 " ");
153 printf(" ");
154 printf(_("(default: %s)\n"), "main");
155 printf("\n");
156
157 printf(" -w, --wait ");
158 printf(_("Wait till the message is spoken or discarded\n"));
159
160 printf(" -S, --stop ");
161 printf(_("Stop speaking the message being spoken\n"));
162
163 printf(" -C, --cancel ");
164 printf(_("Cancel all messages\n"));
165 printf("\n");
166
167 printf(" -v, --version ");
168 printf(_("Print version and copyright info\n"));
169
170 printf(" -h, --help ");
171 printf(_("Print this info\n"));
172 printf("\n");
173
174 printf(_("Please report bugs to %s\n\n"), PACKAGE_BUGREPORT);
175
176 }
177
178 void options_print_version()
179 {
180 printf("spd-say " VERSION "\n");
181 printf(_("Copyright (C) %d-%d Brailcom, o.p.s.\n"
182 "This is free software; you can redistribute it and/or modify it\n"
183 "under the terms of the GNU General Public License as published by\n"
184 "the Free Software Foundation; either version 2, or (at your option)\n"
185 "any later version. Please see COPYING for more details.\n\n"), 2002, 2012);
186 }
187
188 #define OPT_SET_INT(param) \
189 val = strtol(optarg, &tail_ptr, 10); \
190 if(tail_ptr != optarg){ \
191 param = val; \
192 }else{ \
193 printf(_("Syntax error or bad parameter!\n")); \
194 options_print_help(argv); \
195 exit(1); \
196 }
197
198 #define OPT_SET_STR(param) \
199 if(optarg != NULL){ \
200 if (param) \
201 free(param); \
202 param = (char*) strdup(optarg); \
203 }else{ \
204 printf(_("Missing argument!\n")); \
205 options_print_help(argv); \
206 exit(1); \
207 }
208
209 int options_parse(int argc, char *argv[])
210 {
211 char *tail_ptr;
212 int c_opt;
213 int option_index;
214 int val;
215
216 assert(argc > 0);
217 assert(argv);
218
219 while (1) {
220 option_index = 0;
221
222 c_opt = getopt_long(argc, argv, short_options, long_options,
223 &option_index);
224 if (c_opt == -1)
225 break;
226 switch (c_opt) {
227 case 'r':
228 OPT_SET_INT(rate);
229 break;
230 case 'p':
231 OPT_SET_INT(pitch);
232 break;
233 case 'R':
234 OPT_SET_INT(pitch_range);
235 break;
236 case 'i':
237 OPT_SET_INT(volume);
238 break;
239 case 'l':
240 OPT_SET_STR(language);
241 break;
242 case 'o':
243 OPT_SET_STR(output_module);
244 break;
245 case 'O':
246 list_output_modules = 1;
247 break;
248 case 'I':
249 OPT_SET_STR(sound_icon);
250 break;
251 case 't':
252 OPT_SET_STR(voice_type);
253 break;
254 case 'L':
255 list_synthesis_voices = 1;
256 break;
257 case 'y':
258 OPT_SET_STR(synthesis_voice);
259 break;
260 case 'c':
261 character = 1;
262 break;
263 case 'k':
264 key = 1;
265 break;
266 case 'm':
267 OPT_SET_STR(punctuation_mode);
268 break;
269 case 's':
270 spelling = 1;
271 break;
272 case 'e':
273 pipe_mode = 1;
274 break;
275 case 'P':
276 OPT_SET_STR(priority);
277 break;
278 case 'x':
279 ssml_mode = SPD_DATA_SSML;
280 break;
281 case 'N':
282 OPT_SET_STR(application_name);
283 break;
284 case 'n':
285 OPT_SET_STR(connection_name);
286 break;
287 case 'w':
288 wait_till_end = 1;
289 break;
290 case 'S':
291 stop_previous = 1;
292 break;
293 case 'C':
294 cancel_previous = 1;
295 break;
296 case 'v':
297 options_print_version();
298 exit(0);
299 break;
300 case 'h':
301 options_print_help(argv);
302 exit(0);
303 break;
304 default:
305 printf(_("Unrecognized option\n"));
306 options_print_help(argv);
307 exit(1);
308 }
309 }
310 return 0;
311 }
312
313 #undef SPD_OPTION_SET_INT