1 .\" $NetBSD: indent.1,v 1.23 2014/09/04 04:06:07 mrg Exp $
3 .\" Copyright (c) 1980, 1990, 1993
4 .\" The Regents of the University of California. 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 .\" Copyright (c) 1985 Sun Microsystems, Inc.
31 .\" Copyright (c) 1976 Board of Trustees of the University of Illinois.
32 .\" All rights reserved.
34 .\" Redistribution and use in source and binary forms, with or without
35 .\" modification, are permitted provided that the following conditions
37 .\" 1. Redistributions of source code must retain the above copyright
38 .\" notice, this list of conditions and the following disclaimer.
39 .\" 2. Redistributions in binary form must reproduce the above copyright
40 .\" notice, this list of conditions and the following disclaimer in the
41 .\" documentation and/or other materials provided with the distribution.
42 .\" 3. All advertising materials mentioning features or use of this software
43 .\" must display the following acknowledgement:
44 .\" This product includes software developed by the University of
45 .\" California, Berkeley and its contributors.
46 .\" 4. Neither the name of the University nor the names of its contributors
47 .\" may be used to endorse or promote products derived from this software
48 .\" without specific prior written permission.
50 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
51 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
53 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
54 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
55 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
56 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
57 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
58 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
59 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 .\" from: @(#)indent.1 8.1 (Berkeley) 7/1/93
69 .Nd indent and format C program source
72 .Op Ar input-file Op Ar output-file
73 .Op Fl bacc | Fl nbacc
112 according to the switches.
113 The switches which can be specified are described below.
114 They may appear before or after the file names.
117 If you only specify an
120 done `in-place', that is, the formatted file is written back into
124 is written in the current directory.
128 .Sq Pa /blah/blah/file ,
129 the backup file is named
136 checks to make sure it is different from
142 input is read from stdin and the formatted file is written to stdout.
144 The options listed below control the formatting style imposed by
150 is specified, a blank line is forced around every conditional
152 For example, in front of every #ifdef and after every #endif.
153 Other blank lines surrounding such blocks will be swallowed.
159 is specified, a blank line is forced after every block of
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
205 is specified, a blank is forced after
210 The column in which comments on code start.
214 The column in which comments on declarations start.
216 is for these comments to start in the same column as those on code.
218 Enables (disables) the placement of comment delimiters on blank lines.
219 With this option enabled, comments look like this:
220 .Bd -literal -offset indent
226 Rather than like this:
227 .Bd -literal -offset indent
228 /* this is a comment */
231 This only affects block comments, not comments to the right of
236 Enables (disables) forcing `else's to cuddle up to the immediately preceding
241 Sets the continuation indent to be
244 lines will be indented that far from the beginning of the first line of the
246 Parenthesized expressions have extra indentation added to
247 indicate the nesting, unless
251 defaults to the same value as
254 Causes case labels to be indented
256 tab stops to the right of the containing
260 causes case labels to be indented half a tab stop.
264 Controls the placement of comments which are not to the right of code.
267 means that such comments are placed one indentation level to the left of code.
268 Specifying the default
270 lines up these comments with the code.
271 See the section on comment
274 Specifies the indentation, in character positions, from a declaration keyword
275 to the following identifier.
280 left justifies declarations.
282 indents declarations the same as code.
286 Enables (disables) special
293 will have the same indentation as the preceding
299 Enables (disables) extra indentation on continuation lines of
300 the expression part of
305 These continuation lines will be indented one extra level.
309 Enables (disables) the formatting of comments that start in column 1.
310 Often, comments whose leading `/' is in column 1 have been carefully
311 hand formatted by the programmer.
318 The number of spaces for one indentation level.
322 Enables (disables) the indentation of parameter declarations from the left
327 Maximum length of an output line.
331 Lines up code surrounded by parenthesis in continuation lines.
332 If a line has a left parenthesis which is not closed on that line, then
333 continuation lines will be lined up to start at the character
334 position just after the left parenthesis.
335 For example, here is how a piece of continued code looks with
338 .Bd -literal -offset indent
339 p1 = first_procedure(second_procedure(p2, p3),
340 \ \ third_procedure(p4,p5));
345 in effect (the default) the code looks somewhat clearer:
346 .Bd -literal -offset indent
347 p1\ =\ first_procedure(second_procedure(p2,\ p3),
348 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,p5));
351 Inserting two more newlines we get:
352 .Bd -literal -offset indent
353 p1\ =\ first_procedure(second_procedure(p2,
354 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
355 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4
356 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
359 Causes the profile files,
362 .Sq Pa ~/.indent.pro ,
367 all procedure calls will have a space inserted between
368 the name and the `('.
374 the names of procedures being defined are placed in
375 column 1 \- their types, if any, will be left on the previous lines.
379 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
386 is specified, indent will swallow optional blank lines.
387 You can use this to get rid of blank lines after declarations.
393 to take its input from stdin, and put its output to stdout.
394 .It Fl T Ns Ar typename
397 to the list of type keywords.
400 can be specified more than once.
401 You need to specify all the typenames that
402 appear in your program that are defined by
405 harmed if you miss a few, but the program won't be formatted as nicely as
407 This sounds like a painful thing to have to do, but it's really
408 a symptom of a problem in C:
410 causes a syntactic change in the
419 to format the program for processing by
421 It will produce a fancy
422 listing in much the same spirit as
424 If the output file is not specified, the default is standard output,
425 rather than formatting in place.
427 Enables (disables) the use of tab characters in the output.
428 Tabs are assumed to be aligned on columns divisible by 8.
433 turns on `verbose' mode;
436 When in verbose mode,
438 reports when it splits one line of input into two or more lines of output,
439 and gives some size statistics at completion.
444 You may set up your own `profile' of defaults to
446 by creating a file called
448 in your login directory and/or the current directory and including
449 whatever switches you like.
450 A `.indent.pro' in the current directory takes
451 precedence over the one in your login directory.
454 is run and a profile file exists, then it is read to set up the program's
456 Switches on the command line, though, always override profile switches.
457 The switches should be separated by spaces, tabs or newlines.
462 assumes that any comment with a dash or star immediately after the start of
463 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
464 Each line of such a comment is left unchanged, except that its indentation
465 may be adjusted to account for the change in indentation of the first line
469 All other comments are treated as straight text.
471 fits as many words (separated by blanks, tabs, or newlines) on a
473 Blank lines break paragraphs.
474 .Ss Comment indentation
475 If a comment is on a line with code it is started in the `comment column',
478 command line parameter.
479 Otherwise, the comment is started at
481 indentation levels less than where code is currently being placed, where
485 command line parameter.
486 If the code on a line extends past the comment
487 column, the comment starts further to the right, and the right margin may be
488 automatically extended in extreme cases.
489 .Ss Preprocessor lines
492 leaves preprocessor lines alone.
493 The only reformatting that it will do is to straighten up trailing comments.
494 It leaves embedded comments alone.
495 Conditional compilation
496 .Pq Ic #ifdef...#endif
499 attempts to correctly
500 compensate for the syntactic peculiarities introduced.
503 understands a substantial amount about the syntax of C, but it
504 has a `forgiving' parser.
505 It attempts to cope with the usual sorts of incomplete and misformed syntax.
506 In particular, the use of macros like:
508 .Dl #define forever for(;;)
515 environment variable.
517 .Bl -tag -width "./.indent.pro" -compact
530 has even more switches than
533 A common mistake that often causes grief is typing:
537 to the shell in an attempt to indent all the
539 programs in a directory.
540 This is probably a bug, not a feature.