blob: 2240c56589abd84ddb8478559f0f3ae754317221 [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
jjakoa7cd2492003-04-11 09:40:12 +00002 File autogenerated by gengetopt version 2.8
jjako52c24142002-12-16 13:33:51 +00003 generated with the following command:
jjakoa7cd2492003-04-11 09:40:12 +00004 gengetopt --conf-parser
jjako52c24142002-12-16 13:33:51 +00005
6 The developers of gengetopt consider the fixed text that goes in all
7 gengetopt output files to be in the public domain:
8 we make no copyright claims on it.
9*/
10
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15/* If we use autoconf. */
16#ifdef HAVE_CONFIG_H
17#include "config.h"
18#endif
19/* Check for configure's getopt check result. */
20#ifndef HAVE_GETOPT_LONG
21#include "getopt.h"
22#else
23#include <getopt.h>
24#endif
25
26#ifndef HAVE_STRDUP
27#define strdup gengetopt_strdup
28#endif /* HAVE_STRDUP */
29
30#include "cmdline.h"
31
32
33void
34cmdline_parser_print_version (void)
35{
36 printf ("%s %s\n", PACKAGE, VERSION);
37}
38
39void
40cmdline_parser_print_help (void)
41{
42 cmdline_parser_print_version ();
43 printf("\n"
44 "Usage: %s [OPTIONS]...\n", PACKAGE);
45 printf(" -h --help Print help and exit\n");
46 printf(" -V --version Print version and exit\n");
47 printf(" -f --fg Run in foreground (default=off)\n");
48 printf(" -d --debug Run in debug mode (default=off)\n");
49 printf(" -cSTRING --conf=STRING Read configuration file\n");
50 printf(" --pidfile=STRING Filename of process id file (default='./sgsnemu.pid')\n");
51 printf(" --statedir=STRING Directory of nonvolatile data (default='./')\n");
52 printf(" --dns=STRING DNS Server to use\n");
53 printf(" -lSTRING --listen=STRING Local interface\n");
54 printf(" -rSTRING --remote=STRING Remote host\n");
jjako52c24142002-12-16 13:33:51 +000055 printf(" --contexts=INT Number of contexts (default='1')\n");
jjako52c24142002-12-16 13:33:51 +000056 printf(" --timelimit=INT Exit after timelimit seconds (default='0')\n");
57 printf(" -aSTRING --apn=STRING Access point name (default='internet')\n");
58 printf(" -iSTRING --imsi=STRING IMSI (default='240010123456789')\n");
59 printf(" -mSTRING --msisdn=STRING Mobile Station ISDN number (default='46702123456')\n");
60 printf(" -qINT --qos=INT Requested quality of service (default='0x0b921f')\n");
61 printf(" -uSTRING --uid=STRING Login user ID (default='mig')\n");
62 printf(" -pSTRING --pwd=STRING Login password (default='hemmelig')\n");
jjako5da68452003-01-28 16:08:47 +000063 printf(" --createif Create local network interface (default=off)\n");
jjakoa7cd2492003-04-11 09:40:12 +000064 printf(" --defaultroute Create default route (default=off)\n");
jjako5da68452003-01-28 16:08:47 +000065 printf(" --ipup=STRING Script to run after link-up\n");
66 printf(" --ipdown=STRING Script to run after link-down\n");
jjako5da68452003-01-28 16:08:47 +000067 printf(" --pinghost=STRING Ping remote host\n");
68 printf(" --pingrate=INT Number of ping req per second (default='1')\n");
69 printf(" --pingsize=INT Number of ping data bytes (default='56')\n");
70 printf(" --pingcount=INT Number of ping req to send (default='0')\n");
71 printf(" --pingquiet Do not print ping packet info (default=off)\n");
jjako52c24142002-12-16 13:33:51 +000072}
73
74
75#ifndef HAVE_STRDUP
76/* gengetopt_strdup(): automatically generated from strdup.c. */
77/* strdup.c replacement of strdup, which is not standard */
78static char *
79gengetopt_strdup (const char *s)
80{
81 char *result = (char*)malloc(strlen(s) + 1);
82 if (result == (char*)0)
83 return (char*)0;
84 strcpy(result, s);
85 return result;
86}
87#endif /* HAVE_STRDUP */
88
89int
90cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
91{
92 int c; /* Character of the parsed option. */
93 int missing_required_options = 0;
94
95 args_info->help_given = 0 ;
96 args_info->version_given = 0 ;
97 args_info->fg_given = 0 ;
98 args_info->debug_given = 0 ;
99 args_info->conf_given = 0 ;
100 args_info->pidfile_given = 0 ;
101 args_info->statedir_given = 0 ;
102 args_info->dns_given = 0 ;
103 args_info->listen_given = 0 ;
104 args_info->remote_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000105 args_info->contexts_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000106 args_info->timelimit_given = 0 ;
107 args_info->apn_given = 0 ;
108 args_info->imsi_given = 0 ;
109 args_info->msisdn_given = 0 ;
110 args_info->qos_given = 0 ;
111 args_info->uid_given = 0 ;
112 args_info->pwd_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000113 args_info->createif_given = 0 ;
jjakoa7cd2492003-04-11 09:40:12 +0000114 args_info->defaultroute_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000115 args_info->ipup_given = 0 ;
116 args_info->ipdown_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000117 args_info->pinghost_given = 0 ;
118 args_info->pingrate_given = 0 ;
119 args_info->pingsize_given = 0 ;
120 args_info->pingcount_given = 0 ;
121 args_info->pingquiet_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000122#define clear_args() { \
123 args_info->fg_flag = 0;\
124 args_info->debug_flag = 0;\
125 args_info->conf_arg = NULL; \
126 args_info->pidfile_arg = strdup("./sgsnemu.pid") ;\
127 args_info->statedir_arg = strdup("./") ;\
128 args_info->dns_arg = NULL; \
129 args_info->listen_arg = NULL; \
130 args_info->remote_arg = NULL; \
jjako52c24142002-12-16 13:33:51 +0000131 args_info->contexts_arg = 1 ;\
jjako52c24142002-12-16 13:33:51 +0000132 args_info->timelimit_arg = 0 ;\
133 args_info->apn_arg = strdup("internet") ;\
134 args_info->imsi_arg = strdup("240010123456789") ;\
135 args_info->msisdn_arg = strdup("46702123456") ;\
136 args_info->qos_arg = 0x0b921f ;\
137 args_info->uid_arg = strdup("mig") ;\
138 args_info->pwd_arg = strdup("hemmelig") ;\
jjako5da68452003-01-28 16:08:47 +0000139 args_info->createif_flag = 0;\
jjakoa7cd2492003-04-11 09:40:12 +0000140 args_info->defaultroute_flag = 0;\
jjako5da68452003-01-28 16:08:47 +0000141 args_info->ipup_arg = NULL; \
142 args_info->ipdown_arg = NULL; \
jjako5da68452003-01-28 16:08:47 +0000143 args_info->pinghost_arg = NULL; \
144 args_info->pingrate_arg = 1 ;\
145 args_info->pingsize_arg = 56 ;\
146 args_info->pingcount_arg = 0 ;\
147 args_info->pingquiet_flag = 0;\
jjako52c24142002-12-16 13:33:51 +0000148}
149
150 clear_args();
151
152 optarg = 0;
153 optind = 1;
154 opterr = 1;
155 optopt = '?';
156
157 while (1)
158 {
159 int option_index = 0;
160 char *stop_char;
161 static struct option long_options[] = {
162 { "help", 0, NULL, 'h' },
163 { "version", 0, NULL, 'V' },
164 { "fg", 0, NULL, 'f' },
165 { "debug", 0, NULL, 'd' },
166 { "conf", 1, NULL, 'c' },
167 { "pidfile", 1, NULL, 0 },
168 { "statedir", 1, NULL, 0 },
169 { "dns", 1, NULL, 0 },
170 { "listen", 1, NULL, 'l' },
171 { "remote", 1, NULL, 'r' },
jjako52c24142002-12-16 13:33:51 +0000172 { "contexts", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000173 { "timelimit", 1, NULL, 0 },
174 { "apn", 1, NULL, 'a' },
175 { "imsi", 1, NULL, 'i' },
176 { "msisdn", 1, NULL, 'm' },
177 { "qos", 1, NULL, 'q' },
178 { "uid", 1, NULL, 'u' },
179 { "pwd", 1, NULL, 'p' },
jjako5da68452003-01-28 16:08:47 +0000180 { "createif", 0, NULL, 0 },
jjakoa7cd2492003-04-11 09:40:12 +0000181 { "defaultroute", 0, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000182 { "ipup", 1, NULL, 0 },
183 { "ipdown", 1, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000184 { "pinghost", 1, NULL, 0 },
185 { "pingrate", 1, NULL, 0 },
186 { "pingsize", 1, NULL, 0 },
187 { "pingcount", 1, NULL, 0 },
188 { "pingquiet", 0, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000189 { NULL, 0, NULL, 0 }
190 };
191
jjako5da68452003-01-28 16:08:47 +0000192 c = getopt_long (argc, argv, "hVfdc:l:r:a:i:m:q:u:p:", long_options, &option_index);
jjako52c24142002-12-16 13:33:51 +0000193
194 if (c == -1) break; /* Exit from `while (1)' loop. */
195
196 switch (c)
197 {
198 case 'h': /* Print help and exit. */
199 clear_args ();
200 cmdline_parser_print_help ();
201 exit (EXIT_SUCCESS);
202
203 case 'V': /* Print version and exit. */
204 clear_args ();
205 cmdline_parser_print_version ();
206 exit (EXIT_SUCCESS);
207
208 case 'f': /* Run in foreground. */
209 if (args_info->fg_given)
210 {
211 fprintf (stderr, "%s: `--fg' (`-f') option given more than once\n", PACKAGE);
212 clear_args ();
213 exit (EXIT_FAILURE);
214 }
215 args_info->fg_given = 1;
216 args_info->fg_flag = !(args_info->fg_flag);
217 break;
218
219 case 'd': /* Run in debug mode. */
220 if (args_info->debug_given)
221 {
222 fprintf (stderr, "%s: `--debug' (`-d') option given more than once\n", PACKAGE);
223 clear_args ();
224 exit (EXIT_FAILURE);
225 }
226 args_info->debug_given = 1;
227 args_info->debug_flag = !(args_info->debug_flag);
228 break;
229
230 case 'c': /* Read configuration file. */
231 if (args_info->conf_given)
232 {
233 fprintf (stderr, "%s: `--conf' (`-c') option given more than once\n", PACKAGE);
234 clear_args ();
235 exit (EXIT_FAILURE);
236 }
237 args_info->conf_given = 1;
238 args_info->conf_arg = strdup (optarg);
239 break;
240
241 case 'l': /* Local interface. */
242 if (args_info->listen_given)
243 {
244 fprintf (stderr, "%s: `--listen' (`-l') option given more than once\n", PACKAGE);
245 clear_args ();
246 exit (EXIT_FAILURE);
247 }
248 args_info->listen_given = 1;
249 args_info->listen_arg = strdup (optarg);
250 break;
251
252 case 'r': /* Remote host. */
253 if (args_info->remote_given)
254 {
255 fprintf (stderr, "%s: `--remote' (`-r') option given more than once\n", PACKAGE);
256 clear_args ();
257 exit (EXIT_FAILURE);
258 }
259 args_info->remote_given = 1;
260 args_info->remote_arg = strdup (optarg);
261 break;
262
jjako52c24142002-12-16 13:33:51 +0000263 case 'a': /* Access point name. */
264 if (args_info->apn_given)
265 {
266 fprintf (stderr, "%s: `--apn' (`-a') option given more than once\n", PACKAGE);
267 clear_args ();
268 exit (EXIT_FAILURE);
269 }
270 args_info->apn_given = 1;
271 args_info->apn_arg = strdup (optarg);
272 break;
273
274 case 'i': /* IMSI. */
275 if (args_info->imsi_given)
276 {
277 fprintf (stderr, "%s: `--imsi' (`-i') option given more than once\n", PACKAGE);
278 clear_args ();
279 exit (EXIT_FAILURE);
280 }
281 args_info->imsi_given = 1;
282 args_info->imsi_arg = strdup (optarg);
283 break;
284
285 case 'm': /* Mobile Station ISDN number. */
286 if (args_info->msisdn_given)
287 {
288 fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once\n", PACKAGE);
289 clear_args ();
290 exit (EXIT_FAILURE);
291 }
292 args_info->msisdn_given = 1;
293 args_info->msisdn_arg = strdup (optarg);
294 break;
295
296 case 'q': /* Requested quality of service. */
297 if (args_info->qos_given)
298 {
299 fprintf (stderr, "%s: `--qos' (`-q') option given more than once\n", PACKAGE);
300 clear_args ();
301 exit (EXIT_FAILURE);
302 }
303 args_info->qos_given = 1;
304 args_info->qos_arg = strtol (optarg,&stop_char,0);
305 break;
306
307 case 'u': /* Login user ID. */
308 if (args_info->uid_given)
309 {
310 fprintf (stderr, "%s: `--uid' (`-u') option given more than once\n", PACKAGE);
311 clear_args ();
312 exit (EXIT_FAILURE);
313 }
314 args_info->uid_given = 1;
315 args_info->uid_arg = strdup (optarg);
316 break;
317
318 case 'p': /* Login password. */
319 if (args_info->pwd_given)
320 {
321 fprintf (stderr, "%s: `--pwd' (`-p') option given more than once\n", PACKAGE);
322 clear_args ();
323 exit (EXIT_FAILURE);
324 }
325 args_info->pwd_given = 1;
326 args_info->pwd_arg = strdup (optarg);
327 break;
328
329
330 case 0: /* Long option with no short option */
331 /* Filename of process id file. */
332 if (strcmp (long_options[option_index].name, "pidfile") == 0)
333 {
334 if (args_info->pidfile_given)
335 {
336 fprintf (stderr, "%s: `--pidfile' option given more than once\n", PACKAGE);
337 clear_args ();
338 exit (EXIT_FAILURE);
339 }
340 args_info->pidfile_given = 1;
341 args_info->pidfile_arg = strdup (optarg);
342 break;
343 }
344 /* Directory of nonvolatile data. */
345 else if (strcmp (long_options[option_index].name, "statedir") == 0)
346 {
347 if (args_info->statedir_given)
348 {
349 fprintf (stderr, "%s: `--statedir' option given more than once\n", PACKAGE);
350 clear_args ();
351 exit (EXIT_FAILURE);
352 }
353 args_info->statedir_given = 1;
354 args_info->statedir_arg = strdup (optarg);
355 break;
356 }
357 /* DNS Server to use. */
358 else if (strcmp (long_options[option_index].name, "dns") == 0)
359 {
360 if (args_info->dns_given)
361 {
362 fprintf (stderr, "%s: `--dns' option given more than once\n", PACKAGE);
363 clear_args ();
364 exit (EXIT_FAILURE);
365 }
366 args_info->dns_given = 1;
367 args_info->dns_arg = strdup (optarg);
368 break;
369 }
jjako52c24142002-12-16 13:33:51 +0000370 /* Number of contexts. */
371 else if (strcmp (long_options[option_index].name, "contexts") == 0)
372 {
373 if (args_info->contexts_given)
374 {
375 fprintf (stderr, "%s: `--contexts' option given more than once\n", PACKAGE);
376 clear_args ();
377 exit (EXIT_FAILURE);
378 }
379 args_info->contexts_given = 1;
380 args_info->contexts_arg = strtol (optarg,&stop_char,0);
381 break;
382 }
jjako52c24142002-12-16 13:33:51 +0000383 /* Exit after timelimit seconds. */
384 else if (strcmp (long_options[option_index].name, "timelimit") == 0)
385 {
386 if (args_info->timelimit_given)
387 {
388 fprintf (stderr, "%s: `--timelimit' option given more than once\n", PACKAGE);
389 clear_args ();
390 exit (EXIT_FAILURE);
391 }
392 args_info->timelimit_given = 1;
393 args_info->timelimit_arg = strtol (optarg,&stop_char,0);
394 break;
395 }
jjako5da68452003-01-28 16:08:47 +0000396 /* Create local network interface. */
397 else if (strcmp (long_options[option_index].name, "createif") == 0)
398 {
399 if (args_info->createif_given)
400 {
401 fprintf (stderr, "%s: `--createif' option given more than once\n", PACKAGE);
402 clear_args ();
403 exit (EXIT_FAILURE);
404 }
405 args_info->createif_given = 1;
406 args_info->createif_flag = !(args_info->createif_flag);
407 break;
408 }
jjakoa7cd2492003-04-11 09:40:12 +0000409 /* Create default route. */
410 else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
411 {
412 if (args_info->defaultroute_given)
413 {
414 fprintf (stderr, "%s: `--defaultroute' option given more than once\n", PACKAGE);
415 clear_args ();
416 exit (EXIT_FAILURE);
417 }
418 args_info->defaultroute_given = 1;
419 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
420 break;
421 }
jjako5da68452003-01-28 16:08:47 +0000422 /* Script to run after link-up. */
423 else if (strcmp (long_options[option_index].name, "ipup") == 0)
424 {
425 if (args_info->ipup_given)
426 {
427 fprintf (stderr, "%s: `--ipup' option given more than once\n", PACKAGE);
428 clear_args ();
429 exit (EXIT_FAILURE);
430 }
431 args_info->ipup_given = 1;
432 args_info->ipup_arg = strdup (optarg);
433 break;
434 }
435 /* Script to run after link-down. */
436 else if (strcmp (long_options[option_index].name, "ipdown") == 0)
437 {
438 if (args_info->ipdown_given)
439 {
440 fprintf (stderr, "%s: `--ipdown' option given more than once\n", PACKAGE);
441 clear_args ();
442 exit (EXIT_FAILURE);
443 }
444 args_info->ipdown_given = 1;
445 args_info->ipdown_arg = strdup (optarg);
446 break;
447 }
jjako5da68452003-01-28 16:08:47 +0000448 /* Ping remote host. */
449 else if (strcmp (long_options[option_index].name, "pinghost") == 0)
450 {
451 if (args_info->pinghost_given)
452 {
453 fprintf (stderr, "%s: `--pinghost' option given more than once\n", PACKAGE);
454 clear_args ();
455 exit (EXIT_FAILURE);
456 }
457 args_info->pinghost_given = 1;
458 args_info->pinghost_arg = strdup (optarg);
459 break;
460 }
461 /* Number of ping req per second. */
462 else if (strcmp (long_options[option_index].name, "pingrate") == 0)
463 {
464 if (args_info->pingrate_given)
465 {
466 fprintf (stderr, "%s: `--pingrate' option given more than once\n", PACKAGE);
467 clear_args ();
468 exit (EXIT_FAILURE);
469 }
470 args_info->pingrate_given = 1;
471 args_info->pingrate_arg = strtol (optarg,&stop_char,0);
472 break;
473 }
474 /* Number of ping data bytes. */
475 else if (strcmp (long_options[option_index].name, "pingsize") == 0)
476 {
477 if (args_info->pingsize_given)
478 {
479 fprintf (stderr, "%s: `--pingsize' option given more than once\n", PACKAGE);
480 clear_args ();
481 exit (EXIT_FAILURE);
482 }
483 args_info->pingsize_given = 1;
484 args_info->pingsize_arg = strtol (optarg,&stop_char,0);
485 break;
486 }
487 /* Number of ping req to send. */
488 else if (strcmp (long_options[option_index].name, "pingcount") == 0)
489 {
490 if (args_info->pingcount_given)
491 {
492 fprintf (stderr, "%s: `--pingcount' option given more than once\n", PACKAGE);
493 clear_args ();
494 exit (EXIT_FAILURE);
495 }
496 args_info->pingcount_given = 1;
497 args_info->pingcount_arg = strtol (optarg,&stop_char,0);
498 break;
499 }
500 /* Do not print ping packet info. */
501 else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
502 {
503 if (args_info->pingquiet_given)
504 {
505 fprintf (stderr, "%s: `--pingquiet' option given more than once\n", PACKAGE);
506 clear_args ();
507 exit (EXIT_FAILURE);
508 }
509 args_info->pingquiet_given = 1;
510 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
511 break;
512 }
jjako52c24142002-12-16 13:33:51 +0000513
514 case '?': /* Invalid option. */
515 /* `getopt_long' already printed an error message. */
516 exit (EXIT_FAILURE);
517
518 default: /* bug: option not considered. */
519 fprintf (stderr, "%s: option unknown: %c\n", PACKAGE, c);
520 abort ();
521 } /* switch */
522 } /* while */
523
524
525 if ( missing_required_options )
526 exit (EXIT_FAILURE);
527
528 return 0;
529}
530
531#define CONFIGPARSERBUFSIZE 1024
532
533int
534cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override)
535{
536 FILE* file;
537 char linebuf[CONFIGPARSERBUFSIZE];
538 int line_num = 0;
539 int len;
540 int fnum;
541 char fopt[CONFIGPARSERBUFSIZE], farg[CONFIGPARSERBUFSIZE];
542 char *stop_char;
543
544 if ((file = fopen(filename, "r")) == NULL)
545 {
546 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
547 PACKAGE, filename);
548 exit (EXIT_FAILURE);
549 }
550
551 while ((fgets(linebuf, CONFIGPARSERBUFSIZE, file)) != NULL)
552 {
553 ++line_num;
554 len = strlen(linebuf);
555 if (len == CONFIGPARSERBUFSIZE-1)
556 {
557 fprintf (stderr, "%s: Line longer than %d characters found in configuration file '%s'\n",
558 PACKAGE, CONFIGPARSERBUFSIZE, filename);
559 exit (EXIT_FAILURE);
560 }
561
562 if (linebuf[0] == '#')
563 continue; /* Line was a comment */
564
565 /* Get the option */
566 if ((fnum = sscanf(linebuf, "%s %s", fopt, farg)) > 0)
567 {
568 if (!strcmp(fopt, "help"))
569 {
570 if (override || !args_info->help_given)
571 {
572 args_info->help_given = 1;
573
574 }
575 continue;
576 }
577 if (!strcmp(fopt, "version"))
578 {
579 if (override || !args_info->version_given)
580 {
581 args_info->version_given = 1;
582
583 }
584 continue;
585 }
586 if (!strcmp(fopt, "fg"))
587 {
588 if (override || !args_info->fg_given)
589 {
590 args_info->fg_given = 1;
591 args_info->fg_flag = !(args_info->fg_flag);
592 }
593 continue;
594 }
595 if (!strcmp(fopt, "debug"))
596 {
597 if (override || !args_info->debug_given)
598 {
599 args_info->debug_given = 1;
600 args_info->debug_flag = !(args_info->debug_flag);
601 }
602 continue;
603 }
604 if (!strcmp(fopt, "conf"))
605 {
606 if (override || !args_info->conf_given)
607 {
608 args_info->conf_given = 1;
609 if (fnum == 2)
610 args_info->conf_arg = strdup (farg);
611 else
612 {
613 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
614 filename, line_num);
615 exit (EXIT_FAILURE);
616 }
617 }
618 continue;
619 }
620 if (!strcmp(fopt, "pidfile"))
621 {
622 if (override || !args_info->pidfile_given)
623 {
624 args_info->pidfile_given = 1;
625 if (fnum == 2)
626 args_info->pidfile_arg = strdup (farg);
627 else
628 {
629 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
630 filename, line_num);
631 exit (EXIT_FAILURE);
632 }
633 }
634 continue;
635 }
636 if (!strcmp(fopt, "statedir"))
637 {
638 if (override || !args_info->statedir_given)
639 {
640 args_info->statedir_given = 1;
641 if (fnum == 2)
642 args_info->statedir_arg = strdup (farg);
643 else
644 {
645 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
646 filename, line_num);
647 exit (EXIT_FAILURE);
648 }
649 }
650 continue;
651 }
652 if (!strcmp(fopt, "dns"))
653 {
654 if (override || !args_info->dns_given)
655 {
656 args_info->dns_given = 1;
657 if (fnum == 2)
658 args_info->dns_arg = strdup (farg);
659 else
660 {
661 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
662 filename, line_num);
663 exit (EXIT_FAILURE);
664 }
665 }
666 continue;
667 }
668 if (!strcmp(fopt, "listen"))
669 {
670 if (override || !args_info->listen_given)
671 {
672 args_info->listen_given = 1;
673 if (fnum == 2)
674 args_info->listen_arg = strdup (farg);
675 else
676 {
677 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
678 filename, line_num);
679 exit (EXIT_FAILURE);
680 }
681 }
682 continue;
683 }
684 if (!strcmp(fopt, "remote"))
685 {
686 if (override || !args_info->remote_given)
687 {
688 args_info->remote_given = 1;
689 if (fnum == 2)
690 args_info->remote_arg = strdup (farg);
691 else
692 {
693 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
694 filename, line_num);
695 exit (EXIT_FAILURE);
696 }
697 }
698 continue;
699 }
jjako52c24142002-12-16 13:33:51 +0000700 if (!strcmp(fopt, "contexts"))
701 {
702 if (override || !args_info->contexts_given)
703 {
704 args_info->contexts_given = 1;
705 if (fnum == 2)
706 args_info->contexts_arg = strtol (farg,&stop_char,0);
707 else
708 {
709 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
710 filename, line_num);
711 exit (EXIT_FAILURE);
712 }
713 }
714 continue;
715 }
jjako52c24142002-12-16 13:33:51 +0000716 if (!strcmp(fopt, "timelimit"))
717 {
718 if (override || !args_info->timelimit_given)
719 {
720 args_info->timelimit_given = 1;
721 if (fnum == 2)
722 args_info->timelimit_arg = strtol (farg,&stop_char,0);
723 else
724 {
725 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
726 filename, line_num);
727 exit (EXIT_FAILURE);
728 }
729 }
730 continue;
731 }
732 if (!strcmp(fopt, "apn"))
733 {
734 if (override || !args_info->apn_given)
735 {
736 args_info->apn_given = 1;
737 if (fnum == 2)
738 args_info->apn_arg = strdup (farg);
739 else
740 {
741 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
742 filename, line_num);
743 exit (EXIT_FAILURE);
744 }
745 }
746 continue;
747 }
748 if (!strcmp(fopt, "imsi"))
749 {
750 if (override || !args_info->imsi_given)
751 {
752 args_info->imsi_given = 1;
753 if (fnum == 2)
754 args_info->imsi_arg = strdup (farg);
755 else
756 {
757 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
758 filename, line_num);
759 exit (EXIT_FAILURE);
760 }
761 }
762 continue;
763 }
764 if (!strcmp(fopt, "msisdn"))
765 {
766 if (override || !args_info->msisdn_given)
767 {
768 args_info->msisdn_given = 1;
769 if (fnum == 2)
770 args_info->msisdn_arg = strdup (farg);
771 else
772 {
773 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
774 filename, line_num);
775 exit (EXIT_FAILURE);
776 }
777 }
778 continue;
779 }
780 if (!strcmp(fopt, "qos"))
781 {
782 if (override || !args_info->qos_given)
783 {
784 args_info->qos_given = 1;
785 if (fnum == 2)
786 args_info->qos_arg = strtol (farg,&stop_char,0);
787 else
788 {
789 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
790 filename, line_num);
791 exit (EXIT_FAILURE);
792 }
793 }
794 continue;
795 }
796 if (!strcmp(fopt, "uid"))
797 {
798 if (override || !args_info->uid_given)
799 {
800 args_info->uid_given = 1;
801 if (fnum == 2)
802 args_info->uid_arg = strdup (farg);
803 else
804 {
805 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
806 filename, line_num);
807 exit (EXIT_FAILURE);
808 }
809 }
810 continue;
811 }
812 if (!strcmp(fopt, "pwd"))
813 {
814 if (override || !args_info->pwd_given)
815 {
816 args_info->pwd_given = 1;
817 if (fnum == 2)
818 args_info->pwd_arg = strdup (farg);
819 else
820 {
821 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
822 filename, line_num);
823 exit (EXIT_FAILURE);
824 }
825 }
826 continue;
827 }
jjako5da68452003-01-28 16:08:47 +0000828 if (!strcmp(fopt, "createif"))
829 {
830 if (override || !args_info->createif_given)
831 {
832 args_info->createif_given = 1;
833 args_info->createif_flag = !(args_info->createif_flag);
834 }
835 continue;
836 }
jjakoa7cd2492003-04-11 09:40:12 +0000837 if (!strcmp(fopt, "defaultroute"))
838 {
839 if (override || !args_info->defaultroute_given)
840 {
841 args_info->defaultroute_given = 1;
842 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
843 }
844 continue;
845 }
jjako5da68452003-01-28 16:08:47 +0000846 if (!strcmp(fopt, "ipup"))
847 {
848 if (override || !args_info->ipup_given)
849 {
850 args_info->ipup_given = 1;
851 if (fnum == 2)
852 args_info->ipup_arg = strdup (farg);
853 else
854 {
855 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
856 filename, line_num);
857 exit (EXIT_FAILURE);
858 }
859 }
860 continue;
861 }
862 if (!strcmp(fopt, "ipdown"))
863 {
864 if (override || !args_info->ipdown_given)
865 {
866 args_info->ipdown_given = 1;
867 if (fnum == 2)
868 args_info->ipdown_arg = strdup (farg);
869 else
870 {
871 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
872 filename, line_num);
873 exit (EXIT_FAILURE);
874 }
875 }
876 continue;
877 }
jjako5da68452003-01-28 16:08:47 +0000878 if (!strcmp(fopt, "pinghost"))
879 {
880 if (override || !args_info->pinghost_given)
881 {
882 args_info->pinghost_given = 1;
883 if (fnum == 2)
884 args_info->pinghost_arg = strdup (farg);
885 else
886 {
887 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
888 filename, line_num);
889 exit (EXIT_FAILURE);
890 }
891 }
892 continue;
893 }
894 if (!strcmp(fopt, "pingrate"))
895 {
896 if (override || !args_info->pingrate_given)
897 {
898 args_info->pingrate_given = 1;
899 if (fnum == 2)
900 args_info->pingrate_arg = strtol (farg,&stop_char,0);
901 else
902 {
903 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
904 filename, line_num);
905 exit (EXIT_FAILURE);
906 }
907 }
908 continue;
909 }
910 if (!strcmp(fopt, "pingsize"))
911 {
912 if (override || !args_info->pingsize_given)
913 {
914 args_info->pingsize_given = 1;
915 if (fnum == 2)
916 args_info->pingsize_arg = strtol (farg,&stop_char,0);
917 else
918 {
919 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
920 filename, line_num);
921 exit (EXIT_FAILURE);
922 }
923 }
924 continue;
925 }
926 if (!strcmp(fopt, "pingcount"))
927 {
928 if (override || !args_info->pingcount_given)
929 {
930 args_info->pingcount_given = 1;
931 if (fnum == 2)
932 args_info->pingcount_arg = strtol (farg,&stop_char,0);
933 else
934 {
935 fprintf (stderr, "%s:%d: required <option_name> <option_val>\n",
936 filename, line_num);
937 exit (EXIT_FAILURE);
938 }
939 }
940 continue;
941 }
942 if (!strcmp(fopt, "pingquiet"))
943 {
944 if (override || !args_info->pingquiet_given)
945 {
946 args_info->pingquiet_given = 1;
947 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
948 }
949 continue;
950 }
jjako52c24142002-12-16 13:33:51 +0000951
952
953 /* Tried all known options. This one is unknown! */
954 fprintf (stderr, "%s: Unknown option '%s' found in %s\n",
955 PACKAGE, fopt, filename);
956 exit (EXIT_FAILURE);
957 }
958 } /* while */
959 fclose(file); /* No error checking on close */
960
961 return 0;
962}