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.27 2005/07/31 03:30:45 keramida Exp $
36 .\" $DragonFly: src/usr.bin/indent/indent.1,v 1.3 2006/03/26 22:56:57 swildner Exp $
43 .Nd indent and format C program source
46 .Op Ar input-file Op Ar output-file
97 according to the switches.
98 The switches which can be specified are described below.
99 They may appear before or after the file names.
102 If you only specify an
105 done `in-place', that is, the formatted file is written back into
109 is written in the current directory.
113 .Sq Pa /blah/blah/file ,
114 the backup file is named
121 checks to make sure that it is different from
124 The options listed below control the formatting style imposed by
130 is specified, a blank line is forced after every block of
137 is specified, a blank line is forced after every procedure body.
143 is specified, a blank line is forced before every block comment.
149 is specified, then a newline is forced after each comma in a declaration.
151 turns off this option.
157 lines-up compound statements like this:
158 .Bd -literal -offset indent
167 (the default) makes them look like this:
168 .Bd -literal -offset indent
175 The column in which comments on code start.
178 The column in which comments on declarations start.
179 The default is for these comments to start in the same column as those on code.
181 Enables (disables) the placement of comment delimiters on blank lines.
182 With this option enabled, comments look like this:
183 .Bd -literal -offset indent
189 Rather than like this:
190 .Bd -literal -offset indent
191 /* this is a comment */
194 This only affects block comments, not comments to the right of code.
198 Enables (disables) forcing of `else's to cuddle up to the immediately preceding
203 Sets the continuation indent to be
206 lines will be indented that far from the beginning of the first line of the
208 Parenthesized expressions have extra indentation added to
209 indicate the nesting, unless
211 is in effect or the continuation indent is exactly half of the main indent.
213 defaults to the same value as
216 Causes case labels to be indented
218 tab stops to the right of the containing
222 causes case labels to be indented half a tab stop.
226 Controls the placement of comments which are not to the right of code.
229 means that such comments are placed one indentation level to the left of code.
230 Specifying the default
232 lines-up these comments with the code.
233 See the section on comment indentation below.
235 Specifies the indentation, in character positions,
236 of global variable names and all struct/union member names
237 relative to the beginning of their type declaration.
242 left justifies declarations.
244 indents declarations the same as code.
248 Enables (disables) special
255 will have the same indentation as the preceding
261 Enables (disables) splitting the function declaration and opening brace
266 Enables (disables) the formatting of comments that start in column 1.
267 Often, comments whose leading `/' is in column 1 have been carefully
268 hand formatted by the programmer.
275 Enables (disables) the formatting of block comments (ones that begin
277 Often, block comments have been not so carefully hand formatted by the
278 programmer, but reformatting that would just change the line breaks is not
283 Block comments are then handled like box comments.
287 The number of spaces for one indentation level.
290 Enables (disables) the indentation of parameter declarations from the left
295 Maximum length of an output line.
298 Specifies the indentation, in character positions,
299 of local variable names
300 relative to the beginning of their type declaration.
301 The default is for local variable names to be indented
302 by the same amount as global ones.
304 Lines-up code surrounded by parenthesis in continuation lines.
306 has a left paren which is not closed on that line, then continuation lines
307 will be lined up to start at the character position just after the left
309 For example, here is how a piece of continued code looks with
312 .Bd -literal -offset indent
313 p1 = first_procedure(second_procedure(p2, p3),
314 \ \ third_procedure(p4, p5));
319 in effect (the default) the code looks somewhat clearer:
320 .Bd -literal -offset indent
321 p1\ =\ first_procedure(second_procedure(p2,\ p3),
322 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
325 Inserting two more newlines we get:
326 .Bd -literal -offset indent
327 p1\ =\ first_procedure(second_procedure(p2,
328 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
329 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
330 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
333 Causes the profile files,
336 .Sq Pa ~/.indent.pro ,
341 all procedure calls will have a space inserted between the name and the `('.
347 the names of procedures being defined are placed in
348 column 1 \- their types, if any, will be left on the previous lines.
352 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
359 is specified, indent will swallow optional blank lines.
360 You can use this to get rid of blank lines after declarations.
366 to take its input from stdin and put its output to stdout.
367 .It Fl T Ns Ar typename
370 to the list of type keywords.
373 can be specified more than once.
374 You need to specify all the typenames that
375 appear in your program that are defined by
378 harmed if you miss a few, but the program will not be formatted as nicely as
380 This sounds like a painful thing to have to do, but it is really
381 a symptom of a problem in C:
383 causes a syntactic change in the
392 to format the program for processing by
394 It will produce a fancy
395 listing in much the same spirit as
397 If the output file is not specified, the default is standard output,
398 rather than formatting in place.
400 Enables (disables) the use of tab characters in the output.
401 Tabs are assumed to be aligned on columns divisible by 8.
406 turns on `verbose' mode;
409 When in verbose mode,
411 reports when it splits one line of input into two or more lines of output,
412 and gives some size statistics at completion.
417 You may set up your own `profile' of defaults to
419 by creating a file called
421 in your login directory and/or the current directory and including
422 whatever switches you like.
423 A `.indent.pro' in the current directory takes
424 precedence over the one in your login directory.
427 is run and a profile file exists, then it is read to set up the program's
429 Switches on the command line, though, always override profile switches.
430 The switches should be separated by spaces, tabs or newlines.
437 assumes that any comment with a dash or star immediately after the start of
438 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
439 Each line of such a comment is left unchanged, except that its indentation
440 may be adjusted to account for the change in indentation of the first line
444 All other comments are treated as straight text.
447 utility fits as many words (separated by blanks, tabs, or newlines) on a
449 Blank lines break paragraphs.
450 .Ss Comment indentation
451 If a comment is on a line with code it is started in the `comment column',
454 command line parameter.
455 Otherwise, the comment is started at
457 indentation levels less than where code is currently being placed, where
461 command line parameter.
462 If the code on a line extends past the comment
463 column, the comment starts further to the right, and the right margin may be
464 automatically extended in extreme cases.
465 .Ss Preprocessor lines
468 leaves preprocessor lines alone.
469 The only reformatting that it will do is to straighten up trailing comments.
470 It leaves embedded comments alone.
471 Conditional compilation
472 .Pq Ic #ifdef...#endif
475 attempts to correctly
476 compensate for the syntactic peculiarities introduced.
480 utility understands a substantial amount about the syntax of C, but it
481 has a `forgiving' parser.
482 It attempts to cope with the usual sorts of incomplete and misformed syntax.
483 In particular, the use of macros like:
485 .Dl #define forever for(;;)
493 environment variable.
495 .Bl -tag -width "./.indent.pro" -compact
509 utility has even more switches than
512 A common mistake is to try to indent all the
514 programs in a directory by typing:
518 This is probably a bug, not a feature.