diff options
author | B. Watson <urchlay@slackware.uk> | 2025-03-12 00:26:01 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2025-03-12 00:26:01 -0400 |
commit | 14bfd5572a83bc202842ab70c3c02094053d93d6 (patch) | |
tree | efaae2d0025192e4755115e16a25a117ed3c2c73 /listamsb.c | |
parent | be6e080f494d9c2c0dd4b47b740407426e068d3f (diff) | |
download | bw-atari8-tools-14bfd5572a83bc202842ab70c3c02094053d93d6.tar.gz |
listamsb: option sanity checking.
Diffstat (limited to 'listamsb.c')
-rw-r--r-- | listamsb.c | 35 |
1 files changed, 25 insertions, 10 deletions
@@ -758,7 +758,7 @@ void crunch_program(void) { /* show the user how the size changed */ newproglen += 3; - percent = 100.0 * (1.0 - (float)newproglen / (float)proglen); + percent = 100.0 * (1.0 - (float)newproglen / (float)bytes_read); verbose(1, "%scrunched %d byte program to %d bytes (%.1f%% %s)", decrunch ? "de" : "", bytes_read, @@ -773,12 +773,12 @@ void crunch_program(void) { void print_help(void) { printf("%s v" VERSION " - detokenize Atari Microsoft BASIC files\n", self); puts("By B. Watson <urchlay@slackware.uk>, released under the WTFPL"); - printf("Usage: %s [[-l] | [-[acClnviutms] ... ] [-r *start,end*]] <file> <outfile>\n", self); + printf("Usage: %s [[-[acCDUnviutms] ...] [-r *start,end*]] <file> <outfile>\n", self); puts(" -a: raw ATASCII output"); puts(" -c: check only (no listing)"); puts(" -C: crunch program"); puts(" -D: decrunch program"); - puts(" -l: lock or unlock program"); + puts(" -U: lock or unlock program"); puts(" -n: no blank line at start of listing"); puts(" -v: verbosity"); puts(" -r: only list lines numbered from *start* to *end*"); @@ -827,7 +827,7 @@ void get_line_range(const char *arg) { void parse_args(int argc, char **argv) { const char *a8cat; char tmp[10]; - int opt; + int opt, a8catopt = 0, ropt = 0; a8cat = getenv("A8CAT"); if(!a8cat) a8cat = "a8cat"; @@ -846,9 +846,9 @@ void parse_args(int argc, char **argv) { while( (opt = getopt(argc, argv, "DCnLUlr:cvaiutmshk")) != -1) { switch(opt) { - case 'L': crunch = decrunch = 0; break; - case 'D': crunch = decrunch = 1; break; - case 'C': crunch = 1; break; + case 'L': crunch = decrunch = unlock_mode = 0; break; + case 'D': decrunch = 1; break; + case 'C': crunch = 1; break; case 'l': case 'U': unlock_mode = 1; break; case 'k': keep_rems = 1; break; @@ -857,12 +857,13 @@ void parse_args(int argc, char **argv) { case 'v': verbosity++ ; break; case 'n': initial_eol = 0; break; case 'h': print_help(); exit(0); - case 'r': get_line_range(optarg); break; + case 'r': get_line_range(optarg); ropt++; break; case 'i': case 'u': case 't': case 'm': case 's': + a8catopt++; if(strlen(pipe_command) > (BUFSIZ - 10)) os_err("too many a8cat options"); sprintf(tmp, " -%c", opt); @@ -872,6 +873,20 @@ void parse_args(int argc, char **argv) { } } + if((unlock_mode + crunch + decrunch) > 1) { + os_err("only one of -C, -D, -U may be used"); + } + + if(keep_rems && !decrunch) { + warn("-k option ignored since -D not given"); + } + + if(unlock_mode || crunch || decrunch) { + if(!initial_eol || check_only || raw_output || ropt) { + warn("-a, -c, -n, -r options ignored with -U, -C, or -D"); + } + } + if(optind >= argc) { if(isatty(fileno(stdin))) { print_help(); @@ -907,7 +922,7 @@ void open_output() { os_err("/dev/null: %s", strerror(errno)); } verbose(1, "using /dev/null for output (check_only)"); - } else if(raw_output || unlock_mode || crunch) { + } else if(raw_output || unlock_mode || crunch || decrunch) { if(isatty(fileno(stdout))) { os_err("refusing to write %s to a terminal", (raw_output ? "raw ATASCII" : "tokenized BASIC")); @@ -944,7 +959,7 @@ int main(int argc, char **argv) { if(unlock_mode) { unlock_program(); exit(0); /* don't need finish() here, no parsing done */ - } else if(crunch) { + } else if(crunch || decrunch) { crunch_program(); exit(0); } |