summaryrefslogtreecommitdiff
path: root/lib/libc/gen
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2005-08-09 19:38:32 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2005-08-09 19:38:32 +0000
commit37d43a6ee9cff1651397a00f88f10a313035035f (patch)
treefc1348344f7251e2524391f8ab7cb939cfb6673f /lib/libc/gen
parent6d323bce302cff7a7bf4dbdc3f1e1f485c4810d0 (diff)
Add VIS_GLOB to escape special characters used by shell-style globbing.
From Solar Designer based on changes in FreeBSD. OK deraadt@
Diffstat (limited to 'lib/libc/gen')
-rw-r--r--lib/libc/gen/vis.312
-rw-r--r--lib/libc/gen/vis.c23
2 files changed, 23 insertions, 12 deletions
diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3
index 54ed818d507..86cbc81c3e0 100644
--- a/lib/libc/gen/vis.3
+++ b/lib/libc/gen/vis.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: vis.3,v 1.20 2005/02/25 03:12:43 cloder Exp $
+.\" $OpenBSD: vis.3,v 1.21 2005/08/09 19:38:31 millert Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,7 +27,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd June 9, 1993
+.Dd August 8, 2005
.Dt VIS 3
.Os
.Sh NAME
@@ -163,6 +163,14 @@ 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
+.Ql ( * ,
+.Ql \&? ,
+.Ql \&[ )
+and
+.Ql # .
.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 bbe839e9a7a..f56090bfb85 100644
--- a/lib/libc/gen/vis.c
+++ b/lib/libc/gen/vis.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vis.c,v 1.15 2005/08/08 08:05:34 espie Exp $ */
+/* $OpenBSD: vis.c,v 1.16 2005/08/09 19:38:31 millert Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -35,14 +35,17 @@
#include <vis.h>
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
-#define isvisible(c) (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c)) && \
- isgraph((u_char)(c))) || \
- ((flag & VIS_SP) == 0 && (c) == ' ') || \
- ((flag & VIS_TAB) == 0 && (c) == '\t') || \
- ((flag & VIS_NL) == 0 && (c) == '\n') || \
- ((flag & VIS_SAFE) && ((c) == '\b' || \
- (c) == '\007' || (c) == '\r' || \
- isgraph((u_char)(c)))))
+#define isvisible(c) \
+ (((u_int)(c) <= UCHAR_MAX && isascii((u_char)(c))) && \
+ (((((c) != '*' && (c) != '?' && (c) != '[' && (c) != '#') || \
+ (flag & VIS_GLOB) == 0) && \
+ isgraph((u_char)(c))) || \
+ ((flag & VIS_SP) == 0 && (c) == ' ') || \
+ ((flag & VIS_TAB) == 0 && (c) == '\t') || \
+ ((flag & VIS_NL) == 0 && (c) == '\n') || \
+ ((flag & VIS_SAFE) && ((c) == '\b' || \
+ (c) == '\007' || (c) == '\r' || \
+ isgraph((u_char)(c))))))
/*
* vis - visually encode characters
@@ -102,7 +105,7 @@ vis(char *dst, int c, int flag, int 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';