version 1.17, 2011/10/07 20:07:25 |
version 1.18, 2013/01/04 19:31:28 |
|
|
usage(void) |
usage(void) |
{ |
{ |
fprintf(stderr, |
fprintf(stderr, |
"usage: units [-qv] [-f filename] [from-unit to-unit]\n"); |
"usage: units [-qv] [-f filename] [[count] from-unit to-unit]\n"); |
exit(3); |
exit(3); |
} |
} |
|
|
|
|
} |
} |
} |
} |
|
|
if (optind != argc - 2 && optind != argc) |
argc -= optind; |
|
argv += optind; |
|
|
|
if (argc != 3 && argc != 2 && argc != 0) |
usage(); |
usage(); |
|
|
readunits(userfile); |
readunits(userfile); |
|
|
if (optind == argc - 2) { |
if (argc == 3) { |
strlcpy(havestr, argv[optind], sizeof(havestr)); |
strlcpy(havestr, argv[0], sizeof(havestr)); |
strlcpy(wantstr, argv[optind + 1], sizeof(wantstr)); |
strlcat(havestr, " ", sizeof(havestr)); |
|
strlcat(havestr, argv[1], sizeof(havestr)); |
|
argc--; |
|
argv++; |
|
argv[0] = havestr; |
|
} |
|
|
|
if (argc == 2) { |
|
strlcpy(havestr, argv[0], sizeof(havestr)); |
|
strlcpy(wantstr, argv[1], sizeof(wantstr)); |
initializeunit(&have); |
initializeunit(&have); |
addunit(&have, havestr, 0); |
addunit(&have, havestr, 0); |
completereduce(&have); |
completereduce(&have); |