aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrooks Davis <brooks@FreeBSD.org>2017-11-27 23:47:57 +0000
committerBrooks Davis <brooks@FreeBSD.org>2017-11-27 23:47:57 +0000
commit022fad7dfc1d1e367dc331524ae91c74688a3098 (patch)
treebc5a19229ac8c2de69fe0ee42691dd0141de3605
parent46f0e7ccdfb34f49b0cc1de7d00c1429a00f1ff3 (diff)
downloadsrc-vendor/NetBSD/libc-vis.tar.gz
src-vendor/NetBSD/libc-vis.zip
Vendor import of NetBSD's (un)vis(3) at 2017-11-27vendor/NetBSD/libc-vis/20171127vendor/NetBSD/libc-vis
Notes
Notes: svn path=/vendor/NetBSD/libc-vis/dist/; revision=326295 svn path=/vendor/NetBSD/libc-vis/20171127/; revision=326296; tag=vendor/NetBSD/libc-vis/20171127
-rw-r--r--unvis.311
-rw-r--r--vis.317
-rw-r--r--vis.c30
-rw-r--r--vis.h3
4 files changed, 39 insertions, 22 deletions
diff --git a/unvis.3 b/unvis.3
index b856a730e112..0991f19cd3b8 100644
--- a/unvis.3
+++ b/unvis.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: unvis.3,v 1.27 2012/12/15 07:34:36 wiz Exp $
+.\" $NetBSD: unvis.3,v 1.29 2017/10/24 19:14:55 abhinav Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -34,7 +34,10 @@
.Os
.Sh NAME
.Nm unvis ,
-.Nm strunvis
+.Nm strunvis ,
+.Nm strnunvis ,
+.Nm strunvisx ,
+.Nm strnunvisx
.Nd decode a visual representation of characters
.Sh LIBRARY
.Lb libc
@@ -183,7 +186,7 @@ char out;
while ((ch = getchar()) != EOF) {
again:
- switch(unvis(\*[Am]out, ch, \*[Am]state, 0)) {
+ switch(unvis(&out, ch, &state, 0)) {
case 0:
case UNVIS_NOCHAR:
break;
@@ -197,7 +200,7 @@ again:
errx(EXIT_FAILURE, "Bad character sequence!");
}
}
-if (unvis(\*[Am]out, '\e0', \*[Am]state, UNVIS_END) == UNVIS_VALID)
+if (unvis(&out, '\e0', &state, UNVIS_END) == UNVIS_VALID)
(void)putchar(out);
.Ed
.Sh ERRORS
diff --git a/vis.3 b/vis.3
index bde9c00f08e4..24cd2654d027 100644
--- a/vis.3
+++ b/vis.3
@@ -1,4 +1,4 @@
-.\" $NetBSD: vis.3,v 1.45 2016/06/08 15:00:04 wiz Exp $
+.\" $NetBSD: vis.3,v 1.49 2017/08/05 20:22:29 wiz Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)vis.3 8.1 (Berkeley) 6/9/93
.\"
-.Dd January 14, 2015
+.Dd April 22, 2017
.Dt VIS 3
.Os
.Sh NAME
@@ -242,6 +242,8 @@ except space, tab, and newline are encoded (see
The following flags
alter this:
.Bl -tag -width VIS_WHITEX
+.It Dv VIS_DQ
+Also encode double quotes
.It Dv VIS_GLOB
Also encode the magic characters
.Ql ( * ,
@@ -309,7 +311,7 @@ warning on the use of the
.Dv VIS_NOSLASH
flag below).
.Pp
-There are four forms of encoding.
+There are six forms of encoding.
All forms use the backslash character
.Ql \e
to introduce a special
@@ -372,7 +374,6 @@ space.
.It Dv \e240
Represents Meta-space.
.El
-.Pp
.It Dv VIS_CSTYLE
Use C-style backslash sequences to represent standard non-printable
characters.
@@ -401,6 +402,9 @@ If
.Fa nextc
is an octal digit, the latter representation is used to
avoid ambiguity.
+.Pp
+Non-printable characters without C-style
+backslash sequences use the default representation.
.It Dv VIS_OCTAL
Use a three digit octal sequence.
The form is
@@ -408,6 +412,11 @@ The form is
where
.Em d
represents an octal digit.
+.It Dv VIS_CSTYLE \&| Dv VIS_OCTAL
+Same as
+.Dv VIS_CSTYLE
+except that non-printable characters without C-style
+backslash sequences use a three digit octal sequence.
.It Dv VIS_HTTPSTYLE
Use URI encoding as described in RFC 1738.
The form is
diff --git a/vis.c b/vis.c
index b4a5f3291daa..3c965d5e77d9 100644
--- a/vis.c
+++ b/vis.c
@@ -1,4 +1,4 @@
-/* $NetBSD: vis.c,v 1.71 2016/01/14 20:41:23 christos Exp $ */
+/* $NetBSD: vis.c,v 1.74 2017/11/27 16:37:21 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.71 2016/01/14 20:41:23 christos Exp $");
+__RCSID("$NetBSD: vis.c,v 1.74 2017/11/27 16:37:21 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#ifdef __FBSDID
__FBSDID("$FreeBSD$");
@@ -377,6 +377,7 @@ makeextralist(int flags, const char *src)
if (flags & VIS_SP) *d++ = L' ';
if (flags & VIS_TAB) *d++ = L'\t';
if (flags & VIS_NL) *d++ = L'\n';
+ if (flags & VIS_DQ) *d++ = L'"';
if ((flags & VIS_NOSLASH) == 0) *d++ = L'\\';
*d = L'\0';
@@ -405,6 +406,14 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
_DIAGASSERT(mbsrc != NULL || mblength == 0);
_DIAGASSERT(mbextra != NULL);
+ mbslength = (ssize_t)mblength;
+ /*
+ * When inputing a single character, must also read in the
+ * next character for nextc, the look-ahead character.
+ */
+ if (mbslength == 1)
+ mbslength++;
+
/*
* Input (mbsrc) is a char string considered to be multibyte
* characters. The input loop will read this string pulling
@@ -421,12 +430,12 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
/* Allocate space for the wide char strings */
psrc = pdst = extra = NULL;
mdst = NULL;
- if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == NULL)
+ if ((psrc = calloc(mbslength + 1, sizeof(*psrc))) == NULL)
return -1;
- if ((pdst = calloc((4 * mblength) + 1, sizeof(*pdst))) == NULL)
+ if ((pdst = calloc((16 * mbslength) + 1, sizeof(*pdst))) == NULL)
goto out;
if (*mbdstp == NULL) {
- if ((mdst = calloc((4 * mblength) + 1, sizeof(*mdst))) == NULL)
+ if ((mdst = calloc((16 * mbslength) + 1, sizeof(*mdst))) == NULL)
goto out;
*mbdstp = mdst;
}
@@ -449,13 +458,6 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
* stop at NULs because we may be processing a block of data
* that includes NULs.
*/
- mbslength = (ssize_t)mblength;
- /*
- * When inputing a single character, must also read in the
- * next character for nextc, the look-ahead character.
- */
- if (mbslength == 1)
- mbslength++;
while (mbslength > 0) {
/* Convert one multibyte character to wchar_t. */
if (!cerr)
@@ -466,12 +468,13 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
clen = 1;
cerr = 1;
}
- if (clen == 0)
+ if (clen == 0) {
/*
* NUL in input gives 0 return value. process
* as single NUL byte and keep going.
*/
clen = 1;
+ }
/* Advance buffer character pointer. */
src++;
/* Advance input pointer by number of bytes read. */
@@ -481,6 +484,7 @@ istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength,
}
len = src - psrc;
src = psrc;
+
/*
* In the single character input case, we will have actually
* processed two characters, c and nextc. Reset len back to
diff --git a/vis.h b/vis.h
index 501ad182eeb3..7fc880cbfad5 100644
--- a/vis.h
+++ b/vis.h
@@ -1,4 +1,4 @@
-/* $NetBSD: vis.h,v 1.24 2016/01/14 20:42:14 christos Exp $ */
+/* $NetBSD: vis.h,v 1.25 2017/04/23 01:57:36 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
@@ -51,6 +51,7 @@
#define VIS_NL 0x0010 /* also encode newline */
#define VIS_WHITE (VIS_SP | VIS_TAB | VIS_NL)
#define VIS_SAFE 0x0020 /* only encode "unsafe" characters */
+#define VIS_DQ 0x8000 /* also encode double quotes */
/*
* other