aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2024-07-01 18:03:27 -0400
committerB. Watson <urchlay@slackware.uk>2024-07-01 18:03:27 -0400
commit2926604dc6651711ab525ab5fd84762748ce51ff (patch)
tree5fdbbbcc751a7eee25e5a0ddac1b3568a7525031
parent77bdfd18057d87d3af870a6099865d8fa8bb980a (diff)
downloadbw-atari8-tools-2926604dc6651711ab525ab5fd84762748ce51ff.tar.gz
a8cat: refuse to write ATASCII to a terminal; swallow \r in -r mode.
-rw-r--r--a8cat.119
-rw-r--r--a8cat.c5
-rw-r--r--a8cat.rst17
3 files changed, 28 insertions, 13 deletions
diff --git a/a8cat.1 b/a8cat.1
index 30f96d0..8c47e9c 100644
--- a/a8cat.1
+++ b/a8cat.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 "A8CAT" 1 "2024-06-29" "0.2.1" "Urchlay's Atari 8-bit Tools"
+.TH "A8CAT" 1 "2024-07-01" "0.2.1" "Urchlay's Atari 8-bit Tools"
.SH NAME
a8cat \- Convert Atari 8-bit text to UTF-8 encoded Unicode (and back).
.SH SYNOPSIS
@@ -87,12 +87,17 @@ Unicode graphics character. In text mode, ATASCII tabs, backspace,
and bells are translated to the ASCII versions.
.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; piping
-to a pager usually is. Only the UTF\-8 codepoints that correspond to
-ATASCII characters will be converted. If the \fB\-i\fP option was used to
-create the input, it must be used with \fB\-r\fP also.
+Reverse conversion: Input is plain text, or UTF\-8 created by a previous
+run of \fBa8cat\fP; output is ATASCII (or XL ICS, with \fB\-i\fP). ASCII
+tabs, backspaces, and newlines will be coverted to the ATASCII
+equivalent. ASCII carriage returns will be silently ignored.
+.sp
+Only the UTF\-8 codepoints that correspond to ATASCII characters will
+be converted. If the \fB\-i\fP option was used to create the input, it
+must be used with \fB\-r\fP also.
+.sp
+\fBa8cat\fP will refuse to print ATASCII to a terminal. You must
+redirect or pipe the output.
.TP
.B \-m
Magazine listing mode. Rather than Unicode graphics characters,
diff --git a/a8cat.c b/a8cat.c
index e4a88bb..76ec67a 100644
--- a/a8cat.c
+++ b/a8cat.c
@@ -94,6 +94,8 @@ int a8revcat(const char *file) {
while( (c = fgetwc(input)) != WEOF ) {
if(c == 0x1b) {
inv = handle_escape_seq(inv, input, file, line);
+ } else if(c == '\r') {
+ continue; /* swallow carriage returns */
} else if(c == '\n') {
putchar(0x9b);
line++;
@@ -254,6 +256,9 @@ int main(int argc, char **argv) {
}
if(reverse) {
+ if(isatty(fileno(stdout)))
+ die("Refusing to write ATASCII to a terminal.");
+
if(underline || textmode || stripinv || magazine) {
die("-t, -u, -m, -s options don't make sense with -r.\n");
}
diff --git a/a8cat.rst b/a8cat.rst
index 8367e35..3909391 100644
--- a/a8cat.rst
+++ b/a8cat.rst
@@ -61,12 +61,17 @@ OPTIONS
and bells are translated to the ASCII versions.
-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; piping
- to a pager usually is. Only the UTF-8 codepoints that correspond to
- ATASCII characters will be converted. If the **-i** option was used to
- create the input, it must be used with **-r** also.
+ Reverse conversion: Input is plain text, or UTF-8 created by a previous
+ run of **a8cat**; output is ATASCII (or XL ICS, with **-i**). ASCII
+ tabs, backspaces, and newlines will be coverted to the ATASCII
+ equivalent. ASCII carriage returns will be silently ignored.
+
+ Only the UTF-8 codepoints that correspond to ATASCII characters will
+ be converted. If the **-i** option was used to create the input, it
+ must be used with **-r** also.
+
+ **a8cat** will refuse to print ATASCII to a terminal. You must
+ redirect or pipe the output.
-m
Magazine listing mode. Rather than Unicode graphics characters,