diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/opts.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -26,7 +26,30 @@ static void show_globs(void) { #endif int parsenum(const char opt, const char *arg) { - return atoi(arg); /* TODO: use strtol(), die on error */ + const char *p = arg; + int result, err = 0; + + if(opts.extract_num) { + fprintf(stderr, "%s: fatal: can't use multiple -%c arguments (try --help).\n", self, opt); + exit(1); + } + + for(p = arg; *p && (*p >= '0' && *p <= '9'); p++) + ; + + if(*p || p == arg) { + err++; + } else { + result = atoi(arg); + if(!result) err++; + } + + if(err) { + fprintf(stderr, "%s: fatal: invalid number '%s' for -%c option (try --help).\n", self, arg, opt); + exit(1); + } + + return result; } void parse_opts(int argc, char * const *argv) { @@ -72,6 +95,11 @@ void parse_opts(int argc, char * const *argv) { include_globs = &argv[optind + 1]; /* might be null, that's OK */ ig = (char **)include_globs; + if(opts.extract_num && *ig) { + fprintf(stderr, "%s: fatal: can't use wildcards with -n (try -h or --help)\n.", self); + exit(1); + } + while(*ig) { if(globmatch("*.alf", *ig)) { fprintf(stderr, "%s: ALF files don't normally contain other ALF files, are you trying to extract/list multiple ALF files at once?\n", self); |
