From 766a18c686fe200b9ea625014b78ec29a0dc43a0 Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Thu, 25 Dec 2025 02:09:19 -0500 Subject: alf: swap -A and -a, add -aa (to match unalf). --- src/alf.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/alf.c') 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; -- cgit v1.2.3