3
indent \- changes the appearance of a C program by inserting or deleting whitespace.
6
[options] [input\-files]
9
[options] [single\-input\-file] [\-o output\-file]
14
This man page is generated from the file \fIindent.texinfo\fR.
15
This is Edition of "The \fBindent\fR Manual",
16
for Indent Version , last updated .
18
The \fBindent\fR program
19
can be used to make code easier to read. It can also convert from one
20
style of writing C to another.
22
.B indent\fR understands a substantial amount about the syntax of C,
23
but it also attempts to cope with incomplete and misformed syntax.
25
In version 1.2 and more recent versions, the GNU style of indenting is
30
.B -bad\fR, \fB--blank-lines-after-declarations\fR
31
Force blank lines after the declarations.
33
See \fB\ BLANK\ LINES\fR.
35
.B -bap\fR, \fB--blank-lines-after-procedures\fR
36
Force blank lines after procedure bodies.
38
See \fB\ BLANK\ LINES\fR.
40
.B -bbb\fR, \fB--blank-lines-before-block-comments\fR
41
Force blank lines before block comments.
43
See \fB\ BLANK\ LINES\fR.
45
.B -bbo\fR, \fB--break-before-boolean-operator\fR
46
Prefer to break long lines before boolean operators.
48
See \fB\ BREAKING\ LONG\ LINES\fR.
50
.B -bc\fR, \fB--blank-lines-after-commas\fR
51
Force newline after comma in declaration.
53
See \fB\ DECLARATIONS\fR.
55
.B -bl\fR, \fB--braces-after-if-line\fR
56
Put braces on line after \fBif\fR, etc.
58
See \fB\ STATEMENTS\fR.
60
.B -bli\fIn\fB\fR, \fB--brace-indent\fIn\fB\fR
61
Indent braces \fIn\fR spaces.
63
See \fB\ STATEMENTS\fR.
65
.B -bls\fR, \fB--braces-after-struct-decl-line\fR
66
Put braces on the line after \fBstruct\fR declaration lines.
68
See \fB\ DECLARATIONS\fR.
70
.B -br\fR, \fB--braces-on-if-line\fR
71
Put braces on line with \fBif\fR, etc.
73
See \fB\ STATEMENTS\fR.
75
.B -brs\fR, \fB--braces-on-struct-decl-line\fR
76
Put braces on \fBstruct\fR declaration line.
78
See \fB\ DECLARATIONS\fR.
80
.B -bs\fR, \fB--Bill-Shannon\fR, \fB--blank-before-sizeof\fR
81
Put a space between \fBsizeof\fR and its argument.
83
See \fB\ STATEMENTS\fR.
85
.B -c\fIn\fB\fR, \fB--comment-indentation\fIn\fB\fR
86
Put comments to the right of code in column \fIn\fR.
90
.B -cbi\fIn\fB\fR, \fB--case-brace-indentation\fIn\fB\fR
91
Indent braces after a case label N spaces.
93
See \fB\ STATEMENTS\fR.
95
.B -cd\fIn\fB\fR, \fB--declaration-comment-column\fIn\fB\fR
96
Put comments to the right of the declarations in column \fIn\fR.
100
.B -cdb\fR, \fB--comment-delimiters-on-blank-lines\fR
101
Put comment delimiters on blank lines.
103
See \fB\ COMMENTS\fR.
105
.B -cdw\fR, \fB--cuddle-do-while\fR
106
Cuddle while of \fBdo {} while;\fR and preceeding \`}\'.
108
See \fB\ COMMENTS\fR.
110
.B -ce\fR, \fB--cuddle-else\fR
111
Cuddle else and preceeding \`}\'.
113
See \fB\ COMMENTS\fR.
115
.B -ci\fIn\fB\fR, \fB--continuation-indentation\fIn\fB\fR
116
Continuation indent of \fIn\fR spaces.
118
See \fB\ STATEMENTS\fR.
120
.B -cli\fIn\fB\fR, \fB--case-indentation\fIn\fB\fR
121
Case label indent of \fIn\fR spaces.
123
See \fB\ STATEMENTS\fR.
125
.B -cp\fIn\fB\fR, \fB--else-endif-column\fIn\fB\fR
126
Put comments to the right of \fB#else\fR and \fB
127
#endif\fR statements in column \fIn\fR.
129
See \fB\ COMMENTS\fR.
131
.B -cs\fR, \fB--space-after-cast\fR
132
Put a space after a cast operator.
134
See \fB\ STATEMENTS\fR.
136
.B -d\fIn\fB\fR, \fB--line-comments-indentation\fIn\fB\fR
137
Set indentation of comments not to the right
138
of code to \fIn\fR spaces.
140
See \fB\ COMMENTS\fR.
142
.B -bfda\fR, \fB--break-function-decl-args\fR
143
Align all arguments in a declaration with opening paren.
145
See \fB\ DECLARATIONS\fR.
147
.B -di\fIn\fB\fR, \fB--declaration-indentation\fIn\fB\fR
148
Put variables in column \fIn\fR.
150
See \fB\ DECLARATIONS\fR.
152
.B -fc1\fR, \fB--format-first-column-comments\fR
153
Format comments in the first column.
155
See \fB\ COMMENTS\fR.
157
.B -fca\fR, \fB--format-all-comments\fR
158
Do not disable all formatting of comments.
160
See \fB\ COMMENTS\fR.
162
.B -gnu\fR, \fB--gnu-style\fR
163
Use GNU coding style. This is the default.
165
See \fB\ COMMON\ STYLES\fR.
167
.B -hnl\fR, \fB--honour-newlines\fR
168
Prefer to break long lines at the position of newlines in the input.
170
See \fB\ BREAKING\ LONG\ LINES\fR.
172
.B -i\fIn\fB\fR, \fB--indent-level\fIn\fB\fR
173
Set indentation level to \fIn\fR spaces.
175
See \fB\ INDENTATION\fR.
177
.B -ip\fIn\fB\fR, \fB--parameter-indentation\fIn\fB\fR
178
Indent parameter types in old-style function
179
definitions by \fIn\fR spaces.
181
See \fB\ INDENTATION\fR.
183
.B -kr\fR, \fB--k-and-r-style\fR
184
Use Kernighan & Ritchie coding style.
186
See \fB\ COMMON\ STYLES\fR.
188
.B -l\fIn\fB\fR, \fB--line-length\fIn\fB\fR
189
Set maximum line length for non-comment lines to \fIn\fR.
191
See \fB\ BREAKING\ LONG\ LINES\fR.
193
.B -lc\fIn\fB\fR, \fB--comment-line-length\fIn\fB\fR
194
Set maximum line length for comment formatting to \fIn\fR.
196
See \fB\ COMMENTS\fR.
198
.B -lp\fR, \fB--continue-at-parentheses\fR
199
Line up continued lines at parentheses.
201
See \fB\ INDENTATION\fR.
203
.B -lps\fR, \fB--leave-preprocessor-space\fR
204
Leave space between \`#\' and preprocessor directive.
206
See \fB\ INDENTATION\fR.
208
.B -nbad\fR, \fB--no-blank-lines-after-declarations\fR
209
Do not force blank lines after declarations.
211
See \fB\ BLANK\ LINES\fR.
213
.B -nbap\fR, \fB--no-blank-lines-after-procedures\fR
214
Do not force blank lines after procedure bodies.
216
See \fB\ BLANK\ LINES\fR.
218
.B -nbbo\fR, \fB--break-after-boolean-operator\fR
219
Do not prefer to break long lines before boolean operators.
221
See \fB\ BREAKING\ LONG\ LINES\fR.
223
.B -nbc\fR, \fB--no-blank-lines-after-commas\fR
224
Do not force newlines after commas in declarations.
226
See \fB\ DECLARATIONS\fR.
228
.B -nbfda\fR, \fB--dont-break-function-decl-args\fR
229
Don\'t put each argument in a function declaration on a seperate line.
231
See \fB\ DECLARATIONS\fR.
233
.B -ncdb\fR, \fB--no-comment-delimiters-on-blank-lines\fR
234
Do not put comment delimiters on blank lines.
236
See \fB\ COMMENTS\fR.
238
.B -ncdw\fR, \fB--dont-cuddle-do-while\fR
239
Do not cuddle \fB}\fR and the \fBwhile\fR of a \fBdo {} while;\fR.
241
See \fB\ STATEMENTS\fR.
243
.B -nce\fR, \fB--dont-cuddle-else\fR
244
Do not cuddle \fB}\fR and \fBelse\fR.
246
See \fB\ STATEMENTS\fR.
248
.B -ncs\fR, \fB--no-space-after-casts\fR
249
Do not put a space after cast operators.
251
See \fB\ STATEMENTS\fR.
253
.B -nfc1\fR, \fB--dont-format-first-column-comments\fR
254
Do not format comments in the first column as normal.
256
See \fB\ COMMENTS\fR.
258
.B -nfca\fR, \fB--dont-format-comments\fR
259
Do not format any comments.
261
See \fB\ COMMENTS\fR.
263
.B -nhnl\fR, \fB--ignore-newlines\fR
264
Do not prefer to break long lines at the position of newlines in the input.
266
See \fB\ BREAKING\ LONG\ LINES\fR.
268
.B -nip\fR, \fB--no-parameter-indentation\fR
269
Zero width indentation for parameters.
271
See \fB\ INDENTATION\fR.
273
.B -nlp\fR, \fB--dont-line-up-parentheses\fR
274
Do not line up parentheses.
276
See \fB\ STATEMENTS\fR.
278
.B -npcs\fR, \fB--no-space-after-function-call-names\fR
279
Do not put space after the function in function calls.
281
See \fB\ STATEMENTS\fR.
283
.B -nprs\fR, \fB--no-space-after-parentheses\fR
284
Do not put a space after every \'(\' and before every \')\'.
286
See \fB\ STATEMENTS\fR.
288
.B -npsl\fR, \fB--dont-break-procedure-type\fR
289
Put the type of a procedure on the same line as its name.
291
See \fB\ DECLARATIONS\fR.
293
.B -nsaf\fR, \fB--no-space-after-for\fR
294
Do not put a space after every \fBfor\fR.
296
See \fB\ STATEMENTS\fR.
298
.B -nsai\fR, \fB--no-space-after-if\fR
299
Do not put a space after every \fBif\fR.
301
See \fB\ STATEMENTS\fR.
303
.B -nsaw\fR, \fB--no-space-after-while\fR
304
Do not put a space after every \fBwhile\fR.
306
See \fB\ STATEMENTS\fR.
308
.B -nsc\fR, \fB--dont-star-comments\fR
309
Do not put the \`*\' character at the left of comments.
311
See \fB\ COMMENTS\fR.
313
.B -nsob\fR, \fB--leave-optional-blank-lines\fR
314
Do not swallow optional blank lines.
316
See \fB\ BLANK\ LINES\fR.
318
.B -nss\fR, \fB--dont-space-special-semicolon\fR
319
Do not force a space before the semicolon after certain statements.
322
See \fB\ STATEMENTS\fR.
324
.B -nut\fR, \fB--no-tabs\fR
325
Use spaces instead of tabs.
327
See \fB\ INDENTATION\fR.
329
.B -nv\fR, \fB--no-verbosity\fR
330
Disable verbose mode.
332
See \fB\ MISCELLANEOUS\ OPTIONS\fR.
334
.B -orig\fR, \fB--original\fR
335
Use the original Berkeley coding style.
337
See \fB\ COMMON\ STYLES\fR.
339
.B -npro\fR, \fB--ignore-profile\fR
340
Do not read \`.indent.pro\' files.
342
See \fB\ INVOKING\ INDENT\fR.
344
.B -pcs\fR, \fB--space-after-procedure-calls\fR
345
Insert a space between the name of the
346
procedure being called and the \`(\'.
348
See \fB\ STATEMENTS\fR.
350
.B -pi\fIn\fB\fR, \fB--paren-indentation\fIn\fB\fR
351
Specify the extra indentation per open parentheses \'(\' when a
352
statement is broken.See \fB\ STATEMENTS\fR.
354
.B -pmt\fR, \fB--preserve-mtime\fR
355
Preserve access and modification times on output files.See \fB\ MISCELLANEOUS\ OPTIONS\fR.
357
.B -prs\fR, \fB--space-after-parentheses\fR
358
Put a space after every \'(\' and before every \')\'.
360
See \fB\ STATEMENTS\fR.
362
.B -psl\fR, \fB--procnames-start-lines\fR
363
Put the type of a procedure on the line before its name.
365
See \fB\ DECLARATIONS\fR.
367
.B -saf\fR, \fB--space-after-for\fR
368
Put a space after each \fBfor\fR.
370
See \fB\ STATEMENTS\fR.
372
.B -sai\fR, \fB--space-after-if\fR
373
Put a space after each \fBif\fR.
375
See \fB\ STATEMENTS\fR.
377
.B -saw\fR, \fB--space-after-while\fR
378
Put a space after each \fBwhile\fR.
380
See \fB\ STATEMENTS\fR.
382
.B -sbi\fIn\fB\fR, \fB--struct-brace-indentation\fIn\fB\fR
383
Indent braces of a struct, union or enum N spaces.
385
See \fB\ STATEMENTS\fR.
387
.B -sc\fR, \fB--start-left-side-of-comments\fR
388
Put the \`*\' character at the left of comments.
390
See \fB\ COMMENTS\fR.
392
.B -sob\fR, \fB--swallow-optional-blank-lines\fR
393
Swallow optional blank lines.
395
See \fB\ BLANK\ LINES\fR.
397
.B -ss\fR, \fB--space-special-semicolon\fR
398
On one-line \fBfor\fR and \fBwhile\fR statments,
399
force a blank before the semicolon.
401
See \fB\ STATEMENTS\fR.
403
.B -st\fR, \fB--standard-output\fR
404
Write to standard output.
406
See \fB\ INVOKING\ INDENT\fR.
409
Tell \fBindent\fR the name of typenames.
411
See \fB\ DECLARATIONS\fR.
413
.B -ts\fIn\fB\fR, \fB--tab-size\fIn\fB\fR
414
Set tab size to \fIn\fR spaces.
416
See \fB\ INDENTATION\fR.
418
.B -ut\fR, \fB--use-tabs\fR
419
Use tabs. This is the default.
421
See \fB\ INDENTATION\fR.
423
.B -v\fR, \fB--verbose\fR
426
See \fB\ MISCELLANEOUS\ OPTIONS\fR.
429
Output the version number of \fBindent\fR.
431
See \fB\ MISCELLANEOUS\ OPTIONS\fR.
433
.SH "INVOKING INDENT"
435
As of version 1.3, the format of the \fBindent\fR command is:
441
indent [\fIoptions\fR] [\fIinput-files\fR]
443
indent [\fIoptions\fR] [\fIsingle-input-file\fR] [-o \fIoutput-file\fR]
449
This format is different from earlier versions and other versions of
452
In the first form, one or more input files are specified. \fBindent\fR
453
makes a backup copy of each file, and the original file is replaced with
454
its indented version. See \fBBACKUP\ FILES\fR, for an explanation of how
457
In the second form, only one input file is specified. In this case, or
458
when the standard input is used, you may specify an output file after
461
To cause \fBindent\fR to write to standard output, use the \`-st\'
462
option. This is only allowed when there is only one input file, or when
463
the standard input is used.
465
If no input files are named, the standard input is read for input.
466
Also, if a filename named \`-\' is specified, then the standard input
469
As an example, each of the following commands will input the program
470
\`slithy_toves.c\' and write its indented text to
471
\`slithy_toves.out\':
477
indent slithy_toves.c -o slithy_toves.out
479
indent -st slithy_toves.c > slithy_toves.out
481
cat slithy_toves.c | indent -o slithy_toves.out
487
Most other options to \fBindent\fR control how programs are formatted.
488
As of version 1.2, \fBindent\fR also recognizes a long name for each
489
option name. Long options are prefixed by either \`--\' or
491
[ \`+\' is being superseded by \`--\' to
492
maintain consistency with the POSIX standard.]
493
In most of this document,
494
the traditional, short names are used for the sake of brevity.
495
See \fBOPTION\ SUMMARY\fR, for a list of options, including both long and
498
Here is another example:
503
indent -br test/metabolism.c -l85
508
This will indent the program \`test/metabolism.c\' using the
509
\`-br\' and \`-l85\' options, write the output back to
510
\`test/metabolism.c\', and write the original contents of
511
\`test/metabolism.c\' to a backup file in the directory \`test\'.
513
Equivalent invocations using long option names for this example would
520
indent --braces-on-if-line --line-length185 test/metabolism.c
522
indent +braces-on-if-line +line-length185 test/metabolism.c
528
If you find that you often use \fBindent\fR with the same options, you
529
may put those options into a file named \`.indent.pro\'.
530
.B indent\fR will first look for \`.indent.pro\' in the current
531
directory and use that if found. Otherwise, \fBindent\fR will search
532
your home directory for \`.indent.pro\' and use that file if it is
533
found. This behaviour is different from that of other versions of
534
.B indent\fR, which load both files if they both exist.
536
The format of \`.indent.pro\' is simply a list of options, just as
537
they would appear on the command line, separated by white space (tabs,
538
spaces, and newlines). Options in \`.indent.pro\' may be surrounded by C
539
or C++ comments, in which case they are ignored.
541
Command line switches are handled \fIafter\fR processing
542
\`.indent.pro\'. Options specified later override arguments
543
specified earlier, with one exception: Explicitly specified options
544
always override background options (See \fBCOMMON\ STYLES\fR). You can
545
prevent \fBindent\fR from reading an \`.indent.pro\' file by
546
specifying the \`-npro\' option.
550
As of version 1.3, GNU \fBindent\fR makes GNU-style backup files, the
551
same way GNU Emacs does. This means that either \fIsimple\fR or
552
.I numbered\fR backup filenames may be made.
554
Simple backup file names are generated by appending a suffix to the
555
original file name. The default for this suffix is the
556
one-character string \`~\' (tilde). Thus, the backup file for
557
\`python.c\' would be \`python.c~\'.
559
Instead of the default, you may specify any string as a suffix by
560
setting the environment variable \fBSIMPLE_BACKUP_SUFFIX\fR to
561
your preferred suffix.
563
Numbered backup versions of a file \`momeraths.c\' look like
564
\`momeraths.c.~23~\', where 23 is the version of this particular
565
backup. When making a numbered backup of the file \`src/momeraths.c\',
566
the backup file will be named \`src/momeraths.c.~\fIV\fR~\', where
567
.I V\fR is one greater than the highest version currently existing in
568
the directory \`src\'. The environment variable \fBVERSION_WIDTH\fR
569
controls the number of digits, using left zero padding when necessary.
570
For instance, setting this variable to "2" will lead to the backup
571
file being named \`momeraths.c.~04~\'.
573
The type of backup file made is controlled by the value of the
574
environment variable \fBVERSION_CONTROL\fR. If it is the string
575
\`simple\', then only simple backups will be made. If its value is
576
the string \`numbered\', then numbered backups will be made. If its
577
value is \`numbered-existing\', then numbered backups will be made if
578
there \fIalready exist\fR numbered backups for the file being indented;
579
otherwise, a simple backup is made. If \fBVERSION_CONTROL\fR is not
580
set, then \fBindent\fR assumes the behaviour of
581
\`numbered-existing\'.
583
Other versions of \fBindent\fR use the suffix \`.BAK\' in naming
584
backup files. This behaviour can be emulated by setting
585
.B SIMPLE_BACKUP_SUFFIX\fR to \`.BAK\'.
587
Note also that other versions of \fBindent\fR make backups in the
588
current directory, rather than in the directory of the source file as
589
GNU \fBindent\fR now does.
593
There are several common styles of C code, including the GNU style, the
594
Kernighan & Ritchie style, and the original Berkeley style. A style may
595
be selected with a single \fIbackground\fR option, which specifies a set
596
of values for all other options. However, explicitly specified options
597
always override options implied by a background option.
599
As of version 1.2, the default style of GNU \fBindent\fR is the GNU
600
style. Thus, it is no longer necessary to specify the option
601
\`-gnu\' to obtain this format, although doing so will not cause an
602
error. Option settings which correspond to the GNU style are:
607
-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2
608
-ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai
614
The GNU coding style is that preferred by the GNU project. It is the
615
style that the GNU Emacs C mode encourages and which is used in the C
616
portions of GNU Emacs. (People interested in writing programs for
617
Project GNU should get a copy of "The GNU Coding Standards", which
618
also covers semantic and portability issues such as memory usage, the
619
size of integers, etc.)
621
The Kernighan & Ritchie style is used throughout their well-known book
622
"The C Programming Language". It is enabled with the \`-kr\'
623
option. The Kernighan & Ritchie style corresponds to the following set
629
-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0
630
-cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs
631
-nprs -npsl -saf -sai -saw -nsc -nsob -nss
636
Kernighan & Ritchie style does not put comments to the right of code in
637
the same column at all times (nor does it use only one space to the
638
right of the code), so for this style \fBindent\fR has arbitrarily
641
The style of the original Berkeley \fBindent\fR may be obtained by
642
specifying \`-orig\' (or by specifying \`--original\', using the
643
long option name). This style is equivalent to the following settings:
648
-nbad -nbap -bbo -bc -br -brs -c33 -cd33 -cdb -ce -ci4 -cli0
649
-cp33 -di16 -fc1 -fca -hnl -i4 -ip4 -l75 -lp -npcs -nprs -psl
650
-saf -sai -saw -sc -nsob -nss -ts8
657
Various programming styles use blank lines in different places.
658
.B indent\fR has a number of options to insert or delete blank lines in
661
The \`-bad\' option causes \fBindent\fR to force a blank line after
662
every block of declarations. The \`-nbad\' option causes
663
.B indent\fR not to force such blank lines.
665
The \`-bap\' option forces a blank line after every procedure body.
666
The \`-nbap\' option forces no such blank line.
668
The \`-bbb\' option forces a blank line before every boxed comment
669
(See \fBCOMMENTS\fR.)
670
The \`-nbbb\' option does not force such blank lines.
672
The \`-sob\' option causes \fBindent\fR to swallow optional blank
673
lines (that is, any optional blank lines present in the input will be
674
removed from the output). If the \`-nsob\' is specified, any blank
675
lines present in the input file will be copied to the output file.
678
.SH "--blank-lines-after-declarations"
680
The \`-bad\' option forces a blank line after every block of
681
declarations. The \`-nbad\' option does not add any such blank
684
For example, given the input
690
/* This separates blocks of declarations. */
696
.B indent -bad\fR produces
704
/* This separates blocks of declarations. */
710
and \fBindent -nbad\fR produces
717
/* This separates blocks of declarations. */
723
.SH "--blank-lines-after-procedures"
725
The \`-bap\' option forces a blank line after every procedure body.
727
For example, given the input
737
/* The procedure bar is even less interesting. */
747
.B indent -bap\fR produces
758
/* The procedure bar is even less interesting. */
768
and \fBindent -nbap\fR produces
778
/* The procedure bar is even less interesting. */
788
No blank line will be added after the procedure \fBfoo\fR.
792
.B indent\fR formats both C and C++ comments. C comments are begun with
793
\`/*\', terminated with \`*/\' and may contain newline characters.
794
C++ comments begin with the delimiter \`//\' and end at the newline.
796
.B indent\fR handles comments differently depending upon their context.
797
.B indent\fR attempts to distinguish between comments which follow
798
statements, comments which follow declarations, comments following
799
preprocessor directives, and comments which are not preceded by code of
800
any sort, i.e., they begin the text of the line (although not
801
neccessarily in column 1).
803
.B indent\fR further distinguishes between comments found outside of
804
procedures and aggregates, and those found within them. In particular,
805
comments beginning a line found within a procedure will be indented to
806
the column at which code is currently indented. The exception to this a
807
comment beginning in the leftmost column; such a comment is output
810
.B indent\fR attempts to leave \fIboxed comments\fR unmodified. The
811
general idea of such a comment is that it is enclosed in a rectangle or
812
\`\`box\'\' of stars or dashes to visually set it apart. More precisely,
813
boxed comments are defined as those in which the initial \`/*\' is
814
followed immediately by the character \`*\', \`=\', \`_\', or
815
\`-\', or those in which the beginning comment delimiter (\`/*\')
816
is on a line by itself, and the following line begins with a \`*\' in
817
the same column as the star of the opening delimiter.
819
Examples of boxed comments are:
824
/**********************
825
* Comment in a box!! *
826
**********************/
829
* A different kind of scent,
830
* for a different kind of comment.
836
.B indent\fR attempts to leave boxed comments exactly as they are found
837
in the source file. Thus the indentation of the comment is unchanged,
838
and its length is not checked in any way. The only alteration made is
839
that an embedded tab character may be converted into the appropriate
842
If the \`-bbb\' option is specified, all such boxed comments will be
843
preceded by a blank line, unless such a comment is preceded by code.
845
Comments which are not boxed comments may be formatted, which means that
846
the line is broken to fit within a right margin and left-filled with
847
whitespace. Single newlines are equivalent to a space, but blank lines
848
(two or more newlines in a row) are taken to mean a paragraph break.
849
Formatting of comments which begin after the first column is enabled
850
with the \`-fca\' option. To format those beginning in column one,
851
specify \`-fc1\'. Such formatting is disabled by default.
853
The right margin for formatting defaults to 78, but may be changed with
854
the \`-lc\' option. If the margin specified does not allow the
855
comment to be printed, the margin will be automatically extended for the
856
duration of that comment. The margin is not respected if the comment is
859
If the comment begins a line (i.e., there is no program text to its
860
left), it will be indented to the column it was found in unless the
861
comment is within a block of code. In that case, such a comment will be
862
aligned with the indented code of that block (unless the comment began
863
in the first column). This alignment may be affected by the \`-d\'
864
option, which specifies an amount by which such comments are moved to
865
the \fIleft\fR, or unindented. For example, \`-d2\' places comments
866
two spaces to the left of code. By default, comments are aligned with
867
code, unless they begin in the first column, in which case they are left
868
there by default --- to get them aligned with the code, specify \`-fc1\'.
870
Comments to the right of code will appear by default in column 33.
871
This may be changed with one of three options. \`-c\' will specify
872
the column for comments following code, \`-cd\' specifies the
873
column for comments following declarations, and \`-cp\' specifies
874
the column for comments following preprocessor directives \fB#else\fR
877
If the code to the left of the comment exceeds the beginning column,
878
the comment column will be extended to the next tabstop column past
879
the end of the code, or in the case of preprocessor directives, to one
880
space past the end of the directive. This extension lasts only for
881
the output of that particular comment.
883
The \`-cdb\' option places the comment delimiters on blank lines.
884
Thus, a single line comment like \fB/* Loving hug */\fR can be
897
Stars can be placed at the beginning of multi-line comments with the
898
\`-sc\' option. Thus, the single-line comment above can be
899
transformed (with \`-cdb -sc\') into:
913
The \`-br\' or \`-bl\' option specifies how to format braces.
915
The \`-br\' option formats statement braces like this:
927
The \`-bl\' option formats them like this:
940
If you use the \`-bl\' option, you may also want to specify the
941
\`-bli\' option. This option specifies the number of spaces by
942
which braces are indented. \`-bli2\', the default, gives the
943
result shown above. \`-bli0\' results in the following:
956
If you are using the \`-br\' option, you probably want to also use
957
the \`-ce\' option. This causes the \fBelse\fR in an if-then-else
958
construct to cuddle up to the immediately preceding \`}\'. For
959
example, with \`-br -ce\' you get the following:
967
fprintf (stderr, "...something wrong?\\n");
973
With \`-br -nce\' that code would appear as
982
fprintf (stderr, "...something wrong?\\n");
988
This causes the \fBwhile\fR in a do-while
989
loop to cuddle up to the immediately preceding \`}\'. For
990
example, with \`-cdw\' you get the following:
1002
With \`-ncdw\' that code would appear as
1015
The \`-cli\' option specifies the number of spaces that case labels
1016
should be indented to the right of the containing \fBswitch\fR
1019
The default gives code like:
1039
Using the \`-cli2\' that would become:
1059
The indentation of the braces below a case statement can be
1060
controlled with the \`-cbi\fIn\fR\' option. For example,
1061
using \`-cli2 -cbi0\' results in:
1081
If a semicolon is on the same line as a \fBfor\fR or \fBwhile\fR
1082
statement, the \`-ss\' option will cause a space to be placed before
1083
the semicolon. This emphasizes the semicolon, making it clear that the
1084
body of the \fBfor\fR or \fBwhile\fR statement is an empty statement.
1085
\`-nss\' disables this feature.
1087
The \`-pcs\' option causes a space to be placed between the name of
1088
the procedure being called and the \`(\' (for example, \fBputs\ ("Hi");\fR. The \`-npcs\' option would give \fBputs("Hi");\fR).
1091
If the \`-cs\' option is specified, \fBindent\fR puts a space after
1094
The \`-bs\' option ensures that there is a space between the
1095
keyword \fBsizeof\fR and its argument. In some versions, this is
1096
known as the \`Bill_Shannon\' option.
1098
The \`-saf\' option forces a space between an \fBfor\fR
1099
and the following parenthesis. This is the default.
1101
The \`-sai\' option forces a space between an \fBif\fR
1102
and the following parenthesis. This is the default.
1104
The \`-saw\' option forces a space between an \fBwhile\fR
1105
and the following parenthesis. This is the default.
1107
The \`-prs\' option causes all parentheses to be seperated with
1108
a space from the what is between them. For example, using \`-prs\'
1109
results in code like:
1114
while ( ( e_code - s_code ) < ( dec_ind - 1 ) )
1116
set_buf_break ( bb_dec_ind );
1125
By default \fBindent\fR will line up identifiers, in the column
1126
specified by the \`-di\' option. For example, \`-di16\' makes
1138
Using a small value (such as one or two) for the \`-di\' option can
1139
be used to cause the identifiers to be placed in the first available
1140
position; for example:
1151
The value given to the \`-di\' option will still affect variables
1152
which are put on separate lines from their types, for example
1153
\`-di2\' will lead to:
1164
If the \`-bc\' option is specified, a newline is forced after each
1165
comma in a declaration. For example,
1177
With the \`-nbc\' option this would look like
1187
The \`-bfda\' option causes a newline to be forced after the comma
1188
separating the arguments of a function declaration. The arguments will
1189
appear at the current indention level matching the opening paren. This
1190
is particularly helpful for functions with long argument lists. For
1196
void foo (int arg1, char arg2, int *arg3, long arg4, char arg5);
1200
With the \`-bfda\' option this would look like
1214
The \`-psl\' option causes the type of a procedure being defined to
1215
be placed on the line before the name of the procedure. This style is
1216
required for the \fBetags\fR program to work correctly, as well as some
1217
of the \fBc-mode\fR functions of Emacs.
1219
You must use the \`-T\'
1220
option to tell \fBindent\fR the name of all the typenames in your
1221
program that are defined by \fBtypedef\fR. \`-T\' can be specified
1222
more than once, and all names specified are used. For example, if your
1228
typedef unsigned long CODE_ADDR;
1229
typedef enum {red, blue, green} COLOR;
1234
you would use the options \`-T CODE_ADDR -T COLOR\'.
1236
The \`-brs\' or \`-bls\' option specifies how to format braces
1237
in struct declarations. The \`-brs\' option formats braces like
1250
The \`-bls\' option formats them like this:
1265
One issue in the formatting of code is how far each line should be
1266
indented from the left margin. When the beginning of a statement such
1267
as \fBif\fR or \fBfor\fR is encountered, the indentation level is
1268
increased by the value specified by the \`-i\' option. For example,
1269
use \`-i8\' to specify an eight character indentation for each
1270
level. When a statement is broken across two lines, the second line is
1271
indented by a number of additional spaces specified by the \`-ci\'
1272
option. \`-ci\' defaults to 0. However, if the \`-lp\' option is
1273
specified, and a line has a left parenthesis which is not closed on that
1274
line, then continuation lines will be lined up to start at the character
1275
position just after the left parenthesis. This processing also applies
1276
to \`[\' and applies to \`{\' when it occurs in initialization
1277
lists. For example, a piece of continued code might look like this with
1278
\`-nlp -ci3\' in effect:
1283
p1 = first_procedure (second_procedure (p2, p3),
1284
third_procedure (p4, p5));
1289
With \`-lp\' in effect the code looks somewhat clearer:
1294
p1 = first_procedure (second_procedure (p2, p3),
1295
third_procedure (p4, p5));
1300
When a statement is broken in between two or more paren pairs (...),
1301
each extra pair causes the indentation level extra indentation:
1307
k > 0) || p == 0) &&
1314
The option \`-ip\fIN\fR\' can be used to set the extra offset per paren.
1315
For instance, \`-ip0\' would format the above as:
1321
k > 0) || p == 0) &&
1328
.B indent\fR assumes that tabs are placed at regular intervals of both
1329
input and output character streams. These intervals are by default 8
1330
columns wide, but (as of version 1.2) may be changed by the \`-ts\'
1331
option. Tabs are treated as the equivalent number of spaces.
1333
The indentation of type declarations in old-style function definitions
1334
is controlled by the \`-ip\' parameter. This is a numeric parameter
1335
specifying how many spaces to indent type declarations. For example,
1336
the default \`-ip5\' makes definitions look like this:
1342
create_world (x, y, scale)
1353
For compatibility with other versions of indent, the option \`-nip\'
1354
is provided, which is equivalent to \`-ip0\'.
1356
ANSI C allows white space to be placed on preprocessor command lines
1357
between the character \`#\' and the command name. By default,
1358
.B indent\fR removes this space, but specifying the \`-lps\' option
1359
directs \fBindent\fR to leave this space unmodified.
1361
.SH "BREAKING LONG LINES"
1363
With the option \`-l\fIn\fR\', or \`--line-length\fIn\fR\', it is
1364
possible to specify the maximum length of a line of C code, not including
1365
possible comments that follow it.
1367
When lines become longer then the specified line length, GNU \fBindent\fR
1368
tries to break the line at a logical place. This is new as of version 2.1
1369
however and not very intelligent or flexible yet.
1371
Currently there are two options that allows one to interfere with the
1372
algorithm that determines where to break a line.
1374
The \`-bbo\' option causes GNU \fBindent\fR to prefer to break
1375
long lines before the boolean operators \fB&&\fR and \fB||\fR. The
1376
\`-nbbo\' option causes GNU \fBindent\fR not have that
1377
preference. For example, the default option \`-bbo\' (together
1378
with \`--line-length60\' and \`--ignore-newlines\') makes code
1385
&& ((mask[0] == \'\\0\')
1386
|| (mask[1] == \'\\0\'
1387
&& ((mask[0] == \'0\') || (mask[0] == \'*\')))))
1392
Using the option \`-nbbo\' will make it look like this:
1398
((mask[0] == \'\\0\') ||
1399
(mask[1] == \'\\0\' &&
1400
((mask[0] == \'0\') || (mask[0] == \'*\')))))
1405
The default \`-hnl\', however, honours newlines in the input file by
1406
giving them the highest possible priority to break lines at. For example,
1407
when the input file looks like this:
1413
&& ((mask[0] == \'\\0\')
1414
|| (mask[1] == \'\\0\' && ((mask[0] == \'0\') || (mask[0] == \'*\')))))
1419
then using the option \`-hnl\', or \`--honour-newlines\',
1420
together with the previously mentioned \`-nbbo\' and
1421
\`--line-length60\', will cause the output not to be what is given
1422
in the last example but instead will prefer to break at the positions
1423
where the code was broken in the input file:
1429
&& ((mask[0] == \'\\0\')
1430
|| (mask[1] == \'\\0\' &&
1431
((mask[0] == \'0\') || (mask[0] == \'*\')))))
1436
The idea behind this option is that lines which are too long, but are already
1437
broken up, will not be touched by GNU \fBindent\fR. Really messy code
1438
should be run through \fBindent\fR at least once using the
1439
\`--ignore-newlines\' option though.
1441
.SH "DISABLING FORMATTING"
1443
Formatting of C code may be disabled for portions of a program by
1444
embedding special \fIcontrol comments\fR in the program. To turn off
1445
formatting for a section of a program, place the disabling control
1446
comment \fB/* *INDENT-OFF* */\fR on a line by itself just before that
1447
section. Program text scanned after this control comment is output
1448
precisely as input with no modifications until the corresponding
1449
enabling comment is scanned on a line by itself. The disabling control
1450
comment is \fB/* *INDENT-ON* */\fR, and any text following the comment
1451
on the line is also output unformatted. Formatting begins again with
1452
the input line following the enabling control comment.
1454
More precisely, \fBindent\fR does not attempt to verify the closing
1455
delimiter (\fB*/\fR) for these C comments, and any whitespace on the
1456
line is totally transparent.
1458
These control comments also function in their C++ formats, namely
1459
.B // *INDENT-OFF*\fR and \fB// *INDENT-ON*\fR.
1461
It should be noted that the internal state of \fBindent\fR remains
1462
unchanged over the course of the unformatted section. Thus, for
1463
example, turning off formatting in the middle of a function and
1464
continuing it after the end of the function may lead to bizarre
1465
results. It is therefore wise to be somewhat modular in selecting code
1466
to be left unformatted.
1468
As a historical note, some earlier versions of \fBindent\fR produced
1469
error messages beginning with \fB*INDENT**\fR. These versions of
1470
.B indent\fR were written to ignore any input text lines which began
1471
with such error messages. I have removed this incestuous feature from
1474
.SH "MISCELLANEOUS OPTIONS"
1476
To find out what version of \fBindent\fR you have, use the command
1477
.B indent -version\fR. This will report the version number of
1478
.B indent\fR, without doing any of the normal processing.
1480
The \`-v\' option can be used to turn on verbose mode. When in
1481
verbose mode, \fBindent\fR reports when it splits one line of input
1482
into two more more lines of output, and gives some size statistics at
1485
The \`-pmt\' option causes \fBindent\fR to preserve the access
1486
and modification times on the output files. Using this option
1487
has the advantage that running indent on all source and header
1488
files in a project won\'t cause \fBmake\fR to rebuild all targets.
1489
This option is only available on Operating Systems that have the
1490
POSIX \fButime(2)\fR function.
1494
Please report any bugs to bug-indent@@gnu.org.
1496
When \fBindent\fR is run twice on a file, with the same profile,
1497
it should \fInever\fR change that file the second time. With the
1498
current design of \fBindent\fR, this can not be guaranteed, however,
1499
and it has not been extensively tested.
1501
.B indent\fR does not understand C. In some cases this leads to
1502
the inability to join lines. The result is that running a file
1503
through \fBindent\fR is \fIirreversible\fR, even if the used input
1504
file was the result of running \fBindent\fR with a given profile
1507
While an attempt was made to get \fBindent\fR working for C++, is
1508
will not do a good job on any C++ source except the very simple.
1510
.B indent\fR does not look at the given \`--line-length\' option
1511
when writing comments to the output file. This results often in comments
1512
being put far to the right. In order to prohibit \fBindent\fR from
1513
joining a broken line that has a comment at the end, make sure that the
1514
comments start on the first line of the break.
1516
.B indent\fR does not count lines and comments (see the \`-v\'
1517
option) when \fBindent\fR is turned off with
1518
.B /* *INDENT-OFF* */\fR.
1520
Comments of the form \fB/*UPPERCASE*/\fR are not treated as comment but as an
1521
identifier, causing them to be joined with the next line. This renders
1522
comments of this type useless, unless they are embedded in the code to
1527
The following copyright notice applies to the \fBindent\fR program.
1528
The copyright and copying permissions for this manual appear near the
1529
beginning of \`indent.texinfo\' and \`indent.info\', and near the
1530
end of \`indent.1\'.
1534
Copyright (c) 2001 David Ingamells.
1535
Copyright (c) 1999 Carlo Wood.
1536
Copyright (c) 1995, 1996 Joseph Arceneaux.
1537
Copyright (c) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation
1538
Copyright (c) 1985 Sun Microsystems, Inc.
1539
Copyright (c) 1980 The Regents of the University of California.
1540
Copyright (c) 1976 Board of Trustees of the University of Illinois.
1541
All rights reserved.
1543
Redistribution and use in source and binary forms are permitted
1544
provided that the above copyright notice and this paragraph are
1545
duplicated in all such forms and that any documentation,
1546
advertising materials, and other materials related to such
1547
distribution and use acknowledge that the software was developed
1548
by the University of California, Berkeley, the University of Illinois,
1549
Urbana, and Sun Microsystems, Inc. The name of either University
1550
or Sun Microsystems may not be used to endorse or promote products
1551
derived from this software without specific prior written permission.
1552
THIS SOFTWARE IS PROVIDED \`\`AS IS\'\' AND WITHOUT ANY EXPRESS OR
1553
IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1554
WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
1559
.SH "Options\' Cross Key"
1561
Here is a list of options alphabetized by long option, to help you find
1562
the corresponding short option.
1568
--blank-lines-after-commas -bc
1569
--blank-lines-after-declarations -bad
1570
--blank-lines-after-procedures -bap
1571
--blank-lines-before-block-comments -bbb
1572
--braces-after-if-line -bl
1574
--braces-after-struct-decl-line -bls
1575
--braces-on-if-line -br
1576
--braces-on-struct-decl-line -brs
1577
--break-after-boolean-operator -nbbo
1578
--break-before-boolean-operator -bbo
1579
--break-function-decl-args -bfda
1580
--case-indentation -cli\fIn\fR
1581
--case-brace-indentation -cbi\fIn\fR
1582
--comment-delimiters-on-blank-lines -cdb
1583
--comment-indentation -c\fIn\fR
1584
--continuation-indentation -ci\fIn\fR
1585
--continue-at-parentheses -lp
1586
--cuddle-do-while -cdw
1588
--declaration-comment-column -cd\fIn\fR
1589
--declaration-indentation -di\fIn\fR
1590
--dont-break-function-decl-args -nbfda
1591
--dont-break-procedure-type -npsl
1592
--dont-cuddle-do-while -ncdw
1593
--dont-cuddle-else -nce
1594
--dont-format-comments -nfca
1595
--dont-format-first-column-comments -nfc1
1596
--dont-line-up-parentheses -nlp
1597
--dont-space-special-semicolon -nss
1598
--dont-star-comments -nsc
1599
--else-endif-column -cp\fIn\fR
1600
--format-all-comments -fca
1601
--format-first-column-comments -fc1
1603
--honour-newlines -hnl
1604
--ignore-newlines -nhnl
1605
--ignore-profile -npro
1606
--indent-level -i\fIn\fR
1608
--leave-optional-blank-lines -nsob
1609
--leave-preprocessor-space -lps
1610
--line-comments-indentation -d\fIn\fR
1611
--line-length -l\fIn\fR
1612
--no-blank-lines-after-commas -nbc
1613
--no-blank-lines-after-declarations -nbad
1614
--no-blank-lines-after-procedures -nbap
1615
--no-blank-lines-before-block-comments -nbbb
1616
--no-comment-delimiters-on-blank-lines -ncdb
1617
--no-space-after-casts -ncs
1618
--no-parameter-indentation -nip
1619
--no-space-after-for -nsaf
1620
--no-space-after-function-call-names -npcs
1621
--no-space-after-if -nsai
1622
--no-space-after-parentheses -nprs
1623
--no-space-after-while -nsaw
1627
--parameter-indentation -ip\fIn\fR
1628
--paren-indentation -pi\fIn\fR
1629
--preserve-mtime -pmt
1630
--procnames-start-lines -psl
1631
--space-after-cast -cs
1632
--space-after-for -saf
1633
--space-after-if -sai
1634
--space-after-parentheses -prs
1635
--space-after-procedure-calls -pcs
1636
--space-after-while -saw
1637
--space-special-semicolon -ss
1638
--standard-output -st
1639
--start-left-side-of-comments -sc
1640
--struct-brace-indentation -sbi\fIn\fR
1641
--swallow-optional-blank-lines -sob
1642
--tab-size -ts\fIn\fR
1654
.\" set tabstop to longest possible filename, plus a wee bit
1655
.ta \w'$HOME/.indent.pro 'u
1656
\fI$HOME/.indent.pro\fR holds default options for indent.
1667
Derived from the UCB program "indent".
1669
Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
1670
Copyright (C) 1995, 1996 Joseph Arceneaux.
1671
Copyright (C) 1999 Carlo Wood.
1672
Copyright (C) 2001 David Ingamells.
1674
Permission is granted to make and distribute verbatim copies of
1675
this manual provided the copyright notice and this permission notice
1676
are preserved on all copies.