diff options
| author | christos <christos@NetBSD.org> | 2009-02-10 23:06:31 +0000 |
|---|---|---|
| committer | christos <christos@NetBSD.org> | 2009-02-10 23:06:31 +0000 |
| commit | bb0dd6147818d65259296b79d555e7cb09841601 (patch) | |
| tree | db5fd89bb5c1bee43481045702c2cdf6bb38f18d /usr.bin/vis | |
| parent | 78466aa1e74c62c92e0cb9371b8c14c6a1174d8d (diff) | |
Add RFC 2045 MIME Quoted-Printable support.
Diffstat (limited to 'usr.bin/vis')
| -rw-r--r-- | usr.bin/vis/extern.h | 39 | ||||
| -rw-r--r-- | usr.bin/vis/foldit.c | 16 | ||||
| -rw-r--r-- | usr.bin/vis/vis.1 | 9 | ||||
| -rw-r--r-- | usr.bin/vis/vis.c | 125 |
4 files changed, 120 insertions, 69 deletions
diff --git a/usr.bin/vis/extern.h b/usr.bin/vis/extern.h new file mode 100644 index 00000000000..49b6f15b3ba --- /dev/null +++ b/usr.bin/vis/extern.h @@ -0,0 +1,39 @@ +/* $NetBSD: extern.h,v 1.1 2009/02/10 23:06:31 christos Exp $ */ + +/*- + * Copyright (c) 2009 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +int foldit(const char *, int, int, int); diff --git a/usr.bin/vis/foldit.c b/usr.bin/vis/foldit.c index 748d0d29582..789b14cb67c 100644 --- a/usr.bin/vis/foldit.c +++ b/usr.bin/vis/foldit.c @@ -1,4 +1,4 @@ -/* $NetBSD: foldit.c,v 1.6 2003/08/07 11:17:09 agc Exp $ */ +/* $NetBSD: foldit.c,v 1.7 2009/02/10 23:06:31 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -34,19 +34,17 @@ #if 0 static char sccsid[] = "@(#)foldit.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: foldit.c,v 1.6 2003/08/07 11:17:09 agc Exp $"); +__RCSID("$NetBSD: foldit.c,v 1.7 2009/02/10 23:06:31 christos Exp $"); #endif /* not lint */ #include <stdio.h> - -int foldit __P((char *, int, int)); +#include <vis.h> +#include "extern.h" int -foldit(chunk, col, max) - char *chunk; - int col, max; +foldit(const char *chunk, int col, int max, int flags) { - char *cp; + const char *cp; /* * Keep track of column position. Insert hidden newline @@ -70,7 +68,7 @@ again: col++; } if (col > (max - 2)) { - printf("\\\n"); + printf(flags & VIS_MIMESTYLE ? "=\n" : "\\\n"); col = 0; goto again; } diff --git a/usr.bin/vis/vis.1 b/usr.bin/vis/vis.1 index 238972c7dc3..13c28067a11 100644 --- a/usr.bin/vis/vis.1 +++ b/usr.bin/vis/vis.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: vis.1,v 1.13 2004/04/22 06:53:43 lukem Exp $ +.\" $NetBSD: vis.1,v 1.14 2009/02/10 23:06:31 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 April 22, 2004 +.Dd February 10, 2009 .Dt VIS 1 .Os .Sh NAME @@ -37,7 +37,7 @@ .Nd display non-printable characters in a visual format .Sh SYNOPSIS .Nm -.Op Fl bcfhlnostw +.Op Fl bcfhlmnostw .Op Fl e Ar extra .Op Fl F Ar foldwidth .Op Ar file ... @@ -99,6 +99,9 @@ Encode using the URI encoding from RFC 1808. 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 n Turns off any encoding, except for the fact that backslashes are still doubled and hidden newline sequences inserted if diff --git a/usr.bin/vis/vis.c b/usr.bin/vis/vis.c index f4c8c026e07..f2666a29a98 100644 --- a/usr.bin/vis/vis.c +++ b/usr.bin/vis/vis.c @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.12 2008/07/21 14:19:27 lukem Exp $ */ +/* $NetBSD: vis.c,v 1.13 2009/02/10 23:06:31 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\ #if 0 static char sccsid[] = "@(#)vis.c 8.1 (Berkeley) 6/6/93"; #endif -__RCSID("$NetBSD: vis.c,v 1.12 2008/07/21 14:19:27 lukem Exp $"); +__RCSID("$NetBSD: vis.c,v 1.13 2009/02/10 23:06:31 christos Exp $"); #endif /* not lint */ #include <stdio.h> @@ -49,75 +49,87 @@ __RCSID("$NetBSD: vis.c,v 1.12 2008/07/21 14:19:27 lukem Exp $"); #include <err.h> #include <vis.h> -int eflags, fold, foldwidth=80, none, markeol, debug; -char *extra; +#include "extern.h" -int foldit __P((char *, int, int)); -int main __P((int, char **)); -void process __P((FILE *, char *)); +static int eflags, fold, foldwidth = 80, none, markeol; +#ifdef DEBUG +int debug; +#endif +static char *extra; + +static void process(FILE *); int -main(argc, argv) - int argc; - char *argv[]; +main(int argc, char *argv[]) { FILE *fp; int ch; int rval; - while ((ch = getopt(argc, argv, "bcfhlnostwe:F:d")) != -1) + while ((ch = getopt(argc, argv, "bcde:F:fhlmnostw")) != -1) switch((char)ch) { - case 'n': - none++; - break; - case 'w': - eflags |= VIS_WHITE; + case 'b': + eflags |= VIS_NOSLASH; break; case 'c': eflags |= VIS_CSTYLE; break; - case 't': - eflags |= VIS_TAB; - break; - case 's': - eflags |= VIS_SAFE; - break; - case 'o': - eflags |= VIS_OCTAL; - break; - case 'h': - eflags |= VIS_HTTPSTYLE; - break; - case 'b': - eflags |= VIS_NOSLASH; +#ifdef DEBUG + case 'd': + debug++; break; +#endif case 'e': extra = optarg; break; case 'F': - if ((foldwidth = atoi(optarg))<5) { + if ((foldwidth = atoi(optarg)) < 5) { errx(1, "can't fold lines to less than 5 cols"); /* NOTREACHED */ } - /*FALLTHROUGH*/ + markeol++; + break; case 'f': fold++; /* fold output lines to 80 cols */ break; /* using hidden newline */ + case 'h': + eflags |= VIS_HTTPSTYLE; + break; case 'l': markeol++; /* mark end of line with \$ */ break; -#ifdef DEBUG - case 'd': - debug++; + case 'm': + eflags |= VIS_MIMESTYLE; + if (foldwidth == 80) + foldwidth = 76; + break; + case 'n': + none++; + break; + case 'o': + eflags |= VIS_OCTAL; + break; + case 's': + eflags |= VIS_SAFE; + break; + case 't': + eflags |= VIS_TAB; + break; + case 'w': + eflags |= VIS_WHITE; break; -#endif case '?': default: - fprintf(stderr, - "usage: %s [-bcfhlnostw] [-e extra] [-F foldwidth]" - " [file ...]\n", getprogname()); - exit(1); + (void)fprintf(stderr, + "Usage: %s [-bcfhlmmnostw] [-e extra]" + " [-F foldwidth] [file ...]\n", getprogname()); + return 1; } + + if (eflags & (VIS_HTTPSTYLE|VIS_MIMESTYLE) == + (VIS_HTTPSTYLE|VIS_MIMESTYLE)) + errx(1, "Can't specify -m and -h at the same time"); + argc -= optind; argv += optind; @@ -125,9 +137,9 @@ main(argc, argv) if (*argv) while (*argv) { - if ((fp=fopen(*argv, "r")) != NULL) { - process(fp, *argv); - fclose(fp); + if ((fp = fopen(*argv, "r")) != NULL) { + process(fp); + (void)fclose(fp); } else { warn("%s", *argv); rval = 1; @@ -136,16 +148,15 @@ main(argc, argv) } else process(stdin, "<stdin>"); - exit(rval); + return rval; } -void -process(fp, filename) - FILE *fp; - char *filename; +static void +process(FILE *fp) { static int col = 0; - char *cp = "\0"+1; /* so *(cp-1) starts out != '\n' */ + static char nul[] = "\0"; + char *cp = nul + 1; /* so *(cp-1) starts out != '\n' */ int c, rachar; char buff[5]; @@ -166,30 +177,30 @@ process(fp, filename) *cp++ = '\n'; *cp = '\0'; } else if (extra) - (void) svis(buff, (char)c, eflags, (char)rachar, extra); + (void)svis(buff, (char)c, eflags, (char)rachar, extra); else - (void) vis(buff, (char)c, eflags, (char)rachar); + (void)vis(buff, (char)c, eflags, (char)rachar); cp = buff; if (fold) { #ifdef DEBUG if (debug) - printf("<%02d,", col); + (void)printf("<%02d,", col); #endif - col = foldit(cp, col, foldwidth); + col = foldit(cp, col, foldwidth, eflags); #ifdef DEBUG if (debug) - printf("%02d>", col); + (void)printf("%02d>", col); #endif } do { - putchar(*cp); + (void)putchar(*cp); } while (*++cp); c = rachar; } /* * terminate partial line with a hidden newline */ - if (fold && *(cp-1) != '\n') - printf("\\\n"); + if (fold && *(cp - 1) != '\n') + (void)printf(eflags & VIS_MIMESTYLE ? "=\n" : "\\\n"); } |
