From 5ea1671fc34f2262cd11e1188f19fc2ed8da3cef Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Tue, 25 Jun 2024 21:45:47 -0400 Subject: listbas: rearrange some code; chkbas: get rid of listbas symlink. --- listbas.c | 92 +++++++++++++++++++++++++-------------------------------------- 1 file changed, 37 insertions(+), 55 deletions(-) (limited to 'listbas.c') diff --git a/listbas.c b/listbas.c index bc56695..2cb9dcc 100644 --- a/listbas.c +++ b/listbas.c @@ -45,6 +45,40 @@ void parse_args(int argc, char **argv) { open_input(argv[optind]); } +void setup_outfh(void) { + const char *cmd; + + /* search current dir before PATH. no easy way to detect errors here, + have to wait until we call pclose(). */ + if(a8eol) { + cmd = "./a8eol -u -c 2>/dev/null || a8eol -u -c 2>/dev/null || exit 1"; + } else if(a8utf8) { + cmd = "./a8utf8 2>/dev/null || a8utf8 2>/dev/null || exit 1"; + } else { + if(isatty(fileno(stdout))) { + die("Refusing to write ATASCII data to the terminal."); + } + outfh = stdout; + return; + } + + outfh = popen(cmd, "w"); + if(!outfh) { + /* fork() or pipe() failed. does NOT detect if the command + wasn't found. */ + perror(self); + exit(1); + } +} + +void close_outfh(void) { + if(a8eol || a8utf8) { + if(pclose(outfh)) { + die("output filter failed; a8eol or a8utf8 not in current dir or $PATH."); + } + } +} + void outchr(char c) { putc(c, outfh); } @@ -89,27 +123,17 @@ CALLBACK(print_lineno) { } CALLBACK(print_cmd) { - int bad; const char *name; if(tok == CMD_ILET) return; - if(tok > last_command) { - bad = 1; - } else if( (name = commands[tok]) ) { - bad = 0; - } else { - bad = 1; - } - - if(bad) - fprintf(outfh, "(bad cmd token $%02x)", tok); + if(tok > last_command || (!(name = commands[tok]))) + fprintf(outfh, "(bad cmd token $%02x) ", tok); else fprintf(outfh, "%s ", name); } CALLBACK(print_op) { - int bad; const char *name; switch(tok) { @@ -125,15 +149,7 @@ CALLBACK(print_op) { } - if(tok > last_operator) { - bad = 1; - } else if( (name = operators[tok]) ) { - bad = 0; - } else { - bad = 1; - } - - if(bad) + if(tok > last_operator || (!(name = operators[tok]))) fprintf(outfh, "(bad op token $%02x)", tok); else fprintf(outfh, "%s", name); @@ -162,40 +178,6 @@ CALLBACK(print_newline) { outchr(0x9b); } -void setup_outfh(void) { - const char *cmd; - - /* search current dir before PATH. no easy way to detect errors here, - have to wait until we call pclose(). */ - if(a8eol) { - cmd = "./a8eol -u -c 2>/dev/null || a8eol -u -c 2>/dev/null || exit 1"; - } else if(a8utf8) { - cmd = "./a8utf8 2>/dev/null || a8utf8 2>/dev/null || exit 1"; - } else { - if(isatty(fileno(stdout))) { - die("Refusing to write ATASCII data to the terminal."); - } - outfh = stdout; - return; - } - - outfh = popen(cmd, "w"); - if(!outfh) { - /* fork() or pipe() failed. does NOT detect if the command - wasn't found. */ - perror(self); - exit(1); - } -} - -void close_outfh(void) { - if(a8eol || a8utf8) { - if(pclose(outfh)) { - die("output filter failed; a8eol or a8utf8 not in current dir or $PATH."); - } - } -} - CALLBACK(code_prot) { fprintf(stderr, "%s: Program is code-protected, stopping at line %d.\n", self, lineno); close_outfh(); -- cgit v1.2.3