indent (1)
NAME
indent - changes the appearance of a C program by inserting or deleting whitespace.SYNOPSIS
indent [options] [input-files]indent [options] [single-input-file] [-o output-file]
indent --version
DESCRIPTION
This man page is generated from the file indent.texinfo. This is Edition of "The indent Manual", for Indent Version , last updated .The indent program can be used to make code easier to read. It can also convert from one style of writing C to another.
indent understands a substantial amount about the syntax of C, but it also attempts to cope with incomplete and misformed syntax.
In version 1.2 and more recent versions, the GNU style of indenting is the default.
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 oq}cq.
See COMMENTS. - -ce, --cuddle-else
-
Cuddle else and preceding oq}cq.
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 oq#cq 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
-
Doncqt 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 cq(cq and before every cq)cq.
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 oq*cq 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 oq-sscq.
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 oq.indent.procq files.
See INVOKING INDENT. - -pcs, --space-after-procedure-calls
-
Insert a space between the name of the
procedure being called and the oq(cq.
See STATEMENTS. - -pin, --paren-indentationn
- Specify the extra indentation per open parentheses cq(cq 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 cq(cq and before every cq)cq.
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 oq*cq 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]
This format is different from earlier versions and other versions of indent.
In the first form, one or more input files are specified. indent makes a backup copy of each file, and the original file is replaced with its indented version. See BACKUP FILES, for an explanation of how backups are made.
In the second form, only one input file is specified. In this case, or when the standard input is used, you may specify an output file after the oq-ocq option.
To cause indent to write to standard output, use the oq-stcq option. This is only allowed when there is only one input file, or when the standard input is used.
If no input files are named, the standard input is read for input. Also, if a filename named oq-cq is specified, then the standard input is read.
As an example, each of the following commands will input the program oqslithy_toves.ccq and write its indented text to oqslithy_toves.outcq:
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
Most other options to indent control how programs are formatted. As of version 1.2, indent also recognizes a long name for each option name. Long options are prefixed by either oq--cq or oq+cq. [ oq+cq is being superseded by oq--cq to maintain consistency with the POSIX standard.]
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.
Here is another example:
indent -br test/metabolism.c -l85
This will indent the program oqtest/metabolism.ccq using the oq-brcq and oq-l85cq options, write the output back to oqtest/metabolism.ccq, and write the original contents of oqtest/metabolism.ccq to a backup file in the directory oqtestcq.
Equivalent invocations using long option names for this example would be:
indent --braces-on-if-line --line-length185 test/metabolism.c indent +braces-on-if-line +line-length185 test/metabolism.c
If you find that you often use indent with the same options, you may put those options into a file named oq.indent.procq. indent will look for a profile file in three places. First it will check the environment variable INDENT_PROFILE. If that exists its value is expected to name the file that is to be used. If the environment variable does not exist, indent looks for oq.indent.procq in the current directory
and use that if found. Finally indent will search your home directory for oq.indent.procq 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.
The format of oq.indent.procq is simply a list of options, just as they would appear on the command line, separated by white space (tabs, spaces, and newlines). Options in oq.indent.procq may be surrounded by C or C++ comments, in which case they are ignored.
Command line switches are handled after processing oq .indent.procq. Options specified later override arguments specified earlier, with one exception: Explicitly specified options always override background options (See COMMON STYLES). You can prevent indent from reading an oq.indent.procq file by specifying the oq-nprocq option.
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.
Simple backup file names are generated by appending a suffix to the original file name. The default for this suffix is the one-character string oq~cq (tilde). Thus, the backup file for oqpython.ccq would be oqpython.c~cq.
Instead of the default, you may specify any string as a suffix by setting the environment variable SIMPLE_BACKUP_SUFFIX to your preferred suffix.
Numbered backup versions of a file oqmomeraths.ccq look like oqmomeraths.c.~23~cq, where 23 is the version of this particular backup. When making a numbered backup of the file oqsrc/momeraths.ccq, the backup file will be named oqsrc/momeraths.c.~V~cq, where V is one greater than the highest version currently existing in the directory oqsrccq. The environment variable VERSION_WIDTH controls the number of digits, using left zero padding when necessary. For instance, setting this variable to "2" will lead to the backup file being named oqmomeraths.c.~04~cq.
The type of backup file made is controlled by the value of the environment variable VERSION_CONTROL. If it is the string oqsimplecq, then only simple backups will be made. If its value is the string oqnumberedcq, then numbered backups will be made. If its value is oqnumbered-existingcq, then numbered backups will be made if there already exist numbered backups for the file being indented; otherwise, a simple backup is made. If VERSION_CONTROL is not set, then indent assumes the behaviour of oqnumbered-existingcq.
Other versions of indent use the suffix oq.BAKcq in naming backup files. This behaviour can be emulated by setting SIMPLE_BACKUP_SUFFIX to oq.BAKcq.
Note also that other versions of indent make backups in the current directory, rather than in the directory of the source file as GNU indent now does.
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.
As of version 1.2, the default style of GNU indent is the GNU style. Thus, it is no longer necessary to specify the option oq-gnucq to obtain this format, although doing so will not cause an error. Option settings which correspond to the GNU style are:
-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
The GNU coding style is that preferred by the GNU project. It is the style that the GNU Emacs C mode encourages and which is used in the C portions of GNU Emacs. (People interested in writing programs for Project GNU should get a copy of "The GNU Coding Standards", which also covers semantic and portability issues such as memory usage, the size of integers, etc.)
The Kernighan & Ritchie style is used throughout their well-known book "The C Programming Language". It is enabled with the oq-krcq option. The Kernighan & Ritchie style corresponds to the following set of options:
-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
Kernighan & Ritchie style does not put comments to the right of code in the same column at all times (nor does it use only one space to the right of the code), so for this style indent has arbitrarily chosen column 33.
The style of the original Berkeley indent may be obtained by specifying oq-origcq (or by specifying oq--originalcq, using the long option name). This style is equivalent to the following settings:
-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
The Linux style is used in the linux kernel code and drivers. Code generally has to follow the Linux coding style to be accepted. This style is equivalent to the following settings:
-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.
The oq-badcq option causes indent to force a blank line after every block of declarations. The oq-nbadcq option causes indent not to force such blank lines.
The oq-bapcq option forces a blank line after every procedure body. The oq-nbapcq option forces no such blank line.
The oq-bbbcq option forces a blank line before every boxed comment (See COMMENTS.) The oq-nbbbcq option does not force such blank lines.
The oq-sobcq option causes indent to swallow optional blank lines (that is, any optional blank lines present in the input will be removed from the output). If the oq-nsobcq is specified, any blank lines present in the input file will be copied to the output file.
--blank-lines-after-declarations
The oq-badcq option forces a blank line after every block of declarations. The oq-nbadcq option does not add any such blank lines.
For example, given the input
char *foo; char *bar; /* This separates blocks of declarations. */ int baz;
indent -bad produces
char *foo; char *bar; /* This separates blocks of declarations. */ int baz;
and indent -nbad produces
char *foo; char *bar; /* This separates blocks of declarations. */ int baz;
--blank-lines-after-procedures
The oq-bapcq option forces a blank line after every procedure body.
For example, given the input
int foo () { puts("Hi"); } /* The procedure bar is even less interesting. */ char * bar () { puts("Hello"); }
indent -bap produces
int foo () { puts ("Hi"); } /* The procedure bar is even less interesting. */ char * bar () { puts ("Hello"); }
and indent -nbap produces
int foo () { puts ("Hi"); } /* The procedure bar is even less interesting. */ char * bar () { puts ("Hello"); }
No blank line will be added after the procedure foo.
COMMENTS
indent formats both C and C++ comments. C comments are begun with oq/*cq, terminated with oq*/cq and may contain newline characters. C++ comments begin with the delimiter oq//cq and end at the newline.
indent handles comments differently depending upon their context. indent attempts to distinguish between comments which follow statements, comments which follow declarations, comments following preprocessor directives, and comments which are not preceded by code of any sort, i.e., they begin the text of the line (although not necessarily in column 1).
indent further distinguishes between comments found outside of procedures and aggregates, and those found within them. In particular, comments beginning a line found within a procedure will be indented to the column at which code is currently indented. The exception to this is a comment beginning in the leftmost column; such a comment is output at that column.
indent attempts to leave boxed comments unmodified. The general idea of such a comment is that it is enclosed in a rectangle or oqoqboxcqcq of stars or dashes to visually set it apart. More precisely, boxed comments are defined as those in which the initial oq/*cq is followed immediately by the character oq*cq, oq=cq, oq_cq, or oq-cq, or those in which the beginning comment delimiter (oq/*cq) is on a line by itself, and the following line begins with a oq*cq in the same column as the star of the opening delimiter.
Examples of boxed comments are:
/********************** * Comment in a box!! * **********************/ /* * A different kind of scent, * for a different kind of comment. */
indent attempts to leave boxed comments exactly as they are found in the source file. Thus the indentation of the comment is unchanged, and its length is not checked in any way. The only alteration made is that an embedded tab character may be converted into the appropriate number of spaces.
If the oq-bbbcq option is specified, all such boxed comments will be preceded by a blank line, unless such a comment is preceded by code.
Comments which are not boxed comments may be formatted, which means that the line is broken to fit within a right margin and left-filled with whitespace. Single newlines are equivalent to a space, but blank lines (two or more newlines in a row) are taken to mean a paragraph break. Formatting of comments which begin after the first column is enabled with the oq-fcacq option. To format those beginning in column one, specify oq-fc1cq. Such formatting is disabled by default.
The right margin for formatting defaults to 78, but may be changed with the oq-lccq option. If the margin specified does not allow the comment to be printed, the margin will be automatically extended for the duration of that comment. The margin is not respected if the comment is not being formatted.
If the comment begins a line (i.e., there is no program text to its left), it will be indented to the column it was found in unless the comment is within a block of code. In that case, such a comment will be aligned with the indented code of that block (unless the comment began in the first column). This alignment may be affected by the oq-dcq option, which specifies an amount by which such comments are moved to the left, or unindented. For example, oq-d2cq places comments two spaces to the left of code. By default, comments are aligned with code, unless they begin in the first column, in which case they are left there by default --- to get them aligned with the code, specify oq-fc1cq.
Comments to the right of code will appear by default in column 33. This may be changed with one of three options. oq-ccq will specify the column for comments following code, oq-cdcq specifies the column for comments following declarations, and oq-cpcq specifies the column for comments following preprocessor directives #else and #endif. oq-djcq together with oq-cd0cq can be used to suppress alignment of comments to the right of declarations, causing the comment to follow one tabstop from the end of the declaration. Normally oq-cd0cq causes oq-ccq to become effective.
If the code to the left of the comment exceeds the beginning column, the comment column will be extended to the next tabstop column past the end of the code, or in the case of preprocessor directives, to one space past the end of the directive. This extension lasts only for the output of that particular comment.
The oq-cdbcq option places the comment delimiters on blank lines. Thus, a single line comment like /* Loving hug */ can be transformed into:
/* Loving hug */
Stars can be placed at the beginning of multi-line comments with the oq-sccq option. Thus, the single-line comment above can be transformed (with oq-cdb -sccq) into:
/* * Loving hug */
STATEMENTS
The oq-brcq or oq-blcq option specifies how to format braces.
The oq-brcq option formats statement braces like this:
if (x > 0) { x--; }
The oq-blcq option formats them like this:
if (x > 0) { x--; }
If you use the oq-blcq option, you may also want to specify the oq-blicq option. This option specifies the number of spaces by which braces are indented. oq-bli2cq, the default, gives the result shown above. oq-bli0cq results in the following:
if (x > 0) { x--; }
If you are using the oq-brcq option, you probably want to also use the oq-cecq option. This causes the else in an if-then-else construct to cuddle up to the immediately preceding oq}cq. For example, with oq-br -cecq you get the following:
if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); }
With oq-br -ncecq that code would appear as
if (x > 0) { x--; } else { fprintf (stderr, "...something wrong?\n"); }
This causes the while in a do-while loop to cuddle up to the immediately preceding oq}cq. For example, with oq-cdwcq you get the following:
do { x--; } while (x);
With oq-ncdwcq that code would appear as
do { x--; } while (x);
The oq-clicq option specifies the number of spaces that case labels should be indented to the right of the containing switch statement.
The default gives code like:
switch (i) { case 0: break; case 1: { ++i; } default: break; }
Using the oq-cli2cq that would become:
switch (i) { case 0: break; case 1: { ++i; } default: break; }
The indentation of the braces below a case statement can be controlled with the oq-cbincq option. For example, using oq-cli2 -cbi0cq results in:
switch (i) { case 0: break; case 1: { ++i; } default: break; }
If a semicolon is on the same line as a for or while statement, the oq-sscq option will cause a space to be placed before the semicolon. This emphasizes the semicolon, making it clear that the body of the for or while statement is an empty statement. oq-nsscq disables this feature.
The oq-pcscq option causes a space to be placed between the name of the procedure being called and the oq(cq (for example, puts ("Hi");. The oq-npcscq option would give puts("Hi");).
If the oq-cscq option is specified, indent puts a space between a cast operator and the object to be cast. The oq-ncscq ensures that there is no space between the cast operator and the object. Remember that indent only knows about the standard C data types and so cannot recognise user-defined types in casts. Thus (mytype)thing is not treated as a cast.
The oq-bscq option ensures that there is a space between the keyword sizeof and its argument. In some versions, this is known as the oqBill_Shannoncq option.
The oq-safcq option forces a space between a for and the following parenthesis. This is the default.
The oq-saicq option forces a space between a if and the following parenthesis. This is the default.
The oq-sawcq option forces a space between a while and the following parenthesis. This is the default.
The oq-prscq option causes all parentheses to be separated with a space from whatever is between them. For example, using oq-prscq results in code like:
while ( ( e_code - s_code ) < ( dec_ind - 1 ) ) { set_buf_break ( bb_dec_ind ); *e_code++ = cq cq; }
DECLARATIONS
By default indent will line up identifiers, in the column specified by the oq-dicq option. For example, oq-di16cq makes things look like:
int foo; char *bar;
Using a small value (such as one or two) for the oq-dicq option can be used to cause the identifiers to be placed in the first available position; for example:
int foo; char *bar;
The value given to the oq-dicq option will still affect variables which are put on separate lines from their types, for example oq-di2cq will lead to:
int foo;
If the oq-bccq option is specified, a newline is forced after each comma in a declaration. For example,
int a, b, c;
With the oq-nbccq option this would look like
int a, b, c;
The oq-bfdacq option causes a newline to be forced after the comma separating the arguments of a function declaration. The arguments will appear at one indention level deeper than the function declaration. This is particularly helpful for functions with long argument lists. The option oq-bfdecq causes a newline to be forced before the closing bracket of the function declaration. For both options the cqncq setting is the default: -nbdfa and -nbdfe.
For example,
void foo (int arg1, char arg2, int *arg3, long arg4, char arg5);With the oq-bfdacq option this would look like
void foo ( int arg1, char arg2, int *arg3, long arg4, char arg5);
With, in addition, the oq-bfdecq option this would look like
void foo ( int arg1, char arg2, int *arg3, long arg4, char arg5 );
The oq-pslcq option causes the type of a procedure being defined to be placed on the line before the name of the procedure. This style is required for the etags program to work correctly, as well as some of the c-mode functions of Emacs.
You must use the oq-Tcq option to tell indent the name of all the typenames in your program that are defined by typedef. oq-Tcq can be specified more than once, and all names specified are used. For example, if your program contains
typedef unsigned long CODE_ADDR; typedef enum {red, blue, green} COLOR;
you would use the options oq-T CODE_ADDR -T COLORcq.
The oq-brscq or oq-blscq option specifies how to format braces in struct declarations. The oq-brscq option formats braces like this:
struct foo { int x; };
The oq-blscq option formats them like this:
struct foo { int x; };
Similarly to the structure brace oq-brscq and oq-blscq options,
the function brace options oq-brfcq or oq-blfcq specify how to format the braces in function definitions. The oq-brfcq option formats braces like this:
int one(void) { return 1; };
The oq-blfcq option formats them like this:
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 oq-icq option. For example, use oq-i8cq 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 oq-cicq option. oq-cicq defaults to 0. However, if the oq-lpcq 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 oq[cq and applies to oq{cq when it occurs in initialization lists. For example, a piece of continued code might look like this with oq-nlp -ci3cq in effect:
p1 = first_procedure (second_procedure (p2, p3), third_procedure (p4, p5));
With oq-lpcq in effect the code looks somewhat clearer:
p1 = first_procedure (second_procedure (p2, p3), third_procedure (p4, p5));
When a statement is broken in between two or more paren pairs (...), each extra pair causes the indentation level extra indentation:
if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0)
The option oq-ipNcq can be used to set the extra offset per paren. For instance, oq-ip0cq would format the above as:
if ((((i < 2 && k > 0) || p == 0) && q == 1) || n = 0)
indent assumes that tabs are placed at regular intervals of both input and output character streams. These intervals are by default 8 columns wide, but (as of version 1.2) may be changed by the oq-tscq option. Tabs are treated as the equivalent number of spaces.
The indentation of type declarations in old-style function definitions is controlled by the oq-ipcq parameter. This is a numeric parameter specifying how many spaces to indent type declarations. For example, the default oq-ip5cq makes definitions look like this:
char * create_world (x, y, scale) int x; int y; float scale; { . . . }
For compatibility with other versions of indent, the option oq-nipcq is provided, which is equivalent to oq-ip0cq.
ANSI C allows white space to be placed on preprocessor command lines between the character oq#cq and the command name. By default, indent removes this space, but specifying the oq-lpscq option directs indent to leave this space unmodified. The option oq-ppicq overrides oq-nlpscq and oq-lpscq.
This option can be used to request that preprocessor conditional statements can be indented by to given number of spaces, for example with the option oq-ppi 3cq
#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
This option sets the offset at which a label (except case labels) will be positioned. If it is set to zero or a positive number, this indicates how far from the left margin to indent a label. If it is set to a negative number, this indicates how far back from the current indent level to place the label. The default setting is -2 which matches the behaviour of earlier versions of indent. Note that this parameter does not affect the placing of case labels; see the oq-clicq parameter for that. For example with the option oq-il 1cq
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 oq-lncq, or oq--line-lengthncq, it is possible to specify the maximum length of a line of C code, not including possible comments that follow it.
When lines become longer than the specified line length, GNU indent tries to break the line at a logical place. This is new as of version 2.1 however and not very intelligent or flexible yet.
Currently there are two options that allow one to interfere with the algorithm that determines where to break a line.
The oq-bbocq option causes GNU indent to prefer to break long lines before the boolean operators && and ||. The oq-nbbocq option causes GNU indent not have that preference. For example, the default option oq-bbocq (together with oq--line-length60cq and oq--ignore-newlinescq) makes code look like this:
if (mask && ((mask[0] == cq\0cq) || (mask[1] == cq\0cq && ((mask[0] == cq0cq) || (mask[0] == cq*cq)))))
Using the option oq-nbbocq will make it look like this:
if (mask && ((mask[0] == cq\0cq) || (mask[1] == cq\0cq && ((mask[0] == cq0cq) || (mask[0] == cq*cq)))))
The default oq-hnlcq, however, honours newlines in the input file by giving them the highest possible priority to break lines at. For example, when the input file looks like this:
if (mask && ((mask[0] == cq\0cq) || (mask[1] == cq\0cq && ((mask[0] == cq0cq) || (mask[0] == cq*cq)))))
then using the option oq-hnlcq, or oq--honour-newlinescq, together with the previously mentioned oq-nbbocq and oq--line-length60cq, will cause the output not to be what is given in the last example but instead will prefer to break at the positions where the code was broken in the input file:
if (mask && ((mask[0] == cq\0cq) || (mask[1] == cq\0cq && ((mask[0] == cq0cq) || (mask[0] == cq*cq)))))
The idea behind this option is that lines which are too long, but are already broken up, will not be touched by GNU indent. Really messy code should be run through indent at least once using the oq--ignore-newlinescq option though.
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.
More precisely, indent does not attempt to verify the closing delimiter (*/) for these C comments, and any whitespace on the line is totally transparent.
These control comments also function in their C++ formats, namely // *INDENT-OFF* and // *INDENT-ON*.
It should be noted that the internal state of indent remains unchanged over the course of the unformatted section. Thus, for example, turning off formatting in the middle of a function and continuing it after the end of the function may lead to bizarre results. It is therefore wise to be somewhat modular in selecting code to be left unformatted.
As a historical note, some earlier versions of indent produced error messages beginning with *INDENT**. These versions of indent were written to ignore any input text lines which began with such error messages. I have removed this incestuous feature from GNU indent.
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.
The oq-vcq option can be used to turn on verbose mode. When in verbose mode, indent reports when it splits one line of input into two more more lines of output, and gives some size statistics at completion.
The oq-pmtcq option causes indent to preserve the access and modification times on the output files. Using this option has the advantage that running indent on all source and header files in a project woncqt cause make to rebuild all targets. This option is only available on Operating Systems that have the POSIX utime(2) function.
BUGS
Please report any bugs to bug-indent@gnu.org.
When indent is run twice on a file, with the same profile, it should never change that file the second time. With the current design of indent, this can not be guaranteed, and it has not been extensively tested.
indent does not understand C. In some cases this leads to the inability to join lines. The result is that running a file through indent is irreversible, even if the used input file was the result of running indent with a given profile (oq.indent.procq).
While an attempt was made to get indent working for C++, it will not do a good job on any C++ source except the very simplest.
indent does not look at the given oq--line-lengthcq option when writing comments to the output file. This results often in comments being put far to the right. In order to prohibit indent from joining a broken line that has a comment at the end, make sure that the comments start on the first line of the break.
indent does not count lines and comments (see the oq-vcq option) when indent is turned off with /* *INDENT-OFF* */.
Comments of the form /*UPPERCASE*/ are not treated as comment but as an identifier, causing them to be joined with the next line. This renders comments of this type useless, unless they are embedded in the code to begin with.
COPYRIGHT
The following copyright notice applies to the indent program. The copyright and copying permissions for this manual appear near the beginning of oqindent.texinfocq and oqindent.infocq, and near the end of oqindent.1cq.
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 oqoqAS IScqcq AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Optionscq 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 -clin --case-brace-indentation -cbin --comment-delimiters-on-blank-lines -cdb --comment-indentation -cn --continuation-indentation -cin --continue-at-parentheses -lp --cuddle-do-while -cdw --cuddle-else -ce --declaration-comment-column -cdn --declaration-indentation -din --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 -cpn --format-all-comments -fca --format-first-column-comments -fc1 --gnu-style -gnu --honour-newlines -hnl --ignore-newlines -nhnl --ignore-profile -npro --indent-label -iln --indent-level -in --k-and-r-style -kr --leave-optional-blank-lines -nsob --leave-preprocessor-space -lps --left-justify-declarations -dj --line-comments-indentation -dn --line-length -ln --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 -ipn --paren-indentation -pin --preserve-mtime -pmt --preprocessor-indentation -ppin --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 -sbin --swallow-optional-blank-lines -sob --tab-size -tsn --use-tabs -ut --verbose -v
RETURN VALUE
UnknownFILES
$HOME/.indent.pro holds default options for indent.
AUTHORS
Carlo Wood
Joseph Arceneaux
Jim Kingdon
David Ingamells
HISTORY
Derived from the UCB program "indent".COPYING
Copyright (C) 1989, 1992, 1993, 1994, 1995, 1996 Free Software Foundation, Inc. Copyright (C) 1995, 1996 Joseph Arceneaux. Copyright (C) 1999 Carlo Wood. Copyright (C) 2001 David Ingamells.Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.