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 .\" 4. 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: src/usr.bin/indent/indent.1,v 1.28 2010/03/31 17:05:30 avg Exp $
38 .Nd indent and format C program source
41 .Op Ar input-file Op Ar output-file
94 according to the switches.
95 The switches which can be specified are described below.
96 They may appear before or after the file names.
99 If you only specify an
102 done `in-place', that is, the formatted file is written back into
106 is written in the current directory.
110 .Sq Pa /blah/blah/file ,
111 the backup file is named
118 checks to make sure that it is different from
121 The options listed below control the formatting style imposed by
127 is specified, a blank line is forced after every block of
134 is specified, a blank line is forced after every procedure body.
140 is specified, a blank line is forced before every block comment.
146 is specified, then a newline is forced after each comma in a declaration.
148 turns off this option.
154 lines-up compound statements like this:
155 .Bd -literal -offset indent
164 (the default) makes them look like this:
165 .Bd -literal -offset indent
174 is specified, then a space is inserted after
177 turns off this option.
181 The column in which comments on code start.
184 The column in which comments on declarations start.
185 The default is for these comments to start in the same column as those on code.
187 Enables (disables) the placement of comment delimiters on blank lines.
188 With this option enabled, comments look like this:
189 .Bd -literal -offset indent
195 Rather than like this:
196 .Bd -literal -offset indent
197 /* this is a comment */
200 This only affects block comments, not comments to the right of code.
204 Enables (disables) forcing of `else's to cuddle up to the immediately preceding
209 Sets the continuation indent to be
212 lines will be indented that far from the beginning of the first line of the
214 Parenthesized expressions have extra indentation added to
215 indicate the nesting, unless
217 is in effect or the continuation indent is exactly half of the main indent.
219 defaults to the same value as
222 Causes case labels to be indented
224 tab stops to the right of the containing
228 causes case labels to be indented half a tab stop.
232 Controls the placement of comments which are not to the right of code.
235 means that such comments are placed one indentation level to the left of code.
236 Specifying the default
238 lines-up these comments with the code.
239 See the section on comment indentation below.
241 Specifies the indentation, in character positions,
242 of global variable names and all struct/union member names
243 relative to the beginning of their type declaration.
248 left justifies declarations.
250 indents declarations the same as code.
254 Enables (disables) special
261 will have the same indentation as the preceding
267 Enables (disables) splitting the function declaration and opening brace
272 Enables (disables) the formatting of comments that start in column 1.
273 Often, comments whose leading `/' is in column 1 have been carefully
274 hand formatted by the programmer.
281 Enables (disables) the formatting of block comments (ones that begin
283 Often, block comments have been not so carefully hand formatted by the
284 programmer, but reformatting that would just change the line breaks is not
289 Block comments are then handled like box comments.
293 The number of spaces for one indentation level.
296 Enables (disables) the indentation of parameter declarations from the left
301 Maximum length of an output line.
304 Specifies the indentation, in character positions,
305 of local variable names
306 relative to the beginning of their type declaration.
307 The default is for local variable names to be indented
308 by the same amount as global ones.
310 Lines-up code surrounded by parenthesis in continuation lines.
312 has a left paren which is not closed on that line, then continuation lines
313 will be lined up to start at the character position just after the left
315 For example, here is how a piece of continued code looks with
318 .Bd -literal -offset indent
319 p1 = first_procedure(second_procedure(p2, p3),
320 \ \ third_procedure(p4, p5));
325 in effect (the default) the code looks somewhat clearer:
326 .Bd -literal -offset indent
327 p1\ =\ first_procedure(second_procedure(p2,\ p3),
328 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
331 Inserting two more newlines we get:
332 .Bd -literal -offset indent
333 p1\ =\ first_procedure(second_procedure(p2,
334 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
335 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
336 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
339 Causes the profile files,
342 .Sq Pa ~/.indent.pro ,
347 all procedure calls will have a space inserted between the name and the `('.
353 the names of procedures being defined are placed in
354 column 1 \- their types, if any, will be left on the previous lines.
358 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
365 is specified, indent will swallow optional blank lines.
366 You can use this to get rid of blank lines after declarations.
372 to take its input from stdin and put its output to stdout.
374 Automatically add all identifiers ending in "_t" to the list
376 .It Fl T Ns Ar typename
379 to the list of type keywords.
382 can be specified more than once.
383 You need to specify all the typenames that
384 appear in your program that are defined by
387 harmed if you miss a few, but the program will not be formatted as nicely as
389 This sounds like a painful thing to have to do, but it is really
390 a symptom of a problem in C:
392 causes a syntactic change in the
401 to format the program for processing by
403 It will produce a fancy
404 listing in much the same spirit as
406 If the output file is not specified, the default is standard output,
407 rather than formatting in place.
409 Enables (disables) the use of tab characters in the output.
410 Tabs are assumed to be aligned on columns divisible by 8.
415 turns on `verbose' mode;
418 When in verbose mode,
420 reports when it splits one line of input into two or more lines of output,
421 and gives some size statistics at completion.
426 You may set up your own `profile' of defaults to
428 by creating a file called
430 in your login directory and/or the current directory and including
431 whatever switches you like.
432 A `.indent.pro' in the current directory takes
433 precedence over the one in your login directory.
436 is run and a profile file exists, then it is read to set up the program's
438 Switches on the command line, though, always override profile switches.
439 The switches should be separated by spaces, tabs or newlines.
446 assumes that any comment with a dash or star immediately after the start of
447 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
448 Each line of such a comment is left unchanged, except that its indentation
449 may be adjusted to account for the change in indentation of the first line
453 All other comments are treated as straight text.
456 utility fits as many words (separated by blanks, tabs, or newlines) on a
458 Blank lines break paragraphs.
459 .Ss Comment indentation
460 If a comment is on a line with code it is started in the `comment column',
463 command line parameter.
464 Otherwise, the comment is started at
466 indentation levels less than where code is currently being placed, where
470 command line parameter.
471 If the code on a line extends past the comment
472 column, the comment starts further to the right, and the right margin may be
473 automatically extended in extreme cases.
474 .Ss Preprocessor lines
477 leaves preprocessor lines alone.
478 The only reformatting that it will do is to straighten up trailing comments.
479 It leaves embedded comments alone.
480 Conditional compilation
481 .Pq Ic #ifdef...#endif
484 attempts to correctly
485 compensate for the syntactic peculiarities introduced.
489 utility understands a substantial amount about the syntax of C, but it
490 has a `forgiving' parser.
491 It attempts to cope with the usual sorts of incomplete and misformed syntax.
492 In particular, the use of macros like:
494 .Dl #define forever for(;;)
502 environment variable.
504 .Bl -tag -width ".Pa /usr/share/misc/indent.pro" -compact
509 .It Pa /usr/share/misc/indent.pro
520 utility has even more switches than
523 A common mistake is to try to indent all the
525 programs in a directory by typing:
529 This is probably a bug, not a feature.