1 /* $NetBSD: vis.c,v 1.14 2009/02/11 03:04:52 christos Exp $ */
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/cdefs.h>
34 __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
35 The Regents of the University of California. All rights reserved.");
40 static char sccsid
[] = "@(#)vis.c 8.1 (Berkeley) 6/6/93";
42 __RCSID("$NetBSD: vis.c,v 1.14 2009/02/11 03:04:52 christos Exp $");
54 static int eflags
, fold
, foldwidth
= 80, none
, markeol
;
60 static void process(FILE *);
63 main(int argc
, char *argv
[])
69 while ((ch
= getopt(argc
, argv
, "bcde:F:fhlmnostw")) != -1)
72 eflags
|= VIS_NOSLASH
;
86 if ((foldwidth
= atoi(optarg
)) < 5) {
87 errx(1, "can't fold lines to less than 5 cols");
93 fold
++; /* fold output lines to 80 cols */
94 break; /* using hidden newline */
96 eflags
|= VIS_HTTPSTYLE
;
99 markeol
++; /* mark end of line with \$ */
102 eflags
|= VIS_MIMESTYLE
;
123 (void)fprintf(stderr
,
124 "Usage: %s [-bcfhlmnostw] [-e extra]"
125 " [-F foldwidth] [file ...]\n", getprogname());
129 if ((eflags
& (VIS_HTTPSTYLE
|VIS_MIMESTYLE
)) ==
130 (VIS_HTTPSTYLE
|VIS_MIMESTYLE
))
131 errx(1, "Can't specify -m and -h at the same time");
140 if ((fp
= fopen(*argv
, "r")) != NULL
) {
158 static char nul
[] = "\0";
159 char *cp
= nul
+ 1; /* so *(cp-1) starts out != '\n' */
172 } else if (markeol
&& c
== '\n') {
174 if ((eflags
& VIS_NOSLASH
) == 0)
180 (void)svis(buff
, (char)c
, eflags
, (char)rachar
, extra
);
182 (void)vis(buff
, (char)c
, eflags
, (char)rachar
);
188 (void)printf("<%02d,", col
);
190 col
= foldit(cp
, col
, foldwidth
, eflags
);
193 (void)printf("%02d>", col
);
202 * terminate partial line with a hidden newline
204 if (fold
&& *(cp
- 1) != '\n')
205 (void)printf(eflags
& VIS_MIMESTYLE
? "=\n" : "\\\n");