diff options
-rw-r--r-- | include/vis.h | 1 | ||||
-rw-r--r-- | lib/libc/gen/vis.3 | 3 | ||||
-rw-r--r-- | lib/libc/gen/vis.c | 6 |
3 files changed, 8 insertions, 2 deletions
diff --git a/include/vis.h b/include/vis.h index d4134db..28f9765 100644 --- a/include/vis.h +++ b/include/vis.h @@ -65,6 +65,7 @@ typedef __size_t size_t; */ #define VIS_NOSLASH 0x40 /* inhibit printing '\' */ #define VIS_HTTPSTYLE 0x80 /* http-style escape % HEX HEX */ +#define VIS_GLOB 0x100 /* encode glob(3) magics */ /* * unvis return codes diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3 index 6f685a9..25f1365 100644 --- a/lib/libc/gen/vis.3 +++ b/lib/libc/gen/vis.3 @@ -137,6 +137,9 @@ except space, tab, and newline are encoded. The following flags alter this: .Bl -tag -width VIS_WHITEX +.It Dv VIS_GLOB +Also encode magic characters ('*', '?', '[') recognized by +.Xr glob 3 .It Dv VIS_SP Also encode space. .It Dv VIS_TAB diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c index 8868a70..4f594eb 100644 --- a/lib/libc/gen/vis.c +++ b/lib/libc/gen/vis.c @@ -71,7 +71,9 @@ vis(dst, c, flag, nextc) } } - if (isgraph(c) || + if ((flag & VIS_GLOB) && (c == '*' || c == '?' || c == '[')) + ; + else if (isgraph(c) || ((flag & VIS_SP) == 0 && c == ' ') || ((flag & VIS_TAB) == 0 && c == '\t') || ((flag & VIS_NL) == 0 && c == '\n') || @@ -127,7 +129,7 @@ vis(dst, c, flag, nextc) goto done; } } - if (((c & 0177) == ' ') || (flag & VIS_OCTAL)) { + if (((c & 0177) == ' ') || isgraph(c) || (flag & VIS_OCTAL)) { *dst++ = '\\'; *dst++ = ((u_char)c >> 6 & 07) + '0'; *dst++ = ((u_char)c >> 3 & 07) + '0'; |