-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.c
174 lines (162 loc) · 5.64 KB
/
options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* options.c - Parse and process possible command line options
*
* Copyright (C) 2003,2004, 2006, 2007 Brailcom, o.p.s.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this package; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
* $Id: options.c,v 1.10 2008-05-05 09:15:28 hanke Exp $
*/
#include <assert.h>
#include "options.h"
#define SPD_OPTION_SET_INT(param) \
val = strtol(optarg, &tail_ptr, 10); \
if(tail_ptr != optarg){ \
param = val; \
}
void
options_print_help(char *argv[])
{
assert(argv);
assert(argv[0]);
printf("Usage: %s [-{d|s}] [-l {1|2|3|4|5}] [-L=logfile] [-c=encoding] | [-v] | [-h]\n", argv[0]);
printf("SpeechD-Up -- Interface between Speech Dispatcher and SpeakUp (GNU GPL)\n\n");
printf("-d, --run-daemon - Run as a daemon\n"
"-s, --run-single - Run as single application\n"
"-l, --log-level - Set log level (1..5)\n"
"-L, --log-file - Set log file to path\n"
"-D, --device - Specify the device name of Speakup software synthesis\n"
"-i, --language - Set default language for speech output\n"
"-c, --coding - Specify the default encoding to use\n"
"-t, --dont-init-tables - Don't rewrite /proc tables for optimal software synthesis\n"
"-p, --probe - Initialize everything and try to say some message\n"
" but don't connect to SpeakUp. For testing purposes.\n"
"-v, --version - Report version of this program\n"
"-h, --help - Print this info\n\n"
"Copyright (C) 2003,2005 Brailcom, o.p.s.\n"
"This is free software; you can redistribute it and/or modify it\n"
"under the terms of the GNU General Public License as published by\n"
"the Free Software Foundation; either version 2, or (at your option)\n"
"any later version. Please see COPYING for more details.\n\n"
"Please report bugs to <[email protected]>\n\n");
}
void
options_print_version(void)
{
printf("%s %s\n", PACKAGE, VERSION);
printf("Copyright (C) 2002-2003 Brailcom, o.p.s.\n"
"GNU Emacs comes with ABSOLUTELY NO WARRANTY.\n"
"You may redistribute copies of Emacs\n"
"under the terms of the GNU General Public License.\n"
"For more information about these matters, see the file named COPYING.\n"
);
}
void
options_set_default(void)
{
options.spd_spk_mode = MODE_DAEMON;
options.log_level = 3;
options.log_level_set = DEFAULT;
if (!strcmp(LOGPATH, ""))
options.log_file_name = strdup("/var/log/speechd-up.log");
else
options.log_file_name = strdup(LOGPATH"/speechd-up.log");
options.log_file_name_set = DEFAULT;
options.config_file_name = strdup(SYS_CONF"/speechd-up.conf");
options.speakup_device = strdup("/dev/softsynth");
options.speakup_device_set = DEFAULT;
options.speakup_chartab = strdup("/sys/module/speakup/parameters/chartab");
options.speakup_chartab_set = DEFAULT;
options.speakup_characters = strdup("/sys/module/speakup/parameters/characters");
options.speakup_device_set = DEFAULT;
options.speakup_coding = strdup("iso-8859-1");
options.speakup_coding_set = DEFAULT;
options.language = strdup("en");
options.language_set = DEFAULT;
options.probe_mode = 0;
options.dont_init_tables=0;
options.dont_init_tables_set = DEFAULT;
}
void
options_parse(int argc, char *argv[])
{
char* tail_ptr;
int c_opt;
int option_index;
int val;
assert (argc>0);
assert(argv);
while(1){
option_index = 0;
c_opt = getopt_long(argc, argv, spd_short_options, spd_long_options,
&option_index);
if (c_opt == -1) break;
switch(c_opt){
case 'd':
options.spd_spk_mode = MODE_DAEMON;
break;
case 's':
options.spd_spk_mode = MODE_SINGLE;
break;
case 'l':
SPD_OPTION_SET_INT(options.log_level);
options.log_level_set = COMMAND_LINE;
break;
case 'L':
if (options.log_file_name != 0) free(options.log_file_name);
options.log_file_name = strdup(optarg);
options.log_file_name_set = COMMAND_LINE;
break;
case 'C':
if (options.config_file_name != 0) free(options.config_file_name);
options.config_file_name = strdup(optarg);
break;
case 'D':
if (options.speakup_device != 0) free(options.speakup_device);
options.speakup_device = strdup(optarg);
options.speakup_device_set = COMMAND_LINE;
break;
case 'c':
if (options.speakup_coding != 0) free (options.speakup_coding);
options.speakup_coding = strdup(optarg);
options.speakup_coding_set = COMMAND_LINE;
break;
case 'i':
if (options.language != 0) free(options.language);
options.language = strdup(optarg);
options.language_set = COMMAND_LINE;
case 'v':
options_print_version();
exit(0);
break;
case 'h':
options_print_help(argv);
exit(0);
break;
case 'p':
options.probe_mode = 1;
break;
case 't':
options.dont_init_tables = 1;
options.dont_init_tables_set = COMMAND_LINE;
break;
default:
printf("Error: Unrecognized option\n\n");
options_print_help(argv);
exit(1);
}
}
}