From ffeba14c10e1cf7f2936cd9249a352474c0e9526 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sun, 19 May 2024 05:11:11 -0400 Subject: unprotbas: exit status 2 for unprotected program; add -c (check only). --- unprotbas.c | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) (limited to 'unprotbas.c') diff --git a/unprotbas.c b/unprotbas.c index 8dc6844..845c75b 100644 --- a/unprotbas.c +++ b/unprotbas.c @@ -42,6 +42,8 @@ char *self; int keepvars = 0; int forcevars = 0; int keepgarbage = 1; +int checkonly = 0; +int was_protected = 0; int verbose = 0; /* file handles */ @@ -57,6 +59,7 @@ void die(const char *msg) { int readfile(void) { int got = fread(data, 1, 65535, input_file); fprintf(stderr, "read %d bytes\n", got); + fclose(input_file); return got; } @@ -369,6 +372,7 @@ void print_help(void) { fprintf(stderr, "-f: force variable name table rebuild\n"); fprintf(stderr, "-n: do not rebuild variable name table, even if it's invalid\n"); fprintf(stderr, "-g: remove trailing garbage, if present\n"); + fprintf(stderr, "-c: check only; no output file\n"); fprintf(stderr, "Use - as a filename to read from stdin and/or write to stdout\n"); } @@ -432,6 +436,7 @@ void parse_args(int argc, char **argv) { case 'f': forcevars++; break; case 'n': keepvars++; break; case 'g': keepgarbage = 0; break; + case 'c': checkonly = 1; break; case 0: if(!input_file) open_input(NULL); @@ -445,7 +450,7 @@ void parse_args(int argc, char **argv) { } else { if(!input_file) open_input(*argv); - else if(!output_file) + else if(!checkonly && !output_file) open_output(*argv); else invalid_args(*argv); @@ -453,7 +458,7 @@ void parse_args(int argc, char **argv) { } if(!input_file) die("no input file given (use - for stdin)"); - if(!output_file) die("no output file given (use - for stdout)"); + if(!checkonly && !output_file) die("no output file given (use - for stdout)"); if(keepvars && forcevars) die("-f and -n are mutually exclusive"); } @@ -465,26 +470,38 @@ int main(int argc, char **argv) { if(lomem) die("This doesn't look like an Atari BASIC program (no $0000 signature)"); - /* - fprintf(stderr, "data at STMTAB (we hope):\n"); - for(int i=codestart; i