aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-12-05 01:43:07 -0500
committerB. Watson <urchlay@slackware.uk>2025-12-05 01:43:07 -0500
commit88bcda88e2b25d11cd7f81cc93a5ae2bd6d00d3e (patch)
treeb13d62ad1b3a08f76943a0f79658309f52be1d3f
parentd254450d9dcf29ee08df42e2594cb86abc1d54d3 (diff)
downloadalftools-88bcda88e2b25d11cd7f81cc93a5ae2bd6d00d3e.tar.gz
unalf: Error checking for -n option.
-rw-r--r--TODO.txt2
-rw-r--r--src/opts.c30
2 files changed, 29 insertions, 3 deletions
diff --git a/TODO.txt b/TODO.txt
index 5b0b9d9..48ec376 100644
--- a/TODO.txt
+++ b/TODO.txt
@@ -1,5 +1,3 @@
-- error checking for unalf -n (dup option, bad #, wildcards)
-
- maybe: alf foo.alf unix.filename=ATARI.NAM ...unalf could use this too.
- fuzz alf and unalf with afl++ or similar. this is a work in progress,
diff --git a/src/opts.c b/src/opts.c
index 06ad9dc..861ef2b 100644
--- a/src/opts.c
+++ b/src/opts.c
@@ -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);