aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--listamsb.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/listamsb.c b/listamsb.c
index 2581a61..a3614c6 100644
--- a/listamsb.c
+++ b/listamsb.c
@@ -605,22 +605,31 @@ int need_space_between(int ext1, int ext2, unsigned char t1, unsigned char t2) {
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;
+ switch(t1) {
+ case TOK_IF:
+ case TOK_THEN:
+ case TOK_ELSE:
+ case TOK_AND:
+ case TOK_OR:
+ case TOK_NOT:
+ return 1;
+ default: break;
+ }
}
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;
+ /* these always get a space before them, for readability. */
+ switch(t2) {
+ case TOK_THEN:
+ case TOK_AND:
+ case TOK_OR:
+ case TOK_NOT:
+ return 1;
+ default: break;
+ }
}
- if(isalnum(t1last)) {
+ if(t1 >= 0x80 && isalnum(t1last)) {
/* space not really required between OPEN/PRINT/CLOSE and #,
but put one there for neatness. */
if(t2first == '#') return 1;
@@ -662,6 +671,8 @@ int decrunch_line(void) {
byte = read_prog_byte();
if(byte != 0) {
+ if(byte == ' ' || is_comment_start(byte)) spacecount++;
+
if(in_string) {
if(byte == '|')
in_string = 0;
@@ -670,6 +681,11 @@ int decrunch_line(void) {
} else {
if(byte == '"') {
in_string = 1;
+ /* XXX: if a " ever occurs immediately after an extended
+ token, this is wrong. I don't *think* the syntax
+ allows that... */
+ if(need_space_between(0, 0, prev, byte))
+ code[codelen++] = ' ';
} else if(is_comment_start(byte)) {
in_comment = 1;
} else if(byte == 0xff) {
@@ -685,6 +701,11 @@ int decrunch_line(void) {
byte = read_prog_byte();
if(need_space_between(1, 0, prev, byte))
code[codelen++] = ' ';
+ } else if(prev == ':' && byte == TOK_ELSE) {
+ /* special case, ELSE needs a space before the (invisible)
+ colon that comes before it. */
+ code[codelen - 1] = ' ';
+ code[codelen++] = prev;
} else if(need_space_between(0, 0, prev, byte)) {
code[codelen++] = ' ';
}
@@ -735,6 +756,9 @@ void crunch_program(void) {
newproglen,
percent < 0 ? -percent : percent,
percent < 0 ? "larger" : "smaller");
+
+ if(decrunch && spacecount)
+ warn("%d spaces/comments, are you sure it was crunched?", spacecount);
}
void print_help(void) {