4
* Copyright (c) 2002, Smart Link Ltd.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
11
* 1. Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* 2. Redistributions in binary form must reproduce the above
14
* copyright notice, this list of conditions and the following
15
* disclaimer in the documentation and/or other materials provided
16
* with the distribution.
17
* 3. Neither the name of the Smart Link Ltd. nor the names of its
18
* contributors may be used to endorse or promote products derived
19
* from this software without specific prior written permission.
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
* modem_cmdline.c -- simple command line processor,
38
* define config parameters.
40
* Author: Sasha K (sashak@smlink.com)
53
#include <modem_homolog.h>
54
#include <modem_debug.h>
56
#define PR_INFO(fmt...) fprintf(stderr, fmt )
59
/* global config data */
62
extern const char *modem_default_country;
65
extern unsigned int modem_debug_level;
66
extern unsigned int modem_debug_logging;
68
/* config parameters */
69
const char *modem_dev_name = "/dev/slamr0";
70
const char *modem_alsa_dev_name = "hw:1";
71
unsigned int need_realtime = 1;
72
unsigned int use_alsa = 0;
73
const char *modem_group = "uucp";
74
mode_t modem_perm = 0660;
96
enum {NONE=0,MANDATORY,OPTIONAL} arg;
97
enum {INTEGER,STRING} arg_type;
101
{'h',"help","this usage"},
102
{'u',"usage","this usage"},
103
{'v',"version","show version and exit"},
104
{'c',"country","default modem country name",MANDATORY,STRING,"USA"},
105
{ 0 ,"countrylist","show list of supported countries"},
106
{'a',"alsa","ALSA mode (see README for howto)"},
107
{'g',"group","Modem TTY group",MANDATORY,STRING,"uucp"},
108
{'p',"perm","Modem TTY permission",MANDATORY,INTEGER,"0660"},
109
{'n',"nortpriority","run with regular priority"},
110
{'d',"debug","debug level",OPTIONAL,INTEGER,"0"},
111
{'l',"log","logging mode",OPTIONAL,INTEGER,"5"},
117
static void usage(const char *prog_name)
120
PR_INFO("Usage: %s [option...] <device>\n"
121
"Where 'device' is name of modem device (default `%s')\n"
122
" and 'option' may be:\n", prog_name, modem_dev_name);
123
for (opt = opt_list ; opt->name ; opt++ ) {
126
n = PR_INFO(" -%c, ",opt->ch);
129
n += PR_INFO("--%s%s ",opt->name,opt->arg?"=VAL":"");
130
n += PR_INFO("%*s%s",24-n,"",opt->desc);
132
n+= PR_INFO(" (default `%s')",opt->arg_val);
140
static void opt_parse(int argc, char *argv[])
142
const char *prog_name;
143
const char *dev_name = NULL;
150
for( i = 1 ; i < argc ; i++ ) {
160
do { p++; } while( *p == '-' );
161
for (opt = opt_list ; opt->name ; opt++ ) {
162
if(!strncmp(p,opt->name,strlen(opt->name)) ||
163
(opt->ch && *p == opt->ch) ) {
165
if(!strncmp(p,opt->name,strlen(opt->name)))
166
q = p + strlen(opt->name);
171
else if (*q == '=' && opt->arg ) {
175
else if(isdigit(*q) && opt->arg ) {
183
if ( arg && !opt->arg )
186
if (!arg && opt->arg &&
187
(i < argc - 1 && *argv[i+1] != '-') &&
188
(!opt->arg_type == INTEGER || isdigit(*argv[i+1])))
191
if(!arg && opt->arg == MANDATORY)
204
modem_dev_name = dev_name;
209
void modem_cmdline(int argc, char *argv[])
211
const char *prog_name = argv[0];
214
opt_parse(argc,argv);
216
if(opt_list[OPT_HELP].found ||
217
opt_list[OPT_USAGE].found )
220
if(opt_list[OPT_VERSION].found) {
221
extern void modem_print_version();
222
modem_print_version();
226
if(opt_list[OPT_COUNTRYLIST].found) {
227
const struct homolog_set *s ;
228
for( s = homolog_set; s->name ; s++ ) {
229
PR_INFO("%02x: %s\n",s->id,s->name);
233
if(opt_list[OPT_COUNTRY].found)
234
modem_default_country = opt_list[OPT_COUNTRY].arg_val;
235
if(opt_list[OPT_ALSA].found) {
237
PR_INFO("ALSA support is not compiled in (see README for howto).\n");
240
modem_dev_name = modem_alsa_dev_name;
243
if(opt_list[OPT_GROUP].found)
244
modem_group = opt_list[OPT_GROUP].arg_val;
245
if(opt_list[OPT_PERM].found) {
246
val = strtol(opt_list[OPT_PERM].arg_val,NULL,8);
251
if(opt_list[OPT_USER].found)
253
if(opt_list[OPT_DEBUG].found) {
254
modem_debug_level = 1 ;
255
if(opt_list[OPT_DEBUG].arg_val &&
256
(val= strtol(opt_list[OPT_DEBUG].arg_val,NULL,0)) > 0 )
257
modem_debug_level = val;
259
if(opt_list[OPT_LOG].found) {
260
modem_debug_logging = 5;
261
if(opt_list[OPT_LOG].arg_val &&
262
(val= strtol(opt_list[OPT_LOG].arg_val,NULL,0)) > 0 )
263
modem_debug_logging = val;