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
98 according to the switches.
99 The switches which can be
100 specified are described below.
101 They may appear before or after the file
105 If you only specify an
108 done `in-place', that is, the formatted file is written back into
112 is written in the current directory.
116 .Sq Pa /blah/blah/file ,
117 the backup file is named
124 checks to make sure that it is different from
127 The options listed below control the formatting style imposed by
133 is specified, a blank line is forced around every conditional
135 For example, in front of every #ifdef and after every #endif.
136 Other blank lines surrounding such blocks will be swallowed.
142 is specified, a blank line is forced after every block of
149 is specified, a blank line is forced after every procedure body.
155 is specified, a blank line is forced before every block comment.
161 is specified, then a newline is forced after each comma in a declaration.
163 turns off this option.
169 lines-up compound statements like this:
170 .Bd -literal -offset indent
179 (the default) makes them look like this:
180 .Bd -literal -offset indent
186 The column in which comments on code start.
189 The column in which comments on declarations start.
191 is for these comments to start in the same column as those on code.
193 Enables (disables) the placement of comment delimiters on blank lines.
195 this option enabled, comments look like this:
196 .Bd -literal -offset indent
202 Rather than like this:
203 .Bd -literal -offset indent
204 /* this is a comment */
207 This only affects block comments, not comments to the right of
212 Enables (disables) forcing of `else's to cuddle up to the immediately preceding
217 Sets the continuation indent to be
220 lines will be indented that far from the beginning of the first line of the
222 Parenthesized expressions have extra indentation added to
223 indicate the nesting, unless
226 or the continuation indent is exactly half of the main indent.
228 defaults to the same value as
231 Causes case labels to be indented
233 tab stops to the right of the containing
237 causes case labels to be indented half a tab stop.
242 Controls the placement of comments which are not to the
246 means that such comments are placed one indentation level to the
248 Specifying the default
250 lines-up these comments with the code.
251 See the section on comment
254 Specifies the indentation, in character positions,
255 of global variable names and all struct/union member names
256 relative to the beginning of their type declaration.
261 left justifies declarations.
263 indents declarations the same as code.
267 Enables (disables) special
274 will have the same indentation as the preceding
280 Enables (disables) extra indentation on continuation lines of
281 the expression part of
286 These continuation lines will be indented one extra level.
290 Enables (disables) splitting the function declaration and opening brace
295 Enables (disables) the formatting of comments that start in column 1.
296 Often, comments whose leading `/' is in column 1 have been carefully
297 hand formatted by the programmer.
305 Enables (disables) the formatting of block comments (ones that begin
307 Often, block comments have been not so carefully hand formatted by the
308 programmer, but reformatting that would just change the line breaks is not
313 Block comments are then handled like box comments.
317 The number of spaces for one indentation level.
320 Enables (disables) the indentation of parameter declarations from the left
325 Maximum length of an output line.
328 Specifies the indentation, in character positions,
329 of local variable names
330 relative to the beginning of their type declaration.
331 The default is for local variable names to be indented
332 by the same amount as global ones.
334 Lines-up code surrounded by parenthesis in continuation lines.
336 has a left paren which is not closed on that line, then continuation lines
337 will be lined up to start at the character position just after the left
339 For example, here is how a piece of continued code looks with
342 .Bd -literal -offset indent
343 p1 = first_procedure(second_procedure(p2, p3),
344 \ \ third_procedure(p4, p5));
349 in effect (the default) the code looks somewhat clearer:
350 .Bd -literal -offset indent
351 p1\ =\ first_procedure(second_procedure(p2,\ p3),
352 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
355 Inserting two more newlines we get:
356 .Bd -literal -offset indent
357 p1\ =\ first_procedure(second_procedure(p2,
358 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
359 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
360 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
363 Causes the profile files,
366 .Sq Pa ~/.indent.pro ,
371 all procedure calls will have a space inserted between
372 the name and the `('.
378 the names of procedures being defined are placed in
379 column 1 \- their types, if any, will be left on the previous lines.
384 Control whether parenthesized type names in casts are followed by a space or
389 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
396 is specified, indent will swallow optional blank lines.
398 get rid of blank lines after declarations.
404 to take its input from stdin and put its output to stdout.
406 Automatically add all identifiers ending in "_t" to the list
408 .It Fl T Ns Ar typename
411 to the list of type keywords.
414 can be specified more than once.
415 You need to specify all the typenames that
416 appear in your program that are defined by
419 harmed if you miss a few, but the program will not be formatted as nicely as
421 This sounds like a painful thing to have to do, but it is really
422 a symptom of a problem in C:
424 causes a syntactic change in the
433 to format the program for processing by
435 It will produce a fancy
436 listing in much the same spirit as
438 If the output file is not specified, the default is standard output,
439 rather than formatting in place.
443 to the list of type keywords.
445 Enables (disables) the use of tab characters in the output.
446 Tabs are assumed to be aligned on columns divisible by 8.
451 turns on `verbose' mode;
454 When in verbose mode,
456 reports when it splits one line of input into two or more lines of output,
457 and gives some size statistics at completion.
462 You may set up your own `profile' of defaults to
464 by creating a file called
466 in your login directory and/or the current directory and including
467 whatever switches you like.
468 A `.indent.pro' in the current directory takes
469 precedence over the one in your login directory.
472 is run and a profile file exists, then it is read to set up the program's
474 Switches on the command line, though, always override profile
476 The switches should be separated by spaces, tabs or newlines.
484 assumes that any comment with a dash or star immediately after the start of
485 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
486 Each line of such a comment is left unchanged, except that its indentation
487 may be adjusted to account for the change in indentation of the first line
491 All other comments are treated as straight text.
494 utility fits as many words (separated by blanks, tabs, or newlines) on a
496 Blank lines break paragraphs.
497 .Ss Comment indentation
498 If a comment is on a line with code it is started in the `comment column',
501 command line parameter.
502 Otherwise, the comment is started at
504 indentation levels less than where code is currently being placed, where
508 command line parameter.
509 If the code on a line extends past the comment
510 column, the comment starts further to the right, and the right margin may be
511 automatically extended in extreme cases.
512 .Ss Preprocessor lines
515 leaves preprocessor lines alone.
517 reformatting that it will do is to straighten up trailing comments.
519 leaves embedded comments alone.
520 Conditional compilation
521 .Pq Ic #ifdef...#endif
524 attempts to correctly
525 compensate for the syntactic peculiarities introduced.
529 utility understands a substantial amount about the syntax of C, but it
530 has a `forgiving' parser.
531 It attempts to cope with the usual sorts of
532 incomplete and malformed syntax.
533 In particular, the use of macros like:
535 .Dl #define forever for(;;)
543 environment variable.
545 .Bl -tag -width "./.indent.pro" -compact
559 utility has even more switches than
562 A common mistake is to try to indent all the
564 programs in a directory by typing:
568 This is probably a bug, not a feature.