1 .\" Copyright (c) 1980, 1990, 1993
2 .\" The Regents of the University of California. All rights reserved.
3 .\" Copyright (c) 1976 Board of Trustees of the University of Illinois.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)indent.1 8.1 (Berkeley) 7/1/93
42 .Nd indent and format C program source
45 .Op Ar input-file Op Ar output-file
86 program formatter. It reformats the
90 according to the switches. The switches which can be
91 specified are described below. They may appear before or after the file
95 If you only specify an
98 done `in-place', that is, the formatted file is written back into
102 is written in the current directory. If
105 .Sq Pa /blah/blah/file ,
106 the backup file is named
113 checks to make sure it is different from
116 The options listed below control the formatting style imposed by
122 is specified, a blank line is forced after every block of
123 declarations. Default:
128 is specified, a blank line is forced after every procedure body. Default:
133 is specified, a blank line is forced before every block comment. Default:
138 is specified, then a newline is forced after each comma in a declaration.
140 turns off this option. Default:
145 lines-up compound statements like this:
147 .Bd -literal -offset indent
156 (the default) makes them look like this:
158 .Bd -literal -offset indent
165 The column in which comments on code start. The default is 33.
167 The column in which comments on declarations start. The default
168 is for these comments to start in the same column as those on code.
170 Enables (disables) the placement of comment delimiters on blank lines. With
171 this option enabled, comments look like this:
172 .Bd -literal -offset indent
179 Rather than like this:
180 .Bd -literal -offset indent
181 /* this is a comment */
184 This only affects block comments, not comments to the right of
188 Enables (disables) forcing of `else's to cuddle up to the immediately preceding
192 Sets the continuation indent to be
195 lines will be indented that far from the beginning of the first line of the
196 statement. Parenthesized expressions have extra indentation added to
197 indicate the nesting, unless
201 defaults to the same value as
204 Causes case labels to be indented
206 tab stops to the right of the containing
210 causes case labels to be indented half a tab stop. The
214 Controls the placement of comments which are not to the
215 right of code. For example,
217 means that such comments are placed one indentation level to the
218 left of code. Specifying the default
220 lines-up these comments with the code. See the section on comment
223 Specifies the indentation, in character positions, from a declaration keyword
224 to the following identifier. The default is
228 left justifies declarations.
230 indents declarations the same as code. The default is
233 Enables (disables) special
235 processing. If it's enabled, an
239 will have the same indentation as the preceding
241 statement. The default is
244 Enables (disables) the formatting of comments that start in column 1.
245 Often, comments whose leading `/' is in column 1 have been carefully
246 hand formatted by the programmer. In such cases,
252 The number of spaces for one indentation level. The default is 8.
254 Enables (disables) the indentation of parameter declarations from the left
255 margin. The default is
258 Maximum length of an output line. The default is 78.
260 Lines-up code surrounded by parenthesis in continuation lines. If a line
261 has a left paren which is not closed on that line, then continuation lines
262 will be lined up to start at the character position just after the left
263 paren. For example, here is how a piece of continued code looks with
267 .Bd -literal -offset indent
268 p1 = first_procedure(second_procedure(p2, p3),
269 \ \ third_procedure(p4, p5));
275 in effect (the default) the code looks somewhat clearer:
276 .Bd -literal -offset indent
277 p1\ =\ first_procedure(second_procedure(p2,\ p3),
278 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
282 Inserting two more newlines we get:
283 .Bd -literal -offset indent
284 p1\ =\ first_procedure(second_procedure(p2,
285 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
286 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
287 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
290 Causes the profile files,
293 .Sq Pa ~/.indent.pro ,
298 all procedure calls will have a space inserted between
299 the name and the `('. The default is
304 the names of procedures being defined are placed in
305 column 1 \- their types, if any, will be left on the previous lines. The
309 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
310 comments. The default is
315 is specified, indent will swallow optional blank lines. You can use this to
316 get rid of blank lines after declarations. Default:
321 to take its input from stdin and put its output to stdout.
322 .It Fl T Ns Ar typename
325 to the list of type keywords. Names accumulate:
327 can be specified more than once. You need to specify all the typenames that
328 appear in your program that are defined by
331 harmed if you miss a few, but the program won't be formatted as nicely as
332 it should. This sounds like a painful thing to have to do, but it's really
333 a symptom of a problem in C:
335 causes a syntactic change in the
344 to format the program for processing by
346 It will produce a fancy
347 listing in much the same spirit as
349 If the output file is not specified, the default is standard output,
350 rather than formatting in place.
353 turns on `verbose' mode;
355 turns it off. When in verbose mode,
357 reports when it splits one line of input into two or more lines of output,
358 and gives some size statistics at completion. The default is
362 You may set up your own `profile' of defaults to
364 by creating a file called
366 in your login directory and/or the current directory and including
367 whatever switches you like. A `.indent.pro' in the current directory takes
368 precedence over the one in your login directory. If
370 is run and a profile file exists, then it is read to set up the program's
371 defaults. Switches on the command line, though, always override profile
372 switches. The switches should be separated by spaces, tabs or newlines.
378 assumes that any comment with a dash or star immediately after the start of
379 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
380 Each line of such a comment is left unchanged, except that its indentation
381 may be adjusted to account for the change in indentation of the first line
385 All other comments are treated as straight text.
387 fits as many words (separated by blanks, tabs, or newlines) on a
388 line as possible. Blank lines break paragraphs.
390 .Ss Comment indentation
391 If a comment is on a line with code it is started in the `comment column',
394 command line parameter. Otherwise, the comment is started at
396 indentation levels less than where code is currently being placed, where
400 command line parameter. If the code on a line extends past the comment
401 column, the comment starts further to the right, and the right margin may be
402 automatically extended in extreme cases.
404 .Ss Preprocessor lines
407 leaves preprocessor lines alone. The only
408 reformatting that it will do is to straighten up trailing comments. It
409 leaves embedded comments alone. Conditional compilation
410 .Pq Ic #ifdef...#endif
413 attempts to correctly
414 compensate for the syntactic peculiarities introduced.
418 understands a substantial amount about the syntax of C, but it
419 has a `forgiving' parser. It attempts to cope with the usual sorts of
420 incomplete and misformed syntax. In particular, the use of macros like:
422 .Dl #define forever for(;;)
429 environment variable.
431 .Bl -tag -width "./.indent.pro" -compact
444 has even more switches than
448 A common mistake that often causes grief is typing:
452 to the shell in an attempt to indent all the
454 programs in a directory.
455 This is probably a bug, not a feature.