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