Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src add VIS_META/VIS_SHELL support to encode all shell metachara...



details:   https://anonhg.NetBSD.org/src/rev/415e112813a4
branches:  trunk
changeset: 332512:415e112813a4
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Sep 26 01:21:07 2014 +0000

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

diffstat:

 include/vis.h      |   4 +++-
 lib/libc/gen/vis.3 |  30 +++++++++++++++++++++++++++++-
 lib/libc/gen/vis.c |  24 ++++++++++++++----------
 usr.bin/vis/vis.1  |  15 ++++++++++++---
 usr.bin/vis/vis.c  |  14 ++++++++++----
 5 files changed, 68 insertions(+), 19 deletions(-)

diffs (231 lines):

diff -r d4a506fa7786 -r 415e112813a4 include/vis.h
--- a/include/vis.h     Fri Sep 26 01:20:00 2014 +0000
+++ b/include/vis.h     Fri Sep 26 01:21:07 2014 +0000
@@ -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
diff -r d4a506fa7786 -r 415e112813a4 lib/libc/gen/vis.3
--- a/lib/libc/gen/vis.3        Fri Sep 26 01:20:00 2014 +0000
+++ b/lib/libc/gen/vis.3        Fri Sep 26 01:21:07 2014 +0000
@@ -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 @@
 .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 @@
 .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 -r d4a506fa7786 -r 415e112813a4 lib/libc/gen/vis.c
--- a/lib/libc/gen/vis.c        Fri Sep 26 01:20:00 2014 +0000
+++ b/lib/libc/gen/vis.c        Fri Sep 26 01:21:07 2014 +0000
@@ -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 @@
 #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 @@
        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';
diff -r d4a506fa7786 -r 415e112813a4 usr.bin/vis/vis.1
--- a/usr.bin/vis/vis.1 Fri Sep 26 01:20:00 2014 +0000
+++ b/usr.bin/vis/vis.1 Fri Sep 26 01:21:07 2014 +0000
@@ -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 @@
 .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 @@
 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
diff -r d4a506fa7786 -r 415e112813a4 usr.bin/vis/vis.c
--- a/usr.bin/vis/vis.c Fri Sep 26 01:20:00 2014 +0000
+++ b/usr.bin/vis/vis.c Fri Sep 26 01:21:07 2014 +0000
@@ -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 @@
 #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 @@
        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 @@
                        if (foldwidth == 80)
                                foldwidth = 76;
                        break;
+               case 'M':
+                       eflags |= VIS_META;
+                       break;
                case 'n':
                        none++;
                        break;
@@ -116,6 +119,9 @@
                case 's':
                        eflags |= VIS_SAFE;
                        break;
+               case 'S':
+                       eflags |= VIS_SHELL;
+                       break;
                case 't':
                        eflags |= VIS_TAB;
                        break;
@@ -125,7 +131,7 @@
                case '?':
                default:
                        (void)fprintf(stderr, 
-                           "Usage: %s [-bcfhlmnostw] [-e extra]" 
+                           "Usage: %s [-bcfhlmMnosStw] [-e extra]" 
                            " [-F foldwidth] [file ...]\n", getprogname());
                        return 1;
                }



Home | Main Index | Thread Index | Old Index