diff options
author | B. Watson <urchlay@slackware.uk> | 2024-07-07 00:36:32 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-07-07 00:36:32 -0400 |
commit | b478d55399c493752bc86fe0c59d6070a1b506dc (patch) | |
tree | d1a1c8b134acd3e7d9bc566606ef4bac7295989a | |
parent | 697f98438609cfc51fe8781e35f2a4e1c8e68111 (diff) | |
download | bw-atari8-tools-b478d55399c493752bc86fe0c59d6070a1b506dc.tar.gz |
whichbas: stop after first match, add -k to restore original behaviour.
-rw-r--r-- | whichbas.c | 33 | ||||
-rw-r--r-- | whichbas.rst | 19 |
2 files changed, 35 insertions, 17 deletions
@@ -20,16 +20,19 @@ int comma_count; /* count of regular commas (not string/array) in statement */ unsigned char last_cmd; unsigned short last_cmd_pos; +int keep_going = 0; /* -k flag */ + void print_help(void) { - printf("Usage: %s [-v] <inputfile>\n", self); + printf("Usage: %s [-v] [-k] <inputfile>\n", self); } void parse_args(int argc, char **argv) { int opt; - while( (opt = getopt(argc, argv, "v")) != -1) { + while( (opt = getopt(argc, argv, "vk")) != -1) { switch(opt) { case 'v': verbose = 1; break; + case 'k': keep_going = verbose = 1; break; default: print_help(); exit(1); @@ -50,10 +53,6 @@ void add_type(int type) { } */ -void remove_type(int type) { - bas_type &= ((~type) & 0x0f); -} - void print_result(void) { const char *name; @@ -75,6 +74,16 @@ void print_result(void) { exit(bas_type == BT_ATARI ? 0 : bas_type + 8); } +void remove_type(int type) { + bas_type &= ((~type) & 0x0f); + + if(keep_going) return; + + /* without -k, stop if it gets narrowed down to one of these two. */ + if(bas_type == BT_TURBO || bas_type == BT_BXE) + print_result(); +} + CALLBACK(handle_cmd) { int has_args = 0; unsigned char nexttok; @@ -83,7 +92,7 @@ CALLBACK(handle_cmd) { last_cmd_pos = pos; comma_count = 0; - if(verbose) fprintf(stderr, "handle_cmd: lineno %d, tok $%02x, bas_type was %02x...", lineno, tok, bas_type); + if(verbose) fprintf(stderr, "handle_cmd: lineno %d, tok $%02x, bas_type was %02x\n", lineno, tok, bas_type); if(tok <= CMD_ERROR) return; /* legal in BASIC, ignore */ remove_type(BT_ATARI); @@ -204,7 +213,7 @@ CALLBACK(handle_cmd) { } default: break; } - if(verbose) fprintf(stderr, " now %02x\n", bas_type); + if(verbose) fprintf(stderr, " bas_type now %02x\n", bas_type); } CALLBACK(handle_op) { @@ -213,11 +222,11 @@ CALLBACK(handle_op) { if(tok == OP_COMMA) comma_count++; - if(verbose) fprintf(stderr, "handle_op: lineno %d, tok $%02x, comma_count %d, bas_type was %02x...", lineno, tok, comma_count, bas_type); + if(verbose) fprintf(stderr, "handle_op: lineno %d, tok $%02x, comma_count %d, bas_type was %02x\n", lineno, tok, comma_count, bas_type); if(tok == 0x0d) remove_type(BT_ATARI); /* hex const (turbo *and* bxl/xe) */ if(tok <= OP_FUNC_STRIG) { - if(verbose) fprintf(stderr, " now %02x\n", bas_type); + if(verbose) fprintf(stderr, " bas_type now %02x\n", bas_type); return; /* legal in BASIC, ignore */ } remove_type(BT_ATARI); @@ -276,11 +285,11 @@ CALLBACK(handle_op) { remove_type(BT_TURBO); } } - if(verbose) fprintf(stderr, " now %02x\n", bas_type); + if(verbose) fprintf(stderr, " bas_type now %02x\n", bas_type); } CALLBACK(handle_end_stmt) { - if(verbose) fprintf(stderr, "handle_end_stmt: lineno %d, tok $%02x, last_cmd $%02x, comma_count %d, bas_type was %02x...", lineno, tok, last_cmd, comma_count, bas_type); + if(verbose) fprintf(stderr, "handle_end_stmt: lineno %d, tok $%02x, last_cmd $%02x, comma_count %d, bas_type was %02x\n", lineno, tok, last_cmd, comma_count, bas_type); switch(last_cmd) { case 0x38: /* DPOKE (2 args) or WHILE (1 arg) */ if(comma_count) { diff --git a/whichbas.rst b/whichbas.rst index 5e7363c..3eb8854 100644 --- a/whichbas.rst +++ b/whichbas.rst @@ -18,6 +18,20 @@ DESCRIPTION BASIC XL, BASIC XE, or Atari Microsoft BASIC program and attempts to discover which BASIC is required to run it. +OPTIONS +======= + +Detection Options +----------------- + +**-k** + Keep going. The default is to stop looking at the program if the + BASIC type gets narrowed down to either Turbo BASIC XL or BASIC XE. + This option also enables **-v** (verbose). It's really only useful + for testing, if you're hacking on **whichbas** itself. + +.. include:: genopts.rst + NOTES ===== Turbo BASIC, BASIC XL, and BASIC XE are all supersets of Atari BASIC. @@ -62,11 +76,6 @@ Turbo and BXL/BXE support extended variable types. **whichbas** knows nothing about other BASICs such as Frost BASIC, BASIC/A+, Altirra BASIC... -OPTIONS -======= - -.. include:: genopts.rst - EXIT STATUS =========== |