diff options
-rw-r--r-- | listamsb.c | 13 |
1 files changed, 10 insertions, 3 deletions
@@ -99,6 +99,8 @@ void die_with(const char *msg, int status) { #define die(x) die_with(x,1) #define die2(x) die_with(x,2) +/* post-processing: print "summary", exit. called by either read_byte() + (on 'unexpected EOF'), or main() (on normal exit). */ void finish(int rv, const char *msg) { if(msg) fprintf(stderr, "%s: %s\n", self, msg); @@ -230,6 +232,9 @@ void unknown_token(int lineno, unsigned char byte, int ext) { fprintf(outfile, "%s%02x>", (ext ? "$ff ": ""), byte); } +/* meat and potatoes. does the actual detokenizing. gets called once + per line of code. returns false when it hits the last line, or + true if there are more lines. */ int next_line(void) { static int last_lineno = -1; static int last_ptr = -1; @@ -390,7 +395,9 @@ int next_line(void) { /* when this gets called, input and output are open, read_header() has already run. "locking" and "unlocking" are the same - transform, so this function does both. */ + transform, so this function does both. + note that *no* checking of the program code is done here, so + there's no need to finish() afterwards. */ void unlock_program(void) { int c; @@ -407,8 +414,8 @@ void unlock_program(void) { /* rest of file, including trailing nulls, is transformed */ while( (c = fgetc(infile)) >= 0) fputc(unlock_byte(c & 0xff), outfile); - fclose(outfile); + fclose(outfile); exit(0); } @@ -559,7 +566,7 @@ int main(int argc, char **argv) { if(unlock_mode) { unlock_program(); - exit(0); + exit(0); /* don't need finish() here, no parsing done */ } while(next_line()) |