BSD 4_3_Reno development
[unix-history] / usr / share / man / cat1 / indent.0
CommitLineData
e0f03d36
C
1INDENT(1) UNIX Reference Manual INDENT(1)
2
3N\bNA\bAM\bME\bE
4 i\bin\bnd\bde\ben\bnt\bt - indent and format C program source
5
6S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
7 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]
8 [-\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]
9 [-\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]
10 [-\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]
11 [-\b-n\bnp\bpr\bro\bo] [-\b-p\bpc\bcs\bs | -\b-n\bnp\bpc\bcs\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]
12 [-\b- ] [-\b-t\btr\bro\bof\bff\bf] [-\b-v\bv | -\b-n\bnv\bv]
13
14D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
15 I\bIn\bnd\bde\ben\bnt\bt is a _\bC program formatter. It reformats the _\bC program in the
16 _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be according to the switches. The switches which can be speci-
17 fied are described below. They may appear before or after the file names.
18
19 N\bNO\bOT\bTE\bE: If you only specify an _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be, the formatting is done `in-
20 place', that is, the formatted file is written back into _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be and a
21 backup copy of _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be is written in the current directory. If
22 _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be is named `/_\bb_\bl_\ba_\bh/_\bb_\bl_\ba_\bh/_\bf_\bi_\bl_\be', the backup file is named _\bf_\bi_\bl_\be._\bB_\bA_\bK.
23
24 If _\bo_\bu_\bt_\bp_\bu_\bt-_\bf_\bi_\bl_\be is specified, i\bin\bnd\bde\ben\bnt\bt checks to make sure it is different
25 from _\bi_\bn_\bp_\bu_\bt-_\bf_\bi_\bl_\be.
26
27 The options listed below control the formatting style imposed by i\bin\bnd\bde\ben\bnt\bt.
28
29 -\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
30 block of declarations. Default: -\b-n\bnb\bba\bad\bd.
31
32 -\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
33 procedure body. Default: -\b-n\bnb\bba\bap\bp.
34
35 -\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
36 block comment. Default: -\b-n\bnb\bbb\bbb\bb.
37
38 -\b-b\bbc\bc, -\b-n\bnb\bbc\bc If -\b-b\bbc\bc is specified, then a newline is forced after each
39 comma in a declaration. -\b-n\bnb\bbc\bc turns off this option. The
40 default is -\b-b\bbc\bc.
41
42 -\b-b\bbr\br, -\b-b\bbl\bl Specifying -\b-b\bbl\bl lines up compound statements like this:
43 if (...)
44 {
45 code
46 }
47 Specifying -\b-b\bbr\br (the default) makes them look like this:
48 if (...) {
49 code
50 }
51
52 -\b-c\bc -\b-n\bn The column in which comments on code start. The default is
53 33.
54
55 -\b-c\bcd\bd -\b-n\bn The column in which comments on declarations start. The
56 default is for these comments to start in the same column
57 as those on code.
58
59 -\b-c\bcd\bdb\bb, -\b-n\bnc\bcd\bdb\bb Enables (disables) the placement of comment delimiters on
60 blank lines. With this option enabled, comments look like
61 this:
62 /*
63 * this is a comment
64 */
65 Rather than like this:
66 /* this is a comment */
67 This only affects block comments, not comments to the right
68 of code. The default is -\b-c\bcd\bdb\bb.
69
70 -\b-c\bce\be, -\b-n\bnc\bce\be Enables (disables) forcing `else's to cuddle up to the im-
71 mediately preceding `}'. The default is -\b-c\bce\be.
72
73 -\b-c\bci\bi_\bn Sets the continuation indent to be _\bn. Continuation lines
74 will be indented that far from the beginning of the first
75 line of the statement. Parenthesized expressions have ex-
76 tra indentation added to indicate the nesting, unless -\b-l\blp\bp
77 is in effect. -\b-c\bci\bi defaults to the same value as -\b-i\bi.
78
79 -\b-c\bcl\bli\bi_\bn Causes case labels to be indented _\bn tab stops to the right
80 of the containing s\bsw\bwi\bit\btc\bch\bh statement. -\b-c\bcl\bli\bi0\b0 -\b-.\b.5\b5 causes case
81 labels to be indented half a tab stop. The default is
82 -\b-c\bcl\bli\bi0\b0.
83
84 -\b-d\bd_\bn Controls the placement of comments which are not to the
85 right of code. The default -\b-d\bd1\b1 means that such comments
86 are placed one indentation level to the left of code.
87 Specifying -\b-d\bd0\b0 lines up these comments with the code. See
88 the section on comment indentation below.
89
90 -\b-d\bdi\bi_\bn Specifies the indentation, in character positions, from a
91 declaration keyword to the following identifier. The
92 default is -\b-d\bdi\bi1\b16\b6.
93
94 -\b-d\bdj\bj, -\b-n\bnd\bdj\bj -\b-d\bdj\bj left justifies declarations. -\b-n\bnd\bdj\bj indents declarations
95 the same as code. The default is -\b-n\bnd\bdj\bj.
96
97 -\b-e\bei\bi, -\b-n\bne\bei\bi Enables (disables) special e\bel\bls\bse\be-\b-i\bif\bf processing. If it's en-
98 abled, an i\bif\bf following an e\bel\bls\bse\be will have the same indenta-
99 tion as the preceding i\bif\bf statement.
100
101 -\b-f\bfc\bc1\b1, -\b-n\bnf\bfc\bc1\b1 Enables (disables) the formatting of comments that start in
102 column 1. Often, comments whose leading `/' is in column 1
103 have been carefully hand formatted by the programmer. In
104 such cases, -\b-n\bnf\bfc\bc1\b1 should be used. The default is -\b-f\bfc\bc1\b1.
105
106 -\b-i\bi_\bn The number of spaces for one indentation level. The
107 default is 4.
108
109 -\b-i\bip\bp, -\b-n\bni\bip\bp Enables (disables) the indentation of parameter declara-
110 tions from the left margin. The default is -\b-i\bip\bp.
111
112 -\b-l\bl_\bn Maximum length of an output line. The default is 75.
113
114 -\b-l\blp\bp, -\b-n\bnl\blp\bp Lines up code surrounded by parenthesis in continuation
115 lines. If a line has a left paren which is not closed on
116 that line, then continuation lines will be lined up to
117 start at the character position just after the left paren.
118 For example, here is how a piece of continued code looks
119 with -\b-n\bnl\blp\bp in effect:
120 p1 = first_procedure(second_procedure(p2, p3),
121 third_procedure(p4,p5));
122 With -\b-l\blp\bp in effect (the default) the code looks somewhat
123 clearer:
124 p1 = first_procedure(second_procedure(p2, p3),
125 third_procedure(p4,p5));
126 Inserting two more newlines we get:
127 p1 = first_procedure(second_procedure(p2,
128 p3),
129 third_procedure(p4
130 p5));
131
132 -\b-n\bnp\bpr\bro\bo Causes the profile files, `./._\bi_\bn_\bd_\be_\bn_\bt._\bp_\br_\bo' and
133 `~/._\bi_\bn_\bd_\be_\bn_\bt._\bp_\br_\bo', to be ignored.
134 -\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 in-
135 serted between the name and the `('. The default is -\b-n\bnp\bpc\bcs\bs.
136
137 -\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
138 placed in column 1 - their types, if any, will be left on
139 the previous lines. The default is -\b-p\bps\bsl\bl.
140
141 -\b-s\bsc\bc, -\b-n\bns\bsc\bc Enables (disables) the placement of asterisks (`*'s) at the
142 left edge of all comments.
143
144 -\b-s\bso\bob\bb, -\b-n\bns\bso\bob\bb If -\b-s\bso\bob\bb is specified, indent will swallow optional blank
145 lines. You can use this to get rid of blank lines after
146 declarations. Default: -\b-n\bns\bso\bob\bb.
147
148 -\b-s\bst\bt Causes i\bin\bnd\bde\ben\bnt\bt to take its input from stdin, and put its
149 output to stdout.
150
151 -\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 accumu-
152 late: -\b-T\bT can be specified more than once. You need to
153 specify all the typenames that appear in your program that
154 are defined by t\bty\byp\bpe\bed\bde\bef\bf - nothing will be harmed if you miss
155 a few, but the program won't be formatted as nicely as it
156 should. This sounds like a painful thing to have to do,
157 but it's really a symptom of a problem in C: t\bty\byp\bpe\bed\bde\bef\bf causes
158 a syntactic change in the language and i\bin\bnd\bde\ben\bnt\bt can't find
159 all instances of t\bty\byp\bpe\bed\bde\bef\bf.
160
161 -\b-t\btr\bro\bof\bff\bf Causes i\bin\bnd\bde\ben\bnt\bt to format the program for processing by
162 troff. It will produce a fancy listing in much the same
163 spirit as vgrind(1). If the output file is not specified,
164 the default is standard output, rather than formatting in
165 place.
166
167 -\b-v\bv, -\b-n\bnv\bv -\b-v\bv turns on `verbose' mode; -\b-n\bnv\bv turns it off. When in ver-
168 bose mode, i\bin\bnd\bde\ben\bnt\bt reports when it splits one line of input
169 into two or more lines of output, and gives some size
170 statistics at completion. The default is -\b-n\bnv\bv.
171
172 You may set up your own `profile' of defaults to i\bin\bnd\bde\ben\bnt\bt by creating a
173 file called ._\bi_\bn_\bd_\be_\bn_\bt._\bp_\br_\bo in your login directory and/or the current direc-
174 tory and including whatever switches you like. A `.indent.pro' in the
175 current directory takes precedence over the one in your login directory.
176 If i\bin\bnd\bde\ben\bnt\bt is run and a profile file exists, then it is read to set up the
177 program's defaults. Switches on the command line, though, always over-
178 ride profile switches. The switches should be separated by spaces, tabs
179 or newlines.
180
181 C\bCo\bom\bmm\bme\ben\bnt\bts\bs
182 `_\bB_\bo_\bx' _\bc_\bo_\bm_\bm_\be_\bn_\bt_\bs. I\bIn\bnd\bde\ben\bnt\bt assumes that any comment with a dash or star im-
183 mediately after the start of comment (that is, `/*-' or `/**') is a com-
184 ment surrounded by a box of stars. Each line of such a comment is left
185 unchanged, except that its indentation may be adjusted to account for the
186 change in indentation of the first line of the comment.
187
188 _\bS_\bt_\br_\ba_\bi_\bg_\bh_\bt _\bt_\be_\bx_\bt. All other comments are treated as straight text. I\bIn\bnd\bde\ben\bnt\bt
189 fits as many words (separated by blanks, tabs, or newlines) on a line as
190 possible. Blank lines break paragraphs.
191
192 C\bCo\bom\bmm\bme\ben\bnt\bt i\bin\bnd\bde\ben\bnt\bta\bat\bti\bio\bon\bn
193 If a comment is on a line with code it is started in the `comment
194 column', which is set by the -\b-c\bc_\bn command line parameter. Otherwise, the
195 comment is started at _\bn indentation levels less than where code is
196 currently being placed, where _\bn is specified by the -\b-d\bd_\bn command line
197 parameter. If the code on a line extends past the comment column, the
198 comment starts further to the right, and the right margin may be
199 automatically extended in extreme cases.
200 P\bPr\bre\bep\bpr\bro\boc\bce\bes\bss\bso\bor\br l\bli\bin\bne\bes\bs
201 In general, i\bin\bnd\bde\ben\bnt\bt leaves preprocessor lines alone. The only reformat-
202 ting that it will do is to straighten up trailing comments. It leaves
203 embedded comments alone. Conditional compilation (#\b#i\bif\bfd\bde\bef\bf.\b..\b..\b.#\b#e\ben\bnd\bdi\bif\bf) is
204 recognized and i\bin\bnd\bde\ben\bnt\bt attempts to correctly compensate for the syntactic
205 peculiarities introduced.
206
207 C\bC s\bsy\byn\bnt\bta\bax\bx
208 I\bIn\bnd\bde\ben\bnt\bt understands a substantial amount about the syntax of C, but it has
209 a `forgiving' parser. It attempts to cope with the usual sorts of incom-
210 plete and misformed syntax. In particular, the use of macros like:
211 #define forever for(;;)
212 is handled properly.
213
214E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT
215 I\bIn\bnd\bde\ben\bnt\bt uses the HOME environment variable.
216
217F\bFI\bIL\bLE\bES\bS
218 ./._\bi_\bn_\bd_\be_\bn_\bt._\bp_\br_\bo profile file
219 ~/._\bi_\bn_\bd_\be_\bn_\bt._\bp_\br_\bo profile file
220
221
222H\bHI\bIS\bST\bTO\bOR\bRY\bY
223 I\bIn\bnd\bde\ben\bnt\bt appeared in 4.2 BSD.
224
225B\bBU\bUG\bGS\bS
226 I\bIn\bnd\bde\ben\bnt\bt has even more switches than ls(1).
227
228 A common mistake that often causes grief is typing:
229 indent *.c
230 to the shell in an attempt to indent all the C\bC programs in a directory.
231 This is probably a bug, not a feature.