diff options
author | B. Watson <urchlay@slackware.uk> | 2024-07-18 15:33:25 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-07-18 15:33:25 -0400 |
commit | 714c27eb8eebece6a183bf7732a22b61777d0956 (patch) | |
tree | 38eca493c6e35085b47d1ec7999e57ec6c28d277 | |
parent | 01157bd97369e0cde8c765fd63ed49da46511909 (diff) | |
download | bw-atari8-tools-714c27eb8eebece6a183bf7732a22b61777d0956.tar.gz |
listbas: trying to get indentation right. current solution too complex IMO.
-rw-r--r-- | listbas.c | 26 |
1 files changed, 19 insertions, 7 deletions
@@ -482,12 +482,22 @@ const char *get_bxl_ext_name(unsigned char tok) { void clear_callbacks(void); void init_callbacks(void); +int cmd_is_if; + +CALLBACK(find_cmd_if) { + cmd_is_if = 0; + if((bas_type == B_APLUS && tok == 0x06) || (bas_type != B_APLUS && tok == CMD_IF)) { + cmd_is_if = 1; + if_without_then++; /* find_then() decrements it, if there's a THEN */ + } +} + CALLBACK(find_op_then) { if(verbose) fprintf(stderr, "find_op_then lineno %d, pos %04x, tok %02x\n", lineno, pos, tok); - if(tok == OP_THEN) - if_without_then = 0; + if(cmd_is_if && tok == OP_THEN) + if_without_then--; } /* walk_code()'s API isn't really set up to be reentrant, but we @@ -495,6 +505,7 @@ CALLBACK(find_op_then) { void find_then(int lineno, unsigned short pos) { clear_callbacks(); on_exp_token = find_op_then; + on_cmd_token = find_cmd_if; walk_code(lineno, lineno); init_callbacks(); } @@ -504,11 +515,12 @@ CALLBACK(print_lineno) { first_stmt = 1; - cmd_tok = program[pos + 4]; - if_without_then = 0; - if((bas_type == B_APLUS && cmd_tok == 0x06) || (bas_type != B_APLUS && cmd_tok == CMD_IF)) { - if_without_then = 1; /* find_then() clears it, if there's a THEN */ - find_then(lineno, pos); + if(indent) { + cmd_tok = program[pos + 4]; + if_without_then = 0; + if((bas_type == B_APLUS && cmd_tok == 0x06) || (bas_type != B_APLUS && cmd_tok == CMD_IF)) { + find_then(lineno, pos); + } } if(skip_lineno) return; |