diff options
| author | christos <christos@NetBSD.org> | 2014-09-26 01:21:07 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2014-09-26 01:21:07 +0000 |
| commit | 2e73bb3f331088d6eacb1d50bb44121c7adbb9ef (patch) | |
| tree | 41689dea33209a34907c3600b2dc8c8e654ca69d /lib/libc | |
| parent | 911916a201b9a21fb3a9d9b4c346286adcb2953d (diff) | |
add VIS_META/VIS_SHELL support to encode all shell metacharacters.
XXX: /etc/rc.d/wizd fix $
Diffstat (limited to 'lib/libc')
| -rw-r--r-- | lib/libc/gen/vis.3 | 30 | ||||
| -rw-r--r-- | lib/libc/gen/vis.c | 24 |
2 files changed, 43 insertions, 11 deletions
diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3 index 166316d1f9a..bb30ca66d75 100644 --- a/lib/libc/gen/vis.3 +++ b/lib/libc/gen/vis.3 @@ -1,4 +1,4 @@ -.\" $NetBSD: vis.3,v 1.39 2013/02/20 20:05:26 christos Exp $ +.\" $NetBSD: vis.3,v 1.40 2014/09/26 01:21:07 christos Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -244,6 +244,27 @@ and .Ql # ) recognized by .Xr glob 3 . +.It Dv VIS_SHELL +Also encode the meta characters used by shells (in addition to the glob +characters): +.Ql ( ' , +.Ql ` , +.Ql \*[q] , +.Ql \&; , +.Ql \*[Am] , +.Ql \*[Lt] , +.Ql \*[Gt] , +.Ql \&( , +.Ql \&) , +.Ql \&| , +.Ql \&] , +.Ql \&\\ , +.\" XXX: How do you print a $ +.Ql \e(Do , +.Ql \&! , +.Ql \&^ +and +.Ql ~ ). .It Dv VIS_SP Also encode space. .It Dv VIS_TAB @@ -257,6 +278,13 @@ Synonym for .Dv VIS_TAB \&| .Dv VIS_NL . +.It Dv VIS_META +Synonym for +.Dv VIS_WHITE +\&| +.Dv VIS_GLOB +\&| +.Dv VIS_SHELL . .It Dv VIS_SAFE Only encode .Dq unsafe diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c index 4863bbea859..5ebb83b2ff9 100644 --- a/lib/libc/gen/vis.c +++ b/lib/libc/gen/vis.c @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.62 2014/09/08 17:35:01 christos Exp $ */ +/* $NetBSD: vis.c,v 1.63 2014/09/26 01:21:07 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -57,7 +57,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vis.c,v 1.62 2014/09/08 17:35:01 christos Exp $"); +__RCSID("$NetBSD: vis.c,v 1.63 2014/09/26 01:21:07 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #ifdef __FBSDID __FBSDID("$FreeBSD$"); @@ -104,7 +104,10 @@ static wchar_t *do_svis(wchar_t *, wint_t, int, wint_t, const wchar_t *); #define xtoa(c) L"0123456789abcdef"[c] #define XTOA(c) L"0123456789ABCDEF"[c] -#define MAXEXTRAS 10 +#define MAXEXTRAS 30 + +static const wchar_t char_shell[] = L"'`\";&<>()|{}]\\$!^~"; +static const wchar_t char_glob[] = L"*?[#"; #if !HAVE_NBTOOL_CONFIG_H #ifndef __NetBSD__ @@ -318,17 +321,18 @@ makeextralist(int flags, const char *src) if (mbstowcs(dst, src, len) == (size_t)-1) { size_t i; for (i = 0; i < len; i++) - dst[i] = (wint_t)(u_char)src[i]; + dst[i] = (wchar_t)(u_char)src[i]; d = dst + len; } else d = dst + wcslen(dst); - if (flags & VIS_GLOB) { - *d++ = L'*'; - *d++ = L'?'; - *d++ = L'['; - *d++ = L'#'; - } + if (flags & VIS_GLOB) + for (const wchar_t *s = char_glob; *s; *d++ = *s++) + continue; + + if (flags & VIS_SHELL) + for (const wchar_t *s = char_shell; *s; *d++ = *s++) + continue; if (flags & VIS_SP) *d++ = L' '; if (flags & VIS_TAB) *d++ = L'\t'; |
