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