aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--listbas.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/listbas.c b/listbas.c
index b3ef069..dc267c8 100644
--- a/listbas.c
+++ b/listbas.c
@@ -92,10 +92,11 @@ int color_varnames = NO_COLOR;
const char *input_filename;
-int indent_level = 0;
-int badtok = 0; /* set to 1 if we find a bad token */
-int inv = 0; /* set to 1 when we're printing inverse */
-int cur_color = -1; /* -1 = no color */
+int indent_level = 0;
+int if_without_then = 0;
+int badtok = 0; /* set to 1 if we find a bad token */
+int inv = 0; /* set to 1 when we're printing inverse */
+int cur_color = -1; /* -1 = no color */
int first_stmt = 1; /* true if cmd token comes right after lineno */
@@ -530,15 +531,15 @@ block are not indented, only the lines between them.
void print_indent(void) {
int i;
- if(indent_level < 0) indent_level = 1;
+ if(indent_level < 0) indent_level = 0;
for(i = 0; i < indent_level; i++) {
outchr(' ');
outchr(' ');
}
}
-/* TODO: IF without THEN: IF A:stmt */
void aplus_indent_line(const unsigned char tok) {
+ if(if_without_then) indent_level++;
if(first_stmt) print_indent();
switch(tok) {
@@ -548,6 +549,7 @@ void aplus_indent_line(const unsigned char tok) {
return;
case 0x08: /* NEXT */
case 0x14: /* ENDWHILE */
+ case 0x18: /* ENDIF */
indent_level--;
return;
default: break;
@@ -557,9 +559,13 @@ void aplus_indent_line(const unsigned char tok) {
void turbo_indent_line(const unsigned char tok) {
}
-/* TODO: IF without THEN: IF A */
-/* TODO: extended subtokens (PROCEDURE!) */
-void bxl_indent_line(const unsigned char tok) {
+/* TODO: IF without THEN: the actual IF line is supposed to get indented,
+ but only if there's *not* a THEN. no easy way to look ahead that I've
+ thought of yet. */
+/* Note: BXL's PROCEDURE/EXIT (from toolkit extensions) does
+ *not* get indented. */
+void bxl_indent_line(unsigned char tok) {
+ if(if_without_then) indent_level++;
switch(tok) {
case CMD_FOR: /* FOR */
case 0x38: /* WHILE */
@@ -567,6 +573,7 @@ void bxl_indent_line(const unsigned char tok) {
break;
case CMD_NEXT: /* NEXT */
case 0x39: /* ENDWHILE */
+ case 0x3d: /* ENDIF */
if(first_stmt) print_indent();
indent_level--;
return;
@@ -575,9 +582,16 @@ void bxl_indent_line(const unsigned char tok) {
if(first_stmt) print_indent();
}
-/* TODO: IF without THEN: IF A */
void bxe_indent_line(const unsigned char tok) {
+ if(if_without_then) indent_level++;
switch(tok) {
+ case 0x3c: /* ELSE */
+ if(first_stmt) {
+ indent_level--;
+ print_indent();
+ indent_level++;
+ }
+ return;
case CMD_FOR: /* FOR */
case 0x38: /* WHILE */
case 0x59: /* PROCEDURE */
@@ -587,6 +601,7 @@ void bxe_indent_line(const unsigned char tok) {
case CMD_NEXT: /* NEXT */
case 0x39: /* ENDWHILE */
case 0x5e: /* EXIT */
+ case 0x3d: /* ENDIF */
indent_level--;
break;
default: break;
@@ -597,6 +612,9 @@ void bxe_indent_line(const unsigned char tok) {
void indent_line(const unsigned char tok) {
if(!indent) return;
+ /*
+ fprintf(stderr, "if_without_then == %d\n", if_without_then);
+ */
switch(bas_type) {
case B_APLUS: aplus_indent_line(tok); return;
case B_TURBO: turbo_indent_line(tok); return;
@@ -615,10 +633,13 @@ CALLBACK(print_cmd) {
if(first_stmt)
first_stmt = 0;
+ if_without_then = 0;
if(bas_type == B_APLUS) {
if(tok == 0x52) return;
+ if(tok == 0x06) if_without_then = 1;
} else {
if(tok == CMD_ILET) return;
+ if(tok == CMD_IF) if_without_then = 1;
}
if(color) color_on(color_cmd);
@@ -763,6 +784,11 @@ void print_varname(unsigned char varnum) {
CALLBACK(print_op) {
const char *name;
+ if(tok == OP_THEN) {
+ /* same token in A+ as in all the others, for once. */
+ if_without_then = 0;
+ }
+
switch(tok) {
case 0: /* Turbo variables numbered >= $80 */
if(bas_type == B_TURBO) {