1
0
mirror of https://git.FreeBSD.org/src.git synced 2025-01-04 12:52:15 +00:00

Use err(3). Add usage() and prototypes.

This commit is contained in:
Philippe Charnier 1997-08-25 06:37:37 +00:00
parent 3e7ae69f2a
commit d9be0ac773
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28692
3 changed files with 43 additions and 21 deletions

View File

@ -32,9 +32,16 @@
*/ */
#ifndef lint #ifndef lint
#if 0
static char sccsid[] = "@(#)foldit.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)foldit.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include <stdio.h>
int
foldit(chunk, col, max) foldit(chunk, col, max)
char *chunk; char *chunk;
{ {

View File

@ -38,10 +38,10 @@
.Nm vis .Nm vis
.Nd display non-printable characters in a visual format .Nd display non-printable characters in a visual format
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm vis .Nm
.Op Fl cbflnostw .Op Fl cbflnostw
.Op Fl F Ar foldwidth .Op Fl F Ar foldwidth
.Op Ar file ... .Op Ar
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm Vis .Nm Vis
is a filter for converting non-printable characters is a filter for converting non-printable characters
@ -67,7 +67,7 @@ Request a format which displays a small subset of the
non-printable characters using C-style backslash sequences. non-printable characters using C-style backslash sequences.
.It Fl F .It Fl F
Causes Causes
.Nm vis .Nm
to fold output lines to foldwidth columns (default 80), like to fold output lines to foldwidth columns (default 80), like
.Xr fold 1 , .Xr fold 1 ,
except except
@ -95,7 +95,7 @@ or
is selected. When combined with the is selected. When combined with the
.Fl f .Fl f
flag, flag,
.Nm vis .Nm
becomes like becomes like
an invertible version of the an invertible version of the
.Xr fold 1 .Xr fold 1

View File

@ -32,27 +32,36 @@
*/ */
#ifndef lint #ifndef lint
static char copyright[] = static const char copyright[] =
"@(#) Copyright (c) 1989, 1993\n\ "@(#) Copyright (c) 1989, 1993\n\
The Regents of the University of California. All rights reserved.\n"; The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#ifndef lint #ifndef lint
#if 0
static char sccsid[] = "@(#)vis.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)vis.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
#include <stdio.h> #include <err.h>
#include <vis.h>
#include <locale.h> #include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <vis.h>
int eflags, fold, foldwidth=80, none, markeol, debug; int eflags, fold, foldwidth=80, none, markeol, debug;
void process __P((FILE *, char *filename));
static void usage __P((void));
extern int foldit __P((char *, int, int));
int
main(argc, argv) main(argc, argv)
char *argv[]; char *argv[];
{ {
extern char *optarg;
extern int optind;
extern int errno;
FILE *fp; FILE *fp;
int ch; int ch;
@ -82,11 +91,8 @@ main(argc, argv)
eflags |= VIS_NOSLASH; eflags |= VIS_NOSLASH;
break; break;
case 'F': case 'F':
if ((foldwidth = atoi(optarg))<5) { if ((foldwidth = atoi(optarg))<5)
fprintf(stderr, errx(1, "can't fold lines to less than 5 cols");
"vis: can't fold lines to less than 5 cols\n");
exit(1);
}
/*FALLTHROUGH*/ /*FALLTHROUGH*/
case 'f': case 'f':
fold++; /* fold output lines to 80 cols */ fold++; /* fold output lines to 80 cols */
@ -101,9 +107,7 @@ main(argc, argv)
#endif #endif
case '?': case '?':
default: default:
fprintf(stderr, usage();
"usage: vis [-nwctsobf] [-F foldwidth]\n");
exit(1);
} }
argc -= optind; argc -= optind;
argv += optind; argv += optind;
@ -113,8 +117,7 @@ main(argc, argv)
if ((fp=fopen(*argv, "r")) != NULL) if ((fp=fopen(*argv, "r")) != NULL)
process(fp, *argv); process(fp, *argv);
else else
fprintf(stderr, "vis: %s: %s\n", *argv, warn("%s", *argv);
(char *)strerror(errno));
argv++; argv++;
} }
else else
@ -122,6 +125,19 @@ main(argc, argv)
exit(0); exit(0);
} }
static void
usage()
{
#ifdef DEBUG
fprintf(stderr, "usage: vis [-cbflnostwd] [-F foldwidth] [file ...]\n");
#else
fprintf(stderr, "usage: vis [-cbflnostw] [-F foldwidth] [file ...]\n");
#endif
exit(1);
}
void
process(fp, filename) process(fp, filename)
FILE *fp; FILE *fp;
char *filename; char *filename;
@ -129,7 +145,6 @@ process(fp, filename)
static int col = 0; static int col = 0;
register char *cp = "\0"+1; /* so *(cp-1) starts out != '\n' */ register char *cp = "\0"+1; /* so *(cp-1) starts out != '\n' */
register int c, rachar; register int c, rachar;
register char nc;
char buff[5]; char buff[5];
c = getc(fp); c = getc(fp);