Use err(3) and add usage().

This commit is contained in:
Philippe Charnier 1997-08-20 11:05:28 +00:00
parent c7c16beb22
commit 56d8f922bf
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28456

View File

@ -32,24 +32,33 @@
*/ */
#ifndef lint #ifndef lint
static char copyright[] = static const char copyright[] =
"@(#) Copyright (c) 1980, 1993\n\ "@(#) Copyright (c) 1980, 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[] = "@(#)unexpand.c 8.1 (Berkeley) 6/6/93"; static char sccsid[] = "@(#)unexpand.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */ #endif /* not lint */
/* /*
* unexpand - put tabs into a file replacing blanks * unexpand - put tabs into a file replacing blanks
*/ */
#include <err.h>
#include <stdio.h> #include <stdio.h>
char genbuf[BUFSIZ]; char genbuf[BUFSIZ];
char linebuf[BUFSIZ]; char linebuf[BUFSIZ];
int all; int all;
static void usage __P((void));
void tabify __P((char));
void
main(argc, argv) main(argc, argv)
int argc; int argc;
char *argv[]; char *argv[];
@ -58,19 +67,15 @@ main(argc, argv)
argc--, argv++; argc--, argv++;
if (argc > 0 && argv[0][0] == '-') { if (argc > 0 && argv[0][0] == '-') {
if (strcmp(argv[0], "-a") != 0) { if (strcmp(argv[0], "-a") != 0)
fprintf(stderr, "usage: unexpand [ -a ] file ...\n"); usage();
exit(1);
}
all++; all++;
argc--, argv++; argc--, argv++;
} }
do { do {
if (argc > 0) { if (argc > 0) {
if (freopen(argv[0], "r", stdin) == NULL) { if (freopen(argv[0], "r", stdin) == NULL)
perror(argv[0]); err(1, "%s", argv[0]);
exit(1);
}
argc--, argv++; argc--, argv++;
} }
while (fgets(genbuf, BUFSIZ, stdin) != NULL) { while (fgets(genbuf, BUFSIZ, stdin) != NULL) {
@ -85,6 +90,14 @@ main(argc, argv)
exit(0); exit(0);
} }
static void
usage()
{
fprintf(stderr, "usage: unexpand [-a] file ...\n");
exit(1);
}
void
tabify(c) tabify(c)
char c; char c;
{ {