diff options
Diffstat (limited to 'abas2html')
| -rwxr-xr-x | abas2html | 109 | 
1 files changed, 109 insertions, 0 deletions
diff --git a/abas2html b/abas2html new file mode 100755 index 0000000..6da890f --- /dev/null +++ b/abas2html @@ -0,0 +1,109 @@ +#!/bin/sh + +# this is supposed to be POSIX sh compliant. their getopts docs: +# https://pubs.opengroup.org/onlinepubs/9699919799/utilities/getopts.html + +SELF="$( echo $0 | sed 's,.*/,,' )" + +die() { +	echo "$SELF: $1" >& 2 +	exit 1 +} + +checkbin() { +	if ! which "$1" >/dev/null 2>/dev/null; then +		die "$1 not found on PATH, can't continue" +	fi +} + +print_help() { +	cat <<EOF +$SELF: convert tokenized Atari BASIC to HTML +B. Watson <urchlay@slackware.uk>, WTFPL +Usage: $SELF -a<aha-options> -b<basver> -m input.bas <output.html> +  -a   next option is passed to aha(1). may be used multiple times. +  -b   set BASIC dialect. default is autodetection. valid dialects: +       -ba   Atari 8K BASIC +       -ba+  OSS BASIC/A+ +       -bm   Atari Microsoft BASIC +       -bt   Turbo BASIC XL +       -bxl  OSS BASIC XL +       -bxe  OSS BASIC XE +       -bic  OSS Integer BASIC (cartridge version) +       -bid  OSS Integer BASIC (disk version) +  -m   monochrome: disable color syntax highlighting. +if output filename is missing, it defaults to the input filename, with +the extension changed to .html (e.g. FOO.BAS => FOO.html). +EOF +	exit $1 +} + +# main() +if [ "$*" = "--help" ]; then +	print_help 0 +fi + +while getopts ":hb:a:mMn" opt; do +	case "$opt" in +		b)   BASVER="$OPTARG"              ;; +		a)   AHA_OPTS="$AHA_OPTS $OPTARG"  ;; +		m|M|n) MONO="1"                    ;; +		h)   print_help 0                  ;; +		*)   die "invalid option -$OPTARG" ;; +	esac +done + +shift $(($OPTIND - 1)) + +if [ -z "$1" ]; then +	die "no input file given (try -h)" +else +	infile="$1" +fi + +if [ -n "$2" ]; then +	outfile="$2" +else +	outfile="$( echo "$infile" | sed 's,\.[^.]*$,.html,' )" +	if [ "$infile" = "$outfile" ]; then +		outfile="$infile".html +	fi +fi + +if [ "$BASVER" = "" ]; then +	checkbin whichbas +	whichbas -s "$infile" +	case "$?" in +		3)       BASVER="a"  ;; +		4|7|8|9) BASVER="t"  ;; +		5)       BASVER="xl" ;; +		6|12)    BASVER="xe" ;; +		11)      BASVER="m"  ;; +		14)      BASVER="a+" ;; +		15)      BASVER="ic" ;; +		16)      BASVER="id" ;; +		*)       die "can't detect BASIC dialect; use -b<xx> option" ;; +	esac +fi + +case "$BASVER" in +	m)                  LISTER=listamsb ; BASVER=""          ;; +	a|t|xl|xe|a+|id|ic) LISTER=listbas  ; BASVER="-b$BASVER" ;; +	*) die "$BASVER not a valid BASIC dialect"         ;; +esac + +checkbin $LISTER +checkbin aha +if [ "$LISTER" = "listamsb" ]; then +	if [ "$MONO" = "1" ]; then +		MONO_OPT="-M" +	else +		checkbin "${COLORIZE_AMSB:-colorize-amsb}" +	fi +else +	if [ "$MONO" = "1" ]; then +		MONO_OPT="-n" +	fi +fi + +exec $LISTER $BASVER $MONO_OPT "$infile" | aha -t "$infile" $AHA_OPTS > "$outfile"  | 
