]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/indent/indent.1
Update mandoc to 1.13.1
[FreeBSD/FreeBSD.git] / usr.bin / indent / indent.1
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.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
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.
17 .\"
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
28 .\" SUCH DAMAGE.
29 .\"
30 .\"     @(#)indent.1    8.1 (Berkeley) 7/1/93
31 .\" $FreeBSD$
32 .\"
33 .Dd March 3, 2012
34 .Dt INDENT 1
35 .Os
36 .Sh NAME
37 .Nm indent
38 .Nd indent and format C program source
39 .Sh SYNOPSIS
40 .Nm
41 .Op Ar input-file Op Ar output-file
42 .Op Fl bacc | Fl nbacc
43 .Op Fl bad | Fl nbad
44 .Op Fl bap | Fl nbap
45 .Bk -words
46 .Op Fl ei | Fl ei
47 .Op Fl eei | Fl eei
48 .Op Fl bbb | Fl nbbb
49 .Ek
50 .Op Fl \&bc | Fl nbc
51 .Op Fl \&bl
52 .Op Fl \&br
53 .Op Fl c Ns Ar n
54 .Op Fl \&cd Ns Ar n
55 .Bk -words
56 .Op Fl cdb | Fl ncdb
57 .Ek
58 .Op Fl \&ce | Fl nce
59 .Op Fl \&ci Ns Ar n
60 .Op Fl cli Ns Ar n
61 .Op Fl d Ns Ar n
62 .Op Fl \&di Ns Ar n
63 .Bk -words
64 .Op Fl fbs | Fl nfbs
65 .Op Fl fc1 | Fl nfc1
66 .Op Fl fcb | Fl nfcb
67 .Ek
68 .Op Fl i Ns Ar n
69 .Op Fl \&ip | Fl nip
70 .Op Fl l Ns Ar n
71 .Op Fl \&lc Ns Ar n
72 .Op Fl \&ldi Ns Ar n
73 .Op Fl \&lp | Fl nlp
74 .Op Fl npro
75 .Op Fl pcs | Fl npcs
76 .Op Fl psl | Fl npsl
77 .Op Fl \&sc | Fl nsc
78 .Bk -words
79 .Op Fl sob | Fl nsob
80 .Ek
81 .Op Fl \&st
82 .Op Fl \&ta
83 .Op Fl troff
84 .Op Fl ut | Fl nut
85 .Op Fl v | Fl \&nv
86 .Sh DESCRIPTION
87 The
88 .Nm
89 utility is a
90 .Em C
91 program formatter.
92 It reformats the
93 .Em C
94 program in the
95 .Ar input-file
96 according to the switches.
97 The switches which can be
98 specified are described below.
99 They may appear before or after the file
100 names.
101 .Pp
102 .Sy NOTE :
103 If you only specify an
104 .Ar input-file ,
105 the formatting is
106 done `in-place', that is, the formatted file is written back into
107 .Ar input-file
108 and a backup copy of
109 .Ar input-file
110 is written in the current directory.
111 If
112 .Ar input-file
113 is named
114 .Sq Pa /blah/blah/file ,
115 the backup file is named
116 .Sq Pa file.BAK .
117 .Pp
118 If
119 .Ar output-file
120 is specified,
121 .Nm
122 checks to make sure that it is different from
123 .Ar input-file .
124 .Pp
125 The options listed below control the formatting style imposed by
126 .Nm .
127 .Bl -tag -width Op
128 .It Fl bacc , nbacc
129 If
130 .Fl bacc
131 is specified, a blank line is forced around every conditional
132 compilation block.
133 For example, in front of every #ifdef and after every #endif.
134 Other blank lines surrounding such blocks will be swallowed.
135 Default:
136 .Fl nbacc  .
137 .It Fl bad , nbad
138 If
139 .Fl bad
140 is specified, a blank line is forced after every block of
141 declarations.
142 Default:
143 .Fl nbad .
144 .It Fl bap , nbap
145 If
146 .Fl bap
147 is specified, a blank line is forced after every procedure body.
148 Default:
149 .Fl nbap .
150 .It Fl bbb , nbbb
151 If
152 .Fl bbb
153 is specified, a blank line is forced before every block comment.
154 Default:
155 .Fl nbbb .
156 .It Fl \&bc , nbc
157 If
158 .Fl \&bc
159 is specified, then a newline is forced after each comma in a declaration.
160 .Fl nbc
161 turns off this option.
162 Default:
163 .Fl \&nbc .
164 .It Fl \&br , \&bl
165 Specifying
166 .Fl \&bl
167 lines-up compound statements like this:
168 .Bd -literal -offset indent
169 if (...)
170 {
171   code
172 }
173 .Ed
174 .Pp
175 Specifying
176 .Fl \&br
177 (the default) makes them look like this:
178 .Bd -literal -offset indent
179 if (...) {
180   code
181 }
182 .Ed
183 .It Fl c Ns Ar n
184 The column in which comments on code start.
185 The default is 33.
186 .It Fl cd Ns Ar n
187 The column in which comments on declarations start.
188 The default
189 is for these comments to start in the same column as those on code.
190 .It Fl cdb , ncdb
191 Enables (disables) the placement of comment delimiters on blank lines.
192 With
193 this option enabled, comments look like this:
194 .Bd -literal -offset indent
195         /*
196          * this is a comment
197          */
198 .Ed
199 .Pp
200 Rather than like this:
201 .Bd -literal -offset indent
202         /* this is a comment */
203 .Ed
204 .Pp
205 This only affects block comments, not comments to the right of
206 code.
207 The default is
208 .Fl cdb .
209 .It Fl ce , nce
210 Enables (disables) forcing of `else's to cuddle up to the immediately preceding
211 `}'.
212 The default is
213 .Fl \&ce .
214 .It Fl \&ci Ns Ar n
215 Sets the continuation indent to be
216 .Ar n .
217 Continuation
218 lines will be indented that far from the beginning of the first line of the
219 statement.
220 Parenthesized expressions have extra indentation added to
221 indicate the nesting, unless
222 .Fl \&lp
223 is in effect
224 or the continuation indent is exactly half of the main indent.
225 .Fl \&ci
226 defaults to the same value as
227 .Fl i .
228 .It Fl cli Ns Ar n
229 Causes case labels to be indented
230 .Ar n
231 tab stops to the right of the containing
232 .Ic switch
233 statement.
234 .Fl cli0.5
235 causes case labels to be indented half a tab stop.
236 The
237 default is
238 .Fl cli0 .
239 .It Fl d Ns Ar n
240 Controls the placement of comments which are not to the
241 right of code.
242 For example,
243 .Fl \&d\&1
244 means that such comments are placed one indentation level to the
245 left of code.
246 Specifying the default
247 .Fl \&d\&0
248 lines-up these comments with the code.
249 See the section on comment
250 indentation below.
251 .It Fl \&di Ns Ar n
252 Specifies the indentation, in character positions,
253 of global variable names and all struct/union member names
254 relative to the beginning of their type declaration.
255 The default is
256 .Fl di16 .
257 .It Fl dj , ndj
258 .Fl \&dj
259 left justifies declarations.
260 .Fl ndj
261 indents declarations the same as code.
262 The default is
263 .Fl ndj .
264 .It Fl \&ei , nei
265 Enables (disables) special
266 .Ic else-if
267 processing.
268 If it is enabled, an
269 .Ic if
270 following an
271 .Ic else
272 will have the same indentation as the preceding
273 .Ic \&if
274 statement.
275 The default is
276 .Fl ei .
277 .It Fl eei , neei
278 Enables (disables) extra indentation on continuation lines of
279 the expression part of
280 .Ic if
281 and
282 .Ic while
283 statements.
284 These continuation lines will be indented one extra level.
285 The default is
286 .Fl neei .
287 .It Fl fbs , nfbs
288 Enables (disables) splitting the function declaration and opening brace
289 across two lines.
290 The default is
291 .Fl fbs .
292 .It Fl fc1 , nfc1
293 Enables (disables) the formatting of comments that start in column 1.
294 Often, comments whose leading `/' is in column 1 have been carefully
295 hand formatted by the programmer.
296 In such cases,
297 .Fl nfc1
298 should be
299 used.
300 The default is
301 .Fl fc1 .
302 .It Fl fcb , nfcb
303 Enables (disables) the formatting of block comments (ones that begin
304 with `/*\\n').
305 Often, block comments have been not so carefully hand formatted by the
306 programmer, but reformatting that would just change the line breaks is not
307 wanted.
308 In such cases,
309 .Fl nfcb
310 should be used.
311 Block comments are then handled like box comments.
312 The default is
313 .Fl fcb .
314 .It Fl i Ns Ar n
315 The number of spaces for one indentation level.
316 The default is 8.
317 .It Fl \&ip , nip
318 Enables (disables) the indentation of parameter declarations from the left
319 margin.
320 The default is
321 .Fl \&ip .
322 .It Fl l Ns Ar n
323 Maximum length of an output line.
324 The default is 78.
325 .It Fl \&ldi Ns Ar n
326 Specifies the indentation, in character positions,
327 of local variable names
328 relative to the beginning of their type declaration.
329 The default is for local variable names to be indented
330 by the same amount as global ones.
331 .It Fl \&lp , nlp
332 Lines-up code surrounded by parenthesis in continuation lines.
333 If a line
334 has a left paren which is not closed on that line, then continuation lines
335 will be lined up to start at the character position just after the left
336 paren.
337 For example, here is how a piece of continued code looks with
338 .Fl nlp
339 in effect:
340 .Bd -literal -offset indent
341 p1 = first_procedure(second_procedure(p2, p3),
342 \ \ third_procedure(p4, p5));
343 .Ed
344 .Pp
345 With
346 .Fl lp
347 in effect (the default) the code looks somewhat clearer:
348 .Bd -literal -offset indent
349 p1\ =\ first_procedure(second_procedure(p2,\ p3),
350 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,\ p5));
351 .Ed
352 .Pp
353 Inserting two more newlines we get:
354 .Bd -literal -offset indent
355 p1\ =\ first_procedure(second_procedure(p2,
356 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p3),
357 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ third_procedure(p4,
358 \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ p5));
359 .Ed
360 .It Fl npro
361 Causes the profile files,
362 .Sq Pa ./.indent.pro
363 and
364 .Sq Pa ~/.indent.pro ,
365 to be ignored.
366 .It Fl pcs , npcs
367 If true
368 .Pq Fl pcs
369 all procedure calls will have a space inserted between
370 the name and the `('.
371 The default is
372 .Fl npcs .
373 .It Fl psl , npsl
374 If true
375 .Pq Fl psl
376 the names of procedures being defined are placed in
377 column 1 \- their types, if any, will be left on the previous lines.
378 The
379 default is
380 .Fl psl .
381 .It Fl \&sc , nsc
382 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
383 comments.
384 The default is
385 .Fl sc .
386 .It Fl sob , nsob
387 If
388 .Fl sob
389 is specified, indent will swallow optional blank lines.
390 You can use this to
391 get rid of blank lines after declarations.
392 Default:
393 .Fl nsob .
394 .It Fl \&st
395 Causes
396 .Nm
397 to take its input from stdin and put its output to stdout.
398 .It Fl ta
399 Automatically add all identifiers ending in "_t" to the list
400 of type keywords.
401 .It Fl T Ns Ar typename
402 Adds
403 .Ar typename
404 to the list of type keywords.
405 Names accumulate:
406 .Fl T
407 can be specified more than once.
408 You need to specify all the typenames that
409 appear in your program that are defined by
410 .Ic typedef
411 \- nothing will be
412 harmed if you miss a few, but the program will not be formatted as nicely as
413 it should.
414 This sounds like a painful thing to have to do, but it is really
415 a symptom of a problem in C:
416 .Ic typedef
417 causes a syntactic change in the
418 language and
419 .Nm
420 cannot find all
421 instances of
422 .Ic typedef .
423 .It Fl troff
424 Causes
425 .Nm
426 to format the program for processing by
427 .Xr troff 1 .
428 It will produce a fancy
429 listing in much the same spirit as
430 .Xr vgrind 1 .
431 If the output file is not specified, the default is standard output,
432 rather than formatting in place.
433 .It Fl ut , nut
434 Enables (disables) the use of tab characters in the output.
435 Tabs are assumed to be aligned on columns divisible by 8.
436 The default is
437 .Fl ut .
438 .It Fl v , \&nv
439 .Fl v
440 turns on `verbose' mode;
441 .Fl \&nv
442 turns it off.
443 When in verbose mode,
444 .Nm
445 reports when it splits one line of input into two or more lines of output,
446 and gives some size statistics at completion.
447 The default is
448 .Fl \&nv .
449 .El
450 .Pp
451 You may set up your own `profile' of defaults to
452 .Nm
453 by creating a file called
454 .Pa .indent.pro
455 in your login directory and/or the current directory and including
456 whatever switches you like.
457 A `.indent.pro' in the current directory takes
458 precedence over the one in your login directory.
459 If
460 .Nm
461 is run and a profile file exists, then it is read to set up the program's
462 defaults.
463 Switches on the command line, though, always override profile
464 switches.
465 The switches should be separated by spaces, tabs or newlines.
466 .Pp
467 .Ss Comments
468 .Sq Em Box
469 .Em comments .
470 The
471 .Nm
472 utility
473 assumes that any comment with a dash or star immediately after the start of
474 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
475 Each line of such a comment is left unchanged, except that its indentation
476 may be adjusted to account for the change in indentation of the first line
477 of the comment.
478 .Pp
479 .Em Straight text .
480 All other comments are treated as straight text.
481 The
482 .Nm
483 utility fits as many words (separated by blanks, tabs, or newlines) on a
484 line as possible.
485 Blank lines break paragraphs.
486 .Ss Comment indentation
487 If a comment is on a line with code it is started in the `comment column',
488 which is set by the
489 .Fl c Ns Ns Ar n
490 command line parameter.
491 Otherwise, the comment is started at
492 .Ar n
493 indentation levels less than where code is currently being placed, where
494 .Ar n
495 is specified by the
496 .Fl d Ns Ns Ar n
497 command line parameter.
498 If the code on a line extends past the comment
499 column, the comment starts further to the right, and the right margin may be
500 automatically extended in extreme cases.
501 .Ss Preprocessor lines
502 In general,
503 .Nm
504 leaves preprocessor lines alone.
505 The only
506 reformatting that it will do is to straighten up trailing comments.
507 It
508 leaves embedded comments alone.
509 Conditional compilation
510 .Pq Ic #ifdef...#endif
511 is recognized and
512 .Nm
513 attempts to correctly
514 compensate for the syntactic peculiarities introduced.
515 .Ss C syntax
516 The
517 .Nm
518 utility understands a substantial amount about the syntax of C, but it
519 has a `forgiving' parser.
520 It attempts to cope with the usual sorts of
521 incomplete and misformed syntax.
522 In particular, the use of macros like:
523 .Pp
524 .Dl #define forever for(;;)
525 .Pp
526 is handled properly.
527 .Sh ENVIRONMENT
528 The
529 .Nm
530 utility uses the
531 .Ev HOME
532 environment variable.
533 .Sh FILES
534 .Bl -tag -width "./.indent.pro" -compact
535 .It Pa ./.indent.pro
536 profile file
537 .It Pa ~/.indent.pro
538 profile file
539 .El
540 .Sh HISTORY
541 The
542 .Nm
543 command appeared in
544 .Bx 4.2 .
545 .Sh BUGS
546 The
547 .Nm
548 utility has even more switches than
549 .Xr ls 1 .
550 .Pp
551 A common mistake is to try to indent all the
552 .Em C
553 programs in a directory by typing:
554 .Pp
555 .Dl indent *.c
556 .Pp
557 This is probably a bug, not a feature.