]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/indent/indent.1
ident(1): Normalizing date format
[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.
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 psl , npsl
425 If true
426 .Pq Fl psl
427 the names of procedures being defined are placed in
428 column 1 \- their types, if any, will be left on the previous lines.
429 The
430 default is
431 .Fl psl .
432 .It Fl \&sc , nsc
433 Enables (disables) the placement of asterisks (`*'s) at the left edge of all
434 comments.
435 The default is
436 .Fl sc .
437 .It Fl sob , nsob
438 If
439 .Fl sob
440 is specified, indent will swallow optional blank lines.
441 You can use this to
442 get rid of blank lines after declarations.
443 Default:
444 .Fl nsob .
445 .It Fl \&st
446 Causes
447 .Nm
448 to take its input from stdin and put its output to stdout.
449 .It Fl ta
450 Automatically add all identifiers ending in "_t" to the list
451 of type keywords.
452 .It Fl T Ns Ar typename
453 Adds
454 .Ar typename
455 to the list of type keywords.
456 Names accumulate:
457 .Fl T
458 can be specified more than once.
459 You need to specify all the typenames that
460 appear in your program that are defined by
461 .Ic typedef
462 \- nothing will be
463 harmed if you miss a few, but the program will not be formatted as nicely as
464 it should.
465 This sounds like a painful thing to have to do, but it is really
466 a symptom of a problem in C:
467 .Ic typedef
468 causes a syntactic change in the
469 language and
470 .Nm
471 cannot find all
472 instances of
473 .Ic typedef .
474 .It Fl ts Ns Ar n
475 Assumed distance between tab stops.
476 The default is 8.
477 .It Fl U Ns Ar file
478 Adds type names from
479 .Ar file
480 to the list of type keywords.
481 .It Fl ut , nut
482 Enables (disables) the use of tab characters in the output.
483 The default is
484 .Fl ut .
485 .It Fl v , \&nv
486 .Fl v
487 turns on `verbose' mode;
488 .Fl \&nv
489 turns it off.
490 When in verbose mode,
491 .Nm
492 reports when it splits one line of input into two or more lines of output,
493 and gives some size statistics at completion.
494 The default is
495 .Fl \&nv .
496 .It Fl -version
497 Causes
498 .Nm
499 to print its version number and exit.
500 .El
501 .Pp
502 You may set up your own `profile' of defaults to
503 .Nm
504 by creating a file called
505 .Pa .indent.pro
506 in your login directory and/or the current directory and including
507 whatever switches you like.
508 A `.indent.pro' in the current directory takes
509 precedence over the one in your login directory.
510 If
511 .Nm
512 is run and a profile file exists, then it is read to set up the program's
513 defaults.
514 Switches on the command line, though, always override profile
515 switches.
516 The switches should be separated by spaces, tabs or newlines.
517 .Pp
518 .Ss Comments
519 .Sq Em Box
520 .Em comments .
521 The
522 .Nm
523 utility
524 assumes that any comment with a dash or star immediately after the start of
525 comment (that is, `/*\-' or `/**') is a comment surrounded by a box of stars.
526 Each line of such a comment is left unchanged, except that its indentation
527 may be adjusted to account for the change in indentation of the first line
528 of the comment.
529 .Pp
530 .Em Straight text .
531 All other comments are treated as straight text.
532 The
533 .Nm
534 utility fits as many words (separated by blanks, tabs, or newlines) on a
535 line as possible.
536 Blank lines break paragraphs.
537 .Ss Comment indentation
538 If a comment is on a line with code it is started in the `comment column',
539 which is set by the
540 .Fl c Ns Ns Ar n
541 command line parameter.
542 Otherwise, the comment is started at
543 .Ar n
544 indentation levels less than where code is currently being placed, where
545 .Ar n
546 is specified by the
547 .Fl d Ns Ns Ar n
548 command line parameter.
549 If the code on a line extends past the comment
550 column, the comment starts further to the right, and the right margin may be
551 automatically extended in extreme cases.
552 .Ss Preprocessor lines
553 In general,
554 .Nm
555 leaves preprocessor lines alone.
556 The only
557 reformatting that it will do is to straighten up trailing comments.
558 It
559 leaves embedded comments alone.
560 Conditional compilation
561 .Pq Ic #ifdef...#endif
562 is recognized and
563 .Nm
564 attempts to correctly
565 compensate for the syntactic peculiarities introduced.
566 .Ss C syntax
567 The
568 .Nm
569 utility understands a substantial amount about the syntax of C, but it
570 has a `forgiving' parser.
571 It attempts to cope with the usual sorts of
572 incomplete and malformed syntax.
573 In particular, the use of macros like:
574 .Pp
575 .Dl #define forever for(;;)
576 .Pp
577 is handled properly.
578 .Sh ENVIRONMENT
579 The
580 .Nm
581 utility uses the
582 .Ev HOME
583 environment variable.
584 .Sh FILES
585 .Bl -tag -width "./.indent.pro" -compact
586 .It Pa ./.indent.pro
587 profile file
588 .It Pa ~/.indent.pro
589 profile file
590 .El
591 .Sh HISTORY
592 The
593 .Nm
594 command appeared in
595 .Bx 4.2 .
596 .Sh BUGS
597 The
598 .Nm
599 utility has even more switches than
600 .Xr ls 1 .
601 .Pp
602 A common mistake is to try to indent all the
603 .Em C
604 programs in a directory by typing:
605 .Pp
606 .Dl indent *.c
607 .Pp
608 This is probably a bug, not a feature.