diff options
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | listamsb.1 | 47 | ||||
| -rw-r--r-- | listamsb.c | 82 | ||||
| -rw-r--r-- | listamsb.rst | 42 | 
4 files changed, 94 insertions, 79 deletions
@@ -79,6 +79,8 @@ bas2aplus: bas.o  listbas: listbas.c bas.o bcdfp.o tokens.o atables.o turbo_tokens.o aplus_tokens.o bxl_tokens.o bxe_tokens.o int_disk_tokens.o int_tokens.o  	$(CC) $(CFLAGS) -o listbas listbas.c bas.o bcdfp.o tokens.o atables.o turbo_tokens.o aplus_tokens.o bxl_tokens.o bxe_tokens.o int_disk_tokens.o int_tokens.o -lm +listamsb: listamsb.o atascii.o atables.o +  bas.o: bas.c bas.h  wtable.o: wtable.c wtable.h @@ -27,7 +27,7 @@ level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]  .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]  .in \\n[rst2man-indent\\n[rst2man-indent-level]]u  .. -.TH "LISTAMSB" 1 "2025-03-17" "0.2.2" "Urchlay's Atari 8-bit Tools" +.TH "LISTAMSB" 1 "2025-04-01" "0.2.2" "Urchlay's Atari 8-bit Tools"  .SH NAME  listamsb \- List the source of a tokenized Atari Microsoft BASIC program  .SH SYNOPSIS @@ -57,14 +57,14 @@ If no \fBoutput\-file\fP is given, output is to \fBstdout\fP\&. When output  is to a file, the file will be overwritten without prompting if it  already exists.  .sp -When listing a program to \fBstdout\fP, output is piped through -\fBa8cat\fP(1), which converts the ATASCII output to UTF\-8 that\(aqs -human\-readable on modern terminals. This means \fBa8cat\fP must be -available in your \fBPATH\fP\&. If this is not convenient, you can set -the location of \fBa8cat\fP via the \fBA8CAT\fP environment variable. -When listing in color (when the \fB\-M\fP option is not used), \fBa8cat\fP\(aqs -output is piped through \fBcolorize\-amsb\fP, which also must be available -in your \fBPATH\fP\&. +By default, output is modern UTF\-8 equivalents of the ATASCII +character set, with ANSI control sequences for inverse video and +color. See the \fB\-M\fP, \fB\-a\fP, \fB\-i\fP, \fB\-u\fP, \fB\-t\fP, \fB\-m\fP, \fB\-s\fP +options to change the output style. +.sp +When listing in color (when the \fB\-M\fP option is not used), +\fBlistamsb\fP\(aqs output is piped through \fBcolorize\-amsb\fP, which must +be available in your \fBPATH\fP\&.  .sp  \fBlistamsb\fP will not write binary data (ATASCII or tokenized BASIC)  directly to a terminal, under any circumstances. @@ -121,15 +121,28 @@ or \fB\-U\fP\&.  .B \fB\-a\fP  Output raw ATASCII. This option must be used with an  \fBoutput\-file\fP, a pipe, or redirection: \fBlistamsb\fP will not write -ATASCII to a terminal. \fBa8cat\fP and \fBcolorize\-amsb\fP are not used, with this option. +ATASCII to a terminal. \fBcolorize\-amsb\fP is not used, with this option.  .TP  .B \fB\-c\fP  Check only. No output on \fBstdout\fP\&. Diagnostics are still printed on stderr,  and the exit status is unchanged. It\(aqs an error to give an \fBoutput\-file\fP with  this option.  .TP -.B \fB\-i\fP, \fB\-u\fP, \fB\-t\fP, \fB\-m\fP, \fB\-s\fP -These options are passed to \fBa8cat\fP\&. See its man page for details. +.B \fB\-i\fP +Input uses Atari XL/XE International Character Set encoding, rather than +ATASCII graphics. +.TP +.B \fB\-u\fP +Use underlining for inverse video (see \fBa8cat\fP(1) for more detail). +.TP +.B \fB\-t\fP +Text mode (see \fBa8cat\fP(1) for more detail). +.TP +.B \fB\-m\fP +Magazine listing mode (see \fBa8cat\fP(1) for more detail). +.TP +.B \fB\-s\fP +Strip bit 7 (inverse video bit; see \fBa8cat\fP(1) for more detail).  .TP  .B \fB\-M\fP  Monochrome listing: disable color syntax highlighting, meaning \fBcolorize\-amsb\fP @@ -282,16 +295,6 @@ you see this warning, you\(aqll also see \fIN\fP <unknown token \fIXX\fP>  messages in the actual listing.  .UNINDENT  .SH ENVIRONMENT -.sp -\fBA8CAT\fP -.INDENT 0.0 -.INDENT 3.5 -The path to the \fBa8cat\fP(1) binary. Can be a full path or just -the executable name, in which case it will be searched for with the -normal \fBPATH\fP mechanism. If not set, \fIa8cat\fP is used. If there are -spaces or other metacharacters, they must be escaped. -.UNINDENT -.UNINDENT  .SH LIMITATIONS  .sp  \fBlistamsb\fP may behave strangely when fed something other than a @@ -7,6 +7,7 @@  #include <ctype.h>  #include <sys/stat.h> +#include "atascii.h"  #include "amsbtok.h"  /* this should always be defined in <stdio.h>, but just in case... */ @@ -80,7 +81,7 @@  const char *self; -char pipe_command[BUFSIZ + 1] = { "a8cat" }; +atascii_ctx actx;  int verbosity =   0;           /* -v */  int raw_output =  0;           /* -a */ @@ -198,7 +199,7 @@ void finish(int rv) {  		int got = pclose(outfile);  		verbose(1, "return value from pipe is %d", got);  		if(got != 0) { -			os_err("a8cat child process failed, do you have a8cat on your PATH?"); +			os_err("colorize-amsb child process failed, do you have it on your PATH?");  		}  	} else {  		fclose(outfile); @@ -301,7 +302,13 @@ void unknown_token(int tok) {  }  void list_char(unsigned char c) { -	if(printing) fputc(c, outfile); +	if(!printing) return; +	if(raw_output) { +		fputc(c, outfile); +	} else { +		char buf[20]; +		fputs(atascii_a2utf(&actx, c, buf), outfile); +	}  }  int expand_token(int t, unsigned char *buf); @@ -324,7 +331,13 @@ void list_lineno(int l) {  void start_listing(void) {  	/* AMSB always prints a blank line when it LISTs, so we do, too.  	   unless it's disabled with -n, of course. */ -	if(initial_eol) fputc(EOL, outfile); +	if(initial_eol) { +		if(raw_output) { +			fputc(0x9b, outfile); +		} else { +			fputc('\n', outfile); +		} +	}  }  int read_token(int literal); @@ -466,6 +479,11 @@ int next_line(void) {  	list_char(EOL); +	if(!raw_output && (actx.inv)) { +		char buf[20]; +		fputs(atascii_a2utf(&actx, ATA_CHR_FINISH, buf), outfile); +	} +  	return 1;  } @@ -808,9 +826,9 @@ void print_help(void) {  	puts("  -r: only list lines numbered from *start* to *end*");  	puts("  --help, -h: print this help and exit");  	puts("  --version:  print version number and exit"); -	puts("  -i -u -t -m -s: passed to a8cat (try 'a8cat -h')"); +	puts("  -i -u -t -m -s: same as 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)"); +	puts("if outfile not given, writes to stdout");  }  void version(void) { @@ -849,14 +867,8 @@ void get_line_range(const char *arg) {  }  void parse_args(int argc, char **argv) { -	const char *a8cat; -	char tmp[10]; -	int opt, a8catopt = 0, ropt = 0; - -	a8cat = getenv("A8CAT"); -	if(!a8cat) a8cat = "a8cat"; - -	strncpy(pipe_command, a8cat, BUFSIZ); +	int opt, ropt = 0; +	int ata_mode = ATA_MODE_UTF8, ata_flags = ATA_FLAG_NONE, a8catopt = 0;  	if(argc >= 2) {  		if(strcmp(argv[1], "--help") == 0) { @@ -883,17 +895,11 @@ void parse_args(int argc, char **argv) {  			case 'M': color =       0; break;  			case 'h': print_help(); exit(0);  			case 'r': get_line_range(optarg); ropt++; break; -			case 'i': -			case 'u': -			case 't': -			case 'm': -			case 's': -				a8catopt++; -				if(strlen(pipe_command) > (BUFSIZ - 10)) -					os_err("too many a8cat options"); -				sprintf(tmp, " -%c", opt); -				strcat(pipe_command, tmp); -				break; +			case 'i': ata_flags |= ATA_FLAG_ICS; a8catopt++; break; +			case 'u': ata_flags |= ATA_FLAG_UNDERLINE; a8catopt++; break; +			case 't': ata_flags |= ATA_FLAG_ICS; a8catopt++; break; +			case 'm': ata_mode = ATA_MODE_MAGAZINE; a8catopt++; break; +			case 's': ata_flags |= ATA_FLAG_STRIP_INVERSE; a8catopt++; break;  			default: print_help(); exit(1);  		}  	} @@ -910,6 +916,8 @@ void parse_args(int argc, char **argv) {  		if(!initial_eol || check_only || raw_output || ropt || a8catopt || !color) {  			warn("-[acimMnrstu] options ignored with -U, -C, or -D");  		} +	} else if(!raw_output) { +		atascii_context_init(&actx, ata_mode, ata_flags);  	}  	if(optind >= argc) { @@ -956,22 +964,18 @@ void open_output() {  		outfile = stdout;  		verbose(1, "using stdout for output");  	} else { -		const char *a8cat; -		if((a8cat = getenv("A8CAT"))) { -			verbose(1, "read A8CAT=%s from environment", a8cat); +		if(color) { +			verbose(1, "using pipe for output: %s", "colorize-amsb"); +			outfile = popen("colorize-amsb", "w"); /* "wb" not allowed! */ +			/* we probably never see this error. popen() fails only if +				we feed it an invalid mode, or if fork() or pipe() fails, +				or I suppose if some idjit has done a "rm -f /bin/sh"... +				all other errors are caught at pclose(). */ +			if(!outfile) os_err("|%s: %s", "colorize-amsb", strerror(errno)); +			need_pclose = 1;  		} else { -			verbose(1, "A8CAT not set in environment, using 'a8cat'"); +			outfile = stdout;  		} -		if(color) -			strcat(pipe_command, " | colorize-amsb"); -		verbose(1, "using pipe for output: %s", pipe_command); -		outfile = popen(pipe_command, "w"); /* "wb" not allowed! */ -		/* we probably never see this error. popen() fails only if -		   we feed it an invalid mode, or if fork() or pipe() fails, -		   or I suppose if some idjit has done a "rm -f /bin/sh"... -		   all other errors are caught at pclose(). */ -		if(!outfile) os_err("|%s: %s", pipe_command, strerror(errno)); -		need_pclose = 1;  	}  } diff --git a/listamsb.rst b/listamsb.rst index 3753bdf..2a86a23 100644 --- a/listamsb.rst +++ b/listamsb.rst @@ -38,14 +38,14 @@ If no **output-file** is given, output is to **stdout**. When output  is to a file, the file will be overwritten without prompting if it  already exists. -When listing a program to **stdout**, output is piped through -**a8cat**\(1), which converts the ATASCII output to UTF-8 that's -human-readable on modern terminals. This means **a8cat** must be -available in your **PATH**\. If this is not convenient, you can set -the location of **a8cat** via the **A8CAT** environment variable. -When listing in color (when the **-M** option is not used), **a8cat**\'s -output is piped through **colorize-amsb**, which also must be available -in your **PATH**\. +By default, output is modern UTF-8 equivalents of the ATASCII +character set, with ANSI control sequences for inverse video and +color. See the **-M**, **-a**, **-i**, **-u**, **-t**, **-m**, **-s** +options to change the output style. + +When listing in color (when the **-M** option is not used), +**listamsb**\'s output is piped through **colorize-amsb**, which must +be available in your **PATH**\.  **listamsb** will not write binary data (ATASCII or tokenized BASIC)  directly to a terminal, under any circumstances. @@ -105,15 +105,28 @@ or **-U**.  **-a**    Output raw ATASCII. This option must be used with an    **output-file**, a pipe, or redirection: **listamsb** will not write -  ATASCII to a terminal. **a8cat** and **colorize-amsb** are not used, with this option. +  ATASCII to a terminal. **colorize-amsb** is not used, with this option.  **-c**    Check only. No output on **stdout**. Diagnostics are still printed on stderr,    and the exit status is unchanged. It's an error to give an **output-file** with    this option. -**-i**\, **-u**\, **-t**\, **-m**\, **-s** -  These options are passed to **a8cat**. See its man page for details. +**-i** +  Input uses Atari XL/XE International Character Set encoding, rather than +  ATASCII graphics. + +**-u** +  Use underlining for inverse video (see **a8cat**\(1) for more detail). + +**-t** +  Text mode (see **a8cat**\(1) for more detail). + +**-m** +  Magazine listing mode (see **a8cat**\(1) for more detail). + +**-s** +  Strip bit 7 (inverse video bit; see **a8cat**\(1) for more detail).  **-M**    Monochrome listing: disable color syntax highlighting, meaning **colorize-amsb** @@ -270,13 +283,6 @@ continues processing.  ENVIRONMENT  =========== -**A8CAT** - -  The path to the **a8cat**\(1) binary. Can be a full path or just -  the executable name, in which case it will be searched for with the -  normal **PATH** mechanism. If not set, *a8cat* is used. If there are -  spaces or other metacharacters, they must be escaped. -  LIMITATIONS  ===========  | 
