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. Neither the name of the University nor the names of its contributors
15 .\" may be used to endorse or promote products derived from this software
16 .\" without specific prior written permission.
18 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 .\" @(#)indent.1 8.1 (Berkeley) 7/1/93
38 .Nd indent and format C program source
41 .Op Ar input-file Op Ar output-file
42 .Op Fl bacc | Fl nbacc
44 .Op Fl badp | Fl nbadp
77 .Op Fl \&lpl | Fl nlpl
88 .Op Fl T Ns Ar typename
104 according to the switches.
105 The switches which can be
106 specified are described below.
107 They may appear before or after the file
111 If you only specify an
114 done `in-place', that is, the formatted file is written back into
118 is written in the current directory.
122 .Sq Pa /blah/blah/file ,
123 the backup file is named
125 by default. The extension used for the backup file may be overridden using the
126 .Ev SIMPLE_BACKUP_SUFFIX
127 environment variable.
133 checks to make sure that it is different from
136 The options listed below control the formatting style imposed by
142 is specified, a blank line is forced around every conditional
144 For example, in front of every #ifdef and after every #endif.
145 Other blank lines surrounding such blocks will be swallowed.
151 is specified, a blank line is forced after every block of
156 This is vaguely similar to
158 except that it only applies to the first set of declarations
159 in a procedure (just after the first `{') and it causes a blank
160 line to be generated even if there are no declarations.
166 is specified, a blank line is forced after every procedure body.
172 is specified, a blank line is forced before every block comment.
178 is specified, then a newline is forced after each comma in a declaration.
180 turns off this option.
186 lines up compound statements like this:
187 .Bd -literal -offset indent
196 (the default) makes them look like this:
197 .Bd -literal -offset indent
203 Whether a blank should always be inserted after sizeof.
207 The column in which comments on code start.
210 The column in which comments on declarations start.
212 is for these comments to start in the same column as those on code.
214 Enables (disables) the placement of comment delimiters on blank lines.
216 this option enabled, comments look like this:
217 .Bd -literal -offset indent
223 Rather than like this:
224 .Bd -literal -offset indent
225 /* this is a comment */
228 This only affects block comments, not comments to the right of
233 Enables (disables) forcing of `else's to cuddle up to the immediately preceding
238 Sets the continuation indent to be
241 lines will be indented that far from the beginning of the first line of the
243 Parenthesized expressions have extra indentation added to
244 indicate the nesting, unless
247 or the continuation indent is exactly half of the main indent.
249 defaults to the same value as
252 Causes case labels to be indented
254 tab stops to the right of the containing
258 causes case labels to be indented half a tab stop.
263 Control whether parenthesized type names in casts are followed by a space or
268 Controls the placement of comments which are not to the
272 means that such comments are placed one indentation level to the
274 Specifying the default
276 lines up these comments with the code.
277 See the section on comment
280 Specifies the indentation, in character positions,
281 of global variable names and all struct/union member names
282 relative to the beginning of their type declaration.
287 left justifies declarations.
289 indents declarations the same as code.
293 Enables (disables) special
300 will have the same indentation as the preceding
306 Enables (disables) extra indentation on continuation lines of
307 the expression part of
312 These continuation lines will be indented one extra level.
316 Enables (disables) splitting the function declaration and opening brace
321 Enables (disables) the formatting of comments that start in column 1.
322 Often, comments whose leading `/' is in column 1 have been carefully
323 hand formatted by the programmer.
331 Enables (disables) the formatting of block comments (ones that begin
333 Often, block comments have been not so carefully hand formatted by the
334 programmer, but reformatting that would just change the line breaks is not
339 Block comments are then handled like box comments.
343 The number of columns for one indentation level.
346 Enables (disables) the indentation of parameter declarations from the left
351 Maximum length of an output line.
354 Maximum length of an output line in a block comment.
355 The default is 0, which means to limit block comment lines in accordance with
358 Specifies the indentation, in character positions,
359 of local variable names
360 relative to the beginning of their type declaration.
361 The default is for local variable names to be indented
362 by the same amount as global ones.
364 Lines up code surrounded by parentheses in continuation lines.
368 has a left paren which is not closed on that line, then continuation lines
369 will be lined up to start at the character position just after the left
371 For example, here is how a piece of continued code looks with
374 .Bd -literal -offset indent
375 p1 = first_procedure(second_procedure(p2, p3),
376 \ \ third_procedure(p4, p5));
381 in effect (the default) the code looks somewhat clearer:
382 .Bd -literal -offset indent
383 p1\ =\ first_procedure(second_procedure(p2,\ p3),
384 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
387 Inserting two more newlines we get:
388 .Bd -literal -offset indent
389 p1\ =\ first_procedure(second_procedure(p2,
390 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
391 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
392 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
397 code surrounded by parentheses in continuation lines is lined up even if it
398 would extend past the right margin.
401 (the default), such a line that would extend past the right margin is moved
402 left to keep it within the margin, if that does not require placing it to
403 the left of the prevailing indentation level.
404 These switches have no effect if
408 Causes the profile files,
411 .Sq Pa ~/.indent.pro ,
419 all procedure calls will have a space inserted between
420 the name and the `('.
426 the names of procedures being defined are placed in
427 column 1 \- their types, if any, will be left on the previous lines.
432 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
439 is specified, indent will swallow optional blank lines.
441 get rid of blank lines after declarations.
447 to take its input from stdin and put its output to stdout.
449 Automatically add all identifiers ending in "_t" to the list
451 .It Fl T Ns Ar typename
454 to the list of type keywords.
457 can be specified more than once.
458 You need to specify all the typenames that
459 appear in your program that are defined by
462 harmed if you miss a few, but the program will not be formatted as nicely as
464 This sounds like a painful thing to have to do, but it is really
465 a symptom of a problem in C:
467 causes a syntactic change in the
474 Assumed distance between tab stops.
479 to the list of type keywords.
481 Enables (disables) the use of tab characters in the output.
486 turns on `verbose' mode;
489 When in verbose mode,
491 reports when it splits one line of input into two or more lines of output,
492 and gives some size statistics at completion.
498 to print its version number and exit.
501 You may set up your own `profile' of defaults to
503 by creating a file called
505 in your login directory and/or the current directory and including
506 whatever switches you like.
507 A `.indent.pro' in the current directory takes
508 precedence over the one in your login directory.
511 is run and a profile file exists, then it is read to set up the program's
513 Switches on the command line, though, always override profile
515 The switches should be separated by spaces, tabs or newlines.
523 assumes that any comment with a dash or star immediately after the start of
524 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
525 Each line of such a comment is left unchanged, except that its indentation
526 may be adjusted to account for the change in indentation of the first line
530 All other comments are treated as straight text.
533 utility fits as many words (separated by blanks, tabs, or newlines) on a
535 Blank lines break paragraphs.
536 .Ss Comment indentation
537 If a comment is on a line with code it is started in the `comment column',
540 command line parameter.
541 Otherwise, the comment is started at
543 indentation levels less than where code is currently being placed, where
547 command line parameter.
548 If the code on a line extends past the comment
549 column, the comment starts further to the right, and the right margin may be
550 automatically extended in extreme cases.
551 .Ss Preprocessor lines
554 leaves preprocessor lines alone.
556 reformatting that it will do is to straighten up trailing comments.
558 leaves embedded comments alone.
559 Conditional compilation
560 .Pq Ic #ifdef...#endif
563 attempts to correctly
564 compensate for the syntactic peculiarities introduced.
568 utility understands a substantial amount about the syntax of C, but it
569 has a `forgiving' parser.
570 It attempts to cope with the usual sorts of
571 incomplete and malformed syntax.
572 In particular, the use of macros like:
574 .Dl #define forever for(;;)
582 environment variable.
584 .Bl -tag -width "./.indent.pro" -compact
598 utility has even more switches than
601 A common mistake is to try to indent all the
603 programs in a directory by typing:
607 This is probably a bug, not a feature.