aboutsummaryrefslogtreecommitdiff
path: root/listamsb.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-03-09 03:30:33 -0400
committerB. Watson <urchlay@slackware.uk>2025-03-09 03:30:33 -0400
commitf83939324458821440c39c9f63ed3a4a087c750a (patch)
tree0e4fdfbb934ebc9d0f25a957445d4ced5f40f1f8 /listamsb.c
parenta5341afcff7cc4c703257b7405c0e5f62cb704a9 (diff)
downloadbw-atari8-tools-f83939324458821440c39c9f63ed3a4a087c750a.tar.gz
listamsb: clean up -D output.
Diffstat (limited to 'listamsb.c')
-rw-r--r--listamsb.c45
1 files changed, 40 insertions, 5 deletions
diff --git a/listamsb.c b/listamsb.c
index e7dba8a..9eff533 100644
--- a/listamsb.c
+++ b/listamsb.c
@@ -26,8 +26,13 @@
#define TOK_SQUOTE 0x9a
#define TOK_BANG 0x9b
-/* AMSB's token for ELSE */
+/* various other AMSB tokens */
#define TOK_ELSE 0x9c
+#define TOK_IF 0x97
+#define TOK_THEN 0x9d
+#define TOK_AND 0xf3
+#define TOK_OR 0xf4
+#define TOK_NOT 0xf5
/* good old Atari EOL character */
#define EOL 0x9b
@@ -592,9 +597,36 @@ int need_space_between(int ext1, int ext2, unsigned char t1, unsigned char t2) {
t1last = tok1[strlen((char *)tok1) - 1]; /* "PRINT" => "T" */
t2first = tok2[0]; /* "PRINT" => "P" */
- /* space not really required between OPEN/PRINT/CLOSE and #,
- but put one there for neatness. */
- if(t2first == '#') return 1;
+ /* if we already have a space, don't need to add another */
+ if(t1last == ' ' || t2first == ' ') return 0;
+
+ if(!ext1) {
+ /* IF, THEN, and operators like AND/OR/NOT always get a
+ space after them, for readability. */
+ if(t1 == TOK_IF) return 1;
+ if(t1 == TOK_THEN) return 1;
+ if(t1 == TOK_ELSE) return 1;
+ if(t1 == TOK_AND) return 1;
+ if(t1 == TOK_OR) return 1;
+ if(t1 == TOK_NOT) return 1;
+ }
+
+ if(!ext2) {
+ if(t2 == TOK_THEN) return 1;
+ if(t2 == TOK_AND) return 1;
+ if(t2 == TOK_OR) return 1;
+ if(t2 == TOK_NOT) return 1;
+ }
+
+ if(isalnum(t1last)) {
+ /* space not really required between OPEN/PRINT/CLOSE and #,
+ but put one there for neatness. */
+ if(t2first == '#') return 1;
+ /* same for POKE &52,0 or DATA &FF */
+ if(t2first == '&') return 1;
+ /* INPUT "PROMPT";A$ or DATA "FOO" */
+ if(t2first == '"') return 1;
+ }
/* space not really required between a closing quote and
a keyword, but put it in for neatness. examples:
@@ -602,7 +634,10 @@ int need_space_between(int ext1, int ext2, unsigned char t1, unsigned char t2) {
IF A$="FOO" THEN 10
PRINT "YOUR IQ IS" IQ
these look weird without the space after the " */
- if(t1last == '|' && isalnum(t2first)) return 1;
+ if(isalnum(t2first)) {
+ if(t1last == '|') return 1;
+ if(t1last == '$') return 1; /* OPEN #1,F$ OUTPUT */
+ }
return(isalnum(t1last) && isalnum(t2first));
}