diff options
-rw-r--r-- | bas.h | 3 | ||||
-rw-r--r-- | vxrefbas.1 | 36 | ||||
-rw-r--r-- | vxrefbas.c | 47 | ||||
-rw-r--r-- | vxrefbas.rst | 37 |
4 files changed, 86 insertions, 37 deletions
@@ -46,6 +46,9 @@ #define CMD_NEXT 0x09 #define CMD_LET 0x06 #define CMD_ILET 0x36 +#define CMD_DIM 0x14 +#define CMD_READ 0x22 +#define CMD_INPUT 0x02 #define OP_GOTO 0x17 #define OP_GOSUB 0x18 #define OP_THEN 0x1b @@ -35,25 +35,39 @@ vxrefbas \- Variable cross-reference for tokenized Atari 8-bit BASIC files vxrefbas \fBinput\-file\fP .SH DESCRIPTION .sp -\fBvxrefbas\fP reads an Atari 8\-bit BASIC tokenized program and prints -a list of variables, each with a list of line numbers where the -variable is referenced. +\fBvxrefbas\fP reads an Atari 8\-bit BASIC tokenized program and prints a +list of variables (names and token numbers), each with a list of line +numbers where the variable is referenced. .sp +String variable names end with \fI$\fP\&. Arrays end with \fI(\fP\&. Numeric +(scalar) variable names don\(aqt have a special character. +.sp +After the list of lines, the reference count is shown in parentheses. Variables that aren\(aqt used by the program are listed as \fI(no references)\fP\&. .sp -Each line number may be followed by one or more markers, which show the -type of variable access. +Each line number may be followed by an \fI=\fP and one or more markers, +which show the type of variable access. .INDENT 0.0 .TP -.B \fB=\fP -The variable is assigned on this line, with \fILET\fP or "implied LET" (e.g. +.B \fBA\fP +Variable is assigned on this line, with \fILET\fP or "implied LET" (e.g. \fIA=1\fP). .TP -.B \fB{\fP -The variable is used as the control variable of a \fIFOR\fP loop on this line. +.B \fBF\fP +Variable is used as the control variable of a \fIFOR\fP loop on this line. +.TP +.B \fBN\fP +Variable is used in a \fINEXT\fP on this line. +.TP +.B \fBD\fP +The variable is dimensioned (\fIDIM\fP command) on this line. Only applies to +string and array variables. +.TP +.B \fBI\fP +Variable was \fIINPUT\fP on this line. .TP -.B \fB}\fP -The variable is used in a \fINEXT\fP on this line. +.B \fBR\fP +Variable was \fIREAD\fP on this line. .UNINDENT .SH OPTIONS .SS General Options @@ -7,7 +7,10 @@ #include "bas.h" -int target_var, lastline, assign, is_for, is_next; +/* FIXME: lists don't work correctly yet, DIM/READ/INPUT. + Example: 10 DIM A$(10):? B$ ...it thinks B$ was also DIMed. */ + +int target_var, lastline, assign, is_for, is_next, is_dim, is_read, is_input; int refcounts[128]; void print_help(void) { @@ -16,27 +19,41 @@ void print_help(void) { } CALLBACK(new_line) { - assign = is_for = is_next = 0; + assign = is_for = is_next = is_dim = is_read = is_input = 0; } CALLBACK(end_line) { if(lastline != lineno) return; - printf("%d%s%s%s ", - lineno, - assign ? "=" : "", - is_for ? "{": "", - is_next ? "}": ""); + + printf("%d", lineno); + if(assign || is_for || is_next || is_dim || is_read || is_input) { + 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'); + } + putchar(' '); } CALLBACK(new_command) { - if(program[pos + 1] == (target_var | 0x80)) { - if(tok == CMD_LET || tok == CMD_ILET) { - assign = 1; - } else if(tok == CMD_FOR) { - is_for = 1; - } else if(tok == CMD_NEXT) { - is_next = 1; - } + switch(tok) { + case CMD_LET: + case CMD_ILET: + assign = 1; break; + case CMD_FOR: + is_for = 1; break; + case CMD_NEXT: + is_next = 1; break; + case CMD_DIM: + is_dim = 1; break; + case CMD_READ: + is_read= 1; break; + case CMD_INPUT: + is_input= 1; break; + default: break; } } diff --git a/vxrefbas.rst b/vxrefbas.rst index b06deb5..155cd80 100644 --- a/vxrefbas.rst +++ b/vxrefbas.rst @@ -15,24 +15,39 @@ vxrefbas **input-file** DESCRIPTION =========== -**vxrefbas** reads an Atari 8-bit BASIC tokenized program and prints -a list of variables, each with a list of line numbers where the -variable is referenced. +**vxrefbas** reads an Atari 8-bit BASIC tokenized program and prints a +list of variables (names and token numbers), each with a list of line +numbers where the variable is referenced. + +String variable names end with *$*. Arrays end with *(*. Numeric +(scalar) variable names don't have a special character. + +After the list of lines, the reference count is shown in parentheses. Variables that aren't used by the program are listed as *(no references)*. -Each line number may be followed by one or more markers, which show the -type of variable access. +Each line number may be followed by an *=* and one or more markers, +which show the type of variable access. -**=** - The variable is assigned on this line, with *LET* or "implied LET" (e.g. +**A** + Variable is assigned on this line, with *LET* or "implied LET" (e.g. *A=1*). -**{** - The variable is used as the control variable of a *FOR* loop on this line. +**F** + Variable is used as the control variable of a *FOR* loop on this line. + +**N** + Variable is used in a *NEXT* on this line. + +**D** + The variable is dimensioned (*DIM* command) on this line. Only applies to + string and array variables. + +**I** + Variable was *INPUT* on this line. -**}** - The variable is used in a *NEXT* on this line. +**R** + Variable was *READ* on this line. OPTIONS ======= |