summaryrefslogtreecommitdiffstats
path: root/usr.bin/indent
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-07-15 09:50:59 +0000
committercharnier <charnier@FreeBSD.org>1997-07-15 09:50:59 +0000
commitbc62cc22d428b8bf365811ff033a3696292c0300 (patch)
tree7b10c0aea4854d3f1d7ff46e9bef9b304129a472 /usr.bin/indent
parent793ad1484d5d406c30d3f2b2cd3a648dec3bbe02 (diff)
downloadFreeBSD-src-bc62cc22d428b8bf365811ff033a3696292c0300.zip
FreeBSD-src-bc62cc22d428b8bf365811ff033a3696292c0300.tar.gz
Use err(3) instead of local redefinition. Add usage().
Diffstat (limited to 'usr.bin/indent')
-rw-r--r--usr.bin/indent/args.c22
-rw-r--r--usr.bin/indent/indent.122
-rw-r--r--usr.bin/indent/indent.c49
-rw-r--r--usr.bin/indent/io.c12
4 files changed, 54 insertions, 51 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c
index e62f038..376a603 100644
--- a/usr.bin/indent/args.c
+++ b/usr.bin/indent/args.c
@@ -34,7 +34,11 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
/*
@@ -42,8 +46,9 @@ static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";
* here as well.
*/
-#include <stdio.h>
#include <ctype.h>
+#include <err.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "indent_globs.h"
@@ -230,8 +235,7 @@ set_option(arg)
for (p = pro; p->p_name; p++)
if (*p->p_name == *arg && eqin(p->p_name, arg))
goto found;
- fprintf(stderr, "indent: %s: unknown parameter \"%s\"\n", option_source, arg - 1);
- exit(1);
+ errx(1, "%s: unknown parameter \"%s\"", option_source, arg - 1);
found:
switch (p->p_type) {
@@ -265,9 +269,7 @@ found:
break;
default:
- fprintf(stderr, "\
-indent: set_option: internal error: p_special %d\n", p->p_special);
- exit(1);
+ errx(1, "set_option: internal error: p_special %d", p->p_special);
}
break;
@@ -281,9 +283,7 @@ indent: set_option: internal error: p_special %d\n", p->p_special);
case PRO_INT:
if (!isdigit(*param_start)) {
need_param:
- fprintf(stderr, "indent: %s: ``%s'' requires a parameter\n",
- option_source, arg - 1);
- exit(1);
+ errx(1, "%s: ``%s'' requires a parameter", option_source, arg - 1);
}
*p->p_obj = atoi(param_start);
break;
@@ -293,8 +293,6 @@ indent: set_option: internal error: p_special %d\n", p->p_special);
break;
default:
- fprintf(stderr, "indent: set_option: internal error: p_type %d\n",
- p->p_type);
- exit(1);
+ errx(1, "set_option: internal error: p_type %d", p->p_type);
}
}
diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1
index 7f92a23..9b760ba 100644
--- a/usr.bin/indent/indent.1
+++ b/usr.bin/indent/indent.1
@@ -40,7 +40,7 @@
.Nm indent
.Nd indent and format C program source
.Sh SYNOPSIS
-.Nm indent
+.Nm
.Op Ar input-file Op Ar output-file
.Op Fl bad | Fl nbad
.Op Fl bap | Fl nbap
@@ -108,7 +108,7 @@ the backup file is named
If
.Ar output-file
is specified,
-.Nm indent
+.Nm
checks to make sure it is different from
.Ar input-file .
.Pp
@@ -314,7 +314,7 @@ get rid of blank lines after declarations. Default:
.Fl nsob .
.It Fl \&st
Causes
-.Nm indent
+.Nm
to take its input from stdin, and put its output to stdout.
.It Fl T Ns Ar typename
Adds
@@ -331,13 +331,13 @@ a symptom of a problem in C:
.Ic typedef
causes a syntactic change in the
language and
-.Nm indent
+.Nm
can't find all
instances of
.Ic typedef .
.It Fl troff
Causes
-.Nm indent
+.Nm
to format the program for processing by
.Xr troff 1 .
It will produce a fancy
@@ -350,20 +350,20 @@ rather than formatting in place.
turns on `verbose' mode;
.Fl \&nv
turns it off. When in verbose mode,
-.Nm indent
+.Nm
reports when it splits one line of input into two or more lines of output,
and gives some size statistics at completion. The default is
.Fl \&nv .
.El
.Pp
You may set up your own `profile' of defaults to
-.Nm indent
+.Nm
by creating a file called
.Pa .indent.pro
in your login directory and/or the current directory and including
whatever switches you like. A `.indent.pro' in the current directory takes
precedence over the one in your login directory. If
-.Nm indent
+.Nm
is run and a profile file exists, then it is read to set up the program's
defaults. Switches on the command line, though, always override profile
switches. The switches should be separated by spaces, tabs or newlines.
@@ -400,13 +400,13 @@ automatically extended in extreme cases.
.Pp
.Ss Preprocessor lines
In general,
-.Nm indent
+.Nm
leaves preprocessor lines alone. The only
reformatting that it will do is to straighten up trailing comments. It
leaves embedded comments alone. Conditional compilation
.Pq Ic #ifdef...#endif
is recognized and
-.Nm indent
+.Nm
attempts to correctly
compensate for the syntactic peculiarities introduced.
.Pp
@@ -433,7 +433,7 @@ profile file
.El
.Sh HISTORY
The
-.Nm indent
+.Nm
command appeared in
.Bx 4.2 .
.Sh BUGS
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index 132d21f..4dba8d5 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -34,7 +34,7 @@
*/
#ifndef lint
-char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1985 Sun Microsystems, Inc.\n\
@(#) Copyright (c) 1976 Board of Trustees of the University of Illinois.\n\
@(#) Copyright (c) 1980, 1993\n\
@@ -42,10 +42,15 @@ char copyright[] =
#endif /* not lint */
#ifndef lint
+#if 0
static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
#include <sys/param.h>
+#include <err.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
@@ -61,6 +66,8 @@ char *out_name = "Standard Output"; /* will always point to name
* of output file */
char bakfile[MAXPATHLEN] = "";
+static void usage __P((void));
+
main(argc, argv)
int argc;
char **argv;
@@ -182,30 +189,27 @@ main(argc, argv)
in_name = argv[i]; /* remember name of input file */
input = fopen(in_name, "r");
if (input == 0) /* check for open error */
- err(in_name);
+ err(1, in_name);
continue;
}
else if (output == 0) { /* we have the output file */
out_name = argv[i]; /* remember name of output file */
if (strcmp(in_name, out_name) == 0) { /* attempt to overwrite
* the file */
- fprintf(stderr, "indent: input and output files must be different\n");
- exit(1);
+ errx(1, "input and output files must be different");
}
output = fopen(out_name, "w");
if (output == 0) /* check for create error */
- err(out_name);
+ err(1, out_name);
continue;
}
- fprintf(stderr, "indent: unknown parameter: %s\n", argv[i]);
- exit(1);
+ errx(1, "unknown parameter: %s", argv[i]);
}
else
set_option(argv[i]);
} /* end of for */
if (input == 0) {
- fprintf(stderr, "indent: usage: indent file [ outfile ] [ options ]\n");
- exit(1);
+ usage();
}
if (output == 0)
if (troff)
@@ -1126,6 +1130,13 @@ check_type:
} /* end of main while (1) loop */
}
+static void
+usage()
+{
+ fprintf(stderr, "usage: indent file [ outfile ] [ options ]\n");
+ exit(1);
+}
+
/*
* copy input file to backup file if in_name is /blah/blah/blah/file, then
* backup file will be ".Bfile" then make the backup file the input and
@@ -1149,33 +1160,23 @@ bakcopy()
/* copy in_name to backup file */
bakchn = creat(bakfile, 0600);
if (bakchn < 0)
- err(bakfile);
+ err(1, bakfile);
while (n = read(fileno(input), buff, sizeof buff))
if (write(bakchn, buff, n) != n)
- err(bakfile);
+ err(1, bakfile);
if (n < 0)
- err(in_name);
+ err(1, in_name);
close(bakchn);
fclose(input);
/* re-open backup file as the input file */
input = fopen(bakfile, "r");
if (input == 0)
- err(bakfile);
+ err(1, bakfile);
/* now the original input file will be the output */
output = fopen(in_name, "w");
if (output == 0) {
unlink(bakfile);
- err(in_name);
+ err(1, in_name);
}
}
-
-err(msg)
- char *msg;
-{
- extern int errno;
- char *strerror();
-
- (void)fprintf(stderr, "indent: %s: %s\n", msg, strerror(errno));
- exit(1);
-}
diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c
index ae98242..d2222aa 100644
--- a/usr.bin/indent/io.c
+++ b/usr.bin/indent/io.c
@@ -34,11 +34,16 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";
+#endif
+static const char rcsid[] =
+ "$Id$";
#endif /* not lint */
-#include <stdio.h>
#include <ctype.h>
+#include <err.h>
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "indent_globs.h"
@@ -348,7 +353,7 @@ fill_buffer()
register offset = p - in_buffer;
in_buffer = (char *) realloc(in_buffer, size);
if (in_buffer == 0)
- err("input line too long");
+ err(1, "input line too long");
p = in_buffer + offset;
in_buffer_limit = in_buffer + size - 2;
}
@@ -607,8 +612,7 @@ parsefont(f, s0)
else if (*s == '-')
sizedelta--;
else {
- fprintf(stderr, "indent: bad font specification: %s\n", s0);
- exit(1);
+ errx(1, "bad font specification: %s", s0);
}
s++;
}
OpenPOWER on IntegriCloud