cmdline.c

    00001 /*
    00002   File autogenerated by gengetopt version 2.22.4
    00003   generated with the following command:
    00004   gengetopt --unamed-opts
    00005
    00006   The developers of gengetopt consider the fixed text that goes in all
    00007   gengetopt output files to be in the public domain:
    00008   we make no copyright claims on it.
    00009 */
    00010
    00011 /* If we use autoconf.  */
    00012 #ifdef HAVE_CONFIG_H
    00013 #include "config.h"
    00014 #endif
    00015
    00016 #include <stdio.h>
    00017 #include <stdlib.h>
    00018 #include <string.h>
    00019
    00020 #ifndef FIX_UNUSED
    00021 #define FIX_UNUSED(X) (void) (X) /* avoid warnings for unused params */
    00022 #endif
    00023
    00024 #include <getopt.h>
    00025
    00026 #include "cmdline.h"
    00027
    00028 const char *gengetopt_args_info_purpose = "prints to stdout the created OFX file based on the options you pass it. \ncurrently it will only create a statement request file.  you can POST this to \nan OFX server to request a statement from that financial institution for that \naccount.";
    00029
    00030 const char *gengetopt_args_info_usage = "Usage: " CMDLINE_PARSER_PACKAGE " [OPTIONS]... [FILES]...";
    00031
    00032 const char *gengetopt_args_info_description = "";
    00033
    00034 const char *gengetopt_args_info_help[] = {
    00035   "  -h, --help                Print help and exit",
    00036   "  -V, --version             Print version and exit",
    00037   "      --fipid=STRING        FI partner identifier (looks up fid, org & url from \n                              partner server)",
    00038   "      --fid=STRING          FI identifier",
    00039   "      --org=STRING          FI org tag",
    00040   "      --bank=STRING         IBAN bank identifier",
    00041   "      --broker=STRING       Broker identifier",
    00042   "      --user=STRING         User name",
    00043   "      --pass=STRING         Password",
    00044   "      --acct=STRING         Account ID",
    00045   "      --type=INT            Account Type 1=checking 2=invest 3=ccard",
    00046   "      --past=LONG           How far back to look from today (in days)",
    00047   "      --url=STRING          Url to POST the data to (otherwise goes to stdout)",
    00048   "      --trid=INT            Transaction id",
    00049   "\n Group: command",
    00050   "  -s, --statement-req       Request for a statement",
    00051   "  -a, --accountinfo-req     Request for a list of accounts",
    00052   "  -p, --payment-req         Request to make a payment",
    00053   "  -i, --paymentinquiry-req  Request to inquire about the status of a payment",
    00054   "  -b, --bank-list           List all known banks",
    00055   "  -f, --bank-fipid          List all fipids for a given bank",
    00056   "  -v, --bank-services       List supported services for a given fipid",
    00057   "      --allsupport          List all banks which support online banking",
    00058     0
    00059 };
    00060
    00061 typedef enum {ARG_NO
    00062   , ARG_STRING
    00063   , ARG_INT
    00064   , ARG_LONG
    00065 } cmdline_parser_arg_type;
    00066
    00067 static
    00068 void clear_given (struct gengetopt_args_info *args_info);
    00069 static
    00070 void clear_args (struct gengetopt_args_info *args_info);
    00071
    00072 static int
    00073 cmdline_parser_internal (int argc, char **argv, struct gengetopt_args_info *args_info,
    00074                         struct cmdline_parser_params *params, const char *additional_error);
    00075
    00076
    00077 static char *
    00078 gengetopt_strdup (const char *s);
    00079
    00080 static
    00081 void clear_given (struct gengetopt_args_info *args_info)
    00082 {
    00083   args_info->help_given = 0 ;
    00084   args_info->version_given = 0 ;
    00085   args_info->fipid_given = 0 ;
    00086   args_info->fid_given = 0 ;
    00087   args_info->org_given = 0 ;
    00088   args_info->bank_given = 0 ;
    00089   args_info->broker_given = 0 ;
    00090   args_info->user_given = 0 ;
    00091   args_info->pass_given = 0 ;
    00092   args_info->acct_given = 0 ;
    00093   args_info->type_given = 0 ;
    00094   args_info->past_given = 0 ;
    00095   args_info->url_given = 0 ;
    00096   args_info->trid_given = 0 ;
    00097   args_info->statement_req_given = 0 ;
    00098   args_info->accountinfo_req_given = 0 ;
    00099   args_info->payment_req_given = 0 ;
    00100   args_info->paymentinquiry_req_given = 0 ;
    00101   args_info->bank_list_given = 0 ;
    00102   args_info->bank_fipid_given = 0 ;
    00103   args_info->bank_services_given = 0 ;
    00104   args_info->allsupport_given = 0 ;
    00105   args_info->command_group_counter = 0 ;
    00106 }
    00107
    00108 static
    00109 void clear_args (struct gengetopt_args_info *args_info)
    00110 {
    00111   FIX_UNUSED (args_info);
    00112   args_info->fipid_arg = NULL;
    00113   args_info->fipid_orig = NULL;
    00114   args_info->fid_arg = NULL;
    00115   args_info->fid_orig = NULL;
    00116   args_info->org_arg = NULL;
    00117   args_info->org_orig = NULL;
    00118   args_info->bank_arg = NULL;
    00119   args_info->bank_orig = NULL;
    00120   args_info->broker_arg = NULL;
    00121   args_info->broker_orig = NULL;
    00122   args_info->user_arg = NULL;
    00123   args_info->user_orig = NULL;
    00124   args_info->pass_arg = NULL;
    00125   args_info->pass_orig = NULL;
    00126   args_info->acct_arg = NULL;
    00127   args_info->acct_orig = NULL;
    00128   args_info->type_orig = NULL;
    00129   args_info->past_orig = NULL;
    00130   args_info->url_arg = NULL;
    00131   args_info->url_orig = NULL;
    00132   args_info->trid_orig = NULL;
    00133
    00134 }
    00135
    00136 static
    00137 void init_args_info(struct gengetopt_args_info *args_info)
    00138 {
    00139
    00140
    00141   args_info->help_help = gengetopt_args_info_help[0] ;
    00142   args_info->version_help = gengetopt_args_info_help[1] ;
    00143   args_info->fipid_help = gengetopt_args_info_help[2] ;
    00144   args_info->fid_help = gengetopt_args_info_help[3] ;
    00145   args_info->org_help = gengetopt_args_info_help[4] ;
    00146   args_info->bank_help = gengetopt_args_info_help[5] ;
    00147   args_info->broker_help = gengetopt_args_info_help[6] ;
    00148   args_info->user_help = gengetopt_args_info_help[7] ;
    00149   args_info->pass_help = gengetopt_args_info_help[8] ;
    00150   args_info->acct_help = gengetopt_args_info_help[9] ;
    00151   args_info->type_help = gengetopt_args_info_help[10] ;
    00152   args_info->past_help = gengetopt_args_info_help[11] ;
    00153   args_info->url_help = gengetopt_args_info_help[12] ;
    00154   args_info->trid_help = gengetopt_args_info_help[13] ;
    00155   args_info->statement_req_help = gengetopt_args_info_help[15] ;
    00156   args_info->accountinfo_req_help = gengetopt_args_info_help[16] ;
    00157   args_info->payment_req_help = gengetopt_args_info_help[17] ;
    00158   args_info->paymentinquiry_req_help = gengetopt_args_info_help[18] ;
    00159   args_info->bank_list_help = gengetopt_args_info_help[19] ;
    00160   args_info->bank_fipid_help = gengetopt_args_info_help[20] ;
    00161   args_info->bank_services_help = gengetopt_args_info_help[21] ;
    00162   args_info->allsupport_help = gengetopt_args_info_help[22] ;
    00163
    00164 }
    00165
    00166 void
    00167 cmdline_parser_print_version (void)
    00168 {
    00169   printf ("%s %s\n",
    00170      (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
    00171      CMDLINE_PARSER_VERSION);
    00172 }
    00173
    00174 static void print_help_common(void) {
    00175   cmdline_parser_print_version ();
    00176
    00177   if (strlen(gengetopt_args_info_purpose) > 0)
    00178     printf("\n%s\n", gengetopt_args_info_purpose);
    00179
    00180   if (strlen(gengetopt_args_info_usage) > 0)
    00181     printf("\n%s\n", gengetopt_args_info_usage);
    00182
    00183   printf("\n");
    00184
    00185   if (strlen(gengetopt_args_info_description) > 0)
    00186     printf("%s\n\n", gengetopt_args_info_description);
    00187 }
    00188
    00189 void
    00190 cmdline_parser_print_help (void)
    00191 {
    00192   int i = 0;
    00193   print_help_common();
    00194   while (gengetopt_args_info_help[i])
    00195     printf("%s\n", gengetopt_args_info_help[i++]);
    00196 }
    00197
    00198 void
    00199 cmdline_parser_init (struct gengetopt_args_info *args_info)
    00200 {
    00201   clear_given (args_info);
    00202   clear_args (args_info);
    00203   init_args_info (args_info);
    00204
    00205   args_info->inputs = 0;
    00206   args_info->inputs_num = 0;
    00207 }
    00208
    00209 void
    00210 cmdline_parser_params_init(struct cmdline_parser_params *params)
    00211 {
    00212   if (params)
    00213     {
    00214       params->override = 0;
    00215       params->initialize = 1;
    00216       params->check_required = 1;
    00217       params->check_ambiguity = 0;
    00218       params->print_errors = 1;
    00219     }
    00220 }
    00221
    00222 struct cmdline_parser_params *
    00223 cmdline_parser_params_create(void)
    00224 {
    00225   struct cmdline_parser_params *params =
    00226     (struct cmdline_parser_params *)malloc(sizeof(struct cmdline_parser_params));
    00227   cmdline_parser_params_init(params);
    00228   return params;
    00229 }
    00230
    00231 static void
    00232 free_string_field (char **s)
    00233 {
    00234   if (*s)
    00235     {
    00236       free (*s);
    00237       *s = 0;
    00238     }
    00239 }
    00240
    00241
    00242 static void
    00243 cmdline_parser_release (struct gengetopt_args_info *args_info)
    00244 {
    00245   unsigned int i;
    00246   free_string_field (&(args_info->fipid_arg));
    00247   free_string_field (&(args_info->fipid_orig));
    00248   free_string_field (&(args_info->fid_arg));
    00249   free_string_field (&(args_info->fid_orig));
    00250   free_string_field (&(args_info->org_arg));
    00251   free_string_field (&(args_info->org_orig));
    00252   free_string_field (&(args_info->bank_arg));
    00253   free_string_field (&(args_info->bank_orig));
    00254   free_string_field (&(args_info->broker_arg));
    00255   free_string_field (&(args_info->broker_orig));
    00256   free_string_field (&(args_info->user_arg));
    00257   free_string_field (&(args_info->user_orig));
    00258   free_string_field (&(args_info->pass_arg));
    00259   free_string_field (&(args_info->pass_orig));
    00260   free_string_field (&(args_info->acct_arg));
    00261   free_string_field (&(args_info->acct_orig));
    00262   free_string_field (&(args_info->type_orig));
    00263   free_string_field (&(args_info->past_orig));
    00264   free_string_field (&(args_info->url_arg));
    00265   free_string_field (&(args_info->url_orig));
    00266   free_string_field (&(args_info->trid_orig));
    00267
    00268
    00269   for (i = 0; i < args_info->inputs_num; ++i)
    00270     free (args_info->inputs [i]);
    00271
    00272   if (args_info->inputs_num)
    00273     free (args_info->inputs);
    00274
    00275   clear_given (args_info);
    00276 }
    00277
    00278
    00279 static void
    00280 write_into_file(FILE *outfile, const char *opt, const char *arg, const char *values[])
    00281 {
    00282   FIX_UNUSED (values);
    00283   if (arg) {
    00284     fprintf(outfile, "%s=\"%s\"\n", opt, arg);
    00285   } else {
    00286     fprintf(outfile, "%s\n", opt);
    00287   }
    00288 }
    00289
    00290
    00291 int
    00292 cmdline_parser_dump(FILE *outfile, struct gengetopt_args_info *args_info)
    00293 {
    00294   int i = 0;
    00295
    00296   if (!outfile)
    00297     {
    00298       fprintf (stderr, "%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
    00299       return EXIT_FAILURE;
    00300     }
    00301
    00302   if (args_info->help_given)
    00303     write_into_file(outfile, "help", 0, 0 );
    00304   if (args_info->version_given)
    00305     write_into_file(outfile, "version", 0, 0 );
    00306   if (args_info->fipid_given)
    00307     write_into_file(outfile, "fipid", args_info->fipid_orig, 0);
    00308   if (args_info->fid_given)
    00309     write_into_file(outfile, "fid", args_info->fid_orig, 0);
    00310   if (args_info->org_given)
    00311     write_into_file(outfile, "org", args_info->org_orig, 0);
    00312   if (args_info->bank_given)
    00313     write_into_file(outfile, "bank", args_info->bank_orig, 0);
    00314   if (args_info->broker_given)
    00315     write_into_file(outfile, "broker", args_info->broker_orig, 0);
    00316   if (args_info->user_given)
    00317     write_into_file(outfile, "user", args_info->user_orig, 0);
    00318   if (args_info->pass_given)
    00319     write_into_file(outfile, "pass", args_info->pass_orig, 0);
    00320   if (args_info->acct_given)
    00321     write_into_file(outfile, "acct", args_info->acct_orig, 0);
    00322   if (args_info->type_given)
    00323     write_into_file(outfile, "type", args_info->type_orig, 0);
    00324   if (args_info->past_given)
    00325     write_into_file(outfile, "past", args_info->past_orig, 0);
    00326   if (args_info->url_given)
    00327     write_into_file(outfile, "url", args_info->url_orig, 0);
    00328   if (args_info->trid_given)
    00329     write_into_file(outfile, "trid", args_info->trid_orig, 0);
    00330   if (args_info->statement_req_given)
    00331     write_into_file(outfile, "statement-req", 0, 0 );
    00332   if (args_info->accountinfo_req_given)
    00333     write_into_file(outfile, "accountinfo-req", 0, 0 );
    00334   if (args_info->payment_req_given)
    00335     write_into_file(outfile, "payment-req", 0, 0 );
    00336   if (args_info->paymentinquiry_req_given)
    00337     write_into_file(outfile, "paymentinquiry-req", 0, 0 );
    00338   if (args_info->bank_list_given)
    00339     write_into_file(outfile, "bank-list", 0, 0 );
    00340   if (args_info->bank_fipid_given)
    00341     write_into_file(outfile, "bank-fipid", 0, 0 );
    00342   if (args_info->bank_services_given)
    00343     write_into_file(outfile, "bank-services", 0, 0 );
    00344   if (args_info->allsupport_given)
    00345     write_into_file(outfile, "allsupport", 0, 0 );
    00346
    00347
    00348   i = EXIT_SUCCESS;
    00349   return i;
    00350 }
    00351
    00352 int
    00353 cmdline_parser_file_save(const char *filename, struct gengetopt_args_info *args_info)
    00354 {
    00355   FILE *outfile;
    00356   int i = 0;
    00357
    00358   outfile = fopen(filename, "w");
    00359
    00360   if (!outfile)
    00361     {
    00362       fprintf (stderr, "%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
    00363       return EXIT_FAILURE;
    00364     }
    00365
    00366   i = cmdline_parser_dump(outfile, args_info);
    00367   fclose (outfile);
    00368
    00369   return i;
    00370 }
    00371
    00372 void
    00373 cmdline_parser_free (struct gengetopt_args_info *args_info)
    00374 {
    00375   cmdline_parser_release (args_info);
    00376 }
    00377
    00379 char *
    00380 gengetopt_strdup (const char *s)
    00381 {
    00382   char *result = 0;
    00383   if (!s)
    00384     return result;
    00385
    00386   result = (char*)malloc(strlen(s) + 1);
    00387   if (result == (char*)0)
    00388     return (char*)0;
    00389   strcpy(result, s);
    00390   return result;
    00391 }
    00392
    00393 static void
    00394 reset_group_command(struct gengetopt_args_info *args_info)
    00395 {
    00396   if (! args_info->command_group_counter)
    00397     return;
    00398
    00399   args_info->statement_req_given = 0 ;
    00400   args_info->accountinfo_req_given = 0 ;
    00401   args_info->payment_req_given = 0 ;
    00402   args_info->paymentinquiry_req_given = 0 ;
    00403   args_info->bank_list_given = 0 ;
    00404   args_info->bank_fipid_given = 0 ;
    00405   args_info->bank_services_given = 0 ;
    00406   args_info->allsupport_given = 0 ;
    00407
    00408   args_info->command_group_counter = 0;
    00409 }
    00410
    00411 int
    00412 cmdline_parser (int argc, char **argv, struct gengetopt_args_info *args_info)
    00413 {
    00414   return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
    00415 }
    00416
    00417 int
    00418 cmdline_parser_ext (int argc, char **argv, struct gengetopt_args_info *args_info,
    00419                    struct cmdline_parser_params *params)
    00420 {
    00421   int result;
    00422   result = cmdline_parser_internal (argc, argv, args_info, params, 0);
    00423
    00424   if (result == EXIT_FAILURE)
    00425     {
    00426       cmdline_parser_free (args_info);
    00427       exit (EXIT_FAILURE);
    00428     }
    00429
    00430   return result;
    00431 }
    00432
    00433 int
    00434 cmdline_parser2 (int argc, char **argv, struct gengetopt_args_info *args_info, int override, int initialize, int check_required)
    00435 {
    00436   int result;
    00437   struct cmdline_parser_params params;
    00438
    00439   params.override = override;
    00440   params.initialize = initialize;
    00441   params.check_required = check_required;
    00442   params.check_ambiguity = 0;
    00443   params.print_errors = 1;
    00444
    00445   result = cmdline_parser_internal (argc, argv, args_info, &params, 0);
    00446
    00447   if (result == EXIT_FAILURE)
    00448     {
    00449       cmdline_parser_free (args_info);
    00450       exit (EXIT_FAILURE);
    00451     }
    00452
    00453   return result;
    00454 }
    00455
    00456 int
    00457 cmdline_parser_required (struct gengetopt_args_info *args_info, const char *prog_name)
    00458 {
    00459   FIX_UNUSED (args_info);
    00460   FIX_UNUSED (prog_name);
    00461   return EXIT_SUCCESS;
    00462 }
    00463
    00464
    00465 static char *package_name = 0;
    00466
    00485 static
    00486 int update_arg(void *field, char **orig_field,
    00487                unsigned int *field_given, unsigned int *prev_given,
    00488                char *value, const char *possible_values[],
    00489                const char *default_value,
    00490                cmdline_parser_arg_type arg_type,
    00491                int check_ambiguity, int override,
    00492                int no_free, int multiple_option,
    00493                const char *long_opt, char short_opt,
    00494                const char *additional_error)
    00495 {
    00496   char *stop_char = 0;
    00497   const char *val = value;
    00498   int found;
    00499   char **string_field;
    00500   FIX_UNUSED (field);
    00501
    00502   stop_char = 0;
    00503   found = 0;
    00504
    00505   if (!multiple_option && prev_given && (*prev_given || (check_ambiguity && *field_given)))
    00506     {
    00507       if (short_opt != '-')
    00508         fprintf (stderr, "%s: `--%s' (`-%c') option given more than once%s\n",
    00509                package_name, long_opt, short_opt,
    00510                (additional_error ? additional_error : ""));
    00511       else
    00512         fprintf (stderr, "%s: `--%s' option given more than once%s\n",
    00513                package_name, long_opt,
    00514                (additional_error ? additional_error : ""));
    00515       return 1; /* failure */
    00516     }
    00517
    00518   FIX_UNUSED (default_value);
    00519
    00520   if (field_given && *field_given && ! override)
    00521     return 0;
    00522   if (prev_given)
    00523     (*prev_given)++;
    00524   if (field_given)
    00525     (*field_given)++;
    00526   if (possible_values)
    00527     val = possible_values[found];
    00528
    00529   switch(arg_type) {
    00530   case ARG_INT:
    00531     if (val) *((int *)field) = strtol (val, &stop_char, 0);
    00532     break;
    00533   case ARG_LONG:
    00534     if (val) *((long *)field) = (long)strtol (val, &stop_char, 0);
    00535     break;
    00536   case ARG_STRING:
    00537     if (val) {
    00538       string_field = (char **)field;
    00539       if (!no_free && *string_field)
    00540         free (*string_field); /* free previous string */
    00541       *string_field = gengetopt_strdup (val);
    00542     }
    00543     break;
    00544   default:
    00545     break;
    00546   };
    00547
    00548   /* check numeric conversion */
    00549   switch(arg_type) {
    00550   case ARG_INT:
    00551   case ARG_LONG:
    00552     if (val && !(stop_char && *stop_char == '\0')) {
    00553       fprintf(stderr, "%s: invalid numeric value: %s\n", package_name, val);
    00554       return 1; /* failure */
    00555     }
    00556     break;
    00557   default:
    00558     ;
    00559   };
    00560
    00561   /* store the original value */
    00562   switch(arg_type) {
    00563   case ARG_NO:
    00564     break;
    00565   default:
    00566     if (value && orig_field) {
    00567       if (no_free) {
    00568         *orig_field = value;
    00569       } else {
    00570         if (*orig_field)
    00571           free (*orig_field); /* free previous string */
    00572         *orig_field = gengetopt_strdup (value);
    00573       }
    00574     }
    00575   };
    00576
    00577   return 0; /* OK */
    00578 }
    00579
    00580
    00581 int
    00582 cmdline_parser_internal (
    00583   int argc, char **argv, struct gengetopt_args_info *args_info,
    00584                         struct cmdline_parser_params *params, const char *additional_error)
    00585 {
    00586   int c;        /* Character of the parsed option.  */
    00587
    00588   int error = 0;
    00589   struct gengetopt_args_info local_args_info;
    00590
    00591   int override;
    00592   int initialize;
    00593   int check_required;
    00594   int check_ambiguity;
    00595
    00596   package_name = argv[0];
    00597
    00598   override = params->override;
    00599   initialize = params->initialize;
    00600   check_required = params->check_required;
    00601   check_ambiguity = params->check_ambiguity;
    00602
    00603   if (initialize)
    00604     cmdline_parser_init (args_info);
    00605
    00606   cmdline_parser_init (&local_args_info);
    00607
    00608   optarg = 0;
    00609   optind = 0;
    00610   opterr = params->print_errors;
    00611   optopt = '?';
    00612
    00613   while (1)
    00614     {
    00615       int option_index = 0;
    00616
    00617       static struct option long_options[] = {
    00618         { "help",       0, NULL, 'h' },
    00619         { "version",    0, NULL, 'V' },
    00620         { "fipid",      1, NULL, 0 },
    00621         { "fid",        1, NULL, 0 },
    00622         { "org",        1, NULL, 0 },
    00623         { "bank",       1, NULL, 0 },
    00624         { "broker",     1, NULL, 0 },
    00625         { "user",       1, NULL, 0 },
    00626         { "pass",       1, NULL, 0 },
    00627         { "acct",       1, NULL, 0 },
    00628         { "type",       1, NULL, 0 },
    00629         { "past",       1, NULL, 0 },
    00630         { "url",        1, NULL, 0 },
    00631         { "trid",       1, NULL, 0 },
    00632         { "statement-req",      0, NULL, 's' },
    00633         { "accountinfo-req",    0, NULL, 'a' },
    00634         { "payment-req",        0, NULL, 'p' },
    00635         { "paymentinquiry-req", 0, NULL, 'i' },
    00636         { "bank-list",  0, NULL, 'b' },
    00637         { "bank-fipid", 0, NULL, 'f' },
    00638         { "bank-services",      0, NULL, 'v' },
    00639         { "allsupport", 0, NULL, 0 },
    00640         { 0,  0, 0, 0 }
    00641       };
    00642
    00643       c = getopt_long (argc, argv, "hVsapibfv", long_options, &option_index);
    00644
    00645       if (c == -1) break;       /* Exit from `while (1)' loop.  */
    00646
    00647       switch (c)
    00648         {
    00649         case 'h':       /* Print help and exit.  */
    00650           cmdline_parser_print_help ();
    00651           cmdline_parser_free (&local_args_info);
    00652           exit (EXIT_SUCCESS);
    00653
    00654         case 'V':       /* Print version and exit.  */
    00655           cmdline_parser_print_version ();
    00656           cmdline_parser_free (&local_args_info);
    00657           exit (EXIT_SUCCESS);
    00658
    00659         case 's':       /* Request for a statement.  */
    00660
    00661           if (args_info->command_group_counter && override)
    00662             reset_group_command (args_info);
    00663           args_info->command_group_counter += 1;
    00664
    00665           if (update_arg( 0 ,
    00666                0 , &(args_info->statement_req_given),
    00667               &(local_args_info.statement_req_given), optarg, 0, 0, ARG_NO,
    00668               check_ambiguity, override, 0, 0,
    00669               "statement-req", 's',
    00670               additional_error))
    00671             goto failure;
    00672
    00673           break;
    00674         case 'a':       /* Request for a list of accounts.  */
    00675
    00676           if (args_info->command_group_counter && override)
    00677             reset_group_command (args_info);
    00678           args_info->command_group_counter += 1;
    00679
    00680           if (update_arg( 0 ,
    00681                0 , &(args_info->accountinfo_req_given),
    00682               &(local_args_info.accountinfo_req_given), optarg, 0, 0, ARG_NO,
    00683               check_ambiguity, override, 0, 0,
    00684               "accountinfo-req", 'a',
    00685               additional_error))
    00686             goto failure;
    00687
    00688           break;
    00689         case 'p':       /* Request to make a payment.  */
    00690
    00691           if (args_info->command_group_counter && override)
    00692             reset_group_command (args_info);
    00693           args_info->command_group_counter += 1;
    00694
    00695           if (update_arg( 0 ,
    00696                0 , &(args_info->payment_req_given),
    00697               &(local_args_info.payment_req_given), optarg, 0, 0, ARG_NO,
    00698               check_ambiguity, override, 0, 0,
    00699               "payment-req", 'p',
    00700               additional_error))
    00701             goto failure;
    00702
    00703           break;
    00704         case 'i':       /* Request to inquire about the status of a payment.  */
    00705
    00706           if (args_info->command_group_counter && override)
    00707             reset_group_command (args_info);
    00708           args_info->command_group_counter += 1;
    00709
    00710           if (update_arg( 0 ,
    00711                0 , &(args_info->paymentinquiry_req_given),
    00712               &(local_args_info.paymentinquiry_req_given), optarg, 0, 0, ARG_NO,
    00713               check_ambiguity, override, 0, 0,
    00714               "paymentinquiry-req", 'i',
    00715               additional_error))
    00716             goto failure;
    00717
    00718           break;
    00719         case 'b':       /* List all known banks.  */
    00720
    00721           if (args_info->command_group_counter && override)
    00722             reset_group_command (args_info);
    00723           args_info->command_group_counter += 1;
    00724
    00725           if (update_arg( 0 ,
    00726                0 , &(args_info->bank_list_given),
    00727               &(local_args_info.bank_list_given), optarg, 0, 0, ARG_NO,
    00728               check_ambiguity, override, 0, 0,
    00729               "bank-list", 'b',
    00730               additional_error))
    00731             goto failure;
    00732
    00733           break;
    00734         case 'f':       /* List all fipids for a given bank.  */
    00735
    00736           if (args_info->command_group_counter && override)
    00737             reset_group_command (args_info);
    00738           args_info->command_group_counter += 1;
    00739
    00740           if (update_arg( 0 ,
    00741                0 , &(args_info->bank_fipid_given),
    00742               &(local_args_info.bank_fipid_given), optarg, 0, 0, ARG_NO,
    00743               check_ambiguity, override, 0, 0,
    00744               "bank-fipid", 'f',
    00745               additional_error))
    00746             goto failure;
    00747
    00748           break;
    00749         case 'v':       /* List supported services for a given fipid.  */
    00750
    00751           if (args_info->command_group_counter && override)
    00752             reset_group_command (args_info);
    00753           args_info->command_group_counter += 1;
    00754
    00755           if (update_arg( 0 ,
    00756                0 , &(args_info->bank_services_given),
    00757               &(local_args_info.bank_services_given), optarg, 0, 0, ARG_NO,
    00758               check_ambiguity, override, 0, 0,
    00759               "bank-services", 'v',
    00760               additional_error))
    00761             goto failure;
    00762
    00763           break;
    00764
    00765         case 0: /* Long option with no short option */
    00766           /* FI partner identifier (looks up fid, org & url from partner server).  */
    00767           if (strcmp (long_options[option_index].name, "fipid") == 0)
    00768           {
    00769
    00770
    00771             if (update_arg( (void *)&(args_info->fipid_arg),
    00772                  &(args_info->fipid_orig), &(args_info->fipid_given),
    00773                 &(local_args_info.fipid_given), optarg, 0, 0, ARG_STRING,
    00774                 check_ambiguity, override, 0, 0,
    00775                 "fipid", '-',
    00776                 additional_error))
    00777               goto failure;
    00778
    00779           }
    00780           /* FI identifier.  */
    00781           else if (strcmp (long_options[option_index].name, "fid") == 0)
    00782           {
    00783
    00784
    00785             if (update_arg( (void *)&(args_info->fid_arg),
    00786                  &(args_info->fid_orig), &(args_info->fid_given),
    00787                 &(local_args_info.fid_given), optarg, 0, 0, ARG_STRING,
    00788                 check_ambiguity, override, 0, 0,
    00789                 "fid", '-',
    00790                 additional_error))
    00791               goto failure;
    00792
    00793           }
    00794           /* FI org tag.  */
    00795           else if (strcmp (long_options[option_index].name, "org") == 0)
    00796           {
    00797
    00798
    00799             if (update_arg( (void *)&(args_info->org_arg),
    00800                  &(args_info->org_orig), &(args_info->org_given),
    00801                 &(local_args_info.org_given), optarg, 0, 0, ARG_STRING,
    00802                 check_ambiguity, override, 0, 0,
    00803                 "org", '-',
    00804                 additional_error))
    00805               goto failure;
    00806
    00807           }
    00808           /* IBAN bank identifier.  */
    00809           else if (strcmp (long_options[option_index].name, "bank") == 0)
    00810           {
    00811
    00812
    00813             if (update_arg( (void *)&(args_info->bank_arg),
    00814                  &(args_info->bank_orig), &(args_info->bank_given),
    00815                 &(local_args_info.bank_given), optarg, 0, 0, ARG_STRING,
    00816                 check_ambiguity, override, 0, 0,
    00817                 "bank", '-',
    00818                 additional_error))
    00819               goto failure;
    00820
    00821           }
    00822           /* Broker identifier.  */
    00823           else if (strcmp (long_options[option_index].name, "broker") == 0)
    00824           {
    00825
    00826
    00827             if (update_arg( (void *)&(args_info->broker_arg),
    00828                  &(args_info->broker_orig), &(args_info->broker_given),
    00829                 &(local_args_info.broker_given), optarg, 0, 0, ARG_STRING,
    00830                 check_ambiguity, override, 0, 0,
    00831                 "broker", '-',
    00832                 additional_error))
    00833               goto failure;
    00834
    00835           }
    00836           /* User name.  */
    00837           else if (strcmp (long_options[option_index].name, "user") == 0)
    00838           {
    00839
    00840
    00841             if (update_arg( (void *)&(args_info->user_arg),
    00842                  &(args_info->user_orig), &(args_info->user_given),
    00843                 &(local_args_info.user_given), optarg, 0, 0, ARG_STRING,
    00844                 check_ambiguity, override, 0, 0,
    00845                 "user", '-',
    00846                 additional_error))
    00847               goto failure;
    00848
    00849           }
    00850           /* Password.  */
    00851           else if (strcmp (long_options[option_index].name, "pass") == 0)
    00852           {
    00853
    00854
    00855             if (update_arg( (void *)&(args_info->pass_arg),
    00856                  &(args_info->pass_orig), &(args_info->pass_given),
    00857                 &(local_args_info.pass_given), optarg, 0, 0, ARG_STRING,
    00858                 check_ambiguity, override, 0, 0,
    00859                 "pass", '-',
    00860                 additional_error))
    00861               goto failure;
    00862
    00863           }
    00864           /* Account ID.  */
    00865           else if (strcmp (long_options[option_index].name, "acct") == 0)
    00866           {
    00867
    00868
    00869             if (update_arg( (void *)&(args_info->acct_arg),
    00870                  &(args_info->acct_orig), &(args_info->acct_given),
    00871                 &(local_args_info.acct_given), optarg, 0, 0, ARG_STRING,
    00872                 check_ambiguity, override, 0, 0,
    00873                 "acct", '-',
    00874                 additional_error))
    00875               goto failure;
    00876
    00877           }
    00878           /* Account Type 1=checking 2=invest 3=ccard.  */
    00879           else if (strcmp (long_options[option_index].name, "type") == 0)
    00880           {
    00881
    00882
    00883             if (update_arg( (void *)&(args_info->type_arg),
    00884                  &(args_info->type_orig), &(args_info->type_given),
    00885                 &(local_args_info.type_given), optarg, 0, 0, ARG_INT,
    00886                 check_ambiguity, override, 0, 0,
    00887                 "type", '-',
    00888                 additional_error))
    00889               goto failure;
    00890
    00891           }
    00892           /* How far back to look from today (in days).  */
    00893           else if (strcmp (long_options[option_index].name, "past") == 0)
    00894           {
    00895
    00896
    00897             if (update_arg( (void *)&(args_info->past_arg),
    00898                  &(args_info->past_orig), &(args_info->past_given),
    00899                 &(local_args_info.past_given), optarg, 0, 0, ARG_LONG,
    00900                 check_ambiguity, override, 0, 0,
    00901                 "past", '-',
    00902                 additional_error))
    00903               goto failure;
    00904
    00905           }
    00906           /* Url to POST the data to (otherwise goes to stdout).  */
    00907           else if (strcmp (long_options[option_index].name, "url") == 0)
    00908           {
    00909
    00910
    00911             if (update_arg( (void *)&(args_info->url_arg),
    00912                  &(args_info->url_orig), &(args_info->url_given),
    00913                 &(local_args_info.url_given), optarg, 0, 0, ARG_STRING,
    00914                 check_ambiguity, override, 0, 0,
    00915                 "url", '-',
    00916                 additional_error))
    00917               goto failure;
    00918
    00919           }
    00920           /* Transaction id.  */
    00921           else if (strcmp (long_options[option_index].name, "trid") == 0)
    00922           {
    00923
    00924
    00925             if (update_arg( (void *)&(args_info->trid_arg),
    00926                  &(args_info->trid_orig), &(args_info->trid_given),
    00927                 &(local_args_info.trid_given), optarg, 0, 0, ARG_INT,
    00928                 check_ambiguity, override, 0, 0,
    00929                 "trid", '-',
    00930                 additional_error))
    00931               goto failure;
    00932
    00933           }
    00934           /* List all banks which support online banking.  */
    00935           else if (strcmp (long_options[option_index].name, "allsupport") == 0)
    00936           {
    00937
    00938             if (args_info->command_group_counter && override)
    00939               reset_group_command (args_info);
    00940             args_info->command_group_counter += 1;
    00941
    00942             if (update_arg( 0 ,
    00943                  0 , &(args_info->allsupport_given),
    00944                 &(local_args_info.allsupport_given), optarg, 0, 0, ARG_NO,
    00945                 check_ambiguity, override, 0, 0,
    00946                 "allsupport", '-',
    00947                 additional_error))
    00948               goto failure;
    00949
    00950           }
    00951
    00952           break;
    00953         case '?':       /* Invalid option.  */
    00954           /* `getopt_long' already printed an error message.  */
    00955           goto failure;
    00956
    00957         default:        /* bug: option not considered.  */
    00958           fprintf (stderr, "%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : ""));
    00959           abort ();
    00960         } /* switch */
    00961     } /* while */
    00962
    00963   if (args_info->command_group_counter > 1)
    00964     {
    00965       fprintf (stderr, "%s: %d options of group command were given. At most one is required%s.\n", argv[0], args_info->command_group_counter, (additional_error ? additional_error : ""));
    00966       error = 1;
    00967     }
    00968
    00969
    00970
    00971
    00972   cmdline_parser_release (&local_args_info);
    00973
    00974   if ( error )
    00975     return (EXIT_FAILURE);
    00976
    00977   if (optind < argc)
    00978     {
    00979       int i = 0 ;
    00980       int found_prog_name = 0;
    00981       /* whether program name, i.e., argv[0], is in the remaining args
    00982          (this may happen with some implementations of getopt,
    00983           but surely not with the one included by gengetopt) */
    00984
    00985       i = optind;
    00986       while (i < argc)
    00987         if (argv[i++] == argv[0]) {
    00988           found_prog_name = 1;
    00989           break;
    00990         }
    00991       i = 0;
    00992
    00993       args_info->inputs_num = argc - optind - found_prog_name;
    00994       args_info->inputs =
    00995         (char **)(malloc ((args_info->inputs_num)*sizeof(char *))) ;
    00996       while (optind < argc)
    00997         if (argv[optind++] != argv[0])
    00998           args_info->inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
    00999     }
    01000
    01001   return 0;
    01002
    01003 failure:
    01004
    01005   cmdline_parser_release (&local_args_info);
    01006   return (EXIT_FAILURE);
    01007 }