diff options
author | B. Watson <urchlay@slackware.uk> | 2025-02-28 18:07:20 -0500 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2025-02-28 18:07:20 -0500 |
commit | 2969891e182914fbd9818113465016633f5bb1df (patch) | |
tree | 0bb4060816a67175955ebad5045243d7fe9413e3 | |
parent | 2f86fb1ed6ff871c6cccb3136aef363d95ddef5c (diff) | |
download | bw-atari8-tools-2969891e182914fbd9818113465016633f5bb1df.tar.gz |
listamsb: stop using ungetc().
-rw-r--r-- | listamsb.c | 28 |
1 files changed, 16 insertions, 12 deletions
@@ -178,17 +178,13 @@ unsigned char unlock_byte(unsigned char b) { /* the "encryption" is the same (process is reversible) */ #define lock_byte(x) unlock_byte(x) +/* read and (if needed) decrypt a byte from the program. */ unsigned char read_prog_byte(void) { unsigned char b = read_byte(); return locked ? unlock_byte(b) : b; } -void unread_prog_byte(unsigned char b) { - if(locked) b = lock_byte(b); - ungetc(b, infile); - bytes_read--; -} - +/* read a word from the program, does not decrypt */ int read_word(void) { int w; @@ -198,6 +194,7 @@ int read_word(void) { return w; } +/* read and (if needed) decrypt a word from the program. */ int read_prog_word(void) { int w; @@ -250,7 +247,7 @@ void unknown_token(unsigned char byte, int ext) { int next_line(void) { static int last_lineno = -1; static int last_ptr = -1; - int ptr, lineno, was_ff, in_string, in_comment, offset, len; + int ptr, lineno, was_ff, was_colon, in_string, in_comment, offset, len; int printing; unsigned char byte; @@ -308,6 +305,7 @@ int next_line(void) { if(printing) fprintf(outfile, "%d ", lineno); was_ff = 0; + was_colon = 0; in_string = 0; in_comment = 0; @@ -333,16 +331,22 @@ int next_line(void) { if(byte == '"') putc(byte, outfile); } } + continue; } else if(in_comment) { /* null byte ends both the comment and the line of code. */ if(byte == 0x00) break; if(printing) putc(byte, outfile); - } else if(byte == ':') { + continue; + } + + if(was_colon && byte != TOK_SQUOTE && byte != TOK_BANG) { + if(printing) putc(':', outfile); + was_colon = 0; + } + + if(byte == ':') { /* don't print the colon if the next token is a ! or ' for a comment */ - unsigned char next = read_prog_byte(); - if( !(next == TOK_SQUOTE || next == TOK_BANG) ) - if(printing) putc(byte, outfile); - unread_prog_byte(next); + was_colon = 1; } else if(byte == '"') { /* strings start but *don't end* with a double-quote */ in_string = 1; |