do not use global variables app_name, options and option_help so they

can be static


git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@3188 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
ludovic.rousseau 2007-06-21 13:46:08 +00:00
parent b0bc6df80c
commit be309330e5
11 changed files with 30 additions and 32 deletions

View File

@ -353,7 +353,7 @@ int main(int argc, char *const argv[])
switch (c) { switch (c) {
case 'h': case 'h':
case '?': case '?':
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
case 'r': case 'r':
opt_reader = atoi(optarg); opt_reader = atoi(optarg);
break; break;

View File

@ -1099,7 +1099,7 @@ int main(int argc, char * const argv[])
if (c == -1) if (c == -1)
break; break;
if (c == '?') if (c == '?')
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
switch (c) { switch (c) {
case 'l': case 'l':
do_list_keys = 1; do_list_keys = 1;
@ -1161,7 +1161,7 @@ int main(int argc, char * const argv[])
} }
} }
if (action_count == 0) if (action_count == 0)
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
memset(&ctx_param, 0, sizeof(ctx_param)); memset(&ctx_param, 0, sizeof(ctx_param));
ctx_param.ver = 0; ctx_param.ver = 0;

View File

@ -1543,7 +1543,7 @@ int main(int argc, char * const argv[])
if (c == -1) if (c == -1)
break; break;
if (c == '?') if (c == '?')
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
switch (c) { switch (c) {
case 'r': case 'r':
opt_reader = atoi(optarg); opt_reader = atoi(optarg);

View File

@ -392,7 +392,7 @@ int main(int argc, char * const argv[])
if (c == -1) if (c == -1)
break; break;
if (c == '?') if (c == '?')
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
switch (c) { switch (c) {
case 'l': case 'l':
do_list_readers = 1; do_list_readers = 1;
@ -446,7 +446,7 @@ int main(int argc, char * const argv[])
} }
} }
if (action_count == 0) if (action_count == 0)
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
memset(&ctx_param, 0, sizeof(ctx_param)); memset(&ctx_param, 0, sizeof(ctx_param));
ctx_param.ver = 0; ctx_param.ver = 0;

View File

@ -378,7 +378,7 @@ int main(int argc, char * const argv[])
if (c == -1) if (c == -1)
break; break;
if (c == '?') if (c == '?')
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
switch (c) { switch (c) {
case OPT_SERIAL: case OPT_SERIAL:
do_print_serial = 1; do_print_serial = 1;
@ -439,7 +439,7 @@ int main(int argc, char * const argv[])
} }
} }
if (action_count == 0) if (action_count == 0)
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
CRYPTO_malloc_init(); CRYPTO_malloc_init();
ERR_load_crypto_strings(); ERR_load_crypto_strings();

View File

