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