INDENT(1) | General Commands Manual | INDENT(1) |
indent
—
indent |
[input-file [output-file]]
[-bacc | -nbacc ]
[-bad | -nbad ]
[-bap | -nbap ]
[-bbb | -nbbb ]
[-bc | -nbc ]
[-bl ] [-br ]
[-c n]
[-cd n]
[-cdb | -ncdb ]
[-ce | -nce ]
[-ci n]
[-cli n]
[-d n]
[-di n]
[-ei | -nei ]
[-eei | -neei ]
[-fc1 | -nfc1 ]
[-i n]
[-ip | -nip ]
[-l n]
[-lc n]
[-lp | -nlp ]
[-npro ] [-pcs |
-npcs ] [-psl |
-npsl ] [-sc |
-nsc ] [-sob |
-nsob ] [-st ]
[-troff ] [-ut |
-nut ] [-v |
-nv ] |
indent
is a C program formatter. It reformats the C
program in the input-file according to the switches. The
switches which can be specified are described below. They may appear before or
after the file names.
NOTE: If you only specify an input-file, the formatting is done `in-place', that is, the formatted file is written back into input-file and a backup copy of input-file is written in the current directory. If input-file is named ‘/blah/blah/file’, the backup file is named file.BAK.
If output-file is specified,
indent
checks to make sure it is different from
input-file.
If no input-file is specified input is read from stdin and the formatted file is written to stdout.
The options listed below control the formatting style imposed by
indent
.
-bacc
,
-nbacc
-bacc
is specified, a blank line is forced
around every conditional compilation block. For example, in front of every
#ifdef and after every #endif. Other blank lines surrounding such blocks
will be swallowed. Default: -nbacc
.-bad
,
-nbad
-bad
is specified, a blank line is forced after
every block of declarations. Default: -nbad
.-bap
,
-nbap
-bap
is specified, a blank line is forced after
every procedure body. Default: -nbap
.-bbb
,
-nbbb
-bbb
is specified, a blank line is forced
before every block comment. Default: -nbbb
.-bc
,
-nbc
-bc
is specified, then a newline is forced
after each comma in a declaration. -nbc
turns off
this option. Default: -bc
.-br
,
-bl
-bl
lines up compound statements like
this:
if (...) { code }
Specifying -br
(the default) makes
them look like this:
if (...) { code }
-bs
,
-nbs
-bs
is specified, a blank is forced after
sizeof
. Default:
-nbs
.-c
n-c33
.-cd
n-cdb
,
-ncdb
/* * this is a comment */
Rather than like this:
/* this is a comment */
This only affects block comments, not comments to the right of
code. Default: -cdb
.
-ce
,
-nce
-ce
.-ci
n-lp
is in effect.
-ci
defaults to the same value as
-i
.-cli
nswitch
statement.
-cli0.5
causes case labels to be indented half a
tab stop. Default: -cli0
.-d
n-d1
means that such comments are placed
one indentation level to the left of code. Specifying the default
-d0
lines up these comments with the code. See the
section on comment indentation below.-di
n-di16
.-dj
,
-ndj
-dj
left justifies declarations. -ndj
indents
declarations the same as code. Default: -ndj
.-ei
,
-nei
else-if
processing. If
it's enabled, an if
following an
else
will have the same indentation as the
preceding if
statement. Default:
-ei
.-eei
,
-neei
if
and
while
statements. These continuation lines will be
indented one extra level. Default: -neei
.-fc1
,
-nfc1
-nfc1
should be used. Default: -fc1
.-i
n-i8
.-ip
,
-nip
-ip
.-l
n-l78
.-lp
,
-nlp
-nlp
in effect:
p1 = first_procedure(second_procedure(p2, p3), third_procedure(p4,p5));
With -lp
in effect (the default) the
code looks somewhat clearer:
p1 = first_procedure(second_procedure(p2, p3), third_procedure(p4,p5));
Inserting two more newlines we get:
p1 = first_procedure(second_procedure(p2, p3), third_procedure(p4 p5));
-npro
-pcs
,
-npcs
-pcs
) all procedure calls will have a
space inserted between the name and the `('. Default:
-npcs
.-psl
,
-npsl
-psl
) the names of procedures being
defined are placed in column 1 - their types, if any, will be left on the
previous lines. Default: -psl
.-sc
,
-nsc
-sc
.-sob
,
-nsob
-sob
is specified, indent will swallow optional
blank lines. You can use this to get rid of blank lines after
declarations. Default: -nsob
.-st
indent
to take its input from stdin, and
put its output to stdout.-T
typename-T
can be specified more than once.
You need to specify all the typenames that appear in your program that are
defined by typedef
- nothing will be harmed if you
miss a few, but the program won't be formatted as nicely as it should.
This sounds like a painful thing to have to do, but it's really a symptom
of a problem in C: typedef
causes a syntactic
change in the language and indent
can't find all
instances of typedef
.-troff
indent
to format the program for processing
by troff(1). It will produce
a fancy listing in much the same spirit as
vgrind(1). If the output
file is not specified, the default is standard output, rather than
formatting in place.-ut
,
-nut
-ut
.-v
,
-nv
-v
turns on `verbose' mode; -nv
turns it off. When in
verbose mode, indent
reports when it splits one
line of input into two or more lines of output, and gives some size
statistics at completion. Default: -nv
.You may set up your own `profile' of defaults to
indent
by creating a file called
.indent.pro in your login directory and/or the
current directory and including whatever switches you like. A `.indent.pro'
in the current directory takes precedence over the one in your login
directory. If indent
is run and a profile file
exists, then it is read to set up the program's defaults. Switches on the
command line, though, always override profile switches. The switches should
be separated by spaces, tabs or newlines.
indent
assumes that any comment with a dash or star
immediately after the start of comment (that is, `/*-' or `/**') is a comment
surrounded by a box of stars. Each line of such a comment is left unchanged,
except that its indentation may be adjusted to account for the change in
indentation of the first line of the comment.
Straight text. All other comments are treated as
straight text. indent
fits as many words (separated
by blanks, tabs, or newlines) on a line as possible. Blank lines break
paragraphs.
-c
n command line
parameter. Otherwise, the comment is started at n
indentation levels less than where code is currently being placed, where
n is specified by the
-d
n command line parameter. If
the code on a line extends past the comment column, the comment starts further
to the right, and the right margin may be automatically extended in extreme
cases.
indent
leaves preprocessor lines alone. The
only reformatting that it will do is to straighten up trailing comments. It
leaves embedded comments alone. Conditional compilation
(#ifdef...#endif
) is recognized and
indent
attempts to correctly compensate for the
syntactic peculiarities introduced.
indent
understands a substantial amount about the syntax
of C, but it has a `forgiving' parser. It attempts to cope with the usual
sorts of incomplete and misformed syntax. In particular, the use of macros
like:
#define forever for(;;)
is handled properly.
indent
uses the HOME
environment
variable.
indent
command appeared in
4.2BSD.
indent
has even more switches than
ls(1).
A common mistake that often causes grief is typing:
indent *.c
to the shell in an attempt to indent all the C programs in a directory. This is probably a bug, not a feature.
February 24, 2016 | NetBSD 8.99 |