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