INDENT(1) — USER COMMANDS
NAME
indent − indent and format C program source
SYNOPSIS
indent input-file [ output-file ] [ −lnnn ] [ −cnnn ] [ −cdnnn ] [ −innn ] [ −dj | −ndj ]
[ −v | −nv ] [ −bc | −nbc ] [ −dnnn ] [ −br | −bl ]
DESCRIPTION
Indent is intended primarily as a C program formatter. Specifically, indent:
•indents code lines
•aligns comments
•inserts spaces around operators where necessary
•breaks up declaration lists as in ‘int a,b,c;’.
Indent does not break up long statements to make them fit within the maximum line length, but does flag lines that are too long. Lines are broken so that each statement starts a new line, and braces appear alone on a line — see the −br option to inhibit this. Also, an attempt is made to line up identifiers in declarations.
The flags which can be specified follow. They may appear before or after the file names.
NOTE: If you specify only 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 ‘/usr/src/file’, the backup file is named .Bfile.
If output-file is specified, indent checks to make sure it is different from input-file.
OPTIONS
The options listed here control the formatting style imposed by indent.
−lnnn Maximum length of an output line. The default is 75.
−cnnn The column in which comments start. The default is 33.
−cdnnn The column in which comments on declarations start. The default is for these comments to start in the same column as other comments.
−innn The number of spaces for one indentation level. The default is 4.
−dj,−ndj −dj left justifies declarations. −ndj indents declarations the same as code. The default is −ndj.
−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.
−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 −bc.
−dnnn This option controls the placement of comments which are not to the right of code. Specifying −d2 means that such comments are placed two indentation levels to the left of code. The default −d0 lines up these comments with the code. See the section on comment indentation below.
−br,−bl Specifying −bl lines up complex statements like this:
if (...)
{
code
}
Specifying −br (the default) makes them look like this:
if (...) {
code
}
FURTHER DESCRIPTION
You may set up your own ‘profile’ of defaults to indent by creating a file called .indent.pro in your login directory and including whatever switches you like. 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 profile file must be a single line of not more than 127 characters. The switches should be separated on the line by spaces or tabs.
Multi-line expressions
Indent does not break up complicated expressions that extend over multiple lines, but it usually correctly indents such expressions which have already been broken up. Such an expression might end up looking like this:
x =
(
(Arbitrary parenthesized expression)
+
(
(Parenthesized expression)
∗
(Parenthesized expression)
)
);
Comments
Indent recognizes four kinds of comments. They are: straight text, ‘box’ comments, UNIX-style comments, and comments that should be passed through unchanged. The action taken with these various types are as follows:
‘Box’ comments. Indent assumes that any comment with a dash immediately after the start of comment (that is, ‘/∗−’) is a comment surrounded by a box of stars. Each line of such a comment is left unchanged, except that the first non-blank character of each successive line is lined up with the beginning slash of the first line. Box comments are be indented (see below).
‘Unix-style’ comments. This is the type of section header which is used extensively in the UNIX system source. If the start of comment (‘/∗’) appears on a line by itself, indent assumes that it is a UNIX-style comment. These are treated similarly to box comments, except the first non-blank character on each line is lined up with the ‘∗’ of the ‘/∗’.
Unchanged comments. Any comment which starts in column 1 is left completely unchanged. This is intended primarily for documentation header pages. The check for unchanged comments is made before the check for UNIX-style comments.
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. Straight text comments are indented.
Comment indentation
Box, UNIX-style, and straight text comments may be indented. If a comment is on a line with code it is started in the ‘comment column’, which is set by the −cnnn command line parameter. Otherwise, the comment is started at nnn indentation levels less than where code is currently being placed, where nnn is specified by the −dnnn command line parameter. Indented comments are never placed in column 1. If the code on a line extends past the comment column, the comment is moved to the next line.
DIAGNOSTICS
Diagnostic error messages, mostly to tell that a text line has been broken or is too long for the output line.
FILES
.indent.proprofile file
BUGS
Does not know how to format ‘long’ declarations.
Sun Release 2.0 — Last change: 28 September 1984