diff options
author | Harald Welte <laforge@gnumonks.org> | 2017-09-24 10:23:24 +0800 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2017-09-24 10:27:07 +0800 |
commit | f621498129023a17f8023d1f865cfe66ba9c235a (patch) | |
tree | 95632243f01a88802fee38ee122b31943088198b /sgsnemu | |
parent | 7c20148e396928f587a3719e092a8d1486664773 (diff) |
sgsnemu: Re-generate cmdline.[ch] using gengetopt
This will replace the manual additions to cmdline.[ch] with
auto-generated code from gengetopt. We need to fix-up the RAT Type in
sgsnemu.c as the manually-added code diverged from what gengetopt
generates.
Change-Id: Ia687e13d5cec1655a57078a767d2123aa022842c
Diffstat (limited to 'sgsnemu')
-rw-r--r-- | sgsnemu/cmdline.c | 2200 | ||||
-rw-r--r-- | sgsnemu/cmdline.ggo | 6 | ||||
-rw-r--r-- | sgsnemu/cmdline.h | 607 | ||||
-rw-r--r-- | sgsnemu/sgsnemu.c | 6 |
4 files changed, 1419 insertions, 1400 deletions
diff --git a/sgsnemu/cmdline.c b/sgsnemu/cmdline.c index 1ff1a59..88210d7 100644 --- a/sgsnemu/cmdline.c +++ b/sgsnemu/cmdline.c @@ -1,5 +1,5 @@ /* - File autogenerated by gengetopt version 2.17 + File autogenerated by gengetopt version 2.22.6 generated with the following command: gengetopt --conf-parser @@ -17,7 +17,11 @@ #include <stdlib.h> #include <string.h> -#include "getopt.h" +#ifndef FIX_UNUSED +#define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */ +#endif + +#include <getopt.h> #include "cmdline.h" @@ -26,60 +30,67 @@ const char *gengetopt_args_info_purpose = ""; const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]..."; +const char *gengetopt_args_info_versiontext = ""; + +const char *gengetopt_args_info_description = ""; + const char *gengetopt_args_info_help[] = { - " -h, --help Print help and exit", - " -V, --version Print version and exit", - " -d, --debug Run in debug mode (default=off)", - " -c, --conf=STRING Read configuration file", - " --pidfile=STRING Filename of process id file (default=`./sgsnemu.pid')", - " --statedir=STRING Directory of nonvolatile data (default=`./')", - " --dns=STRING DNS Server to use", - " -l, --listen=STRING Local interface", - " -r, --remote=STRING Remote host", - " --contexts=INT Number of contexts (default=`1')", - " --timelimit=INT Exit after timelimit seconds (default=`0')", - " --gtpversion=INT GTP version to use (default=`1')", - " -a, --apn=STRING Access point name (default=`internet')", - " --selmode=INT Selection mode (default=`0x01')", - " --rattype=INT Radio Access Technology Type (optional-1to5)", - " --userloc=STRING User Location Information (optional-type.MCC.MNC.LAC.CIorSACorRAC)", - " --rai=STRING Routing Area Information (optional-MCC.MNC.LAC.RAC)", - " --mstz=STRING MS Time Zone (optional- sign.NbQuartersOfAnHour.DSTAdjustment)", - " --imeisv=STRING IMEI(SV) International Mobile Equipment Identity (and Software Version) (optional,16 digits)", - " -i, --imsi=STRING IMSI (default=`240010123456789')", - " --nsapi=INT NSAPI (default=`0')", - " -m, --msisdn=STRING Mobile Station ISDN number (default=`46702123456')", - " -q, --qos=INT Requested quality of service (default=`0x000b921f')", - " --qose1=INT Requested quality of service Extension 1 (example=`0x9396404074f9ffff')", - " --qose2=INT Requested quality of service Extension 2 (example=`0x11')", - " --qose3=INT Requested quality of service Extension 3 (example=`0x0101')", - " --qose4=INT Requested quality of service Extension 4 (example=`0x4040')", - " --charging=INT Charging characteristics (default=`0x0800')", - " -u, --uid=STRING Login user ID (default=`mig')", - " -p, --pwd=STRING Login password (default=`hemmelig')", - " --createif Create local network interface (default=off)", - " -n, --net=STRING Network address for local interface", - " --defaultroute Create default route (default=off)", - " --ipup=STRING Script to run after link-up", - " --ipdown=STRING Script to run after link-down", - " --pinghost=STRING Ping remote host", - " --pingrate=INT Number of ping req per second (default=`1')", - " --pingsize=INT Number of ping data bytes (default=`56')", - " --pingcount=INT Number of ping req to send (default=`0')", - " --pingquiet Do not print ping packet info (default=off)", - " --norecovery Do not send recovery (default=off)", + " -h, --help Print help and exit", + " -V, --version Print version and exit", + " -d, --debug Run in debug mode (default=off)", + " -c, --conf=STRING Read configuration file", + " --pidfile=STRING Filename of process id file\n (default=`./sgsnemu.pid')", + " --statedir=STRING Directory of nonvolatile data (default=`./')", + " --dns=STRING DNS Server to use", + " -l, --listen=STRING Local interface", + " -r, --remote=STRING Remote host", + " --contexts=INT Number of contexts (default=`1')", + " --timelimit=INT Exit after timelimit seconds (default=`0')", + " --gtpversion=INT GTP version to use (default=`1')", + " -a, --apn=STRING Access point name (default=`internet')", + " --selmode=INT Selection mode (default=`0x01')", + " --rattype=1..5 Radio Access Technology Type (default=`1')", + " --userloc=type.MCC.MNC.LAC.CIorSACorRAC\n User Location Information\n (default=`02509946241207')", + " --rai=MCC.MNC.LAC.RAC Routing Area Information\n (default=`02509946241207')", + " --mstz=sign.NbQuartersOfAnHour.DSTAdjustment\n MS Time Zone (default=`0')", + " --imeisv=STRING IMEI(SV) International Mobile Equipment\n Identity (and Software Version)\n (default=`2143658709214365')", + " --norecovery Do not send recovery (default=off)", + " -i, --imsi=STRING IMSI (default=`240010123456789')", + " --nsapi=INT NSAPI (default=`0')", + " -m, --msisdn=STRING Mobile Station ISDN number\n (default=`46702123456')", + " -q, --qos=INT Requested quality of service\n (default=`0x000b921f')", + " --qose1=INT Requested quality of service Extension 1\n (default=`0x9396404074f9ffff')", + " --qose2=INT Requested quality of service Extension 2\n (default=`0x11')", + " --qose3=INT Requested quality of service Extension 3\n (default=`0x0101')", + " --qose4=INT Requested quality of service Extension 4\n (default=`0x4040')", + " --charging=INT Charging characteristics (default=`0x0800')", + " -u, --uid=STRING Login user ID (default=`mig')", + " -p, --pwd=STRING Login password (default=`hemmelig')", + " --createif Create local network interface (default=off)", + " -n, --net=STRING Network address for local interface", + " --defaultroute Create default route (default=off)", + " --ipup=STRING Script to run after link-up", + " --ipdown=STRING Script to run after link-down", + " --pinghost=STRING Ping remote host", + " --pingrate=INT Number of ping req per second (default=`1')", + " --pingsize=INT Number of ping data bytes (default=`56')", + " --pingcount=INT Number of ping req to send (default=`0')", + " --pingquiet Do not print ping packet info (default=off)", 0 }; +typedef enum { ARG_NO, ARG_FLAG, ARG_STRING, ARG_INT +} cmdline_parser_arg_type; + static void clear_given(struct gengetopt_args_info *args_info); static void clear_args(struct gengetopt_args_info *args_info); static int -cmdline_parser_internal(int argc, char *const *argv, - struct gengetopt_args_info *args_info, int override, - int initialize, int check_required, +cmdline_parser_internal(int argc, char **argv, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params, const char *additional_error); struct line_list { @@ -127,6 +138,7 @@ void clear_given(struct gengetopt_args_info *args_info) args_info->rai_given = 0; args_info->mstz_given = 0; args_info->imeisv_given = 0; + args_info->norecovery_given = 0; args_info->imsi_given = 0; args_info->nsapi_given = 0; args_info->msisdn_given = 0; @@ -148,12 +160,12 @@ void clear_given(struct gengetopt_args_info *args_info) args_info->pingsize_given = 0; args_info->pingcount_given = 0; args_info->pingquiet_given = 0; - args_info->norecovery_given = 0; } static void clear_args(struct gengetopt_args_info *args_info) { + FIX_UNUSED(args_info); args_info->debug_flag = 0; args_info->conf_arg = NULL; args_info->conf_orig = NULL; @@ -177,16 +189,17 @@ void clear_args(struct gengetopt_args_info *args_info) args_info->apn_orig = NULL; args_info->selmode_arg = 0x01; args_info->selmode_orig = NULL; - args_info->rattype_arg = "1"; + args_info->rattype_arg = 1; args_info->rattype_orig = NULL; - args_info->userloc_arg = strdup("02509946241207"); + args_info->userloc_arg = gengetopt_strdup("02509946241207"); args_info->userloc_orig = NULL; - args_info->rai_arg = strdup("02509946241207"); + args_info->rai_arg = gengetopt_strdup("02509946241207"); args_info->rai_orig = NULL; - args_info->mstz_arg = strdup("0"); + args_info->mstz_arg = gengetopt_strdup("0"); args_info->mstz_orig = NULL; - args_info->imeisv_arg = strdup("2143658709214365"); + args_info->imeisv_arg = gengetopt_strdup("2143658709214365"); args_info->imeisv_orig = NULL; + args_info->norecovery_flag = 0; args_info->imsi_arg = gengetopt_strdup("240010123456789"); args_info->imsi_orig = NULL; args_info->nsapi_arg = 0; @@ -226,13 +239,13 @@ void clear_args(struct gengetopt_args_info *args_info) args_info->pingcount_arg = 0; args_info->pingcount_orig = NULL; args_info->pingquiet_flag = 0; - args_info->norecovery_flag = 0; } static void init_args_info(struct gengetopt_args_info *args_info) { + args_info->help_help = gengetopt_args_info_help[0]; args_info->version_help = gengetopt_args_info_help[1]; args_info->debug_help = gengetopt_args_info_help[2]; @@ -247,41 +260,67 @@ void init_args_info(struct gengetopt_args_info *args_info) args_info->gtpversion_help = gengetopt_args_info_help[11]; args_info->apn_help = gengetopt_args_info_help[12]; args_info->selmode_help = gengetopt_args_info_help[13]; - args_info->imsi_help = gengetopt_args_info_help[14]; - args_info->nsapi_help = gengetopt_args_info_help[15]; - args_info->msisdn_help = gengetopt_args_info_help[16]; - args_info->qos_help = gengetopt_args_info_help[17]; - args_info->charging_help = gengetopt_args_info_help[18]; - args_info->uid_help = gengetopt_args_info_help[19]; - args_info->pwd_help = gengetopt_args_info_help[20]; - args_info->createif_help = gengetopt_args_info_help[21]; - args_info->net_help = gengetopt_args_info_help[22]; - args_info->defaultroute_help = gengetopt_args_info_help[23]; - args_info->ipup_help = gengetopt_args_info_help[24]; - args_info->ipdown_help = gengetopt_args_info_help[25]; - args_info->pinghost_help = gengetopt_args_info_help[26]; - args_info->pingrate_help = gengetopt_args_info_help[27]; - args_info->pingsize_help = gengetopt_args_info_help[28]; - args_info->pingcount_help = gengetopt_args_info_help[29]; - args_info->pingquiet_help = gengetopt_args_info_help[30]; - args_info->norecovery_help = gengetopt_args_info_help[31]; + args_info->rattype_help = gengetopt_args_info_help[14]; + args_info->userloc_help = gengetopt_args_info_help[15]; + args_info->rai_help = gengetopt_args_info_help[16]; + args_info->mstz_help = gengetopt_args_info_help[17]; + args_info->imeisv_help = gengetopt_args_info_help[18]; + args_info->norecovery_help = gengetopt_args_info_help[19]; + args_info->imsi_help = gengetopt_args_info_help[20]; + args_info->nsapi_help = gengetopt_args_info_help[21]; + args_info->msisdn_help = gengetopt_args_info_help[22]; + args_info->qos_help = gengetopt_args_info_help[23]; + args_info->qose1_help = gengetopt_args_info_help[24]; + args_info->qose2_help = gengetopt_args_info_help[25]; + args_info->qose3_help = gengetopt_args_info_help[26]; + args_info->qose4_help = gengetopt_args_info_help[27]; + args_info->charging_help = gengetopt_args_info_help[28]; + args_info->uid_help = gengetopt_args_info_help[29]; + args_info->pwd_help = gengetopt_args_info_help[30]; + args_info->createif_help = gengetopt_args_info_help[31]; + args_info->net_help = gengetopt_args_info_help[32]; + args_info->defaultroute_help = gengetopt_args_info_help[33]; + args_info->ipup_help = gengetopt_args_info_help[34]; + args_info->ipdown_help = gengetopt_args_info_help[35]; + args_info->pinghost_help = gengetopt_args_info_help[36]; + args_info->pingrate_help = gengetopt_args_info_help[37]; + args_info->pingsize_help = gengetopt_args_info_help[38]; + args_info->pingcount_help = gengetopt_args_info_help[39]; + args_info->pingquiet_help = gengetopt_args_info_help[40]; } void cmdline_parser_print_version(void) { - printf("%s %s\n", CMDLINE_PARSER_PACKAGE, CMDLINE_PARSER_VERSION); + printf("%s %s\n", + (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? + CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE), + CMDLINE_PARSER_VERSION); + + if (strlen(gengetopt_args_info_versiontext) > 0) + printf("\n%s\n", gengetopt_args_info_versiontext); } -void cmdline_parser_print_help(void) +static void print_help_common(void) { - int i = 0; cmdline_parser_print_version(); if (strlen(gengetopt_args_info_purpose) > 0) printf("\n%s\n", gengetopt_args_info_purpose); - printf("\n%s\n\n", gengetopt_args_info_usage); + if (strlen(gengetopt_args_info_usage) > 0) + printf("\n%s\n", gengetopt_args_info_usage); + + printf("\n"); + + if (strlen(gengetopt_args_info_description) > 0) + printf("%s\n\n", gengetopt_args_info_description); +} + +void cmdline_parser_print_help(void) +{ + int i = 0; + print_help_common(); while (gengetopt_args_info_help[i]) printf("%s\n", gengetopt_args_info_help[i++]); } @@ -293,171 +332,210 @@ void cmdline_parser_init(struct gengetopt_args_info *args_info) init_args_info(args_info); } -static void cmdline_parser_release(struct gengetopt_args_info *args_info) +void cmdline_parser_params_init(struct cmdline_parser_params *params) { - - if (args_info->conf_arg) { - free(args_info->conf_arg); /* free previous argument */ - args_info->conf_arg = 0; - } - if (args_info->conf_orig) { - free(args_info->conf_orig); /* free previous argument */ - args_info->conf_orig = 0; - } - if (args_info->pidfile_arg) { - free(args_info->pidfile_arg); /* free previous argument */ - args_info->pidfile_arg = 0; - } - if (args_info->pidfile_orig) { - free(args_info->pidfile_orig); /* free previous argument */ - args_info->pidfile_orig = 0; - } - if (args_info->statedir_arg) { - free(args_info->statedir_arg); /* free previous argument */ - args_info->statedir_arg = 0; - } - if (args_info->statedir_orig) { - free(args_info->statedir_orig); /* free previous argument */ - args_info->statedir_orig = 0; - } - if (args_info->dns_arg) { - free(args_info->dns_arg); /* free previous argument */ - args_info->dns_arg = 0; - } - if (args_info->dns_orig) { - free(args_info->dns_orig); /* free previous argument */ - args_info->dns_orig = 0; - } - if (args_info->listen_arg) { - free(args_info->listen_arg); /* free previous argument */ - args_info->listen_arg = 0; - } - if (args_info->listen_orig) { - free(args_info->listen_orig); /* free previous argument */ - args_info->listen_orig = 0; - } - if (args_info->remote_arg) { - free(args_info->remote_arg); /* free previous argument */ - args_info->remote_arg = 0; - } - if (args_info->remote_orig) { - free(args_info->remote_orig); /* free previous argument */ - args_info->remote_orig = 0; - } - if (args_info->contexts_orig) { - free(args_info->contexts_orig); /* free previous argument */ - args_info->contexts_orig = 0; - } - if (args_info->timelimit_orig) { - free(args_info->timelimit_orig); /* free previous argument */ - args_info->timelimit_orig = 0; - } - if (args_info->gtpversion_orig) { - free(args_info->gtpversion_orig); /* free previous argument */ - args_info->gtpversion_orig = 0; - } - if (args_info->apn_arg) { - free(args_info->apn_arg); /* free previous argument */ - args_info->apn_arg = 0; - } - if (args_info->apn_orig) { - free(args_info->apn_orig); /* free previous argument */ - args_info->apn_orig = 0; - } - if (args_info->selmode_orig) { - free(args_info->selmode_orig); /* free previous argument */ - args_info->selmode_orig = 0; - } - if (args_info->imsi_arg) { - free(args_info->imsi_arg); /* free previous argument */ - args_info->imsi_arg = 0; - } - if (args_info->imsi_orig) { - free(args_info->imsi_orig); /* free previous argument */ - args_info->imsi_orig = 0; - } - if (args_info->nsapi_orig) { - free(args_info->nsapi_orig); /* free previous argument */ - args_info->nsapi_orig = 0; - } - if (args_info->msisdn_arg) { - free(args_info->msisdn_arg); /* free previous argument */ - args_info->msisdn_arg = 0; - } - if (args_info->msisdn_orig) { - free(args_info->msisdn_orig); /* free previous argument */ - args_info->msisdn_orig = 0; - } - if (args_info->qos_orig) { - free(args_info->qos_orig); /* free previous argument */ - args_info->qos_orig = 0; - } - if (args_info->charging_orig) { - free(args_info->charging_orig); /* free previous argument */ - args_info->charging_orig = 0; - } - if (args_info->uid_arg) { - free(args_info->uid_arg); /* free previous argument */ - args_info->uid_arg = 0; - } - if (args_info->uid_orig) { - free(args_info->uid_orig); /* free previous argument */ - args_info->uid_orig = 0; - } - if (args_info->pwd_arg) { - free(args_info->pwd_arg); /* free previous argument */ - args_info->pwd_arg = 0; - } - if (args_info->pwd_orig) { - free(args_info->pwd_orig); /* free previous argument */ - args_info->pwd_orig = 0; - } - if (args_info->net_arg) { - free(args_info->net_arg); /* free previous argument */ - args_info->net_arg = 0; + if (params) { + params->override = 0; + params->initialize = 1; + params->check_required = 1; + params->check_ambiguity = 0; + params->print_errors = 1; } - if (args_info->net_orig) { - free(args_info->net_orig); /* free previous argument */ - args_info->net_orig = 0; - } - if (args_info->ipup_arg) { - free(args_info->ipup_arg); /* free previous argument */ - args_info->ipup_arg = 0; - } - if (args_info->ipup_orig) { - free(args_info->ipup_orig); /* free previous argument */ - args_info->ipup_orig = 0; - } - if (args_info->ipdown_arg) { - free(args_info->ipdown_arg); /* free previous argument */ - args_info->ipdown_arg = 0; - } - if (args_info->ipdown_orig) { - free(args_info->ipdown_orig); /* free previous argument */ - args_info->ipdown_orig = 0; - } - if (args_info->pinghost_arg) { - free(args_info->pinghost_arg); /* free previous argument */ - args_info->pinghost_arg = 0; - } - if (args_info->pinghost_orig) { - free(args_info->pinghost_orig); /* free previous argument */ - args_info->pinghost_orig = 0; - } - if (args_info->pingrate_orig) { - free(args_info->pingrate_orig); /* free previous argument */ - args_info->pingrate_orig = 0; +} + +struct cmdline_parser_params *cmdline_parser_params_create(void) +{ + struct cmdline_parser_params *params = + (struct cmdline_parser_params *) + malloc(sizeof(struct cmdline_parser_params)); + cmdline_parser_params_init(params); + return params; +} + +static void free_string_field(char **s) +{ + if (*s) { + free(*s); + *s = 0; } - if (args_info->pingsize_orig) { - free(args_info->pingsize_orig); /* free previous argument */ - args_info->pingsize_orig = 0; +} + +static void cmdline_parser_release(struct gengetopt_args_info *args_info) +{ + + free_string_field(&(args_info->conf_arg)); + free_string_field(&(args_info->conf_orig)); + free_string_field(&(args_info->pidfile_arg)); + free_string_field(&(args_info->pidfile_orig)); + free_string_field(&(args_info->statedir_arg)); + free_string_field(&(args_info->statedir_orig)); + free_string_field(&(args_info->dns_arg)); + free_string_field(&(args_info->dns_orig)); + free_string_field(&(args_info->listen_arg)); + free_string_field(&(args_info->listen_orig)); + free_string_field(&(args_info->remote_arg)); + free_string_field(&(args_info->remote_orig)); + free_string_field(&(args_info->contexts_orig)); + free_string_field(&(args_info->timelimit_orig)); + free_string_field(&(args_info->gtpversion_orig)); + free_string_field(&(args_info->apn_arg)); + free_string_field(&(args_info->apn_orig)); + free_string_field(&(args_info->selmode_orig)); + free_string_field(&(args_info->rattype_orig)); + free_string_field(&(args_info->userloc_arg)); + free_string_field(&(args_info->userloc_orig)); + free_string_field(&(args_info->rai_arg)); + free_string_field(&(args_info->rai_orig)); + free_string_field(&(args_info->mstz_arg)); + free_string_field(&(args_info->mstz_orig)); + free_string_field(&(args_info->imeisv_arg)); + free_string_field(&(args_info->imeisv_orig)); + free_string_field(&(args_info->imsi_arg)); + free_string_field(&(args_info->imsi_orig)); + free_string_field(&(args_info->nsapi_orig)); + free_string_field(&(args_info->msisdn_arg)); + free_string_field(&(args_info->msisdn_orig)); + free_string_field(&(args_info->qos_orig)); + free_string_field(&(args_info->qose1_orig)); + free_string_field(&(args_info->qose2_orig)); + free_string_field(&(args_info->qose3_orig)); + free_string_field(&(args_info->qose4_orig)); + free_string_field(&(args_info->charging_orig)); + free_string_field(&(args_info->uid_arg)); + free_string_field(&(args_info->uid_orig)); + free_string_field(&(args_info->pwd_arg)); + free_string_field(&(args_info->pwd_orig)); + free_string_field(&(args_info->net_arg)); + free_string_field(&(args_info->net_orig)); + free_string_field(&(args_info->ipup_arg)); + free_string_field(&(args_info->ipup_orig)); + free_string_field(&(args_info->ipdown_arg)); + free_string_field(&(args_info->ipdown_orig)); + free_string_field(&(args_info->pinghost_arg)); + free_string_field(&(args_info->pinghost_orig)); + free_string_field(&(args_info->pingrate_orig)); + free_string_field(&(args_info->pingsize_orig)); + free_string_field(&(args_info->pingcount_orig)); + + clear_given(args_info); +} + +static void +write_into_file(FILE * outfile, const char *opt, const char *arg, + const char *values[]) +{ + FIX_UNUSED(values); + if (arg) { + fprintf(outfile, "%s=\"%s\"\n", opt, arg); + } else { + fprintf(outfile, "%s\n", opt); } - if (args_info->pingcount_orig) { - free(args_info->pingcount_orig); /* free previous argument */ - args_info->pingcount_orig = 0; +} + +int cmdline_parser_dump(FILE * outfile, struct gengetopt_args_info *args_info) +{ + int i = 0; + + if (!outfile) { + fprintf(stderr, "%s: cannot dump options to stream\n", + CMDLINE_PARSER_PACKAGE); + return EXIT_FAILURE; } - clear_given(args_info); + if (args_info->help_given) + write_into_file(outfile, "help", 0, 0); + if (args_info->version_given) + write_into_file(outfile, "version", 0, 0); + if (args_info->debug_given) + write_into_file(outfile, "debug", 0, 0); + if (args_info->conf_given) + write_into_file(outfile, "conf", args_info->conf_orig, 0); + if (args_info->pidfile_given) + write_into_file(outfile, "pidfile", args_info->pidfile_orig, 0); + if (args_info->statedir_given) + write_into_file(outfile, "statedir", args_info->statedir_orig, + 0); + if (args_info->dns_given) + write_into_file(outfile, "dns", args_info->dns_orig, 0); + if (args_info->listen_given) + write_into_file(outfile, "listen", args_info->listen_orig, 0); + if (args_info->remote_given) + write_into_file(outfile, "remote", args_info->remote_orig, 0); + if (args_info->contexts_given) + write_into_file(outfile, "contexts", args_info->contexts_orig, + 0); + if (args_info->timelimit_given) + write_into_file(outfile, "timelimit", args_info->timelimit_orig, + 0); + if (args_info->gtpversion_given) + write_into_file(outfile, "gtpversion", + args_info->gtpversion_orig, 0); + if (args_info->apn_given) + write_into_file(outfile, "apn", args_info->apn_orig, 0); + if (args_info->selmode_given) + write_into_file(outfile, "selmode", args_info->selmode_orig, 0); + if (args_info->rattype_given) + write_into_file(outfile, "rattype", args_info->rattype_orig, 0); + if (args_info->userloc_given) + write_into_file(outfile, "userloc", args_info->userloc_orig, 0); + if (args_info->rai_given) + write_into_file(outfile, "rai", args_info->rai_orig, 0); + if (args_info->mstz_given) + write_into_file(outfile, "mstz", args_info->mstz_orig, 0); + if (args_info->imeisv_given) + write_into_file(outfile, "imeisv", args_info->imeisv_orig, 0); + if (args_info->norecovery_given) + write_into_file(outfile, "norecovery", 0, 0); + if (args_info->imsi_given) + write_into_file(outfile, "imsi", args_info->imsi_orig, 0); + if (args_info->nsapi_given) + write_into_file(outfile, "nsapi", args_info->nsapi_orig, 0); + if (args_info->msisdn_given) + write_into_file(outfile, "msisdn", args_info->msisdn_orig, 0); + if (args_info->qos_given) + write_into_file(outfile, "qos", args_info->qos_orig, 0); + if (args_info->qose1_given) + write_into_file(outfile, "qose1", args_info->qose1_orig, 0); + if (args_info->qose2_given) + write_into_file(outfile, "qose2", args_info->qose2_orig, 0); + if (args_info->qose3_given) + write_into_file(outfile, "qose3", args_info->qose3_orig, 0); + if (args_info->qose4_given) + write_into_file(outfile, "qose4", args_info->qose4_orig, 0); + if (args_info->charging_given) + write_into_file(outfile, "charging", args_info->charging_orig, + 0); + if (args_info->uid_given) + write_into_file(outfile, "uid", args_info->uid_orig, 0); + if (args_info->pwd_given) + write_into_file(outfile, "pwd", args_info->pwd_orig, 0); + if (args_info->createif_given) + write_into_file(outfile, "createif", 0, 0); + if (args_info->net_given) + write_into_file(outfile, "net", args_info->net_orig, 0); + if (args_info->defaultroute_given) + write_into_file(outfile, "defaultroute", 0, 0); + if (args_info->ipup_given) + write_into_file(outfile, "ipup", args_info->ipup_orig, 0); + if (args_info->ipdown_given) + write_into_file(outfile, "ipdown", args_info->ipdown_orig, 0); + if (args_info->pinghost_given) + write_into_file(outfile, "pinghost", args_info->pinghost_orig, + 0); + if (args_info->pingrate_given) + write_into_file(outfile, "pingrate", args_info->pingrate_orig, + 0); + if (args_info->pingsize_given) + write_into_file(outfile, "pingsize", args_info->pingsize_orig, + 0); + if (args_info->pingcount_given) + write_into_file(outfile, "pingcount", args_info->pingcount_orig, + 0); + if (args_info->pingquiet_given) + write_into_file(outfile, "pingquiet", 0, 0); + + i = EXIT_SUCCESS; + return i; } int @@ -475,231 +553,9 @@ cmdline_parser_file_save(const char *filename, return EXIT_FAILURE; } - if (args_info->help_given) { - fprintf(outfile, "%s\n", "help"); - } - if (args_info->version_given) { - fprintf(outfile, "%s\n", "version"); - } - if (args_info->debug_given) { - fprintf(outfile, "%s\n", "debug"); - } - if (args_info->conf_given) { - if (args_info->conf_orig) { - fprintf(outfile, "%s=\"%s\"\n", "conf", - args_info->conf_orig); - } else { - fprintf(outfile, "%s\n", "conf"); - } - } - if (args_info->pidfile_given) { - if (args_info->pidfile_orig) { - fprintf(outfile, "%s=\"%s\"\n", "pidfile", - args_info->pidfile_orig); - } else { - fprintf(outfile, "%s\n", "pidfile"); - } - } - if (args_info->statedir_given) { - if (args_info->statedir_orig) { - fprintf(outfile, "%s=\"%s\"\n", "statedir", - args_info->statedir_orig); - } else { - fprintf(outfile, "%s\n", "statedir"); - } - } - if (args_info->dns_given) { - if (args_info->dns_orig) { - fprintf(outfile, "%s=\"%s\"\n", "dns", - args_info->dns_orig); - } else { - fprintf(outfile, "%s\n", "dns"); - } - } - if (args_info->listen_given) { - if (args_info->listen_orig) { - fprintf(outfile, "%s=\"%s\"\n", "listen", - args_info->listen_orig); - } else { - fprintf(outfile, "%s\n", "listen"); - } - } - if (args_info->remote_given) { - if (args_info->remote_orig) { - fprintf(outfile, "%s=\"%s\"\n", "remote", - args_info->remote_orig); - } else { - fprintf(outfile, "%s\n", "remote"); - } - } - if (args_info->contexts_given) { - if (args_info->contexts_orig) { - fprintf(outfile, "%s=\"%s\"\n", "contexts", - args_info->contexts_orig); - } else { - fprintf(outfile, "%s\n", "contexts"); - } - } - if (args_info->timelimit_given) { - if (args_info->timelimit_orig) { - fprintf(outfile, "%s=\"%s\"\n", "timelimit", - args_info->timelimit_orig); - } else { - fprintf(outfile, "%s\n", "timelimit"); - } - } - if (args_info->gtpversion_given) { - if (args_info->gtpversion_orig) { - fprintf(outfile, "%s=\"%s\"\n", "gtpversion", - args_info->gtpversion_orig); - } else { - fprintf(outfile, "%s\n", "gtpversion"); - } - } - if (args_info->apn_given) { - if (args_info->apn_orig) { - fprintf(outfile, "%s=\"%s\"\n", "apn", - args_info->apn_orig); - } else { - fprintf(outfile, "%s\n", "apn"); - } - } - if (args_info->selmode_given) { - if (args_info->selmode_orig) { - fprintf(outfile, "%s=\"%s\"\n", "selmode", - args_info->selmode_orig); - } else { - fprintf(outfile, "%s\n", "selmode"); - } - } - if (args_info->imsi_given) { - if (args_info->imsi_orig) { - fprintf(outfile, "%s=\"%s\"\n", "imsi", - args_info->imsi_orig); - } else { - fprintf(outfile, "%s\n", "imsi"); - } - } - if (args_info->nsapi_given) { - if (args_info->nsapi_orig) { - fprintf(outfile, "%s=\"%s\"\n", "nsapi", - args_info->nsapi_orig); - } else { - fprintf(outfile, "%s\n", "nsapi"); - } - } - if (args_info->msisdn_given) { - if (args_info->msisdn_orig) { - fprintf(outfile, "%s=\"%s\"\n", "msisdn", - args_info->msisdn_orig); - } else { - fprintf(outfile, "%s\n", "msisdn"); - } - } - if (args_info->qos_given) { - if (args_info->qos_orig) { - fprintf(outfile, "%s=\"%s\"\n", "qos", - args_info->qos_orig); - } else { - fprintf(outfile, "%s\n", "qos"); - } - } - if (args_info->charging_given) { - if (args_info->charging_orig) { - fprintf(outfile, "%s=\"%s\"\n", "charging", - args_info->charging_orig); - } else { - fprintf(outfile, "%s\n", "charging"); - } - } - if (args_info->uid_given) { - if (args_info->uid_orig) { - fprintf(outfile, "%s=\"%s\"\n", "uid", - args_info->uid_orig); - } else { - fprintf(outfile, "%s\n", "uid"); - } - } - if (args_info->pwd_given) { - if (args_info->pwd_orig) { - fprintf(outfile, "%s=\"%s\"\n", "pwd", - args_info->pwd_orig); - } else { - fprintf(outfile, "%s\n", "pwd"); - } - } - if (args_info->createif_given) { - fprintf(outfile, "%s\n", "createif"); - } - if (args_info->net_given) { - if (args_info->net_orig) { - fprintf(outfile, "%s=\"%s\"\n", "net", - args_info->net_orig); - } else { - fprintf(outfile, "%s\n", "net"); - } - } - if (args_info->defaultroute_given) { - fprintf(outfile, "%s\n", "defaultroute"); - } - if (args_info->ipup_given) { - if (args_info->ipup_orig) { - fprintf(outfile, "%s=\"%s\"\n", "ipup", - args_info->ipup_orig); - } else { - fprintf(outfile, "%s\n", "ipup"); - } - } - if (args_info->ipdown_given) { - if (args_info->ipdown_orig) { - fprintf(outfile, "%s=\"%s\"\n", "ipdown", - args_info->ipdown_orig); - } else { - fprintf(outfile, "%s\n", "ipdown"); - } - } - if (args_info->pinghost_given) { - if (args_info->pinghost_orig) { - fprintf(outfile, "%s=\"%s\"\n", "pinghost", - args_info->pinghost_orig); - } else { - fprintf(outfile, "%s\n", "pinghost"); - } - } - if (args_info->pingrate_given) { - if (args_info->pingrate_orig) { - fprintf(outfile, "%s=\"%s\"\n", "pingrate", - args_info->pingrate_orig); - } else { - fprintf(outfile, "%s\n", "pingrate"); - } - } - if (args_info->pingsize_given) { - if (args_info->pingsize_orig) { - fprintf(outfile, "%s=\"%s\"\n", "pingsize", - args_info->pingsize_orig); - } else { - fprintf(outfile, "%s\n", "pingsize"); - } - } - if (args_info->pingcount_given) { - if (args_info->pingcount_orig) { - fprintf(outfile, "%s=\"%s\"\n", "pingcount", - args_info->pingcount_orig); - } else { - fprintf(outfile, "%s\n", "pingcount"); - } - } - if (args_info->pingquiet_given) { - fprintf(outfile, "%s\n", "pingquiet"); - } - if (args_info->norecovery_given) { - fprintf(outfile, "%s\n", "norecovery"); - } - + i = cmdline_parser_dump(outfile, args_info); fclose(outfile); - i = EXIT_SUCCESS; return i; } @@ -708,11 +564,10 @@ void cmdline_parser_free(struct gengetopt_args_info *args_info) cmdline_parser_release(args_info); } -/* gengetopt_strdup() */ -/* strdup.c replacement of strdup, which is not standard */ +/** @brief replacement of strdup, which is not standard */ char *gengetopt_strdup(const char *s) { - char *result = NULL; + char *result = 0; if (!s) return result; @@ -723,23 +578,40 @@ char *gengetopt_strdup(const char *s) return result; } -int -cmdline_parser(int argc, char *const *argv, - struct gengetopt_args_info *args_info) +int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info) { return cmdline_parser2(argc, argv, args_info, 0, 1, 1); } int -cmdline_parser2(int argc, char *const *argv, - struct gengetopt_args_info *args_info, int override, - int initialize, int check_required) +cmdline_parser_ext(int argc, char **argv, struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params) +{ + int result; + result = cmdline_parser_internal(argc, argv, args_info, params, 0); + + if (result == EXIT_FAILURE) { + cmdline_parser_free(args_info); + exit(EXIT_FAILURE); + } + + return result; +} + +int +cmdline_parser2(int argc, char **argv, struct gengetopt_args_info *args_info, + int override, int initialize, int check_required) { int result; + struct cmdline_parser_params params; - result = - cmdline_parser_internal(argc, argv, args_info, override, initialize, - check_required, NULL); + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; + + result = cmdline_parser_internal(argc, argv, args_info, ¶ms, 0); if (result == EXIT_FAILURE) { cmdline_parser_free(args_info); @@ -753,20 +625,153 @@ int cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name) { + FIX_UNUSED(args_info); + FIX_UNUSED(prog_name); return EXIT_SUCCESS; } +static char *package_name = 0; + +/** + * @brief updates an option + * @param field the generic pointer to the field to update + * @param orig_field the pointer to the orig field + * @param field_given the pointer to the number of occurrence of this option + * @param prev_given the pointer to the number of occurrence already seen + * @param value the argument for this option (if null no arg was specified) + * @param possible_values the possible values for this option (if specified) + * @param default_value the default value (in case the option only accepts fixed values) + * @param arg_type the type of this option + * @param check_ambiguity @see cmdline_parser_params.check_ambiguity + * @param override @see cmdline_parser_params.override + * @param no_free whether to free a possible previous value + * @param multiple_option whether this is a multiple option + * @param long_opt the corresponding long option + * @param short_opt the corresponding short option (or '-' if none) + * @param additional_error possible further error specification + */ +static +int update_arg(void *field, char **orig_field, + unsigned int *field_given, unsigned int *prev_given, + char *value, const char *possible_values[], + const char *default_value, + cmdline_parser_arg_type arg_type, + int check_ambiguity, int override, + int no_free, int multiple_option, + const char *long_opt, char short_opt, + const char *additional_error) +{ + char *stop_char = 0; + const char *val = value; + int found; + char **string_field; + FIX_UNUSED(field); + + stop_char = 0; + found = 0; + + if (!multiple_option && prev_given + && (*prev_given || (check_ambiguity && *field_given))) { + if (short_opt != '-') + fprintf(stderr, + "%s: `--%s' (`-%c') option given more than once%s\n", + package_name, long_opt, short_opt, + (additional_error ? additional_error : "")); + else + fprintf(stderr, + "%s: `--%s' option given more than once%s\n", + package_name, long_opt, + (additional_error ? additional_error : "")); + return 1; /* failure */ + } + + FIX_UNUSED(default_value); + + if (field_given && *field_given && !override) + return 0; + if (prev_given) + (*prev_given)++; + if (field_given) + (*field_given)++; + if (possible_values) + val = possible_values[found]; + + switch (arg_type) { + case ARG_FLAG: + *((int *)field) = !*((int *)field); + break; + case ARG_INT: + if (val) + *((int *)field) = strtol(val, &stop_char, 0); + break; + case ARG_STRING: + if (val) { + string_field = (char **)field; + if (!no_free && *string_field) + free(*string_field); /* free previous string */ + *string_field = gengetopt_strdup(val); + } + break; + default: + break; + }; + + /* check numeric conversion */ + switch (arg_type) { + case ARG_INT: + if (val && !(stop_char && *stop_char == '\0')) { + fprintf(stderr, "%s: invalid numeric value: %s\n", + package_name, val); + return 1; /* failure */ + } + break; + default: + ; + }; + + /* store the original value */ + switch (arg_type) { + case ARG_NO: + case ARG_FLAG: + break; + default: + if (value && orig_field) { + if (no_free) { + *orig_field = value; + } else { + if (*orig_field) + free(*orig_field); /* free previous string */ + *orig_field = gengetopt_strdup(value); + } + } + }; + + return 0; /* OK */ +} + int -cmdline_parser_internal(int argc, char *const *argv, - struct gengetopt_args_info *args_info, int override, - int initialize, int check_required, +cmdline_parser_internal(int argc, char **argv, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params, const char *additional_error) { int c; /* Character of the parsed option. */ - int error = 0; + int error_occurred = 0; struct gengetopt_args_info local_args_info; + int override; + int initialize; + int check_required; + int check_ambiguity; + + package_name = argv[0]; + + override = params->override; + initialize = params->initialize; + check_required = params->check_required; + check_ambiguity = params->check_ambiguity; + if (initialize) cmdline_parser_init(args_info); @@ -774,12 +779,11 @@ cmdline_parser_internal(int argc, char *const *argv, optarg = 0; optind = 0; - opterr = 1; + opterr = params->print_errors; optopt = '?'; while (1) { int option_index = 0; - char *stop_char; static struct option long_options[] = { {"help", 0, NULL, 'h'}, @@ -801,6 +805,7 @@ cmdline_parser_internal(int argc, char *const *argv, {"rai", 1, NULL, 0}, {"mstz", 1, NULL, 0}, {"imeisv", 1, NULL, 0}, + {"norecovery", 0, NULL, 0}, {"imsi", 1, NULL, 'i'}, {"nsapi", 1, NULL, 0}, {"msisdn", 1, NULL, 'm'}, @@ -822,11 +827,9 @@ cmdline_parser_internal(int argc, char *const *argv, {"pingsize", 1, NULL, 0}, {"pingcount", 1, NULL, 0}, {"pingquiet", 0, NULL, 0}, - {"norecovery", 0, NULL, 0}, - {NULL, 0, NULL, 0} + {0, 0, 0, 0} }; - stop_char = 0; c = getopt_long(argc, argv, "hVdc:l:r:a:i:m:q:u:p:n:", long_options, &option_index); @@ -845,884 +848,559 @@ cmdline_parser_internal(int argc, char *const *argv, exit(EXIT_SUCCESS); case 'd': /* Run in debug mode. */ - if (local_args_info.debug_given) { - fprintf(stderr, - "%s: `--debug' (`-d') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg + ((void *)&(args_info->debug_flag), 0, + &(args_info->debug_given), + &(local_args_info.debug_given), optarg, 0, 0, + ARG_FLAG, check_ambiguity, override, 1, 0, "debug", + 'd', additional_error)) goto failure; - } - if (args_info->debug_given && !override) - continue; - local_args_info.debug_given = 1; - args_info->debug_given = 1; - args_info->debug_flag = !(args_info->debug_flag); - break; + break; case 'c': /* Read configuration file. */ - if (local_args_info.conf_given) { - fprintf(stderr, - "%s: `--conf' (`-c') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->conf_arg), + &(args_info->conf_orig), + &(args_info->conf_given), + &(local_args_info.conf_given), optarg, 0, + 0, ARG_STRING, check_ambiguity, override, + 0, 0, "conf", 'c', additional_error)) goto failure; - } - if (args_info->conf_given && !override) - continue; - local_args_info.conf_given = 1; - args_info->conf_given = 1; - if (args_info->conf_arg) - free(args_info->conf_arg); /* free previous string */ - args_info->conf_arg = gengetopt_strdup(optarg); - if (args_info->conf_orig) - free(args_info->conf_orig); /* free previous string */ - args_info->conf_orig = gengetopt_strdup(optarg); - break; + break; case 'l': /* Local interface. */ - if (local_args_info.listen_given) { - fprintf(stderr, - "%s: `--listen' (`-l') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->listen_arg), + &(args_info->listen_orig), + &(args_info->listen_given), + &(local_args_info.listen_given), optarg, + 0, 0, ARG_STRING, check_ambiguity, + override, 0, 0, "listen", 'l', + additional_error)) goto failure; - } - if (args_info->listen_given && !override) - continue; - local_args_info.listen_given = 1; - args_info->listen_given = 1; - if (args_info->listen_arg) - free(args_info->listen_arg); /* free previous string */ - args_info->listen_arg = gengetopt_strdup(optarg); - if (args_info->listen_orig) - free(args_info->listen_orig); /* free previous string */ - args_info->listen_orig = gengetopt_strdup(optarg); - break; + break; case 'r': /* Remote host. */ - if (local_args_info.remote_given) { - fprintf(stderr, - "%s: `--remote' (`-r') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->remote_arg), + &(args_info->remote_orig), + &(args_info->remote_given), + &(local_args_info.remote_given), optarg, + 0, 0, ARG_STRING, check_ambiguity, + override, 0, 0, "remote", 'r', + additional_error)) goto failure; - } - if (args_info->remote_given && !override) - continue; - local_args_info.remote_given = 1; - args_info->remote_given = 1; - if (args_info->remote_arg) - free(args_info->remote_arg); /* free previous string */ - args_info->remote_arg = gengetopt_strdup(optarg); - if (args_info->remote_orig) - free(args_info->remote_orig); /* free previous string */ - args_info->remote_orig = gengetopt_strdup(optarg); - break; + break; case 'a': /* Access point name. */ - if (local_args_info.apn_given) { - fprintf(stderr, - "%s: `--apn' (`-a') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->apn_arg), + &(args_info->apn_orig), + &(args_info->apn_given), + &(local_args_info.apn_given), optarg, 0, + "internet", ARG_STRING, check_ambiguity, + override, 0, 0, "apn", 'a', + additional_error)) goto failure; - } - if (args_info->apn_given && !override) - continue; - local_args_info.apn_given = 1; - args_info->apn_given = 1; - if (args_info->apn_arg) - free(args_info->apn_arg); /* free previous string */ - args_info->apn_arg = gengetopt_strdup(optarg); - if (args_info->apn_orig) - free(args_info->apn_orig); /* free previous string */ - args_info->apn_orig = gengetopt_strdup(optarg); - break; + break; case 'i': /* IMSI. */ - if (local_args_info.imsi_given) { - fprintf(stderr, - "%s: `--imsi' (`-i') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->imsi_arg), + &(args_info->imsi_orig), + &(args_info->imsi_given), + &(local_args_info.imsi_given), optarg, 0, + "240010123456789", ARG_STRING, + check_ambiguity, override, 0, 0, "imsi", + 'i', additional_error)) goto failure; - } - if (args_info->imsi_given && !override) - continue; - local_args_info.imsi_given = 1; - args_info->imsi_given = 1; - if (args_info->imsi_arg) - free(args_info->imsi_arg); /* free previous string */ - args_info->imsi_arg = gengetopt_strdup(optarg); - if (args_info->imsi_orig) - free(args_info->imsi_orig); /* free previous string */ - args_info->imsi_orig = gengetopt_strdup(optarg); - break; + break; case 'm': /* Mobile Station ISDN number. */ - if (local_args_info.msisdn_given) { - fprintf(stderr, - "%s: `--msisdn' (`-m') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->msisdn_arg), + &(args_info->msisdn_orig), + &(args_info->msisdn_given), + &(local_args_info.msisdn_given), optarg, + 0, "46702123456", ARG_STRING, + check_ambiguity, override, 0, 0, + "msisdn", 'm', additional_error)) goto failure; - } - if (args_info->msisdn_given && !override) - continue; - local_args_info.msisdn_given = 1; - args_info->msisdn_given = 1; - if (args_info->msisdn_arg) - free(args_info->msisdn_arg); /* free previous string */ - args_info->msisdn_arg = gengetopt_strdup(optarg); - if (args_info->msisdn_orig) - free(args_info->msisdn_orig); /* free previous string */ - args_info->msisdn_orig = gengetopt_strdup(optarg); - break; + break; case 'q': /* Requested quality of service. */ - if (local_args_info.qos_given) { - fprintf(stderr, - "%s: `--qos' (`-q') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); - goto failure; - } - if (args_info->qos_given && !override) - continue; - local_args_info.qos_given = 1; - args_info->qos_given = 1; - args_info->qos_arg = strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg((void *)&(args_info->qos_arg), + &(args_info->qos_orig), + &(args_info->qos_given), + &(local_args_info.qos_given), optarg, 0, + "0x000b921f", ARG_INT, check_ambiguity, + override, 0, 0, "qos", 'q', + additional_error)) goto failure; - } - if (args_info->qos_orig) - free(args_info->qos_orig); /* free previous string */ - args_info->qos_orig = gengetopt_strdup(optarg); - break; + break; case 'u': /* Login user ID. */ - if (local_args_info.uid_given) { - fprintf(stderr, - "%s: `--uid' (`-u') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->uid_arg), + &(args_info->uid_orig), + &(args_info->uid_given), + &(local_args_info.uid_given), optarg, 0, + "mig", ARG_STRING, check_ambiguity, + override, 0, 0, "uid", 'u', + additional_error)) goto failure; - } - if (args_info->uid_given && !override) - continue; - local_args_info.uid_given = 1; - args_info->uid_given = 1; - if (args_info->uid_arg) - free(args_info->uid_arg); /* free previous string */ - args_info->uid_arg = gengetopt_strdup(optarg); - if (args_info->uid_orig) - free(args_info->uid_orig); /* free previous string */ - args_info->uid_orig = gengetopt_strdup(optarg); - break; + break; case 'p': /* Login password. */ - if (local_args_info.pwd_given) { - fprintf(stderr, - "%s: `--pwd' (`-p') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->pwd_arg), + &(args_info->pwd_orig), + &(args_info->pwd_given), + &(local_args_info.pwd_given), optarg, 0, + "hemmelig", ARG_STRING, check_ambiguity, + override, 0, 0, "pwd", 'p', + additional_error)) goto failure; - } - if (args_info->pwd_given && !override) - continue; - local_args_info.pwd_given = 1; - args_info->pwd_given = 1; - if (args_info->pwd_arg) - free(args_info->pwd_arg); /* free previous string */ - args_info->pwd_arg = gengetopt_strdup(optarg); - if (args_info->pwd_orig) - free(args_info->pwd_orig); /* free previous string */ - args_info->pwd_orig = gengetopt_strdup(optarg); - break; + break; case 'n': /* Network address for local interface. */ - if (local_args_info.net_given) { - fprintf(stderr, - "%s: `--net' (`-n') option given more than once%s\n", - argv[0], - (additional_error ? additional_error : - "")); + + if (update_arg((void *)&(args_info->net_arg), + &(args_info->net_orig), + &(args_info->net_given), + &(local_args_info.net_given), optarg, 0, + 0, ARG_STRING, check_ambiguity, override, + 0, 0, "net", 'n', additional_error)) goto failure; - } - if (args_info->net_given && !override) - continue; - local_args_info.net_given = 1; - args_info->net_given = 1; - if (args_info->net_arg) - free(args_info->net_arg); /* free previous string */ - args_info->net_arg = gengetopt_strdup(optarg); - if (args_info->net_orig) - free(args_info->net_orig); /* free previous string */ - args_info->net_orig = gengetopt_strdup(optarg); + break; case 0: /* Long option with no short option */ /* Filename of process id file. */ if (strcmp(long_options[option_index].name, "pidfile") == 0) { - if (local_args_info.pidfile_given) { - fprintf(stderr, - "%s: `--pidfile' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg + ((void *)&(args_info->pidfile_arg), + &(args_info->pidfile_orig), + &(args_info->pidfile_given), + &(local_args_info.pidfile_given), optarg, + 0, "./sgsnemu.pid", ARG_STRING, + check_ambiguity, override, 0, 0, "pidfile", + '-', additional_error)) goto failure; - } - if (args_info->pidfile_given && !override) - continue; - local_args_info.pidfile_given = 1; - args_info->pidfile_given = 1; - if (args_info->pidfile_arg) - free(args_info->pidfile_arg); /* free previous string */ - args_info->pidfile_arg = - gengetopt_strdup(optarg); - if (args_info->pidfile_orig) - free(args_info->pidfile_orig); /* free previous string */ - args_info->pidfile_orig = - gengetopt_strdup(optarg); + } /* Directory of nonvolatile data. */ else if (strcmp (long_options[option_index].name, "statedir") == 0) { - if (local_args_info.statedir_given) { - fprintf(stderr, - "%s: `--statedir' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg + ((void *)&(args_info->statedir_arg), + &(args_info->statedir_orig), + &(args_info->statedir_given), + &(local_args_info.statedir_given), optarg, + 0, "./", ARG_STRING, check_ambiguity, + override, 0, 0, "statedir", '-', + additional_error)) goto failure; - } - if (args_info->statedir_given && !override) - continue; - local_args_info.statedir_given = 1; - args_info->statedir_given = 1; - if (args_info->statedir_arg) - free(args_info->statedir_arg); /* free previous string */ - args_info->statedir_arg = - gengetopt_strdup(optarg); - if (args_info->statedir_orig) - free(args_info->statedir_orig); /* free previous string */ - args_info->statedir_orig = - gengetopt_strdup(optarg); + } /* DNS Server to use. */ else if (strcmp(long_options[option_index].name, "dns") == 0) { - if (local_args_info.dns_given) { - fprintf(stderr, - "%s: `--dns' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg((void *)&(args_info->dns_arg), + &(args_info->dns_orig), + &(args_info->dns_given), + &(local_args_info.dns_given), + optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "dns", '-', additional_error)) goto failure; - } - if (args_info->dns_given && !override) - continue; - local_args_info.dns_given = 1; - args_info->dns_given = 1; - if (args_info->dns_arg) - free(args_info->dns_arg); /* free previous string */ - args_info->dns_arg = gengetopt_strdup(optarg); - if (args_info->dns_orig) - free(args_info->dns_orig); /* free previous string */ - args_info->dns_orig = gengetopt_strdup(optarg); + } /* Number of contexts. */ else if (strcmp (long_options[option_index].name, "contexts") == 0) { - if (local_args_info.contexts_given) { - fprintf(stderr, - "%s: `--contexts' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->contexts_given && !override) - continue; - local_args_info.contexts_given = 1; - args_info->contexts_given = 1; - args_info->contexts_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg + ((void *)&(args_info->contexts_arg), + &(args_info->contexts_orig), + &(args_info->contexts_given), + &(local_args_info.contexts_given), optarg, + 0, "1", ARG_INT, check_ambiguity, override, + 0, 0, "contexts", '-', additional_error)) goto failure; - } - if (args_info->contexts_orig) - free(args_info->contexts_orig); /* free previous string */ - args_info->contexts_orig = - gengetopt_strdup(optarg); + } /* Exit after timelimit seconds. */ else if (strcmp (long_options[option_index].name, "timelimit") == 0) { - if (local_args_info.timelimit_given) { - fprintf(stderr, - "%s: `--timelimit' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->timelimit_given && !override) - continue; - local_args_info.timelimit_given = 1; - args_info->timelimit_given = 1; - args_info->timelimit_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg + ((void *)&(args_info->timelimit_arg), + &(args_info->timelimit_orig), + &(args_info->timelimit_given), + &(local_args_info.timelimit_given), optarg, + 0, "0", ARG_INT, check_ambiguity, override, + 0, 0, "timelimit", '-', additional_error)) goto failure; - } - if (args_info->timelimit_orig) - free(args_info->timelimit_orig); /* free previous string */ - args_info->timelimit_orig = - gengetopt_strdup(optarg); + } /* GTP version to use. */ else if (strcmp (long_options[option_index].name, "gtpversion") == 0) { - if (local_args_info.gtpversion_given) { - fprintf(stderr, - "%s: `--gtpversion' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->gtpversion_given && !override) - continue; - local_args_info.gtpversion_given = 1; - args_info->gtpversion_given = 1; - args_info->gtpversion_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg + ((void *)&(args_info->gtpversion_arg), + &(args_info->gtpversion_orig), + &(args_info->gtpversion_given), + &(local_args_info.gtpversion_given), + optarg, 0, "1", ARG_INT, check_ambiguity, + override, 0, 0, "gtpversion", '-', + additional_error)) goto failure; - } - if (args_info->gtpversion_orig) - free(args_info->gtpversion_orig); /* free previous string */ - args_info->gtpversion_orig = - gengetopt_strdup(optarg); + } /* Selection mode. */ else if (strcmp (long_options[option_index].name, "selmode") == 0) { - if (local_args_info.selmode_given) { - fprintf(stderr, - "%s: `--selmode' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->selmode_given && !override) - continue; - local_args_info.selmode_given = 1; - args_info->selmode_given = 1; - args_info->selmode_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg + ((void *)&(args_info->selmode_arg), + &(args_info->selmode_orig), + &(args_info->selmode_given), + &(local_args_info.selmode_given), optarg, + 0, "0x01", ARG_INT, check_ambiguity, + override, 0, 0, "selmode", '-', + additional_error)) goto failure; - } - if (args_info->selmode_orig) - free(args_info->selmode_orig); /* free previous string */ - args_info->selmode_orig = - gengetopt_strdup(optarg); + } - /* QoS Extension 1. */ + /* Radio Access Technology Type. */ else if (strcmp (long_options[option_index].name, - "qose1") == 0) { - if (args_info->qose1_given) { - fprintf(stderr, - "%s: `--qose1' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->qose1_given = 1; - args_info->qose1_arg = - strtoull(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + "rattype") == 0) { + + if (update_arg + ((void *)&(args_info->rattype_arg), + &(args_info->rattype_orig), + &(args_info->rattype_given), + &(local_args_info.rattype_given), optarg, + 0, "1", ARG_INT, check_ambiguity, override, + 0, 0, "rattype", '-', additional_error)) goto failure; - } - if (args_info->qose1_orig) - free(args_info->qose1_orig); /* free previous string */ - args_info->qose1_orig = - gengetopt_strdup(optarg); - break; + } - /* QoS Extension 2. */ + /* User Location Information. */ else if (strcmp (long_options[option_index].name, - "qose2") == 0) { - if (args_info->qose2_given) { - fprintf(stderr, - "%s: `--qose2' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->qose2_given = 1; - args_info->qose2_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + "userloc") == 0) { + + if (update_arg + ((void *)&(args_info->userloc_arg), + &(args_info->userloc_orig), + &(args_info->userloc_given), + &(local_args_info.userloc_given), optarg, + 0, "02509946241207", ARG_STRING, + check_ambiguity, override, 0, 0, "userloc", + '-', additional_error)) goto failure; - } - if (args_info->qose2_orig) - free(args_info->qose2_orig); /* free previous string */ - args_info->qose2_orig = - gengetopt_strdup(optarg); - break; + + } + /* Routing Area Information. */ + else if (strcmp(long_options[option_index].name, "rai") + == 0) { + + if (update_arg((void *)&(args_info->rai_arg), + &(args_info->rai_orig), + &(args_info->rai_given), + &(local_args_info.rai_given), + optarg, 0, "02509946241207", + ARG_STRING, check_ambiguity, + override, 0, 0, "rai", '-', + additional_error)) + goto failure; + } - /* QoS Extension 3. */ + /* MS Time Zone. */ + else if (strcmp(long_options[option_index].name, "mstz") + == 0) { + + if (update_arg((void *)&(args_info->mstz_arg), + &(args_info->mstz_orig), + &(args_info->mstz_given), + &(local_args_info.mstz_given), + optarg, 0, "0", ARG_STRING, + check_ambiguity, override, 0, 0, + "mstz", '-', additional_error)) + goto failure; + + } + /* IMEI(SV) International Mobile Equipment Identity (and Software Version). */ else if (strcmp (long_options[option_index].name, - "qose3") == 0) { - if (args_info->qose3_given) { - fprintf(stderr, - "%s: `--qose3' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->qose3_given = 1; - args_info->qose3_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + "imeisv") == 0) { + + if (update_arg((void *)&(args_info->imeisv_arg), + &(args_info->imeisv_orig), + &(args_info->imeisv_given), + &(local_args_info.imeisv_given), + optarg, 0, "2143658709214365", + ARG_STRING, check_ambiguity, + override, 0, 0, "imeisv", '-', + additional_error)) goto failure; - } - if (args_info->qose3_orig) - free(args_info->qose3_orig); /* free previous string */ - args_info->qose3_orig = - gengetopt_strdup(optarg); - break; + } - /* QoS Extension 4. */ + /* Do not send recovery. */ else if (strcmp (long_options[option_index].name, - "qose4") == 0) { - if (args_info->qose4_given) { - fprintf(stderr, - "%s: `--qose4' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->qose4_given = 1; - args_info->qose4_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + "norecovery") == 0) { + + if (update_arg + ((void *)&(args_info->norecovery_flag), 0, + &(args_info->norecovery_given), + &(local_args_info.norecovery_given), + optarg, 0, 0, ARG_FLAG, check_ambiguity, + override, 1, 0, "norecovery", '-', + additional_error)) goto failure; - } - if (args_info->qose4_orig) - free(args_info->qose4_orig); /* free previous string */ - args_info->qose4_orig = - gengetopt_strdup(optarg); - break; + } - /* Radio Access Technology Type. */ + /* NSAPI. */ else if (strcmp (long_options[option_index].name, - "rattype") == 0) { - if (args_info->rattype_given) { - fprintf(stderr, - "%s: `--rattype' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->rattype_given = 1; - /* args_info->rattype_arg = strtol (optarg,&stop_char,0); */ - args_info->rattype_arg = strdup(optarg); - break; + "nsapi") == 0) { + + if (update_arg((void *)&(args_info->nsapi_arg), + &(args_info->nsapi_orig), + &(args_info->nsapi_given), + &(local_args_info.nsapi_given), + optarg, 0, "0", ARG_INT, + check_ambiguity, override, 0, 0, + "nsapi", '-', additional_error)) + goto failure; + } - /* User Location Information. */ + /* Requested quality of service Extension 1. */ else if (strcmp (long_options[option_index].name, - "userloc") == 0) { - if (args_info->userloc_given) { - fprintf(stderr, - "%s: `--userloc' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->userloc_given = 1; - args_info->userloc_arg = strdup(optarg); - break; - } - /* Routing Area Information. */ - else if (strcmp(long_options[option_index].name, "rai") - == 0) { - if (args_info->rai_given) { - fprintf(stderr, - "%s: `--rai' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->rai_given = 1; - args_info->rai_arg = strdup(optarg); - break; - } - /* MS Time Zone */ - else if (strcmp(long_options[option_index].name, "mstz") - == 0) { - if (args_info->mstz_given) { - fprintf(stderr, - "%s: `--mstz' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->mstz_given = 1; - args_info->mstz_arg = strdup(optarg); - break; + "qose1") == 0) { + + if (update_arg((void *)&(args_info->qose1_arg), + &(args_info->qose1_orig), + &(args_info->qose1_given), + &(local_args_info.qose1_given), + optarg, 0, "0x9396404074f9ffff", + ARG_INT, check_ambiguity, + override, 0, 0, "qose1", '-', + additional_error)) + goto failure; + } - /* IMEI(SV) */ + /* Requested quality of service Extension 2. */ else if (strcmp (long_options[option_index].name, - "imeisv") == 0) { - if (args_info->imeisv_given) { - fprintf(stderr, - "%s: `--imeisv' option given more than once\n", - PACKAGE); - exit(EXIT_FAILURE); - } - args_info->imeisv_given = 1; - args_info->imeisv_arg = strdup(optarg); - break; + "qose2") == 0) { + + if (update_arg((void *)&(args_info->qose2_arg), + &(args_info->qose2_orig), + &(args_info->qose2_given), + &(local_args_info.qose2_given), + optarg, 0, "0x11", ARG_INT, + check_ambiguity, override, 0, 0, + "qose2", '-', additional_error)) + goto failure; + } - /* NSAPI. */ + /* Requested quality of service Extension 3. */ else if (strcmp (long_options[option_index].name, - "nsapi") == 0) { - if (local_args_info.nsapi_given) { - fprintf(stderr, - "%s: `--nsapi' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + "qose3") == 0) { + + if (update_arg((void *)&(args_info->qose3_arg), + &(args_info->qose3_orig), + &(args_info->qose3_given), + &(local_args_info.qose3_given), + optarg, 0, "0x0101", ARG_INT, + check_ambiguity, override, 0, 0, + "qose3", '-', additional_error)) goto failure; - } - if (args_info->nsapi_given && !override) - continue; - local_args_info.nsapi_given = 1; - args_info->nsapi_given = 1; - args_info->nsapi_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + } + /* Requested quality of service Extension 4. */ + else if (strcmp + (long_options[option_index].name, + "qose4") == 0) { + + if (update_arg((void *)&(args_info->qose4_arg), + &(args_info->qose4_orig), + &(args_info->qose4_given), + &(local_args_info.qose4_given), + optarg, 0, "0x4040", ARG_INT, + check_ambiguity, override, 0, 0, + "qose4", '-', additional_error)) goto failure; - } - if (args_info->nsapi_orig) - free(args_info->nsapi_orig); /* free previous string */ - args_info->nsapi_orig = - gengetopt_strdup(optarg); + } /* Charging characteristics. */ else if (strcmp (long_options[option_index].name, "charging") == 0) { - if (local_args_info.charging_given) { - fprintf(stderr, - "%s: `--charging' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->charging_given && !override) - continue; - local_args_info.charging_given = 1; - args_info->charging_given = 1; - args_info->charging_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg + ((void *)&(args_info->charging_arg), + &(args_info->charging_orig), + &(args_info->charging_given), + &(local_args_info.charging_given), optarg, + 0, "0x0800", ARG_INT, check_ambiguity, + override, 0, 0, "charging", '-', + additional_error)) goto failure; - } - if (args_info->charging_orig) - free(args_info->charging_orig); /* free previous string */ - args_info->charging_orig = - gengetopt_strdup(optarg); + } /* Create local network interface. */ else if (strcmp (long_options[option_index].name, "createif") == 0) { - if (local_args_info.createif_given) { - fprintf(stderr, - "%s: `--createif' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg + ((void *)&(args_info->createif_flag), 0, + &(args_info->createif_given), + &(local_args_info.createif_given), optarg, + 0, 0, ARG_FLAG, check_ambiguity, override, + 1, 0, "createif", '-', additional_error)) goto failure; - } - if (args_info->createif_given && !override) - continue; - local_args_info.createif_given = 1; - args_info->createif_given = 1; - args_info->createif_flag = - !(args_info->createif_flag); + } /* Create default route. */ else if (strcmp (long_options[option_index].name, "defaultroute") == 0) { - if (local_args_info.defaultroute_given) { - fprintf(stderr, - "%s: `--defaultroute' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg + ((void *)&(args_info->defaultroute_flag), 0, + &(args_info->defaultroute_given), + &(local_args_info.defaultroute_given), + optarg, 0, 0, ARG_FLAG, check_ambiguity, + override, 1, 0, "defaultroute", '-', + additional_error)) goto failure; - } - if (args_info->defaultroute_given && !override) - continue; - local_args_info.defaultroute_given = 1; - args_info->defaultroute_given = 1; - args_info->defaultroute_flag = - !(args_info->defaultroute_flag); + } /* Script to run after link-up. */ else if (strcmp(long_options[option_index].name, "ipup") == 0) { - if (local_args_info.ipup_given) { - fprintf(stderr, - "%s: `--ipup' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg((void *)&(args_info->ipup_arg), + &(args_info->ipup_orig), + &(args_info->ipup_given), + &(local_args_info.ipup_given), + optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "ipup", '-', additional_error)) goto failure; - } - if (args_info->ipup_given && !override) - continue; - local_args_info.ipup_given = 1; - args_info->ipup_given = 1; - if (args_info->ipup_arg) - free(args_info->ipup_arg); /* free previous string */ - args_info->ipup_arg = gengetopt_strdup(optarg); - if (args_info->ipup_orig) - free(args_info->ipup_orig); /* free previous string */ - args_info->ipup_orig = gengetopt_strdup(optarg); + } /* Script to run after link-down. */ else if (strcmp (long_options[option_index].name, "ipdown") == 0) { - if (local_args_info.ipdown_given) { - fprintf(stderr, - "%s: `--ipdown' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg((void *)&(args_info->ipdown_arg), + &(args_info->ipdown_orig), + &(args_info->ipdown_given), + &(local_args_info.ipdown_given), + optarg, 0, 0, ARG_STRING, + check_ambiguity, override, 0, 0, + "ipdown", '-', additional_error)) goto failure; - } - if (args_info->ipdown_given && !override) - continue; - local_args_info.ipdown_given = 1; - args_info->ipdown_given = 1; - if (args_info->ipdown_arg) - free(args_info->ipdown_arg); /* free previous string */ - args_info->ipdown_arg = - gengetopt_strdup(optarg); - if (args_info->ipdown_orig) - free(args_info->ipdown_orig); /* free previous string */ - args_info->ipdown_orig = - gengetopt_strdup(optarg); + } /* Ping remote host. */ else if (strcmp (long_options[option_index].name, "pinghost") == 0) { - if (local_args_info.pinghost_given) { - fprintf(stderr, - "%s: `--pinghost' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg + ((void *)&(args_info->pinghost_arg), + &(args_info->pinghost_orig), + &(args_info->pinghost_given), + &(local_args_info.pinghost_given), optarg, + 0, 0, ARG_STRING, check_ambiguity, + override, 0, 0, "pinghost", '-', + additional_error)) goto failure; - } - if (args_info->pinghost_given && !override) - continue; - local_args_info.pinghost_given = 1; - args_info->pinghost_given = 1; - if (args_info->pinghost_arg) - free(args_info->pinghost_arg); /* free previous string */ - args_info->pinghost_arg = - gengetopt_strdup(optarg); - if (args_info->pinghost_orig) - free(args_info->pinghost_orig); /* free previous string */ - args_info->pinghost_orig = - gengetopt_strdup(optarg); + } /* Number of ping req per second. */ else if (strcmp (long_options[option_index].name, "pingrate") == 0) { - if (local_args_info.pingrate_given) { - fprintf(stderr, - "%s: `--pingrate' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->pingrate_given && !override) - continue; - local_args_info.pingrate_given = 1; - args_info->pingrate_given = 1; - args_info->pingrate_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg + ((void *)&(args_info->pingrate_arg), + &(args_info->pingrate_orig), + &(args_info->pingrate_given), + &(local_args_info.pingrate_given), optarg, + 0, "1", ARG_INT, check_ambiguity, override, + 0, 0, "pingrate", '-', additional_error)) goto failure; - } - if (args_info->pingrate_orig) - free(args_info->pingrate_orig); /* free previous string */ - args_info->pingrate_orig = - gengetopt_strdup(optarg); + } /* Number of ping data bytes. */ else if (strcmp (long_options[option_index].name, "pingsize") == 0) { - if (local_args_info.pingsize_given) { - fprintf(stderr, - "%s: `--pingsize' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->pingsize_given && !override) - continue; - local_args_info.pingsize_given = 1; - args_info->pingsize_given = 1; - args_info->pingsize_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg + ((void *)&(args_info->pingsize_arg), + &(args_info->pingsize_orig), + &(args_info->pingsize_given), + &(local_args_info.pingsize_given), optarg, + 0, "56", ARG_INT, check_ambiguity, + override, 0, 0, "pingsize", '-', + additional_error)) goto failure; - } - if (args_info->pingsize_orig) - free(args_info->pingsize_orig); /* free previous string */ - args_info->pingsize_orig = - gengetopt_strdup(optarg); + } /* Number of ping req to send. */ else if (strcmp (long_options[option_index].name, "pingcount") == 0) { - if (local_args_info.pingcount_given) { - fprintf(stderr, - "%s: `--pingcount' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->pingcount_given && !override) - continue; - local_args_info.pingcount_given = 1; - args_info->pingcount_given = 1; - args_info->pingcount_arg = - strtol(optarg, &stop_char, 0); - if (!(stop_char && *stop_char == '\0')) { - fprintf(stderr, - "%s: invalid numeric value: %s\n", - argv[0], optarg); + + if (update_arg + ((void *)&(args_info->pingcount_arg), + &(args_info->pingcount_orig), + &(args_info->pingcount_given), + &(local_args_info.pingcount_given), optarg, + 0, "0", ARG_INT, check_ambiguity, override, + 0, 0, "pingcount", '-', additional_error)) goto failure; - } - if (args_info->pingcount_orig) - free(args_info->pingcount_orig); /* free previous string */ - args_info->pingcount_orig = - gengetopt_strdup(optarg); + } /* Do not print ping packet info. */ else if (strcmp (long_options[option_index].name, "pingquiet") == 0) { - if (local_args_info.pingquiet_given) { - fprintf(stderr, - "%s: `--pingquiet' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); - goto failure; - } - if (args_info->pingquiet_given && !override) - continue; - local_args_info.pingquiet_given = 1; - args_info->pingquiet_given = 1; - args_info->pingquiet_flag = - !(args_info->pingquiet_flag); - } - /* Do not send recovery. */ - else if (strcmp - (long_options[option_index].name, - "norecovery") == 0) { - if (local_args_info.norecovery_given) { - fprintf(stderr, - "%s: `--norecovery' option given more than once%s\n", - argv[0], - (additional_error ? - additional_error : "")); + + if (update_arg + ((void *)&(args_info->pingquiet_flag), 0, + &(args_info->pingquiet_given), + &(local_args_info.pingquiet_given), optarg, + 0, 0, ARG_FLAG, check_ambiguity, override, + 1, 0, "pingquiet", '-', additional_error)) goto failure; - } - if (args_info->norecovery_given && !override) - continue; - local_args_info.norecovery_given = 1; - args_info->norecovery_given = 1; - args_info->norecovery_flag = - !(args_info->norecovery_flag); + } break; @@ -1740,7 +1418,7 @@ cmdline_parser_internal(int argc, char *const *argv, cmdline_parser_release(&local_args_info); - if (error) + if (error_occurred) return (EXIT_FAILURE); return 0; @@ -1759,40 +1437,25 @@ failure: #define CONFIG_FILE_LINE_BUFFER_SIZE (CONFIG_FILE_LINE_SIZE+3) /* 3 is for "--" and "=" */ -char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE + 1]; - -int -cmdline_parser_configfile(char *const filename, - struct gengetopt_args_info *args_info, int override, - int initialize, int check_required) +static int _cmdline_parser_configfile(const char *filename, int *my_argc) { FILE *file; + char my_argv[CONFIG_FILE_LINE_BUFFER_SIZE + 1]; char linebuf[CONFIG_FILE_LINE_SIZE]; int line_num = 0; - int i, result, equal; + int result = 0, equal; char *fopt, *farg; char *str_index; size_t len, next_token; char delimiter; - int my_argc = 0; - char **my_argv_arg; - char *additional_error; - /* store the program name */ - cmd_line_list_tmp = - (struct line_list *)malloc(sizeof(struct line_list)); - cmd_line_list_tmp->next = cmd_line_list; - cmd_line_list = cmd_line_list_tmp; - cmd_line_list->string_arg = gengetopt_strdup(CMDLINE_PARSER_PACKAGE); - - if ((file = fopen(filename, "r")) == NULL) { + if ((file = fopen(filename, "r")) == 0) { fprintf(stderr, "%s: Error opening configuration file '%s'\n", CMDLINE_PARSER_PACKAGE, filename); - result = EXIT_FAILURE; - goto conf_failure; + return EXIT_FAILURE; } - while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != NULL) { + while ((fgets(linebuf, CONFIG_FILE_LINE_SIZE, file)) != 0) { ++line_num; my_argv[0] = '\0'; len = strlen(linebuf); @@ -1801,7 +1464,7 @@ cmdline_parser_configfile(char *const filename, "%s:%s:%d: Line too long in configuration file\n", CMDLINE_PARSER_PACKAGE, filename, line_num); result = EXIT_FAILURE; - goto conf_failure; + break; } /* find first non-whitespace character in the line */ @@ -1817,7 +1480,7 @@ cmdline_parser_configfile(char *const filename, next_token = strcspn(fopt, " \t\r\n="); if (fopt[next_token] == '\0') { /* the line is over */ - farg = NULL; + farg = 0; equal = 0; goto noarg; } @@ -1828,6 +1491,7 @@ cmdline_parser_configfile(char *const filename, /* advance pointers to the next token after the end of fopt */ next_token += strspn(fopt + next_token, " \t\r\n"); + /* check for the presence of equal sign, and if so, skip it */ if (!equal) if ((equal = (fopt[next_token] == '='))) { @@ -1848,7 +1512,7 @@ cmdline_parser_configfile(char *const filename, CMDLINE_PARSER_PACKAGE, filename, line_num); result = EXIT_FAILURE; - goto conf_failure; + break; } } else { /* read up the remaining part up to a delimiter */ next_token = strcspn(farg, " \t\r\n#\'\""); @@ -1868,20 +1532,31 @@ cmdline_parser_configfile(char *const filename, CMDLINE_PARSER_PACKAGE, filename, line_num); result = EXIT_FAILURE; - goto conf_failure; + break; } } noarg: - ++my_argc; + if (!strcmp(fopt, "include")) { + if (farg && *farg) { + result = + _cmdline_parser_configfile(farg, my_argc); + } else { + fprintf(stderr, + "%s:%s:%d: include requires a filename argument.\n", + CMDLINE_PARSER_PACKAGE, filename, + line_num); + } + continue; + } len = strlen(fopt); - strcat(my_argv, len > 1 ? "--" : "-"); strcat(my_argv, fopt); if (len > 1 && ((farg && *farg) || equal)) strcat(my_argv, "="); if (farg && *farg) strcat(my_argv, farg); + ++(*my_argc); cmd_line_list_tmp = (struct line_list *)malloc(sizeof(struct line_list)); @@ -1890,30 +1565,69 @@ noarg: cmd_line_list->string_arg = gengetopt_strdup(my_argv); } /* while */ - ++my_argc; /* for program name */ - my_argv_arg = (char **)malloc((my_argc + 1) * sizeof(char *)); - cmd_line_list_tmp = cmd_line_list; - for (i = my_argc - 1; i >= 0; --i) { - my_argv_arg[i] = cmd_line_list_tmp->string_arg; - cmd_line_list_tmp = cmd_line_list_tmp->next; - } - my_argv_arg[my_argc] = 0; + if (file) + fclose(file); + return result; +} - additional_error = - (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + 1); - strcpy(additional_error, ADDITIONAL_ERROR); - strcat(additional_error, filename); - result = - cmdline_parser_internal(my_argc, my_argv_arg, args_info, override, - initialize, check_required, - additional_error); +int +cmdline_parser_configfile(const char *filename, + struct gengetopt_args_info *args_info, + int override, int initialize, int check_required) +{ + struct cmdline_parser_params params; - free(additional_error); - free(my_argv_arg); + params.override = override; + params.initialize = initialize; + params.check_required = check_required; + params.check_ambiguity = 0; + params.print_errors = 1; -conf_failure: - if (file) - fclose(file); + return cmdline_parser_config_file(filename, args_info, ¶ms); +} + +int +cmdline_parser_config_file(const char *filename, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params) +{ + int i, result; + int my_argc = 1; + char **my_argv_arg; + char *additional_error; + + /* store the program name */ + cmd_line_list_tmp = + (struct line_list *)malloc(sizeof(struct line_list)); + cmd_line_list_tmp->next = cmd_line_list; + cmd_line_list = cmd_line_list_tmp; + cmd_line_list->string_arg = gengetopt_strdup(CMDLINE_PARSER_PACKAGE); + + result = _cmdline_parser_configfile(filename, &my_argc); + + if (result != EXIT_FAILURE) { + my_argv_arg = (char **)malloc((my_argc + 1) * sizeof(char *)); + cmd_line_list_tmp = cmd_line_list; + + for (i = my_argc - 1; i >= 0; --i) { + my_argv_arg[i] = cmd_line_list_tmp->string_arg; + cmd_line_list_tmp = cmd_line_list_tmp->next; + } + + my_argv_arg[my_argc] = 0; + + additional_error = + (char *)malloc(strlen(filename) + strlen(ADDITIONAL_ERROR) + + 1); + strcpy(additional_error, ADDITIONAL_ERROR); + strcat(additional_error, filename); + result = + cmdline_parser_internal(my_argc, my_argv_arg, args_info, + params, additional_error); + + free(additional_error); + free(my_argv_arg); + } free_cmd_list(); if (result == EXIT_FAILURE) { diff --git a/sgsnemu/cmdline.ggo b/sgsnemu/cmdline.ggo index 2170e8b..0184775 100644 --- a/sgsnemu/cmdline.ggo +++ b/sgsnemu/cmdline.ggo @@ -6,7 +6,11 @@ # notice and this permission notice is included in all copies or # substantial portions of the software. # -# Use "gengetopt --conf-parser < cmdline.ggo" +# Use +# gengetopt --conf-parser < cmdline.ggo +# linux-2.6/scripts/Lindent cmdline.c +# linux-2.6/scripts/Lindent cmdline.h +# sed -i -e 's/int qose1_arg;/unsigned long long int qose1_arg;/' cmdline.h # to generate cmdline.c and cmdline.h option "debug" d "Run in debug mode" flag off diff --git a/sgsnemu/cmdline.h b/sgsnemu/cmdline.h index 17f7c18..248384e 100644 --- a/sgsnemu/cmdline.h +++ b/sgsnemu/cmdline.h @@ -1,6 +1,9 @@ -/* cmdline.h */ - -/* File autogenerated by gengetopt version 2.17 */ +/** @file cmdline.h + * @brief The header file for the command line option parser + * generated by GNU Gengetopt version 2.22.6 + * http://www.gnu.org/software/gengetopt. + * DO NOT modify this file, since it can be overwritten + * @author GNU Gengetopt by Lorenzo Bettini */ #ifndef CMDLINE_H #define CMDLINE_H @@ -10,197 +13,495 @@ #include "config.h" #endif +#include <stdio.h> /* for FILE */ + #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ #ifndef CMDLINE_PARSER_PACKAGE +/** @brief the program name (used for printing errors) */ #define CMDLINE_PARSER_PACKAGE PACKAGE #endif +#ifndef CMDLINE_PARSER_PACKAGE_NAME +/** @brief the complete program name (used for help and version) */ +#ifdef PACKAGE_NAME +#define CMDLINE_PARSER_PACKAGE_NAME PACKAGE_NAME +#else +#define CMDLINE_PARSER_PACKAGE_NAME PACKAGE +#endif +#endif + #ifndef CMDLINE_PARSER_VERSION +/** @brief the program version */ #define CMDLINE_PARSER_VERSION VERSION #endif +/** @brief Where the command line options are stored */ struct gengetopt_args_info { - const char *help_help; /* Print help and exit help description. */ - const char *version_help; /* Print version and exit help description. */ - int debug_flag; /* Run in debug mode (default=off). */ - const char *debug_help; /* Run in debug mode help description. */ - char *conf_arg; /* Read configuration file. */ - char *conf_orig; /* Read configuration file original value given at command line. */ - const char *conf_help; /* Read configuration file help description. */ - char *pidfile_arg; /* Filename of process id file (default='./sgsnemu.pid'). */ - char *pidfile_orig; /* Filename of process id file original value given at command line. */ - const char *pidfile_help; /* Filename of process id file help description. */ - char *statedir_arg; /* Directory of nonvolatile data (default='./'). */ - char *statedir_orig; /* Directory of nonvolatile data original value given at command line. */ - const char *statedir_help; /* Directory of nonvolatile data help description. */ - char *dns_arg; /* DNS Server to use. */ - char *dns_orig; /* DNS Server to use original value given at command line. */ - const char *dns_help; /* DNS Server to use help description. */ - char *listen_arg; /* Local interface. */ - char *listen_orig; /* Local interface original value given at command line. */ - const char *listen_help; /* Local interface help description. */ - char *remote_arg; /* Remote host. */ - char *remote_orig; /* Remote host original value given at command line. */ - const char *remote_help; /* Remote host help description. */ - int contexts_arg; /* Number of contexts (default='1'). */ - char *contexts_orig; /* Number of contexts original value given at command line. */ - const char *contexts_help; /* Number of contexts help description. */ - int timelimit_arg; /* Exit after timelimit seconds (default='0'). */ - char *timelimit_orig; /* Exit after timelimit seconds original value given at command line. */ - const char *timelimit_help; /* Exit after timelimit seconds help description. */ - int gtpversion_arg; /* GTP version to use (default='1'). */ - char *gtpversion_orig; /* GTP version to use original value given at command line. */ - const char *gtpversion_help; /* GTP version to use help description. */ - char *apn_arg; /* Access point name (default='internet'). */ - char *apn_orig; /* Access point name original value given at command line. */ - const char *apn_help; /* Access point name help description. */ - int selmode_arg; /* Selection mode (default='0x01'). */ - char *selmode_orig; /* Selection mode original value given at command line. */ - const char *selmode_help; /* Selection mode help description. */ - char *rattype_arg; /* Radio Access Technology Type (optional). */ + const char *help_help; + /**< @brief Print help and exit help description. */ + const char *version_help; + /**< @brief Print version and exit help description. */ + int debug_flag; + /**< @brief Run in debug mode (default=off). */ + const char *debug_help; + /**< @brief Run in debug mode help description. */ + char *conf_arg; + /**< @brief Read configuration file. */ + char *conf_orig; + /**< @brief Read configuration file original value given at command line. */ + const char *conf_help; + /**< @brief Read configuration file help description. */ + char *pidfile_arg; + /**< @brief Filename of process id file (default='./sgsnemu.pid'). */ + char *pidfile_orig; + /**< @brief Filename of process id file original value given at command line. */ + const char *pidfile_help; + /**< @brief Filename of process id file help description. */ + char *statedir_arg; + /**< @brief Directory of nonvolatile data (default='./'). */ + char *statedir_orig; + /**< @brief Directory of nonvolatile data original value given at command line. */ + const char *statedir_help; + /**< @brief Directory of nonvolatile data help description. */ + char *dns_arg; + /**< @brief DNS Server to use. */ + char *dns_orig; + /**< @brief DNS Server to use original value given at command line. */ + const char *dns_help; + /**< @brief DNS Server to use help description. */ + char *listen_arg; + /**< @brief Local interface. */ + char *listen_orig; + /**< @brief Local interface original value given at command line. */ + const char *listen_help; + /**< @brief Local interface help description. */ + char *remote_arg; + /**< @brief Remote host. */ + char *remote_orig; + /**< @brief Remote host original value given at command line. */ + const char *remote_help; + /**< @brief Remote host help description. */ + int contexts_arg; + /**< @brief Number of contexts (default='1'). */ + char *contexts_orig; + /**< @brief Number of contexts original value given at command line. */ + const char *contexts_help; + /**< @brief Number of contexts help description. */ + int timelimit_arg; + /**< @brief Exit after timelimit seconds (default='0'). */ + char *timelimit_orig; + /**< @brief Exit after timelimit seconds original value given at command line. */ + const char *timelimit_help; + /**< @brief Exit after timelimit seconds help description. */ + int gtpversion_arg; + /**< @brief GTP version to use (default='1'). */ + char *gtpversion_orig; + /**< @brief GTP version to use original value given at command line. */ + const char *gtpversion_help; + /**< @brief GTP version to use help description. */ + char *apn_arg; + /**< @brief Access point name (default='internet'). */ + char *apn_orig; + /**< @brief Access point name original value given at command line. */ + const char *apn_help; + /**< @brief Access point name help description. */ + int selmode_arg; + /**< @brief Selection mode (default='0x01'). */ + char *selmode_orig; + /**< @brief Selection mode original value given at command line. */ + const char *selmode_help; + /**< @brief Selection mode help description. */ + int rattype_arg; + /**< @brief Radio Access Technology Type (default='1'). */ char *rattype_orig; - char *rattype_help; - char *userloc_arg; /* User Location Information (optional). */ + /**< @brief Radio Access Technology Type original value given at command line. */ + const char *rattype_help; + /**< @brief Radio Access Technology Type help description. */ + char *userloc_arg; + /**< @brief User Location Information (default='02509946241207'). */ char *userloc_orig; - char *userloc_help; - char *rai_arg; /* Routing Area Information (optional). */ + /**< @brief User Location Information original value given at command line. */ + const char *userloc_help; + /**< @brief User Location Information help description. */ + char *rai_arg; + /**< @brief Routing Area Information (default='02509946241207'). */ char *rai_orig; - char *rai_help; - char *mstz_arg; /* MS Time Zone (optional). */ + /**< @brief Routing Area Information original value given at command line. */ + const char *rai_help; + /**< @brief Routing Area Information help description. */ + char *mstz_arg; + /**< @brief MS Time Zone (default='0'). */ char *mstz_orig; - char *mstz_help; - char *imeisv_arg; /* IMEI(SV) (optional). */ + /**< @brief MS Time Zone original value given at command line. */ + const char *mstz_help; + /**< @brief MS Time Zone help description. */ + char *imeisv_arg; + /**< @brief IMEI(SV) International Mobile Equipment Identity (and Software Version) (default='2143658709214365'). */ char *imeisv_orig; - char *imeisv_help; - char *imsi_arg; /* IMSI (default='240010123456789'). */ - char *imsi_orig; /* IMSI original value given at command line. */ - const char *imsi_help; /* IMSI help description. */ - int nsapi_arg; /* NSAPI (default='0'). */ - char *nsapi_orig; /* NSAPI original value given at command line. */ - const char *nsapi_help; /* NSAPI help description. */ - char *msisdn_arg; /* Mobile Station ISDN number (default='46702123456'). */ - char *msisdn_orig; /* Mobile Station ISDN number original value given at command line. */ - const char *msisdn_help; /* Mobile Station ISDN number help description. */ - int qos_arg; /* Requested quality of service (default='0x0b921f'). */ - char *qos_orig; /* Requested quality of service original value given at command line. */ - const char *qos_help; /* Requested quality of service help description. */ - unsigned long long int qose1_arg; /* Requested quality of service Extension 1 */ - char *qose1_orig; /* Requested quality of service Extension 1 original value given at command line. */ - int qose2_arg; /* Requested quality of service Extension 2 */ - char *qose2_orig; /* Requested quality of service Extension 2 original value given at command line. */ - int qose3_arg; /* Requested quality of service Extension 3 */ - char *qose3_orig; /* Requested quality of service Extension 3 original value given at command line. */ - int qose4_arg; /* Requested quality of service Extension 4 */ - char *qose4_orig; /* Requested quality of service Extension 4 original value given at command line. */ - int charging_arg; /* Charging characteristics (default='0x0800'). */ - char *charging_orig; /* Charging characteristics original value given at command line. */ - const char *charging_help; /* Charging characteristics help description. */ - char *uid_arg; /* Login user ID (default='mig'). */ - char *uid_orig; /* Login user ID original value given at command line. */ - const char *uid_help; /* Login user ID help description. */ - char *pwd_arg; /* Login password (default='hemmelig'). */ - char *pwd_orig; /* Login password original value given at command line. */ - const char *pwd_help; /* Login password help description. */ - int createif_flag; /* Create local network interface (default=off). */ - const char *createif_help; /* Create local network interface help description. */ - char *net_arg; /* Network address for local interface. */ - char *net_orig; /* Network address for local interface original value given at command line. */ - const char *net_help; /* Network address for local interface help description. */ - int defaultroute_flag; /* Create default route (default=off). */ - const char *defaultroute_help; /* Create default route help description. */ - char *ipup_arg; /* Script to run after link-up. */ - char *ipup_orig; /* Script to run after link-up original value given at command line. */ - const char *ipup_help; /* Script to run after link-up help description. */ - char *ipdown_arg; /* Script to run after link-down. */ - char *ipdown_orig; /* Script to run after link-down original value given at command line. */ - const char *ipdown_help; /* Script to run after link-down help description. */ - char *pinghost_arg; /* Ping remote host. */ - char *pinghost_orig; /* Ping remote host original value given at command line. */ - const char *pinghost_help; /* Ping remote host help description. */ - int pingrate_arg; /* Number of ping req per second (default='1'). */ - char *pingrate_orig; /* Number of ping req per second original value given at command line. */ - const char *pingrate_help; /* Number of ping req per second help description. */ - int pingsize_arg; /* Number of ping data bytes (default='56'). */ - char *pingsize_orig; /* Number of ping data bytes original value given at command line. */ - const char *pingsize_help; /* Number of ping data bytes help description. */ - int pingcount_arg; /* Number of ping req to send (default='0'). */ - char *pingcount_orig; /* Number of ping req to send original value given at command line. */ - const char *pingcount_help; /* Number of ping req to send help description. */ - int pingquiet_flag; /* Do not print ping packet info (default=off). */ - const char *pingquiet_help; /* Do not print ping packet info help description. */ - int norecovery_flag; /* Do not print ping packet info (default=off). */ - const char *norecovery_help; /* Do not print ping packet info help description. */ - - int help_given; /* Whether help was given. */ - int version_given; /* Whether version was given. */ - int debug_given; /* Whether debug was given. */ - int conf_given; /* Whether conf was given. */ - int pidfile_given; /* Whether pidfile was given. */ - int statedir_given; /* Whether statedir was given. */ - int dns_given; /* Whether dns was given. */ - int listen_given; /* Whether listen was given. */ - int remote_given; /* Whether remote was given. */ - int contexts_given; /* Whether contexts was given. */ - int timelimit_given; /* Whether timelimit was given. */ - int gtpversion_given; /* Whether gtpversion was given. */ - int apn_given; /* Whether apn was given. */ - int selmode_given; /* Whether selmode was given. */ - int rattype_given; /* Whether rattype was given. */ - int userloc_given; /* Whether userloc was given. */ - int rai_given; /* Whether RAI was given. */ - int mstz_given; /* Whether mstz was given. */ - int imeisv_given; /* Whether imeisv was given. */ - int imsi_given; /* Whether imsi was given. */ - int nsapi_given; /* Whether nsapi was given. */ - int msisdn_given; /* Whether msisdn was given. */ - int qos_given; /* Whether qos was given. */ - int qose1_given; /* Whether qos Extension 1 was given. */ - int qose2_given; /* Whether qos Extension 2 was given. */ - int qose3_given; /* Whether qos Extension 3 was given. */ - int qose4_given; /* Whether qos Extension 4 was given. */ - int charging_given; /* Whether charging was given. */ - int uid_given; /* Whether uid was given. */ - int pwd_given; /* Whether pwd was given. */ - int createif_given; /* Whether createif was given. */ - int net_given; /* Whether net was given. */ - int defaultroute_given; /* Whether defaultroute was given. */ - int ipup_given; /* Whether ipup was given. */ - int ipdown_given; /* Whether ipdown was given. */ - int pinghost_given; /* Whether pinghost was given. */ - int pingrate_given; /* Whether pingrate was given. */ - int pingsize_given; /* Whether pingsize was given. */ - int pingcount_given; /* Whether pingcount was given. */ - int pingquiet_given; /* Whether pingquiet was given. */ - int norecovery_given; /* Whether norecovery was given. */ + /**< @brief IMEI(SV) International Mobile Equipment Identity (and Software Version) original value given at command line. */ + const char *imeisv_help; + /**< @brief IMEI(SV) International Mobile Equipment Identity (and Software Version) help description. */ + int norecovery_flag; + /**< @brief Do not send recovery (default=off). */ + const char *norecovery_help; + /**< @brief Do not send recovery help description. */ + char *imsi_arg; + /**< @brief IMSI (default='240010123456789'). */ + char *imsi_orig; + /**< @brief IMSI original value given at command line. */ + const char *imsi_help; + /**< @brief IMSI help description. */ + int nsapi_arg; + /**< @brief NSAPI (default='0'). */ + char *nsapi_orig; + /**< @brief NSAPI original value given at command line. */ + const char *nsapi_help; + /**< @brief NSAPI help description. */ + char *msisdn_arg; + /**< @brief Mobile Station ISDN number (default='46702123456'). */ + char *msisdn_orig; + /**< @brief Mobile Station ISDN number original value given at command line. */ + const char *msisdn_help; + /**< @brief Mobile Station ISDN number help description. */ + int qos_arg; + /**< @brief Requested quality of service (default='0x000b921f'). */ + char *qos_orig; + /**< @brief Requested quality of service original value given at command line. */ + const char *qos_help; + /**< @brief Requested quality of service help description. */ + unsigned long long int qose1_arg; + /**< @brief Requested quality of service Extension 1 (default='0x9396404074f9ffff'). */ + char *qose1_orig; + /**< @brief Requested quality of service Extension 1 original value given at command line. */ + const char *qose1_help; + /**< @brief Requested quality of service Extension 1 help description. */ + int qose2_arg; + /**< @brief Requested quality of service Extension 2 (default='0x11'). */ + char *qose2_orig; + /**< @brief Requested quality of service Extension 2 original value given at command line. */ + const char *qose2_help; + /**< @brief Requested quality of service Extension 2 help description. */ + int qose3_arg; + /**< @brief Requested quality of service Extension 3 (default='0x0101'). */ + char *qose3_orig; + /**< @brief Requested quality of service Extension 3 original value given at command line. */ + const char *qose3_help; + /**< @brief Requested quality of service Extension 3 help description. */ + int qose4_arg; + /**< @brief Requested quality of service Extension 4 (default='0x4040'). */ + char *qose4_orig; + /**< @brief Requested quality of service Extension 4 original value given at command line. */ + const char *qose4_help; + /**< @brief Requested quality of service Extension 4 help description. */ + int charging_arg; + /**< @brief Charging characteristics (default='0x0800'). */ + char *charging_orig; + /**< @brief Charging characteristics original value given at command line. */ + const char *charging_help; + /**< @brief Charging characteristics help description. */ + char *uid_arg; + /**< @brief Login user ID (default='mig'). */ + char *uid_orig; + /**< @brief Login user ID original value given at command line. */ + const char *uid_help; + /**< @brief Login user ID help description. */ + char *pwd_arg; + /**< @brief Login password (default='hemmelig'). */ + char *pwd_orig; + /**< @brief Login password original value given at command line. */ + const char *pwd_help; + /**< @brief Login password help description. */ + int createif_flag; + /**< @brief Create local network interface (default=off). */ + const char *createif_help; + /**< @brief Create local network interface help description. */ + char *net_arg; + /**< @brief Network address for local interface. */ + char *net_orig; + /**< @brief Network address for local interface original value given at command line. */ + const char *net_help; + /**< @brief Network address for local interface help description. */ + int defaultroute_flag; + /**< @brief Create default route (default=off). */ + const char *defaultroute_help; + /**< @brief Create default route help description. */ + char *ipup_arg; + /**< @brief Script to run after link-up. */ + char *ipup_orig; + /**< @brief Script to run after link-up original value given at command line. */ + const char *ipup_help; + /**< @brief Script to run after link-up help description. */ + char *ipdown_arg; + /**< @brief Script to run after link-down. */ + char *ipdown_orig; + /**< @brief Script to run after link-down original value given at command line. */ + const char *ipdown_help; + /**< @brief Script to run after link-down help description. */ + char *pinghost_arg; + /**< @brief Ping remote host. */ + char *pinghost_orig; + /**< @brief Ping remote host original value given at command line. */ + const char *pinghost_help; + /**< @brief Ping remote host help description. */ + int pingrate_arg; + /**< @brief Number of ping req per second (default='1'). */ + char *pingrate_orig; + /**< @brief Number of ping req per second original value given at command line. */ + const char *pingrate_help; + /**< @brief Number of ping req per second help description. */ + int pingsize_arg; + /**< @brief Number of ping data bytes (default='56'). */ + char *pingsize_orig; + /**< @brief Number of ping data bytes original value given at command line. */ + const char *pingsize_help; + /**< @brief Number of ping data bytes help description. */ + int pingcount_arg; + /**< @brief Number of ping req to send (default='0'). */ + char *pingcount_orig; + /**< @brief Number of ping req to send original value given at command line. */ + const char *pingcount_help; + /**< @brief Number of ping req to send help description. */ + int pingquiet_flag; + /**< @brief Do not print ping packet info (default=off). */ + const char *pingquiet_help; + /**< @brief Do not print ping packet info help description. */ + + unsigned int help_given; + /**< @brief Whether help was given. */ + unsigned int version_given; + /**< @brief Whether version was given. */ + unsigned int debug_given; + /**< @brief Whether debug was given. */ + unsigned int conf_given; + /**< @brief Whether conf was given. */ + unsigned int pidfile_given; + /**< @brief Whether pidfile was given. */ + unsigned int statedir_given; + /**< @brief Whether statedir was given. */ + unsigned int dns_given; + /**< @brief Whether dns was given. */ + unsigned int listen_given; + /**< @brief Whether listen was given. */ + unsigned int remote_given; + /**< @brief Whether remote was given. */ + unsigned int contexts_given; + /**< @brief Whether contexts was given. */ + unsigned int timelimit_given; + /**< @brief Whether timelimit was given. */ + unsigned int gtpversion_given; + /**< @brief Whether gtpversion was given. */ + unsigned int apn_given; + /**< @brief Whether apn was given. */ + unsigned int selmode_given; + /**< @brief Whether selmode was given. */ + unsigned int rattype_given; + /**< @brief Whether rattype was given. */ + unsigned int userloc_given; + /**< @brief Whether userloc was given. */ + unsigned int rai_given; + /**< @brief Whether rai was given. */ + unsigned int mstz_given; + /**< @brief Whether mstz was given. */ + unsigned int imeisv_given; + /**< @brief Whether imeisv was given. */ + unsigned int norecovery_given; + /**< @brief Whether norecovery was given. */ + unsigned int imsi_given; + /**< @brief Whether imsi was given. */ + unsigned int nsapi_given; + /**< @brief Whether nsapi was given. */ + unsigned int msisdn_given; + /**< @brief Whether msisdn was given. */ + unsigned int qos_given; + /**< @brief Whether qos was given. */ + unsigned int qose1_given; + /**< @brief Whether qose1 was given. */ + unsigned int qose2_given; + /**< @brief Whether qose2 was given. */ + unsigned int qose3_given; + /**< @brief Whether qose3 was given. */ + unsigned int qose4_given; + /**< @brief Whether qose4 was given. */ + unsigned int charging_given; + /**< @brief Whether charging was given. */ + unsigned int uid_given; + /**< @brief Whether uid was given. */ + unsigned int pwd_given; + /**< @brief Whether pwd was given. */ + unsigned int createif_given; + /**< @brief Whether createif was given. */ + unsigned int net_given; + /**< @brief Whether net was given. */ + unsigned int defaultroute_given; + /**< @brief Whether defaultroute was given. */ + unsigned int ipup_given; + /**< @brief Whether ipup was given. */ + unsigned int ipdown_given; + /**< @brief Whether ipdown was given. */ + unsigned int pinghost_given; + /**< @brief Whether pinghost was given. */ + unsigned int pingrate_given; + /**< @brief Whether pingrate was given. */ + unsigned int pingsize_given; + /**< @brief Whether pingsize was given. */ + unsigned int pingcount_given; + /**< @brief Whether pingcount was given. */ + unsigned int pingquiet_given; + /**< @brief Whether pingquiet was given. */ + + }; +/** @brief The additional parameters to pass to parser functions */ + struct cmdline_parser_params { + int override; + /**< @brief whether to override possibly already present options (default 0) */ + int initialize; + /**< @brief whether to initialize the option structure gengetopt_args_info (default 1) */ + int check_required; + /**< @brief whether to check that all required options were provided (default 1) */ + int check_ambiguity; + /**< @brief whether to check for options already specified in the option structure gengetopt_args_info (default 0) */ + int print_errors; + /**< @brief whether getopt_long should print an error message for a bad option (default 1) */ }; +/** @brief the purpose string of the program */ extern const char *gengetopt_args_info_purpose; +/** @brief the usage string of the program */ extern const char *gengetopt_args_info_usage; +/** @brief the description string of the program */ + extern const char *gengetopt_args_info_description; +/** @brief all the lines making the help output */ extern const char *gengetopt_args_info_help[]; - int cmdline_parser(int argc, char *const *argv, +/** + * The command line parser + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @return 0 if everything went fine, NON 0 if an error took place + */ + int cmdline_parser(int argc, char **argv, struct gengetopt_args_info *args_info); - int cmdline_parser2(int argc, char *const *argv, + +/** + * The command line parser (version with additional parameters - deprecated) + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @param override whether to override possibly already present options + * @param initialize whether to initialize the option structure my_args_info + * @param check_required whether to check that all required options were provided + * @return 0 if everything went fine, NON 0 if an error took place + * @deprecated use cmdline_parser_ext() instead + */ + int cmdline_parser2(int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required); + +/** + * The command line parser (version with additional parameters) + * @param argc the number of command line options + * @param argv the command line options + * @param args_info the structure where option information will be stored + * @param params additional parameters for the parser + * @return 0 if everything went fine, NON 0 if an error took place + */ + int cmdline_parser_ext(int argc, char **argv, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params); + +/** + * Save the contents of the option struct into an already open FILE stream. + * @param outfile the stream where to dump options + * @param args_info the option struct to dump + * @return 0 if everything went fine, NON 0 if an error took place + */ + int cmdline_parser_dump(FILE * outfile, + struct gengetopt_args_info *args_info); + +/** + * Save the contents of the option struct into a (text) file. + * This file can be read by the config file parser (if generated by gengetopt) + * @param filename the file where to save + * @param args_info the option struct to save + * @return 0 if everything went fine, NON 0 if an error took place + */ int cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info); +/** + * Print the help + */ void cmdline_parser_print_help(void); +/** + * Print the version + */ void cmdline_parser_print_version(void); +/** + * Initializes all the fields a cmdline_parser_params structure + * to their default values + * @param params the structure to initialize + */ + void cmdline_parser_params_init(struct cmdline_parser_params *params); + +/** + * Allocates dynamically a cmdline_parser_params structure and initializes + * all its fields to their default values + * @return the created and initialized cmdline_parser_params structure + */ + struct cmdline_parser_params *cmdline_parser_params_create(void); + +/** + * Initializes the passed gengetopt_args_info structure's fields + * (also set default values for options that have a default) + * @param args_info the structure to initialize + */ void cmdline_parser_init(struct gengetopt_args_info *args_info); +/** + * Deallocates the string fields of the gengetopt_args_info structure + * (but does not deallocate the structure itself) + * @param args_info the structure to deallocate + */ void cmdline_parser_free(struct gengetopt_args_info *args_info); - int cmdline_parser_configfile(char *const filename, +/** + * The config file parser (deprecated version) + * @param filename the name of the config file + * @param args_info the structure where option information will be stored + * @param override whether to override possibly already present options + * @param initialize whether to initialize the option structure my_args_info + * @param check_required whether to check that all required options were provided + * @return 0 if everything went fine, NON 0 if an error took place + * @deprecated use cmdline_parser_config_file() instead + */ + int cmdline_parser_configfile(const char *filename, struct gengetopt_args_info *args_info, int override, int initialize, int check_required); +/** + * The config file parser + * @param filename the name of the config file + * @param args_info the structure where option information will be stored + * @param params additional parameters for the parser + * @return 0 if everything went fine, NON 0 if an error took place + */ + int cmdline_parser_config_file(const char *filename, + struct gengetopt_args_info *args_info, + struct cmdline_parser_params *params); + +/** + * Checks that all the required options were specified + * @param args_info the structure to check + * @param prog_name the name of the program that will be used to print + * possible errors + * @return + */ int cmdline_parser_required(struct gengetopt_args_info *args_info, const char *prog_name); diff --git a/sgsnemu/sgsnemu.c b/sgsnemu/sgsnemu.c index 0157e22..2bfe801 100644 --- a/sgsnemu/sgsnemu.c +++ b/sgsnemu/sgsnemu.c @@ -565,9 +565,9 @@ int process_options(int argc, char **argv) /* rattype */ if (args_info.rattype_given == 1) { options.rattype_given = 1; - options.rattype.l = strlen(args_info.rattype_arg); - options.rattype.v[0] = atoi(args_info.rattype_arg); - printf("Using RAT Type: %s\n", args_info.rattype_arg); + options.rattype.l = 1; + options.rattype.v[0] = args_info.rattype_arg; + printf("Using RAT Type: %d\n", args_info.rattype_arg); } /* userloc */ |