diff options
| author | B. Watson <urchlay@slackware.uk> | 2025-12-25 02:09:19 -0500 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2025-12-25 02:09:19 -0500 |
| commit | 766a18c686fe200b9ea625014b78ec29a0dc43a0 (patch) | |
| tree | b556f1ab760bf01df3da2dd9c4951624bea6cc0c /src/alf.c | |
| parent | 8017162545171522e1c5e0d8f77634785b2e875f (diff) | |
| download | alftools-766a18c686fe200b9ea625014b78ec29a0dc43a0.tar.gz | |
alf: swap -A and -a, add -aa (to match unalf).
Diffstat (limited to 'src/alf.c')
| -rw-r--r-- | src/alf.c | 19 |
1 files changed, 16 insertions, 3 deletions
@@ -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; |
