21 #define FIX_UNUSED(X) (void) (X)  
   28 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.";
 
   32 const char *gengetopt_args_info_versiontext = 
"";
 
   37   "  -h, --help                Print help and exit",
 
   38   "  -V, --version             Print version and exit",
 
   39   "      --fipid=STRING        FI partner identifier (looks up fid, org & url from\n                              partner server)",
 
   40   "      --fid=STRING          FI identifier",
 
   41   "      --org=STRING          FI org tag",
 
   42   "      --bank=STRING         IBAN bank identifier",
 
   43   "      --broker=STRING       Broker identifier",
 
   44   "      --user=STRING         User name",
 
   45   "      --pass=STRING         Password",
 
   46   "      --acct=STRING         Account ID",
 
   47   "      --type=INT            Account Type 1=checking 2=invest 3=ccard",
 
   48   "      --past=LONG           How far back to look from today (in days)",
 
   49   "      --url=STRING          Url to POST the data to (otherwise goes to stdout)",
 
   50   "      --trid=INT            Transaction id",
 
   52   "  -s, --statement-req       Request for a statement",
 
   53   "  -a, --accountinfo-req     Request for a list of accounts",
 
   54   "  -p, --payment-req         Request to make a payment",
 
   55   "  -i, --paymentinquiry-req  Request to inquire about the status of a payment",
 
   56   "  -b, --bank-list           List all known banks",
 
   57   "  -f, --bank-fipid          List all fipids for a given bank",
 
   58   "  -v, --bank-services       List supported services for a given fipid",
 
   59   "      --allsupport          List all banks which support online banking",
 
   67 } cmdline_parser_arg_type;
 
   80 gengetopt_strdup (
const char *s);
 
  113   FIX_UNUSED (args_info);
 
  175   if (strlen(gengetopt_args_info_versiontext) > 0)
 
  176     printf(
"\n%s\n", gengetopt_args_info_versiontext);
 
  179 static void print_help_common(
void)
 
  187         if (len_purpose > 0) {
 
  191         if (len_usage || len_purpose) {
 
  212   clear_given (args_info);
 
  213   clear_args (args_info);
 
  214   init_args_info (args_info);
 
  243 free_string_field (
char **s)
 
  257   free_string_field (&(args_info->
fipid_arg));
 
  259   free_string_field (&(args_info->
fid_arg));
 
  260   free_string_field (&(args_info->
fid_orig));
 
  261   free_string_field (&(args_info->
org_arg));
 
  262   free_string_field (&(args_info->
org_orig));
 
  263   free_string_field (&(args_info->
bank_arg));
 
  264   free_string_field (&(args_info->
bank_orig));
 
  267   free_string_field (&(args_info->
user_arg));
 
  268   free_string_field (&(args_info->
user_orig));
 
  269   free_string_field (&(args_info->
pass_arg));
 
  270   free_string_field (&(args_info->
pass_orig));
 
  271   free_string_field (&(args_info->
acct_arg));
 
  272   free_string_field (&(args_info->
acct_orig));
 
  273   free_string_field (&(args_info->
type_orig));
 
  274   free_string_field (&(args_info->
past_orig));
 
  275   free_string_field (&(args_info->
url_arg));
 
  276   free_string_field (&(args_info->
url_orig));
 
  277   free_string_field (&(args_info->
trid_orig));
 
  281     free (args_info->
inputs [i]);
 
  286   clear_given (args_info);
 
  291 write_into_file(FILE *outfile, 
const char *opt, 
const char *arg, 
const char *values[])
 
  295     fprintf(outfile, 
"%s=\"%s\"\n", opt, arg);
 
  297     fprintf(outfile, 
"%s\n", opt);
 
  314     write_into_file(outfile, 
"help", 0, 0 );
 
  316     write_into_file(outfile, 
"version", 0, 0 );
 
  318     write_into_file(outfile, 
"fipid", args_info->
fipid_orig, 0);
 
  320     write_into_file(outfile, 
"fid", args_info->
fid_orig, 0);
 
  322     write_into_file(outfile, 
"org", args_info->
org_orig, 0);
 
  324     write_into_file(outfile, 
"bank", args_info->
bank_orig, 0);
 
  326     write_into_file(outfile, 
"broker", args_info->
broker_orig, 0);
 
  328     write_into_file(outfile, 
"user", args_info->
user_orig, 0);
 
  330     write_into_file(outfile, 
"pass", args_info->
pass_orig, 0);
 
  332     write_into_file(outfile, 
"acct", args_info->
acct_orig, 0);
 
  334     write_into_file(outfile, 
"type", args_info->
type_orig, 0);
 
  336     write_into_file(outfile, 
"past", args_info->
past_orig, 0);
 
  338     write_into_file(outfile, 
"url", args_info->
url_orig, 0);
 
  340     write_into_file(outfile, 
"trid", args_info->
trid_orig, 0);
 
  342     write_into_file(outfile, 
"statement-req", 0, 0 );
 
  344     write_into_file(outfile, 
"accountinfo-req", 0, 0 );
 
  346     write_into_file(outfile, 
"payment-req", 0, 0 );
 
  348     write_into_file(outfile, 
"paymentinquiry-req", 0, 0 );
 
  350     write_into_file(outfile, 
"bank-list", 0, 0 );
 
  352     write_into_file(outfile, 
"bank-fipid", 0, 0 );
 
  354     write_into_file(outfile, 
"bank-services", 0, 0 );
 
  356     write_into_file(outfile, 
"allsupport", 0, 0 );
 
  369   outfile = fopen(filename, 
"w");
 
  386   cmdline_parser_release (args_info);
 
  391 gengetopt_strdup (
const char *s)
 
  397   result = (
char*)malloc(strlen(s) + 1);
 
  398   if (result == (
char*)0)
 
  433   result = cmdline_parser_internal (argc, argv, args_info, params, 0);
 
  435   if (result == EXIT_FAILURE)
 
  456   result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
 
  458   if (result == EXIT_FAILURE)
 
  470   FIX_UNUSED (args_info);
 
  471   FIX_UNUSED (prog_name);
 
  476 static char *package_name = 0;
 
  497 int update_arg(
void *field, 
char **orig_field,
 
  498                unsigned int *field_given, 
unsigned int *prev_given, 
 
  499                char *value, 
const char *possible_values[],
 
  500                const char *default_value,
 
  501                cmdline_parser_arg_type arg_type,
 
  503                int no_free, 
int multiple_option,
 
  504                const char *long_opt, 
char short_opt,
 
  505                const char *additional_error)
 
  508   const char *val = value;
 
  516   if (!multiple_option && prev_given && (*prev_given || (
check_ambiguity && *field_given)))
 
  518       if (short_opt != 
'-')
 
  519         fprintf (stderr, 
"%s: `--%s' (`-%c') option given more than once%s\n", 
 
  520                package_name, long_opt, short_opt,
 
  521                (additional_error ? additional_error : 
""));
 
  523         fprintf (stderr, 
"%s: `--%s' option given more than once%s\n", 
 
  524                package_name, long_opt,
 
  525                (additional_error ? additional_error : 
""));
 
  529   FIX_UNUSED (default_value);
 
  531   if (field_given && *field_given && ! 
override)
 
  538     val = possible_values[found];
 
  542     if (val) *((
int *)field) = strtol (val, &stop_char, 0);
 
  545     if (val) *((
long *)field) = (long)strtol (val, &stop_char, 0);
 
  549       string_field = (
char **)field;
 
  550       if (!no_free && *string_field)
 
  551         free (*string_field); 
 
  552       *string_field = gengetopt_strdup (val);
 
  563     if (val && !(stop_char && *stop_char == 
'\0')) {
 
  564       fprintf(stderr, 
"%s: invalid numeric value: %s\n", package_name, val);
 
  577     if (value && orig_field) {
 
  583         *orig_field = gengetopt_strdup (value);
 
  593 cmdline_parser_internal (
 
  599   int error_occurred = 0;
 
  607   package_name = argv[0];
 
  611   FIX_UNUSED(
override);
 
  618   FIX_UNUSED(check_ambiguity);
 
  632       int option_index = 0;
 
  634       static struct option long_options[] = {
 
  635         { 
"help",       0, NULL, 
'h' },
 
  636         { 
"version",    0, NULL, 
'V' },
 
  637         { 
"fipid",      1, NULL, 0 },
 
  638         { 
"fid",        1, NULL, 0 },
 
  639         { 
"org",        1, NULL, 0 },
 
  640         { 
"bank",       1, NULL, 0 },
 
  641         { 
"broker",     1, NULL, 0 },
 
  642         { 
"user",       1, NULL, 0 },
 
  643         { 
"pass",       1, NULL, 0 },
 
  644         { 
"acct",       1, NULL, 0 },
 
  645         { 
"type",       1, NULL, 0 },
 
  646         { 
"past",       1, NULL, 0 },
 
  647         { 
"url",        1, NULL, 0 },
 
  648         { 
"trid",       1, NULL, 0 },
 
  649         { 
"statement-req",      0, NULL, 
's' },
 
  650         { 
"accountinfo-req",    0, NULL, 
'a' },
 
  651         { 
"payment-req",        0, NULL, 
'p' },
 
  652         { 
"paymentinquiry-req", 0, NULL, 
'i' },
 
  653         { 
"bank-list",  0, NULL, 
'b' },
 
  654         { 
"bank-fipid", 0, NULL, 
'f' },
 
  655         { 
"bank-services",      0, NULL, 
'v' },
 
  656         { 
"allsupport", 0, NULL, 0 },
 
  660       c = getopt_long (argc, argv, 
"hVsapibfv", long_options, &option_index);
 
  679             reset_group_command (args_info);
 
  684               &(local_args_info.statement_req_given), optarg, 0, 0, ARG_NO,
 
  685               check_ambiguity, 
override, 0, 0,
 
  686               "statement-req", 
's',
 
  694             reset_group_command (args_info);
 
  699               &(local_args_info.accountinfo_req_given), optarg, 0, 0, ARG_NO,
 
  700               check_ambiguity, 
override, 0, 0,
 
  701               "accountinfo-req", 
'a',
 
  709             reset_group_command (args_info);
 
  714               &(local_args_info.payment_req_given), optarg, 0, 0, ARG_NO,
 
  715               check_ambiguity, 
override, 0, 0,
 
  724             reset_group_command (args_info);
 
  729               &(local_args_info.paymentinquiry_req_given), optarg, 0, 0, ARG_NO,
 
  730               check_ambiguity, 
override, 0, 0,
 
  731               "paymentinquiry-req", 
'i',
 
  739             reset_group_command (args_info);
 
  744               &(local_args_info.bank_list_given), optarg, 0, 0, ARG_NO,
 
  745               check_ambiguity, 
override, 0, 0,
 
  754             reset_group_command (args_info);
 
  759               &(local_args_info.bank_fipid_given), optarg, 0, 0, ARG_NO,
 
  760               check_ambiguity, 
override, 0, 0,
 
  769             reset_group_command (args_info);
 
  774               &(local_args_info.bank_services_given), optarg, 0, 0, ARG_NO,
 
  775               check_ambiguity, 
override, 0, 0,
 
  776               "bank-services", 
'v',
 
  784           if (strcmp (long_options[option_index].name, 
"fipid") == 0)
 
  788             if (update_arg( (
void *)&(args_info->
fipid_arg), 
 
  790                 &(local_args_info.fipid_given), optarg, 0, 0, ARG_STRING,
 
  791                 check_ambiguity, 
override, 0, 0,
 
  798           else if (strcmp (long_options[option_index].name, 
"fid") == 0)
 
  802             if (update_arg( (
void *)&(args_info->
fid_arg), 
 
  804                 &(local_args_info.fid_given), optarg, 0, 0, ARG_STRING,
 
  805                 check_ambiguity, 
override, 0, 0,
 
  812           else if (strcmp (long_options[option_index].name, 
"org") == 0)
 
  816             if (update_arg( (
void *)&(args_info->
org_arg), 
 
  818                 &(local_args_info.org_given), optarg, 0, 0, ARG_STRING,
 
  819                 check_ambiguity, 
override, 0, 0,
 
  826           else if (strcmp (long_options[option_index].name, 
"bank") == 0)
 
  830             if (update_arg( (
void *)&(args_info->
bank_arg), 
 
  832                 &(local_args_info.bank_given), optarg, 0, 0, ARG_STRING,
 
  833                 check_ambiguity, 
override, 0, 0,
 
  840           else if (strcmp (long_options[option_index].name, 
"broker") == 0)
 
  844             if (update_arg( (
void *)&(args_info->
broker_arg), 
 
  846                 &(local_args_info.broker_given), optarg, 0, 0, ARG_STRING,
 
  847                 check_ambiguity, 
override, 0, 0,
 
  854           else if (strcmp (long_options[option_index].name, 
"user") == 0)
 
  858             if (update_arg( (
void *)&(args_info->
user_arg), 
 
  860                 &(local_args_info.user_given), optarg, 0, 0, ARG_STRING,
 
  861                 check_ambiguity, 
override, 0, 0,
 
  868           else if (strcmp (long_options[option_index].name, 
"pass") == 0)
 
  872             if (update_arg( (
void *)&(args_info->
pass_arg), 
 
  874                 &(local_args_info.pass_given), optarg, 0, 0, ARG_STRING,
 
  875                 check_ambiguity, 
override, 0, 0,
 
  882           else if (strcmp (long_options[option_index].name, 
"acct") == 0)
 
  886             if (update_arg( (
void *)&(args_info->
acct_arg), 
 
  888                 &(local_args_info.acct_given), optarg, 0, 0, ARG_STRING,
 
  889                 check_ambiguity, 
override, 0, 0,
 
  896           else if (strcmp (long_options[option_index].name, 
"type") == 0)
 
  900             if (update_arg( (
void *)&(args_info->
type_arg), 
 
  902                 &(local_args_info.type_given), optarg, 0, 0, ARG_INT,
 
  903                 check_ambiguity, 
override, 0, 0,
 
  910           else if (strcmp (long_options[option_index].name, 
"past") == 0)
 
  914             if (update_arg( (
void *)&(args_info->
past_arg), 
 
  916                 &(local_args_info.past_given), optarg, 0, 0, ARG_LONG,
 
  917                 check_ambiguity, 
override, 0, 0,
 
  924           else if (strcmp (long_options[option_index].name, 
"url") == 0)
 
  928             if (update_arg( (
void *)&(args_info->
url_arg), 
 
  930                 &(local_args_info.url_given), optarg, 0, 0, ARG_STRING,
 
  931                 check_ambiguity, 
override, 0, 0,
 
  938           else if (strcmp (long_options[option_index].name, 
"trid") == 0)
 
  942             if (update_arg( (
void *)&(args_info->
trid_arg), 
 
  944                 &(local_args_info.trid_given), optarg, 0, 0, ARG_INT,
 
  945                 check_ambiguity, 
override, 0, 0,
 
  952           else if (strcmp (long_options[option_index].name, 
"allsupport") == 0)
 
  956               reset_group_command (args_info);
 
  961                 &(local_args_info.allsupport_given), optarg, 0, 0, ARG_NO,
 
  962                 check_ambiguity, 
override, 0, 0,
 
  975           fprintf (stderr, 
"%s: option unknown: %c%s\n", 
CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error : 
""));
 
  982       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 : 
""));
 
  988         FIX_UNUSED(check_required);
 
  990   cmdline_parser_release (&local_args_info);
 
  992   if ( error_occurred )
 
  993     return (EXIT_FAILURE);
 
  998       int found_prog_name = 0;
 
 1005         if (argv[i++] == argv[0]) {
 
 1006           found_prog_name = 1;
 
 1011       args_info->
inputs_num = argc - optind - found_prog_name;
 
 1013         (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
 
 1014       while (optind < argc)
 
 1015         if (argv[optind++] != argv[0])
 
 1016           args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
 
 1023   cmdline_parser_release (&local_args_info);
 
 1024   return (EXIT_FAILURE);