aboutsummaryrefslogtreecommitdiff
path: root/listamsb.c
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-03-05 02:05:54 -0500
committerB. Watson <urchlay@slackware.uk>2025-03-05 02:05:54 -0500
commitb369e07e3c59f6b046d3e0f74803fe2f6a764f04 (patch)
tree8d12676d618359524676608fb0975b0ec4f67a9d /listamsb.c
parent29cb89aa668fcfe10a29561314a1f3e7ec8ea019 (diff)
downloadbw-atari8-tools-b369e07e3c59f6b046d3e0f74803fe2f6a764f04.tar.gz
listamsb: allow giving an output filename.
Diffstat (limited to 'listamsb.c')
-rw-r--r--listamsb.c16
1 files changed, 15 insertions, 1 deletions
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 <urchlay@slackware.uk>, 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*]] <file> <outfile>\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() {