aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-07-18 03:14:31 -0400
committerB. Watson <urchlay@slackware.uk>2024-07-18 03:14:31 -0400
commite4d97f267855b9782e1524a3092d0adecb19b25c (patch)
tree72633fdf5016315124651e63cc8d6c3d14399fa9
parent06106300e03dabe51f8ba7805984433730de2fe4 (diff)
downloadbw-atari8-tools-e4d97f267855b9782e1524a3092d0adecb19b25c.tar.gz
listbas: partial indentation for A+, BXL, BXE.
-rw-r--r--listbas.c91
1 files changed, 90 insertions, 1 deletions
diff --git a/listbas.c b/listbas.c
index 9f27480..b3ef069 100644
--- a/listbas.c
+++ b/listbas.c
@@ -97,6 +97,8 @@ 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 */
+
FILE *outfh;
int parse_color(char c) {
@@ -173,7 +175,7 @@ void parse_args(int argc, char **argv, int from_env) {
optind = 1;
- while( (opt = getopt(argc, argv, "Db:UCviamnBdhxulc:k")) != -1) {
+ while( (opt = getopt(argc, argv, "Db:UCviamnBdhxulc:kt")) != -1) {
switch(opt) {
case 'U': output_mode = M_UTF8; break;
case 'a': output_mode = M_ATASCII; color = 0; break;
@@ -189,6 +191,7 @@ void parse_args(int argc, char **argv, int from_env) {
case 'n': color = 0; break;
case 'l': skip_lineno = 1; break;
case 'k': mixed_case = 0; break;
+ case 't': indent = 0; break;
case 'b': autodetect = 0; bas_type = get_bas_type(optarg); break;
case 'c': parse_color_scheme(optarg); break;
case 'h': print_help(); exit(0);
@@ -476,6 +479,7 @@ const char *get_bxl_ext_name(unsigned char tok) {
}
CALLBACK(print_lineno) {
+ first_stmt = 1;
if(skip_lineno) return;
if(color) color_on(color_lineno);
fprintf(outfh, "%d ", lineno);
@@ -523,9 +527,94 @@ block are not indented, only the lines between them.
Print "HEY"
*/
+
+void print_indent(void) {
+ int i;
+ if(indent_level < 0) indent_level = 1;
+ 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(first_stmt) print_indent();
+
+ switch(tok) {
+ case 0x07: /* FOR */
+ case 0x13: /* WHILE */
+ indent_level++;
+ return;
+ case 0x08: /* NEXT */
+ case 0x14: /* ENDWHILE */
+ indent_level--;
+ return;
+ default: break;
+ }
+}
+
+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) {
+ switch(tok) {
+ case CMD_FOR: /* FOR */
+ case 0x38: /* WHILE */
+ indent_level++;
+ break;
+ case CMD_NEXT: /* NEXT */
+ case 0x39: /* ENDWHILE */
+ if(first_stmt) print_indent();
+ indent_level--;
+ return;
+ default: break;
+ }
+ if(first_stmt) print_indent();
+}
+
+/* TODO: IF without THEN: IF A */
+void bxe_indent_line(const unsigned char tok) {
+ switch(tok) {
+ case CMD_FOR: /* FOR */
+ case 0x38: /* WHILE */
+ case 0x59: /* PROCEDURE */
+ if(first_stmt) print_indent();
+ indent_level++;
+ return;
+ case CMD_NEXT: /* NEXT */
+ case 0x39: /* ENDWHILE */
+ case 0x5e: /* EXIT */
+ indent_level--;
+ break;
+ default: break;
+ }
+ if(first_stmt) print_indent();
+}
+
+void indent_line(const unsigned char tok) {
+ if(!indent) return;
+
+ switch(bas_type) {
+ case B_APLUS: aplus_indent_line(tok); return;
+ case B_TURBO: turbo_indent_line(tok); return;
+ case B_BXL: bxl_indent_line(tok); return;
+ case B_BXE: bxe_indent_line(tok); return;
+ case B_ATARI:
+ default:
+ return;
+ }
+}
+
CALLBACK(print_cmd) {
const char *name;
+ indent_line(tok);
+ if(first_stmt)
+ first_stmt = 0;
+
if(bas_type == B_APLUS) {
if(tok == 0x52) return;
} else {