INDENT(1) BSD INDENT(1)
NAME
indent - indent and format C program source
SYNOPSIS
indent [ input-file [ output-file ] ] [ options ]
DESCRIPTION
indent is a C program formatter. It reformats the C program in the
input-file according to the options you specify. These are described
below. They can appear before or after the filenames.
If you specify only an input-file, indent does the formatting in place,
that is, it writes the formatted file back into input-file and writes a
backup copy of input-file in the current directory. If input-file is
named `/blah/blah/file', indent names the backup file `file.BAK.'
If you specify output-file, indent checks to make sure it is different
from input-file.
OPTIONS
The options listed below control the formatting style imposed by indent.
-bad,-nbad If you specify -bad, indent forces a blank line after
every block of declarations. The default is -nbad.
-bap,-nbap If you specify -bap, indent forces a blank line after
every procedure body. The default is -nbap.
-bbb,-nbbb If you specify -bbb, indent forces a blank line before
every block comment. The default is -nbbb.
-bc,-nbc If you specify -bc, indent forces a newline after each
comma in a declaration. -nbc turns off this option. The
default is -nbc.
-br,-bl If you specify -bl, indent lines up compound statements
like this:
if (...)
{
code
}
Specifying -br (the default) indent makes them look like
this:
if (...) {
code
}
-cn The column in which comments on code start. The default
is 33.
-cdn The column in which comments on declarations start. The
default is for these comments to start in the same column
as those on code.
-cdb,-ncdb Enables (-ncdb disables) the placement of comment
delimiters on blank lines. When this option is enabled,
comments look like this:
/*
* this is a comment
*/
Rather than like this:
/* this is a comment */
This affects only block comments, not comments to the
right of code. The default is -cdb.
-ce,-nce Enables (-nce disables) forcing else's to abut the
immediately preceding `}'. The default is -ce.
-cin Sets the continuation indent to be n. Continuation lines
are indented that far from the beginning of the first line
of the statement. Parenthesized expressions have extra
indentation added to indicate the nesting, unless -lp is
in effect. -ci defaults to the same value as -i.
-clin Causes case labels to be indented n tab stops to the right
of the containing switch statement. -cli0.5 causes case
labels to be indented half a tab stop. The default is
-cli0. (This is the only option that takes a fractional
argument.)
-dn Controls the placement of comments that are not to the
right of code. Specifying -d1 means that such comments
are placed one indentation level to the left of code. The
default -d0 lines up these comments with the code. See
the section on comment indentation below.
-din Specifies the indentation, in character positions, from a
declaration keyword to the following identifier. The
default is -di16.
-dj,-ndj -dj left justifies declarations. -ndj indents
declarations the same as code. The default is -ndj.
-ei,-nei Enables (-nei disables) special else-if processing. If
enabled, ifs following elses have the same indentation as
the preceding if statement. The default is -ei.
-fc1,-nfc1 Enables (-nfc1 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, you should use -nfc1. The
default is -fc1.
-in The number of spaces for one indentation level. The
default is 8.
-ip,-nip Enables (-nip disables) the indentation of parameter
declarations from the left margin. The default is -ip.
-ln Maximum length of an output line. The default is 78.
-lp,-nlp Lines up code surrounded by parentheses in continuation
lines. If a line has a left parenthesis that is not
closed on that line, indent lines up continuation lines to
start at the character position just after the left
parenthesis. For example, here is how a piece of
continued code looks with -nlp in effect:
p1 = first_procedure(second_procedure(p2, p3),
third_procedure(p4, p5));
With -lp in effect (the default) the code looks somewhat
clearer:
p1 = first_procedure(second_procedure(p2, p3),
third_procedure(p4, p5));
Inserting two more newlines we get this:
p1 = first_procedure(second_procedure(p2,
p3),
third_procedure(p4,
p5));
-npro Causes the profile files, ./.indent.pro and ~/.indent.pro,
to be ignored.
-pcs,-npcs If true, (-pcs) all procedure calls have a space inserted
between the name and the `('. The default is -npcs.
-ps,-nps If true, (-ps) the pointer following operator `->' is
surrounded by spaces on either side. The default is -nps.
-psl,-npsl If true (-psl) the names of procedures being defined are
placed in column 1; their types, if any,are left on the
previous lines. The default is -psl.
-sc,-nsc Enables (-nsc disables) the placement of asterisks (*) at
the left edge of all comments. The default is -sc.
-sob,-nsob If you specify -sob, indent swallows optional blank lines.
You can use this to get rid of blank lines after
declarations. The default is -nsob.
-st Causes indent to take its input from stdin, and send its
output to stdout.
-Ttypename Adds typename to the list of type keywords. Names
accumulate: you can specify -T more than once. You must
specify all the typenames that appear in your program that
are defined by typedefs - nothing is harmed if you miss a
few, but the program won't be formatted as nicely as it
should. This sounds painful, but it's really a symptom of
a problem in C: typedef causes a syntactic change in the
language and indent can't find all typedefs.
-troff Causes indent to format the program for processing by
troff. It produces a fancy listing in much the same
spirit as vgrind. If you do not specify the output file,
the default is standard output rather than formatting in
place.
-v,-nv -v turns on verbose mode; -nv turns it off. When in
verbose mode, indent 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 -nv.
FURTHER DESCRIPTION
You can set up your own profile of defaults to indent by creating a file
called .indent.pro in either your log-in directory and/or the current
directory, and including whatever options you like. Options in
.indent.pro in the current directory override those in your log-in
directory (with the exception of -T type definitions, which just
accumulate). When you have a profile file and run indent, it reads the
profile file to set up the program's defaults. Separate the options by
spaces, tabs or newlines. However, options that you specify on the
command line override options specified in the profile file.
Comments
Box comments. indent 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. It does not change such a comment,
except that it may adjust indentation to account for the change in
indentation of the first line of the comment.
Straight text. indent treats all other comments as straight text.
indent fits as many words (separated by blanks, tabs, or newlines) on a
line as possible. Blank lines break paragraphs.
Comment indentation
If a comment is on a line with code, it is started in the comment column,
which you can set by the -cn command-line parameter. Otherwise, the
comment is started at n indentation levels less than where code is
currently being placed, where n is specified by the -dn 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.
Preprocessor lines
In general, indent leaves preprocessor lines alone. The only reformatting
it does is to straighten up trailing comments. It leaves embedded
comments alone. indent recognizes conditional compilation
(#ifdef...#endif), and attempts to compensate for the syntactic
peculiarities introduced.
C syntax
indent understands a lot about C syntax, but it has a forgiving parser.
It attempts to cope with the usual sorts of incomplete and misformed
syntax. In particular, it handles macros like
#define forever for(;;)
properly.
FILES
./.indent.pro Profile file
~/.indent.pro Profile file
BUGS
indent has even more options than ls.
A common mistake that often causes grief is typing
indent *.c
to the shell in an attempt to indent all the C programs in a directory.
This is probably a bug, not a feature.