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 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
|
/*
* 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.
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <assert.h>
#include <getopt.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "options.h"
static struct option spd_long_options[] = {
{"run-daemon", 0, 0, 'd'},
{"run-single", 0, 0, 's'},
{"log-level", 1, 0, 'l'},
{"log-file", 1, 0, 'L'},
{"config-file", 1, 0, 'C'},
{"device", 1, 0, 'D'},
{"coding", 1, 0, 'c'},
{"language", 1, 0, 'i'},
{"synthesis", 1, 0, 'S'},
{"dont-init-tables", 0, 0, 't'},
{"probe", 0, 0, 'p'},
{"version", 0, 0, 'v'},
{"help", 0, 0, 'h'},
{0, 0, 0, 0}
};
static char *spd_short_options = "dsvhpti:l:L:C:D:S:c:";
struct spd_options options;
#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("\t-d, --run-daemon Run as a daemon\n"
"\t-s, --run-single Run as single application\n"
"\t-l, --log-level Set log level (1..5)\n"
"\t-L, --log-file Set log file to path\n"
"\t-D, --device Specify the device name of Speakup software synthesis\n"
"\t-i, --language Set default language for speech output\n"
"\t-c, --coding Specify the default encoding to use\n"
"\t-t, --dont-init-tables Don't rewrite /proc tables for optimal software synthesis\n"
"\t-p, --probe Initialize everything and try to say some message\n"
"\t but don't connect to SpeakUp. For testing purposes.\n"
"\t-v, --version Report version of this program\n"
"\t-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 %s\n\n", PACKAGE_BUGREPORT);
}
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/accessibility/speakup/i18n/chartab");
options.speakup_chartab_set = DEFAULT;
options.speakup_characters =
strdup("/sys/accessibility/speakup/i18n/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);
}
}
}
|