blob: f40c58335eb16d217289ce16cf1c87183b19d309 [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:
jjako1a51df72004-07-20 08:30:21 +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 " -d, --debug Run in debug mode (default=off)",
32 " -c, --conf=STRING Read configuration file",
33 " --pidfile=STRING Filename of process id file (default=`./sgsnemu.pid')",
34 " --statedir=STRING Directory of nonvolatile data (default=`./')",
35 " --dns=STRING DNS Server to use",
36 " -l, --listen=STRING Local interface",
37 " -r, --remote=STRING Remote host",
38 " --contexts=INT Number of contexts (default=`1')",
39 " --timelimit=INT Exit after timelimit seconds (default=`0')",
40 " --gtpversion=INT GTP version to use (default=`1')",
41 " -a, --apn=STRING Access point name (default=`internet')",
42 " --selmode=INT Selection mode (default=`0x01')",
Yann BONNAMY944dce32010-10-29 17:07:44 +020043 " --rattype=INT Radio Access Technology Type (optional-1to5)",
44 " --userloc=STRING User Location Information (optional-type.MCC.MNC.LAC.CIorSACorRAC)",
45 " --mstz=STRING MS Time Zone (optional- sign.NbQuartersOfAnHour.DSTAdjustment)",
46 " --imeisv=STRING IMEI(SV) International Mobile Equipment Identity (and Software Version) (optional,16 digits)",
Harald Welte1b3e5772010-05-04 11:13:56 +020047 " -i, --imsi=STRING IMSI (default=`240010123456789')",
48 " --nsapi=INT NSAPI (default=`0')",
49 " -m, --msisdn=STRING Mobile Station ISDN number (default=`46702123456')",
50 " -q, --qos=INT Requested quality of service (default=`0x0b921f')",
51 " --charging=INT Charging characteristics (default=`0x0800')",
52 " -u, --uid=STRING Login user ID (default=`mig')",
53 " -p, --pwd=STRING Login password (default=`hemmelig')",
54 " --createif Create local network interface (default=off)",
55 " -n, --net=STRING Network address for local interface",
56 " --defaultroute Create default route (default=off)",
57 " --ipup=STRING Script to run after link-up",
58 " --ipdown=STRING Script to run after link-down",
59 " --pinghost=STRING Ping remote host",
60 " --pingrate=INT Number of ping req per second (default=`1')",
61 " --pingsize=INT Number of ping data bytes (default=`56')",
62 " --pingcount=INT Number of ping req to send (default=`0')",
63 " --pingquiet Do not print ping packet info (default=off)",
64 0
65};
66
67static
68void clear_given (struct gengetopt_args_info *args_info);
69static
70void clear_args (struct gengetopt_args_info *args_info);
71
72static int
73cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error);
74
75struct line_list
jjako52c24142002-12-16 13:33:51 +000076{
Harald Welte1b3e5772010-05-04 11:13:56 +020077 char * string_arg;
78 struct line_list * next;
79};
80
81static struct line_list *cmd_line_list = 0;
82static struct line_list *cmd_line_list_tmp = 0;
83
84static void
85free_cmd_list(void)
86{
87 /* free the list of a previous call */
88 if (cmd_line_list)
89 {
90 while (cmd_line_list) {
91 cmd_line_list_tmp = cmd_line_list;
92 cmd_line_list = cmd_line_list->next;
93 free (cmd_line_list_tmp->string_arg);
94 free (cmd_line_list_tmp);
95 }
96 }
jjako52c24142002-12-16 13:33:51 +000097}
98
99
jjako52c24142002-12-16 13:33:51 +0000100static char *
Harald Welte1b3e5772010-05-04 11:13:56 +0200101gengetopt_strdup (const char *s);
jjako52c24142002-12-16 13:33:51 +0000102
Harald Welte1b3e5772010-05-04 11:13:56 +0200103static
104void clear_given (struct gengetopt_args_info *args_info)
jjako52c24142002-12-16 13:33:51 +0000105{
jjako52c24142002-12-16 13:33:51 +0000106 args_info->help_given = 0 ;
107 args_info->version_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000108 args_info->debug_given = 0 ;
109 args_info->conf_given = 0 ;
110 args_info->pidfile_given = 0 ;
111 args_info->statedir_given = 0 ;
112 args_info->dns_given = 0 ;
113 args_info->listen_given = 0 ;
114 args_info->remote_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000115 args_info->contexts_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000116 args_info->timelimit_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000117 args_info->gtpversion_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000118 args_info->apn_given = 0 ;
jjako1a51df72004-07-20 08:30:21 +0000119 args_info->selmode_given = 0 ;
Yann BONNAMY944dce32010-10-29 17:07:44 +0200120 args_info->rattype_given = 0 ;
121 args_info->userloc_given = 0 ;
122 args_info->mstz_given = 0 ;
123 args_info->imeisv_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000124 args_info->imsi_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000125 args_info->nsapi_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000126 args_info->msisdn_given = 0 ;
127 args_info->qos_given = 0 ;
jjako7e051d32004-05-27 20:06:36 +0000128 args_info->charging_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000129 args_info->uid_given = 0 ;
130 args_info->pwd_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000131 args_info->createif_given = 0 ;
jjako193e8b12003-11-10 12:31:41 +0000132 args_info->net_given = 0 ;
jjakoa7cd2492003-04-11 09:40:12 +0000133 args_info->defaultroute_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000134 args_info->ipup_given = 0 ;
135 args_info->ipdown_given = 0 ;
jjako5da68452003-01-28 16:08:47 +0000136 args_info->pinghost_given = 0 ;
137 args_info->pingrate_given = 0 ;
138 args_info->pingsize_given = 0 ;
139 args_info->pingcount_given = 0 ;
140 args_info->pingquiet_given = 0 ;
jjako52c24142002-12-16 13:33:51 +0000141}
142
Harald Welte1b3e5772010-05-04 11:13:56 +0200143static
144void clear_args (struct gengetopt_args_info *args_info)
145{
146 args_info->debug_flag = 0;
147 args_info->conf_arg = NULL;
148 args_info->conf_orig = NULL;
149 args_info->pidfile_arg = gengetopt_strdup ("./sgsnemu.pid");
150 args_info->pidfile_orig = NULL;
151 args_info->statedir_arg = gengetopt_strdup ("./");
152 args_info->statedir_orig = NULL;
153 args_info->dns_arg = NULL;
154 args_info->dns_orig = NULL;
155 args_info->listen_arg = NULL;
156 args_info->listen_orig = NULL;
157 args_info->remote_arg = NULL;
158 args_info->remote_orig = NULL;
159 args_info->contexts_arg = 1;
160 args_info->contexts_orig = NULL;
161 args_info->timelimit_arg = 0;
162 args_info->timelimit_orig = NULL;
163 args_info->gtpversion_arg = 1;
164 args_info->gtpversion_orig = NULL;
165 args_info->apn_arg = gengetopt_strdup ("internet");
166 args_info->apn_orig = NULL;
167 args_info->selmode_arg = 0x01;
168 args_info->selmode_orig = NULL;
Yann BONNAMY944dce32010-10-29 17:07:44 +0200169 args_info->rattype_arg = "1";
170 args_info->rattype_orig = NULL;
171 args_info->userloc_arg = strdup("02509946241207");
172 args_info->userloc_orig = NULL;
173 args_info->mstz_arg = strdup("0");
174 args_info->mstz_orig = NULL;
175 args_info->imeisv_arg = strdup("2143658709214365");
176 args_info->imeisv_orig = NULL;
Harald Welte1b3e5772010-05-04 11:13:56 +0200177 args_info->imsi_arg = gengetopt_strdup ("240010123456789");
178 args_info->imsi_orig = NULL;
179 args_info->nsapi_arg = 0;
180 args_info->nsapi_orig = NULL;
181 args_info->msisdn_arg = gengetopt_strdup ("46702123456");
182 args_info->msisdn_orig = NULL;
183 args_info->qos_arg = 0x0b921f;
184 args_info->qos_orig = NULL;
185 args_info->charging_arg = 0x0800;
186 args_info->charging_orig = NULL;
187 args_info->uid_arg = gengetopt_strdup ("mig");
188 args_info->uid_orig = NULL;
189 args_info->pwd_arg = gengetopt_strdup ("hemmelig");
190 args_info->pwd_orig = NULL;
191 args_info->createif_flag = 0;
192 args_info->net_arg = NULL;
193 args_info->net_orig = NULL;
194 args_info->defaultroute_flag = 0;
195 args_info->ipup_arg = NULL;
196 args_info->ipup_orig = NULL;
197 args_info->ipdown_arg = NULL;
198 args_info->ipdown_orig = NULL;
199 args_info->pinghost_arg = NULL;
200 args_info->pinghost_orig = NULL;
201 args_info->pingrate_arg = 1;
202 args_info->pingrate_orig = NULL;
203 args_info->pingsize_arg = 56;
204 args_info->pingsize_orig = NULL;
205 args_info->pingcount_arg = 0;
206 args_info->pingcount_orig = NULL;
207 args_info->pingquiet_flag = 0;
208
209}
210
211static
212void init_args_info(struct gengetopt_args_info *args_info)
213{
214 args_info->help_help = gengetopt_args_info_help[0] ;
215 args_info->version_help = gengetopt_args_info_help[1] ;
216 args_info->debug_help = gengetopt_args_info_help[2] ;
217 args_info->conf_help = gengetopt_args_info_help[3] ;
218 args_info->pidfile_help = gengetopt_args_info_help[4] ;
219 args_info->statedir_help = gengetopt_args_info_help[5] ;
220 args_info->dns_help = gengetopt_args_info_help[6] ;
221 args_info->listen_help = gengetopt_args_info_help[7] ;
222 args_info->remote_help = gengetopt_args_info_help[8] ;
223 args_info->contexts_help = gengetopt_args_info_help[9] ;
224 args_info->timelimit_help = gengetopt_args_info_help[10] ;
225 args_info->gtpversion_help = gengetopt_args_info_help[11] ;
226 args_info->apn_help = gengetopt_args_info_help[12] ;
227 args_info->selmode_help = gengetopt_args_info_help[13] ;
228 args_info->imsi_help = gengetopt_args_info_help[14] ;
229 args_info->nsapi_help = gengetopt_args_info_help[15] ;
230 args_info->msisdn_help = gengetopt_args_info_help[16] ;
231 args_info->qos_help = gengetopt_args_info_help[17] ;
232 args_info->charging_help = gengetopt_args_info_help[18] ;
233 args_info->uid_help = gengetopt_args_info_help[19] ;
234 args_info->pwd_help = gengetopt_args_info_help[20] ;
235 args_info->createif_help = gengetopt_args_info_help[21] ;
236 args_info->net_help = gengetopt_args_info_help[22] ;
237 args_info->defaultroute_help = gengetopt_args_info_help[23] ;
238 args_info->ipup_help = gengetopt_args_info_help[24] ;
239 args_info->ipdown_help = gengetopt_args_info_help[25] ;
240 args_info->pinghost_help = gengetopt_args_info_help[26] ;
241 args_info->pingrate_help = gengetopt_args_info_help[27] ;
242 args_info->pingsize_help = gengetopt_args_info_help[28] ;
243 args_info->pingcount_help = gengetopt_args_info_help[29] ;
244 args_info->pingquiet_help = gengetopt_args_info_help[30] ;
245
246}
247
248void
249cmdline_parser_print_version (void)
250{
251 printf ("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION);
252}
253
254void
255cmdline_parser_print_help (void)
256{
257 int i = 0;
258 cmdline_parser_print_version ();
259
260 if (strlen(gengetopt_args_info_purpose) > 0)
261 printf("\n%s\n", gengetopt_args_info_purpose);
262
263 printf("\n%s\n\n", gengetopt_args_info_usage);
264 while (gengetopt_args_info_help[i])
265 printf("%s\n", gengetopt_args_info_help[i++]);
266}
267
268void
269cmdline_parser_init (struct gengetopt_args_info *args_info)
270{
271 clear_given (args_info);
272 clear_args (args_info);
273 init_args_info (args_info);
274}
275
276static void
277cmdline_parser_release (struct gengetopt_args_info *args_info)
278{
279
280 if (args_info->conf_arg)
281 {
282 free (args_info->conf_arg); /* free previous argument */
283 args_info->conf_arg = 0;
284 }
285 if (args_info->conf_orig)
286 {
287 free (args_info->conf_orig); /* free previous argument */
288 args_info->conf_orig = 0;
289 }
290 if (args_info->pidfile_arg)
291 {
292 free (args_info->pidfile_arg); /* free previous argument */
293 args_info->pidfile_arg = 0;
294 }
295 if (args_info->pidfile_orig)
296 {
297 free (args_info->pidfile_orig); /* free previous argument */
298 args_info->pidfile_orig = 0;
299 }
300 if (args_info->statedir_arg)
301 {
302 free (args_info->statedir_arg); /* free previous argument */
303 args_info->statedir_arg = 0;
304 }
305 if (args_info->statedir_orig)
306 {
307 free (args_info->statedir_orig); /* free previous argument */
308 args_info->statedir_orig = 0;
309 }
310 if (args_info->dns_arg)
311 {
312 free (args_info->dns_arg); /* free previous argument */
313 args_info->dns_arg = 0;
314 }
315 if (args_info->dns_orig)
316 {
317 free (args_info->dns_orig); /* free previous argument */
318 args_info->dns_orig = 0;
319 }
320 if (args_info->listen_arg)
321 {
322 free (args_info->listen_arg); /* free previous argument */
323 args_info->listen_arg = 0;
324 }
325 if (args_info->listen_orig)
326 {
327 free (args_info->listen_orig); /* free previous argument */
328 args_info->listen_orig = 0;
329 }
330 if (args_info->remote_arg)
331 {
332 free (args_info->remote_arg); /* free previous argument */
333 args_info->remote_arg = 0;
334 }
335 if (args_info->remote_orig)
336 {
337 free (args_info->remote_orig); /* free previous argument */
338 args_info->remote_orig = 0;
339 }
340 if (args_info->contexts_orig)
341 {
342 free (args_info->contexts_orig); /* free previous argument */
343 args_info->contexts_orig = 0;
344 }
345 if (args_info->timelimit_orig)
346 {
347 free (args_info->timelimit_orig); /* free previous argument */
348 args_info->timelimit_orig = 0;
349 }
350 if (args_info->gtpversion_orig)
351 {
352 free (args_info->gtpversion_orig); /* free previous argument */
353 args_info->gtpversion_orig = 0;
354 }
355 if (args_info->apn_arg)
356 {
357 free (args_info->apn_arg); /* free previous argument */
358 args_info->apn_arg = 0;
359 }
360 if (args_info->apn_orig)
361 {
362 free (args_info->apn_orig); /* free previous argument */
363 args_info->apn_orig = 0;
364 }
365 if (args_info->selmode_orig)
366 {
367 free (args_info->selmode_orig); /* free previous argument */
368 args_info->selmode_orig = 0;
369 }
370 if (args_info->imsi_arg)
371 {
372 free (args_info->imsi_arg); /* free previous argument */
373 args_info->imsi_arg = 0;
374 }
375 if (args_info->imsi_orig)
376 {
377 free (args_info->imsi_orig); /* free previous argument */
378 args_info->imsi_orig = 0;
379 }
380 if (args_info->nsapi_orig)
381 {
382 free (args_info->nsapi_orig); /* free previous argument */
383 args_info->nsapi_orig = 0;
384 }
385 if (args_info->msisdn_arg)
386 {
387 free (args_info->msisdn_arg); /* free previous argument */
388 args_info->msisdn_arg = 0;
389 }
390 if (args_info->msisdn_orig)
391 {
392 free (args_info->msisdn_orig); /* free previous argument */
393 args_info->msisdn_orig = 0;
394 }
395 if (args_info->qos_orig)
396 {
397 free (args_info->qos_orig); /* free previous argument */
398 args_info->qos_orig = 0;
399 }
400 if (args_info->charging_orig)
401 {
402 free (args_info->charging_orig); /* free previous argument */
403 args_info->charging_orig = 0;
404 }
405 if (args_info->uid_arg)
406 {
407 free (args_info->uid_arg); /* free previous argument */
408 args_info->uid_arg = 0;
409 }
410 if (args_info->uid_orig)
411 {
412 free (args_info->uid_orig); /* free previous argument */
413 args_info->uid_orig = 0;
414 }
415 if (args_info->pwd_arg)
416 {
417 free (args_info->pwd_arg); /* free previous argument */
418 args_info->pwd_arg = 0;
419 }
420 if (args_info->pwd_orig)
421 {
422 free (args_info->pwd_orig); /* free previous argument */
423 args_info->pwd_orig = 0;
424 }
425 if (args_info->net_arg)
426 {
427 free (args_info->net_arg); /* free previous argument */
428 args_info->net_arg = 0;
429 }
430 if (args_info->net_orig)
431 {
432 free (args_info->net_orig); /* free previous argument */
433 args_info->net_orig = 0;
434 }
435 if (args_info->ipup_arg)
436 {
437 free (args_info->ipup_arg); /* free previous argument */
438 args_info->ipup_arg = 0;
439 }
440 if (args_info->ipup_orig)
441 {
442 free (args_info->ipup_orig); /* free previous argument */
443 args_info->ipup_orig = 0;
444 }
445 if (args_info->ipdown_arg)
446 {
447 free (args_info->ipdown_arg); /* free previous argument */
448 args_info->ipdown_arg = 0;
449 }
450 if (args_info->ipdown_orig)
451 {
452 free (args_info->ipdown_orig); /* free previous argument */
453 args_info->ipdown_orig = 0;
454 }
455 if (args_info->pinghost_arg)
456 {
457 free (args_info->pinghost_arg); /* free previous argument */
458 args_info->pinghost_arg = 0;
459 }
460 if (args_info->pinghost_orig)
461 {
462 free (args_info->pinghost_orig); /* free previous argument */
463 args_info->pinghost_orig = 0;
464 }
465 if (args_info->pingrate_orig)
466 {
467 free (args_info->pingrate_orig); /* free previous argument */
468 args_info->pingrate_orig = 0;
469 }
470 if (args_info->pingsize_orig)
471 {
472 free (args_info->pingsize_orig); /* free previous argument */
473 args_info->pingsize_orig = 0;
474 }
475 if (args_info->pingcount_orig)
476 {
477 free (args_info->pingcount_orig); /* free previous argument */
478 args_info->pingcount_orig = 0;
479 }
480
481 clear_given (args_info);
482}
483
484int
485cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
486{
487 FILE *outfile;
488 int i = 0;
489
490 outfile = fopen(filename, "w");
491
492 if (!outfile)
493 {
494 fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
495 return EXIT_FAILURE;
496 }
497
498 if (args_info->help_given) {
499 fprintf(outfile, "%s\n", "help");
500 }
501 if (args_info->version_given) {
502 fprintf(outfile, "%s\n", "version");
503 }
504 if (args_info->debug_given) {
505 fprintf(outfile, "%s\n", "debug");
506 }
507 if (args_info->conf_given) {
508 if (args_info->conf_orig) {
509 fprintf(outfile, "%s=\"%s\"\n", "conf", args_info->conf_orig);
510 } else {
511 fprintf(outfile, "%s\n", "conf");
512 }
513 }
514 if (args_info->pidfile_given) {
515 if (args_info->pidfile_orig) {
516 fprintf(outfile, "%s=\"%s\"\n", "pidfile", args_info->pidfile_orig);
517 } else {
518 fprintf(outfile, "%s\n", "pidfile");
519 }
520 }
521 if (args_info->statedir_given) {
522 if (args_info->statedir_orig) {
523 fprintf(outfile, "%s=\"%s\"\n", "statedir", args_info->statedir_orig);
524 } else {
525 fprintf(outfile, "%s\n", "statedir");
526 }
527 }
528 if (args_info->dns_given) {
529 if (args_info->dns_orig) {
530 fprintf(outfile, "%s=\"%s\"\n", "dns", args_info->dns_orig);
531 } else {
532 fprintf(outfile, "%s\n", "dns");
533 }
534 }
535 if (args_info->listen_given) {
536 if (args_info->listen_orig) {
537 fprintf(outfile, "%s=\"%s\"\n", "listen", args_info->listen_orig);
538 } else {
539 fprintf(outfile, "%s\n", "listen");
540 }
541 }
542 if (args_info->remote_given) {
543 if (args_info->remote_orig) {
544 fprintf(outfile, "%s=\"%s\"\n", "remote", args_info->remote_orig);
545 } else {
546 fprintf(outfile, "%s\n", "remote");
547 }
548 }
549 if (args_info->contexts_given) {
550 if (args_info->contexts_orig) {
551 fprintf(outfile, "%s=\"%s\"\n", "contexts", args_info->contexts_orig);
552 } else {
553 fprintf(outfile, "%s\n", "contexts");
554 }
555 }
556 if (args_info->timelimit_given) {
557 if (args_info->timelimit_orig) {
558 fprintf(outfile, "%s=\"%s\"\n", "timelimit", args_info->timelimit_orig);
559 } else {
560 fprintf(outfile, "%s\n", "timelimit");
561 }
562 }
563 if (args_info->gtpversion_given) {
564 if (args_info->gtpversion_orig) {
565 fprintf(outfile, "%s=\"%s\"\n", "gtpversion", args_info->gtpversion_orig);
566 } else {
567 fprintf(outfile, "%s\n", "gtpversion");
568 }
569 }
570 if (args_info->apn_given) {
571 if (args_info->apn_orig) {
572 fprintf(outfile, "%s=\"%s\"\n", "apn", args_info->apn_orig);
573 } else {
574 fprintf(outfile, "%s\n", "apn");
575 }
576 }
577 if (args_info->selmode_given) {
578 if (args_info->selmode_orig) {
579 fprintf(outfile, "%s=\"%s\"\n", "selmode", args_info->selmode_orig);
580 } else {
581 fprintf(outfile, "%s\n", "selmode");
582 }
583 }
584 if (args_info->imsi_given) {
585 if (args_info->imsi_orig) {
586 fprintf(outfile, "%s=\"%s\"\n", "imsi", args_info->imsi_orig);
587 } else {
588 fprintf(outfile, "%s\n", "imsi");
589 }
590 }
591 if (args_info->nsapi_given) {
592 if (args_info->nsapi_orig) {
593 fprintf(outfile, "%s=\"%s\"\n", "nsapi", args_info->nsapi_orig);
594 } else {
595 fprintf(outfile, "%s\n", "nsapi");
596 }
597 }
598 if (args_info->msisdn_given) {
599 if (args_info->msisdn_orig) {
600 fprintf(outfile, "%s=\"%s\"\n", "msisdn", args_info->msisdn_orig);
601 } else {
602 fprintf(outfile, "%s\n", "msisdn");
603 }
604 }
605 if (args_info->qos_given) {
606 if (args_info->qos_orig) {
607 fprintf(outfile, "%s=\"%s\"\n", "qos", args_info->qos_orig);
608 } else {
609 fprintf(outfile, "%s\n", "qos");
610 }
611 }
612 if (args_info->charging_given) {
613 if (args_info->charging_orig) {
614 fprintf(outfile, "%s=\"%s\"\n", "charging", args_info->charging_orig);
615 } else {
616 fprintf(outfile, "%s\n", "charging");
617 }
618 }
619 if (args_info->uid_given) {
620 if (args_info->uid_orig) {
621 fprintf(outfile, "%s=\"%s\"\n", "uid", args_info->uid_orig);
622 } else {
623 fprintf(outfile, "%s\n", "uid");
624 }
625 }
626 if (args_info->pwd_given) {
627 if (args_info->pwd_orig) {
628 fprintf(outfile, "%s=\"%s\"\n", "pwd", args_info->pwd_orig);
629 } else {
630 fprintf(outfile, "%s\n", "pwd");
631 }
632 }
633 if (args_info->createif_given) {
634 fprintf(outfile, "%s\n", "createif");
635 }
636 if (args_info->net_given) {
637 if (args_info->net_orig) {
638 fprintf(outfile, "%s=\"%s\"\n", "net", args_info->net_orig);
639 } else {
640 fprintf(outfile, "%s\n", "net");
641 }
642 }
643 if (args_info->defaultroute_given) {
644 fprintf(outfile, "%s\n", "defaultroute");
645 }
646 if (args_info->ipup_given) {
647 if (args_info->ipup_orig) {
648 fprintf(outfile, "%s=\"%s\"\n", "ipup", args_info->ipup_orig);
649 } else {
650 fprintf(outfile, "%s\n", "ipup");
651 }
652 }
653 if (args_info->ipdown_given) {
654 if (args_info->ipdown_orig) {
655 fprintf(outfile, "%s=\"%s\"\n", "ipdown", args_info->ipdown_orig);
656 } else {
657 fprintf(outfile, "%s\n", "ipdown");
658 }
659 }
660 if (args_info->pinghost_given) {
661 if (args_info->pinghost_orig) {
662 fprintf(outfile, "%s=\"%s\"\n", "pinghost", args_info->pinghost_orig);
663 } else {
664 fprintf(outfile, "%s\n", "pinghost");
665 }
666 }
667 if (args_info->pingrate_given) {
668 if (args_info->pingrate_orig) {
669 fprintf(outfile, "%s=\"%s\"\n", "pingrate", args_info->pingrate_orig);
670 } else {
671 fprintf(outfile, "%s\n", "pingrate");
672 }
673 }
674 if (args_info->pingsize_given) {
675 if (args_info->pingsize_orig) {
676 fprintf(outfile, "%s=\"%s\"\n", "pingsize", args_info->pingsize_orig);
677 } else {
678 fprintf(outfile, "%s\n", "pingsize");
679 }
680 }
681 if (args_info->pingcount_given) {
682 if (args_info->pingcount_orig) {
683 fprintf(outfile, "%s=\"%s\"\n", "pingcount", args_info->pingcount_orig);
684 } else {
685 fprintf(outfile, "%s\n", "pingcount");
686 }
687 }
688 if (args_info->pingquiet_given) {
689 fprintf(outfile, "%s\n", "pingquiet");
690 }
691
692 fclose (outfile);
693
694 i = EXIT_SUCCESS;
695 return i;
696}
697
698void
699cmdline_parser_free (struct gengetopt_args_info *args_info)
700{
701 cmdline_parser_release (args_info);
702}
703
704
705/* gengetopt_strdup() */
706/* strdup.c replacement of strdup, which is not standard */
707char *
708gengetopt_strdup (const char *s)
709{
710 char *result = NULL;
711 if (!s)
712 return result;
713
714 result = (char*)malloc(strlen(s) + 1);
715 if (result == (char*)0)
716 return (char*)0;
717 strcpy(result, s);
718 return result;
719}
720
721int
722cmdline_parser (int argc, char * const *argv, struct gengetopt_args_info *args_info)
723{
724 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
725}
726
727int
728cmdline_parser2 (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
729{
730 int result;
731
732 result = cmdline_parser_internal (argc, argv, args_info, override, initialize, check_required, NULL);
733
734 if (result == EXIT_FAILURE)
735 {
736 cmdline_parser_free (args_info);
737 exit (EXIT_FAILURE);
738 }
739
740 return result;
741}
742
743int
744cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
745{
746 return EXIT_SUCCESS;
747}
748
749int
750cmdline_parser_internal (int argc, char * const *argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required, const char *additional_error)
751{
752 int c; /* Character of the parsed option. */
753
754 int error = 0;
755 struct gengetopt_args_info local_args_info;
756
757 if (initialize)
758 cmdline_parser_init (args_info);
759
760 cmdline_parser_init (&local_args_info);
jjako52c24142002-12-16 13:33:51 +0000761
762 optarg = 0;
Harald Welte1b3e5772010-05-04 11:13:56 +0200763 optind = 0;
jjako52c24142002-12-16 13:33:51 +0000764 opterr = 1;
765 optopt = '?';
766
767 while (1)
768 {
769 int option_index = 0;
770 char *stop_char;
Harald Welte1b3e5772010-05-04 11:13:56 +0200771
jjako52c24142002-12-16 13:33:51 +0000772 static struct option long_options[] = {
773 { "help", 0, NULL, 'h' },
774 { "version", 0, NULL, 'V' },
jjako52c24142002-12-16 13:33:51 +0000775 { "debug", 0, NULL, 'd' },
776 { "conf", 1, NULL, 'c' },
777 { "pidfile", 1, NULL, 0 },
778 { "statedir", 1, NULL, 0 },
779 { "dns", 1, NULL, 0 },
780 { "listen", 1, NULL, 'l' },
781 { "remote", 1, NULL, 'r' },
jjako52c24142002-12-16 13:33:51 +0000782 { "contexts", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000783 { "timelimit", 1, NULL, 0 },
jjako193e8b12003-11-10 12:31:41 +0000784 { "gtpversion", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000785 { "apn", 1, NULL, 'a' },
jjako1a51df72004-07-20 08:30:21 +0000786 { "selmode", 1, NULL, 0 },
Yann BONNAMY944dce32010-10-29 17:07:44 +0200787 { "rattype", 1, NULL, 0},
788 { "userloc", 1, NULL, 0},
789 { "mstz", 1, NULL, 0},
790 { "imeisv", 1, NULL, 0},
jjako52c24142002-12-16 13:33:51 +0000791 { "imsi", 1, NULL, 'i' },
jjako193e8b12003-11-10 12:31:41 +0000792 { "nsapi", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000793 { "msisdn", 1, NULL, 'm' },
794 { "qos", 1, NULL, 'q' },
jjako7e051d32004-05-27 20:06:36 +0000795 { "charging", 1, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000796 { "uid", 1, NULL, 'u' },
797 { "pwd", 1, NULL, 'p' },
jjako5da68452003-01-28 16:08:47 +0000798 { "createif", 0, NULL, 0 },
jjako193e8b12003-11-10 12:31:41 +0000799 { "net", 1, NULL, 'n' },
jjakoa7cd2492003-04-11 09:40:12 +0000800 { "defaultroute", 0, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000801 { "ipup", 1, NULL, 0 },
802 { "ipdown", 1, NULL, 0 },
jjako5da68452003-01-28 16:08:47 +0000803 { "pinghost", 1, NULL, 0 },
804 { "pingrate", 1, NULL, 0 },
805 { "pingsize", 1, NULL, 0 },
806 { "pingcount", 1, NULL, 0 },
807 { "pingquiet", 0, NULL, 0 },
jjako52c24142002-12-16 13:33:51 +0000808 { NULL, 0, NULL, 0 }
809 };
810
Harald Welte1b3e5772010-05-04 11:13:56 +0200811 stop_char = 0;
jjako193e8b12003-11-10 12:31:41 +0000812 c = getopt_long (argc, argv, "hVdc:l:r:a:i:m:q:u:p:n:", long_options, &option_index);
jjako52c24142002-12-16 13:33:51 +0000813
814 if (c == -1) break; /* Exit from `while (1)' loop. */
815
816 switch (c)
817 {
818 case 'h': /* Print help and exit. */
jjako52c24142002-12-16 13:33:51 +0000819 cmdline_parser_print_help ();
Harald Welte1b3e5772010-05-04 11:13:56 +0200820 cmdline_parser_free (&local_args_info);
jjako52c24142002-12-16 13:33:51 +0000821 exit (EXIT_SUCCESS);
822
823 case 'V': /* Print version and exit. */
jjako52c24142002-12-16 13:33:51 +0000824 cmdline_parser_print_version ();
Harald Welte1b3e5772010-05-04 11:13:56 +0200825 cmdline_parser_free (&local_args_info);
jjako52c24142002-12-16 13:33:51 +0000826 exit (EXIT_SUCCESS);
827
jjako52c24142002-12-16 13:33:51 +0000828 case 'd': /* Run in debug mode. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200829 if (local_args_info.debug_given)
jjako52c24142002-12-16 13:33:51 +0000830 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200831 fprintf (stderr, "%s: `--debug' (`-d') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
832 goto failure;
jjako52c24142002-12-16 13:33:51 +0000833 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200834 if (args_info->debug_given && ! override)
835 continue;
836 local_args_info.debug_given = 1;
jjako52c24142002-12-16 13:33:51 +0000837 args_info->debug_given = 1;
838 args_info->debug_flag = !(args_info->debug_flag);
839 break;
840
841 case 'c': /* Read configuration file. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200842 if (local_args_info.conf_given)
jjako52c24142002-12-16 13:33:51 +0000843 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200844 fprintf (stderr, "%s: `--conf' (`-c') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
845 goto failure;
jjako52c24142002-12-16 13:33:51 +0000846 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200847 if (args_info->conf_given && ! override)
848 continue;
849 local_args_info.conf_given = 1;
jjako52c24142002-12-16 13:33:51 +0000850 args_info->conf_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200851 if (args_info->conf_arg)
852 free (args_info->conf_arg); /* free previous string */
853 args_info->conf_arg = gengetopt_strdup (optarg);
854 if (args_info->conf_orig)
855 free (args_info->conf_orig); /* free previous string */
856 args_info->conf_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000857 break;
858
859 case 'l': /* Local interface. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200860 if (local_args_info.listen_given)
jjako52c24142002-12-16 13:33:51 +0000861 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200862 fprintf (stderr, "%s: `--listen' (`-l') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
863 goto failure;
jjako52c24142002-12-16 13:33:51 +0000864 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200865 if (args_info->listen_given && ! override)
866 continue;
867 local_args_info.listen_given = 1;
jjako52c24142002-12-16 13:33:51 +0000868 args_info->listen_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200869 if (args_info->listen_arg)
870 free (args_info->listen_arg); /* free previous string */
871 args_info->listen_arg = gengetopt_strdup (optarg);
872 if (args_info->listen_orig)
873 free (args_info->listen_orig); /* free previous string */
874 args_info->listen_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000875 break;
876
877 case 'r': /* Remote host. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200878 if (local_args_info.remote_given)
jjako52c24142002-12-16 13:33:51 +0000879 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200880 fprintf (stderr, "%s: `--remote' (`-r') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
881 goto failure;
jjako52c24142002-12-16 13:33:51 +0000882 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200883 if (args_info->remote_given && ! override)
884 continue;
885 local_args_info.remote_given = 1;
jjako52c24142002-12-16 13:33:51 +0000886 args_info->remote_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200887 if (args_info->remote_arg)
888 free (args_info->remote_arg); /* free previous string */
889 args_info->remote_arg = gengetopt_strdup (optarg);
890 if (args_info->remote_orig)
891 free (args_info->remote_orig); /* free previous string */
892 args_info->remote_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000893 break;
894
jjako52c24142002-12-16 13:33:51 +0000895 case 'a': /* Access point name. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200896 if (local_args_info.apn_given)
jjako52c24142002-12-16 13:33:51 +0000897 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200898 fprintf (stderr, "%s: `--apn' (`-a') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
899 goto failure;
jjako52c24142002-12-16 13:33:51 +0000900 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200901 if (args_info->apn_given && ! override)
902 continue;
903 local_args_info.apn_given = 1;
jjako52c24142002-12-16 13:33:51 +0000904 args_info->apn_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200905 if (args_info->apn_arg)
906 free (args_info->apn_arg); /* free previous string */
907 args_info->apn_arg = gengetopt_strdup (optarg);
908 if (args_info->apn_orig)
909 free (args_info->apn_orig); /* free previous string */
910 args_info->apn_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000911 break;
912
913 case 'i': /* IMSI. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200914 if (local_args_info.imsi_given)
jjako52c24142002-12-16 13:33:51 +0000915 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200916 fprintf (stderr, "%s: `--imsi' (`-i') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
917 goto failure;
jjako52c24142002-12-16 13:33:51 +0000918 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200919 if (args_info->imsi_given && ! override)
920 continue;
921 local_args_info.imsi_given = 1;
jjako52c24142002-12-16 13:33:51 +0000922 args_info->imsi_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200923 if (args_info->imsi_arg)
924 free (args_info->imsi_arg); /* free previous string */
925 args_info->imsi_arg = gengetopt_strdup (optarg);
926 if (args_info->imsi_orig)
927 free (args_info->imsi_orig); /* free previous string */
928 args_info->imsi_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000929 break;
930
931 case 'm': /* Mobile Station ISDN number. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200932 if (local_args_info.msisdn_given)
jjako52c24142002-12-16 13:33:51 +0000933 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200934 fprintf (stderr, "%s: `--msisdn' (`-m') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
935 goto failure;
jjako52c24142002-12-16 13:33:51 +0000936 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200937 if (args_info->msisdn_given && ! override)
938 continue;
939 local_args_info.msisdn_given = 1;
jjako52c24142002-12-16 13:33:51 +0000940 args_info->msisdn_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200941 if (args_info->msisdn_arg)
942 free (args_info->msisdn_arg); /* free previous string */
943 args_info->msisdn_arg = gengetopt_strdup (optarg);
944 if (args_info->msisdn_orig)
945 free (args_info->msisdn_orig); /* free previous string */
946 args_info->msisdn_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000947 break;
948
949 case 'q': /* Requested quality of service. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200950 if (local_args_info.qos_given)
jjako52c24142002-12-16 13:33:51 +0000951 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200952 fprintf (stderr, "%s: `--qos' (`-q') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
953 goto failure;
jjako52c24142002-12-16 13:33:51 +0000954 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200955 if (args_info->qos_given && ! override)
956 continue;
957 local_args_info.qos_given = 1;
jjako52c24142002-12-16 13:33:51 +0000958 args_info->qos_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200959 args_info->qos_arg = strtol (optarg, &stop_char, 0);
960 if (!(stop_char && *stop_char == '\0')) {
961 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
962 goto failure;
963 }
964 if (args_info->qos_orig)
965 free (args_info->qos_orig); /* free previous string */
966 args_info->qos_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000967 break;
968
969 case 'u': /* Login user ID. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200970 if (local_args_info.uid_given)
jjako52c24142002-12-16 13:33:51 +0000971 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200972 fprintf (stderr, "%s: `--uid' (`-u') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
973 goto failure;
jjako52c24142002-12-16 13:33:51 +0000974 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200975 if (args_info->uid_given && ! override)
976 continue;
977 local_args_info.uid_given = 1;
jjako52c24142002-12-16 13:33:51 +0000978 args_info->uid_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200979 if (args_info->uid_arg)
980 free (args_info->uid_arg); /* free previous string */
981 args_info->uid_arg = gengetopt_strdup (optarg);
982 if (args_info->uid_orig)
983 free (args_info->uid_orig); /* free previous string */
984 args_info->uid_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +0000985 break;
986
987 case 'p': /* Login password. */
Harald Welte1b3e5772010-05-04 11:13:56 +0200988 if (local_args_info.pwd_given)
jjako52c24142002-12-16 13:33:51 +0000989 {
Harald Welte1b3e5772010-05-04 11:13:56 +0200990 fprintf (stderr, "%s: `--pwd' (`-p') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
991 goto failure;
jjako52c24142002-12-16 13:33:51 +0000992 }
Harald Welte1b3e5772010-05-04 11:13:56 +0200993 if (args_info->pwd_given && ! override)
994 continue;
995 local_args_info.pwd_given = 1;
jjako52c24142002-12-16 13:33:51 +0000996 args_info->pwd_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +0200997 if (args_info->pwd_arg)
998 free (args_info->pwd_arg); /* free previous string */
999 args_info->pwd_arg = gengetopt_strdup (optarg);
1000 if (args_info->pwd_orig)
1001 free (args_info->pwd_orig); /* free previous string */
1002 args_info->pwd_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +00001003 break;
1004
jjako193e8b12003-11-10 12:31:41 +00001005 case 'n': /* Network address for local interface. */
Harald Welte1b3e5772010-05-04 11:13:56 +02001006 if (local_args_info.net_given)
jjako193e8b12003-11-10 12:31:41 +00001007 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001008 fprintf (stderr, "%s: `--net' (`-n') option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1009 goto failure;
jjako193e8b12003-11-10 12:31:41 +00001010 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001011 if (args_info->net_given && ! override)
1012 continue;
1013 local_args_info.net_given = 1;
jjako193e8b12003-11-10 12:31:41 +00001014 args_info->net_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001015 if (args_info->net_arg)
1016 free (args_info->net_arg); /* free previous string */
1017 args_info->net_arg = gengetopt_strdup (optarg);
1018 if (args_info->net_orig)
1019 free (args_info->net_orig); /* free previous string */
1020 args_info->net_orig = gengetopt_strdup (optarg);
jjako193e8b12003-11-10 12:31:41 +00001021 break;
1022
jjako52c24142002-12-16 13:33:51 +00001023
1024 case 0: /* Long option with no short option */
1025 /* Filename of process id file. */
1026 if (strcmp (long_options[option_index].name, "pidfile") == 0)
1027 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001028 if (local_args_info.pidfile_given)
jjako52c24142002-12-16 13:33:51 +00001029 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001030 fprintf (stderr, "%s: `--pidfile' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1031 goto failure;
jjako52c24142002-12-16 13:33:51 +00001032 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001033 if (args_info->pidfile_given && ! override)
1034 continue;
1035 local_args_info.pidfile_given = 1;
jjako52c24142002-12-16 13:33:51 +00001036 args_info->pidfile_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001037 if (args_info->pidfile_arg)
1038 free (args_info->pidfile_arg); /* free previous string */
1039 args_info->pidfile_arg = gengetopt_strdup (optarg);
1040 if (args_info->pidfile_orig)
1041 free (args_info->pidfile_orig); /* free previous string */
1042 args_info->pidfile_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +00001043 }
1044 /* Directory of nonvolatile data. */
1045 else if (strcmp (long_options[option_index].name, "statedir") == 0)
1046 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001047 if (local_args_info.statedir_given)
jjako52c24142002-12-16 13:33:51 +00001048 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001049 fprintf (stderr, "%s: `--statedir' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1050 goto failure;
jjako52c24142002-12-16 13:33:51 +00001051 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001052 if (args_info->statedir_given && ! override)
1053 continue;
1054 local_args_info.statedir_given = 1;
jjako52c24142002-12-16 13:33:51 +00001055 args_info->statedir_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001056 if (args_info->statedir_arg)
1057 free (args_info->statedir_arg); /* free previous string */
1058 args_info->statedir_arg = gengetopt_strdup (optarg);
1059 if (args_info->statedir_orig)
1060 free (args_info->statedir_orig); /* free previous string */
1061 args_info->statedir_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +00001062 }
1063 /* DNS Server to use. */
1064 else if (strcmp (long_options[option_index].name, "dns") == 0)
1065 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001066 if (local_args_info.dns_given)
jjako52c24142002-12-16 13:33:51 +00001067 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001068 fprintf (stderr, "%s: `--dns' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1069 goto failure;
jjako52c24142002-12-16 13:33:51 +00001070 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001071 if (args_info->dns_given && ! override)
1072 continue;
1073 local_args_info.dns_given = 1;
jjako52c24142002-12-16 13:33:51 +00001074 args_info->dns_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001075 if (args_info->dns_arg)
1076 free (args_info->dns_arg); /* free previous string */
1077 args_info->dns_arg = gengetopt_strdup (optarg);
1078 if (args_info->dns_orig)
1079 free (args_info->dns_orig); /* free previous string */
1080 args_info->dns_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +00001081 }
jjako52c24142002-12-16 13:33:51 +00001082 /* Number of contexts. */
1083 else if (strcmp (long_options[option_index].name, "contexts") == 0)
1084 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001085 if (local_args_info.contexts_given)
jjako52c24142002-12-16 13:33:51 +00001086 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001087 fprintf (stderr, "%s: `--contexts' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1088 goto failure;
jjako52c24142002-12-16 13:33:51 +00001089 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001090 if (args_info->contexts_given && ! override)
1091 continue;
1092 local_args_info.contexts_given = 1;
jjako52c24142002-12-16 13:33:51 +00001093 args_info->contexts_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001094 args_info->contexts_arg = strtol (optarg, &stop_char, 0);
1095 if (!(stop_char && *stop_char == '\0')) {
1096 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1097 goto failure;
1098 }
1099 if (args_info->contexts_orig)
1100 free (args_info->contexts_orig); /* free previous string */
1101 args_info->contexts_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +00001102 }
jjako52c24142002-12-16 13:33:51 +00001103 /* Exit after timelimit seconds. */
1104 else if (strcmp (long_options[option_index].name, "timelimit") == 0)
1105 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001106 if (local_args_info.timelimit_given)
jjako52c24142002-12-16 13:33:51 +00001107 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001108 fprintf (stderr, "%s: `--timelimit' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1109 goto failure;
jjako52c24142002-12-16 13:33:51 +00001110 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001111 if (args_info->timelimit_given && ! override)
1112 continue;
1113 local_args_info.timelimit_given = 1;
jjako52c24142002-12-16 13:33:51 +00001114 args_info->timelimit_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001115 args_info->timelimit_arg = strtol (optarg, &stop_char, 0);
1116 if (!(stop_char && *stop_char == '\0')) {
1117 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1118 goto failure;
1119 }
1120 if (args_info->timelimit_orig)
1121 free (args_info->timelimit_orig); /* free previous string */
1122 args_info->timelimit_orig = gengetopt_strdup (optarg);
jjako52c24142002-12-16 13:33:51 +00001123 }
jjako193e8b12003-11-10 12:31:41 +00001124 /* GTP version to use. */
1125 else if (strcmp (long_options[option_index].name, "gtpversion") == 0)
1126 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001127 if (local_args_info.gtpversion_given)
jjako193e8b12003-11-10 12:31:41 +00001128 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001129 fprintf (stderr, "%s: `--gtpversion' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1130 goto failure;
jjako193e8b12003-11-10 12:31:41 +00001131 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001132 if (args_info->gtpversion_given && ! override)
1133 continue;
1134 local_args_info.gtpversion_given = 1;
jjako193e8b12003-11-10 12:31:41 +00001135 args_info->gtpversion_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001136 args_info->gtpversion_arg = strtol (optarg, &stop_char, 0);
1137 if (!(stop_char && *stop_char == '\0')) {
1138 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1139 goto failure;
1140 }
1141 if (args_info->gtpversion_orig)
1142 free (args_info->gtpversion_orig); /* free previous string */
1143 args_info->gtpversion_orig = gengetopt_strdup (optarg);
jjako193e8b12003-11-10 12:31:41 +00001144 }
jjako1a51df72004-07-20 08:30:21 +00001145 /* Selection mode. */
1146 else if (strcmp (long_options[option_index].name, "selmode") == 0)
1147 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001148 if (local_args_info.selmode_given)
jjako1a51df72004-07-20 08:30:21 +00001149 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001150 fprintf (stderr, "%s: `--selmode' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1151 goto failure;
jjako1a51df72004-07-20 08:30:21 +00001152 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001153 if (args_info->selmode_given && ! override)
1154 continue;
1155 local_args_info.selmode_given = 1;
jjako1a51df72004-07-20 08:30:21 +00001156 args_info->selmode_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001157 args_info->selmode_arg = strtol (optarg, &stop_char, 0);
1158 if (!(stop_char && *stop_char == '\0')) {
1159 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1160 goto failure;
1161 }
1162 if (args_info->selmode_orig)
1163 free (args_info->selmode_orig); /* free previous string */
1164 args_info->selmode_orig = gengetopt_strdup (optarg);
jjako1a51df72004-07-20 08:30:21 +00001165 }
Yann BONNAMY944dce32010-10-29 17:07:44 +02001166 /* Radio Access Technology Type. */
1167 else if (strcmp (long_options[option_index].name, "rattype") == 0)
1168 {
1169 if (args_info->rattype_given)
1170 {
1171 fprintf (stderr, "%s: `--rattype' option given more than once\n", PACKAGE);
1172 exit (EXIT_FAILURE);
1173 }
1174 args_info->rattype_given = 1;
1175 /* args_info->rattype_arg = strtol (optarg,&stop_char,0); */
1176 args_info->rattype_arg = strdup (optarg);
1177 break;
1178 }
1179 /* User Location Information. */
1180 else if (strcmp (long_options[option_index].name, "userloc") == 0)
1181 {
1182 if (args_info->userloc_given)
1183 {
1184 fprintf (stderr, "%s: `--userloc' option given more than once\n", PACKAGE);
1185 exit (EXIT_FAILURE);
1186 }
1187 args_info->userloc_given = 1;
1188 args_info->userloc_arg = strdup (optarg);
1189 break;
1190 }
1191 /* MS Time Zone */
1192 else if (strcmp (long_options[option_index].name, "mstz") == 0)
1193 {
1194 if (args_info->mstz_given)
1195 {
1196 fprintf (stderr, "%s: `--mstz' option given more than once\n", PACKAGE);
1197 exit (EXIT_FAILURE);
1198 }
1199 args_info->mstz_given = 1;
1200 args_info->mstz_arg = strdup (optarg);
1201 break;
1202 }
1203 /* IMEI(SV) */
1204 else if (strcmp (long_options[option_index].name, "imeisv") == 0)
1205 {
1206 if (args_info->imeisv_given)
1207 {
1208 fprintf (stderr, "%s: `--imeisv' option given more than once\n", PACKAGE);
1209 exit (EXIT_FAILURE);
1210 }
1211 args_info->imeisv_given = 1;
1212 args_info->imeisv_arg = strdup (optarg);
1213 break;
1214 }
jjako193e8b12003-11-10 12:31:41 +00001215 /* NSAPI. */
1216 else if (strcmp (long_options[option_index].name, "nsapi") == 0)
1217 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001218 if (local_args_info.nsapi_given)
jjako193e8b12003-11-10 12:31:41 +00001219 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001220 fprintf (stderr, "%s: `--nsapi' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1221 goto failure;
jjako193e8b12003-11-10 12:31:41 +00001222 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001223 if (args_info->nsapi_given && ! override)
1224 continue;
1225 local_args_info.nsapi_given = 1;
jjako193e8b12003-11-10 12:31:41 +00001226 args_info->nsapi_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001227 args_info->nsapi_arg = strtol (optarg, &stop_char, 0);
1228 if (!(stop_char && *stop_char == '\0')) {
1229 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1230 goto failure;
1231 }
1232 if (args_info->nsapi_orig)
1233 free (args_info->nsapi_orig); /* free previous string */
1234 args_info->nsapi_orig = gengetopt_strdup (optarg);
jjako193e8b12003-11-10 12:31:41 +00001235 }
jjako7e051d32004-05-27 20:06:36 +00001236 /* Charging characteristics. */
1237 else if (strcmp (long_options[option_index].name, "charging") == 0)
1238 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001239 if (local_args_info.charging_given)
jjako7e051d32004-05-27 20:06:36 +00001240 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001241 fprintf (stderr, "%s: `--charging' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1242 goto failure;
jjako7e051d32004-05-27 20:06:36 +00001243 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001244 if (args_info->charging_given && ! override)
1245 continue;
1246 local_args_info.charging_given = 1;
jjako7e051d32004-05-27 20:06:36 +00001247 args_info->charging_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001248 args_info->charging_arg = strtol (optarg, &stop_char, 0);
1249 if (!(stop_char && *stop_char == '\0')) {
1250 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1251 goto failure;
1252 }
1253 if (args_info->charging_orig)
1254 free (args_info->charging_orig); /* free previous string */
1255 args_info->charging_orig = gengetopt_strdup (optarg);
jjako7e051d32004-05-27 20:06:36 +00001256 }
jjako5da68452003-01-28 16:08:47 +00001257 /* Create local network interface. */
1258 else if (strcmp (long_options[option_index].name, "createif") == 0)
1259 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001260 if (local_args_info.createif_given)
jjako5da68452003-01-28 16:08:47 +00001261 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001262 fprintf (stderr, "%s: `--createif' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1263 goto failure;
jjako5da68452003-01-28 16:08:47 +00001264 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001265 if (args_info->createif_given && ! override)
1266 continue;
1267 local_args_info.createif_given = 1;
jjako5da68452003-01-28 16:08:47 +00001268 args_info->createif_given = 1;
1269 args_info->createif_flag = !(args_info->createif_flag);
jjako5da68452003-01-28 16:08:47 +00001270 }
jjakoa7cd2492003-04-11 09:40:12 +00001271 /* Create default route. */
1272 else if (strcmp (long_options[option_index].name, "defaultroute") == 0)
1273 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001274 if (local_args_info.defaultroute_given)
jjakoa7cd2492003-04-11 09:40:12 +00001275 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001276 fprintf (stderr, "%s: `--defaultroute' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1277 goto failure;
jjakoa7cd2492003-04-11 09:40:12 +00001278 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001279 if (args_info->defaultroute_given && ! override)
1280 continue;
1281 local_args_info.defaultroute_given = 1;
jjakoa7cd2492003-04-11 09:40:12 +00001282 args_info->defaultroute_given = 1;
1283 args_info->defaultroute_flag = !(args_info->defaultroute_flag);
jjakoa7cd2492003-04-11 09:40:12 +00001284 }
jjako5da68452003-01-28 16:08:47 +00001285 /* Script to run after link-up. */
1286 else if (strcmp (long_options[option_index].name, "ipup") == 0)
1287 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001288 if (local_args_info.ipup_given)
jjako5da68452003-01-28 16:08:47 +00001289 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001290 fprintf (stderr, "%s: `--ipup' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1291 goto failure;
jjako5da68452003-01-28 16:08:47 +00001292 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001293 if (args_info->ipup_given && ! override)
1294 continue;
1295 local_args_info.ipup_given = 1;
jjako5da68452003-01-28 16:08:47 +00001296 args_info->ipup_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001297 if (args_info->ipup_arg)
1298 free (args_info->ipup_arg); /* free previous string */
1299 args_info->ipup_arg = gengetopt_strdup (optarg);
1300 if (args_info->ipup_orig)
1301 free (args_info->ipup_orig); /* free previous string */
1302 args_info->ipup_orig = gengetopt_strdup (optarg);
jjako5da68452003-01-28 16:08:47 +00001303 }
1304 /* Script to run after link-down. */
1305 else if (strcmp (long_options[option_index].name, "ipdown") == 0)
1306 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001307 if (local_args_info.ipdown_given)
jjako5da68452003-01-28 16:08:47 +00001308 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001309 fprintf (stderr, "%s: `--ipdown' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1310 goto failure;
jjako5da68452003-01-28 16:08:47 +00001311 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001312 if (args_info->ipdown_given && ! override)
1313 continue;
1314 local_args_info.ipdown_given = 1;
jjako5da68452003-01-28 16:08:47 +00001315 args_info->ipdown_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001316 if (args_info->ipdown_arg)
1317 free (args_info->ipdown_arg); /* free previous string */
1318 args_info->ipdown_arg = gengetopt_strdup (optarg);
1319 if (args_info->ipdown_orig)
1320 free (args_info->ipdown_orig); /* free previous string */
1321 args_info->ipdown_orig = gengetopt_strdup (optarg);
jjako5da68452003-01-28 16:08:47 +00001322 }
jjako5da68452003-01-28 16:08:47 +00001323 /* Ping remote host. */
1324 else if (strcmp (long_options[option_index].name, "pinghost") == 0)
1325 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001326 if (local_args_info.pinghost_given)
jjako5da68452003-01-28 16:08:47 +00001327 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001328 fprintf (stderr, "%s: `--pinghost' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1329 goto failure;
jjako5da68452003-01-28 16:08:47 +00001330 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001331 if (args_info->pinghost_given && ! override)
1332 continue;
1333 local_args_info.pinghost_given = 1;
jjako5da68452003-01-28 16:08:47 +00001334 args_info->pinghost_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001335 if (args_info->pinghost_arg)
1336 free (args_info->pinghost_arg); /* free previous string */
1337 args_info->pinghost_arg = gengetopt_strdup (optarg);
1338 if (args_info->pinghost_orig)
1339 free (args_info->pinghost_orig); /* free previous string */
1340 args_info->pinghost_orig = gengetopt_strdup (optarg);
jjako5da68452003-01-28 16:08:47 +00001341 }
1342 /* Number of ping req per second. */
1343 else if (strcmp (long_options[option_index].name, "pingrate") == 0)
1344 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001345 if (local_args_info.pingrate_given)
jjako5da68452003-01-28 16:08:47 +00001346 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001347 fprintf (stderr, "%s: `--pingrate' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1348 goto failure;
jjako5da68452003-01-28 16:08:47 +00001349 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001350 if (args_info->pingrate_given && ! override)
1351 continue;
1352 local_args_info.pingrate_given = 1;
jjako5da68452003-01-28 16:08:47 +00001353 args_info->pingrate_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001354 args_info->pingrate_arg = strtol (optarg, &stop_char, 0);
1355 if (!(stop_char && *stop_char == '\0')) {
1356 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1357 goto failure;
1358 }
1359 if (args_info->pingrate_orig)
1360 free (args_info->pingrate_orig); /* free previous string */
1361 args_info->pingrate_orig = gengetopt_strdup (optarg);
jjako5da68452003-01-28 16:08:47 +00001362 }
1363 /* Number of ping data bytes. */
1364 else if (strcmp (long_options[option_index].name, "pingsize") == 0)
1365 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001366 if (local_args_info.pingsize_given)
jjako5da68452003-01-28 16:08:47 +00001367 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001368 fprintf (stderr, "%s: `--pingsize' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1369 goto failure;
jjako5da68452003-01-28 16:08:47 +00001370 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001371 if (args_info->pingsize_given && ! override)
1372 continue;
1373 local_args_info.pingsize_given = 1;
jjako5da68452003-01-28 16:08:47 +00001374 args_info->pingsize_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001375 args_info->pingsize_arg = strtol (optarg, &stop_char, 0);
1376 if (!(stop_char && *stop_char == '\0')) {
1377 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1378 goto failure;
1379 }
1380 if (args_info->pingsize_orig)
1381 free (args_info->pingsize_orig); /* free previous string */
1382 args_info->pingsize_orig = gengetopt_strdup (optarg);
jjako5da68452003-01-28 16:08:47 +00001383 }
1384 /* Number of ping req to send. */
1385 else if (strcmp (long_options[option_index].name, "pingcount") == 0)
1386 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001387 if (local_args_info.pingcount_given)
jjako5da68452003-01-28 16:08:47 +00001388 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001389 fprintf (stderr, "%s: `--pingcount' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1390 goto failure;
jjako5da68452003-01-28 16:08:47 +00001391 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001392 if (args_info->pingcount_given && ! override)
1393 continue;
1394 local_args_info.pingcount_given = 1;
jjako5da68452003-01-28 16:08:47 +00001395 args_info->pingcount_given = 1;
Harald Welte1b3e5772010-05-04 11:13:56 +02001396 args_info->pingcount_arg = strtol (optarg, &stop_char, 0);
1397 if (!(stop_char && *stop_char == '\0')) {
1398 fprintf(stderr, "%s: invalid numeric value: %s\n", argv[0], optarg);
1399 goto failure;
1400 }
1401 if (args_info->pingcount_orig)
1402 free (args_info->pingcount_orig); /* free previous string */
1403 args_info->pingcount_orig = gengetopt_strdup (optarg);
jjako5da68452003-01-28 16:08:47 +00001404 }
1405 /* Do not print ping packet info. */
1406 else if (strcmp (long_options[option_index].name, "pingquiet") == 0)
1407 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001408 if (local_args_info.pingquiet_given)
jjako5da68452003-01-28 16:08:47 +00001409 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001410 fprintf (stderr, "%s: `--pingquiet' option given more than once%s\n", argv[0], (additional_error ? additional_error : ""));
1411 goto failure;
jjako5da68452003-01-28 16:08:47 +00001412 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001413 if (args_info->pingquiet_given && ! override)
1414 continue;
1415 local_args_info.pingquiet_given = 1;
jjako5da68452003-01-28 16:08:47 +00001416 args_info->pingquiet_given = 1;
1417 args_info->pingquiet_flag = !(args_info->pingquiet_flag);
jjako5da68452003-01-28 16:08:47 +00001418 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001419
1420 break;
jjako52c24142002-12-16 13:33:51 +00001421 case '?': /* Invalid option. */
1422 /* `getopt_long' already printed an error message. */
Harald Welte1b3e5772010-05-04 11:13:56 +02001423 goto failure;
jjako52c24142002-12-16 13:33:51 +00001424
1425 default: /* bug: option not considered. */
Harald Welte1b3e5772010-05-04 11:13:56 +02001426 fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
jjako52c24142002-12-16 13:33:51 +00001427 abort ();
1428 } /* switch */
1429 } /* while */
1430
1431
Harald Welte1b3e5772010-05-04 11:13:56 +02001432
1433
1434 cmdline_parser_release (&local_args_info);
1435
1436 if ( error )
1437 return (EXIT_FAILURE);
jjako52c24142002-12-16 13:33:51 +00001438
1439 return 0;
Harald Welte1b3e5772010-05-04 11:13:56 +02001440
1441failure:
1442
1443 cmdline_parser_release (&local_args_info);
1444 return (EXIT_FAILURE);
jjako52c24142002-12-16 13:33:51 +00001445}
1446
Harald Welte1b3e5772010-05-04 11:13:56 +02001447#ifndef CONFIG_FILE_LINE_SIZE
1448#define CONFIG_FILE_LINE_SIZE 2048
1449#endif
1450#define ADDITIONAL_ERROR " in configuration file "
1451
1452#define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3)
1453/* 3 is for "--" and "=" */
1454
1455char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE+1];
jjako52c24142002-12-16 13:33:51 +00001456
1457int
Harald Welte1b3e5772010-05-04 11:13:56 +02001458cmdline_parser_configfile (char * const filename, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
jjako52c24142002-12-16 13:33:51 +00001459{
1460 FILE* file;
Harald Welte1b3e5772010-05-04 11:13:56 +02001461 char linebuf[CONFIG_FILE_LINE_SIZE];
jjako52c24142002-12-16 13:33:51 +00001462 int line_num = 0;
Harald Welte1b3e5772010-05-04 11:13:56 +02001463 int i, result, equal;
1464 char *fopt, *farg;
1465 char *str_index;
1466 size_t len, next_token;
1467 char delimiter;
1468 int my_argc = 0;
1469 char **my_argv_arg;
1470 char *additional_error;
1471
1472 /* store the program name */
1473 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1474 cmd_line_list_tmp->next = cmd_line_list;
1475 cmd_line_list = cmd_line_list_tmp;
1476 cmd_line_list->string_arg = gengetopt_strdup (CMDLINE_PARSER_PACKAGE);
jjako52c24142002-12-16 13:33:51 +00001477
1478 if ((file = fopen(filename, "r")) == NULL)
1479 {
1480 fprintf (stderr, "%s: Error opening configuration file '%s'\n",
Harald Welte1b3e5772010-05-04 11:13:56 +02001481 CMDLINE_PARSER_PACKAGE, filename);
1482 result = EXIT_FAILURE;
1483 goto conf_failure;
jjako52c24142002-12-16 13:33:51 +00001484 }
1485
Harald Welte1b3e5772010-05-04 11:13:56 +02001486 while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL)
jjako52c24142002-12-16 13:33:51 +00001487 {
1488 ++line_num;
Harald Welte1b3e5772010-05-04 11:13:56 +02001489 my_argv[0] = '\0';
jjako52c24142002-12-16 13:33:51 +00001490 len = strlen(linebuf);
Harald Welte1b3e5772010-05-04 11:13:56 +02001491 if (len > (CONFIG_FILE_LINE_BUFFER_SIZE-1))
jjako52c24142002-12-16 13:33:51 +00001492 {
Harald Welte1b3e5772010-05-04 11:13:56 +02001493 fprintf (stderr, "%s:%s:%d: Line too long in configuration file\n",
1494 CMDLINE_PARSER_PACKAGE, filename, line_num);
1495 result = EXIT_FAILURE;
1496 goto conf_failure;
jjako52c24142002-12-16 13:33:51 +00001497 }
1498
Harald Welte1b3e5772010-05-04 11:13:56 +02001499 /* find first non-whitespace character in the line */
1500 next_token = strspn ( linebuf, " \t\r\n");
1501 str_index = linebuf + next_token;
jjako52c24142002-12-16 13:33:51 +00001502
Harald Welte1b3e5772010-05-04 11:13:56 +02001503 if ( str_index[0] == '\0' || str_index[0] == '#')
1504 continue; /* empty line or comment line is skipped */
1505
1506 fopt = str_index;
1507
1508 /* truncate fopt at the end of the first non-valid character */
1509 next_token = strcspn (fopt, " \t\r\n=");
1510
1511 if (fopt[next_token] == '\0') /* the line is over */
1512 {
1513 farg = NULL;
1514 equal = 0;
1515 goto noarg;
jjako52c24142002-12-16 13:33:51 +00001516 }
Harald Welte1b3e5772010-05-04 11:13:56 +02001517
1518 /* remember if equal sign is present */
1519 equal = (fopt[next_token] == '=');
1520 fopt[next_token++] = '\0';
1521
1522 /* advance pointers to the next token after the end of fopt */
1523 next_token += strspn (fopt + next_token, " \t\r\n");
1524 /* check for the presence of equal sign, and if so, skip it */
1525 if ( !equal )
1526 if ((equal = (fopt[next_token] == '=')))
1527 {
1528 next_token++;
1529 next_token += strspn (fopt + next_token, " \t\r\n");
1530 }
1531 str_index += next_token;
1532
1533 /* find argument */
1534 farg = str_index;
1535 if ( farg[0] == '\"' || farg[0] == '\'' )
1536 { /* quoted argument */
1537 str_index = strchr (++farg, str_index[0] ); /* skip opening quote */
1538 if (! str_index)
1539 {
1540 fprintf
1541 (stderr,
1542 "%s:%s:%d: unterminated string in configuration file\n",
1543 CMDLINE_PARSER_PACKAGE, filename, line_num);
1544 result = EXIT_FAILURE;
1545 goto conf_failure;
1546 }
1547 }
1548 else
1549 { /* read up the remaining part up to a delimiter */
1550 next_token = strcspn (farg, " \t\r\n#\'\"");
1551 str_index += next_token;
1552 }
1553
1554 /* truncate farg at the delimiter and store it for further check */
1555 delimiter = *str_index, *str_index++ = '\0';
1556
1557 /* everything but comment is illegal at the end of line */
1558 if (delimiter != '\0' && delimiter != '#')
1559 {
1560 str_index += strspn(str_index, " \t\r\n");
1561 if (*str_index != '\0' && *str_index != '#')
1562 {
1563 fprintf
1564 (stderr,
1565 "%s:%s:%d: malformed string in configuration file\n",
1566 CMDLINE_PARSER_PACKAGE, filename, line_num);
1567 result = EXIT_FAILURE;
1568 goto conf_failure;
1569 }
1570 }
1571
1572 noarg:
1573 ++my_argc;
1574 len = strlen(fopt);
1575
1576 strcat (my_argv, len > 1 ? "--" : "-");
1577 strcat (my_argv, fopt);
1578 if (len > 1 && ((farg &&*farg) || equal))
1579 strcat (my_argv, "=");
1580 if (farg && *farg)
1581 strcat (my_argv, farg);
1582
1583 cmd_line_list_tmp = (struct line_list *) malloc (sizeof (struct line_list));
1584 cmd_line_list_tmp->next = cmd_line_list;
1585 cmd_line_list = cmd_line_list_tmp;
1586 cmd_line_list->string_arg = gengetopt_strdup(my_argv);
jjako52c24142002-12-16 13:33:51 +00001587 } /* while */
jjako52c24142002-12-16 13:33:51 +00001588
Harald Welte1b3e5772010-05-04 11:13:56 +02001589 ++my_argc; /* for program name */
1590 my_argv_arg = (char **) malloc((my_argc+1) * sizeof(char *));
1591 cmd_line_list_tmp = cmd_line_list;
1592 for (i = my_argc - 1; i >= 0; --i) {
1593 my_argv_arg[i] = cmd_line_list_tmp->string_arg;
1594 cmd_line_list_tmp = cmd_line_list_tmp->next;
1595 }
1596 my_argv_arg[my_argc] = 0;
1597
1598 additional_error = (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1);
1599 strcpy (additional_error, ADDITIONAL_ERROR);
1600 strcat (additional_error, filename);
1601 result =
1602 cmdline_parser_internal (my_argc, my_argv_arg, args_info, override, initialize, check_required, additional_error);
1603
1604 free (additional_error);
1605 free (my_argv_arg);
1606
1607conf_failure:
1608 if (file)
1609 fclose(file);
1610
1611 free_cmd_list();
1612 if (result == EXIT_FAILURE)
1613 {
1614 cmdline_parser_free (args_info);
1615 exit (EXIT_FAILURE);
1616 }
1617
1618 return result;
jjako52c24142002-12-16 13:33:51 +00001619}