diff options
author | Brooks Davis <brooks@FreeBSD.org> | 2017-11-27 23:47:57 +0000 |
---|---|---|
committer | Brooks Davis <brooks@FreeBSD.org> | 2017-11-27 23:47:57 +0000 |
commit | 022fad7dfc1d1e367dc331524ae91c74688a3098 (patch) | |
tree | bc5a19229ac8c2de69fe0ee42691dd0141de3605 | |
parent | 46f0e7ccdfb34f49b0cc1de7d00c1429a00f1ff3 (diff) |
Notes
-rw-r--r-- | unvis.3 | 11 | ||||
-rw-r--r-- | vis.3 | 17 | ||||
-rw-r--r-- | vis.c | 30 | ||||
-rw-r--r-- | vis.h | 3 |
4 files changed, 39 insertions, 22 deletions
@@ -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 @@ -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 @@ -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 @@ -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 |