blob: c5da6b47b0b47f50e53a7e653bf6ad90ad431117 [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 Weltebed35df2011-11-02 13:06:18 +010026const char *gengetopt_args_info_usage =
27 "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]...";
jjako52c24142002-12-16 13:33:51 +000028
Harald Welte1b3e5772010-05-04 11:13:56 +020029const char *gengetopt_args_info_help[] = {
Harald Weltebed35df2011-11-02 13:06:18 +010030 " -h, --help Print help and exit",
31 " -V, --version Print version and exit",
32 " -f, --fg Run in foreground (default=off)",
33 " -d, --debug Run in debug mode (default=off)",
34 " -c, --conf=STRING Read configuration file (default=`/etc/ggsn.conf')",
35 " --pidfile=STRING Filename of process id file \n (default=`/var/run/ggsn.pid')",
36 " --statedir=STRING Directory of nonvolatile data \n (default=`/var/lib/ggsn/')",
37 " -l, --listen=STRING Local interface",
38 " -n, --net=STRING Network (default=`192.168.0.0/24')",
39 " --ipup=STRING Script to run after link-up",
40 " --ipdown=STRING Script to run after link-down",
41 " --dynip=STRING Dynamic IP address pool",
42 " --statip=STRING Static IP address pool",
43 " --pcodns1=STRING PCO DNS Server 1 (default=`0.0.0.0')",
44 " --pcodns2=STRING PCO DNS Server 2 (default=`0.0.0.0')",
45 " --timelimit=INT Exit after timelimit seconds (default=`0')",
46 " -a, --apn=STRING Access point name (default=`internet')",
47 " -q, --qos=INT Requested quality of service (default=`0x0b921f')",
48 0
Harald Welte1b3e5772010-05-04 11:13:56 +020049};
50
51static
Harald Weltebed35df2011-11-02 13:06:18 +010052void clear_given(struct gengetopt_args_info *args_info);
Harald Welte1b3e5772010-05-04 11:13:56 +020053static
Harald Weltebed35df2011-11-02 13:06:18 +010054void clear_args(struct gengetopt_args_info *args_info);
Harald Welte1b3e5772010-05-04 11:13:56 +020055
56static int
Harald Weltebed35df2011-11-02 13:06:18 +010057cmdline_parser_internal(int argc, char *const *argv,
58 struct gengetopt_args_info *args_info, int override,
59 int initialize, int check_required,
60 const char *additional_error);
Harald Welte1b3e5772010-05-04 11:13:56 +020061
Harald Weltebed35df2011-11-02 13:06:18 +010062struct line_list {
63 char *string_arg;
64 struct line_list *next;
Harald Welte1b3e5772010-05-04 11:13:56 +020065};
66
67static struct line_list *cmd_line_list = 0;
68static struct line_list *cmd_line_list_tmp = 0;
69
Harald Weltebed35df2011-11-02 13:06:18 +010070static void free_cmd_list(void)
Harald Welte1b3e5772010-05-04 11:13:56 +020071{
Harald Weltebed35df2011-11-02 13:06:18 +010072 /* free the list of a previous call */
73 if (cmd_line_list) {
74 while (cmd_line_list) {
75 cmd_line_list_tmp = cmd_line_list;
76 cmd_line_list = cmd_line_list->next;
77 free(cmd_line_list_tmp->string_arg);
78 free(cmd_line_list_tmp);
79 }
80 }
jjako52c24142002-12-16 13:33:51 +000081}
82
Harald Weltebed35df2011-11-02 13:06:18 +010083static char *gengetopt_strdup(const char *s);
jjako52c24142002-12-16 13:33:51 +000084
Harald Welte1b3e5772010-05-04 11:13:56 +020085static
Harald Weltebed35df2011-11-02 13:06:18 +010086void clear_given(struct gengetopt_args_info *args_info)
jjako52c24142002-12-16 13:33:51 +000087{
Harald Weltebed35df2011-11-02 13:06:18 +010088 args_info->help_given = 0;
89 args_info->version_given = 0;
90 args_info->fg_given = 0;
91 args_info->debug_given = 0;
92 args_info->conf_given = 0;
93 args_info->pidfile_given = 0;
94 args_info->statedir_given = 0;
95 args_info->listen_given = 0;
96 args_info->net_given = 0;
97 args_info->ipup_given = 0;
98 args_info->ipdown_given = 0;
99 args_info->dynip_given = 0;
100 args_info->statip_given = 0;
101 args_info->pcodns1_given = 0;
102 args_info->pcodns2_given = 0;
103 args_info->timelimit_given = 0;
104 args_info->apn_given = 0;
105 args_info->qos_given = 0;
jjako52c24142002-12-16 13:33:51 +0000106}
107
Harald Welte1b3e5772010-05-04 11:13:56 +0200108static
Harald Weltebed35df2011-11-02 13:06:18 +0100109void clear_args(struct gengetopt_args_info *args_info)
Harald Welte1b3e5772010-05-04 11:13:56 +0200110{
Harald Weltebed35df2011-11-02 13:06:18 +0100111 args_info->fg_flag = 0;
112 args_info->debug_flag = 0;
113 args_info->conf_arg = gengetopt_strdup("/etc/ggsn.conf");
114 args_info->conf_orig = NULL;
115 args_info->pidfile_arg = gengetopt_strdup("/var/run/ggsn.pid");
116 args_info->pidfile_orig = NULL;
117 args_info->statedir_arg = gengetopt_strdup("/var/lib/ggsn/");
118 args_info->statedir_orig = NULL;
119 args_info->listen_arg = NULL;
120 args_info->listen_orig = NULL;
121 args_info->net_arg = gengetopt_strdup("192.168.0.0/24");
122 args_info->net_orig = NULL;
123 args_info->ipup_arg = NULL;
124 args_info->ipup_orig = NULL;
125 args_info->ipdown_arg = NULL;
126 args_info->ipdown_orig = NULL;
127 args_info->dynip_arg = NULL;
128 args_info->dynip_orig = NULL;
129 args_info->statip_arg = NULL;
130 args_info->statip_orig = NULL;
131 args_info->pcodns1_arg = gengetopt_strdup("0.0.0.0");
132 args_info->pcodns1_orig = NULL;
133 args_info->pcodns2_arg = gengetopt_strdup("0.0.0.0");
134 args_info->pcodns2_orig = NULL;
135 args_info->timelimit_arg = 0;
136 args_info->timelimit_orig = NULL;
137 args_info->apn_arg = gengetopt_strdup("internet");
138 args_info->apn_orig = NULL;
139 args_info->qos_arg = 0x0b921f;
140 args_info->qos_orig = NULL;
141
Harald Welte1b3e5772010-05-04 11:13:56 +0200142}
143
144static
145void init_args_info(struct gengetopt_args_info *args_info)
146{
Harald Weltebed35df2011-11-02 13:06:18 +0100147 args_info->help_help = gengetopt_args_info_help[0];
148 args_info->version_help = gengetopt_args_info_help[1];
149 args_info->fg_help = gengetopt_args_info_help[2];
150 args_info->debug_help = gengetopt_args_info_help[3];
151 args_info->conf_help = gengetopt_args_info_help[4];
152 args_info->pidfile_help = gengetopt_args_info_help[5];
153 args_info->statedir_help = gengetopt_args_info_help[6];
154 args_info->listen_help = gengetopt_args_info_help[7];
155 args_info->net_help = gengetopt_args_info_help[8];
156 args_info->ipup_help = gengetopt_args_info_help[9];
157 args_info->ipdown_help = gengetopt_args_info_help[10];
158 args_info->dynip_help = gengetopt_args_info_help[11];
159 args_info->statip_help = gengetopt_args_info_help[12];
160 args_info->pcodns1_help = gengetopt_args_info_help[13];
161 args_info->pcodns2_help = gengetopt_args_info_help[14];
162 args_info->timelimit_help = gengetopt_args_info_help[15];
163 args_info->apn_help = gengetopt_args_info_help[16];
164 args_info->qos_help = gengetopt_args_info_help[17];
165
Harald Welte1b3e5772010-05-04 11:13:56 +0200166}
167
Harald Weltebed35df2011-11-02 13:06:18 +0100168void cmdline_parser_print_version(void)
Harald Welte1b3e5772010-05-04 11:13:56 +0200169{
Harald Weltebed35df2011-11-02 13:06:18 +0100170 printf("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
Harald Welte1b3e5772010-05-04 11:13:56 +0200171}
172
Harald Weltebed35df2011-11-02 13:06:18 +0100173void cmdline_parser_print_help(void)
Harald Welte1b3e5772010-05-04 11:13:56 +0200174{
Harald Weltebed35df2011-11-02 13:06:18 +0100175 int i = 0;
176 cmdline_parser_print_version();
Harald Welte1b3e5772010-05-04 11:13:56 +0200177
Harald Weltebed35df2011-11-02 13:06:18 +0100178 if (strlen(gengetopt_args_info_purpose) > 0)
179 printf("\n%s\n", gengetopt_args_info_purpose);
Harald Welte1b3e5772010-05-04 11:13:56 +0200180
Harald Weltebed35df2011-11-02 13:06:18 +0100181 printf("\n%s\n\n", gengetopt_args_info_usage);
182 while (gengetopt_args_info_help[i])
183 printf("%s\n", gengetopt_args_info_help[i++]);
Harald Welte1b3e5772010-05-04 11:13:56 +0200184}
185
Harald Weltebed35df2011-11-02 13:06:18 +0100186void cmdline_parser_init(struct gengetopt_args_info *args_info)
Harald Welte1b3e5772010-05-04 11:13:56 +0200187{
Harald Weltebed35df2011-11-02 13:06:18 +0100188 clear_given(args_info);
189 clear_args(args_info);
190 init_args_info(args_info);
Harald Welte1b3e5772010-05-04 11:13:56 +0200191}
192
Harald Weltebed35df2011-11-02 13:06:18 +0100193static void cmdline_parser_release(struct gengetopt_args_info *args_info)
Harald Welte1b3e5772010-05-04 11:13:56 +0200194{
Harald Weltebed35df2011-11-02 13:06:18 +0100195
196 if (args_info->conf_arg) {
197 free(args_info->conf_arg); /* free previous argument */
198 args_info->conf_arg = 0;
199 }
200 if (args_info->conf_orig) {
201 free(args_info->conf_orig); /* free previous argument */
202 args_info->conf_orig = 0;
203 }
204 if (args_info->pidfile_arg) {
205 free(args_info->pidfile_arg); /* free previous argument */
206 args_info->pidfile_arg = 0;
207 }
208 if (args_info->pidfile_orig) {
209 free(args_info->pidfile_orig); /* free previous argument */
210 args_info->pidfile_orig = 0;
211 }
212 if (args_info->statedir_arg) {
213 free(args_info->statedir_arg); /* free previous argument */
214 args_info->statedir_arg = 0;
215 }
216 if (args_info->statedir_orig) {
217 free(args_info->statedir_orig); /* free previous argument */
218 args_info->statedir_orig = 0;
219 }
220 if (args_info->listen_arg) {
221 free(args_info->listen_arg); /* free previous argument */
222 args_info->listen_arg = 0;
223 }
224 if (args_info->listen_orig) {
225 free(args_info->listen_orig); /* free previous argument */
226 args_info->listen_orig = 0;
227 }
228 if (args_info->net_arg) {
229 free(args_info->net_arg); /* free previous argument */
230 args_info->net_arg = 0;
231 }
232 if (args_info->net_orig) {
233 free(args_info->net_orig); /* free previous argument */
234 args_info->net_orig = 0;
235 }
236 if (args_info->ipup_arg) {
237 free(args_info->ipup_arg); /* free previous argument */
238 args_info->ipup_arg = 0;
239 }
240 if (args_info->ipup_orig) {
241 free(args_info->ipup_orig); /* free previous argument */
242 args_info->ipup_orig = 0;
243 }
244 if (args_info->ipdown_arg) {
245 free(args_info->ipdown_arg); /* free previous argument */
246 args_info->ipdown_arg = 0;
247 }
248 if (args_info->ipdown_orig) {
249 free(args_info->ipdown_orig); /* free previous argument */
250 args_info->ipdown_orig = 0;
251 }
252 if (args_info->dynip_arg) {
253 free(args_info->dynip_arg); /* free previous argument */
254 args_info->dynip_arg = 0;
255 }
256 if (args_info->dynip_orig) {
257 free(args_info->dynip_orig); /* free previous argument */
258 args_info->dynip_orig = 0;
259 }
260 if (args_info->statip_arg) {
261 free(args_info->statip_arg); /* free previous argument */
262 args_info->statip_arg = 0;
263 }
264 if (args_info->statip_orig) {
265 free(args_info->statip_orig); /* free previous argument */
266 args_info->statip_orig = 0;
267 }
268 if (args_info->pcodns1_arg) {
269 free(args_info->pcodns1_arg); /* free previous argument */
270 args_info->pcodns1_arg = 0;
271 }
272 if (args_info->pcodns1_orig) {
273 free(args_info->pcodns1_orig); /* free previous argument */
274 args_info->pcodns1_orig = 0;
275 }
276 if (args_info->pcodns2_arg) {
277 free(args_info->pcodns2_arg); /* free previous argument */
278 args_info->pcodns2_arg = 0;
279 }
280 if (args_info->pcodns2_orig) {
281 free(args_info->pcodns2_orig); /* free previous argument */
282 args_info->pcodns2_orig = 0;
283 }
284 if (args_info->timelimit_orig) {
285 free(args_info->timelimit_orig); /* free previous argument */
286 args_info->timelimit_orig = 0;
287 }
288 if (args_info->apn_arg) {
289 free(args_info->apn_arg); /* free previous argument */
290 args_info->apn_arg = 0;
291 }
292 if (args_info->apn_orig) {
293 free(args_info->apn_orig); /* free previous argument */
294 args_info->apn_orig = 0;
295 }
296 if (args_info->qos_orig) {
297 free(args_info->qos_orig); /* free previous argument */
298 args_info->qos_orig = 0;
299 }
300
301 clear_given(args_info);
Harald Welte1b3e5772010-05-04 11:13:56 +0200302}
303
304int
Harald Weltebed35df2011-11-02 13:06:18 +0100305cmdline_parser_file_save(const char *filename,
306 struct gengetopt_args_info *args_info)
Harald Welte1b3e5772010-05-04 11:13:56 +0200307{
Harald Weltebed35df2011-11-02 13:06:18 +0100308 FILE *outfile;
309 int i = 0;
Harald Welte1b3e5772010-05-04 11:13:56 +0200310
Harald Weltebed35df2011-11-02 13:06:18 +0100311 outfile = fopen(filename, "w");
Harald Welte1b3e5772010-05-04 11:13:56 +0200312
Harald Weltebed35df2011-11-02 13:06:18 +0100313 if (!outfile) {
314 fprintf(stderr, "%s: cannot open file for writing: %s\n",
315 CMDLINE_PARSER_PACKAGE, filename);
316 return EXIT_FAILURE;
317 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200318
Harald Weltebed35df2011-11-02 13:06:18 +0100319 if (args_info->help_given) {
320 fprintf(outfile, "%s\n", "help");
321 }
322 if (args_info->version_given) {
323 fprintf(outfile, "%s\n", "version");
324 }
325 if (args_info->fg_given) {
326 fprintf(outfile, "%s\n", "fg");
327 }
328 if (args_info->debug_given) {
329 fprintf(outfile, "%s\n", "debug");
330 }
331 if (args_info->conf_given) {
332 if (args_info->conf_orig) {
333 fprintf(outfile, "%s=\"%s\"\n", "conf",
334 args_info->conf_orig);
335 } else {
336 fprintf(outfile, "%s\n", "conf");
337 }
338 }
339 if (args_info->pidfile_given) {
340 if (args_info->pidfile_orig) {
341 fprintf(outfile, "%s=\"%s\"\n", "pidfile",
342 args_info->pidfile_orig);
343 } else {
344 fprintf(outfile, "%s\n", "pidfile");
345 }
346 }
347 if (args_info->statedir_given) {
348 if (args_info->statedir_orig) {
349 fprintf(outfile, "%s=\"%s\"\n", "statedir",
350 args_info->statedir_orig);
351 } else {
352 fprintf(outfile, "%s\n", "statedir");
353 }
354 }
355 if (args_info->listen_given) {
356 if (args_info->listen_orig) {
357 fprintf(outfile, "%s=\"%s\"\n", "listen",
358 args_info->listen_orig);
359 } else {
360 fprintf(outfile, "%s\n", "listen");
361 }
362 }
363 if (args_info->net_given) {
364 if (args_info->net_orig) {
365 fprintf(outfile, "%s=\"%s\"\n", "net",
366 args_info->net_orig);
367 } else {
368 fprintf(outfile, "%s\n", "net");
369 }
370 }
371 if (args_info->ipup_given) {
372 if (args_info->ipup_orig) {
373 fprintf(outfile, "%s=\"%s\"\n", "ipup",
374 args_info->ipup_orig);
375 } else {
376 fprintf(outfile, "%s\n", "ipup");
377 }
378 }
379 if (args_info->ipdown_given) {
380 if (args_info->ipdown_orig) {
381 fprintf(outfile, "%s=\"%s\"\n", "ipdown",
382 args_info->ipdown_orig);
383 } else {
384 fprintf(outfile, "%s\n", "ipdown");
385 }
386 }
387 if (args_info->dynip_given) {
388 if (args_info->dynip_orig) {
389 fprintf(outfile, "%s=\"%s\"\n", "dynip",
390 args_info->dynip_orig);
391 } else {
392 fprintf(outfile, "%s\n", "dynip");
393 }
394 }
395 if (args_info->statip_given) {
396 if (args_info->statip_orig) {
397 fprintf(outfile, "%s=\"%s\"\n", "statip",
398 args_info->statip_orig);
399 } else {
400 fprintf(outfile, "%s\n", "statip");
401 }
402 }
403 if (args_info->pcodns1_given) {
404 if (args_info->pcodns1_orig) {
405 fprintf(outfile, "%s=\"%s\"\n", "pcodns1",
406 args_info->pcodns1_orig);
407 } else {
408 fprintf(outfile, "%s\n", "pcodns1");
409 }
410 }
411 if (args_info->pcodns2_given) {
412 if (args_info->pcodns2_orig) {
413 fprintf(outfile, "%s=\"%s\"\n", "pcodns2",
414 args_info->pcodns2_orig);
415 } else {
416 fprintf(outfile, "%s\n", "pcodns2");
417 }
418 }
419 if (args_info->timelimit_given) {
420 if (args_info->timelimit_orig) {
421 fprintf(outfile, "%s=\"%s\"\n", "timelimit",
422 args_info->timelimit_orig);
423 } else {
424 fprintf(outfile, "%s\n", "timelimit");
425 }
426 }
427 if (args_info->apn_given) {
428 if (args_info->apn_orig) {
429 fprintf(outfile, "%s=\"%s\"\n", "apn",
430 args_info->apn_orig);
431 } else {
432 fprintf(outfile, "%s\n", "apn");
433 }
434 }
435 if (args_info->qos_given) {
436 if (args_info->qos_orig) {
437 fprintf(outfile, "%s=\"%s\"\n", "qos",
438 args_info->qos_orig);
439 } else {
440 fprintf(outfile, "%s\n", "qos");
441 }
442 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200443
Harald Weltebed35df2011-11-02 13:06:18 +0100444 fclose(outfile);
445
446 i = EXIT_SUCCESS;
447 return i;
Harald Welte1b3e5772010-05-04 11:13:56 +0200448}
449
Harald Weltebed35df2011-11-02 13:06:18 +0100450void cmdline_parser_free(struct gengetopt_args_info *args_info)
Harald Welte1b3e5772010-05-04 11:13:56 +0200451{
Harald Weltebed35df2011-11-02 13:06:18 +0100452 cmdline_parser_release(args_info);
Harald Welte1b3e5772010-05-04 11:13:56 +0200453}
454
Harald Welte1b3e5772010-05-04 11:13:56 +0200455/* gengetopt_strdup() */
456/* strdup.c replacement of strdup, which is not standard */
Harald Weltebed35df2011-11-02 13:06:18 +0100457char *gengetopt_strdup(const char *s)
Harald Welte1b3e5772010-05-04 11:13:56 +0200458{
Harald Weltebed35df2011-11-02 13:06:18 +0100459 char *result = NULL;
460 if (!s)
461 return result;
Harald Welte1b3e5772010-05-04 11:13:56 +0200462
Harald Weltebed35df2011-11-02 13:06:18 +0100463 result = (char *)malloc(strlen(s) + 1);
464 if (result == (char *)0)
465 return (char *)0;
466 strcpy(result, s);
467 return result;
Harald Welte1b3e5772010-05-04 11:13:56 +0200468}
469
470int
Harald Weltebed35df2011-11-02 13:06:18 +0100471cmdline_parser(int argc, char *const *argv,
472 struct gengetopt_args_info *args_info)
Harald Welte1b3e5772010-05-04 11:13:56 +0200473{
Harald Weltebed35df2011-11-02 13:06:18 +0100474 return cmdline_parser2(argc, argv, args_info, 0, 1, 1);
Harald Welte1b3e5772010-05-04 11:13:56 +0200475}
476
477int
Harald Weltebed35df2011-11-02 13:06:18 +0100478cmdline_parser2(int argc, char *const *argv,
479 struct gengetopt_args_info *args_info, int override,
480 int initialize, int check_required)
Harald Welte1b3e5772010-05-04 11:13:56 +0200481{
Harald Weltebed35df2011-11-02 13:06:18 +0100482 int result;
Harald Welte1b3e5772010-05-04 11:13:56 +0200483
Harald Weltebed35df2011-11-02 13:06:18 +0100484 result =
485 cmdline_parser_internal(argc, argv, args_info, override, initialize,
486 check_required, NULL);
Harald Welte1b3e5772010-05-04 11:13:56 +0200487
Harald Weltebed35df2011-11-02 13:06:18 +0100488 if (result == EXIT_FAILURE) {
489 cmdline_parser_free(args_info);
490 exit(EXIT_FAILURE);
491 }
492
493 return result;
Harald Welte1b3e5772010-05-04 11:13:56 +0200494}
495
496int
Harald Weltebed35df2011-11-02 13:06:18 +0100497cmdline_parser_required(struct gengetopt_args_info *args_info,
498 const char *prog_name)
Harald Welte1b3e5772010-05-04 11:13:56 +0200499{
Harald Weltebed35df2011-11-02 13:06:18 +0100500 return EXIT_SUCCESS;
Harald Welte1b3e5772010-05-04 11:13:56 +0200501}
502
503int
Harald Weltebed35df2011-11-02 13:06:18 +0100504cmdline_parser_internal(int argc, char *const *argv,
505 struct gengetopt_args_info *args_info, int override,
506 int initialize, int check_required,
507 const char *additional_error)
Harald Welte1b3e5772010-05-04 11:13:56 +0200508{
Harald Weltebed35df2011-11-02 13:06:18 +0100509 int c; /* Character of the parsed option. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200510
Harald Weltebed35df2011-11-02 13:06:18 +0100511 int error = 0;
512 struct gengetopt_args_info local_args_info;
Harald Welte1b3e5772010-05-04 11:13:56 +0200513
Harald Weltebed35df2011-11-02 13:06:18 +0100514 if (initialize)
515 cmdline_parser_init(args_info);
Harald Welte1b3e5772010-05-04 11:13:56 +0200516
Harald Weltebed35df2011-11-02 13:06:18 +0100517 cmdline_parser_init(&local_args_info);
jjako52c24142002-12-16 13:33:51 +0000518
Harald Weltebed35df2011-11-02 13:06:18 +0100519 optarg = 0;
520 optind = 0;
521 opterr = 1;
522 optopt = '?';
jjako52c24142002-12-16 13:33:51 +0000523
Harald Weltebed35df2011-11-02 13:06:18 +0100524 while (1) {
525 int option_index = 0;
526 char *stop_char;
Harald Welte1b3e5772010-05-04 11:13:56 +0200527
Harald Weltebed35df2011-11-02 13:06:18 +0100528 static struct option long_options[] = {
529 {"help", 0, NULL, 'h'},
530 {"version", 0, NULL, 'V'},
531 {"fg", 0, NULL, 'f'},
532 {"debug", 0, NULL, 'd'},
533 {"conf", 1, NULL, 'c'},
534 {"pidfile", 1, NULL, 0},
535 {"statedir", 1, NULL, 0},
536 {"listen", 1, NULL, 'l'},
537 {"net", 1, NULL, 'n'},
538 {"ipup", 1, NULL, 0},
539 {"ipdown", 1, NULL, 0},
540 {"dynip", 1, NULL, 0},
541 {"statip", 1, NULL, 0},
542 {"pcodns1", 1, NULL, 0},
543 {"pcodns2", 1, NULL, 0},
544 {"timelimit", 1, NULL, 0},
545 {"apn", 1, NULL, 'a'},
546 {"qos", 1, NULL, 'q'},
547 {NULL, 0, NULL, 0}
548 };
jjako52c24142002-12-16 13:33:51 +0000549
Harald Weltebed35df2011-11-02 13:06:18 +0100550 stop_char = 0;
551 c = getopt_long(argc, argv, "hVfdc:l:n:a:q:", long_options,
552 &option_index);
jjako52c24142002-12-16 13:33:51 +0000553
Harald Weltebed35df2011-11-02 13:06:18 +0100554 if (c == -1)
555 break; /* Exit from `while (1)' loop. */
jjako52c24142002-12-16 13:33:51 +0000556
Harald Weltebed35df2011-11-02 13:06:18 +0100557 switch (c) {
558 case 'h': /* Print help and exit. */
559 cmdline_parser_print_help();
560 cmdline_parser_free(&local_args_info);
561 exit(EXIT_SUCCESS);
jjako52c24142002-12-16 13:33:51 +0000562
Harald Weltebed35df2011-11-02 13:06:18 +0100563 case 'V': /* Print version and exit. */
564 cmdline_parser_print_version();
565 cmdline_parser_free(&local_args_info);
566 exit(EXIT_SUCCESS);
jjako52c24142002-12-16 13:33:51 +0000567
Harald Weltebed35df2011-11-02 13:06:18 +0100568 case 'f': /* Run in foreground. */
569 if (local_args_info.fg_given) {
570 fprintf(stderr,
571 "%s: `--fg' (`-f') option given more than once%s\n",
572 argv[0],
573 (additional_error ? additional_error :
574 ""));
575 goto failure;
576 }
577 if (args_info->fg_given && !override)
578 continue;
579 local_args_info.fg_given = 1;
580 args_info->fg_given = 1;
581 args_info->fg_flag = !(args_info->fg_flag);
582 break;
jjako52c24142002-12-16 13:33:51 +0000583
Harald Weltebed35df2011-11-02 13:06:18 +0100584 case 'd': /* Run in debug mode. */
585 if (local_args_info.debug_given) {
586 fprintf(stderr,
587 "%s: `--debug' (`-d') option given more than once%s\n",
588 argv[0],
589 (additional_error ? additional_error :
590 ""));
591 goto failure;
592 }
593 if (args_info->debug_given && !override)
594 continue;
595 local_args_info.debug_given = 1;
596 args_info->debug_given = 1;
597 args_info->debug_flag = !(args_info->debug_flag);
598 break;
jjako52c24142002-12-16 13:33:51 +0000599
Harald Weltebed35df2011-11-02 13:06:18 +0100600 case 'c': /* Read configuration file. */
601 if (local_args_info.conf_given) {
602 fprintf(stderr,
603 "%s: `--conf' (`-c') option given more than once%s\n",
604 argv[0],
605 (additional_error ? additional_error :
606 ""));
607 goto failure;
608 }
609 if (args_info->conf_given && !override)
610 continue;
611 local_args_info.conf_given = 1;
612 args_info->conf_given = 1;
613 if (args_info->conf_arg)
614 free(args_info->conf_arg); /* free previous string */
615 args_info->conf_arg = gengetopt_strdup(optarg);
616 if (args_info->conf_orig)
617 free(args_info->conf_orig); /* free previous string */
618 args_info->conf_orig = gengetopt_strdup(optarg);
619 break;
jjako52c24142002-12-16 13:33:51 +0000620
Harald Weltebed35df2011-11-02 13:06:18 +0100621 case 'l': /* Local interface. */
622 if (local_args_info.listen_given) {
623 fprintf(stderr,
624 "%s: `--listen' (`-l') option given more than once%s\n",
625 argv[0],
626 (additional_error ? additional_error :
627 ""));
628 goto failure;
629 }
630 if (args_info->listen_given && !override)
631 continue;
632 local_args_info.listen_given = 1;
633 args_info->listen_given = 1;
634 if (args_info->listen_arg)
635 free(args_info->listen_arg); /* free previous string */
636 args_info->listen_arg = gengetopt_strdup(optarg);
637 if (args_info->listen_orig)
638 free(args_info->listen_orig); /* free previous string */
639 args_info->listen_orig = gengetopt_strdup(optarg);
640 break;
jjako52c24142002-12-16 13:33:51 +0000641
Harald Weltebed35df2011-11-02 13:06:18 +0100642 case 'n': /* Network. */
643 if (local_args_info.net_given) {
644 fprintf(stderr,
645 "%s: `--net' (`-n') option given more than once%s\n",
646 argv[0],
647 (additional_error ? additional_error :
648 ""));
649 goto failure;
650 }
651 if (args_info->net_given && !override)
652 continue;
653 local_args_info.net_given = 1;
654 args_info->net_given = 1;
655 if (args_info->net_arg)
656 free(args_info->net_arg); /* free previous string */
657 args_info->net_arg = gengetopt_strdup(optarg);
658 if (args_info->net_orig)
659 free(args_info->net_orig); /* free previous string */
660 args_info->net_orig = gengetopt_strdup(optarg);
661 break;
jjako52c24142002-12-16 13:33:51 +0000662
Harald Weltebed35df2011-11-02 13:06:18 +0100663 case 'a': /* Access point name. */
664 if (local_args_info.apn_given) {
665 fprintf(stderr,
666 "%s: `--apn' (`-a') option given more than once%s\n",
667 argv[0],
668 (additional_error ? additional_error :
669 ""));
670 goto failure;
671 }
672 if (args_info->apn_given && !override)
673 continue;
674 local_args_info.apn_given = 1;
675 args_info->apn_given = 1;
676 if (args_info->apn_arg)
677 free(args_info->apn_arg); /* free previous string */
678 args_info->apn_arg = gengetopt_strdup(optarg);
679 if (args_info->apn_orig)
680 free(args_info->apn_orig); /* free previous string */
681 args_info->apn_orig = gengetopt_strdup(optarg);
682 break;
jjako52c24142002-12-16 13:33:51 +0000683
Harald Weltebed35df2011-11-02 13:06:18 +0100684 case 'q': /* Requested quality of service. */
685 if (local_args_info.qos_given) {
686 fprintf(stderr,
687 "%s: `--qos' (`-q') option given more than once%s\n",
688 argv[0],
689 (additional_error ? additional_error :
690 ""));
691 goto failure;
692 }
693 if (args_info->qos_given && !override)
694 continue;
695 local_args_info.qos_given = 1;
696 args_info->qos_given = 1;
697 args_info->qos_arg = strtol(optarg, &stop_char, 0);
698 if (!(stop_char && *stop_char == '\0')) {
699 fprintf(stderr,
700 "%s: invalid numeric value: %s\n",
701 argv[0], optarg);
702 goto failure;
703 }
704 if (args_info->qos_orig)
705 free(args_info->qos_orig); /* free previous string */
706 args_info->qos_orig = gengetopt_strdup(optarg);
707 break;
jjako52c24142002-12-16 13:33:51 +0000708
Harald Weltebed35df2011-11-02 13:06:18 +0100709 case 0: /* Long option with no short option */
710 /* Filename of process id file. */
711 if (strcmp(long_options[option_index].name, "pidfile")
712 == 0) {
713 if (local_args_info.pidfile_given) {
714 fprintf(stderr,
715 "%s: `--pidfile' option given more than once%s\n",
716 argv[0],
717 (additional_error ?
718 additional_error : ""));
719 goto failure;
720 }
721 if (args_info->pidfile_given && !override)
722 continue;
723 local_args_info.pidfile_given = 1;
724 args_info->pidfile_given = 1;
725 if (args_info->pidfile_arg)
726 free(args_info->pidfile_arg); /* free previous string */
727 args_info->pidfile_arg =
728 gengetopt_strdup(optarg);
729 if (args_info->pidfile_orig)
730 free(args_info->pidfile_orig); /* free previous string */
731 args_info->pidfile_orig =
732 gengetopt_strdup(optarg);
733 }
734 /* Directory of nonvolatile data. */
735 else if (strcmp
736 (long_options[option_index].name,
737 "statedir") == 0) {
738 if (local_args_info.statedir_given) {
739 fprintf(stderr,
740 "%s: `--statedir' option given more than once%s\n",
741 argv[0],
742 (additional_error ?
743 additional_error : ""));
744 goto failure;
745 }
746 if (args_info->statedir_given && !override)
747 continue;
748 local_args_info.statedir_given = 1;
749 args_info->statedir_given = 1;
750 if (args_info->statedir_arg)
751 free(args_info->statedir_arg); /* free previous string */
752 args_info->statedir_arg =
753 gengetopt_strdup(optarg);
754 if (args_info->statedir_orig)
755 free(args_info->statedir_orig); /* free previous string */
756 args_info->statedir_orig =
757 gengetopt_strdup(optarg);
758 }
759 /* Script to run after link-up. */
760 else if (strcmp(long_options[option_index].name, "ipup")
761 == 0) {
762 if (local_args_info.ipup_given) {
763 fprintf(stderr,
764 "%s: `--ipup' option given more than once%s\n",
765 argv[0],
766 (additional_error ?
767 additional_error : ""));
768 goto failure;
769 }
770 if (args_info->ipup_given && !override)
771 continue;
772 local_args_info.ipup_given = 1;
773 args_info->ipup_given = 1;
774 if (args_info->ipup_arg)
775 free(args_info->ipup_arg); /* free previous string */
776 args_info->ipup_arg = gengetopt_strdup(optarg);
777 if (args_info->ipup_orig)
778 free(args_info->ipup_orig); /* free previous string */
779 args_info->ipup_orig = gengetopt_strdup(optarg);
780 }
781 /* Script to run after link-down. */
782 else if (strcmp
783 (long_options[option_index].name,
784 "ipdown") == 0) {
785 if (local_args_info.ipdown_given) {
786 fprintf(stderr,
787 "%s: `--ipdown' option given more than once%s\n",
788 argv[0],
789 (additional_error ?
790 additional_error : ""));
791 goto failure;
792 }
793 if (args_info->ipdown_given && !override)
794 continue;
795 local_args_info.ipdown_given = 1;
796 args_info->ipdown_given = 1;
797 if (args_info->ipdown_arg)
798 free(args_info->ipdown_arg); /* free previous string */
799 args_info->ipdown_arg =
800 gengetopt_strdup(optarg);
801 if (args_info->ipdown_orig)
802 free(args_info->ipdown_orig); /* free previous string */
803 args_info->ipdown_orig =
804 gengetopt_strdup(optarg);
805 }
806 /* Dynamic IP address pool. */
807 else if (strcmp
808 (long_options[option_index].name,
809 "dynip") == 0) {
810 if (local_args_info.dynip_given) {
811 fprintf(stderr,
812 "%s: `--dynip' option given more than once%s\n",
813 argv[0],
814 (additional_error ?
815 additional_error : ""));
816 goto failure;
817 }
818 if (args_info->dynip_given && !override)
819 continue;
820 local_args_info.dynip_given = 1;
821 args_info->dynip_given = 1;
822 if (args_info->dynip_arg)
823 free(args_info->dynip_arg); /* free previous string */
824 args_info->dynip_arg = gengetopt_strdup(optarg);
825 if (args_info->dynip_orig)
826 free(args_info->dynip_orig); /* free previous string */
827 args_info->dynip_orig =
828 gengetopt_strdup(optarg);
829 }
830 /* Static IP address pool. */
831 else if (strcmp
832 (long_options[option_index].name,
833 "statip") == 0) {
834 if (local_args_info.statip_given) {
835 fprintf(stderr,
836 "%s: `--statip' option given more than once%s\n",
837 argv[0],
838 (additional_error ?
839 additional_error : ""));
840 goto failure;
841 }
842 if (args_info->statip_given && !override)
843 continue;
844 local_args_info.statip_given = 1;
845 args_info->statip_given = 1;
846 if (args_info->statip_arg)
847 free(args_info->statip_arg); /* free previous string */
848 args_info->statip_arg =
849 gengetopt_strdup(optarg);
850 if (args_info->statip_orig)
851 free(args_info->statip_orig); /* free previous string */
852 args_info->statip_orig =
853 gengetopt_strdup(optarg);
854 }
855 /* PCO DNS Server 1. */
856 else if (strcmp
857 (long_options[option_index].name,
858 "pcodns1") == 0) {
859 if (local_args_info.pcodns1_given) {
860 fprintf(stderr,
861 "%s: `--pcodns1' option given more than once%s\n",
862 argv[0],
863 (additional_error ?
864 additional_error : ""));
865 goto failure;
866 }
867 if (args_info->pcodns1_given && !override)
868 continue;
869 local_args_info.pcodns1_given = 1;
870 args_info->pcodns1_given = 1;
871 if (args_info->pcodns1_arg)
872 free(args_info->pcodns1_arg); /* free previous string */
873 args_info->pcodns1_arg =
874 gengetopt_strdup(optarg);
875 if (args_info->pcodns1_orig)
876 free(args_info->pcodns1_orig); /* free previous string */
877 args_info->pcodns1_orig =
878 gengetopt_strdup(optarg);
879 }
880 /* PCO DNS Server 2. */
881 else if (strcmp
882 (long_options[option_index].name,
883 "pcodns2") == 0) {
884 if (local_args_info.pcodns2_given) {
885 fprintf(stderr,
886 "%s: `--pcodns2' option given more than once%s\n",
887 argv[0],
888 (additional_error ?
889 additional_error : ""));
890 goto failure;
891 }
892 if (args_info->pcodns2_given && !override)
893 continue;
894 local_args_info.pcodns2_given = 1;
895 args_info->pcodns2_given = 1;
896 if (args_info->pcodns2_arg)
897 free(args_info->pcodns2_arg); /* free previous string */
898 args_info->pcodns2_arg =
899 gengetopt_strdup(optarg);
900 if (args_info->pcodns2_orig)
901 free(args_info->pcodns2_orig); /* free previous string */
902 args_info->pcodns2_orig =
903 gengetopt_strdup(optarg);
904 }
905 /* Exit after timelimit seconds. */
906 else if (strcmp
907 (long_options[option_index].name,
908 "timelimit") == 0) {
909 if (local_args_info.timelimit_given) {
910 fprintf(stderr,
911 "%s: `--timelimit' option given more than once%s\n",
912 argv[0],
913 (additional_error ?
914 additional_error : ""));
915 goto failure;
916 }
917 if (args_info->timelimit_given && !override)
918 continue;
919 local_args_info.timelimit_given = 1;
920 args_info->timelimit_given = 1;
921 args_info->timelimit_arg =
922 strtol(optarg, &stop_char, 0);
923 if (!(stop_char && *stop_char == '\0')) {
924 fprintf(stderr,
925 "%s: invalid numeric value: %s\n",
926 argv[0], optarg);
927 goto failure;
928 }
929 if (args_info->timelimit_orig)
930 free(args_info->timelimit_orig); /* free previous string */
931 args_info->timelimit_orig =
932 gengetopt_strdup(optarg);
933 }
jjako52c24142002-12-16 13:33:51 +0000934
Harald Weltebed35df2011-11-02 13:06:18 +0100935 break;
936 case '?': /* Invalid option. */
937 /* `getopt_long' already printed an error message. */
938 goto failure;
jjako52c24142002-12-16 13:33:51 +0000939
Harald Weltebed35df2011-11-02 13:06:18 +0100940 default: /* bug: option not considered. */
941 fprintf(stderr, "%s: option unknown: %c%s\n",
942 CMDLINE_PARSER_PACKAGE, c,
943 (additional_error ? additional_error : ""));
944 abort();
945 } /* switch */
946 } /* while */
jjako52c24142002-12-16 13:33:51 +0000947
Harald Weltebed35df2011-11-02 13:06:18 +0100948 cmdline_parser_release(&local_args_info);
jjako52c24142002-12-16 13:33:51 +0000949
Harald Weltebed35df2011-11-02 13:06:18 +0100950 if (error)
951 return (EXIT_FAILURE);
Harald Welte1b3e5772010-05-04 11:13:56 +0200952
Harald Weltebed35df2011-11-02 13:06:18 +0100953 return 0;
Harald Welte1b3e5772010-05-04 11:13:56 +0200954
955failure:
Harald Weltebed35df2011-11-02 13:06:18 +0100956
957 cmdline_parser_release(&local_args_info);
958 return (EXIT_FAILURE);
jjako52c24142002-12-16 13:33:51 +0000959}
960
Harald Welte1b3e5772010-05-04 11:13:56 +0200961#ifndef CONFIG_FILE_LINE_SIZE
962#define CONFIG_FILE_LINE_SIZE 2048
963#endif
964#define ADDITIONAL_ERROR " in configuration file "
965
966#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
967/* 3 is for "--" and "=" */
968
Harald Weltebed35df2011-11-02 13:06:18 +0100969char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE + 1];
jjako52c24142002-12-16 13:33:51 +0000970
971int
Harald Weltebed35df2011-11-02 13:06:18 +0100972cmdline_parser_configfile(char *const filename,
973 struct gengetopt_args_info *args_info, int override,
974 int initialize, int check_required)
jjako52c24142002-12-16 13:33:51 +0000975{
Harald Weltebed35df2011-11-02 13:06:18 +0100976 FILE *file;
977 char linebuf[CONFIG_FILE_LINE_SIZE];
978 int line_num = 0;
979 int i, result, equal;
980 char *fopt, *farg;
981 char *str_index;
982 size_t len, next_token;
983 char delimiter;
984 int my_argc = 0;
985 char **my_argv_arg;
986 char *additional_error;
Harald Welte1b3e5772010-05-04 11:13:56 +0200987
Harald Weltebed35df2011-11-02 13:06:18 +0100988 /* store the program name */
989 cmd_line_list_tmp =
990 (struct line_list *)malloc(sizeof(struct line_list));
991 cmd_line_list_tmp->next = cmd_line_list;
992 cmd_line_list = cmd_line_list_tmp;
993 cmd_line_list->string_arg = gengetopt_strdup(CMDLINE_PARSER_PACKAGE);
jjako52c24142002-12-16 13:33:51 +0000994
Harald Weltebed35df2011-11-02 13:06:18 +0100995 if ((file = fopen(filename, "r")) == NULL) {
996 fprintf(stderr, "%s: Error opening configuration file '%s'\n",
997 CMDLINE_PARSER_PACKAGE, filename);
998 result = EXIT_FAILURE;
999 goto conf_failure;
1000 }
jjako52c24142002-12-16 13:33:51 +00001001
Harald Weltebed35df2011-11-02 13:06:18 +01001002 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) {
1003 ++line_num;
1004 my_argv[0] = '\0';
1005 len = strlen(linebuf);
1006 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE - 1)) {
1007 fprintf(stderr,
1008 "%s:%s:%d: Line too long in configuration file\n",
1009 CMDLINE_PARSER_PACKAGE, filename, line_num);
1010 result = EXIT_FAILURE;
1011 goto conf_failure;
1012 }
jjako52c24142002-12-16 13:33:51 +00001013
Harald Weltebed35df2011-11-02 13:06:18 +01001014 /* find first non-whitespace character in the line */
1015 next_token = strspn(linebuf, " \t\r\n");
1016 str_index = linebuf + next_token;
jjako52c24142002-12-16 13:33:51 +00001017
Harald Weltebed35df2011-11-02 13:06:18 +01001018 if (str_index[0] == '\0' || str_index[0] == '#')
1019 continue; /* empty line or comment line is skipped */
Harald Welte1b3e5772010-05-04 11:13:56 +02001020
Harald Weltebed35df2011-11-02 13:06:18 +01001021 fopt = str_index;
Harald Welte1b3e5772010-05-04 11:13:56 +02001022
Harald Weltebed35df2011-11-02 13:06:18 +01001023 /* truncate fopt at the end of the first non-valid character */
1024 next_token = strcspn(fopt, " \t\r\n=");
Harald Welte1b3e5772010-05-04 11:13:56 +02001025
Harald Weltebed35df2011-11-02 13:06:18 +01001026 if (fopt[next_token] == '\0') { /* the line is over */
1027 farg = NULL;
1028 equal = 0;
1029 goto noarg;
1030 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001031
Harald Weltebed35df2011-11-02 13:06:18 +01001032 /* remember if equal sign is present */
1033 equal = (fopt[next_token] == '=');
1034 fopt[next_token++] = '\0';
Harald Welte1b3e5772010-05-04 11:13:56 +02001035
Harald Weltebed35df2011-11-02 13:06:18 +01001036 /* advance pointers to the next token after the end of fopt */
1037 next_token += strspn(fopt + next_token, " \t\r\n");
1038 /* check for the presence of equal sign, and if so, skip it */
1039 if (!equal)
1040 if ((equal = (fopt[next_token] == '='))) {
1041 next_token++;
1042 next_token +=
1043 strspn(fopt + next_token, " \t\r\n");
1044 }
1045 str_index += next_token;
Harald Welte1b3e5772010-05-04 11:13:56 +02001046
Harald Weltebed35df2011-11-02 13:06:18 +01001047 /* find argument */
1048 farg = str_index;
1049 if (farg[0] == '\"' || farg[0] == '\'') { /* quoted argument */
1050 str_index = strchr(++farg, str_index[0]); /* skip opening quote */
1051 if (!str_index) {
1052 fprintf
1053 (stderr,
1054 "%s:%s:%d: unterminated string in configuration file\n",
1055 CMDLINE_PARSER_PACKAGE, filename,
1056 line_num);
1057 result = EXIT_FAILURE;
1058 goto conf_failure;
1059 }
1060 } else { /* read up the remaining part up to a delimiter */
1061 next_token = strcspn(farg, " \t\r\n#\'\"");
1062 str_index += next_token;
1063 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001064
Harald Weltebed35df2011-11-02 13:06:18 +01001065 /* truncate farg at the delimiter and store it for further check */
1066 delimiter = *str_index, *str_index++ = '\0';
Harald Welte1b3e5772010-05-04 11:13:56 +02001067
Harald Weltebed35df2011-11-02 13:06:18 +01001068 /* everything but comment is illegal at the end of line */
1069 if (delimiter != '\0' && delimiter != '#') {
1070 str_index += strspn(str_index, " \t\r\n");
1071 if (*str_index != '\0' && *str_index != '#') {
1072 fprintf
1073 (stderr,
1074 "%s:%s:%d: malformed string in configuration file\n",
1075 CMDLINE_PARSER_PACKAGE, filename,
1076 line_num);
1077 result = EXIT_FAILURE;
1078 goto conf_failure;
1079 }
1080 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001081
Harald Weltebed35df2011-11-02 13:06:18 +01001082noarg:
1083 ++my_argc;
1084 len = strlen(fopt);
Harald Welte1b3e5772010-05-04 11:13:56 +02001085
Harald Weltebed35df2011-11-02 13:06:18 +01001086 strcat(my_argv, len > 1 ? "--" : "-");
1087 strcat(my_argv, fopt);
1088 if (len > 1 && ((farg && *farg) || equal))
1089 strcat(my_argv, "=");
1090 if (farg && *farg)
1091 strcat(my_argv, farg);
Harald Welte1b3e5772010-05-04 11:13:56 +02001092
Harald Weltebed35df2011-11-02 13:06:18 +01001093 cmd_line_list_tmp =
1094 (struct line_list *)malloc(sizeof(struct line_list));
1095 cmd_line_list_tmp->next = cmd_line_list;
1096 cmd_line_list = cmd_line_list_tmp;
1097 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
1098 } /* while */
jjako52c24142002-12-16 13:33:51 +00001099
Harald Weltebed35df2011-11-02 13:06:18 +01001100 ++my_argc; /* for program name */
1101 my_argv_arg = (char **)malloc((my_argc + 1) * sizeof(char *));
1102 cmd_line_list_tmp = cmd_line_list;
1103 for (i = my_argc - 1; i >= 0; --i) {
1104 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1105 cmd_line_list_tmp = cmd_line_list_tmp->next;
1106 }
1107 my_argv_arg[my_argc] = 0;
Harald Welte1b3e5772010-05-04 11:13:56 +02001108
Harald Weltebed35df2011-11-02 13:06:18 +01001109 additional_error =
1110 (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1111 strcpy(additional_error, ADDITIONAL_ERROR);
1112 strcat(additional_error, filename);
1113 result =
1114 cmdline_parser_internal(my_argc, my_argv_arg, args_info, override,
1115 initialize, check_required,
1116 additional_error);
Harald Welte1b3e5772010-05-04 11:13:56 +02001117
Harald Weltebed35df2011-11-02 13:06:18 +01001118 free(additional_error);
1119 free(my_argv_arg);
Harald Welte1b3e5772010-05-04 11:13:56 +02001120
1121conf_failure:
Harald Weltebed35df2011-11-02 13:06:18 +01001122 if (file)
1123 fclose(file);
Harald Welte1b3e5772010-05-04 11:13:56 +02001124
Harald Weltebed35df2011-11-02 13:06:18 +01001125 free_cmd_list();
1126 if (result == EXIT_FAILURE) {
1127 cmdline_parser_free(args_info);
1128 exit(EXIT_FAILURE);
1129 }
1130
1131 return result;
jjako52c24142002-12-16 13:33:51 +00001132}