1INDENT(1L) INDENT(1L)
2
3
4
6 indent - changes the appearance of a C program by inserting or deleting
7 whitespace.
8
10 indent [options] [input-files]
11
12 indent [options] [single-input-file] [-o output-file]
13
14 indent --version
15
17 This man page is generated from the file indent.texinfo. This is Edi‐
18 tion of "The indent Manual", for Indent Version , last updated .
19
20 The indent program can be used to make code easier to read. It can
21 also convert from one style of writing C to another.
22
23 indent understands a substantial amount about the syntax of C, but it
24 also attempts to cope with incomplete and misformed syntax.
25
26 In version 1.2 and more recent versions, the GNU style of indenting is
27 the default.
28
30 -bad, --blank-lines-after-declarations
31 Force blank lines after the declarations.
32 See BLANK LINES.
33
34 -bap, --blank-lines-after-procedures
35 Force blank lines after procedure bodies.
36 See BLANK LINES.
37
38 -bbb, --blank-lines-before-block-comments
39 Force blank lines before block comments.
40 See BLANK LINES.
41
42 -bbo, --break-before-boolean-operator
43 Prefer to break long lines before boolean operators.
44 See BREAKING LONG LINES.
45
46 -bc, --blank-lines-after-commas
47 Force newline after comma in declaration.
48 See DECLARATIONS.
49
50 -bl, --braces-after-if-line
51 Put braces on line after if, etc.
52 See STATEMENTS.
53
54 -blf, --braces-after-func-def-line
55 Put braces on line following function definition line.
56 See DECLARATIONS.
57
58 -blin, --brace-indentn
59 Indent braces n spaces.
60 See STATEMENTS.
61
62 -bls, --braces-after-struct-decl-line
63 Put braces on the line after struct declaration lines.
64 See DECLARATIONS.
65
66 -br, --braces-on-if-line
67 Put braces on line with if, etc.
68 See STATEMENTS.
69
70 -brf, --braces-on-func-def-line
71 Put braces on function definition line.
72 See DECLARATIONS.
73
74 -brs, --braces-on-struct-decl-line
75 Put braces on struct declaration line.
76 See DECLARATIONS.
77
78 -bs, --Bill-Shannon, --blank-before-sizeof
79 Put a space between sizeof and its argument.
80 See STATEMENTS.
81
82 -cn, --comment-indentationn
83 Put comments to the right of code in column n.
84 See COMMENTS.
85
86 -cbin, --case-brace-indentationn
87 Indent braces after a case label N spaces.
88 See STATEMENTS.
89
90 -cdn, --declaration-comment-columnn
91 Put comments to the right of the declarations in column n.
92 See COMMENTS.
93
94 -cdb, --comment-delimiters-on-blank-lines
95 Put comment delimiters on blank lines.
96 See COMMENTS.
97
98 -cdw, --cuddle-do-while
99 Cuddle while of do {} while; and preceding `}´.
100 See COMMENTS.
101
102 -ce, --cuddle-else
103 Cuddle else and preceding `}´.
104 See COMMENTS.
105
106 -cin, --continuation-indentationn
107 Continuation indent of n spaces.
108 See STATEMENTS.
109
110 -clin, --case-indentationn
111 Case label indent of n spaces.
112 See STATEMENTS.
113
114 -cpn, --else-endif-columnn
115 Put comments to the right of #else and #endif statements in column
116 n.
117 See COMMENTS.
118
119 -cs, --space-after-cast
120 Put a space after a cast operator.
121 See STATEMENTS.
122
123 -dn, --line-comments-indentationn
124 Set indentation of comments not to the right of code to n spaces.
125 See COMMENTS.
126
127 -bfda, --break-function-decl-args
128 Break the line before all arguments in a declaration.
129 See DECLARATIONS.
130
131 -bfde, --break-function-decl-args
132 Break the line after the last argument in a declaration.
133 See DECLARATIONS.
134
135 -djn, --left-justify-declarations
136 If -cd 0 is used then comments after declarations are left justi‐
137 fied behind the declaration.
138 See DECLARATIONS.
139
140 -din, --declaration-indentationn
141 Put variables in column n.
142 See DECLARATIONS.
143
144 -fc1, --format-first-column-comments
145 Format comments in the first column.
146 See COMMENTS.
147
148 -fca, --format-all-comments
149 Do not disable all formatting of comments.
150 See COMMENTS.
151
152 -gnu, --gnu-style
153 Use GNU coding style. This is the default.
154 See COMMON STYLES.
155
156 -hnl, --honour-newlines
157 Prefer to break long lines at the position of newlines in the
158 input.
159 See BREAKING LONG LINES.
160
161 -in, --indent-leveln
162 Set indentation level to n spaces.
163 See INDENTATION.
164
165 -iln, --indent-labeln
166 Set offset for labels to column n.
167 See INDENTATION.
168
169 -ipn, --parameter-indentationn
170 Indent parameter types in old-style function definitions by n spa‐
171 ces.
172 See INDENTATION.
173
174 -kr, --k-and-r-style
175 Use Kernighan & Ritchie coding style.
176 See COMMON STYLES.
177
178 -ln, --line-lengthn
179 Set maximum line length for non-comment lines to n.
180 See BREAKING LONG LINES.
181
182 -lcn, --comment-line-lengthn
183 Set maximum line length for comment formatting to n.
184 See COMMENTS.
185
186 -linux, --linux-style
187 Use Linux coding style.
188 See COMMON STYLES.
189
190 -lp, --continue-at-parentheses
191 Line up continued lines at parentheses.
192 See INDENTATION.
193
194 -lps, --leave-preprocessor-space
195 Leave space between `#´ and preprocessor directive.
196 See INDENTATION.
197
198 -nlps, --remove-preprocessor-space
199 Remove space between `#´ and preprocessor directive.
200 See INDENTATION.
201
202 -nbad, --no-blank-lines-after-declarations
203 Do not force blank lines after declarations.
204 See BLANK LINES.
205
206 -nbap, --no-blank-lines-after-procedures
207 Do not force blank lines after procedure bodies.
208 See BLANK LINES.
209
210 -nbbo, --break-after-boolean-operator
211 Do not prefer to break long lines before boolean operators.
212 See BREAKING LONG LINES.
213
214 -nbc, --no-blank-lines-after-commas
215 Do not force newlines after commas in declarations.
216 See DECLARATIONS.
217
218 -nbfda, --dont-break-function-decl-args
219 Don´t put each argument in a function declaration on a separate
220 line.
221 See DECLARATIONS.
222
223 -ncdb, --no-comment-delimiters-on-blank-lines
224 Do not put comment delimiters on blank lines.
225 See COMMENTS.
226
227 -ncdw, --dont-cuddle-do-while
228 Do not cuddle } and the while of a do {} while;.
229 See STATEMENTS.
230
231 -nce, --dont-cuddle-else
232 Do not cuddle } and else.
233 See STATEMENTS.
234
235 -ncs, --no-space-after-casts
236 Do not put a space after cast operators.
237 See STATEMENTS.
238
239 -ndjn, --dont-left-justify-declarations
240 Comments after declarations are treated the same as comments after
241 other statements.
242 See DECLARATIONS.
243
244 -nfc1, --dont-format-first-column-comments
245 Do not format comments in the first column as normal.
246 See COMMENTS.
247
248 -nfca, --dont-format-comments
249 Do not format any comments.
250 See COMMENTS.
251
252 -nhnl, --ignore-newlines
253 Do not prefer to break long lines at the position of newlines in
254 the input.
255 See BREAKING LONG LINES.
256
257 -nip, --no-parameter-indentation
258 Zero width indentation for parameters.
259 See INDENTATION.
260
261 -nlp, --dont-line-up-parentheses
262 Do not line up parentheses.
263 See STATEMENTS.
264
265 -npcs, --no-space-after-function-call-names
266 Do not put space after the function in function calls.
267 See STATEMENTS.
268
269 -nprs, --no-space-after-parentheses
270 Do not put a space after every ´(´ and before every ´)´.
271 See STATEMENTS.
272
273 -npsl, --dont-break-procedure-type
274 Put the type of a procedure on the same line as its name.
275 See DECLARATIONS.
276
277 -nsaf, --no-space-after-for
278 Do not put a space after every for.
279 See STATEMENTS.
280
281 -nsai, --no-space-after-if
282 Do not put a space after every if.
283 See STATEMENTS.
284
285 -nsaw, --no-space-after-while
286 Do not put a space after every while.
287 See STATEMENTS.
288
289 -nsc, --dont-star-comments
290 Do not put the `*´ character at the left of comments.
291 See COMMENTS.
292
293 -nsob, --leave-optional-blank-lines
294 Do not swallow optional blank lines.
295 See BLANK LINES.
296
297 -nss, --dont-space-special-semicolon
298 Do not force a space before the semicolon after certain statements.
299 Disables `-ss´.
300 See STATEMENTS.
301
302 -nut, --no-tabs
303 Use spaces instead of tabs.
304 See INDENTATION.
305
306 -nv, --no-verbosity
307 Disable verbose mode.
308 See MISCELLANEOUS OPTIONS.
309
310 -orig, --original
311 Use the original Berkeley coding style.
312 See COMMON STYLES.
313
314 -npro, --ignore-profile
315 Do not read `.indent.pro´ files.
316 See INVOKING INDENT.
317
318 -pcs, --space-after-procedure-calls
319 Insert a space between the name of the procedure being called and
320 the `(´.
321 See STATEMENTS.
322
323 -pin, --paren-indentationn
324 Specify the extra indentation per open parentheses ´(´ when a
325 statement is broken.See STATEMENTS.
326
327 -pmt, --preserve-mtime
328 Preserve access and modification times on output files.See MISCEL‐
329 LANEOUS OPTIONS.
330
331 -ppin, --preprocessor-indentationn
332 Specify the indentation for preprocessor conditional statements.See
333 INDENTATION.
334
335 -prs, --space-after-parentheses
336 Put a space after every ´(´ and before every ´)´.
337 See STATEMENTS.
338
339 -psl, --procnames-start-lines
340 Put the type of a procedure on the line before its name.
341 See DECLARATIONS.
342
343 -saf, --space-after-for
344 Put a space after each for.
345 See STATEMENTS.
346
347 -sai, --space-after-if
348 Put a space after each if.
349 See STATEMENTS.
350
351 -saw, --space-after-while
352 Put a space after each while.
353 See STATEMENTS.
354
355 -sbin, --struct-brace-indentationn
356 Indent braces of a struct, union or enum N spaces.
357 See STATEMENTS.
358
359 -sc, --start-left-side-of-comments
360 Put the `*´ character at the left of comments.
361 See COMMENTS.
362
363 -sob, --swallow-optional-blank-lines
364 Swallow optional blank lines.
365 See BLANK LINES.
366
367 -ss, --space-special-semicolon
368 On one-line for and while statements, force a blank before the
369 semicolon.
370 See STATEMENTS.
371
372 -st, --standard-output
373 Write to standard output.
374 See INVOKING INDENT.
375
376 -T Tell indent the name of typenames.
377 See DECLARATIONS.
378
379 -tsn, --tab-sizen
380 Set tab size to n spaces.
381 See INDENTATION.
382
383 -ut, --use-tabs
384 Use tabs. This is the default.
385 See INDENTATION.
386
387 -v, --verbose
388 Enable verbose mode.
389 See MISCELLANEOUS OPTIONS.
390
391 -version
392 Output the version number of indent.
393 See MISCELLANEOUS OPTIONS.
394
395
397 As of version 1.3, the format of the indent command is:
398
399
400 indent [options] [input-files]
401
402 indent [options] [single-input-file] [-o output-file]
403
404
405 This format is different from earlier versions and other versions of
406 indent.
407
408 In the first form, one or more input files are specified. indent makes
409 a backup copy of each file, and the original file is replaced with its
410 indented version. See BACKUP FILES, for an explanation of how backups
411 are made.
412
413 In the second form, only one input file is specified. In this case, or
414 when the standard input is used, you may specify an output file after
415 the `-o´ option.
416
417 To cause indent to write to standard output, use the `-st´ option.
418 This is only allowed when there is only one input file, or when the
419 standard input is used.
420
421 If no input files are named, the standard input is read for input.
422 Also, if a filename named `-´ is specified, then the standard input is
423 read.
424
425 As an example, each of the following commands will input the program
426 `slithy_toves.c´ and write its indented text to `slithy_toves.out´:
427
428
429 indent slithy_toves.c -o slithy_toves.out
430
431 indent -st slithy_toves.c > slithy_toves.out
432
433 cat slithy_toves.c | indent -o slithy_toves.out
434
435
436 Most other options to indent control how programs are formatted. As of
437 version 1.2, indent also recognizes a long name for each option name.
438 Long options are prefixed by either `--´ or `+´. [ `+´ is being super‐
439 seded by `--´ to maintain consistency with the POSIX standard.]
440 In most of this document, the traditional, short names are used for
441 the sake of brevity. See OPTION SUMMARY, for a list of options,
442 including both long and short names.
443
444 Here is another example:
445
446 indent -br test/metabolism.c -l85
447
448 This will indent the program `test/metabolism.c´ using the `-br´ and
449 `-l85´ options, write the output back to `test/metabolism.c´, and write
450 the original contents of `test/metabolism.c´ to a backup file in the
451 directory `test´.
452
453 Equivalent invocations using long option names for this example would
454 be:
455
456
457 indent --braces-on-if-line --line-length185 test/metabolism.c
458
459 indent +braces-on-if-line +line-length185 test/metabolism.c
460
461
462 If you find that you often use indent with the same options, you may
463 put those options into a file named `.indent.pro´. indent will look
464 for a profile file in three places. First it will check the environment
465 variable INDENT_PROFILE. If that exists its value is expected to name
466 the file that is to be used. If the environment variable does not
467 exist, indent looks for `.indent.pro´ in the current directory
468 and use that if found. Finally indent will search your home directory
469 for `.indent.pro´ and use that file if it is found. This behaviour is
470 different from that of other versions of indent, which load both files
471 if they both exist.
472
473 The format of `.indent.pro´ is simply a list of options, just as they
474 would appear on the command line, separated by white space (tabs, spa‐
475 ces, and newlines). Options in `.indent.pro´ may be surrounded by C or
476 C++ comments, in which case they are ignored.
477
478 Command line switches are handled after processing `.indent.pro´.
479 Options specified later override arguments specified earlier, with one
480 exception: Explicitly specified options always override background
481 options (See COMMON STYLES). You can prevent indent from reading an
482 `.indent.pro´ file by specifying the `-npro´ option.
483
484
486 As of version 1.3, GNU indent makes GNU-style backup files, the same
487 way GNU Emacs does. This means that either simple or numbered backup
488 filenames may be made.
489
490 Simple backup file names are generated by appending a suffix to the
491 original file name. The default for this suffix is the one-character
492 string `~´ (tilde). Thus, the backup file for `python.c´ would be
493 `python.c~´.
494
495 Instead of the default, you may specify any string as a suffix by set‐
496 ting the environment variable SIMPLE_BACKUP_SUFFIX to your preferred
497 suffix.
498
499 Numbered backup versions of a file `momeraths.c´ look like
500 `momeraths.c.~23~´, where 23 is the version of this particular backup.
501 When making a numbered backup of the file `src/momeraths.c´, the backup
502 file will be named `src/momeraths.c.~V~´, where V is one greater than
503 the highest version currently existing in the directory `src´. The
504 environment variable VERSION_WIDTH controls the number of digits, using
505 left zero padding when necessary. For instance, setting this variable
506 to "2" will lead to the backup file being named `momeraths.c.~04~´.
507
508 The type of backup file made is controlled by the value of the environ‐
509 ment variable VERSION_CONTROL. If it is the string `simple´, then only
510 simple backups will be made. If its value is the string `numbered´,
511 then numbered backups will be made. If its value is `numbered-exist‐
512 ing´, then numbered backups will be made if there already exist num‐
513 bered backups for the file being indented; otherwise, a simple backup
514 is made. If VERSION_CONTROL is not set, then indent assumes the behav‐
515 iour of `numbered-existing´.
516
517 Other versions of indent use the suffix `.BAK´ in naming backup files.
518 This behaviour can be emulated by setting SIMPLE_BACKUP_SUFFIX to
519 `.BAK´.
520
521 Note also that other versions of indent make backups in the current
522 directory, rather than in the directory of the source file as GNU
523 indent now does.
524
525
527 There are several common styles of C code, including the GNU style, the
528 Kernighan & Ritchie style, and the original Berkeley style. A style
529 may be selected with a single background option, which specifies a set
530 of values for all other options. However, explicitly specified options
531 always override options implied by a background option.
532
533 As of version 1.2, the default style of GNU indent is the GNU style.
534 Thus, it is no longer necessary to specify the option `-gnu´ to obtain
535 this format, although doing so will not cause an error. Option set‐
536 tings which correspond to the GNU style are:
537
538 -nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
539 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai
540 -saw -nsc -nsob
541
542 The GNU coding style is that preferred by the GNU project. It is the
543 style that the GNU Emacs C mode encourages and which is used in the C
544 portions of GNU Emacs. (People interested in writing programs for
545 Project GNU should get a copy of "The GNU Coding Standards", which also
546 covers semantic and portability issues such as memory usage, the size
547 of integers, etc.)
548
549 The Kernighan & Ritchie style is used throughout their well-known book
550 "The C Programming Language". It is enabled with the `-kr´ option.
551 The Kernighan & Ritchie style corresponds to the following set of
552 options:
553
554 -nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
555 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
556 -nprs -npsl -saf -sai -saw -nsc -nsob -nss
557
558 Kernighan & Ritchie style does not put comments to the right of code in
559 the same column at all times (nor does it use only one space to the
560 right of the code), so for this style indent has arbitrarily chosen
561 column 33.
562
563 The style of the original Berkeley indent may be obtained by specifying
564 `-orig´ (or by specifying `--original´, using the long option name).
565 This style is equivalent to the following settings:
566
567 -nbad -nbap -bbo -bc -br -brs -c33 -cd33 -cdb -ce -ci4 -cli0
568 -cp33 -di16 -fc1 -fca -hnl -i4 -ip4 -l75 -lp -npcs -nprs -psl
569 -saf -sai -saw -sc -nsob -nss -ts8
570
571 The Linux style is used in the linux kernel code and drivers. Code gen‐
572 erally has to follow the Linux coding style to be accepted. This style
573 is equivalent to the following settings:
574
575 -nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4
576 -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai
577 -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1
578
579
581 Various programming styles use blank lines in different places. indent
582 has a number of options to insert or delete blank lines in specific
583 places.
584
585 The `-bad´ option causes indent to force a blank line after every block
586 of declarations. The `-nbad´ option causes indent not to force such
587 blank lines.
588
589 The `-bap´ option forces a blank line after every procedure body. The
590 `-nbap´ option forces no such blank line.
591
592 The `-bbb´ option forces a blank line before every boxed comment (See
593 COMMENTS.) The `-nbbb´ option does not force such blank lines.
594
595 The `-sob´ option causes indent to swallow optional blank lines (that
596 is, any optional blank lines present in the input will be removed from
597 the output). If the `-nsob´ is specified, any blank lines present in
598 the input file will be copied to the output file.
599
600
601
603 The `-bad´ option forces a blank line after every block of declara‐
604 tions. The `-nbad´ option does not add any such blank lines.
605
606 For example, given the input
607 char *foo;
608 char *bar;
609 /* This separates blocks of declarations. */
610 int baz;
611
612 indent -bad produces
613
614 char *foo;
615 char *bar;
616
617 /* This separates blocks of declarations. */
618 int baz;
619
620 and indent -nbad produces
621
622 char *foo;
623 char *bar;
624 /* This separates blocks of declarations. */
625 int baz;
626
627
629 The `-bap´ option forces a blank line after every procedure body.
630
631 For example, given the input
632
633 int
634 foo ()
635 {
636 puts("Hi");
637 }
638 /* The procedure bar is even less interesting. */
639 char *
640 bar ()
641 {
642 puts("Hello");
643 }
644
645 indent -bap produces
646
647 int
648 foo ()
649 {
650 puts ("Hi");
651 }
652
653 /* The procedure bar is even less interesting. */
654 char *
655 bar ()
656 {
657 puts ("Hello");
658 }
659
660 and indent -nbap produces
661
662 int
663 foo ()
664 {
665 puts ("Hi");
666 }
667 /* The procedure bar is even less interesting. */
668 char *
669 bar ()
670 {
671 puts ("Hello");
672 }
673
674 No blank line will be added after the procedure foo.
675
676
678 indent formats both C and C++ comments. C comments are begun with `/*´,
679 terminated with `*/´ and may contain newline characters. C++ comments
680 begin with the delimiter `//´ and end at the newline.
681
682 indent handles comments differently depending upon their context.
683 indent attempts to distinguish between comments which follow state‐
684 ments, comments which follow declarations, comments following pre‐
685 processor directives, and comments which are not preceded by code of
686 any sort, i.e., they begin the text of the line (although not necessar‐
687 ily in column 1).
688
689 indent further distinguishes between comments found outside of proce‐
690 dures and aggregates, and those found within them. In particular, com‐
691 ments beginning a line found within a procedure will be indented to the
692 column at which code is currently indented. The exception to this is a
693 comment beginning in the leftmost column; such a comment is output at
694 that column.
695
696 indent attempts to leave boxed comments unmodified. The general idea of
697 such a comment is that it is enclosed in a rectangle or ``box´´ of
698 stars or dashes to visually set it apart. More precisely, boxed com‐
699 ments are defined as those in which the initial `/*´ is followed imme‐
700 diately by the character `*´, `=´, `_´, or `-´, or those in which the
701 beginning comment delimiter (`/*´) is on a line by itself, and the fol‐
702 lowing line begins with a `*´ in the same column as the star of the
703 opening delimiter.
704
705 Examples of boxed comments are:
706
707 /**********************
708 * Comment in a box!! *
709 **********************/
710
711 /*
712 * A different kind of scent,
713 * for a different kind of comment.
714 */
715
716 indent attempts to leave boxed comments exactly as they are found in
717 the source file. Thus the indentation of the comment is unchanged, and
718 its length is not checked in any way. The only alteration made is that
719 an embedded tab character may be converted into the appropriate number
720 of spaces.
721
722 If the `-bbb´ option is specified, all such boxed comments will be pre‐
723 ceded by a blank line, unless such a comment is preceded by code.
724
725 Comments which are not boxed comments may be formatted, which means
726 that the line is broken to fit within a right margin and left-filled
727 with whitespace. Single newlines are equivalent to a space, but blank
728 lines (two or more newlines in a row) are taken to mean a paragraph
729 break. Formatting of comments which begin after the first column is
730 enabled with the `-fca´ option. To format those beginning in column
731 one, specify `-fc1´. Such formatting is disabled by default.
732
733 The right margin for formatting defaults to 78, but may be changed with
734 the `-lc´ option. If the margin specified does not allow the comment
735 to be printed, the margin will be automatically extended for the dura‐
736 tion of that comment. The margin is not respected if the comment is
737 not being formatted.
738
739 If the comment begins a line (i.e., there is no program text to its
740 left), it will be indented to the column it was found in unless the
741 comment is within a block of code. In that case, such a comment will
742 be aligned with the indented code of that block (unless the comment
743 began in the first column). This alignment may be affected by the `-d´
744 option, which specifies an amount by which such comments are moved to
745 the left, or unindented. For example, `-d2´ places comments two spaces
746 to the left of code. By default, comments are aligned with code,
747 unless they begin in the first column, in which case they are left
748 there by default --- to get them aligned with the code, specify `-fc1´.
749
750 Comments to the right of code will appear by default in column 33.
751 This may be changed with one of three options. `-c´ will specify the
752 column for comments following code, `-cd´ specifies the column for com‐
753 ments following declarations, and `-cp´ specifies the column for com‐
754 ments following preprocessor directives #else and #endif. `-dj´
755 together with `-cd0´ can be used to suppress alignment of comments to
756 the right of declarations, causing the comment to follow one tabstop
757 from the end of the declaration. Normally `-cd0´ causes `-c´ to become
758 effective.
759
760 If the code to the left of the comment exceeds the beginning column,
761 the comment column will be extended to the next tabstop column past the
762 end of the code, or in the case of preprocessor directives, to one
763 space past the end of the directive. This extension lasts only for the
764 output of that particular comment.
765
766 The `-cdb´ option places the comment delimiters on blank lines. Thus,
767 a single line comment like /* Loving hug */ can be transformed into:
768
769 /*
770 Loving hug
771 */
772
773 Stars can be placed at the beginning of multi-line comments with the
774 `-sc´ option. Thus, the single-line comment above can be transformed
775 (with `-cdb -sc´) into:
776
777 /*
778 * Loving hug
779 */
780
781
783 The `-br´ or `-bl´ option specifies how to format braces.
784
785 The `-br´ option formats statement braces like this:
786
787 if (x > 0) {
788 x--;
789 }
790
791 The `-bl´ option formats them like this:
792
793 if (x > 0)
794 {
795 x--;
796 }
797
798 If you use the `-bl´ option, you may also want to specify the `-bli´
799 option. This option specifies the number of spaces by which braces are
800 indented. `-bli2´, the default, gives the result shown above. `-bli0´
801 results in the following:
802
803 if (x > 0)
804 {
805 x--;
806 }
807
808 If you are using the `-br´ option, you probably want to also use the
809 `-ce´ option. This causes the else in an if-then-else construct to
810 cuddle up to the immediately preceding `}´. For example, with `-br
811 -ce´ you get the following:
812
813 if (x > 0) {
814 x--;
815 } else {
816 fprintf (stderr, "...something wrong?\n");
817 }
818
819 With `-br -nce´ that code would appear as
820
821 if (x > 0) {
822 x--;
823 }
824 else {
825 fprintf (stderr, "...something wrong?\n");
826 }
827
828 This causes the while in a do-while loop to cuddle up to the immedi‐
829 ately preceding `}´. For example, with `-cdw´ you get the following:
830
831 do {
832 x--;
833 } while (x);
834
835 With `-ncdw´ that code would appear as
836
837 do {
838 x--;
839 }
840 while (x);
841
842 The `-cli´ option specifies the number of spaces that case labels
843 should be indented to the right of the containing switch statement.
844
845 The default gives code like:
846
847 switch (i)
848 {
849 case 0:
850 break;
851 case 1:
852 {
853 ++i;
854 }
855 default:
856 break;
857 }
858
859 Using the `-cli2´ that would become:
860
861 switch (i)
862 {
863 case 0:
864 break;
865 case 1:
866 {
867 ++i;
868 }
869 default:
870 break;
871 }
872
873 The indentation of the braces below a case statement can be controlled
874 with the `-cbin´ option. For example, using `-cli2 -cbi0´ results in:
875
876 switch (i)
877 {
878 case 0:
879 break;
880 case 1:
881 {
882 ++i;
883 }
884 default:
885 break;
886 }
887
888 If a semicolon is on the same line as a for or while statement, the
889 `-ss´ option will cause a space to be placed before the semicolon.
890 This emphasizes the semicolon, making it clear that the body of the for
891 or while statement is an empty statement. `-nss´ disables this fea‐
892 ture.
893
894 The `-pcs´ option causes a space to be placed between the name of the
895 procedure being called and the `(´ (for example, puts ("Hi");. The
896 `-npcs´ option would give puts("Hi");).
897
898
899 If the `-cs´ option is specified, indent puts a space after a cast
900 operator.
901
902 The `-bs´ option ensures that there is a space between the keyword
903 sizeof and its argument. In some versions, this is known as the
904 `Bill_Shannon´ option.
905
906 The `-saf´ option forces a space between a for and the following paren‐
907 thesis. This is the default.
908
909 The `-sai´ option forces a space between a if and the following paren‐
910 thesis. This is the default.
911
912 The `-saw´ option forces a space between a while and the following
913 parenthesis. This is the default.
914
915 The `-prs´ option causes all parentheses to be separated with a space
916 from whatever is between them. For example, using `-prs´ results in
917 code like:
918
919 while ( ( e_code - s_code ) < ( dec_ind - 1 ) )
920 {
921 set_buf_break ( bb_dec_ind );
922 *e_code++ = ´ ´;
923 }
924
925
927 By default indent will line up identifiers, in the column specified by
928 the `-di´ option. For example, `-di16´ makes things look like:
929
930 int foo;
931 char *bar;
932
933 Using a small value (such as one or two) for the `-di´ option can be
934 used to cause the identifiers to be placed in the first available posi‐
935 tion; for example:
936
937 int foo;
938 char *bar;
939
940 The value given to the `-di´ option will still affect variables which
941 are put on separate lines from their types, for example `-di2´ will
942 lead to:
943
944 int
945 foo;
946
947 If the `-bc´ option is specified, a newline is forced after each comma
948 in a declaration. For example,
949
950 int a,
951 b,
952 c;
953
954 With the `-nbc´ option this would look like
955
956 int a, b, c;
957
958 The `-bfda´ option causes a newline to be forced after the comma sepa‐
959 rating the arguments of a function declaration. The arguments will
960 appear at one indention level deeper than the function declaration.
961 This is particularly helpful for functions with long argument lists.
962 The option `-bfde´ causes a newline to be forced before the closing
963 bracket of the function declaration. For both options the ´n´ setting
964 is the default: -nbdfa and -nbdfe.
965
966
967 For example,
968
969 void foo (int arg1, char arg2, int *arg3, long arg4, char arg5);
970 With the `-bfda´ option this would look like
971
972 void foo (
973 int arg1,
974 char arg2,
975 int *arg3,
976 long arg4,
977 char arg5);
978
979 With, in addition, the `-bfde´ option this would look like
980
981 void foo (
982 int arg1,
983 char arg2,
984 int *arg3,
985 long arg4,
986 char arg5
987 );
988
989 The `-psl´ option causes the type of a procedure being defined to be
990 placed on the line before the name of the procedure. This style is
991 required for the etags program to work correctly, as well as some of
992 the c-mode functions of Emacs.
993
994 You must use the `-T´ option to tell indent the name of all the type‐
995 names in your program that are defined by typedef. `-T´ can be speci‐
996 fied more than once, and all names specified are used. For example, if
997 your program contains
998
999 typedef unsigned long CODE_ADDR;
1000 typedef enum {red, blue, green} COLOR;
1001
1002 you would use the options `-T CODE_ADDR -T COLOR´.
1003
1004
1005 The `-brs´ or `-bls´ option specifies how to format braces in struct
1006 declarations. The `-brs´ option formats braces like this:
1007
1008 struct foo {
1009 int x;
1010 };
1011
1012 The `-bls´ option formats them like this:
1013
1014 struct foo
1015 {
1016 int x;
1017 };
1018
1019
1020 Similarly to the structure brace `-brs´ and `-bls´ options,
1021 the function brace options `-brf´ or `-blf´ specify how to format the
1022 braces in function definitions. The `-brf´ option formats braces like
1023 this:
1024
1025 int one(void) {
1026 return 1;
1027 };
1028
1029 The `-blf´ option formats them like this:
1030
1031 int one(void)
1032 {
1033 return 1;
1034 };
1035
1036
1038 One issue in the formatting of code is how far each line should be
1039 indented from the left margin. When the beginning of a statement such
1040 as if or for is encountered, the indentation level is increased by the
1041 value specified by the `-i´ option. For example, use `-i8´ to specify
1042 an eight character indentation for each level. When a statement is
1043 broken across two lines, the second line is indented by a number of
1044 additional spaces specified by the `-ci´ option. `-ci´ defaults to 0.
1045 However, if the `-lp´ option is specified, and a line has a left paren‐
1046 thesis which is not closed on that line, then continuation lines will
1047 be lined up to start at the character position just after the left
1048 parenthesis. This processing also applies to `[´ and applies to `{´
1049 when it occurs in initialization lists. For example, a piece of con‐
1050 tinued code might look like this with `-nlp -ci3´ in effect:
1051
1052 p1 = first_procedure (second_procedure (p2, p3),
1053 third_procedure (p4, p5));
1054
1055 With `-lp´ in effect the code looks somewhat clearer:
1056
1057 p1 = first_procedure (second_procedure (p2, p3),
1058 third_procedure (p4, p5));
1059
1060 When a statement is broken in between two or more paren pairs (...),
1061 each extra pair causes the indentation level extra indentation:
1062
1063 if ((((i < 2 &&
1064 k > 0) || p == 0) &&
1065 q == 1) ||
1066 n = 0)
1067
1068 The option `-ipN´ can be used to set the extra offset per paren. For
1069 instance, `-ip0´ would format the above as:
1070
1071 if ((((i < 2 &&
1072 k > 0) || p == 0) &&
1073 q == 1) ||
1074 n = 0)
1075
1076 indent assumes that tabs are placed at regular intervals of both input
1077 and output character streams. These intervals are by default 8 columns
1078 wide, but (as of version 1.2) may be changed by the `-ts´ option. Tabs
1079 are treated as the equivalent number of spaces.
1080
1081 The indentation of type declarations in old-style function definitions
1082 is controlled by the `-ip´ parameter. This is a numeric parameter
1083 specifying how many spaces to indent type declarations. For example,
1084 the default `-ip5´ makes definitions look like this:
1085
1086 char *
1087 create_world (x, y, scale)
1088 int x;
1089 int y;
1090 float scale;
1091 {
1092 . . .
1093 }
1094
1095 For compatibility with other versions of indent, the option `-nip´ is
1096 provided, which is equivalent to `-ip0´.
1097
1098 ANSI C allows white space to be placed on preprocessor command lines
1099 between the character `#´ and the command name. By default, indent
1100 removes this space, but specifying the `-lps´ option directs indent to
1101 leave this space unmodified. The option `-ppi´ overrides `-nlps´ and
1102 `-lps´.
1103
1104 This option can be used to request that preprocessor conditional state‐
1105 ments can be indented by to given number of spaces, for example with
1106 the option `-ppi 3´
1107
1108 #if X
1109 #if Y
1110 #define Z 1
1111 #else
1112 #define Z 0
1113 #endif
1114 #endif
1115 becomes
1116 #if X
1117 # if Y
1118 # define Z 1
1119 # else
1120 # define Z 0
1121 # endif
1122 #endif
1123
1124 This option sets the offset at which a label (except case labels) will
1125 be positioned. If it is set to zero or a positive number, this indi‐
1126 cates how far from the left margin to indent a label. If it is set to
1127 a negative number, this indicates how far back from the current indent
1128 level to place the label. The default setting is -2 which matches the
1129 behaviour of earlier versions of indent. Note that this parameter does
1130 not affect the placing of case labels; see the `-cli´ parameter for
1131 that. For example with the option `-il 1´
1132
1133 group
1134 function()
1135 {
1136 if (do_stuff1() == ERROR)
1137 goto cleanup1;
1138
1139 if (do_stuff2() == ERROR)
1140 goto cleanup2;
1141
1142 return SUCCESS;
1143
1144 cleanup2:
1145 do_cleanup2();
1146
1147 cleanup1:
1148 do_cleanup1();
1149
1150 return ERROR;
1151 }
1152 becomes
1153 group
1154 function()
1155 {
1156 if (do_stuff1() == ERROR)
1157 goto cleanup1;
1158
1159 if (do_stuff2() == ERROR)
1160 goto cleanup2;
1161
1162 return SUCCESS;
1163
1164 cleanup2:
1165 do_cleanup2();
1166
1167 cleanup1:
1168 do_cleanup1();
1169
1170 return ERROR;
1171 }
1172
1173
1175 With the option `-ln´, or `--line-lengthn´, it is possible to specify
1176 the maximum length of a line of C code, not including possible comments
1177 that follow it.
1178
1179 When lines become longer than the specified line length, GNU indent
1180 tries to break the line at a logical place. This is new as of version
1181 2.1 however and not very intelligent or flexible yet.
1182
1183 Currently there are two options that allow one to interfere with the
1184 algorithm that determines where to break a line.
1185
1186 The `-bbo´ option causes GNU indent to prefer to break long lines
1187 before the boolean operators && and ||. The `-nbbo´ option causes GNU
1188 indent not have that preference. For example, the default option
1189 `-bbo´ (together with `--line-length60´ and `--ignore-newlines´) makes
1190 code look like this:
1191
1192 if (mask
1193 && ((mask[0] == ´\0´)
1194 || (mask[1] == ´\0´
1195 && ((mask[0] == ´0´) || (mask[0] == ´*´)))))
1196
1197 Using the option `-nbbo´ will make it look like this:
1198
1199 if (mask &&
1200 ((mask[0] == ´\0´) ||
1201 (mask[1] == ´\0´ &&
1202 ((mask[0] == ´0´) || (mask[0] == ´*´)))))
1203
1204 The default `-hnl´, however, honours newlines in the input file by giv‐
1205 ing them the highest possible priority to break lines at. For example,
1206 when the input file looks like this:
1207
1208 if (mask
1209 && ((mask[0] == ´\0´)
1210 || (mask[1] == ´\0´ && ((mask[0] == ´0´) || (mask[0] == ´*´)))))
1211
1212 then using the option `-hnl´, or `--honour-newlines´, together with the
1213 previously mentioned `-nbbo´ and `--line-length60´, will cause the out‐
1214 put not to be what is given in the last example but instead will prefer
1215 to break at the positions where the code was broken in the input file:
1216
1217 if (mask
1218 && ((mask[0] == ´\0´)
1219 || (mask[1] == ´\0´ &&
1220 ((mask[0] == ´0´) || (mask[0] == ´*´)))))
1221
1222 The idea behind this option is that lines which are too long, but are
1223 already broken up, will not be touched by GNU indent. Really messy
1224 code should be run through indent at least once using the `--ignore-
1225 newlines´ option though.
1226
1227
1229 Formatting of C code may be disabled for portions of a program by
1230 embedding special control comments in the program. To turn off format‐
1231 ting for a section of a program, place the disabling control comment /*
1232 *INDENT-OFF* */ on a line by itself just before that section. Program
1233 text scanned after this control comment is output precisely as input
1234 with no modifications until the corresponding enabling comment is
1235 scanned on a line by itself. The disabling control comment is /*
1236 *INDENT-ON* */, and any text following the comment on the line is also
1237 output unformatted. Formatting begins again with the input line fol‐
1238 lowing the enabling control comment.
1239
1240 More precisely, indent does not attempt to verify the closing delimiter
1241 (*/) for these C comments, and any whitespace on the line is totally
1242 transparent.
1243
1244 These control comments also function in their C++ formats, namely //
1245 *INDENT-OFF* and // *INDENT-ON*.
1246
1247 It should be noted that the internal state of indent remains unchanged
1248 over the course of the unformatted section. Thus, for example, turning
1249 off formatting in the middle of a function and continuing it after the
1250 end of the function may lead to bizarre results. It is therefore wise
1251 to be somewhat modular in selecting code to be left unformatted.
1252
1253 As a historical note, some earlier versions of indent produced error
1254 messages beginning with *INDENT**. These versions of indent were writ‐
1255 ten to ignore any input text lines which began with such error mes‐
1256 sages. I have removed this incestuous feature from GNU indent.
1257
1258
1260 To find out what version of indent you have, use the command indent
1261 -version. This will report the version number of indent, without doing
1262 any of the normal processing.
1263
1264 The `-v´ option can be used to turn on verbose mode. When in verbose
1265 mode, indent reports when it splits one line of input into two more
1266 more lines of output, and gives some size statistics at completion.
1267
1268 The `-pmt´ option causes indent to preserve the access and modification
1269 times on the output files. Using this option has the advantage that
1270 running indent on all source and header files in a project won´t cause
1271 make to rebuild all targets. This option is only available on Operat‐
1272 ing Systems that have the POSIX utime(2) function.
1273
1274
1276 Please report any bugs to bug-indent@gnu.org.
1277
1278 When indent is run twice on a file, with the same profile, it should
1279 never change that file the second time. With the current design of
1280 indent, this can not be guaranteed, and it has not been extensively
1281 tested.
1282
1283 indent does not understand C. In some cases this leads to the inability
1284 to join lines. The result is that running a file through indent is
1285 irreversible, even if the used input file was the result of running
1286 indent with a given profile (`.indent.pro´).
1287
1288 While an attempt was made to get indent working for C++, it will not do
1289 a good job on any C++ source except the very simplest.
1290
1291 indent does not look at the given `--line-length´ option when writing
1292 comments to the output file. This results often in comments being put
1293 far to the right. In order to prohibit indent from joining a broken
1294 line that has a comment at the end, make sure that the comments start
1295 on the first line of the break.
1296
1297 indent does not count lines and comments (see the `-v´ option) when
1298 indent is turned off with /* *INDENT-OFF* */.
1299
1300 Comments of the form /*UPPERCASE*/ are not treated as comment but as an
1301 identifier, causing them to be joined with the next line. This renders
1302 comments of this type useless, unless they are embedded in the code to
1303 begin with.
1304
1305
1307 The following copyright notice applies to the indent program. The
1308 copyright and copying permissions for this manual appear near the
1309 beginning of `indent.texinfo´ and `indent.info´, and near the end of
1310 `indent.1´.
1311
1312 Copyright (c) 2001 David Ingamells.
1313 Copyright (c) 1999 Carlo Wood.
1314 Copyright (c) 1995, 1996 Joseph Arceneaux.
1315 Copyright (c) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation
1316 Copyright (c) 1985 Sun Microsystems, Inc.
1317 Copyright (c) 1980 The Regents of the University of California.
1318 Copyright (c) 1976 Board of Trustees of the University of Illinois.
1319 All rights reserved.
1320
1321 Redistribution and use in source and binary forms are permitted
1322 provided that the above copyright notice and this paragraph are
1323 duplicated in all such forms and that any documentation,
1324 advertising materials, and other materials related to such
1325 distribution and use acknowledge that the software was developed
1326 by the University of California, Berkeley, the University of Illinois,
1327 Urbana, and Sun Microsystems, Inc. The name of either University
1328 or Sun Microsystems may not be used to endorse or promote products
1329 derived from this software without specific prior written permission.
1330 THIS SOFTWARE IS PROVIDED ``AS IS´´ AND WITHOUT ANY EXPRESS OR
1331 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1332 WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1333 PURPOSE.
1334
1335
1337 Here is a list of options alphabetized by long option, to help you find
1338 the corresponding short option.
1339
1340
1341 --blank-lines-after-commas -bc
1342 --blank-lines-after-declarations -bad
1343 --blank-lines-after-procedures -bap
1344 --blank-lines-before-block-comments -bbb
1345 --braces-after-if-line -bl
1346 --braces-after-func-def-line -blf
1347 --brace-indent -bli
1348 --braces-after-struct-decl-line -bls
1349 --braces-on-if-line -br
1350 --braces-on-func-def-line -brf
1351 --braces-on-struct-decl-line -brs
1352 --break-after-boolean-operator -nbbo
1353 --break-before-boolean-operator -bbo
1354 --break-function-decl-args -bfda
1355 --break-function-decl-args-end -bfde
1356 --case-indentation -clin
1357 --case-brace-indentation -cbin
1358 --comment-delimiters-on-blank-lines -cdb
1359 --comment-indentation -cn
1360 --continuation-indentation -cin
1361 --continue-at-parentheses -lp
1362 --cuddle-do-while -cdw
1363 --cuddle-else -ce
1364 --declaration-comment-column -cdn
1365 --declaration-indentation -din
1366 --dont-break-function-decl-args -nbfda
1367 --dont-break-function-decl-args-end -nbfde
1368 --dont-break-procedure-type -npsl
1369 --dont-cuddle-do-while -ncdw
1370 --dont-cuddle-else -nce
1371 --dont-format-comments -nfca
1372 --dont-format-first-column-comments -nfc1
1373 --dont-line-up-parentheses -nlp
1374 --dont-left-justify-declarations -ndj
1375 --dont-space-special-semicolon -nss
1376 --dont-star-comments -nsc
1377 --else-endif-column -cpn
1378 --format-all-comments -fca
1379 --format-first-column-comments -fc1
1380 --gnu-style -gnu
1381 --honour-newlines -hnl
1382 --ignore-newlines -nhnl
1383 --ignore-profile -npro
1384 --indent-label -iln
1385 --indent-level -in
1386 --k-and-r-style -kr
1387 --leave-optional-blank-lines -nsob
1388 --leave-preprocessor-space -lps
1389 --left-justify-declarations -dj
1390 --line-comments-indentation -dn
1391 --line-length -ln
1392 --linux-style -linux
1393 --no-blank-lines-after-commas -nbc
1394 --no-blank-lines-after-declarations -nbad
1395 --no-blank-lines-after-procedures -nbap
1396 --no-blank-lines-before-block-comments -nbbb
1397 --no-comment-delimiters-on-blank-lines -ncdb
1398 --no-space-after-casts -ncs
1399 --no-parameter-indentation -nip
1400 --no-space-after-for -nsaf
1401 --no-space-after-function-call-names -npcs
1402 --no-space-after-if -nsai
1403 --no-space-after-parentheses -nprs
1404 --no-space-after-while -nsaw
1405 --no-tabs -nut
1406 --no-verbosity -nv
1407 --original -orig
1408 --parameter-indentation -ipn
1409 --paren-indentation -pin
1410 --preserve-mtime -pmt
1411 --preprocessor-indentation -ppin
1412 --procnames-start-lines -psl
1413 --remove-preprocessor-space -nlps
1414 --space-after-cast -cs
1415 --space-after-for -saf
1416 --space-after-if -sai
1417 --space-after-parentheses -prs
1418 --space-after-procedure-calls -pcs
1419 --space-after-while -saw
1420 --space-special-semicolon -ss
1421 --standard-output -st
1422 --start-left-side-of-comments -sc
1423 --struct-brace-indentation -sbin
1424 --swallow-optional-blank-lines -sob
1425 --tab-size -tsn
1426 --use-tabs -ut
1427 --verbose -v
1428
1429
1431 Unknown
1432
1434 $HOME/.indent.pro holds default options for indent.
1435
1437 Carlo Wood
1438 Joseph Arceneaux
1439 Jim Kingdon
1440 David Ingamells
1441
1443 Derived from the UCB program "indent".
1444
1446 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Founda‐
1447 tion, Inc. Copyright (C) 1995, 1996 Joseph Arceneaux. Copyright (C)
1448 1999 Carlo Wood. Copyright (C) 2001 David Ingamells.
1449
1450 Permission is granted to make and distribute verbatim copies of this
1451 manual provided the copyright notice and this permission notice are
1452 preserved on all copies.
1453
1454
1455
1456
1457
1458 INDENT(1L)