tools: allow arguments to be printed in usage message
Extend util_print_usage_and_die() by a string argument that describes further arguments to the program. 1st user: opensc-explorer
This commit is contained in:
parent
61ca69c251
commit
367ebd94d4
|
@ -1090,7 +1090,7 @@ int main(int argc, char *const argv[])
|
|||
switch (c) {
|
||||
case 'h':
|
||||
printf("NB! This tool is only for Siemens CardOS based cards!\n\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
case 'i':
|
||||
do_info = 1;
|
||||
action_count++;
|
||||
|
|
|
@ -968,7 +968,7 @@ int main(int argc, char * const argv[])
|
|||
if (c == -1)
|
||||
break;
|
||||
if (c == '?')
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
switch (c) {
|
||||
case 'l':
|
||||
do_list_keys = 1;
|
||||
|
@ -1033,7 +1033,7 @@ int main(int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
if (action_count == 0)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
|
||||
memset(&ctx_param, 0, sizeof(ctx_param));
|
||||
ctx_param.ver = 0;
|
||||
|
|
|
@ -233,7 +233,7 @@ static int decode_options(int argc, char **argv)
|
|||
actions++;;
|
||||
break;
|
||||
case 'h':
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
break;
|
||||
case 'w':
|
||||
opt_wait = 1;
|
||||
|
@ -246,7 +246,7 @@ static int decode_options(int argc, char **argv)
|
|||
exit(EXIT_SUCCESS);
|
||||
break;
|
||||
default:
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -387,7 +387,7 @@ int main(int argc, char **argv)
|
|||
|
||||
/* fail on too many arguments */
|
||||
if (argind > argc)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
|
||||
/* set default action */
|
||||
if (!actions)
|
||||
|
|
|
@ -1684,7 +1684,7 @@ int main(int argc, char * const argv[])
|
|||
if (c == -1)
|
||||
break;
|
||||
if (c == '?')
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, "[SCRIPT]");
|
||||
switch (c) {
|
||||
case 'r':
|
||||
opt_reader = optarg;
|
||||
|
@ -1760,7 +1760,7 @@ int main(int argc, char * const argv[])
|
|||
|
||||
switch (argc - optind) {
|
||||
default:
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, "[SCRIPT]");
|
||||
break;
|
||||
case 0:
|
||||
script = stdin;
|
||||
|
@ -1770,7 +1770,7 @@ int main(int argc, char * const argv[])
|
|||
script = stdin;
|
||||
}
|
||||
else if ((script = fopen(argv[optind], "r")) == NULL) {
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, "[SCRIPT]");
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -666,7 +666,7 @@ int main(int argc, char * const argv[])
|
|||
if (c == -1)
|
||||
break;
|
||||
if (c == '?')
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
switch (c) {
|
||||
case 'i':
|
||||
do_info = 1;
|
||||
|
@ -734,7 +734,7 @@ int main(int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
if (action_count == 0)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
|
||||
if (do_info) {
|
||||
opensc_info();
|
||||
|
|
|
@ -439,7 +439,7 @@ int main(int argc, char * const argv[])
|
|||
if (c == -1)
|
||||
break;
|
||||
if (c == '?')
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
switch (c) {
|
||||
case OPT_SERIAL:
|
||||
do_print_serial = 1;
|
||||
|
@ -501,7 +501,7 @@ int main(int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
if (action_count == 0)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
|
||||
CRYPTO_malloc_init();
|
||||
ERR_load_crypto_strings();
|
||||
|
|
|
@ -418,7 +418,7 @@ int main(int argc, char * argv[])
|
|||
new_object_id_len = sizeof(new_object_id);
|
||||
if (!hex_to_bin(optarg, new_object_id, &new_object_id_len)) {
|
||||
printf("Invalid ID \"%s\"\n", optarg);
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
action_count++;
|
||||
break;
|
||||
|
@ -437,14 +437,14 @@ int main(int argc, char * argv[])
|
|||
opt_object_class = CKO_DATA;
|
||||
else {
|
||||
printf("Unsupported object type \"%s\"\n", optarg);
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
break;
|
||||
case 'd':
|
||||
opt_object_id_len = sizeof(opt_object_id);
|
||||
if (!hex_to_bin(optarg, opt_object_id, &opt_object_id_len)) {
|
||||
printf("Invalid ID \"%s\"\n", optarg);
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
break;
|
||||
case 'a':
|
||||
|
@ -504,14 +504,14 @@ int main(int argc, char * argv[])
|
|||
case OPT_SLOT_DESCRIPTION:
|
||||
if (opt_slot_set) {
|
||||
fprintf(stderr, "Error: Only one of --slot, --slot-label, --slot-index or --token-label can be used\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
opt_slot_description = optarg;
|
||||
break;
|
||||
case OPT_SLOT_INDEX:
|
||||
if (opt_slot_set || opt_slot_description) {
|
||||
fprintf(stderr, "Error: Only one of --slot, --slot-label, --slot-index or --token-label can be used\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
opt_slot_index = (CK_ULONG) strtoul(optarg, NULL, 0);
|
||||
opt_slot_index_set = 1;
|
||||
|
@ -519,7 +519,7 @@ int main(int argc, char * argv[])
|
|||
case OPT_TOKEN_LABEL:
|
||||
if (opt_slot_set || opt_slot_description || opt_slot_index_set) {
|
||||
fprintf(stderr, "Error: Only one of --slot, --slot-label, --slot-index or --token-label can be used\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
opt_token_label = optarg;
|
||||
break;
|
||||
|
@ -547,7 +547,7 @@ int main(int argc, char * argv[])
|
|||
opt_login_type = CKU_CONTEXT_SPECIFIC;
|
||||
else {
|
||||
printf("Unsupported login type \"%s\"\n", optarg);
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
break;
|
||||
case OPT_SO_PIN:
|
||||
|
@ -577,15 +577,15 @@ int main(int argc, char * argv[])
|
|||
action_count++;
|
||||
break;
|
||||
default:
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (opt_module == NULL)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
|
||||
if (action_count == 0)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
|
||||
module = C_LoadModule(opt_module, &p11);
|
||||
if (module == NULL)
|
||||
|
@ -709,7 +709,7 @@ int main(int argc, char * argv[])
|
|||
if (opt_login_type != -1
|
||||
&& opt_login_type != CKU_CONTEXT_SPECIFIC) {
|
||||
printf("Invalid login type for 'Unlock User PIN' operation\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
|
||||
return unlock_pin(opt_slot, session, opt_login_type);
|
||||
|
@ -1483,7 +1483,7 @@ static int gen_keypair(CK_SESSION_HANDLE session,
|
|||
util_fatal("Allocation error", 0);
|
||||
if (!hex_to_bin(ec_curve_infos[ii].oid_encoded, ecparams, &ecparams_size)) {
|
||||
printf("Cannot convert \"%s\"\n", ec_curve_infos[ii].oid_encoded);
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
|
||||
FILL_ATTR(publicKeyTemplate[n_pubkey_attr], CKA_EC_PARAMS, ecparams, ecparams_size);
|
||||
|
|
|
@ -333,7 +333,7 @@ int main(int argc, char * const argv[])
|
|||
if (c == -1)
|
||||
break;
|
||||
if (c == '?')
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
switch (c) {
|
||||
case 's':
|
||||
do_sign++;
|
||||
|
@ -395,7 +395,7 @@ int main(int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
if (action_count == 0)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
|
||||
memset(&ctx_param, 0, sizeof(ctx_param));
|
||||
ctx_param.ver = 0;
|
||||
|
|
|
@ -420,14 +420,14 @@ main(int argc, char **argv)
|
|||
parse_commandline(argc, argv);
|
||||
|
||||
if (optind != argc)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
if (opt_actions == 0) {
|
||||
fprintf(stderr, "No action specified.\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
if (!opt_profile) {
|
||||
fprintf(stderr, "No profile specified.\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
|
||||
/* Connect to the card */
|
||||
|
@ -2476,7 +2476,7 @@ handle_option(const struct option *opt)
|
|||
opt_format = optarg;
|
||||
break;
|
||||
case 'h':
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
case 'i':
|
||||
opt_objectid = optarg;
|
||||
break;
|
||||
|
@ -2574,7 +2574,7 @@ handle_option(const struct option *opt)
|
|||
this_action = ACTION_SANITY_CHECK;
|
||||
break;
|
||||
default:
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
|
||||
if ((opt_actions & (1 << this_action)) && opt->has_arg != no_argument) {
|
||||
|
@ -2584,7 +2584,7 @@ handle_option(const struct option *opt)
|
|||
if (isprint(opt->val))
|
||||
fprintf(stderr, " -%c", opt->val);
|
||||
fprintf(stderr, " more than once.\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
if (this_action)
|
||||
opt_actions |= (1 << this_action);
|
||||
|
@ -2593,13 +2593,13 @@ handle_option(const struct option *opt)
|
|||
fprintf(stderr, "Error: "
|
||||
"The --no-so-pin option and --so-pin/--so-puk are mutually"
|
||||
"exclusive.\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
|
||||
if ((opt_actions & (1 << ACTION_ERASE)) &&
|
||||
(opt_actions != (1 << ACTION_ERASE))) {
|
||||
fprintf(stderr, "Error: erasing a card is incompatible with all other actions\n");
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2673,7 +2673,7 @@ read_options_file(const char *filename)
|
|||
break;
|
||||
if (!o->name) {
|
||||
util_error("Unknown option \"%s\"\n", name);
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
if (o->has_arg != no_argument) {
|
||||
optarg = strtok(NULL, "");
|
||||
|
@ -2686,7 +2686,7 @@ read_options_file(const char *filename)
|
|||
if (o->has_arg == required_argument
|
||||
&& (!optarg || !*optarg)) {
|
||||
util_error("Option %s: missing argument\n", name);
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
}
|
||||
handle_option(o);
|
||||
name = strtok(NULL, " \t");
|
||||
|
|
|
@ -1679,7 +1679,7 @@ int main(int argc, char * const argv[])
|
|||
if (c == -1)
|
||||
break;
|
||||
if (c == '?')
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
switch (c) {
|
||||
case 'r':
|
||||
opt_cert = optarg;
|
||||
|
@ -1787,7 +1787,7 @@ int main(int argc, char * const argv[])
|
|||
}
|
||||
}
|
||||
if (action_count == 0)
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
|
||||
memset(&ctx_param, 0, sizeof(ctx_param));
|
||||
ctx_param.ver = 0;
|
||||
|
|
|
@ -197,10 +197,14 @@ void util_hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr)
|
|||
}
|
||||
|
||||
void util_print_usage_and_die(const char *app_name, const struct option options[],
|
||||
const char *option_help[])
|
||||
const char *option_help[], const char *args)
|
||||
{
|
||||
int i = 0;
|
||||
printf("Usage: %s [OPTIONS]\nOptions:\n", app_name);
|
||||
|
||||
if (args)
|
||||
printf("Usage: %s [OPTIONS] %s\nOptions:\n", app_name, args);
|
||||
else
|
||||
printf("Usage: %s [OPTIONS]\nOptions:\n", app_name);
|
||||
|
||||
while (options[i].name) {
|
||||
char buf[40], tmp[5];
|
||||
|
|
|
@ -27,7 +27,7 @@ void util_print_binary(FILE *f, const u8 *buf, int count);
|
|||
void util_hex_dump(FILE *f, const u8 *in, int len, const char *sep);
|
||||
void util_hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr);
|
||||
void util_print_usage_and_die(const char *app_name, const struct option options[],
|
||||
const char *option_help[]);
|
||||
const char *option_help[], const char *args);
|
||||
const char * util_acl_to_str(const struct sc_acl_entry *e);
|
||||
void util_warn(const char *fmt, ...);
|
||||
void util_error(const char *fmt, ...);
|
||||
|
|
|
@ -378,7 +378,7 @@ int main(int argc, char *argv[])
|
|||
if (c == -1)
|
||||
break;
|
||||
if (c == '?' || c == 'h')
|
||||
util_print_usage_and_die(app_name, options, option_help);
|
||||
util_print_usage_and_die(app_name, options, option_help, NULL);
|
||||
switch (c)
|
||||
{
|
||||
case 'r':
|
||||
|
|
Loading…
Reference in New Issue