tech-userlevel archive

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

VIS_GLOB flag for vis(3)



As part of importing NetBSD's vis(3) APIs into FreeBSD I needed to add
support for our VIS_GLOB flag.  It's not an especially useful edition
given the existence of strs*vis*() but it's small and reduces diffs so
I'm submitting it for potential inclusion since I have to implement it
to preserve ABI compatibility.  This patch differs slightly from the one
I'm planning to import into FreeBSD in that I've made VIS_GLOB 0x0100
there to avoid requiring compatibility symbols.

-- Brooks

Index: include/vis.h
===================================================================
RCS file: /cvsroot/src/include/vis.h,v
retrieving revision 1.19
diff -u -r1.19 vis.h
--- include/vis.h       12 Mar 2011 19:52:45 -0000      1.19
+++ include/vis.h       14 Dec 2012 17:42:49 -0000
@@ -55,13 +55,14 @@
 /*
  * other
  */
-#define        VIS_NOSLASH     0x040   /* inhibit printing '\' */
-#define        VIS_HTTP1808    0x080   /* http-style escape % hex hex */
-#define        VIS_HTTPSTYLE   0x080   /* http-style escape % hex hex */
-#define        VIS_MIMESTYLE   0x100   /* mime-style escape = HEX HEX */
-#define        VIS_HTTP1866    0x200   /* http-style &#num; or &string; */
-#define        VIS_NOESCAPE    0x400   /* don't decode `\' */
-#define        _VIS_END        0x800   /* for unvis */
+#define        VIS_NOSLASH     0x0040  /* inhibit printing '\' */
+#define        VIS_HTTP1808    0x0080  /* http-style escape % hex hex */
+#define        VIS_HTTPSTYLE   0x0080  /* http-style escape % hex hex */
+#define        VIS_MIMESTYLE   0x0100  /* mime-style escape = HEX HEX */
+#define        VIS_HTTP1866    0x0200  /* http-style &#num; or &string; */
+#define        VIS_NOESCAPE    0x0400  /* don't decode `\' */
+#define        _VIS_END        0x0800  /* for unvis */
+#define        VIS_GLOB        0x1000  /* encode glob(3) magics */
 
 /*
  * unvis return codes
Index: lib/libc/gen/vis.3
===================================================================
RCS file: /cvsroot/src/lib/libc/gen/vis.3,v
retrieving revision 1.27
diff -u -r1.27 vis.3
--- lib/libc/gen/vis.3  17 May 2011 07:10:39 -0000      1.27
+++ lib/libc/gen/vis.3  14 Dec 2012 17:42:50 -0000
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)vis.3      8.1 (Berkeley) 6/9/93
 .\"
-.Dd March 12, 2011
+.Dd December 14, 2012
 .Dt VIS 3
 .Os
 .Sh NAME
@@ -219,6 +219,15 @@
 The following flags
 alter this:
 .Bl -tag -width VIS_WHITEX
++.It Dv VIS_GLOB
+Also encode magic characters
+.Ql ( * ,
+.Ql \&? ,
+.Ql \&[
+and
+.Ql # )
+recognized by
+.Xr glob 3 .
 .It Dv VIS_SP
 Also encode space.
 .It Dv VIS_TAB
@@ -408,6 +417,7 @@
 .Sh SEE ALSO
 .Xr unvis 1 ,
 .Xr vis 1 ,
+.Xr glob 3 ,
 .Xr unvis 3
 .Rs
 .%A T. Berners-Lee
Index: lib/libc/gen/vis.c
===================================================================
RCS file: /cvsroot/src/lib/libc/gen/vis.c,v
retrieving revision 1.44
diff -u -r1.44 vis.c
--- lib/libc/gen/vis.c  12 Mar 2011 19:52:48 -0000      1.44
+++ lib/libc/gen/vis.c  14 Dec 2012 17:42:50 -0000
@@ -89,7 +89,7 @@
 #define xtoa(c)                "0123456789abcdef"[c]
 #define XTOA(c)                "0123456789ABCDEF"[c]
 
-#define MAXEXTRAS      5
+#define MAXEXTRAS      9
 
 #define MAKEEXTRALIST(flag, extra, orig_str)                                 \
 do {                                                                         \
@@ -103,6 +103,12 @@
        for (o = orig, e = extra; (*e++ = *o++) != '\0';)                     \
                continue;                                                     \
        e--;                                                                  \
+       if (flag & VIS_GLOB) {                                                \
+               *e++ = '*';                                                   \
+               *e++ = '?';                                                   \
+               *e++ = '[';                                                   \
+               *e++ = '#';                                                   \
+       }                                                                     \
        if (flag & VIS_SP) *e++ = ' ';                                        \
        if (flag & VIS_TAB) *e++ = '\t';                                      \
        if (flag & VIS_NL) *e++ = '\n';                                       \

Attachment: pgpXgh5XPxCyq.pgp
Description: PGP signature



Home | Main Index | Thread Index | Old Index