CVS commit: src/usr.bin/vis
Module Name:src Committed By: nia Date: Sat Feb 20 09:31:51 UTC 2021 Modified Files: src/usr.bin/vis: vis.1 Log Message: fix URL To generate a diff of this commit: cvs rdiff -u -r1.24 -r1.25 src/usr.bin/vis/vis.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.24 src/usr.bin/vis/vis.1:1.25 --- src/usr.bin/vis/vis.1:1.24 Thu Feb 18 18:27:24 2021 +++ src/usr.bin/vis/vis.1 Sat Feb 20 09:31:51 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: vis.1,v 1.24 2021/02/18 18:27:24 christos Exp $ +.\" $NetBSD: vis.1,v 1.25 2021/02/20 09:31:51 nia Exp $ .\" .\" Copyright (c) 1989, 1991, 1993, 1994 .\" The Regents of the University of California. All rights reserved. @@ -187,8 +187,8 @@ $ printf "\\x10\\n\\t\\n" | vis -w -t -l .Pp Visualize string using URI encoding: .Bd -literal -offset indent -$ printf http://www.freebsd.org | vis -h -http%3a%2f%2fwww.freebsd.org +$ printf https://www.NetBSD.org | vis -h +https%3a%2f%2fwww.NetBSD.org .Ed .Sh SEE ALSO .Xr unvis 1 ,
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Thu Feb 18 18:27:24 UTC 2021 Modified Files: src/usr.bin/vis: vis.1 Log Message: Add examples (Fernando Apestegu�a at FreeBSD) To generate a diff of this commit: cvs rdiff -u -r1.23 -r1.24 src/usr.bin/vis/vis.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.23 src/usr.bin/vis/vis.1:1.24 --- src/usr.bin/vis/vis.1:1.23 Sun May 24 15:42:39 2015 +++ src/usr.bin/vis/vis.1 Thu Feb 18 13:27:24 2021 @@ -1,4 +1,4 @@ -.\" $NetBSD: vis.1,v 1.23 2015/05/24 19:42:39 christos Exp $ +.\" $NetBSD: vis.1,v 1.24 2021/02/18 18:27:24 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 May 24, 2015 +.Dd February 18, 2021 .Dt VIS 1 .Os .Sh NAME @@ -171,6 +171,25 @@ instead. Specify the locale of the input data. Set to C if the input data locale is unknown. .El +.Sh EXAMPLES +Visualize characters encoding white spaces and tabs: +.Bd -literal -offset indent +$ printf "\\x10\\n\\t\\n" | vis -w -t +\\^P\\012\\011\\012 +.Ed +.Pp +Same as above but using `\\$' for newline followed by an actual newline: +.Bd -literal -offset indent +$ printf "\\x10\\n\\t\\n" | vis -w -t -l +\\^P\\$ +\\011\\$ +.Ed +.Pp +Visualize string using URI encoding: +.Bd -literal -offset indent +$ printf http://www.freebsd.org | vis -h +http%3a%2f%2fwww.freebsd.org +.Ed .Sh SEE ALSO .Xr unvis 1 , .Xr svis 3 ,
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Sun May 24 19:42:39 UTC 2015 Modified Files: src/usr.bin/vis: vis.1 vis.c Log Message: Add -N (VIS_NOLOCALE), sort. To generate a diff of this commit: cvs rdiff -u -r1.22 -r1.23 src/usr.bin/vis/vis.1 cvs rdiff -u -r1.24 -r1.25 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/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.22 src/usr.bin/vis/vis.1:1.23 --- src/usr.bin/vis/vis.1:1.22 Thu Sep 25 22:20:39 2014 +++ src/usr.bin/vis/vis.1 Sun May 24 15:42:39 2015 @@ -1,4 +1,4 @@ -.\ $NetBSD: vis.1,v 1.22 2014/09/26 02:20:39 wiz Exp $ +.\ $NetBSD: vis.1,v 1.23 2015/05/24 19:42:39 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 September 25, 2014 +.Dd May 24, 2015 .Dt VIS 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd display non-printable characters in a visual format .Sh SYNOPSIS .Nm -.Op Fl bcfhlMmnoSstw +.Op Fl bcfhlMmNnoSstw .Op Fl e Ar extra .Op Fl F Ar foldwidth .Op Ar file ... @@ -99,15 +99,22 @@ Encode using the URI encoding from RFC 1 Mark newlines with the visible sequence .Ql \e$ , 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 m +Encode using the MIME Quoted-Printable encoding from RFC 2045. +.Pq Dv VIS_MIMESTYLE +.It Fl N +Turn on the +.Dv VIS_NOLOCALE +flag which encodes using the +.Dq C +locale, removing any encoding dependencies caused by the current +locale settings specified in the environment. .It Fl n Turns off any encoding, except for the fact that backslashes are still doubled and hidden newline sequences inserted if @@ -129,14 +136,14 @@ That is, the output can be unfolded by r Request a format which displays non-printable characters as an octal number, \eddd. .Pq Dv VIS_OCTAL +.It Fl S +Encode shell meta-characters that are non-white space or glob. +.Pq Dv VIS_SHELL .It Fl s Only characters considered unsafe to send to a terminal are encoded. 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.24 src/usr.bin/vis/vis.c:1.25 --- src/usr.bin/vis/vis.c:1.24 Thu Sep 25 22:20:39 2014 +++ src/usr.bin/vis/vis.c Sun May 24 15:42:39 2015 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.24 2014/09/26 02:20:39 wiz Exp $ */ +/* $NetBSD: vis.c,v 1.25 2015/05/24 19:42:39 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.24 2014/09/26 02:20:39 wiz Exp $); +__RCSID($NetBSD: vis.c,v 1.25 2015/05/24 19:42:39 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:fhlMmnoSstw)) != -1) + while ((ch = getopt(argc, argv, bcde:F:fhlMmNnoSstw)) != -1) switch((char)ch) { case 'b': eflags |= VIS_NOSLASH; @@ -102,13 +102,16 @@ main(int argc, char *argv[]) case 'l': markeol++; /* mark end of line with \$ */ break; + case 'M': + eflags |= VIS_META; + break; case 'm': eflags |= VIS_MIMESTYLE; if (foldwidth == 80) foldwidth = 76; break; - case 'M': - eflags |= VIS_META; + case 'N': + eflags |= VIS_NOLOCALE; break; case 'n': none++; @@ -116,12 +119,12 @@ main(int argc, char *argv[]) case 'o': eflags |= VIS_OCTAL; break; - case 's': - eflags |= VIS_SAFE; - break; case 'S': eflags |= VIS_SHELL; break; + case 's': + eflags |= VIS_SAFE; + break; case 't': eflags |= VIS_TAB; break; @@ -131,7 +134,7 @@ main(int argc, char *argv[]) case '?': default: (void)fprintf(stderr, - Usage: %s [-bcfhlMmnoSstw] [-e extra] + Usage: %s [-bcfhlMmNnoSstw] [-e extra] [-F foldwidth] [file ...]\n, getprogname()); return 1; }
CVS commit: src/usr.bin/vis
Module Name:src Committed By: wiz Date: Fri Sep 26 02:20:39 UTC 2014 Modified Files: src/usr.bin/vis: vis.1 vis.c Log Message: Sort options in SYNOPSIS/usage. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 src/usr.bin/vis/vis.1 cvs rdiff -u -r1.23 -r1.24 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/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.21 src/usr.bin/vis/vis.1:1.22 --- src/usr.bin/vis/vis.1:1.21 Fri Sep 26 01:21:07 2014 +++ src/usr.bin/vis/vis.1 Fri Sep 26 02:20:39 2014 @@ -1,4 +1,4 @@ -.\ $NetBSD: vis.1,v 1.21 2014/09/26 01:21:07 christos Exp $ +.\ $NetBSD: vis.1,v 1.22 2014/09/26 02:20:39 wiz Exp $ .\ .\ Copyright (c) 1989, 1991, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -37,7 +37,7 @@ .Nd display non-printable characters in a visual format .Sh SYNOPSIS .Nm -.Op Fl bcfhlmMnosStw +.Op Fl bcfhlMmnoSstw .Op Fl e Ar extra .Op Fl F Ar foldwidth .Op Ar file ... Index: src/usr.bin/vis/vis.c diff -u src/usr.bin/vis/vis.c:1.23 src/usr.bin/vis/vis.c:1.24 --- src/usr.bin/vis/vis.c:1.23 Fri Sep 26 01:21:07 2014 +++ src/usr.bin/vis/vis.c Fri Sep 26 02:20:39 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.23 2014/09/26 01:21:07 christos Exp $ */ +/* $NetBSD: vis.c,v 1.24 2014/09/26 02:20:39 wiz 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.23 2014/09/26 01:21:07 christos Exp $); +__RCSID($NetBSD: vis.c,v 1.24 2014/09/26 02:20:39 wiz 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:fhlmMnosStw)) != -1) + while ((ch = getopt(argc, argv, bcde:F:fhlMmnoSstw)) != -1) switch((char)ch) { case 'b': eflags |= VIS_NOSLASH; @@ -131,7 +131,7 @@ main(int argc, char *argv[]) case '?': default: (void)fprintf(stderr, - Usage: %s [-bcfhlmMnosStw] [-e extra] + Usage: %s [-bcfhlMmnoSstw] [-e extra] [-F foldwidth] [file ...]\n, getprogname()); return 1; }
CVS commit: src/usr.bin/vis
Module Name:src Committed By: njoly Date: Tue Oct 29 12:27:23 UTC 2013 Modified Files: src/usr.bin/vis: vis.1 Log Message: Small typo. From Michael W. Bombardieri. To generate a diff of this commit: cvs rdiff -u -r1.19 -r1.20 src/usr.bin/vis/vis.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.19 src/usr.bin/vis/vis.1:1.20 --- src/usr.bin/vis/vis.1:1.19 Thu Mar 14 19:17:23 2013 +++ src/usr.bin/vis/vis.1 Tue Oct 29 12:27:23 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: vis.1,v 1.19 2013/03/14 19:17:23 njoly Exp $ +.\ $NetBSD: vis.1,v 1.20 2013/10/29 12:27:23 njoly Exp $ .\ .\ Copyright (c) 1989, 1991, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -164,7 +164,7 @@ The .Nm command appears in .Bx 4.4 . -Myltibyte character support was added in +Multibyte character support was added in .Nx 7.0 and .Fx 9.2 .
CVS commit: src/usr.bin/vis
Module Name:src Committed By: njoly Date: Thu Mar 14 19:17:23 UTC 2013 Modified Files: src/usr.bin/vis: vis.1 Log Message: Add missing .El macro. To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 src/usr.bin/vis/vis.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.18 src/usr.bin/vis/vis.1:1.19 --- src/usr.bin/vis/vis.1:1.18 Wed Feb 27 20:12:44 2013 +++ src/usr.bin/vis/vis.1 Thu Mar 14 19:17:23 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: vis.1,v 1.18 2013/02/27 20:12:44 christos Exp $ +.\ $NetBSD: vis.1,v 1.19 2013/03/14 19:17:23 njoly Exp $ .\ .\ Copyright (c) 1989, 1991, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -154,6 +154,7 @@ instead. .It Ev LC_CTYPE Specify the locale of the input data. Set to C if the input data locale is unknown. +.El .Sh SEE ALSO .Xr unvis 1 , .Xr svis 3 ,
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Wed Feb 27 20:12:44 UTC 2013 Modified Files: src/usr.bin/vis: vis.1 Log Message: update dates, version To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/vis/vis.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.17 src/usr.bin/vis/vis.1:1.18 --- src/usr.bin/vis/vis.1:1.17 Thu Feb 14 09:00:00 2013 +++ src/usr.bin/vis/vis.1 Wed Feb 27 15:12:44 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: vis.1,v 1.17 2013/02/14 14:00:00 christos Exp $ +.\ $NetBSD: vis.1,v 1.18 2013/02/27 20:12:44 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 13, 2013 +.Dd February 19, 2013 .Dt VIS 1 .Os .Sh NAME @@ -164,6 +164,6 @@ The command appears in .Bx 4.4 . Myltibyte character support was added in -.Nx 6.1 +.Nx 7.0 and .Fx 9.2 .
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Wed Feb 20 17:04:45 UTC 2013 Modified Files: src/usr.bin/vis: vis.c Log Message: use MB_LEN_MAX directly instead of assuming how large it is. To generate a diff of this commit: cvs rdiff -u -r1.21 -r1.22 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/usr.bin/vis/vis.c diff -u src/usr.bin/vis/vis.c:1.21 src/usr.bin/vis/vis.c:1.22 --- src/usr.bin/vis/vis.c:1.21 Thu Feb 14 19:29:44 2013 +++ src/usr.bin/vis/vis.c Wed Feb 20 12:04:45 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.21 2013/02/15 00:29:44 christos Exp $ */ +/* $NetBSD: vis.c,v 1.22 2013/02/20 17:04:45 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.21 2013/02/15 00:29:44 christos Exp $); +__RCSID($NetBSD: vis.c,v 1.22 2013/02/20 17:04:45 christos Exp $); #endif /* not lint */ #include stdio.h @@ -162,8 +162,8 @@ process(FILE *fp) static char nul[] = \0; char *cp = nul + 1; /* so *(cp-1) starts out != '\n' */ wint_t c, c1, rachar; - char mbibuff[13]; /* (2 wchars (i.e., c + c1)) * MB_LEN_MAX) */ - char buff[5]; /* max vis-encoding length for one char + NUL */ + char mbibuff[2 * MB_LEN_MAX + 1]; /* max space for 2 wchars */ + char buff[4 * MB_LEN_MAX + 1]; /* max encoding length for one char */ int mbilen, cerr = 0, raerr = 0; /* @@ -189,8 +189,9 @@ process(FILE *fp) /* Clear multibyte input buffer. */ memset(mbibuff, 0, sizeof(mbibuff)); /* Read-ahead next multibyte character. */ - rachar = getwc(fp); - if (rachar == WEOF errno == EILSEQ) { + if (!cerr) + rachar = getwc(fp); + if (cerr || (rachar == WEOF errno == EILSEQ)) { /* Error in multibyte data. Read one byte. */ rachar = (wint_t)getc(fp); raerr = 1; @@ -245,7 +246,8 @@ process(FILE *fp) else wctomb(mbibuff + mbilen, c1); /* Perform encoding on just first character. */ - (void)strsvisx(buff, mbibuff, 1, eflags, extra); + (void) strsenvisx(buff, 4 * MB_LEN_MAX, mbibuff, + 1, eflags, extra, cerr); } cp = buff; @@ -265,7 +267,6 @@ process(FILE *fp) } while (*++cp); c = rachar; cerr = raerr; - raerr = 0; } /* * terminate partial line with a hidden newline
CVS commit: src/usr.bin/vis
Module Name:src Committed By: wiz Date: Thu Feb 14 08:56:59 UTC 2013 Modified Files: src/usr.bin/vis: vis.1 Log Message: Mark up LC_CTYPE with Ev (didn't I just do this? :) ). To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 src/usr.bin/vis/vis.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files. Modified files: Index: src/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.15 src/usr.bin/vis/vis.1:1.16 --- src/usr.bin/vis/vis.1:1.15 Wed Feb 13 22:24:48 2013 +++ src/usr.bin/vis/vis.1 Thu Feb 14 08:56:59 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: vis.1,v 1.15 2013/02/13 22:24:48 christos Exp $ +.\ $NetBSD: vis.1,v 1.16 2013/02/14 08:56:59 wiz Exp $ .\ .\ Copyright (c) 1989, 1991, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -138,12 +138,14 @@ White space (space-tab-newline) is also .Sh MULTIBYTE CHARACTER SUPPORT .Nm supports multibyte character input. -The encoding conversion is influenced by the setting of the LC_CTYPE +The encoding conversion is influenced by the setting of the +.Ev LC_CTYPE environment variable which defines the set of characters that can be copied without encoding. .Pp -When 8-bit data is present in the input, LC_CTYPE must be set to -the correct locale or to the C locale. +When 8-bit data is present in the input, +.Ev LC_CTYPE +must be set to the correct locale or to the C locale. If the locales of the data and the conversion are mismatched, multibyte character recognition may fail and encoding will be performed byte-by-byte instead.
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Thu Feb 14 14:00:01 UTC 2013 Modified Files: src/usr.bin/vis: vis.1 vis.c Log Message: do the encoding character by character instead of failing on encoding mismatch To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.bin/vis/vis.1 cvs rdiff -u -r1.19 -r1.20 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/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.16 src/usr.bin/vis/vis.1:1.17 --- src/usr.bin/vis/vis.1:1.16 Thu Feb 14 03:56:59 2013 +++ src/usr.bin/vis/vis.1 Thu Feb 14 09:00:00 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: vis.1,v 1.16 2013/02/14 08:56:59 wiz Exp $ +.\ $NetBSD: vis.1,v 1.17 2013/02/14 14:00:00 christos Exp $ .\ .\ Copyright (c) 1989, 1991, 1993, 1994 .\ The Regents of the University of California. All rights reserved. @@ -149,11 +149,6 @@ must be set to the correct locale or to If the locales of the data and the conversion are mismatched, multibyte character recognition may fail and encoding will be performed byte-by-byte instead. -The result of encoding using -.Nm -followed by decoding using -.Xr unvis 3 -is unlikely to return the same input data in this case. .Sh ENVIRONMENT .Bl -tag -width .Ev LC_CTYPE .It Ev LC_CTYPE Index: src/usr.bin/vis/vis.c diff -u src/usr.bin/vis/vis.c:1.19 src/usr.bin/vis/vis.c:1.20 --- src/usr.bin/vis/vis.c:1.19 Wed Feb 13 17:28:41 2013 +++ src/usr.bin/vis/vis.c Thu Feb 14 09:00:01 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.19 2013/02/13 22:28:41 christos Exp $ */ +/* $NetBSD: vis.c,v 1.20 2013/02/14 14:00:01 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.19 2013/02/13 22:28:41 christos Exp $); +__RCSID($NetBSD: vis.c,v 1.20 2013/02/14 14:00:01 christos Exp $); #endif /* not lint */ #include stdio.h @@ -161,17 +161,21 @@ process(FILE *fp) static char nul[] = \0; char *cp = nul + 1; /* so *(cp-1) starts out != '\n' */ wint_t c, c1, rachar; - wchar_t ibuff[3]; /* room for c + rachar + NUL */ char mbibuff[13]; /* ((sizeof(ibuff) - 1) * MB_LEN_MAX) + NUL */ char buff[5]; /* max vis-encoding length for one char + NUL */ + int mbilen, cerr = 0, raerr = 0; c = getwc(fp); - if (c == WEOF errno == EILSEQ) + if (c == WEOF errno == EILSEQ) { c = (wint_t)getc(fp); + cerr = 1; + } while (c != WEOF) { rachar = getwc(fp); - if (rachar == WEOF errno == EILSEQ) + if (rachar == WEOF errno == EILSEQ) { rachar = (wint_t)getc(fp); + raerr = 1; + } if (none) { cp = buff; *cp++ = c; @@ -189,10 +193,16 @@ process(FILE *fp) c1 = rachar; if (c1 == WEOF) c1 = L'\0'; - swprintf(ibuff, 3, L%lc%lc, c, c1); - wcstombs(mbibuff, ibuff, - (wcslen(ibuff) * MB_LEN_MAX) + 1); - (void) strsvisx(buff, mbibuff, 1, eflags, extra); + if (cerr) { +*mbibuff = c; +mbilen = 1; + } else +mbilen = wctomb(mbibuff, c); + if (raerr) +mbibuff[mbilen] = c1; + else +wctomb(mbibuff + mbilen, c1); + (void)strsvisx(buff, mbibuff, mbilen, eflags, extra); } cp = buff; @@ -211,6 +221,8 @@ process(FILE *fp) (void)putchar(*cp); } while (*++cp); c = rachar; + cerr = raerr; + raerr = 0; } /* * terminate partial line with a hidden newline
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Fri Feb 15 00:29:45 UTC 2013 Modified Files: src/usr.bin/vis: vis.c Log Message: More fixes from J.R. Oldroyd: - I have added a call to memset() to clear the mbibuff on each loop. Since we're dealing with possibly broken multibyte sequences, clearing it will avoid problems with a new input sequence possibly being confused by extra bytes still there from the last iteration. wctomb(), which is used to fill that buffer, does not append a NUL. - I have added a (char) cast when copying single bytes into the input buffer after a multibyte conversion error. - In the call to strvisx() the count must be 1, not mbilen which can be 2 or 3 etc for a multibyte character. This value is a count of characters - not bytes - to process. It even says characters in the man page. In vis(3) I am interpreting this value to mean multibyte characters. To generate a diff of this commit: cvs rdiff -u -r1.20 -r1.21 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/usr.bin/vis/vis.c diff -u src/usr.bin/vis/vis.c:1.20 src/usr.bin/vis/vis.c:1.21 --- src/usr.bin/vis/vis.c:1.20 Thu Feb 14 09:00:01 2013 +++ src/usr.bin/vis/vis.c Thu Feb 14 19:29:44 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.20 2013/02/14 14:00:01 christos Exp $ */ +/* $NetBSD: vis.c,v 1.21 2013/02/15 00:29:44 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -39,12 +39,13 @@ __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.20 2013/02/14 14:00:01 christos Exp $); +__RCSID($NetBSD: vis.c,v 1.21 2013/02/15 00:29:44 christos Exp $); #endif /* not lint */ #include stdio.h #include string.h #include stdlib.h +#include string.h #include errno.h #include wchar.h #include limits.h @@ -160,29 +161,49 @@ process(FILE *fp) static int col = 0; static char nul[] = \0; char *cp = nul + 1; /* so *(cp-1) starts out != '\n' */ - wint_t c, c1, rachar; - char mbibuff[13]; /* ((sizeof(ibuff) - 1) * MB_LEN_MAX) + NUL */ + wint_t c, c1, rachar; + char mbibuff[13]; /* (2 wchars (i.e., c + c1)) * MB_LEN_MAX) */ char buff[5]; /* max vis-encoding length for one char + NUL */ int mbilen, cerr = 0, raerr = 0; +/* + * The input stream is considered to be multibyte characters. + * The input loop will read this data inputing one character, + * possibly multiple bytes, at a time and converting each to + * a wide character wchar_t. + * + * The vis(3) functions, however, require single either bytes + * or a multibyte string as their arguments. So we convert + * our input wchar_t and the following look-ahead wchar_t to + * a multibyte string for processing by vis(3). + */ + + /* Read one multibyte character, store as wchar_t */ c = getwc(fp); if (c == WEOF errno == EILSEQ) { + /* Error in multibyte data. Read one byte. */ c = (wint_t)getc(fp); cerr = 1; } while (c != WEOF) { + /* Clear multibyte input buffer. */ + memset(mbibuff, 0, sizeof(mbibuff)); + /* Read-ahead next multibyte character. */ rachar = getwc(fp); if (rachar == WEOF errno == EILSEQ) { + /* Error in multibyte data. Read one byte. */ rachar = (wint_t)getc(fp); raerr = 1; } if (none) { + /* Handle -n flag. */ cp = buff; *cp++ = c; if (c == '\\') *cp++ = '\\'; *cp = '\0'; } else if (markeol c == '\n') { + /* Handle -l flag. */ cp = buff; if ((eflags VIS_NOSLASH) == 0) *cp++ = '\\'; @@ -190,19 +211,41 @@ process(FILE *fp) *cp++ = '\n'; *cp = '\0'; } else { + /* + * Convert character using vis(3) library. + * At this point we will process one character. + * But we must pass the vis(3) library this + * character plus the next one because the next + * one is used as a look-ahead to decide how to + * encode this one under certain circumstances. + * + * Since our characters may be multibyte, e.g., + * in the UTF-8 locale, we cannot use vis() and + * svis() which require byte input, so we must + * create a multibyte string and use strvisx(). + */ + /* Treat EOF as a NUL char. */ c1 = rachar; if (c1 == WEOF) c1 = L'\0'; + /* + * If we hit a multibyte conversion error above, + * insert byte directly into string buff because + * wctomb() will fail. Else convert wchar_t to + * multibyte using wctomb(). + */ if (cerr) { -*mbibuff = c; +*mbibuff = (char)c; mbilen = 1; } else mbilen = wctomb(mbibuff, c); + /* Same for look-ahead character. */ if (raerr) -mbibuff[mbilen] = c1; +mbibuff[mbilen] = (char)c1; else wctomb(mbibuff + mbilen, c1); - (void)strsvisx(buff, mbibuff, mbilen, eflags, extra); + /* Perform encoding on just first character. */ +
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Wed Feb 13 13:58:44 UTC 2013 Modified Files: src/usr.bin/vis: vis.c Log Message: handle EILSEQ. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 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/usr.bin/vis/vis.c diff -u src/usr.bin/vis/vis.c:1.16 src/usr.bin/vis/vis.c:1.17 --- src/usr.bin/vis/vis.c:1.16 Tue Feb 12 23:52:31 2013 +++ src/usr.bin/vis/vis.c Wed Feb 13 08:58:44 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.16 2013/02/13 04:52:31 christos Exp $ */ +/* $NetBSD: vis.c,v 1.17 2013/02/13 13:58:44 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -39,12 +39,13 @@ __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.16 2013/02/13 04:52:31 christos Exp $); +__RCSID($NetBSD: vis.c,v 1.17 2013/02/13 13:58:44 christos Exp $); #endif /* not lint */ #include stdio.h #include string.h #include stdlib.h +#include errno.h #include wchar.h #include unistd.h #include err.h @@ -162,8 +163,12 @@ process(FILE *fp) char buff[5]; c = getwc(fp); - while (c != EOF) { + if (c == WEOF errno == EILSEQ) + c = (wint_t)getc(fp); + while (c != WEOF) { rachar = getwc(fp); + if (rachar == WEOF errno == EILSEQ) + rachar = (wint_t)getc(fp); if (none) { cp = buff; *cp++ = c;
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Wed Feb 13 22:24:48 UTC 2013 Modified Files: src/usr.bin/vis: vis.1 vis.c Log Message: Multi-byte docs and fixes for 2 mblen charsets from J.R. Oldroyd To generate a diff of this commit: cvs rdiff -u -r1.14 -r1.15 src/usr.bin/vis/vis.1 cvs rdiff -u -r1.17 -r1.18 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/usr.bin/vis/vis.1 diff -u src/usr.bin/vis/vis.1:1.14 src/usr.bin/vis/vis.1:1.15 --- src/usr.bin/vis/vis.1:1.14 Tue Feb 10 18:06:31 2009 +++ src/usr.bin/vis/vis.1 Wed Feb 13 17:24:48 2013 @@ -1,4 +1,4 @@ -.\ $NetBSD: vis.1,v 1.14 2009/02/10 23:06:31 christos Exp $ +.\ $NetBSD: vis.1,v 1.15 2013/02/13 22:24:48 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 10, 2009 +.Dd February 13, 2013 .Dt VIS 1 .Os .Sh NAME @@ -135,6 +135,28 @@ Tabs are also encoded. White space (space-tab-newline) is also encoded. .Pq Dv VIS_WHITE .El +.Sh MULTIBYTE CHARACTER SUPPORT +.Nm +supports multibyte character input. +The encoding conversion is influenced by the setting of the LC_CTYPE +environment variable which defines the set of characters that can be +copied without encoding. +.Pp +When 8-bit data is present in the input, LC_CTYPE must be set to +the correct locale or to the C locale. +If the locales of the data and the conversion are mismatched, multibyte +character recognition may fail and encoding will be performed byte-by-byte +instead. +The result of encoding using +.Nm +followed by decoding using +.Xr unvis 3 +is unlikely to return the same input data in this case. +.Sh ENVIRONMENT +.Bl -tag -width .Ev LC_CTYPE +.It Ev LC_CTYPE +Specify the locale of the input data. +Set to C if the input data locale is unknown. .Sh SEE ALSO .Xr unvis 1 , .Xr svis 3 , @@ -144,3 +166,7 @@ The .Nm command appears in .Bx 4.4 . +Myltibyte character support was added in +.Nx 6.1 +and +.Fx 9.2 . Index: src/usr.bin/vis/vis.c diff -u src/usr.bin/vis/vis.c:1.17 src/usr.bin/vis/vis.c:1.18 --- src/usr.bin/vis/vis.c:1.17 Wed Feb 13 08:58:44 2013 +++ src/usr.bin/vis/vis.c Wed Feb 13 17:24:48 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.17 2013/02/13 13:58:44 christos Exp $ */ +/* $NetBSD: vis.c,v 1.18 2013/02/13 22:24:48 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.17 2013/02/13 13:58:44 christos Exp $); +__RCSID($NetBSD: vis.c,v 1.18 2013/02/13 22:24:48 christos Exp $); #endif /* not lint */ #include stdio.h @@ -47,6 +47,7 @@ __RCSID($NetBSD: vis.c,v 1.17 2013/02/1 #include stdlib.h #include errno.h #include wchar.h +#include limits.h #include unistd.h #include err.h #include vis.h @@ -159,8 +160,10 @@ process(FILE *fp) static int col = 0; static char nul[] = \0; char *cp = nul + 1; /* so *(cp-1) starts out != '\n' */ - wint_t c, rachar; - char buff[5]; + wint_t c, c1, rachar; + wchar_t ibuff[3]; /* room for c + rachar + NUL */ + char mbibuff[13]; /* ((sizeof(ibuff) - 1) * MB_LEN_MAX) + NUL */ + char buff[5]; /* max vis-encoding length for one char + NUL */ c = getwc(fp); if (c == WEOF errno == EILSEQ) @@ -182,10 +185,15 @@ process(FILE *fp) *cp++ = '$'; *cp++ = '\n'; *cp = '\0'; - } else if (extra) - (void)svis(buff, c, eflags, rachar, extra); - else - (void)vis(buff, c, eflags, rachar); + } else { + c1 = rachar; + if (c1 == WEOF) +c1 = L'\0'; + swprintf(ibuff, 3, L%lc%lc, c, c1); + wcstombs(mbibuff, ibuff, + (wcslen(ibuff) * MB_LEN_MAX) + 1); + (void) strsvisx(buff, mbibuff, 1, eflags, extra); + } cp = buff; if (fold) {
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Wed Feb 13 22:28:41 UTC 2013 Modified Files: src/usr.bin/vis: vis.c Log Message: don't allow NULL for extra To generate a diff of this commit: cvs rdiff -u -r1.18 -r1.19 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/usr.bin/vis/vis.c diff -u src/usr.bin/vis/vis.c:1.18 src/usr.bin/vis/vis.c:1.19 --- src/usr.bin/vis/vis.c:1.18 Wed Feb 13 17:24:48 2013 +++ src/usr.bin/vis/vis.c Wed Feb 13 17:28:41 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.18 2013/02/13 22:24:48 christos Exp $ */ +/* $NetBSD: vis.c,v 1.19 2013/02/13 22:28:41 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.18 2013/02/13 22:24:48 christos Exp $); +__RCSID($NetBSD: vis.c,v 1.19 2013/02/13 22:28:41 christos Exp $); #endif /* not lint */ #include stdio.h @@ -58,7 +58,7 @@ static int eflags, fold, foldwidth = 80, #ifdef DEBUG int debug; #endif -static char *extra; +static const char *extra = ; static void process(FILE *);
CVS commit: src/usr.bin/vis
Module Name:src Committed By: christos Date: Wed Feb 13 04:52:31 UTC 2013 Modified Files: src/usr.bin/vis: vis.c Log Message: handle wide chars To generate a diff of this commit: cvs rdiff -u -r1.15 -r1.16 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/usr.bin/vis/vis.c diff -u src/usr.bin/vis/vis.c:1.15 src/usr.bin/vis/vis.c:1.16 --- src/usr.bin/vis/vis.c:1.15 Wed Feb 11 01:42:31 2009 +++ src/usr.bin/vis/vis.c Tue Feb 12 23:52:31 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.15 2009/02/11 06:42:31 wiz Exp $ */ +/* $NetBSD: vis.c,v 1.16 2013/02/13 04:52:31 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -39,12 +39,13 @@ __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.15 2009/02/11 06:42:31 wiz Exp $); +__RCSID($NetBSD: vis.c,v 1.16 2013/02/13 04:52:31 christos Exp $); #endif /* not lint */ #include stdio.h #include string.h #include stdlib.h +#include wchar.h #include unistd.h #include err.h #include vis.h @@ -157,12 +158,12 @@ process(FILE *fp) static int col = 0; static char nul[] = \0; char *cp = nul + 1; /* so *(cp-1) starts out != '\n' */ - int c, rachar; + wint_t c, rachar; char buff[5]; - c = getc(fp); + c = getwc(fp); while (c != EOF) { - rachar = getc(fp); + rachar = getwc(fp); if (none) { cp = buff; *cp++ = c; @@ -177,9 +178,9 @@ process(FILE *fp) *cp++ = '\n'; *cp = '\0'; } else if (extra) - (void)svis(buff, (char)c, eflags, (char)rachar, extra); + (void)svis(buff, c, eflags, rachar, extra); else - (void)vis(buff, (char)c, eflags, (char)rachar); + (void)vis(buff, c, eflags, rachar); cp = buff; if (fold) {