table of contents
- NAME
- SYNOPSIS
- DESCRIPTION
- OPTIONS
- INVOKING INDENT
- BACKUP FILES
- COMMON STYLES
- BLANK LINES
- --blank-lines-after-declarations
- --blank-lines-after-procedures
- COMMENTS
- STATEMENTS
- DECLARATIONS
- INDENTATION
- BREAKING LONG LINES
- DISABLING FORMATTING
- MISCELLANEOUS OPTIONS
- BUGS
- COPYRIGHT
- Options’ Cross Key
- RETURN VALUE
- FILES
- AUTHORS
- HISTORY
- COPYING
other sections
| INDENT(1) | General Commands Manual | INDENT(1) |
NAME¶
indent - changes the appearance of a C program by inserting or deleting whitespace.SYNOPSIS¶
indent [options] [input-files]DESCRIPTION¶
This man page is generated from the file indent.texinfo. This is Edition of "The indent Manual", for Indent Version , last updated .OPTIONS¶
- -bad, --blank-lines-after-declarations
- Force blank lines after the declarations.
See BLANK LINES.
- -bap, --blank-lines-after-procedures
- Force blank lines after procedure bodies.
See BLANK LINES.
- -bbb, --blank-lines-before-block-comments
- Force blank lines before block comments.
See BLANK LINES.
- -bbo, --break-before-boolean-operator
- Prefer to break long lines before boolean operators.
See BREAKING LONG LINES.
- -bc, --blank-lines-after-commas
- Force newline after comma in declaration.
See DECLARATIONS.
- -bl, --braces-after-if-line
- Put braces on line after if, etc.
See STATEMENTS.
- -blf, --braces-after-func-def-line
- Put braces on line following function definition line.
See DECLARATIONS.
- -blin, --brace-indentn
- Indent braces n spaces.
See STATEMENTS.
- -bls, --braces-after-struct-decl-line
- Put braces on the line after struct declaration
lines.
See DECLARATIONS.
- -br, --braces-on-if-line
- Put braces on line with if, etc.
See STATEMENTS.
- -brf, --braces-on-func-def-line
- Put braces on function definition line.
See DECLARATIONS.
- -brs, --braces-on-struct-decl-line
- Put braces on struct declaration line.
See DECLARATIONS.
- -bs, --Bill-Shannon, --blank-before-sizeof
- Put a space between sizeof and its argument.
See STATEMENTS.
- -cn, --comment-indentationn
- Put comments to the right of code in column n.
See COMMENTS.
- -cbin, --case-brace-indentationn
- Indent braces after a case label N spaces.
See STATEMENTS.
- -cdn, --declaration-comment-columnn
- Put comments to the right of the declarations in column
n.
See COMMENTS.
- -cdb, --comment-delimiters-on-blank-lines
- Put comment delimiters on blank lines.
See COMMENTS.
- -cdw, --cuddle-do-while
- Cuddle while of do {} while; and preceding
‘}’.
See COMMENTS.
- -ce, --cuddle-else
- Cuddle else and preceding ‘}’.
See COMMENTS.
- -cin, --continuation-indentationn
- Continuation indent of n spaces.
See STATEMENTS.
- -clin, --case-indentationn
- Case label indent of n spaces.
See STATEMENTS.
- -cpn, --else-endif-columnn
- Put comments to the right of #else and
#endif statements in column n.
See COMMENTS.
- -cs, --space-after-cast
- Put a space after a cast operator.
See STATEMENTS.
- -dn, --line-comments-indentationn
- Set indentation of comments not to the right of code to
n spaces.
See COMMENTS.
- -bfda, --break-function-decl-args
- Break the line before all arguments in a declaration.
See DECLARATIONS.
- -bfde, --break-function-decl-args-end
- Break the line after the last argument in a declaration.
See DECLARATIONS.
- -dj, --left-justify-declarations
- If -cd 0 is used then comments after declarations are left
justified behind the declaration.
See DECLARATIONS.
- -din, --declaration-indentationn
- Put variables in column n.
See DECLARATIONS.
- -fc1, --format-first-column-comments
- Format comments in the first column.
See COMMENTS.
- -fca, --format-all-comments
- Do not disable all formatting of comments.
See COMMENTS.
- -gnu, --gnu-style
- Use GNU coding style. This is the default.
See COMMON STYLES.
- -hnl, --honour-newlines
- Prefer to break long lines at the position of newlines in
the input.
See BREAKING LONG LINES.
- -in, --indent-leveln
- Set indentation level to n spaces.
See INDENTATION.
- -iln, --indent-labeln
- Set offset for labels to column n.
See INDENTATION.
- -ipn, --parameter-indentationn
- Indent parameter types in old-style function definitions by
n spaces.
See INDENTATION.
- -kr, --k-and-r-style
- Use Kernighan & Ritchie coding style.
See COMMON STYLES.
- -ln, --line-lengthn
- Set maximum line length for non-comment lines to n.
See BREAKING LONG LINES.
- -lcn, --comment-line-lengthn
- Set maximum line length for comment formatting to n.
See COMMENTS.
- -linux, --linux-style
- Use Linux coding style.
See COMMON STYLES.
- -lp, --continue-at-parentheses
- Line up continued lines at parentheses.
See INDENTATION.
- -lps, --leave-preprocessor-space
- Leave space between ‘#’ and preprocessor
directive.
See INDENTATION.
- -nbad, --no-blank-lines-after-declarations
- Do not force blank lines after declarations.
See BLANK LINES.
- -nbap, --no-blank-lines-after-procedures
- Do not force blank lines after procedure bodies.
See BLANK LINES.
- -nbbo, --break-after-boolean-operator
- Do not prefer to break long lines before boolean operators.
See BREAKING LONG LINES.
- -nbc, --no-blank-lines-after-commas
- Do not force newlines after commas in declarations.
See DECLARATIONS.
- -nbfda, --dont-break-function-decl-args
- Don’t put each argument in a function declaration on
a separate line.
See DECLARATIONS.
- -ncdb, --no-comment-delimiters-on-blank-lines
- Do not put comment delimiters on blank lines.
See COMMENTS.
- -ncdw, --dont-cuddle-do-while
- Do not cuddle } and the while of a do {}
while;.
See STATEMENTS.
- -nce, --dont-cuddle-else
- Do not cuddle } and else.
See STATEMENTS.
- -ncs, --no-space-after-casts
- Do not put a space after cast operators.
See STATEMENTS.
- -ndjn, --dont-left-justify-declarations
- Comments after declarations are treated the same as
comments after other statements.
See DECLARATIONS.
- -nfc1, --dont-format-first-column-comments
- Do not format comments in the first column as normal.
See COMMENTS.
- -nfca, --dont-format-comments
- Do not format any comments.
See COMMENTS.
- -nhnl, --ignore-newlines
- Do not prefer to break long lines at the position of
newlines in the input.
See BREAKING LONG LINES.
- -nip, --no-parameter-indentation
- Zero width indentation for parameters.
See INDENTATION.
- -nlp, --dont-line-up-parentheses
- Do not line up parentheses.
See STATEMENTS.
- -npcs, --no-space-after-function-call-names
- Do not put space after the function in function calls.
See STATEMENTS.
- -nprs, --no-space-after-parentheses
- Do not put a space after every ’(’ and before
every ’)’.
See STATEMENTS.
- -npsl, --dont-break-procedure-type
- Put the type of a procedure on the same line as its name.
See DECLARATIONS.
- -nsaf, --no-space-after-for
- Do not put a space after every for.
See STATEMENTS.
- -nsai, --no-space-after-if
- Do not put a space after every if.
See STATEMENTS.
- -nsaw, --no-space-after-while
- Do not put a space after every while.
See STATEMENTS.
- -nsc, --dont-star-comments
- Do not put the ‘*’ character at the left of
comments.
See COMMENTS.
- -nsob, --leave-optional-blank-lines
- Do not swallow optional blank lines.
See BLANK LINES.
- -nss, --dont-space-special-semicolon
- Do not force a space before the semicolon after certain
statements. Disables ‘-ss’.
See STATEMENTS.
- -nut, --no-tabs
- Use spaces instead of tabs.
See INDENTATION.
- -nv, --no-verbosity
- Disable verbose mode.
See MISCELLANEOUS OPTIONS.
- -orig, --original
- Use the original Berkeley coding style.
See COMMON STYLES.
- -npro, --ignore-profile
- Do not read ‘.indent.pro’ files.
See INVOKING INDENT.
- -pcs, --space-after-procedure-calls
- Insert a space between the name of the procedure being
called and the ‘(’.
See STATEMENTS.
- -pin, --paren-indentationn
- Specify the extra indentation per open parentheses ’(’ when a statement is broken.See STATEMENTS.
- -pmt, --preserve-mtime
- Preserve access and modification times on output files.See MISCELLANEOUS OPTIONS.
- -ppin, --preprocessor-indentationn
- Specify the indentation for preprocessor conditional statements.See INDENTATION.
- -prs, --space-after-parentheses
- Put a space after every ’(’ and before every
’)’.
See STATEMENTS.
- -psl, --procnames-start-lines
- Put the type of a procedure on the line before its name.
See DECLARATIONS.
- -saf, --space-after-for
- Put a space after each for.
See STATEMENTS.
- -sai, --space-after-if
- Put a space after each if.
See STATEMENTS.
- -saw, --space-after-while
- Put a space after each while.
See STATEMENTS.
- -sbin, --struct-brace-indentationn
- Indent braces of a struct, union or enum N spaces.
See STATEMENTS.
- -sc, --start-left-side-of-comments
- Put the ‘*’ character at the left of comments.
See COMMENTS.
- -sob, --swallow-optional-blank-lines
- Swallow optional blank lines.
See BLANK LINES.
- -ss, --space-special-semicolon
- On one-line for and while statements, force a
blank before the semicolon.
See STATEMENTS.
- -st, --standard-output
- Write to standard output.
See INVOKING INDENT.
- -T
- Tell indent the name of typenames.
See DECLARATIONS.
- -tsn, --tab-sizen
- Set tab size to n spaces.
See INDENTATION.
- -ut, --use-tabs
- Use tabs. This is the default.
See INDENTATION.
- -v, --verbose
- Enable verbose mode.
See MISCELLANEOUS OPTIONS.
- -version
- Output the version number of indent.
See MISCELLANEOUS OPTIONS.
INVOKING INDENT¶
As of version 1.3, the format of the indent command is:indent [ options] [input-files] indent [ options] [single-input-file] [-o output-file]
indent slithy_toves.c -o slithy_toves.out indent -st slithy_toves.c > slithy_toves.out cat slithy_toves.c | indent -o slithy_toves.out
In most of this document, the traditional, short names are used for the sake of brevity. See OPTION SUMMARY, for a list of options, including both long and short names.
indent -br test/metabolism.c -l85
indent --braces-on-if-line --line-length185 test/metabolism.c indent +braces-on-if-line +line-length185 test/metabolism.c
and use that if found. Finally indent will search your home directory for ‘.indent.pro’ and use that file if it is found. This behaviour is different from that of other versions of indent, which load both files if they both exist.
BACKUP FILES¶
As of version 1.3, GNU indent makes GNU-style backup files, the same way GNU Emacs does. This means that either simple or numbered backup filenames may be made.COMMON STYLES¶
There are several common styles of C code, including the GNU style, the Kernighan & Ritchie style, and the original Berkeley style. A style may be selected with a single background option, which specifies a set of values for all other options. However, explicitly specified options always override options implied by a background option.-nbad -bap -nbc -bbo -bl -bli2 -bls -ncdb -nce -cp1 -cs -di2 -ndj -nfc1 -nfca -hnl -i2 -ip5 -lp -pcs -nprs -psl -saf -sai -saw -nsc -nsob
-nbad -bap -bbo -nbc -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -cp33 -cs -d0 -di1 -nfc1 -nfca -hnl -i4 -ip0 -l75 -lp -npcs -nprs -npsl -saf -sai -saw -nsc -nsob -nss
-nbad -nbap -bbo -bc -br -brs -c33 -cd33 -cdb -ce -ci4 -cli0 -cp33 -di16 -fc1 -fca -hnl -i4 -ip4 -l75 -lp -npcs -nprs -psl -saf -sai -saw -sc -nsob -nss -ts8
-nbad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -i8 -ip0 -l80 -lp -npcs -nprs -npsl -sai -saf -saw -ncs -nsc -sob -nfca -cp33 -ss -ts8 -il1
BLANK LINES¶
Various programming styles use blank lines in different places. indent has a number of options to insert or delete blank lines in specific places.--blank-lines-after-declarations¶
The ‘-bad’ option forces a blank line after every block of declarations. The ‘-nbad’ option does not add any such blank lines.char *foo; char *bar; /* This separates blocks of declarations. */ int baz;
char *foo; char *bar; /* This separates blocks of declarations. */ int baz;
char *foo; char *bar; /* This separates blocks of declarations. */ int baz;
--blank-lines-after-procedures¶
The ‘-bap’ option forces a blank line after every procedure body.int
foo ()
{
puts("Hi");
}
/* The procedure bar is even less interesting. */
char *
bar ()
{
puts("Hello");
}
int
foo ()
{
puts ("Hi");
}
/* The procedure bar is even less interesting. */
char *
bar ()
{
puts ("Hello");
}
int
foo ()
{
puts ("Hi");
}
/* The procedure bar is even less interesting. */
char *
bar ()
{
puts ("Hello");
}
COMMENTS¶
indent formats both C and C++ comments. C comments are begun with ‘/*’, terminated with ‘*/’ and may contain newline characters. C++ comments begin with the delimiter ‘//’ and end at the newline./**********************
* Comment in a box!! *
**********************/
/*
* A different kind of scent,
* for a different kind of comment.
*/
/* Loving hug */
/* * Loving hug */
STATEMENTS¶
The ‘-br’ or ‘-bl’ option specifies how to format braces.if (x > 0) {
x--;
}
if (x > 0)
{
x--;
}
if (x > 0)
{
x--;
}
if (x > 0) {
x--;
} else {
fprintf (stderr, "...something wrong?\n");
}
if (x > 0) {
x--;
}
else {
fprintf (stderr, "...something wrong?\n");
}
do {
x--;
} while (x);
do {
x--;
}
while (x);
switch (i)
{
case 0:
break;
case 1:
{
++i;
}
default:
break;
}
switch (i)
{
case 0:
break;
case 1:
{
++i;
}
default:
break;
}
switch (i)
{
case 0:
break;
case 1:
{
++i;
}
default:
break;
}
while ( ( e_code - s_code ) < ( dec_ind - 1 ) )
{
set_buf_break ( bb_dec_ind );
*e_code++ = ’ ’;
}
DECLARATIONS¶
By default indent will line up identifiers, in the column specified by the ‘-di’ option. For example, ‘-di16’ makes things look like:int foo; char *bar;
int foo; char *bar;
int foo;
int a, b, c;
int a, b, c;
void foo (int arg1, char arg2, int *arg3, long arg4, char arg5);With the ‘-bfda’ option this would look like
void foo (
int arg1,
char arg2,
int *arg3,
long arg4,
char arg5);
void foo (
int arg1,
char arg2,
int *arg3,
long arg4,
char arg5
);
typedef unsigned long CODE_ADDR;
typedef enum {red, blue, green} COLOR;
struct foo {
int x;
};
struct foo
{
int x;
};
the function brace options ‘-brf’ or ‘-blf’ specify how to format the braces in function definitions. The ‘-brf’ option formats braces like this:
int one(void) {
return 1;
};
int one(void)
{
return 1;
};
INDENTATION¶
One issue in the formatting of code is how far each line should be indented from the left margin. When the beginning of a statement such as if or for is encountered, the indentation level is increased by the value specified by the ‘-i’ option. For example, use ‘-i8’ to specify an eight character indentation for each level. When a statement is broken across two lines, the second line is indented by a number of additional spaces specified by the ‘-ci’ option. ‘-ci’ defaults to 0. However, if the ‘-lp’ option is specified, and a line has a left parenthesis which is not closed on that line, then continuation lines will be lined up to start at the character position just after the left parenthesis. This processing also applies to ‘[’ and applies to ‘{’ when it occurs in initialization lists. For example, a piece of continued code might look like this with ‘-nlp -ci3’ in effect: p1 = first_procedure (second_procedure (p2, p3),
third_procedure (p4, p5));
p1 = first_procedure (second_procedure (p2, p3),
third_procedure (p4, p5));
if ((((i < 2 &&
k > 0) || p == 0) &&
q == 1) ||
n = 0)
if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0)
char *
create_world (x, y, scale)
int x;
int y;
float scale;
{
. . .
}
#if X #if Y #define Z 1 #else #define Z 0 #endif #endifbecomes
#if X # if Y # define Z 1 # else # define Z 0 # endif #endif
group
function()
{
if (do_stuff1() == ERROR)
goto cleanup1;
if (do_stuff2() == ERROR)
goto cleanup2;
return SUCCESS;
cleanup2:
do_cleanup2();
cleanup1:
do_cleanup1();
return ERROR;
}
becomes
group
function()
{
if (do_stuff1() == ERROR)
goto cleanup1;
if (do_stuff2() == ERROR)
goto cleanup2;
return SUCCESS;
cleanup2:
do_cleanup2();
cleanup1:
do_cleanup1();
return ERROR;
}
BREAKING LONG LINES¶
With the option ‘-l n’, or ‘--line-lengthn’, it is possible to specify the maximum length of a line of C code, not including possible comments that follow it. if (mask
&& ((mask[0] == ’\0’)
|| (mask[1] == ’\0’
&& ((mask[0] == ’0’) || (mask[0] == ’*’)))))
if (mask &&
((mask[0] == ’\0’) ||
(mask[1] == ’\0’ &&
((mask[0] == ’0’) || (mask[0] == ’*’)))))
if (mask
&& ((mask[0] == ’\0’)
|| (mask[1] == ’\0’ && ((mask[0] == ’0’) || (mask[0] == ’*’)))))
if (mask
&& ((mask[0] == ’\0’)
|| (mask[1] == ’\0’ &&
((mask[0] == ’0’) || (mask[0] == ’*’)))))
DISABLING FORMATTING¶
Formatting of C code may be disabled for portions of a program by embedding special control comments in the program. To turn off formatting for a section of a program, place the disabling control comment /* *INDENT-OFF* */ on a line by itself just before that section. Program text scanned after this control comment is output precisely as input with no modifications until the corresponding enabling comment is scanned on a line by itself. The disabling control comment is /* *INDENT-ON* */, and any text following the comment on the line is also output unformatted. Formatting begins again with the input line following the enabling control comment.MISCELLANEOUS OPTIONS¶
To find out what version of indent you have, use the command indent -version. This will report the version number of indent, without doing any of the normal processing.BUGS¶
Please report any bugs to bug-indent@gnu.org.COPYRIGHT¶
The following copyright notice applies to the indent program. The copyright and copying permissions for this manual appear near the beginning of ‘indent.texinfo’ and ‘indent.info’, and near the end of ‘indent.1’.Copyright (c) 2001 David Ingamells. Copyright (c) 1999 Carlo Wood. Copyright (c) 1995, 1996 Joseph Arceneaux. Copyright (c) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation Copyright (c) 1985 Sun Microsystems, Inc. Copyright (c) 1980 The Regents of the University of California. Copyright (c) 1976 Board of Trustees of the University of Illinois. All rights reserved. Redistribution and use in source and binary forms are permitted provided that the above copyright notice and this paragraph are duplicated in all such forms and that any documentation, advertising materials, and other materials related to such distribution and use acknowledge that the software was developed by the University of California, Berkeley, the University of Illinois, Urbana, and Sun Microsystems, Inc. The name of either University or Sun Microsystems may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED ‘‘AS IS’’ AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Options’ Cross Key¶
Here is a list of options alphabetized by long option, to help you find the corresponding short option.--blank-lines-after-commas -bc --blank-lines-after-declarations -bad --blank-lines-after-procedures -bap --blank-lines-before-block-comments -bbb --braces-after-if-line -bl --braces-after-func-def-line -blf --brace-indent -bli --braces-after-struct-decl-line -bls --braces-on-if-line -br --braces-on-func-def-line -brf --braces-on-struct-decl-line -brs --break-after-boolean-operator -nbbo --break-before-boolean-operator -bbo --break-function-decl-args -bfda --break-function-decl-args-end -bfde --case-indentation -cli n --case-brace-indentation -cbi n --comment-delimiters-on-blank-lines -cdb --comment-indentation -c n --continuation-indentation -ci n --continue-at-parentheses -lp --cuddle-do-while -cdw --cuddle-else -ce --declaration-comment-column -cd n --declaration-indentation -di n --dont-break-function-decl-args -nbfda --dont-break-function-decl-args-end -nbfde --dont-break-procedure-type -npsl --dont-cuddle-do-while -ncdw --dont-cuddle-else -nce --dont-format-comments -nfca --dont-format-first-column-comments -nfc1 --dont-line-up-parentheses -nlp --dont-left-justify-declarations -ndj --dont-space-special-semicolon -nss --dont-star-comments -nsc --else-endif-column -cp n --format-all-comments -fca --format-first-column-comments -fc1 --gnu-style -gnu --honour-newlines -hnl --ignore-newlines -nhnl --ignore-profile -npro --indent-label -il n --indent-level -i n --k-and-r-style -kr --leave-optional-blank-lines -nsob --leave-preprocessor-space -lps --left-justify-declarations -dj --line-comments-indentation -d n --line-length -l n --linux-style -linux --no-blank-lines-after-commas -nbc --no-blank-lines-after-declarations -nbad --no-blank-lines-after-procedures -nbap --no-blank-lines-before-block-comments -nbbb --no-comment-delimiters-on-blank-lines -ncdb --no-space-after-casts -ncs --no-parameter-indentation -nip --no-space-after-for -nsaf --no-space-after-function-call-names -npcs --no-space-after-if -nsai --no-space-after-parentheses -nprs --no-space-after-while -nsaw --no-tabs -nut --no-verbosity -nv --original -orig --parameter-indentation -ip n --paren-indentation -pi n --preserve-mtime -pmt --preprocessor-indentation -ppi n --procnames-start-lines -psl --space-after-cast -cs --space-after-for -saf --space-after-if -sai --space-after-parentheses -prs --space-after-procedure-calls -pcs --space-after-while -saw --space-special-semicolon -ss --standard-output -st --start-left-side-of-comments -sc --struct-brace-indentation -sbi n --swallow-optional-blank-lines -sob --tab-size -ts n --use-tabs -ut --verbose -v
RETURN VALUE¶
UnknownFILES¶
$HOME/.indent.pro holds default options for indent.