diff options
author | B. Watson <urchlay@slackware.uk> | 2024-04-23 22:28:28 -0400 |
---|---|---|
committer | B. Watson <urchlay@slackware.uk> | 2024-04-23 22:28:28 -0400 |
commit | 140ced429cba74084d65942840b1f97fc77d8d9b (patch) | |
tree | 94c26f67f46d4cffe6c3265dde192cfd7fc9ccba | |
parent | 046326dc430a15b675eff425ddd31d1ceb0fe916 (diff) | |
download | bw-atari8-tools-140ced429cba74084d65942840b1f97fc77d8d9b.tar.gz |
a8utf8: add -r (reverse) option.
-rwxr-xr-x | a8utf8 | 11 | ||||
-rw-r--r-- | a8utf8.1 | 21 | ||||
-rw-r--r-- | a8utf8.rst | 19 |
3 files changed, 35 insertions, 16 deletions
@@ -121,6 +121,7 @@ while(@ARGV && $ARGV[0] =~ /^-/) { for($ARGV[0]) { /^-i$/ && do { $table = \%xl_intl_table; next; }; /^-t$/ && do { $print_table = 1; next; }; + /^-r$/ && do { $reverse = 1; next; }; /^--?h/ && do { usage(0) }; warn "$SELF: unknown option: $_\n"; usage(1); @@ -128,6 +129,14 @@ while(@ARGV && $ARGV[0] =~ /^-/) { shift @ARGV; } +if($reverse) { + binmode(STDOUT, ":bytes"); + for(keys %$table) { + $revtable{ord($table->{$_})} = chr($_); + } + $table = \%revtable; +} + if($print_table) { for(sort { $a <=> $b } keys %$table) { my $chr = translate(chr $_); @@ -156,7 +165,7 @@ sub translate { sub usage { print <<EOF; -Usage: $SELF [--help] | [-t [-i]] | [-i] infile [infile ...] +Usage: $SELF [--help] | [-t [-r] [-i]] | [-r] [-i] infile [infile ...] See man page for details. EOF exit $_[0]; @@ -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 "A8UTF8" 1 "2022-08-27" "0.2.0" "Urchlay's Atari 8-bit Tools" +.TH "A8UTF8" 1 "2024-04-23" "0.2.1" "Urchlay's Atari 8-bit Tools" .SH NAME a8utf8 \- Convert Atari 8-bit text to UTF-8 encoded Unicode. .\" RST source for a8utf8(1) man page. Convert with: @@ -38,15 +38,15 @@ a8utf8 \- Convert Atari 8-bit text to UTF-8 encoded Unicode. . .SH SYNOPSIS .sp -\fIa8utf8\fP [\fB\-i\fP] [\fIinfile\fP] [\fIinfile ...\fP] +\fIa8utf8\fP [\fB\-r\fP] [\fB\-i\fP] [\fIinfile\fP] [\fIinfile ...\fP] .sp -\fIa8utf8\fP [\fB\-i\fP] \fB\-t\fP +\fIa8utf8\fP [\fB\-r\fP] [\fB\-i\fP] \fB\-t\fP .SH DESCRIPTION .sp -Convert Atari 8\-bit ATASCII or International Character Set text to -UTF\-8 encoded Unicode. Control graphics characters are replaced with -their nearest Unicode equivalents (mostly from the Box Drawing block, -or from the Basic Latin block with \fB\-i\fP option). +Convert Atari 8\-bit ATASCII or XL ICS (International Character +Set) text to UTF\-8 encoded Unicode. Control graphics characters are +replaced with their nearest Unicode equivalents (mostly from the Box +Drawing block, or from the Basic Latin block with \fB\-i\fP option). .sp If no \fIinfile\fP is given, input is read from standard input. Output always goes to standard output; to write to a file, use a command like: @@ -75,7 +75,12 @@ ATASCII graphics. .TP .B \-t Print table of Atari to Unicode equivalents, in CSV format. Can -be used with or without \fB\-i\fP (two different tables). +be used with or without \fB\-i\fP and/or \fB\-r\fP (four different tables). +.TP +.B \-r +Reverse conversion: Input is UTF\-8, output is ATASCII (or XL ICS, with \fB\-i\fP). +Beware that printing ATASCII to a terminal may look funny, and may even confuse +the terminal. Redirecting to a file is safe. .UNINDENT .SH COPYRIGHT .sp @@ -15,17 +15,17 @@ Convert Atari 8-bit text to UTF-8 encoded Unicode. SYNOPSIS ======== -*a8utf8* [**-i**] [*infile*] [*infile ...*] +*a8utf8* [**-r**] [**-i**] [*infile*] [*infile ...*] -*a8utf8* [**-i**] **-t** +*a8utf8* [**-r**] [**-i**] **-t** DESCRIPTION =========== -Convert Atari 8-bit ATASCII or International Character Set text to -UTF-8 encoded Unicode. Control graphics characters are replaced with -their nearest Unicode equivalents (mostly from the Box Drawing block, -or from the Basic Latin block with **-i** option). +Convert Atari 8-bit ATASCII or XL ICS (International Character +Set) text to UTF-8 encoded Unicode. Control graphics characters are +replaced with their nearest Unicode equivalents (mostly from the Box +Drawing block, or from the Basic Latin block with **-i** option). If no *infile* is given, input is read from standard input. Output always goes to standard output; to write to a file, use a command like:: @@ -47,6 +47,11 @@ OPTIONS -t Print table of Atari to Unicode equivalents, in CSV format. Can - be used with or without **-i** (two different tables). + be used with or without **-i** and/or **-r** (four different tables). + +-r + Reverse conversion: Input is UTF-8, output is ATASCII (or XL ICS, with **-i**). + Beware that printing ATASCII to a terminal may look funny, and may even confuse + the terminal. Redirecting to a file is safe. .. include:: manftr.rst |