blob: d83376fde639dcd844d4902c65e50c581cd1c0ba [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
Harald Welte1b3e5772010-05-04 11:13:56 +02002 File autogenerated by gengetopt version 2.17
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
jjako52c24142002-12-16 13:33:51 +000011/* If we use autoconf. */
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
jjako52c24142002-12-16 13:33:51 +000015
Harald Welte1b3e5772010-05-04 11:13:56 +020016#include <stdio.h>
17#include <stdlib.h>
18#include <string.h>
19
20#include "getopt.h"
jjako52c24142002-12-16 13:33:51 +000021
22#include "cmdline.h"
23
Harald Welte1b3e5772010-05-04 11:13:56 +020024const char *gengetopt_args_info_purpose = "";
jjako52c24142002-12-16 13:33:51 +000025
Harald Welte1b3e5772010-05-04 11:13:56 +020026const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]...";
jjako52c24142002-12-16 13:33:51 +000027
Harald Welte1b3e5772010-05-04 11:13:56 +020028const char *gengetopt_args_info_help[] = {
29 " -h, --help Print help and exit",
30 " -V, --version Print version and exit",
31 " -f, --fg Run in foreground (default=off)",
32 " -d, --debug Run in debug mode (default=off)",
33 " -c, --conf=STRING Read configuration file (default=`/etc/ggsn.conf')",
34 " --pidfile=STRING Filename of process id file \n (default=`/var/run/ggsn.pid')",
35 " --statedir=STRING Directory of nonvolatile data \n (default=`/var/lib/ggsn/')",
36 " -l, --listen=STRING Local interface",
37 " -n, --net=STRING Network (default=`192.168.0.0/24')",
38 " --ipup=STRING Script to run after link-up",
39 " --ipdown=STRING Script to run after link-down",
40 " --dynip=STRING Dynamic IP address pool",
41 " --statip=STRING Static IP address pool",
42 " --pcodns1=STRING PCO DNS Server 1 (default=`0.0.0.0')",
43 " --pcodns2=STRING PCO DNS Server 2 (default=`0.0.0.0')",
44 " --timelimit=INT Exit after timelimit seconds (default=`0')",
45 " -a, --apn=STRING Access point name (default=`internet')",
46 " -q, --qos=INT Requested quality of service (default=`0x0b921f')",
47 0
48};
49
50static
51void clear_given (struct gengetopt_args_info *args_info);
52static
53void clear_args (struct gengetopt_args_info *args_info);
54
55static int
56cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
57
58struct line_list
jjako52c24142002-12-16 13:33:51 +000059{
Harald Welte1b3e5772010-05-04 11:13:56 +020060 char * string_arg;
61 struct line_list * next;
62};
63
64static struct line_list *cmd_line_list = 0;
65static struct line_list *cmd_line_list_tmp = 0;
66
67static void
68free_cmd_list(void)
69{
70 /* free the list of a previous call */
71 if (cmd_line_list)
72 {
73 while (cmd_line_list) {
74 cmd_line_list_tmp = cmd_line_list;
75 cmd_line_list = cmd_line_list->next;
76 free (cmd_line_list_tmp->string_arg);
77 free (cmd_line_list_tmp);
78 }
79 }
jjako52c24142002-12-16 13:33:51 +000080}
81
82
jjako52c24142002-12-16 13:33:51 +000083static char *
Harald Welte1b3e5772010-05-04 11:13:56 +020084gengetopt_strdup (const char *s);
jjako52c24142002-12-16 13:33:51 +000085
Harald Welte1b3e5772010-05-04 11:13:56 +020086static
87void clear_given (struct gengetopt_args_info *args_info)
jjako52c24142002-12-16 13:33:51 +000088{
jjako52c24142002-12-16 13:33:51 +000089 args_info->help_given = 0 ;
90 args_info->version_given = 0 ;
91 args_info->fg_given = 0 ;
92 args_info->debug_given = 0 ;
93 args_info->conf_given = 0 ;
94 args_info->pidfile_given = 0 ;
95 args_info->statedir_given = 0 ;
96 args_info->listen_given = 0 ;
97 args_info->net_given = 0 ;
jjakoa7cd2492003-04-11 09:40:12 +000098 args_info->ipup_given = 0 ;
99 args_info->ipdown_given = 0 ;
100 args_info->dynip_given = 0 ;
101 args_info->statip_given = 0 ;
102 args_info->pcodns1_given = 0 ;
103 args_info->pcodns2_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000104 args_info->timelimit_given = 0 ;
105 args_info->apn_given = 0 ;
106 args_info->qos_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000107}
108
Harald Welte1b3e5772010-05-04 11:13:56 +0200109static
110void clear_args (struct gengetopt_args_info *args_info)
111{
112 args_info->fg_flag = 0;
113 args_info->debug_flag = 0;
114 args_info->conf_arg = gengetopt_strdup ("/etc/ggsn.conf");
115 args_info->conf_orig = NULL;
116 args_info->pidfile_arg = gengetopt_strdup ("/var/run/ggsn.pid");
117 args_info->pidfile_orig = NULL;
118 args_info->statedir_arg = gengetopt_strdup ("/var/lib/ggsn/");
119 args_info->statedir_orig = NULL;
120 args_info->listen_arg = NULL;
121 args_info->listen_orig = NULL;
122 args_info->net_arg = gengetopt_strdup ("192.168.0.0/24");
123 args_info->net_orig = NULL;
124 args_info->ipup_arg = NULL;
125 args_info->ipup_orig = NULL;
126 args_info->ipdown_arg = NULL;
127 args_info->ipdown_orig = NULL;
128 args_info->dynip_arg = NULL;
129 args_info->dynip_orig = NULL;
130 args_info->statip_arg = NULL;
131 args_info->statip_orig = NULL;
132 args_info->pcodns1_arg = gengetopt_strdup ("0.0.0.0");
133 args_info->pcodns1_orig = NULL;
134 args_info->pcodns2_arg = gengetopt_strdup ("0.0.0.0");
135 args_info->pcodns2_orig = NULL;
136 args_info->timelimit_arg = 0;
137 args_info->timelimit_orig = NULL;
138 args_info->apn_arg = gengetopt_strdup ("internet");
139 args_info->apn_orig = NULL;
140 args_info->qos_arg = 0x0b921f;
141 args_info->qos_orig = NULL;
142
143}
144
145static
146void init_args_info(struct gengetopt_args_info *args_info)
147{
148 args_info->help_help = gengetopt_args_info_help[0] ;
149 args_info->version_help = gengetopt_args_info_help[1] ;
150 args_info->fg_help = gengetopt_args_info_help[2] ;
151 args_info->debug_help = gengetopt_args_info_help[3] ;
152 args_info->conf_help = gengetopt_args_info_help[4] ;
153 args_info->pidfile_help = gengetopt_args_info_help[5] ;
154 args_info->statedir_help = gengetopt_args_info_help[6] ;
155 args_info->listen_help = gengetopt_args_info_help[7] ;
156 args_info->net_help = gengetopt_args_info_help[8] ;
157 args_info->ipup_help = gengetopt_args_info_help[9] ;
158 args_info->ipdown_help = gengetopt_args_info_help[10] ;
159 args_info->dynip_help = gengetopt_args_info_help[11] ;
160 args_info->statip_help = gengetopt_args_info_help[12] ;
161 args_info->pcodns1_help = gengetopt_args_info_help[13] ;
162 args_info->pcodns2_help = gengetopt_args_info_help[14] ;
163 args_info->timelimit_help = gengetopt_args_info_help[15] ;
164 args_info->apn_help = gengetopt_args_info_help[16] ;
165 args_info->qos_help = gengetopt_args_info_help[17] ;
166
167}
168
169void
170cmdline_parser_print_version (void)
171{
172 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
173}
174
175void
176cmdline_parser_print_help (void)
177{
178 int i = 0;
179 cmdline_parser_print_version ();
180
181 if (strlen(gengetopt_args_info_purpose) > 0)
182 printf("\n%s\n", gengetopt_args_info_purpose);
183
184 printf("\n%s\n\n", gengetopt_args_info_usage);
185 while (gengetopt_args_info_help[i])
186 printf("%s\n", gengetopt_args_info_help[i++]);
187}
188
189void
190cmdline_parser_init (struct gengetopt_args_info *args_info)
191{
192 clear_given (args_info);
193 clear_args (args_info);
194 init_args_info (args_info);
195}
196
197static void
198cmdline_parser_release (struct gengetopt_args_info *args_info)
199{
200
201 if (args_info->conf_arg)
202 {
203 free (args_info->conf_arg); /* free previous argument */
204 args_info->conf_arg = 0;
205 }
206 if (args_info->conf_orig)
207 {
208 free (args_info->conf_orig); /* free previous argument */
209 args_info->conf_orig = 0;
210 }
211 if (args_info->pidfile_arg)
212 {
213 free (args_info->pidfile_arg); /* free previous argument */
214 args_info->pidfile_arg = 0;
215 }
216 if (args_info->pidfile_orig)
217 {
218 free (args_info->pidfile_orig); /* free previous argument */
219 args_info->pidfile_orig = 0;
220 }
221 if (args_info->statedir_arg)
222 {
223 free (args_info->statedir_arg); /* free previous argument */
224 args_info->statedir_arg = 0;
225 }
226 if (args_info->statedir_orig)
227 {
228 free (args_info->statedir_orig); /* free previous argument */
229 args_info->statedir_orig = 0;
230 }
231 if (args_info->listen_arg)
232 {
233 free (args_info->listen_arg); /* free previous argument */
234 args_info->listen_arg = 0;
235 }
236 if (args_info->listen_orig)
237 {
238 free (args_info->listen_orig); /* free previous argument */
239 args_info->listen_orig = 0;
240 }
241 if (args_info->net_arg)
242 {
243 free (args_info->net_arg); /* free previous argument */
244 args_info->net_arg = 0;
245 }
246 if (args_info->net_orig)
247 {
248 free (args_info->net_orig); /* free previous argument */
249 args_info->net_orig = 0;
250 }
251 if (args_info->ipup_arg)
252 {
253 free (args_info->ipup_arg); /* free previous argument */
254 args_info->ipup_arg = 0;
255 }
256 if (args_info->ipup_orig)
257 {
258 free (args_info->ipup_orig); /* free previous argument */
259 args_info->ipup_orig = 0;
260 }
261 if (args_info->ipdown_arg)
262 {
263 free (args_info->ipdown_arg); /* free previous argument */
264 args_info->ipdown_arg = 0;
265 }
266 if (args_info->ipdown_orig)
267 {
268 free (args_info->ipdown_orig); /* free previous argument */
269 args_info->ipdown_orig = 0;
270 }
271 if (args_info->dynip_arg)
272 {
273 free (args_info->dynip_arg); /* free previous argument */
274 args_info->dynip_arg = 0;
275 }
276 if (args_info->dynip_orig)
277 {
278 free (args_info->dynip_orig); /* free previous argument */
279 args_info->dynip_orig = 0;
280 }
281 if (args_info->statip_arg)
282 {
283 free (args_info->statip_arg); /* free previous argument */
284 args_info->statip_arg = 0;
285 }
286 if (args_info->statip_orig)
287 {
288 free (args_info->statip_orig); /* free previous argument */
289 args_info->statip_orig = 0;
290 }
291 if (args_info->pcodns1_arg)
292 {
293 free (args_info->pcodns1_arg); /* free previous argument */
294 args_info->pcodns1_arg = 0;
295 }
296 if (args_info->pcodns1_orig)
297 {
298 free (args_info->pcodns1_orig); /* free previous argument */
299 args_info->pcodns1_orig = 0;
300 }
301 if (args_info->pcodns2_arg)
302 {
303 free (args_info->pcodns2_arg); /* free previous argument */
304 args_info->pcodns2_arg = 0;
305 }
306 if (args_info->pcodns2_orig)
307 {
308 free (args_info->pcodns2_orig); /* free previous argument */
309 args_info->pcodns2_orig = 0;
310 }
311 if (args_info->timelimit_orig)
312 {
313 free (args_info->timelimit_orig); /* free previous argument */
314 args_info->timelimit_orig = 0;
315 }
316 if (args_info->apn_arg)
317 {
318 free (args_info->apn_arg); /* free previous argument */
319 args_info->apn_arg = 0;
320 }
321 if (args_info->apn_orig)
322 {
323 free (args_info->apn_orig); /* free previous argument */
324 args_info->apn_orig = 0;
325 }
326 if (args_info->qos_orig)
327 {
328 free (args_info->qos_orig); /* free previous argument */
329 args_info->qos_orig = 0;
330 }
331
332 clear_given (args_info);
333}
334
335int
336cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
337{
338 FILE *outfile;
339 int i = 0;
340
341 outfile = fopen(filename, "w");
342
343 if (!outfile)
344 {
345 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
346 return EXIT_FAILURE;
347 }
348
349 if (args_info->help_given) {
350 fprintf(outfile, "%s\n", "help");
351 }
352 if (args_info->version_given) {
353 fprintf(outfile, "%s\n", "version");
354 }
355 if (args_info->fg_given) {
356 fprintf(outfile, "%s\n", "fg");
357 }
358 if (args_info->debug_given) {
359 fprintf(outfile, "%s\n", "debug");
360 }
361 if (args_info->conf_given) {
362 if (args_info->conf_orig) {
363 fprintf(outfile, "%s=\"%s\"\n", "conf", args_info->conf_orig);
364 } else {
365 fprintf(outfile, "%s\n", "conf");
366 }
367 }
368 if (args_info->pidfile_given) {
369 if (args_info->pidfile_orig) {
370 fprintf(outfile, "%s=\"%s\"\n", "pidfile", args_info->pidfile_orig);
371 } else {
372 fprintf(outfile, "%s\n", "pidfile");
373 }
374 }
375 if (args_info->statedir_given) {
376 if (args_info->statedir_orig) {
377 fprintf(outfile, "%s=\"%s\"\n", "statedir", args_info->statedir_orig);
378 } else {
379 fprintf(outfile, "%s\n", "statedir");
380 }
381 }
382 if (args_info->listen_given) {
383 if (args_info->listen_orig) {
384 fprintf(outfile, "%s=\"%s\"\n", "listen", args_info->listen_orig);
385 } else {
386 fprintf(outfile, "%s\n", "listen");
387 }
388 }
389 if (args_info->net_given) {
390 if (args_info->net_orig) {
391 fprintf(outfile, "%s=\"%s\"\n", "net", args_info->net_orig);
392 } else {
393 fprintf(outfile, "%s\n", "net");
394 }
395 }
396 if (args_info->ipup_given) {
397 if (args_info->ipup_orig) {
398 fprintf(outfile, "%s=\"%s\"\n", "ipup", args_info->ipup_orig);
399 } else {
400 fprintf(outfile, "%s\n", "ipup");
401 }
402 }
403 if (args_info->ipdown_given) {
404 if (args_info->ipdown_orig) {
405 fprintf(outfile, "%s=\"%s\"\n", "ipdown", args_info->ipdown_orig);
406 } else {
407 fprintf(outfile, "%s\n", "ipdown");
408 }
409 }
410 if (args_info->dynip_given) {
411 if (args_info->dynip_orig) {
412 fprintf(outfile, "%s=\"%s\"\n", "dynip", args_info->dynip_orig);
413 } else {
414 fprintf(outfile, "%s\n", "dynip");
415 }
416 }
417 if (args_info->statip_given) {
418 if (args_info->statip_orig) {
419 fprintf(outfile, "%s=\"%s\"\n", "statip", args_info->statip_orig);
420 } else {
421 fprintf(outfile, "%s\n", "statip");
422 }
423 }
424 if (args_info->pcodns1_given) {
425 if (args_info->pcodns1_orig) {
426 fprintf(outfile, "%s=\"%s\"\n", "pcodns1", args_info->pcodns1_orig);
427 } else {
428 fprintf(outfile, "%s\n", "pcodns1");
429 }
430 }
431 if (args_info->pcodns2_given) {
432 if (args_info->pcodns2_orig) {
433 fprintf(outfile, "%s=\"%s\"\n", "pcodns2", args_info->pcodns2_orig);
434 } else {
435 fprintf(outfile, "%s\n", "pcodns2");
436 }
437 }
438 if (args_info->timelimit_given) {
439 if (args_info->timelimit_orig) {
440 fprintf(outfile, "%s=\"%s\"\n", "timelimit", args_info->timelimit_orig);
441 } else {
442 fprintf(outfile, "%s\n", "timelimit");
443 }
444 }
445 if (args_info->apn_given) {
446 if (args_info->apn_orig) {
447 fprintf(outfile, "%s=\"%s\"\n", "apn", args_info->apn_orig);
448 } else {
449 fprintf(outfile, "%s\n", "apn");
450 }
451 }
452 if (args_info->qos_given) {
453 if (args_info->qos_orig) {
454 fprintf(outfile, "%s=\"%s\"\n", "qos", args_info->qos_orig);
455 } else {
456 fprintf(outfile, "%s\n", "qos");
457 }
458 }
459
460 fclose (outfile);
461
462 i = EXIT_SUCCESS;
463 return i;
464}
465
466void
467cmdline_parser_free (struct gengetopt_args_info *args_info)
468{
469 cmdline_parser_release (args_info);
470}
471
472
473/* gengetopt_strdup() */
474/* strdup.c replacement of strdup, which is not standard */
475char *
476gengetopt_strdup (const char *s)
477{
478 char *result = NULL;
479 if (!s)
480 return result;
481
482 result = (char*)malloc(strlen(s) + 1);
483 if (result == (char*)0)
484 return (char*)0;
485 strcpy(result, s);
486 return result;
487}
488
489int
490cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
491{
492 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
493}
494
495int
496cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
497{
498 int result;
499
500 result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
501
502 if (result == EXIT_FAILURE)
503 {
504 cmdline_parser_free (args_info);
505 exit (EXIT_FAILURE);
506 }
507
508 return result;
509}
510
511int
512cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
513{
514 return EXIT_SUCCESS;
515}
516
517int
518cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
519{
520 int c; /* Character of the parsed option. */
521
522 int error = 0;
523 struct gengetopt_args_info local_args_info;
524
525 if (initialize)
526 cmdline_parser_init (args_info);
527
528 cmdline_parser_init (&local_args_info);
jjako52c24142002-12-16 13:33:51 +0000529
530 optarg = 0;
Harald Welte1b3e5772010-05-04 11:13:56 +0200531 optind = 0;
jjako52c24142002-12-16 13:33:51 +0000532 opterr = 1;
533 optopt = '?';
534
535 while (1)
536 {
537 int option_index = 0;
538 char *stop_char;
Harald Welte1b3e5772010-05-04 11:13:56 +0200539
jjako52c24142002-12-16 13:33:51 +0000540 static struct option long_options[] = {
541 { "help", 0, NULL, 'h' },
542 { "version", 0, NULL, 'V' },
543 { "fg", 0, NULL, 'f' },
544 { "debug", 0, NULL, 'd' },
545 { "conf", 1, NULL, 'c' },
546 { "pidfile", 1, NULL, 0 },
547 { "statedir", 1, NULL, 0 },
548 { "listen", 1, NULL, 'l' },
549 { "net", 1, NULL, 'n' },
jjakoa7cd2492003-04-11 09:40:12 +0000550 { "ipup", 1, NULL, 0 },
551 { "ipdown", 1, NULL, 0 },
552 { "dynip", 1, NULL, 0 },
553 { "statip", 1, NULL, 0 },
554 { "pcodns1", 1, NULL, 0 },
555 { "pcodns2", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000556 { "timelimit", 1, NULL, 0 },
557 { "apn", 1, NULL, 'a' },
558 { "qos", 1, NULL, 'q' },
559 { NULL, 0, NULL, 0 }
560 };
561
Harald Welte1b3e5772010-05-04 11:13:56 +0200562 stop_char = 0;
jjako52c24142002-12-16 13:33:51 +0000563 c = getopt_long (argc, argv, "hVfdc:l:n:a:q:", long_options, &option_index);
564
565 if (c == -1) break; /* Exit from `while (1)' loop. */
566
567 switch (c)
568 {
569 case 'h': /* Print help and exit. */
jjako52c24142002-12-16 13:33:51 +0000570 cmdline_parser_print_help ();
Harald Welte1b3e5772010-05-04 11:13:56 +0200571 cmdline_parser_free (&local_args_info);
jjako52c24142002-12-16 13:33:51 +0000572 exit (EXIT_SUCCESS);
573
574 case 'V': /* Print version and exit. */
jjako52c24142002-12-16 13:33:51 +0000575 cmdline_parser_print_version ();
Harald Welte1b3e5772010-05-04 11:13:56 +0200576 cmdline_parser_free (&local_args_info);
jjako52c24142002-12-16 13:33:51 +0000577 exit (EXIT_SUCCESS);
578
579 case 'f': /* Run in foreground. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200580 if (local_args_info.fg_given)
jjako52c24142002-12-16 13:33:51 +0000581 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200582 fprintf (stderr, "%s: `--fg' (`-f') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
583 goto failure;
jjako52c24142002-12-16 13:33:51 +0000584 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200585 if (args_info->fg_given && ! override)
586 continue;
587 local_args_info.fg_given = 1;
jjako52c24142002-12-16 13:33:51 +0000588 args_info->fg_given = 1;
589 args_info->fg_flag = !(args_info->fg_flag);
590 break;
591
592 case 'd': /* Run in debug mode. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200593 if (local_args_info.debug_given)
jjako52c24142002-12-16 13:33:51 +0000594 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200595 fprintf (stderr, "%s: `--debug' (`-d') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
596 goto failure;
jjako52c24142002-12-16 13:33:51 +0000597 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200598 if (args_info->debug_given && ! override)
599 continue;
600 local_args_info.debug_given = 1;
jjako52c24142002-12-16 13:33:51 +0000601 args_info->debug_given = 1;
602 args_info->debug_flag = !(args_info->debug_flag);
603 break;
604
605 case 'c': /* Read configuration file. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200606 if (local_args_info.conf_given)
jjako52c24142002-12-16 13:33:51 +0000607 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200608 fprintf (stderr, "%s: `--conf' (`-c') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
609 goto failure;
jjako52c24142002-12-16 13:33:51 +0000610 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200611 if (args_info->conf_given && ! override)
612 continue;
613 local_args_info.conf_given = 1;
jjako52c24142002-12-16 13:33:51 +0000614 args_info->conf_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200615 if (args_info->conf_arg)
616 free (args_info->conf_arg); /* free previous string */
617 args_info->conf_arg = gengetopt_strdup (optarg);
618 if (args_info->conf_orig)
619 free (args_info->conf_orig); /* free previous string */
620 args_info->conf_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000621 break;
622
623 case 'l': /* Local interface. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200624 if (local_args_info.listen_given)
jjako52c24142002-12-16 13:33:51 +0000625 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200626 fprintf (stderr, "%s: `--listen' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
627 goto failure;
jjako52c24142002-12-16 13:33:51 +0000628 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200629 if (args_info->listen_given && ! override)
630 continue;
631 local_args_info.listen_given = 1;
jjako52c24142002-12-16 13:33:51 +0000632 args_info->listen_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200633 if (args_info->listen_arg)
634 free (args_info->listen_arg); /* free previous string */
635 args_info->listen_arg = gengetopt_strdup (optarg);
636 if (args_info->listen_orig)
637 free (args_info->listen_orig); /* free previous string */
638 args_info->listen_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000639 break;
640
641 case 'n': /* Network. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200642 if (local_args_info.net_given)
jjako52c24142002-12-16 13:33:51 +0000643 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200644 fprintf (stderr, "%s: `--net' (`-n') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
645 goto failure;
jjako52c24142002-12-16 13:33:51 +0000646 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200647 if (args_info->net_given && ! override)
648 continue;
649 local_args_info.net_given = 1;
jjako52c24142002-12-16 13:33:51 +0000650 args_info->net_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200651 if (args_info->net_arg)
652 free (args_info->net_arg); /* free previous string */
653 args_info->net_arg = gengetopt_strdup (optarg);
654 if (args_info->net_orig)
655 free (args_info->net_orig); /* free previous string */
656 args_info->net_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000657 break;
658
659 case 'a': /* Access point name. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200660 if (local_args_info.apn_given)
jjako52c24142002-12-16 13:33:51 +0000661 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200662 fprintf (stderr, "%s: `--apn' (`-a') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
663 goto failure;
jjako52c24142002-12-16 13:33:51 +0000664 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200665 if (args_info->apn_given && ! override)
666 continue;
667 local_args_info.apn_given = 1;
jjako52c24142002-12-16 13:33:51 +0000668 args_info->apn_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200669 if (args_info->apn_arg)
670 free (args_info->apn_arg); /* free previous string */
671 args_info->apn_arg = gengetopt_strdup (optarg);
672 if (args_info->apn_orig)
673 free (args_info->apn_orig); /* free previous string */
674 args_info->apn_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000675 break;
676
677 case 'q': /* Requested quality of service. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200678 if (local_args_info.qos_given)
jjako52c24142002-12-16 13:33:51 +0000679 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200680 fprintf (stderr, "%s: `--qos' (`-q') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
681 goto failure;
jjako52c24142002-12-16 13:33:51 +0000682 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200683 if (args_info->qos_given && ! override)
684 continue;
685 local_args_info.qos_given = 1;
jjako52c24142002-12-16 13:33:51 +0000686 args_info->qos_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200687 args_info->qos_arg = strtol (optarg, &stop_char, 0);
688 if (!(stop_char && *stop_char == '\0')) {
689 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
690 goto failure;
691 }
692 if (args_info->qos_orig)
693 free (args_info->qos_orig); /* free previous string */
694 args_info->qos_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000695 break;
696
697
698 case 0: /* Long option with no short option */
699 /* Filename of process id file. */
700 if (strcmp (long_options[option_index].name, "pidfile") == 0)
701 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200702 if (local_args_info.pidfile_given)
jjako52c24142002-12-16 13:33:51 +0000703 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200704 fprintf (stderr, "%s: `--pidfile' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
705 goto failure;
jjako52c24142002-12-16 13:33:51 +0000706 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200707 if (args_info->pidfile_given && ! override)
708 continue;
709 local_args_info.pidfile_given = 1;
jjako52c24142002-12-16 13:33:51 +0000710 args_info->pidfile_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200711 if (args_info->pidfile_arg)
712 free (args_info->pidfile_arg); /* free previous string */
713 args_info->pidfile_arg = gengetopt_strdup (optarg);
714 if (args_info->pidfile_orig)
715 free (args_info->pidfile_orig); /* free previous string */
716 args_info->pidfile_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000717 }
718 /* Directory of nonvolatile data. */
719 else if (strcmp (long_options[option_index].name, "statedir") == 0)
720 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200721 if (local_args_info.statedir_given)
jjako52c24142002-12-16 13:33:51 +0000722 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200723 fprintf (stderr, "%s: `--statedir' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
724 goto failure;
jjako52c24142002-12-16 13:33:51 +0000725 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200726 if (args_info->statedir_given && ! override)
727 continue;
728 local_args_info.statedir_given = 1;
jjako52c24142002-12-16 13:33:51 +0000729 args_info->statedir_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200730 if (args_info->statedir_arg)
731 free (args_info->statedir_arg); /* free previous string */
732 args_info->statedir_arg = gengetopt_strdup (optarg);
733 if (args_info->statedir_orig)
734 free (args_info->statedir_orig); /* free previous string */
735 args_info->statedir_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000736 }
jjako4b26b512003-01-28 16:13:57 +0000737 /* Script to run after link-up. */
738 else if (strcmp (long_options[option_index].name, "ipup") == 0)
739 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200740 if (local_args_info.ipup_given)
jjako4b26b512003-01-28 16:13:57 +0000741 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200742 fprintf (stderr, "%s: `--ipup' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
743 goto failure;
jjako4b26b512003-01-28 16:13:57 +0000744 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200745 if (args_info->ipup_given && ! override)
746 continue;
747 local_args_info.ipup_given = 1;
jjako4b26b512003-01-28 16:13:57 +0000748 args_info->ipup_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200749 if (args_info->ipup_arg)
750 free (args_info->ipup_arg); /* free previous string */
751 args_info->ipup_arg = gengetopt_strdup (optarg);
752 if (args_info->ipup_orig)
753 free (args_info->ipup_orig); /* free previous string */
754 args_info->ipup_orig = gengetopt_strdup (optarg);
jjako4b26b512003-01-28 16:13:57 +0000755 }
756 /* Script to run after link-down. */
757 else if (strcmp (long_options[option_index].name, "ipdown") == 0)
758 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200759 if (local_args_info.ipdown_given)
jjako4b26b512003-01-28 16:13:57 +0000760 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200761 fprintf (stderr, "%s: `--ipdown' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
762 goto failure;
jjako4b26b512003-01-28 16:13:57 +0000763 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200764 if (args_info->ipdown_given && ! override)
765 continue;
766 local_args_info.ipdown_given = 1;
jjako4b26b512003-01-28 16:13:57 +0000767 args_info->ipdown_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200768 if (args_info->ipdown_arg)
769 free (args_info->ipdown_arg); /* free previous string */
770 args_info->ipdown_arg = gengetopt_strdup (optarg);
771 if (args_info->ipdown_orig)
772 free (args_info->ipdown_orig); /* free previous string */
773 args_info->ipdown_orig = gengetopt_strdup (optarg);
jjako4b26b512003-01-28 16:13:57 +0000774 }
jjakoa7cd2492003-04-11 09:40:12 +0000775 /* Dynamic IP address pool. */
776 else if (strcmp (long_options[option_index].name, "dynip") == 0)
777 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200778 if (local_args_info.dynip_given)
jjakoa7cd2492003-04-11 09:40:12 +0000779 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200780 fprintf (stderr, "%s: `--dynip' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
781 goto failure;
jjakoa7cd2492003-04-11 09:40:12 +0000782 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200783 if (args_info->dynip_given && ! override)
784 continue;
785 local_args_info.dynip_given = 1;
jjakoa7cd2492003-04-11 09:40:12 +0000786 args_info->dynip_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200787 if (args_info->dynip_arg)
788 free (args_info->dynip_arg); /* free previous string */
789 args_info->dynip_arg = gengetopt_strdup (optarg);
790 if (args_info->dynip_orig)
791 free (args_info->dynip_orig); /* free previous string */
792 args_info->dynip_orig = gengetopt_strdup (optarg);
jjakoa7cd2492003-04-11 09:40:12 +0000793 }
794 /* Static IP address pool. */
795 else if (strcmp (long_options[option_index].name, "statip") == 0)
796 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200797 if (local_args_info.statip_given)
jjakoa7cd2492003-04-11 09:40:12 +0000798 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200799 fprintf (stderr, "%s: `--statip' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
800 goto failure;
jjakoa7cd2492003-04-11 09:40:12 +0000801 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200802 if (args_info->statip_given && ! override)
803 continue;
804 local_args_info.statip_given = 1;
jjakoa7cd2492003-04-11 09:40:12 +0000805 args_info->statip_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200806 if (args_info->statip_arg)
807 free (args_info->statip_arg); /* free previous string */
808 args_info->statip_arg = gengetopt_strdup (optarg);
809 if (args_info->statip_orig)
810 free (args_info->statip_orig); /* free previous string */
811 args_info->statip_orig = gengetopt_strdup (optarg);
jjakoa7cd2492003-04-11 09:40:12 +0000812 }
813 /* PCO DNS Server 1. */
814 else if (strcmp (long_options[option_index].name, "pcodns1") == 0)
815 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200816 if (local_args_info.pcodns1_given)
jjakoa7cd2492003-04-11 09:40:12 +0000817 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200818 fprintf (stderr, "%s: `--pcodns1' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
819 goto failure;
jjakoa7cd2492003-04-11 09:40:12 +0000820 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200821 if (args_info->pcodns1_given && ! override)
822 continue;
823 local_args_info.pcodns1_given = 1;
jjakoa7cd2492003-04-11 09:40:12 +0000824 args_info->pcodns1_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200825 if (args_info->pcodns1_arg)
826 free (args_info->pcodns1_arg); /* free previous string */
827 args_info->pcodns1_arg = gengetopt_strdup (optarg);
828 if (args_info->pcodns1_orig)
829 free (args_info->pcodns1_orig); /* free previous string */
830 args_info->pcodns1_orig = gengetopt_strdup (optarg);
jjakoa7cd2492003-04-11 09:40:12 +0000831 }
832 /* PCO DNS Server 2. */
833 else if (strcmp (long_options[option_index].name, "pcodns2") == 0)
834 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200835 if (local_args_info.pcodns2_given)
jjakoa7cd2492003-04-11 09:40:12 +0000836 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200837 fprintf (stderr, "%s: `--pcodns2' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
838 goto failure;
jjakoa7cd2492003-04-11 09:40:12 +0000839 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200840 if (args_info->pcodns2_given && ! override)
841 continue;
842 local_args_info.pcodns2_given = 1;
jjakoa7cd2492003-04-11 09:40:12 +0000843 args_info->pcodns2_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200844 if (args_info->pcodns2_arg)
845 free (args_info->pcodns2_arg); /* free previous string */
846 args_info->pcodns2_arg = gengetopt_strdup (optarg);
847 if (args_info->pcodns2_orig)
848 free (args_info->pcodns2_orig); /* free previous string */
849 args_info->pcodns2_orig = gengetopt_strdup (optarg);
jjakoa7cd2492003-04-11 09:40:12 +0000850 }
851 /* Exit after timelimit seconds. */
852 else if (strcmp (long_options[option_index].name, "timelimit") == 0)
853 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200854 if (local_args_info.timelimit_given)
jjakoa7cd2492003-04-11 09:40:12 +0000855 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200856 fprintf (stderr, "%s: `--timelimit' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
857 goto failure;
jjakoa7cd2492003-04-11 09:40:12 +0000858 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200859 if (args_info->timelimit_given && ! override)
860 continue;
861 local_args_info.timelimit_given = 1;
jjakoa7cd2492003-04-11 09:40:12 +0000862 args_info->timelimit_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200863 args_info->timelimit_arg = strtol (optarg, &stop_char, 0);
864 if (!(stop_char && *stop_char == '\0')) {
865 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
866 goto failure;
867 }
868 if (args_info->timelimit_orig)
869 free (args_info->timelimit_orig); /* free previous string */
870 args_info->timelimit_orig = gengetopt_strdup (optarg);
jjakoa7cd2492003-04-11 09:40:12 +0000871 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200872
873 break;
jjako52c24142002-12-16 13:33:51 +0000874 case '?': /* Invalid option. */
875 /* `getopt_long' already printed an error message. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200876 goto failure;
jjako52c24142002-12-16 13:33:51 +0000877
878 default: /* bug: option not considered. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200879 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
jjako52c24142002-12-16 13:33:51 +0000880 abort ();
881 } /* switch */
882 } /* while */
883
884
Harald Welte1b3e5772010-05-04 11:13:56 +0200885
886
887 cmdline_parser_release (&local_args_info);
888
889 if ( error )
890 return (EXIT_FAILURE);
jjako52c24142002-12-16 13:33:51 +0000891
892 return 0;
Harald Welte1b3e5772010-05-04 11:13:56 +0200893
894failure:
895
896 cmdline_parser_release (&local_args_info);
897 return (EXIT_FAILURE);
jjako52c24142002-12-16 13:33:51 +0000898}
899
Harald Welte1b3e5772010-05-04 11:13:56 +0200900#ifndef CONFIG_FILE_LINE_SIZE
901#define CONFIG_FILE_LINE_SIZE 2048
902#endif
903#define ADDITIONAL_ERROR " in configuration file "
904
905#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
906/* 3 is for "--" and "=" */
907
908char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
jjako52c24142002-12-16 13:33:51 +0000909
910int
Harald Welte1b3e5772010-05-04 11:13:56 +0200911cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
jjako52c24142002-12-16 13:33:51 +0000912{
913 FILE* file;
Harald Welte1b3e5772010-05-04 11:13:56 +0200914 char linebuf[CONFIG_FILE_LINE_SIZE];
jjako52c24142002-12-16 13:33:51 +0000915 int line_num = 0;
Harald Welte1b3e5772010-05-04 11:13:56 +0200916 int i, result, equal;
917 char *fopt, *farg;
918 char *str_index;
919 size_t len, next_token;
920 char delimiter;
921 int my_argc = 0;
922 char **my_argv_arg;
923 char *additional_error;
924
925 /* store the program name */
926 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
927 cmd_line_list_tmp->next = cmd_line_list;
928 cmd_line_list = cmd_line_list_tmp;
929 cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_PACKAGE);
jjako52c24142002-12-16 13:33:51 +0000930
931 if ((file = fopen(filename, "r")) == NULL)
932 {
933 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
Harald Welte1b3e5772010-05-04 11:13:56 +0200934 CMDLINE_PARSER_PACKAGE, filename);
935 result = EXIT_FAILURE;
936 goto conf_failure;
jjako52c24142002-12-16 13:33:51 +0000937 }
938
Harald Welte1b3e5772010-05-04 11:13:56 +0200939 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
jjako52c24142002-12-16 13:33:51 +0000940 {
941 ++line_num;
Harald Welte1b3e5772010-05-04 11:13:56 +0200942 my_argv[0] = '\0';
jjako52c24142002-12-16 13:33:51 +0000943 len = strlen(linebuf);
Harald Welte1b3e5772010-05-04 11:13:56 +0200944 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
jjako52c24142002-12-16 13:33:51 +0000945 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200946 fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
947 CMDLINE_PARSER_PACKAGE, filename, line_num);
948 result = EXIT_FAILURE;
949 goto conf_failure;
jjako52c24142002-12-16 13:33:51 +0000950 }
951
Harald Welte1b3e5772010-05-04 11:13:56 +0200952 /* find first non-whitespace character in the line */
953 next_token = strspn ( linebuf, " \t\r\n");
954 str_index = linebuf + next_token;
jjako52c24142002-12-16 13:33:51 +0000955
Harald Welte1b3e5772010-05-04 11:13:56 +0200956 if ( str_index[0] == '\0' || str_index[0] == '#')
957 continue; /* empty line or comment line is skipped */
958
959 fopt = str_index;
960
961 /* truncate fopt at the end of the first non-valid character */
962 next_token = strcspn (fopt, " \t\r\n=");
963
964 if (fopt[next_token] == '\0') /* the line is over */
965 {
966 farg = NULL;
967 equal = 0;
968 goto noarg;
jjako52c24142002-12-16 13:33:51 +0000969 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200970
971 /* remember if equal sign is present */
972 equal = (fopt[next_token] == '=');
973 fopt[next_token++] = '\0';
974
975 /* advance pointers to the next token after the end of fopt */
976 next_token += strspn (fopt + next_token, " \t\r\n");
977 /* check for the presence of equal sign, and if so, skip it */
978 if ( !equal )
979 if ((equal = (fopt[next_token] == '=')))
980 {
981 next_token++;
982 next_token += strspn (fopt + next_token, " \t\r\n");
983 }
984 str_index += next_token;
985
986 /* find argument */
987 farg = str_index;
988 if ( farg[0] == '\"' || farg[0] == '\'' )
989 { /* quoted argument */
990 str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
991 if (! str_index)
992 {
993 fprintf
994 (stderr,
995 "%s:%s:%d: unterminated string in configuration file\n",
996 CMDLINE_PARSER_PACKAGE, filename, line_num);
997 result = EXIT_FAILURE;
998 goto conf_failure;
999 }
1000 }
1001 else
1002 { /* read up the remaining part up to a delimiter */
1003 next_token = strcspn (farg, " \t\r\n#\'\"");
1004 str_index += next_token;
1005 }
1006
1007 /* truncate farg at the delimiter and store it for further check */
1008 delimiter = *str_index, *str_index++ = '\0';
1009
1010 /* everything but comment is illegal at the end of line */
1011 if (delimiter != '\0' && delimiter != '#')
1012 {
1013 str_index += strspn(str_index, " \t\r\n");
1014 if (*str_index != '\0' && *str_index != '#')
1015 {
1016 fprintf
1017 (stderr,
1018 "%s:%s:%d: malformed string in configuration file\n",
1019 CMDLINE_PARSER_PACKAGE, filename, line_num);
1020 result = EXIT_FAILURE;
1021 goto conf_failure;
1022 }
1023 }
1024
1025 noarg:
1026 ++my_argc;
1027 len = strlen(fopt);
1028
1029 strcat (my_argv, len > 1 ? "--" : "-");
1030 strcat (my_argv, fopt);
1031 if (len > 1 && ((farg &&*farg) || equal))
1032 strcat (my_argv, "=");
1033 if (farg && *farg)
1034 strcat (my_argv, farg);
1035
1036 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1037 cmd_line_list_tmp->next = cmd_line_list;
1038 cmd_line_list = cmd_line_list_tmp;
1039 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
jjako52c24142002-12-16 13:33:51 +00001040 } /* while */
jjako52c24142002-12-16 13:33:51 +00001041
Harald Welte1b3e5772010-05-04 11:13:56 +02001042 ++my_argc; /* for program name */
1043 my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
1044 cmd_line_list_tmp = cmd_line_list;
1045 for (i = my_argc - 1; i >= 0; --i) {
1046 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1047 cmd_line_list_tmp = cmd_line_list_tmp->next;
1048 }
1049 my_argv_arg[my_argc] = 0;
1050
1051 additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1052 strcpy (additional_error, ADDITIONAL_ERROR);
1053 strcat (additional_error, filename);
1054 result =
1055 cmdline_parser_internal (my_argc, my_argv_arg, args_info, override, initialize, check_required, additional_error);
1056
1057 free (additional_error);
1058 free (my_argv_arg);
1059
1060conf_failure:
1061 if (file)
1062 fclose(file);
1063
1064 free_cmd_list();
1065 if (result == EXIT_FAILURE)
1066 {
1067 cmdline_parser_free (args_info);
1068 exit (EXIT_FAILURE);
1069 }
1070
1071 return result;
jjako52c24142002-12-16 13:33:51 +00001072}