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