BSD 4_3_Tahoe development
[unix-history] / usr / man / cat1 / indent.0
INDENT(1) UNIX Programmer's Manual INDENT(1)
N\bNA\bAM\bME\bE
indent - indent and format C program source
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
i\bin\bnd\bde\ben\bnt\bt [ _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be [ _\bo_\bu_\bt_\bp_\bu_\bt-_\bf_\bi_\bl_\be ] ] [ -\b-b\bba\bad\bd | -\b-n\bnb\bba\bad\bd ]
[ -\b-b\bba\bap\bp | -\b-n\bnb\bba\bap\bp ] [ -\b-b\bbb\bbb\bb | -\b-n\bnb\bbb\bbb\bb ] [ -\b-b\bbc\bc | -\b-n\bnb\bbc\bc ]
[ -\b-b\bbl\bl | -\b-b\bbr\br ] [ -\b-c\bc_\bn ] [ -\b-c\bcd\bd_\bn ] [ -\b-c\bcd\bdb\bb | -\b-n\bnc\bcd\bdb\bb ]
[ -\b-c\bce\be | -\b-n\bnc\bce\be ] [ -\b-c\bci\bi_\bn ] [ -\b-c\bcl\bli\bi_\bn ] [ -\b-d\bd_\bn ] [ -\b-d\bdi\bi_\bn ]
[ -\b-d\bdj\bj | -\b-n\bnd\bdj\bj ] [ -\b-e\bei\bi | -\b-n\bne\bei\bi ] [ -\b-f\bfc\bc1\b1 | -\b-n\bnf\bfc\bc1\b1 ]
[ -\b-i\bi_\bn ] [ -\b-i\bip\bp | -\b-n\bni\bip\bp ] [ -\b-l\bl_\bn ] [ -\b-l\blc\bc_\bn ]
[ -\b-l\blp\bp | -\b-n\bnl\blp\bp ] [ -\b-n\bnp\bpr\bro\bo ] [ -\b-p\bpc\bcs\bs | -\b-n\bnp\bpc\bcs\bs ]
[ -\b-p\bps\bs | -\b-n\bnp\bps\bs ] [ -\b-p\bps\bsl\bl | -\b-n\bnp\bps\bsl\bl ] [ -\b-s\bsc\bc | -\b-n\bns\bsc\bc ]
[ -\b-s\bso\bob\bb | -\b-n\bns\bso\bob\bb ] [ -\b-s\bst\bt ] [ -\b-t\btr\bro\bof\bff\bf ] [ -\b-v\bv | -\b-n\bnv\bv ]
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
_\bI_\bn_\bd_\be_\bn_\bt is a C\bC program formatter. It reformats the C\bC program
in the _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be according to the switches. The switches
which can be specified are described below. They may appear
before or after the file names.
N\bNO\bOT\bTE\bE: If you only specify an _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be, the formatting is
done `in-place', that is, the formatted file is written back
into _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be and a backup copy of _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be is written
in the current directory. If _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be is named
`/blah/blah/file', the backup file is named file._\bB_\bA_\bK.
If _\bo_\bu_\bt_\bp_\bu_\bt-_\bf_\bi_\bl_\be is specified, _\bi_\bn_\bd_\be_\bn_\bt checks to make sure it
is different from _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be.
O\bOP\bPT\bTI\bIO\bON\bNS\bS
The options listed below control the formatting style
imposed by _\bi_\bn_\bd_\be_\bn_\bt.
-\b-b\bba\bad\bd,-\b-n\bnb\bba\bad\bd If -\b-b\bba\bad\bd is specified, a blank line is forced
after every block of declarations. Default:
-\b-n\bnb\bba\bad\bd.
-\b-b\bba\bap\bp,-\b-n\bnb\bba\bap\bp If -\b-b\bba\bap\bp is specified, a blank line is forced
after every procedure body. Default: -\b-n\bnb\bba\bap\bp.\b.
-\b-b\bbb\bbb\bb,-\b-n\bnb\bbb\bbb\bb If -\b-b\bbb\bbb\bb is specified, a blank line is forced
before every block comment. Default: -\b-n\bnb\bbb\bbb\bb.\b.
-\b-b\bbc\bc,-\b-n\bnb\bbc\bc If -\b-b\bbc\bc is specified, then a newline is forced
after each comma in a declaration. -\b-n\bnb\bbc\bc turns
off this option. The default is -\b-n\bnb\bbc\bc.
-\b-b\bbr\br,-\b-b\bbl\bl Specifying -\b-b\bbl\bl lines up compound statements
like this:
if (...)
{
code
Printed 7/9/88 September 10, 1985 1
INDENT(1) UNIX Programmer's Manual INDENT(1)
}
Specifying -\b-b\bbr\br (the default) makes them look
like this:
if (...) {
code
}
-\b-c\bc_\bn The column in which comments on code start.
The default is 33.
-\b-c\bcd\bd_\bn The column in which comments on declarations
start. The default is for these comments to
start in the same column as those on code.
-\b-c\bcd\bdb\bb,-\b-n\bnc\bcd\bdb\bb Enables (disables) the placement of comment
delimiters on blank lines. With this option
enabled, comments look like this:
/*
* this is a comment
*/
Rather than like this:
/* this is a comment */
This only affects block comments, not com-
ments to the right of code. The default is
-\b-c\bcd\bdb\bb.
-\b-c\bce\be,-\b-n\bnc\bce\be Enables (disables) forcing `else's to cuddle
up to the immediately preceding `}'. The
default is -\b-c\bce\be.
-\b-c\bci\bi_\bn Sets the continuation indent to be _\bn. Con-
tinuation 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 nest-
ing, unless -\b-l\blp\bp is in effect. -\b-c\bci\bi defaults
to the same value as -\b-i\bi.
-\b-c\bcl\bli\bi_\bn Causes case labels to be indented _\bn tab stops
to the right of the containing s\bsw\bwi\bit\btc\bch\bh state-
ment. -\b-c\bcl\bli\bi0\b0.\b.5\b5 causes case labels to be
indented half a tab stop. The default is
-\b-c\bcl\bli\bi0\b0. (This is the only option that takes a
fractional argument.)
-\b-d\bd_\bn Controls the placement of comments which are
not to the right of code. Specifying -\b-d\bd1\b1
means that such comments are placed one
indentation level to the left of code. The
default -\b-d\bd0\b0 lines up these comments with the
code. See the section on comment indentation
below.
Printed 7/9/88 September 10, 1985 2
INDENT(1) UNIX Programmer's Manual INDENT(1)
-\b-d\bdi\bi_\bn Specifies the indentation, in character posi-
tions, from a declaration keyword to the fol-
lowing identifier. The default is -\b-d\bdi\bi1\b16\b6.
-\b-d\bdj\bj,-\b-n\bnd\bdj\bj -\b-d\bdj\bj left justifies declarations. -\b-n\bnd\bdj\bj
indents declarations the same as code. The
default is -\b-n\bnd\bdj\bj.
-\b-e\bei\bi,-\b-n\bne\bei\bi Enables (disables) special e\bel\bls\bse\be-\b-i\bif\bf process-
ing. If enabled, i\bif\bfs following e\bel\bls\bse\bes will
have the same indentation as the preceding i\bif\bf
statement. The default is -\b-e\bei\bi.
-\b-f\bfc\bc1\b1,-\b-n\bnf\bfc\bc1\b1 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, -\b-n\bnf\bfc\bc1\b1 should be used. The
default is -\b-f\bfc\bc1\b1.
-\b-i\bi_\bn The number of spaces for one indentation
level. The default is 8.
-\b-i\bip\bp,-\b-n\bni\bip\bp Enables (disables) the indentation of parame-
ter declarations from the left margin. The
default is -\b-i\bip\bp.
-\b-l\bl_\bn Maximum length of an output line. The
default is 78.
-\b-l\blp\bp,-\b-n\bnl\blp\bp 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 -\b-n\bnl\blp\bp in effect:
p1 = first_procedure(second_procedure(p2, p3),
third_procedure(p4, p5));
With -\b-l\blp\bp 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:
p1 = first_procedure(second_procedure(p2,
p3),
third_procedure(p4,
p5));
-\b-n\bnp\bpr\bro\bo Causes the profile files, `./.indent.pro' and
`~/.indent.pro', to be ignored.
Printed 7/9/88 September 10, 1985 3
INDENT(1) UNIX Programmer's Manual INDENT(1)
-\b-p\bpc\bcs\bs,-\b-n\bnp\bpc\bcs\bs If true (-\b-p\bpc\bcs\bs) all procedure calls will have
a space inserted between the name and the
`('. The default is -\b-n\bnp\bpc\bcs\bs.
-\b-p\bps\bs,-\b-n\bnp\bps\bs If true (-\b-p\bps\bs) the pointer following operator
`->' will be surrounded by spaces on either
side. The default is -\b-n\bnp\bps\bs.
-\b-p\bps\bsl\bl,-\b-n\bnp\bps\bsl\bl If true (-\b-p\bps\bsl\bl) the names of procedures being
defined are placed in column 1 - their types,
if any, will be left on the previous lines.
The default is -\b-p\bps\bsl\bl.
-\b-s\bsc\bc,-\b-n\bns\bsc\bc Enables (disables) the placement of asterisks
(`*'s) at the left edge of all comments. The
default is -\b-s\bsc\bc.
-\b-s\bso\bob\bb,-\b-n\bns\bso\bob\bb If -\b-s\bso\bob\bb is specified, indent will swallow
optional blank lines. You can use this to
get rid of blank lines after declarations.
Default: -\b-n\bns\bso\bob\bb.
-\b-s\bst\bt Causes i\bin\bnd\bde\ben\bnt\bt to take its input from stdin,
and put its output to stdout.
-\b-T\bT_\bt_\by_\bp_\be_\bn_\ba_\bm_\be Adds _\bt_\by_\bp_\be_\bn_\ba_\bm_\be to the list of type keywords.
Names accumulate: -\b-T\bT can be specified more
than once. You need to specify all the
typenames that appear in your program that
are defined by t\bty\byp\bpe\bed\bde\bef\bfs - 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: t\bty\byp\bpe\bed\bde\bef\bf causes a syntactic change in the
language and _\bi_\bn_\bd_\be_\bn_\bt can't find all t\bty\byp\bpe\bed\bde\bef\bfs.
-\b-t\btr\bro\bof\bff\bf Causes i\bin\bnd\bde\ben\bnt\bt to format the program for pro-
cessing by troff. It will produce a fancy
listing in much the same spirit as v\bvg\bgr\bri\bin\bnd\bd.
If the output file is not specified, the
default is standard output, rather than for-
matting in place.
-\b-v\bv,-\b-n\bnv\bv -\b-v\bv turns on `verbose' mode; -\b-n\bnv\bv turns it off.
When in verbose mode, _\bi_\bn_\bd_\be_\bn_\bt reports when it
splits one line of input into two or more
lines of output, and gives some size statis-
tics at completion. The default is -\b-n\bnv\bv.
F\bFU\bUR\bRT\bTH\bHE\bER\bR D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
Printed 7/9/88 September 10, 1985 4
INDENT(1) UNIX Programmer's Manual INDENT(1)
You may set up your own `profile' of defaults to _\bi_\bn_\bd_\be_\bn_\bt by
creating a file called .\b._\bi_\bn_\bd_\be_\bn_\bt.\b._\bp_\br_\bo in either your login
directory and/or the current directory and including what-
ever switches you like. Switches in `.indent.pro' in the
current directory override those in your login directory
(with the exception of -\b-T\bT type definitions, which just accu-
mulate). If _\bi_\bn_\bd_\be_\bn_\bt is run and a profile file exists, then
it is read to set up the program's defaults. The switches
should be separated by spaces, tabs or newlines. Switches
on the command line, however, override profile switches.
C\bCo\bom\bmm\bme\ben\bnt\bts\bs
`_\bB_\bo_\bx' _\bc_\bo_\bm_\bm_\be_\bn_\bt_\bs. _\bI_\bn_\bd_\be_\bn_\bt 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 of the comment.
_\bS_\bt_\br_\ba_\bi_\bg_\bh_\bt _\bt_\be_\bx_\bt. All other comments are treated as straight
text. _\bI_\bn_\bd_\be_\bn_\bt fits as many words (separated by blanks, tabs,
or newlines) on a line as possible. Blank lines break para-
graphs.
C\bCo\bom\bmm\bme\ben\bnt\bt i\bin\bnd\bde\ben\bnt\bta\bat\bti\bio\bon\bn
If a comment is on a line with code it is started in the
`comment column', which is set by the -\b-c\bc_\bn command line
parameter. Otherwise, the comment is started at _\bn indenta-
tion levels less than where code is currently being placed,
where _\bn is specified by the -\b-d\bd_\bn command line parameter. If
the code on a line extends past the comment column, the com-
ment starts further to the right, and the right margin may
be automatically extended in extreme cases.
P\bPr\bre\bep\bpr\bro\boc\bce\bes\bss\bso\bor\br l\bli\bin\bne\bes\bs
In general, _\bi_\bn_\bd_\be_\bn_\bt leaves preprocessor lines alone. The
only reformatting that it will do is to straighten up trail-
ing comments. It leaves embedded comments alone. Condi-
tional compilation (#\b#i\bif\bfd\bde\bef\bf.\b..\b..\b.#\b#e\ben\bnd\bdi\bif\bf) is recognized and
_\bi_\bn_\bd_\be_\bn_\bt attempts to correctly compensate for the syntactic
peculiarities introduced.
C\bC s\bsy\byn\bnt\bta\bax\bx
_\bI_\bn_\bd_\be_\bn_\bt 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:
#define forever for(;;)
Printed 7/9/88 September 10, 1985 5
INDENT(1) UNIX Programmer's Manual INDENT(1)
is handled properly.
F\bFI\bIL\bLE\bES\bS
./.indent.pro profile file
~/.indent.pro profile file
B\bBU\bUG\bGS\bS
_\bI_\bn_\bd_\be_\bn_\bt has even more switches than _\bl_\bs.
A common mistake that often causes grief is typing:
indent *.c
to the shell in an attempt to indent all the C\bC programs in a
directory. This is probably a bug, not a feature.
Printed 7/9/88 September 10, 1985 6