MirBSD manpage: indent(1)

INDENT(1)                    BSD Reference Manual                    INDENT(1)


     indent - indent and format C program source


     indent [input-file [output-file]] [-bad | -nbad] [-bap | -nbap]
            [-bbb | -nbbb] [-bc | -nbc] [-bl | -br] [-bs | -nbs] [-cn] [-cdn]
            [-cdb | -ncdb] [-ce | -nce] [-cin] [-clin] [-csp | -ncsp] [-dn]
            [-din] [-dj | -ndj] [-ei | -nei] [-fc1 | -nfc1] [-in] [-ip | -nip]
            [-ln] [-lcn] [-lp | -nlp] [-lpi | -nlpi] [-npro] [-pcs | -npcs]
            [-psl | -npsl] [-sc | -nsc] [-sob | -nsob] [-st] [-Ttypename]
            [-troff] [-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
     file.BAK exists, it is overwritten.

     If output-file is specified, indent checks to make sure it is different
     from input-file.

     The options listed below control the formatting style imposed by indent.

     -bad, -nbad     If -bad is specified, a blank line is forced after every
                     block of declarations. Default: -nbad.

     -bap, -nbap     If -bap is specified, a blank line is forced after every
                     procedure body. Default: -nbap. Note: This option
                     currently has no effect.

     -bbb, -nbbb     If -bbb is specified, a blank line is forced before every
                     block comment. Default: -nbbb.

     -bc, -nbc       If -bc is specified, then a newline is forced after each
                     comma in a declaration. -nbc turns off this option. The
                     default is -nbc.

     -bl, -br        Specifying -bl lines up compound statements like this:

                           if (...)

                     Specifying -br (the default) makes them look like this:

                           if (...) {

     -bs, -nbs       Enables (disables) Bill Shannon mode, in which the sizeof
                     keyword is always followed by a space.

     -cn             The column in which comments on code start. The default
                     is 33.

                     If the option -c0 is used, comments are not touched if

     -cdn            The column in which comments on declarations start. The
                     default is for these comments to start in the same column
                     as those on code.

     -cdb, -ncdb     Enables (disables) the placement of comment delimiters on
                     blank lines. With this option enabled, comments look like

                            * this is a comment

                     Rather than like this:

                           /* this is a comment */

                     This only affects block comments, not comments to the
                     right of code. The default is -cdb.

     -ce, -nce       Enables (disables) forcing  "else"s to cuddle up to the
                     immediately preceding '}'. The default is -ce.

     -cin            Sets the continuation indent to be n. Continuation lines
                     will be indented that far from the beginning of the first
                     line of the statement. Parenthesized expressions have ex-
                     tra indentation added to indicate the nesting, unless -lp
                     is in effect. -ci defaults to the same value as -i.

     -clin           Causes case labels to be indented n tab stops to the
                     right of the containing switch statement. -cli0.5 causes
                     case labels to be indented half a tab stop. The default
                     is -cli0.

     -csp, -ncsp     Enables (disables) space after cast. The default is -csp.

     -dn             Controls the placement of comments which are not to the
                     right of code. Specifying -d1 means that such comments
                     are placed one indentation level to the left of code. The
                     default, -d0, lines up these comments with the code. See
                     the section on comment indentation below.

     -din            Specifies the indentation, in character positions, from a
                     declaration keyword to the following identifier. The de-
                     fault is -di16.

     -dj, -ndj       -dj left justifies declarations. -ndj indents declara-
                     tions the same as code. The default is -ndj.

     -ei, -nei       Enables (disables) special else-if processing. If it's
                     enabled, an if following an else will have the same in-
                     dentation as the preceding if statement. The default is

     -fc1, -nfc1     Enables (disables) the formatting of comments that start
                     in column 1. Often, comments whose leading '/' is in
                     column 1 have been carefully formatted by the programmer.
                     In such cases, -nfc1 should be used. The default is -fc1.

     -in             The number of spaces for one indentation level. The de-
                     fault is 8.

     -ip, -nip       Enables (disables) the indentation of parameter declara-
                     tions from the left margin. The default is -ip. Note:
                     This option currently has no effect.

     -ln             Maximum length of an output line. The default is 75.
                     Note: This option currently has no effect.

     -lcn            Specify a column width for comments.

     -lp, -nlp       Lines up code surrounded by parentheses in continuation
                     lines. If 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. For example, here is how a piece of
                     continued code looks with -nlp in effect:

                           p1 = first_procedure(second_procedure(p2, p3),

                     With -lp in effect (the default) the code looks somewhat

                           p1 = first_procedure(second_procedure(p2, p3),

                     Inserting two more newlines we get:

                           p1 = first_procedure(second_procedure(p2,

                     The default is -lp.

     -lpi, -nlpi     When -lpi is in effect (default), the continued lines
                     generated with -nlp are offset by a multiple (the
                     parenthesis level) of the default continuation indention
                     set with -ci, else only the basic continuation indention
                     is used. Caveat: if the option -lp is in effect (de-
                     fault), the value of this option is being ignored.

                     The default is -lpi.

     -npro           Causes the profile files, ./.indent.pro and
                     ~/.indent.pro, to be ignored.

     -pcs, -npcs     If true (-pcs) all procedure calls will have a space in-
                     serted between the name and the '('. The default is

     -psl, -npsl     If true (-psl) the names of procedures being defined are
                     placed in column 1 - their types, if any, will be left on
                     the previous lines. The default is -psl.

     -sc, -nsc       Enables (disables) the placement of asterisks ('*') at
                     the left edge of all comments. The default is -sc.

     -sob, -nsob     If -sob is specified, indent will swallow optional blank
                     lines. You can use this to get rid of blank lines after
                     declarations. Default: -nsob. Note: This option currently
                     has no effect.

     -st             Causes indent to take its input from stdin, and put its
                     output to stdout.

     -Ttypename      Adds typename to the list of type keywords. Names accumu-
                     late: -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. A symptom of missing typedef key-
                     words is having an extra space after an asterisk in a
                     code fragment such as:

                           int foo(char *bar, FILE * baz);

                     The same code formats nicely, adding -TFILE:

                           int foo(char *bar, FILE *baz);

                     This sounds like a painful thing to have to do, but it's
                     really a symptom of a problem in C: typedef causes a syn-
                     tactic change in the language and indent can't find all
                     instances of typedef.

     -troff          Causes 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.

     -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. The default is -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 direc-
     tory and including whatever switches you like. An .indent.pro file 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


     'Box' comments. indent assumes that any comment with a dash, star, or
     newline immediately after the start of comment (that is, '/*-', '/**', or
     '/*' followed immediately by a newline character) 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 inden-
     tation 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.

Comment indentation

     If a comment is on a line with code it is started in the "comment
     column", which is set by the -cn 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 -dn 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 automat-
     ically extended in extreme cases.

Preprocessor lines

     In general, 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 peculiari-
     ties introduced.

C syntax

     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 incom-
     plete and misformed syntax. In particular, the use of macros like:

           #define forever for(;;)

     is handled properly.


     HOME    Used to locate the full path to ~/.indent.pro.


     ./.indent.pro  profile file
     ~/.indent.pro  profile file


     The indent command appeared in 4.2BSD.


     indent has even more switches than ls(1).

     A common mistake is to try to indent all the C programs in a directory by

           $ indent *.c

     This is probably a bug, not a feature.

MirBSD #10-current              March 29, 2014                               4

Generated on 2022-12-24 01:00:14 by $MirOS: src/scripts/roff2htm,v 1.113 2022/12/21 23:14:31 tg Exp $ — This product includes material provided by mirabilos.

These manual pages and other documentation are copyrighted by their respective writers; their sources are available at the project’s CVSweb, AnonCVS and other mirrors. The rest is Copyright © 2002–2022 MirBSD.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.

Kontakt / Impressum & Datenschutzerklärung