improved option parsing
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@78 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
37
ccid/usb.c
37
ccid/usb.c
@@ -1760,8 +1760,8 @@ void parse_error(const char *app_name, const char *optarg, int opt_ind)
|
|||||||
int
|
int
|
||||||
main (int argc, char **argv)
|
main (int argc, char **argv)
|
||||||
{
|
{
|
||||||
int fd, c, i;
|
int fd, c, i;
|
||||||
int long_optind = 0;
|
int oindex = 0;
|
||||||
|
|
||||||
/* random initial serial number */
|
/* random initial serial number */
|
||||||
srand ((int) time (0));
|
srand ((int) time (0));
|
||||||
@@ -1772,32 +1772,32 @@ main (int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
c = getopt_long(argc, argv, "hnr:ls:i::u::a::z::p:e:vo", options, &long_optind);
|
c = getopt_long(argc, argv, "hnr:ls:i::u::a::z::p:e:vo", options, &oindex);
|
||||||
if (c == -1)
|
if (c == -1)
|
||||||
break;
|
break;
|
||||||
if (c == '?' || c == OPT_HELP) {
|
|
||||||
print_usage(argv[0] , options, option_help);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case OPT_HELP:
|
||||||
|
print_usage(argv[0] , options, option_help);
|
||||||
|
exit(0);
|
||||||
|
break;
|
||||||
case OPT_READER:
|
case OPT_READER:
|
||||||
if (sscanf(optarg, "%d", &usb_reader_num) != 1)
|
if (sscanf(optarg, "%d", &usb_reader_num) != 1)
|
||||||
parse_error(argv[0], optarg, long_optind);
|
parse_error(argv[0], optarg, oindex);
|
||||||
break;
|
break;
|
||||||
case OPT_LIST:
|
case OPT_LIST:
|
||||||
dolist++;
|
dolist++;
|
||||||
break;
|
break;
|
||||||
case OPT_SERIAL:
|
case OPT_SERIAL:
|
||||||
if (sscanf(optarg, "%56s", serial) != 1)
|
if (sscanf(optarg, "%56s", serial) != 1)
|
||||||
parse_error(argv[0], optarg, long_optind);
|
parse_error(argv[0], optarg, oindex);
|
||||||
break;
|
break;
|
||||||
case OPT_PRODUCT:
|
case OPT_PRODUCT:
|
||||||
if (sscanf(optarg, "%x", &productid) != 1)
|
if (sscanf(optarg, "%x", &productid) != 1)
|
||||||
parse_error(argv[0], optarg, long_optind);
|
parse_error(argv[0], optarg, oindex);
|
||||||
break;
|
break;
|
||||||
case OPT_VENDOR:
|
case OPT_VENDOR:
|
||||||
if (sscanf(optarg, "%x", &vendorid) != 1)
|
if (sscanf(optarg, "%x", &vendorid) != 1)
|
||||||
parse_error(argv[0], optarg, long_optind);
|
parse_error(argv[0], optarg, oindex);
|
||||||
break;
|
break;
|
||||||
case OPT_VERBOSE:
|
case OPT_VERBOSE:
|
||||||
verbose++;
|
verbose++;
|
||||||
@@ -1827,9 +1827,24 @@ main (int argc, char **argv)
|
|||||||
dopacetest = 1;
|
dopacetest = 1;
|
||||||
pin = optarg;
|
pin = optarg;
|
||||||
break;
|
break;
|
||||||
|
case '?':
|
||||||
|
/* fall through */
|
||||||
|
default:
|
||||||
|
exit(1);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (optind < argc) {
|
||||||
|
fprintf (stderr, "Unknown argument%s:", optind+1 == argc ? "" : "s");
|
||||||
|
while (optind < argc) {
|
||||||
|
fprintf(stderr, " \"%s\"", argv[optind++]);
|
||||||
|
fprintf(stderr, "%c", optind == argc ? '\n' : ',');
|
||||||
|
}
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (dolist)
|
if (dolist)
|
||||||
return ccid_list_readers(verbose);
|
return ccid_list_readers(verbose);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user