24
24
/* NOTE: Be careful not to include options.h, we would
25
25
get repetitive initializations warnings */
27
31
#include <sys/stat.h>
29
33
#include "speechd.h"
31
35
#include "options.h"
34
options_print_help(char *argv[])
39
static const struct option spd_long_options[] = {
40
{"run-daemon", 0, 0, 'd'},
41
{"run-single", 0, 0, 's'},
43
{"log-level", 1, 0, 'l'},
44
{"log-dir", required_argument, 0, 'L'},
45
{"communication-method", 1, 0, 'c'},
46
{"socket-path", 1, 0, 'S'},
48
{"pid-file", 1, 0, 'P'},
49
{"config-dir", required_argument, 0, 'C'},
50
{"version", 0, 0, 'v'},
56
static const char *const spd_short_options = "dsal:L:c:S:p:P:C:vDh";
58
void options_print_help(char *argv[])
39
printf("Usage: %s [-{d|s}] [-l {1|2|3|4|5}] [-c com_method] [-S socket_path] [-p port] | [-v] | [-h]\n", argv[0]);
40
printf("Speech Dispatcher -- Common interface for Speech Synthesis (GNU GPL)\n\n");
41
printf("-d, --run-daemon - Run as a daemon\n"
42
"-s, --run-single - Run as single application\n"
43
"-a, --spawn - Start only if autospawn is not disabled\n"
44
"-l, --log-level - Set log level (1..5)\n"
45
"-c, --communication-method Communication method to use (unix_socket or inet_socket)\n"
46
"-S, --socket-path - Socket path to use for 'unix_socket' method (filesystem path or 'default')\n"
47
"-p, --port - Specify a port number for 'inet_socket' method\n"
48
"-P, --pid-file - Set path to pid file\n"
49
"-C, --config-dir - Set path to configuration\n"
50
"-v, --version - Report version of this program\n"
51
"-D, --debug - Output debugging information into /tmp/.speech-dispatcher\n"
52
"-h, --help - Print this info\n\n"
53
"Copyright (C) 2003, 2004, 2006, 2007, 2008, 2010 Brailcom, o.p.s.\n"
54
"This is free software; you can redistribute it and/or modify it\n"
55
"under the terms of the GNU General Public License as published by\n"
56
"the Free Software Foundation; either version 2, or (at your option)\n"
57
"any later version. Please see COPYING for more details.\n\n"
58
"Please report bugs to <speechd-bugs@freebsoft.org>\n\n");
65
("%s [-{d|s}] [-l {1|2|3|4|5}] [-c com_method] [-S socket_path] [-p port] | [-v] | [-h]\n",
67
printf(_("%s -- Common interface for Speech Synthesis %s\n\n"),
68
"Speech Dispatcher", "(GNU GPL)");
69
printf("-d, --run-daemon\t");
70
printf(_("Run as a daemon\n"));
71
printf("-s, --run-single\t");
72
printf(_("Run as single application\n"));
73
printf("-a, --spawn\t\t");
74
printf(_("Start only if autospawn is not disabled\n"));
75
printf("-l, --log-level\t\t");
76
printf(_("Set log level (between %d and %d)\n"), 1, 5);
77
printf("-L, --log-dir\t\t");
78
printf(_("Set path to logging\n"));
79
printf("-c, --communication-method\t");
80
printf(_("Communication method to use ('%s' or '%s')\n"), "unix_socket",
82
printf("-S, --socket-path\t");
84
("Socket path to use for '%s' method (filesystem path or '%s')\n"),
85
"unix_socket", "default");
86
printf("-p, --port\t\t");
87
printf(_("Specify a port number for '%s' method\n"), "inet_socket");
88
printf("-P, --pid-file\t\t");
89
printf(_("Set path to pid file\n"));
90
printf("-C, --config-dir\t");
91
printf(_("Set path to configuration\n"));
92
printf("-v, --version\t\t");
93
printf(_("Report version of this program\n"));
94
printf("-D, --debug\t\t");
95
printf(_("Output debugging information into %s\n"),
96
"/tmp/.speech-dispatcher");
97
printf("-h, --help\t\t");
98
printf(_("Print this info\n"));
101
("Copyright (C) %d-%d Brailcom, o.p.s.\n"
102
"This is free software; you can redistribute it and/or modify it\n"
103
"under the terms of the GNU General Public License as published by\n"
104
"the Free Software Foundation; either version 2, or (at your option)\n"
105
"any later version. Please see COPYING for more details.\n\n"
106
"Please report bugs to %s\n\n"), 2002, 2012, PACKAGE_BUGREPORT);
63
options_print_version(void)
110
void options_print_version(void)
65
printf("%s %s\n", PACKAGE, VERSION);
66
printf("Copyright (C) 2003, 2004, 2006, 2007, 2008, 2010 Brailcom, o.p.s.\n"
67
"Speech Dispatcher comes with ABSOLUTELY NO WARRANTY.\n"
68
"You may redistribute copies of Speech Dispatcher\n"
69
"under the terms of the GNU General Public License.\n"
70
"For more information about these matters, see the file named COPYING.\n"
112
printf("%s %s\n", PACKAGE, VERSION);
114
("Copyright (C) %d-%d Brailcom, o.p.s.\n"
115
"%s comes with ABSOLUTELY NO WARRANTY.\n"
116
"You may redistribute copies of this program\n"
117
"under the terms of the GNU General Public License.\n"
118
"For more information about these matters, see the file named COPYING.\n"),
119
2002, 2012, "Speech Dispatcher");
74
122
#define SPD_OPTION_SET_INT(param) \
81
129
#define SPD_OPTION_SET_STR(param) \
82
SpeechdOptions.param = strdup(optarg)
130
SpeechdOptions.param = g_strdup(optarg)
85
options_parse(int argc, char *argv[])
132
void options_parse(int argc, char *argv[])
94
char *debug_logfile_path;
103
c_opt = getopt_long(argc, argv, spd_short_options, spd_long_options,
105
if (c_opt == -1) break;
108
spd_mode = SPD_MODE_DAEMON;
111
spd_mode = SPD_MODE_SINGLE;
114
SPD_OPTION_SET_INT(log_level);
117
SPD_OPTION_SET_STR(communication_method);
118
SpeechdOptions.communication_method_set = 1;
121
SPD_OPTION_SET_STR(socket_path);
122
SpeechdOptions.socket_path_set = 1;
125
SPD_OPTION_SET_INT(port);
128
SpeechdOptions.spawn = TRUE;
131
SPD_OPTION_SET_STR(pid_file);
134
SPD_OPTION_SET_STR(conf_dir);
137
options_print_version();
141
tmpdir = g_strdup(getenv("TMPDIR"));
143
tmpdir = g_strdup("/tmp");
144
SpeechdOptions.debug_destination=g_strdup_printf("%s/speechd-debug", tmpdir);
147
ret = mkdir(SpeechdOptions.debug_destination, S_IRWXU);
149
MSG(1, "Can't create additional debug destination in %s, reason %d-%s",
150
SpeechdOptions.debug_destination, errno, strerror(errno));
151
if (errno == EEXIST){
152
MSG(1, "Debugging directory %s already exists, please delete it first",
153
SpeechdOptions.debug_destination);
158
debug_logfile_path = g_strdup_printf("%s/speech-dispatcher.log",
159
SpeechdOptions.debug_destination);
160
/* Open logfile for writing */
161
debug_logfile = fopen(debug_logfile_path, "wx");
162
spd_free(debug_logfile_path);
163
if (debug_logfile == NULL){
164
MSG(1, "Error: can't open additional debug logging file %s [%d-%s]!\n",
165
debug_logfile_path, errno, strerror(errno));
168
SpeechdOptions.debug = 1;
171
options_print_help(argv);
175
MSG(2, "Unrecognized option\n");
176
options_print_help(argv);
141
char *debug_logfile_path;
150
getopt_long(argc, argv, spd_short_options, spd_long_options,
156
spd_mode = SPD_MODE_DAEMON;
159
spd_mode = SPD_MODE_SINGLE;
162
SPD_OPTION_SET_INT(log_level);
165
SPD_OPTION_SET_STR(log_dir);
166
SpeechdOptions.log_dir_set = 1;
169
SPD_OPTION_SET_STR(communication_method);
170
SpeechdOptions.communication_method_set = 1;
173
SPD_OPTION_SET_STR(socket_path);
174
SpeechdOptions.socket_path_set = 1;
177
SPD_OPTION_SET_INT(port);
180
SpeechdOptions.spawn = TRUE;
183
SPD_OPTION_SET_STR(pid_file);
186
SPD_OPTION_SET_STR(conf_dir);
189
options_print_version();
193
tmpdir = g_strdup(getenv("TMPDIR"));
195
tmpdir = g_strdup("/tmp");
196
SpeechdOptions.debug_destination =
197
g_strdup_printf("%s/speechd-debug", tmpdir);
200
ret = mkdir(SpeechdOptions.debug_destination, S_IRWXU);
203
"Can't create additional debug destination in %s, reason %d-%s",
204
SpeechdOptions.debug_destination, errno,
206
if (errno == EEXIST) {
208
"Debugging directory %s already exists, please delete it first",
209
SpeechdOptions.debug_destination);
215
g_strdup_printf("%s/speech-dispatcher.log",
216
SpeechdOptions.debug_destination);
217
/* Open logfile for writing */
218
debug_logfile = fopen(debug_logfile_path, "wx");
219
g_free(debug_logfile_path);
220
if (debug_logfile == NULL) {
222
"Error: can't open additional debug logging file %s [%d-%s]!\n",
223
debug_logfile_path, errno, strerror(errno));
226
SpeechdOptions.debug = 1;
229
options_print_help(argv);
233
MSG(2, "Unrecognized option\n");
234
options_print_help(argv);
181
240
#undef SPD_OPTION_SET_INT