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
31 .\" $FreeBSD: head/usr.bin/indent/indent.1 334944 2018-06-11 05:35:57Z pstef $
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 specified are described below.
106 They may appear before or after the file names.
109 If you only specify an
112 done `in-place', that is, the formatted file is written back into
116 is written in the current directory.
120 .Sq Pa /blah/blah/file ,
121 the backup file is named
123 by default. The extension used for the backup file may be overridden using the
124 .Ev SIMPLE_BACKUP_SUFFIX
125 environment variable.
131 checks to make sure that it is different from
134 The options listed below control the formatting style imposed by
140 is specified, a blank line is forced around every conditional
142 For example, in front of every #ifdef and after every #endif.
143 Other blank lines surrounding such blocks will be swallowed.
149 is specified, a blank line is forced after every block of
154 This is vaguely similar to
156 except that it only applies to the first set of declarations
157 in a procedure (just after the first `{') and it causes a blank
158 line to be generated even if there are no declarations.
164 is specified, a blank line is forced after every procedure body.
170 is specified, a blank line is forced before every block comment.
176 is specified, then a newline is forced after each comma in a declaration.
178 turns off this option.
184 lines up compound statements like this:
185 .Bd -literal -offset indent
194 (the default) makes them look like this:
195 .Bd -literal -offset indent
201 Whether a blank should always be inserted after sizeof.
205 The column in which comments on code start.
208 The column in which comments on declarations start.
209 The default is for these comments to start in the same column as those on code.
211 Enables (disables) the placement of comment delimiters on blank lines.
212 With this option enabled, comments look like this:
213 .Bd -literal -offset indent
219 Rather than like this:
220 .Bd -literal -offset indent
221 /* this is a comment */
224 This only affects block comments, not comments to the right of code.
228 Enables (disables) forcing of `else's to cuddle up to the immediately preceding
233 Sets the continuation indent to be
236 lines will be indented that far from the beginning of the first line of the
238 Parenthesized expressions have extra indentation added to
239 indicate the nesting, unless
241 is in effect or the continuation indent is exactly half of the main indent.
243 defaults to the same value as
246 Causes case labels to be indented
248 tab stops to the right of the containing
252 causes case labels to be indented half a tab stop.
256 Control whether parenthesized type names in casts are followed by a space or
261 Controls the placement of comments which are not to the right of code.
264 means that such comments are placed one indentation level to the left of code.
265 Specifying the default
267 lines up these comments with the code.
268 See the section on comment indentation below.
270 Specifies the indentation, in character positions,
271 of global variable names and all struct/union member names
272 relative to the beginning of their type declaration.
277 left justifies declarations.
279 indents declarations the same as code.
283 Enables (disables) special
290 will have the same indentation as the preceding
296 Enables (disables) extra indentation on continuation lines of
297 the expression part of
302 These continuation lines will be indented one extra level.
306 Enables (disables) splitting the function declaration and opening brace
311 Enables (disables) the formatting of comments that start in column 1.
312 Often, comments whose leading `/' is in column 1 have been carefully
313 hand formatted by the programmer.
320 Enables (disables) the formatting of block comments (ones that begin
322 Often, block comments have been not so carefully hand formatted by the
323 programmer, but reformatting that would just change the line breaks is not
328 Block comments are then handled like box comments.
332 The number of columns for one indentation level.
335 Enables (disables) the indentation of parameter declarations from the left
340 Maximum length of an output line.
343 Maximum length of an output line in a block comment.
344 The default is 0, which means to limit block comment lines in accordance with
347 Specifies the indentation, in character positions,
348 of local variable names
349 relative to the beginning of their type declaration.
350 The default is for local variable names to be indented
351 by the same amount as global ones.
353 Lines up code surrounded by parentheses in continuation lines.
357 has a left paren which is not closed on that line, then continuation lines
358 will be lined up to start at the character position just after the left
360 For example, here is how a piece of continued code looks with
363 .Bd -literal -offset indent
364 p1 = first_procedure(second_procedure(p2, p3),
365 \ \ third_procedure(p4, p5));
370 in effect (the default) the code looks somewhat clearer:
371 .Bd -literal -offset indent
372 p1\ =\ first_procedure(second_procedure(p2,\ p3),
373 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
376 Inserting two more newlines we get:
377 .Bd -literal -offset indent
378 p1\ =\ first_procedure(second_procedure(p2,
379 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
380 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
381 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
386 code surrounded by parentheses in continuation lines is lined up even if it
387 would extend past the right margin.
390 (the default), such a line that would extend past the right margin is moved
391 left to keep it within the margin, if that does not require placing it to
392 the left of the prevailing indentation level.
393 These switches have no effect if
397 Causes the profile files,
400 .Sq Pa ~/.indent.pro ,
408 all procedure calls will have a space inserted between the name and the `('.
414 the names of procedures being defined are placed in
415 column 1 \- their types, if any, will be left on the previous lines.
419 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
426 is specified, indent will swallow optional blank lines.
427 You can use this to get rid of blank lines after declarations.
433 to take its input from stdin and put its output to stdout.
435 Automatically add all identifiers ending in "_t" to the list
437 .It Fl T Ns Ar typename
440 to the list of type keywords.
443 can be specified more than once.
444 You need to specify all the typenames that
445 appear in your program that are defined by
448 harmed if you miss a few, but the program will not be formatted as nicely as
450 This sounds like a painful thing to have to do, but it is really
451 a symptom of a problem in C:
453 causes a syntactic change in the
460 Assumed distance between tab stops.
465 to the list of type keywords.
467 Enables (disables) the use of tab characters in the output.
472 turns on `verbose' mode;
475 When in verbose mode,
477 reports when it splits one line of input into two or more lines of output,
478 and gives some size statistics at completion.
484 to print its version number and exit.
487 You may set up your own `profile' of defaults to
489 by creating a file called
491 in your login directory and/or the current directory and including
492 whatever switches you like.
493 A `.indent.pro' in the current directory takes
494 precedence over the one in your login directory.
497 is run and a profile file exists, then it is read to set up the program's
499 Switches on the command line, though, always override profile switches.
500 The switches should be separated by spaces, tabs or newlines.
507 assumes that any comment with a dash or star immediately after the start of
508 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
509 Each line of such a comment is left unchanged, except that its indentation
510 may be adjusted to account for the change in indentation of the first line
514 All other comments are treated as straight text.
517 utility fits as many words (separated by blanks, tabs, or newlines) on a
519 Blank lines break paragraphs.
520 .Ss Comment indentation
521 If a comment is on a line with code it is started in the `comment column',
524 command line parameter.
525 Otherwise, the comment is started at
527 indentation levels less than where code is currently being placed, where
531 command line parameter.
532 If the code on a line extends past the comment
533 column, the comment starts further to the right, and the right margin may be
534 automatically extended in extreme cases.
535 .Ss Preprocessor lines
538 leaves preprocessor lines alone.
539 The only reformatting that it will do is to straighten up trailing comments.
540 It leaves embedded comments alone.
541 Conditional compilation
542 .Pq Ic #ifdef...#endif
545 attempts to correctly
546 compensate for the syntactic peculiarities introduced.
550 utility understands a substantial amount about the syntax of C, but it
551 has a `forgiving' parser.
552 It attempts to cope with the usual sorts of incomplete and malformed syntax.
553 In particular, the use of macros like:
555 .Dl #define forever for(;;)
563 environment variable.
565 .Bl -tag -width ".Pa /usr/share/misc/indent.pro" -compact
570 .It Pa /usr/share/misc/indent.pro
581 utility has even more switches than
584 A common mistake is to try to indent all the
586 programs in a directory by typing:
590 This is probably a bug, not a feature.