aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorJens Schweikhardt <schweikh@FreeBSD.org>2004-07-11 19:24:14 +0000
committerJens Schweikhardt <schweikh@FreeBSD.org>2004-07-11 19:24:14 +0000
commit183462409bc3dea08a985d851583d473b76a3cd3 (patch)
treecfc65ea428cf6747d25e6be104df0e95cb41609b /usr.bin
parentc2dad9ae3f8227152fa495fb14482599b750f34c (diff)
Notes
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/indent/README7
-rw-r--r--usr.bin/indent/args.c55
-rw-r--r--usr.bin/indent/indent.1222
-rw-r--r--usr.bin/indent/indent.c137
-rw-r--r--usr.bin/indent/indent.h8
-rw-r--r--usr.bin/indent/indent_globs.h29
-rw-r--r--usr.bin/indent/io.c82
-rw-r--r--usr.bin/indent/lexi.c60
-rw-r--r--usr.bin/indent/parse.c10
-rw-r--r--usr.bin/indent/pr_comment.c10
10 files changed, 395 insertions, 225 deletions
diff --git a/usr.bin/indent/README b/usr.bin/indent/README
index 618f1de1fe50..03d5d3d8d39e 100644
--- a/usr.bin/indent/README
+++ b/usr.bin/indent/README
@@ -1,3 +1,6 @@
+
+ $FreeBSD$
+
This is the C indenter, it originally came from the University of Illinois
via some distribution tape for PDP-11 Unix. It has subsequently been
hacked upon by James Gosling @ CMU. It isn't very pretty, and really needs
@@ -45,7 +48,7 @@ version. David Willcox (the author) states that:
| Time passed. Some years later, indent showed up on one of the early
| emacs distributions.
|
-| Later still, someone from UC Berlekey called the UofI and asked if
+| Later still, someone from UC Berkeley called the UofI and asked if
| indent was in the public domain. They wanted to include it in their
| UNIX distributions, along with the emacs stuff. I was no longer at the
| UofI, but Rob Kolstad, who was, asked me about it. I told him I didn't
@@ -67,7 +70,7 @@ version. David Willcox (the author) states that:
| Berkeley's copyright probably should only cover their changes, and I
| don't know their feelings about sending it out.
-In any case, there appears to be noone at UofI to clarify/and change
+In any case, there appears to be none at UofI to clarify/and change
that copyright, but I am confident (based on the statements of its
author) that the code, as it stands with its copyright, is
distributable, and will not cause any legal problems.
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c
index 3693e1e217a7..eb9396060726 100644
--- a/usr.bin/indent/args.c
+++ b/usr.bin/indent/args.c
@@ -33,13 +33,14 @@
* SUCH DAMAGE.
*/
-#ifndef lint
#if 0
+#ifndef lint
static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
#endif /* not lint */
+#endif
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
/*
* Argument scanning and profile reading code. Default parameters are set
@@ -72,7 +73,7 @@ static const char rcsid[] =
static void scan_profile(FILE *);
-char *option_source = "?";
+const char *option_source = "?";
/*
* N.B.: because of the way the table here is scanned, options whose names are
@@ -81,7 +82,7 @@ char *option_source = "?";
* default value is the one actually assigned.
*/
struct pro {
- char *p_name; /* name, eg -bl, -cli */
+ const char *p_name; /* name, e.g. -bl, -cli */
int p_type; /* type (int, bool, special) */
int p_default; /* the default value (if int) */
int p_special; /* depends on type */
@@ -110,6 +111,7 @@ struct pro {
{"eei", PRO_BOOL, false, ON, &extra_expression_indent},
{"ei", PRO_BOOL, true, ON, &ps.else_if},
{"fbc", PRO_FONT, 0, 0, (int *) &blkcomf},
+ {"fbs", PRO_BOOL, true, ON, &function_brace_split},
{"fbx", PRO_FONT, 0, 0, (int *) &boxcomf},
{"fb", PRO_FONT, 0, 0, (int *) &bodyf},
{"fc1", PRO_BOOL, true, ON, &format_col1_comments},
@@ -120,6 +122,7 @@ struct pro {
{"ip", PRO_BOOL, true, ON, &ps.indent_parameters},
{"i", PRO_INT, 8, 0, &ps.ind_size},
{"lc", PRO_INT, 0, 0, &block_comment_max_col},
+ {"ldi", PRO_INT, -1, 0, &ps.local_decl_indent},
{"lp", PRO_BOOL, true, ON, &lineup_to_parens},
{"l", PRO_INT, 78, 0, &max_col},
{"nbacc", PRO_BOOL, false, OFF, &blanklines_around_conditional_compilation},
@@ -134,6 +137,7 @@ struct pro {
{"ndj", PRO_BOOL, false, OFF, &ps.ljust_decl},
{"neei", PRO_BOOL, false, OFF, &extra_expression_indent},
{"nei", PRO_BOOL, true, OFF, &ps.else_if},
+ {"nfbs", PRO_BOOL, true, OFF, &function_brace_split},
{"nfc1", PRO_BOOL, true, OFF, &format_col1_comments},
{"nfcb", PRO_BOOL, true, OFF, &format_block_comments},
{"nip", PRO_BOOL, true, OFF, &ps.indent_parameters},
@@ -144,6 +148,7 @@ struct pro {
{"nps", PRO_BOOL, false, OFF, &pointer_as_binop},
{"nsc", PRO_BOOL, true, OFF, &star_comment_cont},
{"nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines},
+ {"nut", PRO_BOOL, true, OFF, &use_tabs},
{"nv", PRO_BOOL, false, OFF, &verbose},
{"pcs", PRO_BOOL, false, ON, &proc_calls_space},
{"psl", PRO_BOOL, true, ON, &procnames_start_line},
@@ -152,6 +157,7 @@ struct pro {
{"sob", PRO_BOOL, false, ON, &swallow_optional_blanklines},
{"st", PRO_SPECIAL, 0, STDIN, 0},
{"troff", PRO_BOOL, false, ON, &troff},
+ {"ut", PRO_BOOL, true, ON, &use_tabs},
{"v", PRO_BOOL, false, ON, &verbose},
/* whew! */
{0, 0, 0, 0, 0}
@@ -164,7 +170,7 @@ struct pro {
void
set_profile(void)
{
- register FILE *f;
+ FILE *f;
char fname[BUFSIZ];
static char prof[] = ".indent.pro";
@@ -181,14 +187,29 @@ set_profile(void)
}
static void
-scan_profile(register FILE *f)
+scan_profile(FILE *f)
{
- register int i;
- register char *p;
+ int comment, i;
+ char *p;
char buf[BUFSIZ];
while (1) {
- for (p = buf; (i = getc(f)) != EOF && (*p = i) > ' '; ++p);
+ p = buf;
+ comment = 0;
+ while ((i = getc(f)) != EOF) {
+ if (i == '*' && !comment && p > buf && p[-1] == '/') {
+ comment = p - buf;
+ *p++ = i;
+ } else if (i == '/' && comment && p > buf && p[-1] == '*') {
+ p = buf + comment - 1;
+ comment = 0;
+ } else if (isspace(i)) {
+ if (p > buf && !comment)
+ break;
+ } else {
+ *p++ = i;
+ }
+ }
if (p != buf) {
*p++ = 0;
if (verbose)
@@ -200,10 +221,10 @@ scan_profile(register FILE *f)
}
}
-char *param_start;
+const char *param_start;
static int
-eqin(char *s1, char *s2)
+eqin(const char *s1, const char *s2)
{
while (*s1) {
if (*s1++ != *s2++)
@@ -219,7 +240,7 @@ eqin(char *s1, char *s2)
void
set_defaults(void)
{
- register struct pro *p;
+ struct pro *p;
/*
* Because ps.case_indent is a float, we can't initialize it from the
@@ -234,7 +255,7 @@ set_defaults(void)
void
set_option(char *arg)
{
- register struct pro *p;
+ struct pro *p;
arg++; /* ignore leading "-" */
for (p = pro; p->p_name; p++)
@@ -267,7 +288,9 @@ found:
if (*param_start == 0)
goto need_param;
{
- register char *str = (char *) malloc(strlen(param_start) + 1);
+ char *str = (char *) malloc(strlen(param_start) + 1);
+ if (str == NULL)
+ err(1, NULL);
strcpy(str, param_start);
addkey(str, 4);
}
diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1
index c0b77ab755d1..f6ecc62959d6 100644
--- a/usr.bin/indent/indent.1
+++ b/usr.bin/indent/indent.1
@@ -34,7 +34,7 @@
.\" @(#)indent.1 8.1 (Berkeley) 7/1/93
.\" $FreeBSD$
.\"
-.Dd July 1, 1993
+.Dd June 29, 2004
.Dt INDENT 1
.Os
.Sh NAME
@@ -62,6 +62,7 @@
.Op Fl d Ns Ar n
.Op Fl \&di Ns Ar n
.Bk -words
+.Op Fl fbs | Fl nfbs
.Op Fl fc1 | Fl nfc1
.Op Fl fcb | Fl nfcb
.Ek
@@ -69,6 +70,7 @@
.Op Fl \&ip | Fl nip
.Op Fl l Ns Ar n
.Op Fl \&lc Ns Ar n
+.Op Fl \&ldi Ns Ar n
.Op Fl \&lp | Fl nlp
.Op Fl npro
.Op Fl pcs | Fl npcs
@@ -79,29 +81,34 @@
.Ek
.Op Fl \&st
.Op Fl troff
+.Op Fl ut | Fl nut
.Op Fl v | Fl \&nv
.Sh DESCRIPTION
The
.Nm
utility is a
.Em C
-program formatter. It reformats the
+program formatter.
+It reformats the
.Em C
program in the
.Ar input-file
-according to the switches. The switches which can be
-specified are described below. They may appear before or after the file
+according to the switches.
+The switches which can be
+specified are described below.
+They may appear before or after the file
names.
.Pp
-.Sy NOTE :
+.Sy NOTE :
If you only specify an
-.Ar input-file ,
+.Ar input-file ,
the formatting is
done `in-place', that is, the formatted file is written back into
.Ar input-file
and a backup copy of
.Ar input-file
-is written in the current directory. If
+is written in the current directory.
+If
.Ar input-file
is named
.Sq Pa /blah/blah/file ,
@@ -113,7 +120,7 @@ If
is specified,
.Nm
checks to make sure it is different from
-.Ar input-file .
+.Ar input-file .
.Pp
The options listed below control the formatting style imposed by
.Nm .
@@ -122,25 +129,29 @@ The options listed below control the formatting style imposed by
If
.Fl bad
is specified, a blank line is forced after every block of
-declarations. Default:
-.Fl nbad .
+declarations.
+Default:
+.Fl nbad .
.It Fl bap , nbap
If
.Fl bap
-is specified, a blank line is forced after every procedure body. Default:
+is specified, a blank line is forced after every procedure body.
+Default:
.Fl nbap .
.It Fl bbb , nbbb
If
.Fl bbb
-is specified, a blank line is forced before every block comment. Default:
+is specified, a blank line is forced before every block comment.
+Default:
.Fl nbbb .
.It Fl \&bc , nbc
If
.Fl \&bc
is specified, then a newline is forced after each comma in a declaration.
.Fl nbc
-turns off this option. Default:
-.Fl \&nbc .
+turns off this option.
+Default:
+.Fl \&nbc .
.It Fl \&br , \&bl
Specifying
.Fl \&bl
@@ -162,12 +173,15 @@ if (...) {
.Ed
.Pp
.It Fl c Ns Ar n
-The column in which comments on code start. The default is 33.
+The column in which comments on code start.
+The default is 33.
.It Fl cd Ns Ar n
-The column in which comments on declarations start. The default
+The column in which comments on declarations start.
+The default
is for these comments to start in the same column as those on code.
.It Fl cdb , ncdb
-Enables (disables) the placement of comment delimiters on blank lines. With
+Enables (disables) the placement of comment delimiters on blank lines.
+With
this option enabled, comments look like this:
.Bd -literal -offset indent
/*
@@ -181,24 +195,28 @@ Rather than like this:
.Ed
.Pp
This only affects block comments, not comments to the right of
-code. The default is
-.Fl cdb .
+code.
+The default is
+.Fl cdb .
.It Fl ce , nce
Enables (disables) forcing of `else's to cuddle up to the immediately preceding
-`}'. The default is
-.Fl \&ce .
+`}'.
+The default is
+.Fl \&ce .
.It Fl \&ci Ns Ar n
Sets the continuation indent to be
-.Ar n .
+.Ar n .
Continuation
lines will be indented that far from the beginning of the first line of the
-statement. Parenthesized expressions have extra indentation added to
+statement.
+Parenthesized expressions have extra indentation added to
indicate the nesting, unless
.Fl \&lp
-is in effect.
+is in effect
+or the contination indent is exactly half of the main indent.
.Fl \&ci
defaults to the same value as
-.Fl i .
+.Fl i .
.It Fl cli Ns Ar n
Causes case labels to be indented
.Ar n
@@ -206,47 +224,63 @@ tab stops to the right of the containing
.Ic switch
statement.
.Fl cli0.5
-causes case labels to be indented half a tab stop. The
+causes case labels to be indented half a tab stop.
+The
default is
-.Fl cli0 .
+.Fl cli0 .
.It Fl d Ns Ar n
Controls the placement of comments which are not to the
-right of code. For example,
+right of code.
+For example,
.Fl \&d\&1
means that such comments are placed one indentation level to the
-left of code. Specifying the default
+left of code.
+Specifying the default
.Fl \&d\&0
-lines-up these comments with the code. See the section on comment
+lines-up these comments with the code.
+See the section on comment
indentation below.
.It Fl \&di Ns Ar n
-Specifies the indentation, in character positions, from a declaration keyword
-to the following identifier. The default is
-.Fl di16 .
+Specifies the indentation, in character positions,
+of global variable names and all struct/union member names
+relative to the beginning of their type declaration.
+The default is
+.Fl di16 .
.It Fl dj , ndj
.Fl \&dj
left justifies declarations.
.Fl ndj
-indents declarations the same as code. The default is
-.Fl ndj .
+indents declarations the same as code.
+The default is
+.Fl ndj .
.It Fl \&ei , nei
Enables (disables) special
.Ic else-if
-processing. If it's enabled, an
+processing.
+If it's enabled, an
.Ic if
following an
.Ic else
will have the same indentation as the preceding
.Ic \&if
-statement. The default is
-.Fl ei .
+statement.
+The default is
+.Fl ei .
+.It Fl fbs , nfbs
+Enables (disables) splitting the function declaration and opening brace
+across two lines.
+The default is
+.Fl fbs .
.It Fl fc1 , nfc1
Enables (disables) the formatting of comments that start in column 1.
Often, comments whose leading `/' is in column 1 have been carefully
-hand formatted by the programmer. In such cases,
+hand formatted by the programmer.
+In such cases,
.Fl nfc1
should be
-used. The default is
-.Fl fc1 .
+used.
+The default is
+.Fl fc1 .
.It Fl fcb , nfcb
Enables (disables) the formatting of block comments (ones that begin
with `/*\\n').
@@ -258,20 +292,31 @@ In such cases,
should be used.
Block comments are then handled like box comments.
The default is
-.Fl fcb .
+.Fl fcb .
.It Fl i Ns Ar n
-The number of spaces for one indentation level. The default is 8.
+The number of spaces for one indentation level.
+The default is 8.
.It Fl \&ip , nip
Enables (disables) the indentation of parameter declarations from the left
-margin. The default is
-.Fl \&ip .
+margin.
+The default is
+.Fl \&ip .
.It Fl l Ns Ar n
-Maximum length of an output line. The default is 78.
+Maximum length of an output line.
+The default is 78.
+.It Fl \&ldi Ns Ar n
+Specifies the indentation, in character positions,
+of local variable names
+relative to the beginning of their type declaration.
+The default is for local variable names to be indented
+by the same amount as global ones.
.It Fl \&lp , nlp
-Lines-up code surrounded by parenthesis in continuation lines. If a line
+Lines-up code surrounded by parenthesis in continuation lines.
+If a line
has a left paren which is not closed on that line, then continuation lines
will be lined up to start at the character position just after the left
-paren. For example, here is how a piece of continued code looks with
+paren.
+For example, here is how a piece of continued code looks with
.Fl nlp
in effect:
.Bd -literal -offset indent
@@ -304,25 +349,30 @@ to be ignored.
If true
.Pq Fl pcs
all procedure calls will have a space inserted between
-the name and the `('. The default is
-.Fl npcs .
+the name and the `('.
+The default is
+.Fl npcs .
.It Fl psl , npsl
If true
.Pq Fl psl
the names of procedures being defined are placed in
-column 1 \- their types, if any, will be left on the previous lines. The
+column 1 \- their types, if any, will be left on the previous lines.
+The
default is
-.Fl psl .
+.Fl psl .
.It Fl \&sc , nsc
Enables (disables) the placement of asterisks (`*'s) at the left edge of all
-comments. The default is
-.Fl sc .
+comments.
+The default is
+.Fl sc .
.It Fl sob , nsob
If
.Fl sob
-is specified, indent will swallow optional blank lines. You can use this to
-get rid of blank lines after declarations. Default:
-.Fl nsob .
+is specified, indent will swallow optional blank lines.
+You can use this to
+get rid of blank lines after declarations.
+Default:
+.Fl nsob .
.It Fl \&st
Causes
.Nm
@@ -330,14 +380,17 @@ to take its input from stdin and put its output to stdout.
.It Fl T Ns Ar typename
Adds
.Ar typename
-to the list of type keywords. Names accumulate:
+to the list of type keywords.
+Names accumulate:
.Fl T
-can be specified more than once. You need to specify all the typenames that
+can be specified more than once.
+You need to specify all the typenames that
appear in your program that are defined by
.Ic typedef
\- nothing will be
harmed if you miss a few, but the program won't be formatted as nicely as
-it should. This sounds like a painful thing to have to do, but it's really
+it should.
+This sounds like a painful thing to have to do, but it's really
a symptom of a problem in C:
.Ic typedef
causes a syntactic change in the
@@ -356,15 +409,22 @@ listing in much the same spirit as
.Xr vgrind 1 .
If the output file is not specified, the default is standard output,
rather than formatting in place.
+.It Fl ut , nut
+Enables (disables) the use of tab characters in the output.
+Tabs are assumed to be aligned on columns divisble by 8.
+The default is
+.Fl ut .
.It Fl v , \&nv
.Fl v
turns on `verbose' mode;
.Fl \&nv
-turns it off. When in verbose mode,
+turns it off.
+When in verbose mode,
.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 .
+and gives some size statistics at completion.
+The default is
+.Fl \&nv .
.El
.Pp
You may set up your own `profile' of defaults to
@@ -372,12 +432,16 @@ You may set up your own `profile' of defaults to
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
+whatever switches you like.
+A `.indent.pro' in the current directory takes
+precedence over the one in your login directory.
+If
.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.
+defaults.
+Switches on the command line, though, always override profile
+switches.
+The switches should be separated by spaces, tabs or newlines.
.Pp
.Ss Comments
.Sq Em Box
@@ -396,28 +460,34 @@ All other comments are treated as straight text.
The
.Nm
utility fits as many words (separated by blanks, tabs, or newlines) on a
-line as possible. Blank lines break paragraphs.
+line as possible.
+Blank lines break paragraphs.
.Pp
.Ss Comment indentation
If a comment is on a line with code it is started in the `comment column',
which is set by the
.Fl c Ns Ns Ar n
-command line parameter. Otherwise, the comment is started at
+command line parameter.
+Otherwise, the comment is started at
.Ar n
indentation levels less than where code is currently being placed, where
.Ar n
is specified by the
.Fl d Ns Ns Ar n
-command line parameter. If the code on a line extends past the comment
+command line parameter.
+If the code on a line extends past the comment
column, the comment starts further to the right, and the right margin may be
automatically extended in extreme cases.
.Pp
.Ss Preprocessor lines
In general,
.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
+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
@@ -428,8 +498,10 @@ compensate for the syntactic peculiarities introduced.
The
.Nm
utility understands a substantial amount about the syntax of C, but it
-has a `forgiving' parser. It attempts to cope with the usual sorts of
-incomplete and misformed syntax. In particular, the use of macros like:
+has a `forgiving' parser.
+It attempts to cope with the usual sorts of
+incomplete and misformed syntax.
+In particular, the use of macros like:
.Pp
.Dl #define forever for(;;)
.Pp
diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c
index 71259a8b3fae..f91043f7d3b1 100644
--- a/usr.bin/indent/indent.c
+++ b/usr.bin/indent/indent.c
@@ -41,13 +41,14 @@ static const char copyright[] =
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
-#ifndef lint
#if 0
+#ifndef lint
static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
#endif /* not lint */
+#endif
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <err.h>
@@ -63,17 +64,18 @@ static const char rcsid[] =
static void bakcopy(void);
-char *in_name = "Standard Input"; /* will always point to name of input
+const char *in_name = "Standard Input"; /* will always point to name of input
* file */
-char *out_name = "Standard Output"; /* will always point to name
+const char *out_name = "Standard Output"; /* will always point to name
* of output file */
char bakfile[MAXPATHLEN] = "";
+extern int found_err; /* flag set in diagN() on error */
+
int
main(int argc, char **argv)
{
- extern int found_err; /* flag set in diagN() on error */
int dec_ind; /* current indentation for declarations */
int di_stack[20]; /* a stack of structure indentation levels */
int flushed_nl; /* used when buffering up comments to remember
@@ -81,15 +83,16 @@ main(int argc, char **argv)
int force_nl; /* when true, code must be broken */
int hd_type = 0; /* used to store type of stmt for if (...),
* for (...), etc */
- register int i; /* local loop counter */
+ int i; /* local loop counter */
int scase; /* set to true when we see a case, so we will
* know what to do with the following colon */
- int sp_sw; /* when true, we are in the expressin of
+ int sp_sw; /* when true, we are in the expression of
* if(...), while(...), etc. */
int squest; /* when this is positive, we have seen a ?
* without the matching : in a <c>?<s>:<s>
* construct */
- register char *t_ptr; /* used for copying tokens */
+ const char *t_ptr; /* used for copying tokens */
+ int tabs_to_var; /* true if using tabs to indent to var name */
int type_code; /* the type of token, returned by lexi */
int last_else = 0; /* true iff last keyword was an else */
@@ -99,15 +102,24 @@ main(int argc, char **argv)
| INITIALIZATION |
\*-----------------------------------------------*/
+ found_err = 0;
ps.p_stack[0] = stmt; /* this is the parser's stack */
ps.last_nl = true; /* this is true if the last thing scanned was
* a newline */
ps.last_token = semicolon;
combuf = (char *) malloc(bufsize);
+ if (combuf == NULL)
+ err(1, NULL);
labbuf = (char *) malloc(bufsize);
+ if (labbuf == NULL)
+ err(1, NULL);
codebuf = (char *) malloc(bufsize);
+ if (codebuf == NULL)
+ err(1, NULL);
tokenbuf = (char *) malloc(bufsize);
+ if (tokenbuf == NULL)
+ err(1, NULL);
l_com = combuf + bufsize - 5;
l_lab = labbuf + bufsize - 5;
l_code = codebuf + bufsize - 5;
@@ -122,6 +134,8 @@ main(int argc, char **argv)
s_token = e_token = tokenbuf + 1;
in_buffer = (char *) malloc(10);
+ if (in_buffer == NULL)
+ err(1, NULL);
in_buffer_limit = in_buffer + 8;
buf_ptr = buf_end = in_buffer;
line_no = 1;
@@ -133,7 +147,6 @@ main(int argc, char **argv)
di_stack[ps.dec_nest = 0] = 0;
ps.want_blank = ps.in_stmt = ps.ind_stmt = false;
-
scase = ps.pcase = false;
squest = 0;
sc_end = 0;
@@ -142,8 +155,6 @@ main(int argc, char **argv)
output = 0;
-
-
/*--------------------------------------------------*\
| COMMAND LINE SCAN |
\*--------------------------------------------------*/
@@ -157,6 +168,9 @@ main(int argc, char **argv)
ps.ind_size = 8; /* -i8 */
verbose = 0;
ps.decl_indent = 16; /* -di16 */
+ ps.local_decl_indent = -1; /* if this is not set to some nonnegative value
+ * by an arg, we will set this equal to
+ * ps.decl_ind */
ps.indent_parameters = 1; /* -ip */
ps.decl_com_ind = 0; /* if this is not set to some positive value
* by an arg, we will set this equal to
@@ -243,6 +257,8 @@ main(int argc, char **argv)
}
if (block_comment_max_col <= 0)
block_comment_max_col = max_col;
+ if (ps.local_decl_indent < 0) /* if not specified by user, set this */
+ ps.local_decl_indent = ps.decl_indent;
if (ps.decl_com_ind <= 0) /* if not specified by user, set this */
ps.decl_com_ind = ps.ljust_decl ? (ps.com_ind <= 10 ? 2 : ps.com_ind - 8) : ps.com_ind;
if (continuation_indent == 0)
@@ -251,8 +267,8 @@ main(int argc, char **argv)
parse(semicolon);
{
- register char *p = buf_ptr;
- register int col = 1;
+ char *p = buf_ptr;
+ int col = 1;
while (1) {
if (*p == ' ')
@@ -267,7 +283,7 @@ main(int argc, char **argv)
ps.ind_level = ps.i_l_follow = col / ps.ind_size;
}
if (troff) {
- register char *p = in_name,
+ const char *p = in_name,
*beg = in_name;
while (*p)
@@ -349,7 +365,7 @@ main(int argc, char **argv)
if (sc_end >= &(save_com[sc_size])) { /* check for temp buffer
* overflow */
- diag2(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever.");
+ diag2(1, "Internal buffer overflow - Move big comment from right after if, while, or whatever");
fflush(output);
exit(1);
}
@@ -359,7 +375,7 @@ main(int argc, char **argv)
fill_buffer();
break;
}
- default: /* it is the start of a normal statment */
+ default: /* it is the start of a normal statement */
if (flushed_nl) /* if we flushed a newline, make sure it is
* put back */
force_nl = true;
@@ -419,7 +435,7 @@ check_type:
|| s_com != e_com) /* must dump end of line */
dump_line();
if (ps.tos > 1) /* check for balanced braces */
- diag2(1, "Stuff missing from end of file.");
+ diag2(1, "Stuff missing from end of file");
if (verbose) {
printf("There were %d output lines and %d comments\n",
@@ -574,7 +590,7 @@ check_type:
e_code += strlen(e_code);
}
else {
- char *res = token;
+ const char *res = token;
if (ps.in_decl && !ps.block_init) { /* if this is a unary op
* in a declaration, we
@@ -600,7 +616,7 @@ check_type:
if (ps.want_blank)
*e_code++ = ' ';
{
- char *res = token;
+ const char *res = token;
if (troff)
switch (token[0]) {
@@ -686,7 +702,7 @@ check_type:
case semicolon: /* got a ';' */
ps.in_or_st = false;/* we are not in an initialization or
* structure declaration */
- scase = false; /* these will only need resetting in a error */
+ scase = false; /* these will only need resetting in an error */
squest = 0;
if (ps.last_token == rparen && rparen_count == 0)
ps.in_parameter_declaration = 0;
@@ -715,7 +731,7 @@ check_type:
*/
diag2(1, "Unbalanced parens");
ps.p_l_follow = 0;
- if (sp_sw) { /* this is a check for a if, while, etc. with
+ if (sp_sw) { /* this is a check for an if, while, etc. with
* unbalanced parens */
sp_sw = false;
parse(hd_type); /* dont lose the if, or whatever */
@@ -728,7 +744,7 @@ check_type:
if (!sp_sw) { /* if not if for (;;) */
parse(semicolon); /* let parser know about end of stmt */
- force_nl = true;/* force newline after a end of stmt */
+ force_nl = true;/* force newline after an end of stmt */
}
break;
@@ -749,8 +765,12 @@ check_type:
}
else if (ps.in_parameter_declaration && !ps.in_or_st) {
ps.i_l_follow = 0;
- dump_line();
- ps.want_blank = false;
+ if (function_brace_split) { /* dump the line prior to the
+ * brace ... */
+ dump_line();
+ ps.want_blank = false;
+ } else /* add a space between the decl and brace */
+ ps.want_blank = true;
}
}
if (ps.in_parameter_declaration)
@@ -895,37 +915,74 @@ check_type:
prefix_blankline_requested = 0;
for (i = 0; token[i++];); /* get length of token */
- /*
- * dec_ind = e_code - s_code + (ps.decl_indent>i ? ps.decl_indent
- * : i);
- */
- dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
+ if (ps.ind_level == 0 || ps.dec_nest > 0) {
+ /* global variable or struct member in local variable */
+ dec_ind = ps.decl_indent > 0 ? ps.decl_indent : i;
+ tabs_to_var = (use_tabs ? ps.decl_indent > 0 : 0);
+ } else {
+ /* local variable */
+ dec_ind = ps.local_decl_indent > 0 ? ps.local_decl_indent : i;
+ tabs_to_var = (use_tabs ? ps.local_decl_indent > 0 : 0);
+ }
goto copy_id;
case ident: /* got an identifier or constant */
if (ps.in_decl) { /* if we are in a declaration, we must indent
* identifier */
- if (ps.want_blank)
- *e_code++ = ' ';
- ps.want_blank = false;
if (is_procname == 0 || !procnames_start_line) {
if (!ps.block_init) {
if (troff && !ps.dumped_decl_indent) {
+ if (ps.want_blank)
+ *e_code++ = ' ';
+ ps.want_blank = false;
sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
ps.dumped_decl_indent = 1;
e_code += strlen(e_code);
} else {
- while ((e_code - s_code) < dec_ind) {
+ int cur_dec_ind;
+ int pos, startpos;
+
+ /*
+ * in order to get the tab math right for
+ * indentations that are not multiples of 8 we
+ * need to modify both startpos and dec_ind
+ * (cur_dec_ind) here by eight minus the
+ * remainder of the current starting column
+ * divided by eight. This seems to be a
+ * properly working fix
+ */
+ startpos = e_code - s_code;
+ cur_dec_ind = dec_ind;
+ pos = startpos;
+ if ((ps.ind_level * ps.ind_size) % 8 != 0) {
+ pos += (ps.ind_level * ps.ind_size) % 8;
+ cur_dec_ind += (ps.ind_level * ps.ind_size) % 8;
+ }
+
+ if (tabs_to_var) {
+ while ((pos & ~7) + 8 <= cur_dec_ind) {
+ CHECK_SIZE_CODE;
+ *e_code++ = '\t';
+ pos = (pos & ~7) + 8;
+ }
+ }
+ while (pos < cur_dec_ind) {
CHECK_SIZE_CODE;
*e_code++ = ' ';
+ pos++;
}
+ if (ps.want_blank && e_code - s_code == startpos)
+ *e_code++ = ' ';
+ ps.want_blank = false;
}
}
} else {
+ if (ps.want_blank)
+ *e_code++ = ' ';
+ ps.want_blank = false;
if (dec_ind && s_code != e_code)
dump_line();
dec_ind = 0;
- ps.want_blank = false;
}
}
else if (sp_sw && ps.p_l_follow == 0) {
@@ -1072,12 +1129,12 @@ check_type:
if (strncmp(s_lab, "#if", 3) == 0) {
if (blanklines_around_conditional_compilation) {
- register int c;
+ int c;
prefix_blankline_requested++;
while ((c = getc(input)) == '\n');
ungetc(c, input);
}
- if (ifdef_level < sizeof state_stack / sizeof state_stack[0]) {
+ if ((size_t)ifdef_level < sizeof(state_stack)/sizeof(state_stack[0])) {
match_state[ifdef_level].tos = -1;
state_stack[ifdef_level++] = ps;
}
@@ -1104,7 +1161,7 @@ check_type:
*/
if (match_state[ifdef_level].tos >= 0
&& bcmp(&ps, &match_state[ifdef_level], sizeof ps))
- diag2(0, "Syntactically inconsistant #ifdef alternatives.");
+ diag2(0, "Syntactically inconsistent #ifdef alternatives");
#endif
}
if (blanklines_around_conditional_compilation) {
@@ -1143,7 +1200,7 @@ bakcopy(void)
int n,
bakchn;
char buff[8 * 1024];
- register char *p;
+ const char *p;
/* construct file name .Bfile */
for (p = in_name; *p; p++); /* skip to end of string */
diff --git a/usr.bin/indent/indent.h b/usr.bin/indent/indent.h
index cd644988715d..4c52bf8370e4 100644
--- a/usr.bin/indent/indent.h
+++ b/usr.bin/indent/indent.h
@@ -33,13 +33,13 @@ int compute_code_target(void);
int compute_label_target(void);
int count_spaces(int, char *);
int lexi(void);
-void diag2(int, char *);
-void diag3(int, char *, int);
-void diag4(int, char *, int, int);
+void diag2(int, const char *);
+void diag3(int, const char *, int);
+void diag4(int, const char *, int, int);
void dump_line(void);
void fill_buffer(void);
void parse(int);
-void parsefont(struct fstate *, char *);
+void parsefont(struct fstate *, const char *);
void pr_comment(void);
void set_defaults(void);
void set_option(char *);
diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h
index f366560f9675..010b3a3d6794 100644
--- a/usr.bin/indent/indent_globs.h
+++ b/usr.bin/indent/indent_globs.h
@@ -56,32 +56,40 @@ FILE *output; /* the output file */
#define CHECK_SIZE_CODE \
if (e_code >= l_code) { \
- register int nsize = l_code-s_code+400; \
+ int nsize = l_code-s_code+400; \
codebuf = (char *) realloc(codebuf, nsize); \
+ if (codebuf == NULL) \
+ err(1, NULL); \
e_code = codebuf + (e_code-s_code) + 1; \
l_code = codebuf + nsize - 5; \
s_code = codebuf + 1; \
}
#define CHECK_SIZE_COM \
if (e_com >= l_com) { \
- register int nsize = l_com-s_com+400; \
+ int nsize = l_com-s_com+400; \
combuf = (char *) realloc(combuf, nsize); \
+ if (combuf == NULL) \
+ err(1, NULL); \
e_com = combuf + (e_com-s_com) + 1; \
l_com = combuf + nsize - 5; \
s_com = combuf + 1; \
}
#define CHECK_SIZE_LAB \
if (e_lab >= l_lab) { \
- register int nsize = l_lab-s_lab+400; \
+ int nsize = l_lab-s_lab+400; \
labbuf = (char *) realloc(labbuf, nsize); \
+ if (labbuf == NULL) \
+ err(1, NULL); \
e_lab = labbuf + (e_lab-s_lab) + 1; \
l_lab = labbuf + nsize - 5; \
s_lab = labbuf + 1; \
}
#define CHECK_SIZE_TOKEN \
if (e_token >= l_token) { \
- register int nsize = l_token-s_token+400; \
+ int nsize = l_token-s_token+400; \
tokenbuf = (char *) realloc(tokenbuf, nsize); \
+ if (tokenbuf == NULL) \
+ err(1, NULL); \
e_token = tokenbuf + (e_token-s_token) + 1; \
l_token = tokenbuf + nsize - 5; \
s_token = tokenbuf + 1; \
@@ -185,12 +193,16 @@ int blanklines_after_declarations_at_proctop; /* This is vaguely
* if there are no
* declarations */
int block_comment_max_col;
-int extra_expression_indent; /* True if continuation lines from the
+int extra_expression_indent; /* true if continuation lines from the
* expression part of "if(e)",
* "while(e)", "for(e;e;e)" should be
* indented an extra tab stop so that
* they don't conflict with the code
* that follows */
+int function_brace_split; /* split function declaration and
+ * brace onto separate lines */
+int use_tabs; /* set true to use tabs for spacing,
+ * false uses all spaces */
/* -troff font state information */
@@ -199,7 +211,7 @@ struct fstate {
char size;
int allcaps:1;
};
-char *chfont();
+char *chfont(struct fstate *, struct fstate *, char *);
struct fstate
keywordf, /* keyword font */
@@ -241,7 +253,7 @@ struct parser_state {
int col_1; /* set to true if the last token started in
* column 1 */
int com_col; /* this is the column in which the current
- * coment should start */
+ * comment should start */
int com_ind; /* the column in which comments to the right
* of code should start */
int com_lines; /* the number of lines with comments, set by
@@ -275,7 +287,7 @@ struct parser_state {
int p_l_follow; /* used to remember how to indent following
* statement */
int paren_level; /* parenthesization level. used to indent
- * within stmts */
+ * within statements */
short paren_indents[20]; /* column positions of each paren */
int pcase; /* set to 1 if the current line label is a
* case. It is printed differently from a
@@ -295,6 +307,7 @@ struct parser_state {
int else_if; /* True iff else if pairs should be handled
* specially */
int decl_indent; /* column to indent declared identifiers to */
+ int local_decl_indent; /* like decl_indent but for locals */
int its_a_keyword;
int sizeof_keyword;
int dumped_decl_indent;
diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c
index b8f7a56fb547..45eb6c2d5f3b 100644
--- a/usr.bin/indent/io.c
+++ b/usr.bin/indent/io.c
@@ -33,13 +33,14 @@
* SUCH DAMAGE.
*/
-#ifndef lint
#if 0
+#ifndef lint
static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93";
-#endif
-static const char rcsid[] =
- "$FreeBSD$";
#endif /* not lint */
+#endif
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
#include <ctype.h>
#include <err.h>
@@ -60,7 +61,7 @@ dump_line(void)
* prints the label section, followed by the
* code section with the appropriate nesting
* level, followed by any comments */
- register int cur_col,
+ int cur_col,
target_col = 1;
static int not_first_line;
@@ -118,7 +119,7 @@ dump_line(void)
cur_col = pad_output(1, compute_label_target());
if (s_lab[0] == '#' && (strncmp(s_lab, "#else", 5) == 0
|| strncmp(s_lab, "#endif", 6) == 0)) {
- register char *s = s_lab;
+ char *s = s_lab;
if (e_lab[-1] == '\n') e_lab--;
do putc(*s++, output);
while (s < e_lab && 'a' <= *s && *s<='z');
@@ -126,9 +127,9 @@ dump_line(void)
s++;
if (s < e_lab)
fprintf(output, s[0]=='/' && s[1]=='*' ? "\t%.*s" : "\t/* %.*s */",
- e_lab - s, s);
+ (int)(e_lab - s), s);
}
- else fprintf(output, "%.*s", e_lab - s_lab, s_lab);
+ else fprintf(output, "%.*s", (int)(e_lab - s_lab), s_lab);
cur_col = count_spaces(cur_col, s_lab);
}
else
@@ -137,7 +138,7 @@ dump_line(void)
ps.pcase = false;
if (s_code != e_code) { /* print code section, if any */
- register char *p;
+ char *p;
if (comment_open) {
comment_open = 0;
@@ -145,7 +146,7 @@ dump_line(void)
}
target_col = compute_code_target();
{
- register int i;
+ int i;
for (i = 0; i < ps.p_l_follow; i++)
if (ps.paren_indents[i] >= 0)
@@ -162,7 +163,7 @@ dump_line(void)
if (s_com != e_com) {
if (troff) {
int all_here = 0;
- register char *p;
+ char *p;
if (e_com[-1] == '/' && e_com[-2] == '*')
e_com -= 2, all_here++;
@@ -188,7 +189,7 @@ dump_line(void)
if ('a' <= *p && *p <= 'z')
*p = *p + 'A' - 'a';
if (e_com - p < 50 && all_here == 2) {
- register char *follow = p;
+ char *follow = p;
fprintf(output, "\n.nr C! \\w\1");
while (follow < e_com) {
switch (*follow) {
@@ -218,8 +219,8 @@ dump_line(void)
}
}
else { /* print comment, if any */
- register int target = ps.com_col;
- register char *com_st = s_com;
+ int target = ps.com_col;
+ char *com_st = s_com;
target += ps.comment_delta;
while (*com_st == '\t')
@@ -290,14 +291,15 @@ inhibit_newline:
int
compute_code_target(void)
{
- register int target_col = ps.ind_size * ps.ind_level + 1;
+ int target_col = ps.ind_size * ps.ind_level + 1;
if (ps.paren_level)
if (!lineup_to_parens)
- target_col += continuation_indent * ps.paren_level;
+ target_col += continuation_indent
+ * (2 * continuation_indent == ps.ind_size ? 1 : ps.paren_level);
else {
- register int w;
- register int t = paren_target;
+ int w;
+ int t = paren_target;
if ((w = count_spaces(t, s_code) - max_col) > 0
&& count_spaces(target_col, s_code) <= max_col) {
@@ -341,9 +343,9 @@ compute_label_target(void)
void
fill_buffer(void)
{ /* this routine reads stuff from the input */
- register char *p;
- register int i;
- register FILE *f = input;
+ char *p;
+ int i;
+ FILE *f = input;
if (bp_save != 0) { /* there is a partly filled input buffer left */
buf_ptr = bp_save; /* dont read anything, just switch buffers */
@@ -355,11 +357,11 @@ fill_buffer(void)
}
for (p = in_buffer;;) {
if (p >= in_buffer_limit) {
- register int size = (in_buffer_limit - in_buffer) * 2 + 10;
- register int offset = p - in_buffer;
+ int size = (in_buffer_limit - in_buffer) * 2 + 10;
+ int offset = p - in_buffer;
in_buffer = realloc(in_buffer, size);
- if (in_buffer == 0)
- err(1, "input line too long");
+ if (in_buffer == NULL)
+ errx(1, "input line too long");
p = in_buffer + offset;
in_buffer_limit = in_buffer + size - 2;
}
@@ -461,8 +463,8 @@ pad_output(int current, int target)
/* current: the current column value */
/* target: position we want it at */
{
- register int curr; /* internal column pointer */
- register int tcur;
+ int curr; /* internal column pointer */
+ int tcur;
if (troff)
fprintf(output, "\\h'|%dp'", (target - 1) * 7);
@@ -470,11 +472,13 @@ pad_output(int current, int target)
if (current >= target)
return (current); /* line is already long enough */
curr = current;
- while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target) {
- putc('\t', output);
- curr = tcur;
- }
- while (curr++ < target)
+ if (use_tabs) {
+ while ((tcur = ((curr - 1) & tabmask) + tabsize + 1) <= target) {
+ putc('\t', output);
+ curr = tcur;
+ }
+ }
+ while (curr++ < target)
putc(' ', output); /* pad with final blanks */
}
return (target);
@@ -507,8 +511,8 @@ count_spaces(int current, char *buffer)
* printing the text in buffer starting at column "current"
*/
{
- register char *buf; /* used to look thru buffer */
- register int cur; /* current character counter */
+ char *buf; /* used to look thru buffer */
+ int cur; /* current character counter */
cur = current;
@@ -539,7 +543,7 @@ count_spaces(int current, char *buffer)
int found_err;
void
-diag4(int level, char *msg, int a, int b)
+diag4(int level, const char *msg, int a, int b)
{
if (level)
found_err = 1;
@@ -556,7 +560,7 @@ diag4(int level, char *msg, int a, int b)
}
void
-diag3(int level, char *msg, int a)
+diag3(int level, const char *msg, int a)
{
if (level)
found_err = 1;
@@ -573,7 +577,7 @@ diag3(int level, char *msg, int a)
}
void
-diag2(int level, char *msg)
+diag2(int level, const char *msg)
{
if (level)
found_err = 1;
@@ -627,9 +631,9 @@ chfont(struct fstate *of, struct fstate *nf, char *s)
}
void
-parsefont(struct fstate *f, char *s0)
+parsefont(struct fstate *f, const char *s0)
{
- register char *s = s0;
+ const char *s = s0;
int sizedelta = 0;
bzero(f, sizeof *f);
diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c
index 837471075c31..3d30bb337ce5 100644
--- a/usr.bin/indent/lexi.c
+++ b/usr.bin/indent/lexi.c
@@ -36,10 +36,10 @@
#if 0
#ifndef lint
static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93";
-static const char rcsid[] =
- "$FreeBSD$";
#endif /* not lint */
#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
/*
* Here we have the token scanner for indent. It scans off one token and puts
@@ -47,20 +47,20 @@ static const char rcsid[] =
* of token scanned.
*/
+#include <err.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "indent_globs.h"
#include "indent_codes.h"
+#include "indent.h"
#define alphanum 1
#define opchar 3
-void fill_buffer(void);
-
struct templ {
- char *rwd;
+ const char *rwd;
int rwcode;
};
@@ -86,6 +86,8 @@ struct templ specials[1000] =
{"global", 4},
{"extern", 4},
{"void", 4},
+ {"const", 4},
+ {"volatile", 4},
{"goto", 0},
{"return", 0},
{"if", 5},
@@ -94,8 +96,6 @@ struct templ specials[1000] =
{"else", 6},
{"do", 6},
{"sizeof", 7},
- {"const", 9},
- {"volatile", 9},
{0, 0}
};
@@ -149,10 +149,10 @@ lexi(void)
/*
* we have a character or number
*/
- register char *j; /* used for searching thru list of
+ const char *j; /* used for searching thru list of
*
* reserved words */
- register struct templ *p;
+ struct templ *p;
if (isdigit(*buf_ptr) || (buf_ptr[0] == '.' && isdigit(buf_ptr[1]))) {
int seendot = 0,
@@ -234,14 +234,18 @@ lexi(void)
}
ps.its_a_keyword = false;
ps.sizeof_keyword = false;
- if (l_struct) { /* if last token was 'struct', then this token
+ if (l_struct && !ps.p_l_follow) {
+ /* if last token was 'struct' and we're not
+ * in parentheses, then this token
* should be treated as a declaration */
l_struct = false;
last_code = ident;
ps.last_u_d = true;
return (decl);
}
- ps.last_u_d = false; /* Operator after indentifier is binary */
+ ps.last_u_d = l_struct; /* Operator after identifier is binary
+ * unless last token was 'struct' */
+ l_struct = false;
last_code = ident; /* Remember that this is the code we will
* return */
@@ -249,15 +253,15 @@ lexi(void)
* This loop will check if the token is a keyword.
*/
for (p = specials; (j = p->rwd) != 0; p++) {
- register char *p = s_token; /* point at scanned token */
- if (*j++ != *p++ || *j++ != *p++)
+ const char *q = s_token; /* point at scanned token */
+ if (*j++ != *q++ || *j++ != *q++)
continue; /* This test depends on the fact that
* identifiers are always at least 1 character
* long (ie. the first two bytes of the
* identifier are always meaningful) */
- if (p[-1] == 0)
+ if (q[-1] == 0)
break; /* If its a one-character identifier */
- while (*p++ == *j)
+ while (*q++ == *j)
if (*j++ == 0)
goto found_keyword; /* I wish that C had a multi-level
* break... */
@@ -273,29 +277,17 @@ lexi(void)
return (casestmt);
case 3: /* a "struct" */
- if (ps.p_l_follow)
- break; /* inside parens: cast */
/*
- * Next time around, we may want to know that we have had a
+ * Next time around, we will want to know that we have had a
* 'struct'
*/
l_struct = true;
+ /* FALLTHROUGH */
- /*
- * Fall through to test for a cast, function prototype or
- * sizeof().
- */
case 4: /* one of the declaration keywords */
if (ps.p_l_follow) {
- ps.cast_mask |= 1 << ps.p_l_follow;
-
- /*
- * Forget that we saw `struct' if we're in a sizeof().
- */
- if (ps.sizeof_mask)
- l_struct = false;
-
- break; /* inside parens: cast, prototype or sizeof() */
+ ps.cast_mask |= (1 << ps.p_l_follow) & ~ps.sizeof_mask;
+ break; /* inside parens: cast, param list or sizeof */
}
last_code = decl;
return (decl);
@@ -314,7 +306,7 @@ lexi(void)
} /* end of switch */
} /* end of if (found_it) */
if (*buf_ptr == '(' && ps.tos <= 1 && ps.ind_level == 0) {
- register char *tp = buf_ptr;
+ char *tp = buf_ptr;
while (tp < buf_end)
if (*tp++ == ')' && (*tp == ';' || *tp == ','))
goto not_proc;
@@ -361,7 +353,7 @@ lexi(void)
code = (had_eof ? 0 : newline);
/*
- * if data has been exausted, the newline is a dummy, and we should
+ * if data has been exhausted, the newline is a dummy, and we should
* return code to stop
*/
break;
@@ -587,7 +579,7 @@ stop_lit:
void
addkey(char *key, int val)
{
- register struct templ *p = specials;
+ struct templ *p = specials;
while (p->rwd)
if (p->rwd[0] == key[0] && strcmp(p->rwd, key) == 0)
return;
diff --git a/usr.bin/indent/parse.c b/usr.bin/indent/parse.c
index c87d1d471486..65d9a6bb8c47 100644
--- a/usr.bin/indent/parse.c
+++ b/usr.bin/indent/parse.c
@@ -32,14 +32,16 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#if 0
#ifndef lint
static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93";
-static const char rcsid[] =
- "$FreeBSD$";
#endif /* not lint */
#endif
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <stdio.h>
#include "indent_globs.h"
#include "indent_codes.h"
@@ -168,7 +170,7 @@ parse(int tk) /* tk: the code for the construct scanned */
ps.p_stack[ps.tos] = stmt;
}
else
- diag2(1, "Stmt nesting error.");
+ diag2(1, "Statement nesting error");
break;
case swstmt: /* had switch (...) */
@@ -251,7 +253,7 @@ parse(int tk) /* tk: the code for the construct scanned */
static void
reduce(void)
{
- register int i;
+ int i;
for (;;) { /* keep looping until there is nothing left to
* reduce */
diff --git a/usr.bin/indent/pr_comment.c b/usr.bin/indent/pr_comment.c
index 70c31aa1de35..9524bf404f19 100644
--- a/usr.bin/indent/pr_comment.c
+++ b/usr.bin/indent/pr_comment.c
@@ -32,13 +32,17 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
+
#if 0
#ifndef lint
static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93";
-static const char rcsid[] =
- "$FreeBSD$";
#endif /* not lint */
#endif
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include "indent_globs.h"
@@ -136,7 +140,7 @@ pr_comment(void)
ps.com_col = 1 + !format_col1_comments;
}
else {
- register int target_col;
+ int target_col;
break_delim = 0;
if (s_code != e_code)
target_col = count_spaces(compute_code_target(), s_code);