.\" Copyright (c) 1983 Regents of the University of California.
.\" All rights reserved. The Berkeley software License Agreement
.\" specifies the terms and conditions for redistribution.
.\" @(#)indent.1 6.2 (Berkeley) %G%
indent \- indent and format C program source
\fBindent \fR [ \fIinput-file\fR [ \fIoutput-file\fR ] ]
[\ \fB\-bad\fR\ |\ \fB\-nbad\fR\ ]
[\ \fB\-bap\fR\ |\ \fB\-nbap\fR\ ]
[\ \fB\-bbb\fR\ |\ \fB\-nbbb\fR\ ]
[\ \fB\-bc\fR\ |\ \fB\-nbc\fR\ ]
[\ \fB\-cdb\fR\ |\ \fB\-ncdb\fR\ ]
[\ \fB\-ce\fR\ |\ \fB\-nce\fR\ ]
[\ \fB\-fc1\fR\ |\ \fB\-nfc1\fR\ ]
[\ \fB\-ip\fR\ |\ \fB\-nip\fR\ ]
[\ \fB\-lp\fR\ |\ \fB\-nlp\fR\ ]
[\ \fB\-pcs\fR\ |\ \fB\-npcs\fR\ ]
[\ \fB\-psl\fR\ |\ \fB\-npsl\fR\ ]
[\ \fB\-sc\fR\ |\ \fB\-nsc\fR\ ]
[\ \fB\-sob\fR\ |\ \fB\-nsob\fR\ ]
[\ \fB\-v\fR\ |\ \fB\-nv\fR\ ]
.IX indent "" "\fLindent\fP \(em format C source"
.IX "programming tools" "indent" "" "\fLindent\fP \(em format C source"
.IX "languages" "indent" "" "\fLindent\fP \(em format C source"
.IX "C programming language" "indent" "" "\fLindent\fP \(em format C source"
.IX "pretty printer" "indent" "" "\fLindent\fP \(em format C source"
.IX "format C programs" "" "format C programs \(em \fLindent\fP"
.IX "code formatter" "indent" "" "\fLindent\fP \(em format C source"
.IX "cb" "indent" "\fLcb\fP" "try \fLindent\fP \(em format C source"
is a \fBC\fR program formatter. It reformats the \fBC\fR program in the
\fIinput-file\fR according to the switches. The switches which can be
specified are described below. They may appear before or after the file
\fBNOTE\fP: If you only specify an \fIinput-file\fR, the formatting is
done `in-place', that is, the formatted file is written back into
is written in the current directory. If
is named `/blah/blah/file', the backup file is named
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 procedure body. Default:
is specified, a blank line is forced after every block of
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:
(the default) makes them look like this:
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:
This only affects block comments, not comments to the right of code. The default is
Enables (disables) forcing `else's to cuddle up to the immediatly preceeding
Sets the continuation indent to be \fIn\fR. Continuation
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 \fB\-lp\fR is in effect.
\fB\-ci\fR defaults to the same value as \fB\-i\fR.
Causes case labels to be indented
tab stops to the right of the containing \fBswitch\fR statement.
\fB-cli0.5\fR 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,
will have the same indendation as the preceeding
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, \fB\-nfc1\fR should be
used. The default is \fB\-fc1\fR.
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.
Causes the profile files, `./.indent.pro' and `~/.indent.pro', to be ignored.
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 -nlp
p1 = first_procedure(second_procedure(p2, p3),
third_procedure(p4, p5));
With \fB-lp\fR in effect (the default) the code looks somewhat clearer:
p1 = first_procedure(second_procedure(p2, p3),
third_procedure(p4, p5));
Inserting a couple more newlines we get:
p1 = first_procedure(second_procedure(p2,
If true (\fB-pcs\fR) all procedure calls will have a space inserted between
the name and the '('. The default is
If true (\fB-psl\fR) 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 \fBtypedef\fRs \- 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
a symptom of a problem in C: \fBtypedef\fR causes a syntactic change in the
laguage and \fIindent\fR can't find all \fBtypedef\fRs.
to format the program for processing by troff. It will produce a fancy
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
.SH "FURTHER DESCRIPTION"
You may set up your own `profile' of defaults to
by creating a file called
in either your login directory 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.
In general, \fIindent\fR leaves preprocessor lines alone. The only
reformmatting that it will do is to straighten up trailing comments. It
leaves imbedded comments alone. Conditional compilation
(\fB#ifdef...#endif\fR) is recognized and \fIindent\fR attempts to correctly
compensate for the syntactic peculiarites introduced.
\fIIndent\fR 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:
\&./.indent.pro profile file
~/.indent.pro profile file
has even more switches than \fIls\fR.
A common mistake that often causes grief is typing:
to the shell in an attempt to indent all the \fBC\fR programs in a directory.
This is probably a bug, not a feature.