From 2025724a923b73a1cce27524aea5ed4ac22ffd21 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Mon, 17 Jun 2024 18:36:05 -0400 Subject: cxrefbas: show ref type in output. --- cxrefbas.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) (limited to 'cxrefbas.c') diff --git a/cxrefbas.c b/cxrefbas.c index 9228f28..4598117 100644 --- a/cxrefbas.c +++ b/cxrefbas.c @@ -8,39 +8,41 @@ #include "bas.h" #include "bcdfp.h" -/* not yet... typedef struct { unsigned short lineno; unsigned short pos; - unsigned char type; + unsigned char cmd; } lineref_t; -*/ -unsigned short *linerefs[32769]; +lineref_t *linerefs[32769]; int refcounts[32769]; int lines_exist[32769]; unsigned char last_cmd, on_op; int last_cmd_pos; -void add_lineref(unsigned short from, unsigned short to) { - unsigned short *p; +void add_lineref(unsigned short from, unsigned short pos) { + lineref_t *p; int c; + unsigned short to; + to = fp2int(program + pos); if(to > 32767) return; p = linerefs[to]; c = refcounts[to]; if(c) { - p = realloc(p, sizeof(unsigned short) * (c + 1)); + p = realloc(p, sizeof(lineref_t) * (c + 1)); } else { - p = malloc(sizeof(unsigned short)); + p = malloc(sizeof(lineref_t)); } if(!p) die("Out of memory."); linerefs[to] = p; - p[c] = from; + linerefs[to][c].lineno = from; + linerefs[to][c].pos = pos; + linerefs[to][c].cmd = last_cmd; c++; refcounts[to] = c; } @@ -137,14 +139,14 @@ CALLBACK(got_exp) { case CMD_RESTORE: case CMD_TRAP: if((pos == last_cmd_pos + 1) && standalone) { - add_lineref(lineno, fp2int(program + pos + 1)); + add_lineref(lineno, pos + 1); } else { computed_msg(lineno); } break; case CMD_IF: if(last_tok == OP_THEN) { - add_lineref(lineno, fp2int(program + pos + 1)); + add_lineref(lineno, pos + 1); } break; case CMD_ON: { @@ -153,7 +155,7 @@ CALLBACK(got_exp) { case OP_GOSUB: case OP_COMMA: if(standalone) - add_lineref(lineno, fp2int(program + pos + 1)); + add_lineref(lineno, pos + 1); else computed_msg(lineno); break; @@ -176,13 +178,26 @@ void build_ref_table(void) { } void print_ref_table(void) { + char c; int i, j; for(i = 0; i < 32768; i++) { if(refcounts[i]) { if(!lines_exist[i]) putchar('!'); printf("%d: ", i); for(j = 0; j < refcounts[i]; j++) { - printf("%d ", linerefs[i][j]); + printf("%d:", linerefs[i][j].lineno); + switch(linerefs[i][j].cmd) { + case CMD_GOTO: c = 'G'; break; + case CMD_GO_TO: c = 'G'; break; + case CMD_GOSUB: c = 'S'; break; + case CMD_RESTORE: c = 'R'; break; + case CMD_TRAP: c = 'T'; break; + case CMD_IF: c = 'I'; break; + case CMD_ON: c = 'O'; break; + default: c = '?'; break; + } + putchar(c); + putchar(' '); } putchar('\n'); } -- cgit v1.2.3