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
35 .\" $FreeBSD: src/usr.bin/indent/indent.1,v 1.28 2010/03/31 17:05:30 avg Exp $
42 .Nd indent and format C program source
45 .Op Ar input-file Op Ar output-file
98 according to the switches.
99 The switches which can be specified are described below.
100 They may appear before or after the file names.
103 If you only specify an
106 done `in-place', that is, the formatted file is written back into
110 is written in the current directory.
114 .Sq Pa /blah/blah/file ,
115 the backup file is named
122 checks to make sure that it is different from
125 The options listed below control the formatting style imposed by
131 is specified, a blank line is forced after every block of
138 is specified, a blank line is forced after every procedure body.
144 is specified, a blank line is forced before every block comment.
150 is specified, then a newline is forced after each comma in a declaration.
152 turns off this option.
158 lines-up compound statements like this:
159 .Bd -literal -offset indent
168 (the default) makes them look like this:
169 .Bd -literal -offset indent
178 is specified, then a space is inserted after
181 turns off this option.
185 The column in which comments on code start.
188 The column in which comments on declarations start.
189 The default is for these comments to start in the same column as those on code.
191 Enables (disables) the placement of comment delimiters on blank lines.
192 With this option enabled, comments look like this:
193 .Bd -literal -offset indent
199 Rather than like this:
200 .Bd -literal -offset indent
201 /* this is a comment */
204 This only affects block comments, not comments to the right of code.
208 Enables (disables) forcing of `else's to cuddle up to the immediately preceding
213 Sets the continuation indent to be
216 lines will be indented that far from the beginning of the first line of the
218 Parenthesized expressions have extra indentation added to
219 indicate the nesting, unless
221 is in effect or the continuation indent is exactly half of the main indent.
223 defaults to the same value as
226 Causes case labels to be indented
228 tab stops to the right of the containing
232 causes case labels to be indented half a tab stop.
236 Controls the placement of comments which are not to the right of code.
239 means that such comments are placed one indentation level to the left of code.
240 Specifying the default
242 lines-up these comments with the code.
243 See the section on comment indentation below.
245 Specifies the indentation, in character positions,
246 of global variable names and all struct/union member names
247 relative to the beginning of their type declaration.
252 left justifies declarations.
254 indents declarations the same as code.
258 Enables (disables) special
265 will have the same indentation as the preceding
271 Enables (disables) splitting the function declaration and opening brace
276 Enables (disables) the formatting of comments that start in column 1.
277 Often, comments whose leading `/' is in column 1 have been carefully
278 hand formatted by the programmer.
285 Enables (disables) the formatting of block comments (ones that begin
287 Often, block comments have been not so carefully hand formatted by the
288 programmer, but reformatting that would just change the line breaks is not
293 Block comments are then handled like box comments.
297 The number of spaces for one indentation level.
300 Enables (disables) the indentation of parameter declarations from the left
305 Maximum length of an output line.
308 Specifies the indentation, in character positions,
309 of local variable names
310 relative to the beginning of their type declaration.
311 The default is for local variable names to be indented
312 by the same amount as global ones.
314 Lines-up code surrounded by parenthesis in continuation lines.
316 has a left paren which is not closed on that line, then continuation lines
317 will be lined up to start at the character position just after the left
319 For example, here is how a piece of continued code looks with
322 .Bd -literal -offset indent
323 p1 = first_procedure(second_procedure(p2, p3),
324 \ \ third_procedure(p4, p5));
329 in effect (the default) the code looks somewhat clearer:
330 .Bd -literal -offset indent
331 p1\ =\ first_procedure(second_procedure(p2,\ p3),
332 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
335 Inserting two more newlines we get:
336 .Bd -literal -offset indent
337 p1\ =\ first_procedure(second_procedure(p2,
338 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
339 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
340 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
343 Causes the profile files,
346 .Sq Pa ~/.indent.pro ,
351 all procedure calls will have a space inserted between the name and the `('.
357 the names of procedures being defined are placed in
358 column 1 \- their types, if any, will be left on the previous lines.
362 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
369 is specified, indent will swallow optional blank lines.
370 You can use this to get rid of blank lines after declarations.
376 to take its input from stdin and put its output to stdout.
378 Automatically add all identifiers ending in "_t" to the list
380 .It Fl T Ns Ar typename
383 to the list of type keywords.
386 can be specified more than once.
387 You need to specify all the typenames that
388 appear in your program that are defined by
391 harmed if you miss a few, but the program will not be formatted as nicely as
393 This sounds like a painful thing to have to do, but it is really
394 a symptom of a problem in C:
396 causes a syntactic change in the
405 to format the program for processing by
407 It will produce a fancy
408 listing in much the same spirit as
410 If the output file is not specified, the default is standard output,
411 rather than formatting in place.
413 Enables (disables) the use of tab characters in the output.
414 Tabs are assumed to be aligned on columns divisible by 8.
419 turns on `verbose' mode;
422 When in verbose mode,
424 reports when it splits one line of input into two or more lines of output,
425 and gives some size statistics at completion.
430 You may set up your own `profile' of defaults to
432 by creating a file called
434 in your login directory and/or the current directory and including
435 whatever switches you like.
436 A `.indent.pro' in the current directory takes
437 precedence over the one in your login directory.
440 is run and a profile file exists, then it is read to set up the program's
442 Switches on the command line, though, always override profile switches.
443 The switches should be separated by spaces, tabs or newlines.
450 assumes that any comment with a dash or star immediately after the start of
451 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
452 Each line of such a comment is left unchanged, except that its indentation
453 may be adjusted to account for the change in indentation of the first line
457 All other comments are treated as straight text.
460 utility fits as many words (separated by blanks, tabs, or newlines) on a
462 Blank lines break paragraphs.
463 .Ss Comment indentation
464 If a comment is on a line with code it is started in the `comment column',
467 command line parameter.
468 Otherwise, the comment is started at
470 indentation levels less than where code is currently being placed, where
474 command line parameter.
475 If the code on a line extends past the comment
476 column, the comment starts further to the right, and the right margin may be
477 automatically extended in extreme cases.
478 .Ss Preprocessor lines
481 leaves preprocessor lines alone.
482 The only reformatting that it will do is to straighten up trailing comments.
483 It leaves embedded comments alone.
484 Conditional compilation
485 .Pq Ic #ifdef...#endif
488 attempts to correctly
489 compensate for the syntactic peculiarities introduced.
493 utility understands a substantial amount about the syntax of C, but it
494 has a `forgiving' parser.
495 It attempts to cope with the usual sorts of incomplete and misformed syntax.
496 In particular, the use of macros like:
498 .Dl #define forever for(;;)
506 environment variable.
508 .Bl -tag -width ".Pa /usr/share/misc/indent.pro" -compact
513 .It Pa /usr/share/misc/indent.pro
524 utility has even more switches than
527 A common mistake is to try to indent all the
529 programs in a directory by typing:
533 This is probably a bug, not a feature.