Module Name:    src
Committed By:   christos
Date:           Fri Sep 26 01:21:07 UTC 2014

Modified Files:
        src/include: vis.h
        src/lib/libc/gen: vis.3 vis.c
        src/usr.bin/vis: vis.1 vis.c

Log Message:
add VIS_META/VIS_SHELL support to encode all shell metacharacters.
XXX: /etc/rc.d/wizd fix $


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/include/vis.h
cvs rdiff -u -r1.39 -r1.40 src/lib/libc/gen/vis.3
cvs rdiff -u -r1.62 -r1.63 src/lib/libc/gen/vis.c
cvs rdiff -u -r1.20 -r1.21 src/usr.bin/vis/vis.1
cvs rdiff -u -r1.22 -r1.23 src/usr.bin/vis/vis.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/include/vis.h
diff -u src/include/vis.h:1.21 src/include/vis.h:1.22
--- src/include/vis.h:1.21	Wed Feb 20 12:01:15 2013
+++ src/include/vis.h	Thu Sep 25 21:21:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vis.h,v 1.21 2013/02/20 17:01:15 christos Exp $	*/
+/*	$NetBSD: vis.h,v 1.22 2014/09/26 01:21:07 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -63,6 +63,8 @@
 #define	VIS_NOESCAPE	0x0400	/* don't decode `\' */
 #define	_VIS_END	0x0800	/* for unvis */
 #define	VIS_GLOB	0x1000	/* encode glob(3) magic characters */
+#define	VIS_SHELL	0x2000	/* encode shell special characters [not glob] */
+#define	VIS_META	(VIS_WHITE | VIS_GLOB | VIS_SHELL)
 
 /*
  * unvis return codes

Index: src/lib/libc/gen/vis.3
diff -u src/lib/libc/gen/vis.3:1.39 src/lib/libc/gen/vis.3:1.40
--- src/lib/libc/gen/vis.3:1.39	Wed Feb 20 15:05:26 2013
+++ src/lib/libc/gen/vis.3	Thu Sep 25 21:21:07 2014
@@ -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

Index: src/lib/libc/gen/vis.c
diff -u src/lib/libc/gen/vis.c:1.62 src/lib/libc/gen/vis.c:1.63
--- src/lib/libc/gen/vis.c:1.62	Mon Sep  8 13:35:01 2014
+++ src/lib/libc/gen/vis.c	Thu Sep 25 21:21:07 2014
@@ -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_
 #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';

Index: src/usr.bin/vis/vis.1
diff -u src/usr.bin/vis/vis.1:1.20 src/usr.bin/vis/vis.1:1.21
--- src/usr.bin/vis/vis.1:1.20	Tue Oct 29 08:27:23 2013
+++ src/usr.bin/vis/vis.1	Thu Sep 25 21:21:07 2014
@@ -1,4 +1,4 @@
-.\"	$NetBSD: vis.1,v 1.20 2013/10/29 12:27:23 njoly Exp $
+.\"	$NetBSD: vis.1,v 1.21 2014/09/26 01:21:07 christos Exp $
 .\"
 .\" Copyright (c) 1989, 1991, 1993, 1994
 .\"	The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)vis.1	8.4 (Berkeley) 4/19/94
 .\"
-.Dd February 19, 2013
+.Dd September 25, 2014
 .Dt VIS 1
 .Os
 .Sh NAME
@@ -37,7 +37,7 @@
 .Nd display non-printable characters in a visual format
 .Sh SYNOPSIS
 .Nm
-.Op Fl bcfhlmnostw
+.Op Fl bcfhlmMnosStw
 .Op Fl e Ar extra
 .Op Fl F Ar foldwidth
 .Op Ar file ...
@@ -102,6 +102,12 @@ followed by the newline.
 .It Fl m
 Encode using the MIME Quoted-Printable encoding from RFC 2045.
 .Pq Dv VIS_MIMESTYLE
+.It Fl M
+Encode all shell meta characters (implies
+.Fl S ,
+.Fl w ,
+.Fl g )
+.Pq Dv VIS_META
 .It Fl n
 Turns off any encoding, except for the fact that backslashes are
 still doubled and hidden newline sequences inserted if
@@ -128,6 +134,9 @@ Only characters considered unsafe to sen
 This flag allows backspace, bell, and carriage return in addition
 to the default space, tab and newline.
 .Pq Dv VIS_SAFE
+.It Fl S
+Encode shell meta-characters that are non-white space or glob.
+.Pq Dv VIS_SHELL
 .It Fl t
 Tabs are also encoded.
 .Pq Dv VIS_TAB

Index: src/usr.bin/vis/vis.c
diff -u src/usr.bin/vis/vis.c:1.22 src/usr.bin/vis/vis.c:1.23
--- src/usr.bin/vis/vis.c:1.22	Wed Feb 20 12:04:45 2013
+++ src/usr.bin/vis/vis.c	Thu Sep 25 21:21:07 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: vis.c,v 1.22 2013/02/20 17:04:45 christos Exp $	*/
+/*	$NetBSD: vis.c,v 1.23 2014/09/26 01:21:07 christos Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19
 #if 0
 static char sccsid[] = "@(#)vis.c	8.1 (Berkeley) 6/6/93";
 #endif
-__RCSID("$NetBSD: vis.c,v 1.22 2013/02/20 17:04:45 christos Exp $");
+__RCSID("$NetBSD: vis.c,v 1.23 2014/09/26 01:21:07 christos Exp $");
 #endif /* not lint */
 
 #include <stdio.h>
@@ -70,7 +70,7 @@ main(int argc, char *argv[])
 	int ch;
 	int rval;
 
-	while ((ch = getopt(argc, argv, "bcde:F:fhlmnostw")) != -1)
+	while ((ch = getopt(argc, argv, "bcde:F:fhlmMnosStw")) != -1)
 		switch((char)ch) {
 		case 'b':
 			eflags |= VIS_NOSLASH;
@@ -107,6 +107,9 @@ main(int argc, char *argv[])
 			if (foldwidth == 80)
 				foldwidth = 76;
 			break;
+		case 'M':
+			eflags |= VIS_META;
+			break;
 		case 'n':
 			none++;
 			break;
@@ -116,6 +119,9 @@ main(int argc, char *argv[])
 		case 's':
 			eflags |= VIS_SAFE;
 			break;
+		case 'S':
+			eflags |= VIS_SHELL;
+			break;
 		case 't':
 			eflags |= VIS_TAB;
 			break;
@@ -125,7 +131,7 @@ main(int argc, char *argv[])
 		case '?':
 		default:
 			(void)fprintf(stderr, 
-			    "Usage: %s [-bcfhlmnostw] [-e extra]" 
+			    "Usage: %s [-bcfhlmMnosStw] [-e extra]" 
 			    " [-F foldwidth] [file ...]\n", getprogname());
 			return 1;
 		}

Reply via email to