From 6c7534fdf870f171125ca7845b2b7493b0379a05 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 25 Feb 2025 04:43:28 -0500 Subject: listamsb: swallow colon before ! or ', exit w/status 2 if invalid tokens. --- TODO | 5 ----- listamsb.c | 24 ++++++++++++++---------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/TODO b/TODO index a9a7e8c..d76feb6 100644 --- a/TODO +++ b/TODO @@ -1,10 +1,5 @@ for now: -listamsb: -- don't display the colon before a ! or ' comment that appears - as the 2nd or later statement on a line. -- actually exit with status 2 if there were uknown tokens. - fauxtari: - Figure out why fauxtari doesn't show up in font-selections dialogs in xfc4-terminal, gnome-terminal; also it doesn't diff --git a/listamsb.c b/listamsb.c index 6890d37..a8a3e86 100644 --- a/listamsb.c +++ b/listamsb.c @@ -24,6 +24,7 @@ int raw_output = 0; int need_pclose = 0; int bytes_read = 0; +int unknowns = 0; FILE *infile; FILE *outfile; @@ -77,12 +78,13 @@ int read_header(void) { } void unknown_token(int lineno, unsigned char byte, int ext) { + unknowns++; fprintf(outfile, "", (ext ? "ff ": ""), byte); } int next_line(void) { - int ptr, lineno, was_ff, in_string, start; + int ptr, lineno, was_ff, in_string; unsigned char byte; /* pointer to last token on the line, offset by whatever MEMLO @@ -105,20 +107,11 @@ int next_line(void) { was_ff = 0; in_string = 0; - start = 1; /* walk and print the tokens. when we hit a null byte, we're done. */ while(1) { byte = read_byte(); - /* lines that consist entirely of a comment introduced with a - single-quote or exclamation point have a : before the comment - start character. don't print it. */ - if(start) { - start = 0; - if(byte == ':') continue; - } - if(in_string) { if(byte == 0x00 || byte == '|') { /* end of string */ @@ -134,6 +127,12 @@ int next_line(void) { } } putc(byte, outfile); + } else if(byte == ':') { + /* don't print the colon if the next token is a ! or ' for a comment */ + unsigned char next = read_byte(); + if( !(next == 0x9a || next == 0x9b) ) + putc(byte, outfile); + ungetc(next, infile); } else if(byte == '"') { /* strings start but *don't end* with a double-quote */ in_string = 1; @@ -247,5 +246,10 @@ int main(int argc, char **argv) { if(need_pclose) pclose(outfile); + if(unknowns) { + fprintf(stderr, "%s: input has %d unknown tokens\n", self, unknowns);; + exit(2); + } + exit(0); } -- cgit v1.2.3