From b369e07e3c59f6b046d3e0f74803fe2f6a764f04 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Wed, 5 Mar 2025 02:05:54 -0500 Subject: listamsb: allow giving an output filename. --- listamsb.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'listamsb.c') diff --git a/listamsb.c b/listamsb.c index a289eca..88c465a 100644 --- a/listamsb.c +++ b/listamsb.c @@ -94,6 +94,8 @@ int printing = 0; FILE *infile; FILE *outfile; +const char *outname = NULL; + void verbose(int level, const char *fmt, ...) { va_list ap; @@ -472,7 +474,7 @@ void unlock_program(void) { void print_help(void) { printf("%s v" VERSION " - detokenize Atari Microsoft BASIC files\n", self); puts("By B. Watson , released under the WTFPL"); - printf("Usage: %s [[-l] | [-a] [-v] [-h] [-i] [-n] [-u] [-t] [-m] [-s] [-r *start,end*]] [file]\n", self); + printf("Usage: %s [[-l] | [-[avhinutms] ... ] [-r *start,end*]] \n", self); puts(" -a: raw ATASCII output"); puts(" -c: check only (no listing)"); puts(" -l: lock or unlock program"); @@ -483,6 +485,7 @@ void print_help(void) { puts(" --version: print version number and exit"); puts(" -i -u -t -m -s: passed to a8cat (try 'a8cat -h')"); puts("file must be a tokenized (SAVEd) AMSB file. if not given, reads from stdin."); + puts("if outfile not given, writes to stdout (via pipe to a8cat)"); } void version(void) { @@ -570,6 +573,17 @@ void parse_args(int argc, char **argv) { os_err("%s: %s", argv[optind], strerror(errno)); } } + + optind++; + if(optind < argc) { + /* we were passed an output file */ + outname = argv[optind]; + if(check_only) + os_err("can't use output filename %s with -c", outname); + if(!freopen(outname, "wb", stdout)) + os_err("%s: %s", outname, strerror(errno)); + verbose(1, "redirected stdout to %s", outname); + } } void open_output() { -- cgit v1.2.3