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