diff options
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/printable.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libbb/printable.c b/libbb/printable.c index f6ada4904..9a423431e 100644 --- a/libbb/printable.c +++ b/libbb/printable.c | |||
@@ -32,3 +32,27 @@ void FAST_FUNC fputc_printable(int ch, FILE *file) | |||
32 | } | 32 | } |
33 | fputc(ch, file); | 33 | fputc(ch, file); |
34 | } | 34 | } |
35 | |||
36 | void FAST_FUNC visible(unsigned ch, char *buf, int flags) | ||
37 | { | ||
38 | if (ch == '\t' && !(flags & VISIBLE_SHOW_TABS)) { | ||
39 | goto raw; | ||
40 | } | ||
41 | if (ch == '\n') { | ||
42 | if (flags & VISIBLE_ENDLINE) | ||
43 | *buf++ = '$'; | ||
44 | } else { | ||
45 | if (ch >= 128) { | ||
46 | ch -= 128; | ||
47 | *buf++ = 'M'; | ||
48 | *buf++ = '-'; | ||
49 | } | ||
50 | if (ch < 32 || ch == 127) { | ||
51 | *buf++ = '^'; | ||
52 | ch ^= 0x40; | ||
53 | } | ||
54 | } | ||
55 | raw: | ||
56 | *buf++ = ch; | ||
57 | *buf = '\0'; | ||
58 | } | ||