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-end
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 between a cast
900 operator and the object to be cast. The ‘-ncs’ ensures that there is no
901 space between the cast operator and the object. Remember that indent
902 only knows about the standard C data types and so cannot recognise
903 user-defined types in casts. Thus (mytype)thing is not treated as a
904 cast.
905
906 The ‘-bs’ option ensures that there is a space between the keyword
907 sizeof and its argument. In some versions, this is known as the
908 ‘Bill_Shannon’ option.
909
910 The ‘-saf’ option forces a space between a for and the following paren‐
911 thesis. This is the default.
912
913 The ‘-sai’ option forces a space between a if and the following paren‐
914 thesis. This is the default.
915
916 The ‘-saw’ option forces a space between a while and the following
917 parenthesis. This is the default.
918
919 The ‘-prs’ option causes all parentheses to be separated with a space
920 from whatever is between them. For example, using ‘-prs’ results in
921 code like:
922
923 while ( ( e_code - s_code ) < ( dec_ind - 1 ) )
924 {
925 set_buf_break ( bb_dec_ind );
926 *e_code++ = ’ ’;
927 }
928
929
931 By default indent will line up identifiers, in the column specified by
932 the ‘-di’ option. For example, ‘-di16’ makes things look like:
933
934 int foo;
935 char *bar;
936
937 Using a small value (such as one or two) for the ‘-di’ option can be
938 used to cause the identifiers to be placed in the first available posi‐
939 tion; for example:
940
941 int foo;
942 char *bar;
943
944 The value given to the ‘-di’ option will still affect variables which
945 are put on separate lines from their types, for example ‘-di2’ will
946 lead to:
947
948 int
949 foo;
950
951 If the ‘-bc’ option is specified, a newline is forced after each comma
952 in a declaration. For example,
953
954 int a,
955 b,
956 c;
957
958 With the ‘-nbc’ option this would look like
959
960 int a, b, c;
961
962 The ‘-bfda’ option causes a newline to be forced after the comma sepa‐
963 rating the arguments of a function declaration. The arguments will
964 appear at one indention level deeper than the function declaration.
965 This is particularly helpful for functions with long argument lists.
966 The option ‘-bfde’ causes a newline to be forced before the closing
967 bracket of the function declaration. For both options the ’n’ setting
968 is the default: -nbdfa and -nbdfe.
969
970
971 For example,
972
973 void foo (int arg1, char arg2, int *arg3, long arg4, char arg5);
974 With the ‘-bfda’ option this would look like
975
976 void foo (
977 int arg1,
978 char arg2,
979 int *arg3,
980 long arg4,
981 char arg5);
982
983 With, in addition, the ‘-bfde’ option this would look like
984
985 void foo (
986 int arg1,
987 char arg2,
988 int *arg3,
989 long arg4,
990 char arg5
991 );
992
993 The ‘-psl’ option causes the type of a procedure being defined to be
994 placed on the line before the name of the procedure. This style is
995 required for the etags program to work correctly, as well as some of
996 the c-mode functions of Emacs.
997
998 You must use the ‘-T’ option to tell indent the name of all the type‐
999 names in your program that are defined by typedef. ‘-T’ can be speci‐
1000 fied more than once, and all names specified are used. For example, if
1001 your program contains
1002
1003 typedef unsigned long CODE_ADDR;
1004 typedef enum {red, blue, green} COLOR;
1005
1006 you would use the options ‘-T CODE_ADDR -T COLOR’.
1007
1008
1009 The ‘-brs’ or ‘-bls’ option specifies how to format braces in struct
1010 declarations. The ‘-brs’ option formats braces like this:
1011
1012 struct foo {
1013 int x;
1014 };
1015
1016 The ‘-bls’ option formats them like this:
1017
1018 struct foo
1019 {
1020 int x;
1021 };
1022
1023
1024 Similarly to the structure brace ‘-brs’ and ‘-bls’ options,
1025 the function brace options ‘-brf’ or ‘-blf’ specify how to format the
1026 braces in function definitions. The ‘-brf’ option formats braces like
1027 this:
1028
1029 int one(void) {
1030 return 1;
1031 };
1032
1033 The ‘-blf’ option formats them like this:
1034
1035 int one(void)
1036 {
1037 return 1;
1038 };
1039
1040
1042 One issue in the formatting of code is how far each line should be
1043 indented from the left margin. When the beginning of a statement such
1044 as if or for is encountered, the indentation level is increased by the
1045 value specified by the ‘-i’ option. For example, use ‘-i8’ to specify
1046 an eight character indentation for each level. When a statement is
1047 broken across two lines, the second line is indented by a number of
1048 additional spaces specified by the ‘-ci’ option. ‘-ci’ defaults to 0.
1049 However, if the ‘-lp’ option is specified, and a line has a left paren‐
1050 thesis which is not closed on that line, then continuation lines will
1051 be lined up to start at the character position just after the left
1052 parenthesis. This processing also applies to ‘[’ and applies to ‘{’
1053 when it occurs in initialization lists. For example, a piece of con‐
1054 tinued code might look like this with ‘-nlp -ci3’ in effect:
1055
1056 p1 = first_procedure (second_procedure (p2, p3),
1057 third_procedure (p4, p5));
1058
1059 With ‘-lp’ in effect the code looks somewhat clearer:
1060
1061 p1 = first_procedure (second_procedure (p2, p3),
1062 third_procedure (p4, p5));
1063
1064 When a statement is broken in between two or more paren pairs (...),
1065 each extra pair causes the indentation level extra indentation:
1066
1067 if ((((i < 2 &&
1068 k > 0) || p == 0) &&
1069 q == 1) ||
1070 n = 0)
1071
1072 The option ‘-ipN’ can be used to set the extra offset per paren. For
1073 instance, ‘-ip0’ would format the above as:
1074
1075 if ((((i < 2 &&
1076 k > 0) || p == 0) &&
1077 q == 1) ||
1078 n = 0)
1079
1080 indent assumes that tabs are placed at regular intervals of both input
1081 and output character streams. These intervals are by default 8 columns
1082 wide, but (as of version 1.2) may be changed by the ‘-ts’ option. Tabs
1083 are treated as the equivalent number of spaces.
1084
1085 The indentation of type declarations in old-style function definitions
1086 is controlled by the ‘-ip’ parameter. This is a numeric parameter
1087 specifying how many spaces to indent type declarations. For example,
1088 the default ‘-ip5’ makes definitions look like this:
1089
1090 char *
1091 create_world (x, y, scale)
1092 int x;
1093 int y;
1094 float scale;
1095 {
1096 . . .
1097 }
1098
1099 For compatibility with other versions of indent, the option ‘-nip’ is
1100 provided, which is equivalent to ‘-ip0’.
1101
1102 ANSI C allows white space to be placed on preprocessor command lines
1103 between the character ‘#’ and the command name. By default, indent
1104 removes this space, but specifying the ‘-lps’ option directs indent to
1105 leave this space unmodified. The option ‘-ppi’ overrides ‘-nlps’ and
1106 ‘-lps’.
1107
1108 This option can be used to request that preprocessor conditional state‐
1109 ments can be indented by to given number of spaces, for example with
1110 the option ‘-ppi 3’
1111
1112 #if X
1113 #if Y
1114 #define Z 1
1115 #else
1116 #define Z 0
1117 #endif
1118 #endif
1119 becomes
1120 #if X
1121 # if Y
1122 # define Z 1
1123 # else
1124 # define Z 0
1125 # endif
1126 #endif
1127
1128 This option sets the offset at which a label (except case labels) will
1129 be positioned. If it is set to zero or a positive number, this indi‐
1130 cates how far from the left margin to indent a label. If it is set to
1131 a negative number, this indicates how far back from the current indent
1132 level to place the label. The default setting is -2 which matches the
1133 behaviour of earlier versions of indent. Note that this parameter does
1134 not affect the placing of case labels; see the ‘-cli’ parameter for
1135 that. For example with the option ‘-il 1’
1136
1137 group
1138 function()
1139 {
1140 if (do_stuff1() == ERROR)
1141 goto cleanup1;
1142
1143 if (do_stuff2() == ERROR)
1144 goto cleanup2;
1145
1146 return SUCCESS;
1147
1148 cleanup2:
1149 do_cleanup2();
1150
1151 cleanup1:
1152 do_cleanup1();
1153
1154 return ERROR;
1155 }
1156 becomes
1157 group
1158 function()
1159 {
1160 if (do_stuff1() == ERROR)
1161 goto cleanup1;
1162
1163 if (do_stuff2() == ERROR)
1164 goto cleanup2;
1165
1166 return SUCCESS;
1167
1168 cleanup2:
1169 do_cleanup2();
1170
1171 cleanup1:
1172 do_cleanup1();
1173
1174 return ERROR;
1175 }
1176
1177
1179 With the option ‘-ln’, or ‘--line-lengthn’, it is possible to specify
1180 the maximum length of a line of C code, not including possible comments
1181 that follow it.
1182
1183 When lines become longer than the specified line length, GNU indent
1184 tries to break the line at a logical place. This is new as of version
1185 2.1 however and not very intelligent or flexible yet.
1186
1187 Currently there are two options that allow one to interfere with the
1188 algorithm that determines where to break a line.
1189
1190 The ‘-bbo’ option causes GNU indent to prefer to break long lines
1191 before the boolean operators && and ||. The ‘-nbbo’ option causes GNU
1192 indent not have that preference. For example, the default option
1193 ‘-bbo’ (together with ‘--line-length60’ and ‘--ignore-newlines’) makes
1194 code look like this:
1195
1196 if (mask
1197 && ((mask[0] == ’\0’)
1198 || (mask[1] == ’\0’
1199 && ((mask[0] == ’0’) || (mask[0] == ’*’)))))
1200
1201 Using the option ‘-nbbo’ will make it look like this:
1202
1203 if (mask &&
1204 ((mask[0] == ’\0’) ||
1205 (mask[1] == ’\0’ &&
1206 ((mask[0] == ’0’) || (mask[0] == ’*’)))))
1207
1208 The default ‘-hnl’, however, honours newlines in the input file by giv‐
1209 ing them the highest possible priority to break lines at. For example,
1210 when the input file looks like this:
1211
1212 if (mask
1213 && ((mask[0] == ’\0’)
1214 || (mask[1] == ’\0’ && ((mask[0] == ’0’) || (mask[0] == ’*’)))))
1215
1216 then using the option ‘-hnl’, or ‘--honour-newlines’, together with the
1217 previously mentioned ‘-nbbo’ and ‘--line-length60’, will cause the out‐
1218 put not to be what is given in the last example but instead will prefer
1219 to break at the positions where the code was broken in the input file:
1220
1221 if (mask
1222 && ((mask[0] == ’\0’)
1223 || (mask[1] == ’\0’ &&
1224 ((mask[0] == ’0’) || (mask[0] == ’*’)))))
1225
1226 The idea behind this option is that lines which are too long, but are
1227 already broken up, will not be touched by GNU indent. Really messy
1228 code should be run through indent at least once using the ‘--ignore-
1229 newlines’ option though.
1230
1231
1233 Formatting of C code may be disabled for portions of a program by
1234 embedding special control comments in the program. To turn off format‐
1235 ting for a section of a program, place the disabling control comment /*
1236 *INDENT-OFF* */ on a line by itself just before that section. Program
1237 text scanned after this control comment is output precisely as input
1238 with no modifications until the corresponding enabling comment is
1239 scanned on a line by itself. The disabling control comment is /*
1240 *INDENT-ON* */, and any text following the comment on the line is also
1241 output unformatted. Formatting begins again with the input line fol‐
1242 lowing the enabling control comment.
1243
1244 More precisely, indent does not attempt to verify the closing delimiter
1245 (*/) for these C comments, and any whitespace on the line is totally
1246 transparent.
1247
1248 These control comments also function in their C++ formats, namely //
1249 *INDENT-OFF* and // *INDENT-ON*.
1250
1251 It should be noted that the internal state of indent remains unchanged
1252 over the course of the unformatted section. Thus, for example, turning
1253 off formatting in the middle of a function and continuing it after the
1254 end of the function may lead to bizarre results. It is therefore wise
1255 to be somewhat modular in selecting code to be left unformatted.
1256
1257 As a historical note, some earlier versions of indent produced error
1258 messages beginning with *INDENT**. These versions of indent were writ‐
1259 ten to ignore any input text lines which began with such error mes‐
1260 sages. I have removed this incestuous feature from GNU indent.
1261
1262
1264 To find out what version of indent you have, use the command indent
1265 -version. This will report the version number of indent, without doing
1266 any of the normal processing.
1267
1268 The ‘-v’ option can be used to turn on verbose mode. When in verbose
1269 mode, indent reports when it splits one line of input into two more
1270 more lines of output, and gives some size statistics at completion.
1271
1272 The ‘-pmt’ option causes indent to preserve the access and modification
1273 times on the output files. Using this option has the advantage that
1274 running indent on all source and header files in a project won’t cause
1275 make to rebuild all targets. This option is only available on Operat‐
1276 ing Systems that have the POSIX utime(2) function.
1277
1278
1280 Please report any bugs to bug-indent@gnu.org.
1281
1282 When indent is run twice on a file, with the same profile, it should
1283 never change that file the second time. With the current design of
1284 indent, this can not be guaranteed, and it has not been extensively
1285 tested.
1286
1287 indent does not understand C. In some cases this leads to the inability
1288 to join lines. The result is that running a file through indent is
1289 irreversible, even if the used input file was the result of running
1290 indent with a given profile (‘.indent.pro’).
1291
1292 While an attempt was made to get indent working for C++, it will not do
1293 a good job on any C++ source except the very simplest.
1294
1295 indent does not look at the given ‘--line-length’ option when writing
1296 comments to the output file. This results often in comments being put
1297 far to the right. In order to prohibit indent from joining a broken
1298 line that has a comment at the end, make sure that the comments start
1299 on the first line of the break.
1300
1301 indent does not count lines and comments (see the ‘-v’ option) when
1302 indent is turned off with /* *INDENT-OFF* */.
1303
1304 Comments of the form /*UPPERCASE*/ are not treated as comment but as an
1305 identifier, causing them to be joined with the next line. This renders
1306 comments of this type useless, unless they are embedded in the code to
1307 begin with.
1308
1309
1311 The following copyright notice applies to the indent program. The
1312 copyright and copying permissions for this manual appear near the
1313 beginning of ‘indent.texinfo’ and ‘indent.info’, and near the end of
1314 ‘indent.1’.
1315
1316 Copyright (c) 2001 David Ingamells.
1317 Copyright (c) 1999 Carlo Wood.
1318 Copyright (c) 1995, 1996 Joseph Arceneaux.
1319 Copyright (c) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation
1320 Copyright (c) 1985 Sun Microsystems, Inc.
1321 Copyright (c) 1980 The Regents of the University of California.
1322 Copyright (c) 1976 Board of Trustees of the University of Illinois.
1323 All rights reserved.
1324
1325 Redistribution and use in source and binary forms are permitted
1326 provided that the above copyright notice and this paragraph are
1327 duplicated in all such forms and that any documentation,
1328 advertising materials, and other materials related to such
1329 distribution and use acknowledge that the software was developed
1330 by the University of California, Berkeley, the University of Illinois,
1331 Urbana, and Sun Microsystems, Inc. The name of either University
1332 or Sun Microsystems may not be used to endorse or promote products
1333 derived from this software without specific prior written permission.
1334 THIS SOFTWARE IS PROVIDED ‘‘AS IS’’ AND WITHOUT ANY EXPRESS OR
1335 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1336 WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1337 PURPOSE.
1338
1339
1341 Here is a list of options alphabetized by long option, to help you find
1342 the corresponding short option.
1343
1344
1345 --blank-lines-after-commas -bc
1346 --blank-lines-after-declarations -bad
1347 --blank-lines-after-procedures -bap
1348 --blank-lines-before-block-comments -bbb
1349 --braces-after-if-line -bl
1350 --braces-after-func-def-line -blf
1351 --brace-indent -bli
1352 --braces-after-struct-decl-line -bls
1353 --braces-on-if-line -br
1354 --braces-on-func-def-line -brf
1355 --braces-on-struct-decl-line -brs
1356 --break-after-boolean-operator -nbbo
1357 --break-before-boolean-operator -bbo
1358 --break-function-decl-args -bfda
1359 --break-function-decl-args-end -bfde
1360 --case-indentation -clin
1361 --case-brace-indentation -cbin
1362 --comment-delimiters-on-blank-lines -cdb
1363 --comment-indentation -cn
1364 --continuation-indentation -cin
1365 --continue-at-parentheses -lp
1366 --cuddle-do-while -cdw
1367 --cuddle-else -ce
1368 --declaration-comment-column -cdn
1369 --declaration-indentation -din
1370 --dont-break-function-decl-args -nbfda
1371 --dont-break-function-decl-args-end -nbfde
1372 --dont-break-procedure-type -npsl
1373 --dont-cuddle-do-while -ncdw
1374 --dont-cuddle-else -nce
1375 --dont-format-comments -nfca
1376 --dont-format-first-column-comments -nfc1
1377 --dont-line-up-parentheses -nlp
1378 --dont-left-justify-declarations -ndj
1379 --dont-space-special-semicolon -nss
1380 --dont-star-comments -nsc
1381 --else-endif-column -cpn
1382 --format-all-comments -fca
1383 --format-first-column-comments -fc1
1384 --gnu-style -gnu
1385 --honour-newlines -hnl
1386 --ignore-newlines -nhnl
1387 --ignore-profile -npro
1388 --indent-label -iln
1389 --indent-level -in
1390 --k-and-r-style -kr
1391 --leave-optional-blank-lines -nsob
1392 --leave-preprocessor-space -lps
1393 --left-justify-declarations -dj
1394 --line-comments-indentation -dn
1395 --line-length -ln
1396 --linux-style -linux
1397 --no-blank-lines-after-commas -nbc
1398 --no-blank-lines-after-declarations -nbad
1399 --no-blank-lines-after-procedures -nbap
1400 --no-blank-lines-before-block-comments -nbbb
1401 --no-comment-delimiters-on-blank-lines -ncdb
1402 --no-space-after-casts -ncs
1403 --no-parameter-indentation -nip
1404 --no-space-after-for -nsaf
1405 --no-space-after-function-call-names -npcs
1406 --no-space-after-if -nsai
1407 --no-space-after-parentheses -nprs
1408 --no-space-after-while -nsaw
1409 --no-tabs -nut
1410 --no-verbosity -nv
1411 --original -orig
1412 --parameter-indentation -ipn
1413 --paren-indentation -pin
1414 --preserve-mtime -pmt
1415 --preprocessor-indentation -ppin
1416 --procnames-start-lines -psl
1417 --remove-preprocessor-space -nlps
1418 --space-after-cast -cs
1419 --space-after-for -saf
1420 --space-after-if -sai
1421 --space-after-parentheses -prs
1422 --space-after-procedure-calls -pcs
1423 --space-after-while -saw
1424 --space-special-semicolon -ss
1425 --standard-output -st
1426 --start-left-side-of-comments -sc
1427 --struct-brace-indentation -sbin
1428 --swallow-optional-blank-lines -sob
1429 --tab-size -tsn
1430 --use-tabs -ut
1431 --verbose -v
1432
1433
1435 Unknown
1436
1438 $HOME/.indent.pro holds default options for indent.
1439
1441 Carlo Wood
1442 Joseph Arceneaux
1443 Jim Kingdon
1444 David Ingamells
1445
1447 Derived from the UCB program "indent".
1448
1450 Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Founda‐
1451 tion, Inc. Copyright (C) 1995, 1996 Joseph Arceneaux. Copyright (C)
1452 1999 Carlo Wood. Copyright (C) 2001 David Ingamells.
1453
1454 Permission is granted to make and distribute verbatim copies of this
1455 manual provided the copyright notice and this permission notice are
1456 preserved on all copies.
1457
1458
1459
1460
1461
1462 INDENT(1L)