aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-02-25 04:43:28 -0500
committerB. Watson <urchlay@slackware.uk>2025-02-25 04:43:28 -0500
commit6c7534fdf870f171125ca7845b2b7493b0379a05 (patch)
tree25dd9482e6177df68cd98c008af78d5b7ea8c122
parente80e3d541059c8bec0bd18bbd35b23dcb236f591 (diff)
downloadbw-atari8-tools-6c7534fdf870f171125ca7845b2b7493b0379a05.tar.gz
listamsb: swallow colon before ! or ', exit w/status 2 if invalid tokens.
-rw-r--r--TODO5
-rw-r--r--listamsb.c24
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, "<unknown %stoken ", (ext ? "extended " : ""));
fprintf(outfile, "%s%02x>", (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);
}