@ -337,7 +337,7 @@ int main(int argc, char * argv[])
new_object_id_len = sizeof(new_object_id); new_object_id_len = sizeof(new_object_id);
if (!hex_to_bin(optarg, new_object_id, &new_object_id_len)) { if (!hex_to_bin(optarg, new_object_id, &new_object_id_len)) {
printf("Invalid ID \"%s\"\n", optarg); printf("Invalid ID \"%s\"\n", optarg);
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
action_count++; action_count++;
break; break;
@ -356,14 +356,14 @@ int main(int argc, char * argv[])
opt_object_class = CKO_DATA; opt_object_class = CKO_DATA;
else { else {
printf("Unsupported object type \"%s\"\n", optarg); printf("Unsupported object type \"%s\"\n", optarg);
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
break; break;
case 'd': case 'd':
opt_object_id_len = sizeof(opt_object_id); opt_object_id_len = sizeof(opt_object_id);
if (!hex_to_bin(optarg, opt_object_id, &opt_object_id_len)) { if (!hex_to_bin(optarg, opt_object_id, &opt_object_id_len)) {
printf("Invalid ID \"%s\"\n", optarg); printf("Invalid ID \"%s\"\n", optarg);
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
break; break;
case 'a': case 'a':
@ -444,11 +444,11 @@ int main(int argc, char * argv[])
opt_is_private = 1; opt_is_private = 1;
break; break;
default: default:
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
} }
if (action_count == 0) if (action_count == 0)
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
/* ERR_load_crypto_strings(); */ /* ERR_load_crypto_strings(); */

View File

@ -493,7 +493,7 @@ int main(int argc, char * const argv[])
if (c == -1) if (c == -1)
break; break;
if (c == '?') if (c == '?')
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
switch (c) { switch (c) {
case 's': case 's':
do_sign++; do_sign++;
@ -552,7 +552,7 @@ int main(int argc, char * const argv[])
} }
} }
if (action_count == 0) if (action_count == 0)
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
memset(&ctx_param, 0, sizeof(ctx_param)); memset(&ctx_param, 0, sizeof(ctx_param));
ctx_param.ver = 0; ctx_param.ver = 0;

View File

@ -349,14 +349,14 @@ main(int argc, char **argv)
parse_commandline(argc, argv); parse_commandline(argc, argv);
if (optind != argc) if (optind != argc)
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
if (opt_actions == 0) { if (opt_actions == 0) {
fprintf(stderr, "No action specified.\n"); fprintf(stderr, "No action specified.\n");
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
if (!opt_profile) { if (!opt_profile) {
fprintf(stderr, "No profile specified.\n"); fprintf(stderr, "No profile specified.\n");
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
/* Connect to the card */ /* Connect to the card */
@ -2371,7 +2371,7 @@ handle_option(const struct option *opt)
opt_format = optarg; opt_format = optarg;
break; break;
case 'h': case 'h':
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
case 'i': case 'i':
opt_objectid = optarg; opt_objectid = optarg;
break; break;
@ -2457,7 +2457,7 @@ handle_option(const struct option *opt)
opt_cert_label = optarg; opt_cert_label = optarg;
break; break;
default: default:
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
if ((opt_actions & (1 << this_action)) && opt->has_arg != no_argument) { if ((opt_actions & (1 << this_action)) && opt->has_arg != no_argument) {
@ -2467,7 +2467,7 @@ handle_option(const struct option *opt)
if (isprint(opt->val)) if (isprint(opt->val))
fprintf(stderr, " -%c", opt->val); fprintf(stderr, " -%c", opt->val);
fprintf(stderr, " more than once.\n"); fprintf(stderr, " more than once.\n");
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
if (this_action) if (this_action)
opt_actions |= (1 << this_action); opt_actions |= (1 << this_action);
@ -2476,7 +2476,7 @@ handle_option(const struct option *opt)
fprintf(stderr, "Error: " fprintf(stderr, "Error: "
"The --no-so-pin option and --so-pin/--so-puk are mutually\n" "The --no-so-pin option and --so-pin/--so-puk are mutually\n"
"exclusive.\n"); "exclusive.\n");
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
} }
@ -2550,7 +2550,7 @@ read_options_file(const char *filename)
break; break;
if (!o->name) { if (!o->name) {
error("Unknown option \"%s\"\n", name); error("Unknown option \"%s\"\n", name);
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
if (o->has_arg != no_argument) { if (o->has_arg != no_argument) {
optarg = strtok(NULL, ""); optarg = strtok(NULL, "");
@ -2563,7 +2563,7 @@ read_options_file(const char *filename)
if (o->has_arg == required_argument if (o->has_arg == required_argument
&& (!optarg || !*optarg)) { && (!optarg || !*optarg)) {
error("Option %s: missing argument\n", name); error("Option %s: missing argument\n", name);
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
} }
handle_option(o); handle_option(o);
name = strtok(NULL, " \t"); name = strtok(NULL, " \t");

View File

@ -1201,7 +1201,7 @@ int main(int argc, char * const argv[])
if (c == -1) if (c == -1)
break; break;
if (c == '?') if (c == '?')
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
switch (c) { switch (c) {
case 'r': case 'r':
opt_cert = optarg; opt_cert = optarg;
@ -1291,7 +1291,7 @@ int main(int argc, char * const argv[])
} }
} }
if (action_count == 0) if (action_count == 0)
print_usage_and_die(); print_usage_and_die(app_name, options, option_help);
memset(&ctx_param, 0, sizeof(ctx_param)); memset(&ctx_param, 0, sizeof(ctx_param));
ctx_param.ver = 0; ctx_param.ver = 0;

View File

@ -148,7 +148,8 @@ void hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr)
} }
} }
void print_usage_and_die(void) void print_usage_and_die(const char *app_name, const struct option options[],
const char *option_help[])
{ {
int i = 0; int i = 0;
printf("Usage: %s [OPTIONS]\nOptions:\n", app_name); printf("Usage: %s [OPTIONS]\nOptions:\n", app_name);

View File

@ -23,14 +23,11 @@
extern "C" { extern "C" {
#endif #endif
extern const struct option options[];
extern const char *option_help[];
extern const char *app_name;
void print_binary(FILE *f, const u8 *buf, int count); void print_binary(FILE *f, const u8 *buf, int count);
void hex_dump(FILE *f, const u8 *in, int len, const char *sep); void hex_dump(FILE *f, const u8 *in, int len, const char *sep);
void hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr); void hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr);
void print_usage_and_die(void); void print_usage_and_die(const char *app_name, const struct option options[],
const char *option_help[]);
const char * acl_to_str(const struct sc_acl_entry *e); const char * acl_to_str(const struct sc_acl_entry *e);
void warn(const char *fmt, ...); void warn(const char *fmt, ...);
void error(const char *fmt, ...); void error(const char *fmt, ...);