.\" Copyright (c) 1980, 1990 The Regents of the University of California.
.\" Copyright (c) 1985 Sun Microsystems, Inc.
.\" Copyright (c) 1976 Board of Trustees of the University of Illinois.
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" @(#)indent.1 6.11 (Berkeley) 7/24/91
.Nd indent and format C program source
.Op Ar input-file Op Ar output-file
program formatter. It reformats the
according to the switches. The switches which can be
specified are described below. They may appear before or after the file
done `in-place', that is, the formatted file is written back into
is written in the current directory. If
checks to make sure it is different from
The options listed below control the formatting style imposed by
is specified, a blank line is forced after every block of
is specified, a blank line is forced after every procedure body. Default:
is specified, a blank line is forced before every block comment. Default:
is specified, then a newline is forced after each comma in a declaration.
turns off this option. The default is
lines up compound statements like this:
.Bd -literal -offset indent
(the default) makes them look like this:
.Bd -literal -offset indent
The column in which comments on code start. The default is 33.
The column in which comments on declarations start. The default
is for these comments to start in the same column as those on code.
Enables (disables) the placement of comment delimiters on blank lines. With
this option enabled, comments look like this:
.Bd -literal -offset indent
.Bd -literal -offset indent
This only affects block comments, not comments to the right of
Enables (disables) forcing `else's to cuddle up to the immediately preceding
Sets the continuation indent to be
lines will be indented that far from the beginning of the first line of the
statement. Parenthesized expressions have extra indentation added to
indicate the nesting, unless
defaults to the same value as
Causes case labels to be indented
tab stops to the right of the containing
causes case labels to be indented half a tab stop. The
Controls the placement of comments which are not to the
right of code. The default
means that such comments are placed one indentation level to the
lines up these comments with the code. See the section on comment
Specifies the indentation, in character positions, from a declaration keyword
to the following identifier. The default is
left justifies declarations.
indents declarations the same as code. The default is
Enables (disables) special
processing. If it's enabled, an
will have the same indentation as the preceding
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,
The number of spaces for one indentation level. The default is 4.
Enables (disables) the indentation of parameter declarations from the left
Maximum length of an output line. The default is 75.
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
.Bd -literal -offset indent
.Li p1 = first_procedure(second_procedure(p2, p3),
.Li \ \ third_procedure(p4,p5));
in effect (the default) the code looks somewhat clearer:
.Bd -literal -offset indent
.Li p1\ =\ first_procedure(second_procedure(p2,\ p3),
.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,p5));
Inserting two more newlines we get:
.Bd -literal -offset indent
.Li p1\ =\ first_procedure(second_procedure(p2,
.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4
.Li \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
Causes the profile files,
all procedure calls will have a space inserted between
the name and the `('. The default is
the names of procedures being defined are placed in
column 1 \- their types, if any, will be left on the previous lines. The
Enables (disables) the placement of asterisks (`*'s) at the left edge of all
is specified, indent will swallow optional blank lines. You can use this to
get rid of blank lines after declarations. Default:
to take its input from stdin, and put its output to stdout.
to the list of type keywords. Names accumulate:
can be specified more than once. You need to specify all the typenames that
appear in your program that are defined by
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
a symptom of a problem in C:
causes a syntactic change in the
to format the program for processing by
listing in much the same spirit as
If the output file is not specified, the default is standard output,
rather than formatting in place.
turns it off. When in verbose mode,
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
You may set up your own `profile' of defaults to
by creating a file called
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
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.
assumes that any comment with a dash or star immediately after the start of
comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
Each line of such a comment is left unchanged, except that its indentation
may be adjusted to account for the change in indentation of the first line
All other comments are treated as straight text.
fits as many words (separated by blanks, tabs, or newlines) on a
line as possible. Blank lines break paragraphs.
If a comment is on a line with code it is started in the `comment column',
command line parameter. Otherwise, the comment is started at
indentation levels less than where code is currently being placed, where
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.
leaves preprocessor lines alone. The only
reformatting that it will do is to straighten up trailing comments. It
leaves embedded comments alone. Conditional compilation
compensate for the syntactic peculiarities introduced.
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:
.Dl #define forever for(;;)
.Bl -tag -width "./.indent.pro" -compact
has even more switches than
A common mistake that often causes grief is typing:
to the shell in an attempt to indent all the
This is probably a bug, not a feature.