aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xa8utf811
-rw-r--r--a8utf8.121
-rw-r--r--a8utf8.rst19
3 files changed, 35 insertions, 16 deletions
diff --git a/a8utf8 b/a8utf8
index f5f2df7..0cca2ac 100755
--- a/a8utf8
+++ b/a8utf8
@@ -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];
diff --git a/a8utf8.1 b/a8utf8.1
index 3ff998f..2a7bec4 100644
--- a/a8utf8.1
+++ b/a8utf8.1
@@ -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
diff --git a/a8utf8.rst b/a8utf8.rst
index 2d36193..ec9fbba 100644
--- a/a8utf8.rst
+++ b/a8utf8.rst
@@ -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