aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bas.h3
-rw-r--r--vxrefbas.115
-rw-r--r--vxrefbas.c42
-rw-r--r--vxrefbas.rst15
4 files changed, 59 insertions, 16 deletions
diff --git a/bas.h b/bas.h
index c88d035..1a3ee17 100644
--- a/bas.h
+++ b/bas.h
@@ -50,11 +50,14 @@
#define CMD_READ 0x22
#define CMD_INPUT 0x02
#define CMD_GET 0x29
+#define CMD_LOCATE 0x31
+#define CMD_NOTE 0x1b
#define OP_GOTO 0x17
#define OP_GOSUB 0x18
#define OP_THEN 0x1b
#define OP_COMMA 0x12
#define OP_ARR_COMMA 0x3c
+#define OP_SEMICOLON 0x15
#define OP_EOS 0x14
#define OP_EOL 0x16
#define OP_NUMCONST 0x0e
diff --git a/vxrefbas.1 b/vxrefbas.1
index e139d59..fcee203 100644
--- a/vxrefbas.1
+++ b/vxrefbas.1
@@ -43,7 +43,10 @@ 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\&.
+Multiple references on the same line of code are not counted
+separately, so this is a count of \fIlines\fP that reference the variable.
+Variables that aren\(aqt used by the program are listed as \fI(no
+references)\fP\&.
.sp
Each line number may be followed by an \fI=\fP and one or more markers,
which show the type of variable access.
@@ -71,7 +74,17 @@ Variable was \fIREAD\fP on this line.
.TP
.B \fBG\fP
Variable was read with \fIGET\fP on this line.
+.TP
+.B \fBO\fP
+Variable was set by \fINOTE\fP on this line. Sorry, this can\(aqt be \fIN\fP, it\(aqs
+already used for \fINEXT\fP\&.
+.TP
+.B \fBL\fP
+Variable was set by \fILOCATE\fP on this line.
.UNINDENT
+.sp
+The last line of output shows the total number of variables and the
+number of unreferenced variables.
.SH OPTIONS
.SS General Options
.INDENT 0.0
diff --git a/vxrefbas.c b/vxrefbas.c
index e05e2d7..0cffc64 100644
--- a/vxrefbas.c
+++ b/vxrefbas.c
@@ -7,9 +7,9 @@
#include "bas.h"
-int A, F, N, D, I, R, G;
+int A, F, N, D, I, R, G, O, L;
int target_var, lastline;
-unsigned char last_cmd = 0, last_op = 0;
+unsigned char last_cmd = 0;
int refcounts[128];
void print_help(void) {
@@ -18,13 +18,13 @@ void print_help(void) {
}
CALLBACK(new_line) {
- A = F = N = D = I = R = G = 0;
+ A = F = N = D = I = R = G = O = L = 0;
}
CALLBACK(end_line) {
if(lastline != lineno) return;
- if(A || F || N || D || I || R || G) {
+ if(A || F || N || D || I || R || G || O || L) {
putchar('=');
if(A) putchar('A');
if(F) putchar('F');
@@ -33,6 +33,8 @@ CALLBACK(end_line) {
if(I) putchar('I');
if(R) putchar('R');
if(G) putchar('G');
+ if(O) putchar('O');
+ if(L) putchar('L');
}
putchar(' ');
@@ -43,11 +45,12 @@ CALLBACK(new_command) {
}
CALLBACK(end_stmt) {
- last_cmd = last_op = 0;
+ last_cmd = 0;
}
CALLBACK(handle_var) {
- unsigned char last_tok;
+ unsigned char last_tok, next_tok;
+ int was_cmd, was_comma, was_semicolon;
if(tok != (target_var | 0x80)) return;
@@ -57,30 +60,41 @@ CALLBACK(handle_var) {
}
lastline = lineno;
+
last_tok = program[pos - 1];
+ next_tok = program[pos + 1];
+ was_cmd = (last_tok == last_cmd);
+ was_comma = (last_tok == OP_COMMA);
+ was_semicolon = (last_tok == OP_SEMICOLON);
switch(last_cmd) {
case CMD_LET:
case CMD_ILET:
- if(last_tok == last_cmd) A = 1;
+ if(was_cmd) A = 1;
break;
case CMD_FOR:
- if(last_tok == last_cmd) F = 1;
+ if(was_cmd) F = 1;
break;
case CMD_NEXT:
- if(last_tok == last_cmd) N = 1;
+ if(was_cmd) N = 1;
break;
case CMD_DIM:
- if(last_tok == last_cmd || last_tok == OP_COMMA) D = 1;
+ if(was_cmd || was_comma) D = 1;
break;
- case CMD_INPUT:
- if(last_tok == last_cmd || last_tok == OP_COMMA) I = 1;
+ case CMD_INPUT: /* INPUT #1;A and INPUT #1,A are both allowed, grr. */
+ if(was_cmd || was_comma || was_semicolon) I = 1;
break;
case CMD_READ:
- if(last_tok == last_cmd || last_tok == OP_COMMA) R = 1;
+ if(was_cmd || was_comma) R = 1;
break;
case CMD_GET:
- if(last_tok == OP_COMMA) G = 1;
+ if(was_comma) G = 1;
+ break;
+ case CMD_NOTE:
+ if(was_comma) O = 1;
+ break;
+ case CMD_LOCATE:
+ if(next_tok == OP_EOS || next_tok == OP_EOL) L = 1;
break;
}
}
diff --git a/vxrefbas.rst b/vxrefbas.rst
index 2e18186..5a17cdb 100644
--- a/vxrefbas.rst
+++ b/vxrefbas.rst
@@ -24,7 +24,10 @@ 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)*.
+Multiple references on the same line of code are not counted
+separately, so this is a count of *lines* that reference the variable.
+Variables that aren't used by the program are listed as *(no
+references)*.
Each line number may be followed by an *=* and one or more markers,
which show the type of variable access.
@@ -52,6 +55,16 @@ which show the type of variable access.
**G**
Variable was read with *GET* on this line.
+**O**
+ Variable was set by *NOTE* on this line. Sorry, this can't be *N*, it's
+ already used for *NEXT*.
+
+**L**
+ Variable was set by *LOCATE* on this line.
+
+The last line of output shows the total number of variables and the
+number of unreferenced variables.
+
OPTIONS
=======