From 5b4d161d5c82105f92006aa9cebbcd72b9383178 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Sat, 15 Jun 2024 16:22:25 -0400 Subject: vxrefbas: WIP. --- vxrefbas.c | 100 ++++++++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 66 insertions(+), 34 deletions(-) (limited to 'vxrefbas.c') diff --git a/vxrefbas.c b/vxrefbas.c index acc830c..e05e2d7 100644 --- a/vxrefbas.c +++ b/vxrefbas.c @@ -7,8 +7,9 @@ #include "bas.h" -int target_var, lastline, assign, is_for, is_next, is_dim, is_read, is_input; -int in_dim, in_read, in_input; +int A, F, N, D, I, R, G; +int target_var, lastline; +unsigned char last_cmd = 0, last_op = 0; int refcounts[128]; void print_help(void) { @@ -17,57 +18,87 @@ void print_help(void) { } CALLBACK(new_line) { - assign = is_for = is_next = is_dim = is_read = is_input = 0; + A = F = N = D = I = R = G = 0; } CALLBACK(end_line) { if(lastline != lineno) return; - printf("%d", lineno); - if(assign || is_for || is_next || is_dim || is_read || is_input) { + if(A || F || N || D || I || R || G) { putchar('='); - if(assign) putchar('A'); - if(is_for) putchar('F'); - if(is_next) putchar('N'); - if(is_dim) putchar('D'); - if(is_read) putchar('R'); - if(is_input) putchar('I'); + if(A) putchar('A'); + if(F) putchar('F'); + if(N) putchar('N'); + if(D) putchar('D'); + if(I) putchar('I'); + if(R) putchar('R'); + if(G) putchar('G'); } + putchar(' '); } CALLBACK(new_command) { - switch(tok) { + last_cmd = tok; +} + +CALLBACK(end_stmt) { + last_cmd = last_op = 0; +} + +CALLBACK(handle_var) { + unsigned char last_tok; + + if(tok != (target_var | 0x80)) return; + + if(lastline != lineno) { + printf("%d", lineno); + refcounts[target_var]++; + } + + lastline = lineno; + last_tok = program[pos - 1]; + + switch(last_cmd) { case CMD_LET: case CMD_ILET: - assign = 1; break; + if(last_tok == last_cmd) A = 1; + break; case CMD_FOR: - is_for = 1; break; + if(last_tok == last_cmd) F = 1; + break; case CMD_NEXT: - is_next = 1; break; + if(last_tok == last_cmd) N = 1; + break; case CMD_DIM: - in_dim = 1; break; - case CMD_READ: - in_read= 1; break; + if(last_tok == last_cmd || last_tok == OP_COMMA) D = 1; + break; case CMD_INPUT: - in_input= 1; break; - default: break; + if(last_tok == last_cmd || last_tok == OP_COMMA) I = 1; + break; + case CMD_READ: + if(last_tok == last_cmd || last_tok == OP_COMMA) R = 1; + break; + case CMD_GET: + if(last_tok == OP_COMMA) G = 1; + break; } } -CALLBACK(end_stmt) { - in_dim = in_read = in_input = 0; -} +void parse_args(int argc, char **argv) { + int opt; -CALLBACK(handle_var) { - if(in_dim) is_dim = 1; - if(in_input) is_input = 1; - if(in_read) is_read = 1; - if(lastline == lineno) return; - if((tok & 0x7f) == target_var) { - refcounts[target_var]++; - lastline = lineno; + while( (opt = getopt(argc, argv, "v")) != -1) { + switch(opt) { + case 'v': verbose = 1; break; + default: print_help(); exit(1); + } } + + if(optind >= argc) + die("No input file given (use - for stdin)."); + else + open_input(argv[optind]); } int main(int argc, char **argv) { @@ -77,8 +108,7 @@ int main(int argc, char **argv) { set_self(*argv); parse_general_args(argc, argv, print_help); - - open_input(argv[1]); + parse_args(argc, argv); readfile(); parse_header(); @@ -92,6 +122,7 @@ int main(int argc, char **argv) { target_var = 0; vnpos = vnstart; + /* walk the variable value table */ for(pos = vvstart; pos < codestart; pos += 8) { /* print the variable name */ while(program[vnpos] < 0x80) @@ -110,7 +141,8 @@ int main(int argc, char **argv) { } putchar('\n'); - if(target_var++ == 128) break; + /* ignore any ERROR-4 vars, since they don't have tokens anyway. */ + if(++target_var == 128) break; } printf(" %d variables, %d unreferenced.\n", target_var, unref); -- cgit v1.2.3