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.";
30 const char *gengetopt_args_info_usage =
"Usage: " CMDLINE_PARSER_PACKAGE
" [OPTION]... [FILE]...";
32 const char *gengetopt_args_info_versiontext =
"";
34 const char *gengetopt_args_info_description =
"";
36 const char *gengetopt_args_info_help[] = {
37 " -h, --help Print help and exit",
38 " -V, --version Print version and exit",
39 " --fid=STRING FI identifier",
40 " --org=STRING FI org tag",
41 " --bank=STRING IBAN bank identifier",
42 " --broker=STRING Broker identifier",
43 " --user=STRING User name",
44 " --pass=STRING Password",
45 " --acct=STRING Account ID",
46 " --type=INT Account Type 1=checking 2=invest 3=ccard",
47 " --past=LONG How far back to look from today (in days)",
48 " --url=STRING Url to POST the data to (otherwise goes to stdout)",
49 " --trid=INT Transaction id",
51 " -s, --statement-req Request for a statement",
52 " -a, --accountinfo-req Request for a list of accounts",
53 " -p, --payment-req Request to make a payment",
54 " -i, --paymentinquiry-req Request to inquire about the status of a payment",
62 } cmdline_parser_arg_type;
75 gengetopt_strdup (
const char *s);
103 FIX_UNUSED (args_info);
131 args_info->
help_help = gengetopt_args_info_help[0] ;
133 args_info->
fid_help = gengetopt_args_info_help[2] ;
134 args_info->
org_help = gengetopt_args_info_help[3] ;
135 args_info->
bank_help = gengetopt_args_info_help[4] ;
136 args_info->
broker_help = gengetopt_args_info_help[5] ;
137 args_info->
user_help = gengetopt_args_info_help[6] ;
138 args_info->
pass_help = gengetopt_args_info_help[7] ;
139 args_info->
acct_help = gengetopt_args_info_help[8] ;
140 args_info->
type_help = gengetopt_args_info_help[9] ;
141 args_info->
past_help = gengetopt_args_info_help[10] ;
142 args_info->
url_help = gengetopt_args_info_help[11] ;
143 args_info->
trid_help = gengetopt_args_info_help[12] ;
152 cmdline_parser_print_version (
void)
155 (strlen(CMDLINE_PARSER_PACKAGE_NAME) ? CMDLINE_PARSER_PACKAGE_NAME : CMDLINE_PARSER_PACKAGE),
156 CMDLINE_PARSER_VERSION);
158 if (strlen(gengetopt_args_info_versiontext) > 0)
159 printf(
"\n%s\n", gengetopt_args_info_versiontext);
162 static void print_help_common(
void)
164 size_t len_purpose = strlen(gengetopt_args_info_purpose);
165 size_t len_usage = strlen(gengetopt_args_info_usage);
168 printf(
"%s\n", gengetopt_args_info_usage);
170 if (len_purpose > 0) {
171 printf(
"%s\n", gengetopt_args_info_purpose);
174 if (len_usage || len_purpose) {
178 if (strlen(gengetopt_args_info_description) > 0) {
179 printf(
"%s\n\n", gengetopt_args_info_description);
184 cmdline_parser_print_help (
void)
188 while (gengetopt_args_info_help[i])
189 printf(
"%s\n", gengetopt_args_info_help[i++]);
195 clear_given (args_info);
196 clear_args (args_info);
197 init_args_info (args_info);
217 cmdline_parser_params_create(
void)
221 cmdline_parser_params_init(params);
226 free_string_field (
char **s)
240 free_string_field (&(args_info->
fid_arg));
241 free_string_field (&(args_info->
fid_orig));
242 free_string_field (&(args_info->
org_arg));
243 free_string_field (&(args_info->
org_orig));
244 free_string_field (&(args_info->
bank_arg));
245 free_string_field (&(args_info->
bank_orig));
248 free_string_field (&(args_info->
user_arg));
249 free_string_field (&(args_info->
user_orig));
250 free_string_field (&(args_info->
pass_arg));
251 free_string_field (&(args_info->
pass_orig));
252 free_string_field (&(args_info->
acct_arg));
253 free_string_field (&(args_info->
acct_orig));
254 free_string_field (&(args_info->
type_orig));
255 free_string_field (&(args_info->
past_orig));
256 free_string_field (&(args_info->
url_arg));
257 free_string_field (&(args_info->
url_orig));
258 free_string_field (&(args_info->
trid_orig));
262 free (args_info->
inputs [i]);
267 clear_given (args_info);
272 write_into_file(FILE *outfile,
const char *opt,
const char *arg,
const char *values[])
276 fprintf(outfile,
"%s=\"%s\"\n", opt, arg);
278 fprintf(outfile,
"%s\n", opt);
290 fprintf (stderr,
"%s: cannot dump options to stream\n", CMDLINE_PARSER_PACKAGE);
295 write_into_file(outfile,
"help", 0, 0 );
297 write_into_file(outfile,
"version", 0, 0 );
299 write_into_file(outfile,
"fid", args_info->
fid_orig, 0);
301 write_into_file(outfile,
"org", args_info->
org_orig, 0);
303 write_into_file(outfile,
"bank", args_info->
bank_orig, 0);
305 write_into_file(outfile,
"broker", args_info->
broker_orig, 0);
307 write_into_file(outfile,
"user", args_info->
user_orig, 0);
309 write_into_file(outfile,
"pass", args_info->
pass_orig, 0);
311 write_into_file(outfile,
"acct", args_info->
acct_orig, 0);
313 write_into_file(outfile,
"type", args_info->
type_orig, 0);
315 write_into_file(outfile,
"past", args_info->
past_orig, 0);
317 write_into_file(outfile,
"url", args_info->
url_orig, 0);
319 write_into_file(outfile,
"trid", args_info->
trid_orig, 0);
321 write_into_file(outfile,
"statement-req", 0, 0 );
323 write_into_file(outfile,
"accountinfo-req", 0, 0 );
325 write_into_file(outfile,
"payment-req", 0, 0 );
327 write_into_file(outfile,
"paymentinquiry-req", 0, 0 );
340 outfile = fopen(filename,
"w");
344 fprintf (stderr,
"%s: cannot open file for writing: %s\n", CMDLINE_PARSER_PACKAGE, filename);
348 i = cmdline_parser_dump(outfile, args_info);
357 cmdline_parser_release (args_info);
362 gengetopt_strdup (
const char *s)
368 result = (
char*)malloc(strlen(s) + 1);
369 if (result == (
char*)0)
392 return cmdline_parser2 (argc, argv, args_info, 0, 1, 1);
400 result = cmdline_parser_internal (argc, argv, args_info, params, 0);
402 if (result == EXIT_FAILURE)
404 cmdline_parser_free (args_info);
423 result = cmdline_parser_internal (argc, argv, args_info, ¶ms, 0);
425 if (result == EXIT_FAILURE)
427 cmdline_parser_free (args_info);
437 FIX_UNUSED (args_info);
438 FIX_UNUSED (prog_name);
443 static char *package_name = 0;
464 int update_arg(
void *field,
char **orig_field,
465 unsigned int *field_given,
unsigned int *prev_given,
466 char *value,
const char *possible_values[],
467 const char *default_value,
468 cmdline_parser_arg_type arg_type,
470 int no_free,
int multiple_option,
471 const char *long_opt,
char short_opt,
472 const char *additional_error)
475 const char *val = value;
483 if (!multiple_option && prev_given && (*prev_given || (
check_ambiguity && *field_given)))
485 if (short_opt !=
'-')
486 fprintf (stderr,
"%s: `--%s' (`-%c') option given more than once%s\n",
487 package_name, long_opt, short_opt,
488 (additional_error ? additional_error :
""));
490 fprintf (stderr,
"%s: `--%s' option given more than once%s\n",
491 package_name, long_opt,
492 (additional_error ? additional_error :
""));
496 FIX_UNUSED (default_value);
498 if (field_given && *field_given && !
override)
505 val = possible_values[found];
509 if (val) *((
int *)field) = strtol (val, &stop_char, 0);
512 if (val) *((
long *)field) = (long)strtol (val, &stop_char, 0);
516 string_field = (
char **)field;
517 if (!no_free && *string_field)
518 free (*string_field);
519 *string_field = gengetopt_strdup (val);
530 if (val && !(stop_char && *stop_char ==
'\0')) {
531 fprintf(stderr,
"%s: invalid numeric value: %s\n", package_name, val);
544 if (value && orig_field) {
550 *orig_field = gengetopt_strdup (value);
560 cmdline_parser_internal (
566 int error_occurred = 0;
574 package_name = argv[0];
578 FIX_UNUSED(
override);
585 FIX_UNUSED(check_ambiguity);
588 cmdline_parser_init (args_info);
590 cmdline_parser_init (&local_args_info);
599 int option_index = 0;
601 static struct option long_options[] = {
602 {
"help", 0, NULL,
'h' },
603 {
"version", 0, NULL,
'V' },
604 {
"fid", 1, NULL, 0 },
605 {
"org", 1, NULL, 0 },
606 {
"bank", 1, NULL, 0 },
607 {
"broker", 1, NULL, 0 },
608 {
"user", 1, NULL, 0 },
609 {
"pass", 1, NULL, 0 },
610 {
"acct", 1, NULL, 0 },
611 {
"type", 1, NULL, 0 },
612 {
"past", 1, NULL, 0 },
613 {
"url", 1, NULL, 0 },
614 {
"trid", 1, NULL, 0 },
615 {
"statement-req", 0, NULL,
's' },
616 {
"accountinfo-req", 0, NULL,
'a' },
617 {
"payment-req", 0, NULL,
'p' },
618 {
"paymentinquiry-req", 0, NULL,
'i' },
622 c = getopt_long (argc, argv,
"hVsapi", long_options, &option_index);
629 cmdline_parser_print_help ();
630 cmdline_parser_free (&local_args_info);
634 cmdline_parser_print_version ();
635 cmdline_parser_free (&local_args_info);
641 reset_group_command (args_info);
646 &(local_args_info.statement_req_given), optarg, 0, 0, ARG_NO,
647 check_ambiguity,
override, 0, 0,
648 "statement-req",
's',
656 reset_group_command (args_info);
661 &(local_args_info.accountinfo_req_given), optarg, 0, 0, ARG_NO,
662 check_ambiguity,
override, 0, 0,
663 "accountinfo-req",
'a',
671 reset_group_command (args_info);
676 &(local_args_info.payment_req_given), optarg, 0, 0, ARG_NO,
677 check_ambiguity,
override, 0, 0,
686 reset_group_command (args_info);
691 &(local_args_info.paymentinquiry_req_given), optarg, 0, 0, ARG_NO,
692 check_ambiguity,
override, 0, 0,
693 "paymentinquiry-req",
'i',
701 if (strcmp (long_options[option_index].name,
"fid") == 0)
705 if (update_arg( (
void *)&(args_info->
fid_arg),
707 &(local_args_info.fid_given), optarg, 0, 0, ARG_STRING,
708 check_ambiguity,
override, 0, 0,
715 else if (strcmp (long_options[option_index].name,
"org") == 0)
719 if (update_arg( (
void *)&(args_info->
org_arg),
721 &(local_args_info.org_given), optarg, 0, 0, ARG_STRING,
722 check_ambiguity,
override, 0, 0,
729 else if (strcmp (long_options[option_index].name,
"bank") == 0)
733 if (update_arg( (
void *)&(args_info->
bank_arg),
735 &(local_args_info.bank_given), optarg, 0, 0, ARG_STRING,
736 check_ambiguity,
override, 0, 0,
743 else if (strcmp (long_options[option_index].name,
"broker") == 0)
747 if (update_arg( (
void *)&(args_info->
broker_arg),
749 &(local_args_info.broker_given), optarg, 0, 0, ARG_STRING,
750 check_ambiguity,
override, 0, 0,
757 else if (strcmp (long_options[option_index].name,
"user") == 0)
761 if (update_arg( (
void *)&(args_info->
user_arg),
763 &(local_args_info.user_given), optarg, 0, 0, ARG_STRING,
764 check_ambiguity,
override, 0, 0,
771 else if (strcmp (long_options[option_index].name,
"pass") == 0)
775 if (update_arg( (
void *)&(args_info->
pass_arg),
777 &(local_args_info.pass_given), optarg, 0, 0, ARG_STRING,
778 check_ambiguity,
override, 0, 0,
785 else if (strcmp (long_options[option_index].name,
"acct") == 0)
789 if (update_arg( (
void *)&(args_info->
acct_arg),
791 &(local_args_info.acct_given), optarg, 0, 0, ARG_STRING,
792 check_ambiguity,
override, 0, 0,
799 else if (strcmp (long_options[option_index].name,
"type") == 0)
803 if (update_arg( (
void *)&(args_info->
type_arg),
805 &(local_args_info.type_given), optarg, 0, 0, ARG_INT,
806 check_ambiguity,
override, 0, 0,
813 else if (strcmp (long_options[option_index].name,
"past") == 0)
817 if (update_arg( (
void *)&(args_info->
past_arg),
819 &(local_args_info.past_given), optarg, 0, 0, ARG_LONG,
820 check_ambiguity,
override, 0, 0,
827 else if (strcmp (long_options[option_index].name,
"url") == 0)
831 if (update_arg( (
void *)&(args_info->
url_arg),
833 &(local_args_info.url_given), optarg, 0, 0, ARG_STRING,
834 check_ambiguity,
override, 0, 0,
841 else if (strcmp (long_options[option_index].name,
"trid") == 0)
845 if (update_arg( (
void *)&(args_info->
trid_arg),
847 &(local_args_info.trid_given), optarg, 0, 0, ARG_INT,
848 check_ambiguity,
override, 0, 0,
861 fprintf (stderr,
"%s: option unknown: %c%s\n", CMDLINE_PARSER_PACKAGE, c, (additional_error ? additional_error :
""));
868 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 :
""));
874 FIX_UNUSED(check_required);
876 cmdline_parser_release (&local_args_info);
878 if ( error_occurred )
879 return (EXIT_FAILURE);
884 int found_prog_name = 0;
891 if (argv[i++] == argv[0]) {
897 args_info->
inputs_num = argc - optind - found_prog_name;
899 (
char **)(malloc ((args_info->
inputs_num)*
sizeof(
char *))) ;
900 while (optind < argc)
901 if (argv[optind++] != argv[0])
902 args_info->
inputs[ i++ ] = gengetopt_strdup (argv[optind-1]) ;
909 cmdline_parser_release (&local_args_info);
910 return (EXIT_FAILURE);
int override
whether to override possibly already present options (default 0)
char * past_orig
How far back to look from today (in days) original value given at command line.
unsigned int org_given
Whether org was given.
const char * accountinfo_req_help
Request for a list of accounts help description.
int initialize
whether to initialize the option structure gengetopt_args_info (default 1)
char * type_orig
Account Type 1=checking 2=invest 3=ccard original value given at command line.
char * url_orig
Url to POST the data to (otherwise goes to stdout) original value given at command line...
long past_arg
How far back to look from today (in days).
unsigned int payment_req_given
Whether payment-req was given.
unsigned int fid_given
Whether fid was given.
Where the command line options are stored.
unsigned int help_given
Whether help was given.
unsigned int type_given
Whether type was given.
char * fid_arg
FI identifier.
unsigned int bank_given
Whether bank was given.
const char * type_help
Account Type 1=checking 2=invest 3=ccard help description.
const char * pass_help
Password help description.
const char * user_help
User name help description.
The additional parameters to pass to parser functions.
char * url_arg
Url to POST the data to (otherwise goes to stdout).
const char * version_help
Print version and exit help description.
const char * acct_help
Account ID help description.
char * bank_orig
IBAN bank identifier original value given at command line.
unsigned int url_given
Whether url was given.
const char * fid_help
FI identifier help description.
const char * url_help
Url to POST the data to (otherwise goes to stdout) help description.
char * acct_orig
Account ID original value given at command line.
const char * bank_help
IBAN bank identifier help description.
const char * help_help
Print help and exit help description.
char * user_orig
User name original value given at command line.
char * acct_arg
Account ID.
const char * statement_req_help
Request for a statement help description.
char * user_arg
User name.
const char * payment_req_help
Request to make a payment help description.
unsigned int pass_given
Whether pass was given.
unsigned inputs_num
unnamed options number
int trid_arg
Transaction id.
const char * past_help
How far back to look from today (in days) help description.
unsigned int statement_req_given
Whether statement-req was given.
const char * paymentinquiry_req_help
Request to inquire about the status of a payment help description.
int print_errors
whether getopt_long should print an error message for a bad option (default 1)
unsigned int trid_given
Whether trid was given.
int check_ambiguity
whether to check for options already specified in the option structure gengetopt_args_info (default 0...
int check_required
whether to check that all required options were provided (default 1)
int command_group_counter
Counter for group command.
unsigned int past_given
Whether past was given.
unsigned int acct_given
Whether acct was given.
const char * trid_help
Transaction id help description.
char ** inputs
unnamed options (options without names)
const char * org_help
FI org tag help description.
char * org_orig
FI org tag original value given at command line.
char * fid_orig
FI identifier original value given at command line.
unsigned int user_given
Whether user was given.
unsigned int paymentinquiry_req_given
Whether paymentinquiry-req was given.
const char * broker_help
Broker identifier help description.
unsigned int accountinfo_req_given
Whether accountinfo-req was given.
char * pass_orig
Password original value given at command line.
char * trid_orig
Transaction id original value given at command line.
char * broker_orig
Broker identifier original value given at command line.
char * bank_arg
IBAN bank identifier.
unsigned int broker_given
Whether broker was given.
char * org_arg
FI org tag.
char * broker_arg
Broker identifier.
int type_arg
Account Type 1=checking 2=invest 3=ccard.
unsigned int version_given
Whether version was given.