aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorB. Watson <urchlay@slackware.uk>2025-12-25 02:09:19 -0500
committerB. Watson <urchlay@slackware.uk>2025-12-25 02:09:19 -0500
commit766a18c686fe200b9ea625014b78ec29a0dc43a0 (patch)
treeb556f1ab760bf01df3da2dd9c4951624bea6cc0c /src
parent8017162545171522e1c5e0d8f77634785b2e875f (diff)
downloadalftools-766a18c686fe200b9ea625014b78ec29a0dc43a0.tar.gz
alf: swap -A and -a, add -aa (to match unalf).
Diffstat (limited to 'src')
-rw-r--r--src/alf.121
-rw-r--r--src/alf.c19
-rw-r--r--src/alf.rst17
-rw-r--r--src/alfusage.c5
4 files changed, 44 insertions, 18 deletions
diff --git a/src/alf.1 b/src/alf.1
index 9445969..608aeaf 100644
--- a/src/alf.1
+++ b/src/alf.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 "ALF" 1 "2025-12-16" "0.4.1" "Urchlay's Atari 8-bit Tools"
+.TH "ALF" 1 "2025-12-25" "0.4.1" "Urchlay's Atari 8-bit Tools"
.SH NAME
alf \- create Atari 8-bit ALF archives
.\" RST source for alf(1) man page. Convert with:
@@ -67,7 +67,7 @@ Options can be combined (e.g. \fB\-ov\fP means \fB\-o\fP \fB\-v\fP), though the
an error; \fB\-vtd\fP is OK).
.INDENT 0.0
.TP
-.B \-a
+.B \-A
Append to \fIalf\-file\fP\&. The files are added to the end of the archive. Be
careful not to add a file with the same name as as existing member of
the archive. If \fIalf\-file\fP doesn\(aqt exist, it will be created. No backup
@@ -77,11 +77,18 @@ is made with \fB\-a\fP\&.
.
.INDENT 0.0
.TP
-.B \-A
-Convert line endings and tabs from ASCII to ATASCII in all input
-files. This will corrupt any executables or non\-text data files,
-so use with caution. There is no way to autodetect text files,
-unlike \fBunalf\fP\&.
+.B \-a
+Convert text file line endings and tabs from ASCII to ATASCII. Text
+files are detected by looking at the first 2 bytes of the file. If both
+are printable ASCII, the file is considered text.
+.UNINDENT
+.\" convert EOLs and tabs in text files.
+.
+.INDENT 0.0
+.TP
+.BI \-a\fB a
+Convert line endings and tabs in \fIall\fP input files. This will
+corrupt any executables or non\-text data files, so use with caution.
.UNINDENT
.\" convert EOLs and tabs in all input files.
.
diff --git a/src/alf.c b/src/alf.c
index e8090f9..1558107 100644
--- a/src/alf.c
+++ b/src/alf.c
@@ -177,9 +177,22 @@ void make_backup(void) {
}
}
+int is_printable(u8 c) {
+ return (c == '\n' || c == '\t' || (c >= 0x20 && c <= 0x7c));
+}
+
+int is_text_file(void) {
+ if(input_len < 2) return 0;
+ return (is_printable(input_buf[0]) && is_printable(input_buf[1]));
+}
+
void convert_eols(void) {
int i;
+ if(opt_verbose) {
+ fprintf(stderr, "%s: converting EOLs/tabs in %s\n", self, in_filename);
+ }
+
for(i = 0; i < input_len; i++) {
if(input_buf[i] == '\n')
input_buf[i] = 0x9b;
@@ -214,7 +227,7 @@ void crunch_file(const char *filename_arg) {
fprintf(stderr, "%s: %s: this file is too large; only compressing the first 16MB.\n", self, in_filename);
}
- if(opt_txtconv)
+ if(opt_txtconv > 1 || (opt_txtconv && is_text_file()))
convert_eols();
output_len = 0;
@@ -324,8 +337,8 @@ int main(int argc, char **argv) {
while((opt = getopt(argc, argv, "aAt:oqvV")) != -1) {
switch(opt) {
- case 'A': opt_txtconv = 1; break;
- case 'a': opt_append = 1; opt_overwrite = 1; break;
+ case 'a': opt_txtconv++; break;
+ case 'A': opt_append = 1; opt_overwrite = 1; break;
case 'o': opt_overwrite = 1; opt_append = 0; break;
case 'q': opt_quiet = 1; break;
case 't': opt_zerotime = opt_alftime = opt_gmtime = 0;
diff --git a/src/alf.rst b/src/alf.rst
index 0c72aa2..aa5978c 100644
--- a/src/alf.rst
+++ b/src/alf.rst
@@ -55,7 +55,7 @@ Options can be combined (e.g. **-ov** means **-o** **-v**), though the
**-td**, **-tu**, **-tz** options must appear last (**-tdv** would be
an error; **-vtd** is OK).
--a
+-A
Append to *alf-file*. The files are added to the end of the archive. Be
careful not to add a file with the same name as as existing member of
the archive. If *alf-file* doesn't exist, it will be created. No backup
@@ -63,11 +63,16 @@ an error; **-vtd** is OK).
.. append to ALF file.
--A
- Convert line endings and tabs from ASCII to ATASCII in all input
- files. This will corrupt any executables or non-text data files,
- so use with caution. There is no way to autodetect text files,
- unlike **unalf**.
+-a
+ Convert text file line endings and tabs from ASCII to ATASCII. Text
+ files are detected by looking at the first 2 bytes of the file. If both
+ are printable ASCII, the file is considered text.
+
+.. convert EOLs and tabs in text files.
+
+-aa
+ Convert line endings and tabs in *all* input files. This will
+ corrupt any executables or non-text data files, so use with caution.
.. convert EOLs and tabs in all input files.
diff --git a/src/alfusage.c b/src/alfusage.c
index a3eb8f5..4040b32 100644
--- a/src/alfusage.c
+++ b/src/alfusage.c
@@ -1,6 +1,7 @@
const char *usage_msg[] = {
- " -a: append to ALF file.",
- " -A: convert EOLs and tabs in all input files.",
+ " -A: append to ALF file.",
+ " -a: convert EOLs and tabs in text files.",
+ " -aa: convert EOLs and tabs in all input files.",
" -h: show this help message.",
" -o: overwrite ALF file if it exists (don't create file~ backup).",
" -q: quiet.",