nightmaremail

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit cff53ac08dadec27debcbfe6ea9bf76ae979247c
parent 21d898f96dd02101759fcea39980aa81381b532a
Author: Rolf Eike Beer <eike@sf-mail.de>
Date:   Sun, 24 May 2020 17:06:39 +0200

make most output of auto-str readable

Avoid recoding letters and anything from "/.-_" into octal, just print them
directly.

Diffstat:
Mauto-str.c | 29+++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/auto-str.c b/auto-str.c @@ -1,3 +1,4 @@ +#include <ctype.h> #include "substdio.h" #include "readwrite.h" #include "exit.h" @@ -11,6 +12,17 @@ char *s; if (substdio_puts(&ss1,s) == -1) _exit(111); } +// check if a given character can be printed unquoted in a C string +// does not accept digits as they may be hardly visible between octal encoded chars +static int is_legible(unsigned char ch) +{ + if (isascii(ch)) + return 1; + if (ch == '/' || ch == '_' || ch == '-' || ch == '.') + return 1; + return 0; +} + void main(argc,argv) int argc; char **argv; @@ -30,12 +42,17 @@ char **argv; puts("[] = \"\\\n"); while (ch = *value++) { - puts("\\"); - octal[3] = 0; - octal[2] = '0' + (ch & 7); ch >>= 3; - octal[1] = '0' + (ch & 7); ch >>= 3; - octal[0] = '0' + (ch & 7); - puts(octal); + if (is_legible(ch)) { + if (substdio_put(&ss1, &ch, 1) == -1) + _exit(111); + } else { + puts("\\"); + octal[3] = 0; + octal[2] = '0' + (ch & 7); ch >>= 3; + octal[1] = '0' + (ch & 7); ch >>= 3; + octal[0] = '0' + (ch & 7); + puts(octal); + } } puts("\\\n\";\n");