aboutsummaryrefslogtreecommitdiff
path: root/listbas.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-06-25 21:45:47 -0400
committerB. Watson <urchlay@slackware.uk>2024-06-25 21:46:05 -0400
commit5ea1671fc34f2262cd11e1188f19fc2ed8da3cef (patch)
treee18756518912566a4ae963a382369fb41211c5ad /listbas.c
parentec5d94be4d5bf775599f67875e07da869b9c1834 (diff)
downloadbw-atari8-tools-5ea1671fc34f2262cd11e1188f19fc2ed8da3cef.tar.gz
listbas: rearrange some code; chkbas: get rid of listbas symlink.
Diffstat (limited to 'listbas.c')
-rw-r--r--listbas.c92
1 files changed, 37 insertions, 55 deletions
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();