BSD 4_1c_2 release
[unix-history] / usr / man / man1 / indent.1
CommitLineData
331ce6fe
DW
1.TH INDENT 1 "22 December 1977"
2.UC 4
3.SH NAME
4indent \- indent and format a C program source
5.SH SYNOPSIS
6indent ifile [ ofile ] [ args ]
7.SH DESCRIPTION
8The arguments that can be specified follows. They
9may appear before or after the file names.
10
11.TP 10
12.B ifile
13Input file specification.
14.TP 10
15.B ofile
16Output file specification.
17.br
18If omitted, then the indented formatted file will be written
19back into the input file,
20and there will be a "back\-up" copy of ifile written
21in the current directory.
22For an ifile named "/blah/blah/file", the backup file will be
23named ".Bfile". (It will only be listed when the `\-a' argument
24is specified in ls.)
25If ofile is specified, indent checks to make sure it is different from ifile.
26.TP 10
27.B \-lnnn
28Maximum length of an output line. The default is 75.
29.TP 10
30.B \-cnnn
31The column in which comments will start. The default is 33.
32.TP 10
33.B \-cdnnn
34The column in which comments on declarations will start. The default
35is for these comments to start in the same column as other comments.
36.TP 10
37.B \-innn
38The number of spaces for one indentation level. The default is 4.
39.TP 10
40.B \-dj,\-ndj
41\-dj will cause declarations to be left justified. \-ndj will cause
42them to be indented the same as code. The default is \-ndj.
43.TP 10
44.B \-v,\-nv
45\-v turns on "verbose" mode, \-nv turns it off. When in verbose
46mode, indent will report when it
47splits one line of input into two or more lines of output,
48and it will give some size statistics at completion. The default is \-nv.
49.TP 10
50.B \-bc,\-nbc
51If \-bc is specified, then a newline will be forced after each
52comma in a declaration. \-nbc will turn off this option. The default is \-bc.
53.TP 10
54.B \-dnnn
55This option controls the placement of comments which are not to the right
56of code.
57Specifying \-d2 means that such comments will be placed two
58indentation levels to the left of code.
59The default \-d0 lines up these comments with the code.
60See the section on comment indentation below.
61.TP 10
62.B \-br,\-bl
63Specifying \-bl will cause
64complex statements to be lined up like this:
65.ne 4
66.nf
67 if (...)
68 {
69 code
70 }
71.fi
72Specifying \-br (the default) will make them look like this:
73.ne 3
74.nf
75 if (...) {
76 code
77 }
78.fi
79.PP
80You may set up your own `profile' of defaults to indent
81by creating the file `/usr/your\-name/.indent.pro'
82(where your\-name is your
83login name)
84and including whatever switches you like.
85If indent is run and a profile file exists, then it is read
86to set up the program's defaults.
87Switches on the command line, though,
88will always over\-ride profile switches.
89The profile
90file must be a single line of not more than 127 characters.
91The switches should be seperated on the line by spaces or tabs.
92Indent is intended primarily as a C program indenter.
93Specifically, indent will:
94.IP " >" 5
95indent code lines
96.IP " >" 5
97align comments
98.IP " >" 5
99insert spaces around operators where necessary
100.IP " >" 5
101break up declaration lists as in "int a,b,c;".
102.PP
103It will not break up long statements to make them fit within the
104maximum line length, but it will flag lines that are too long. Lines
105will be broken so that each statement starts a new line, and braces
106will appear alone on a line. (See the \-br option to inhibit this.)
107Also, an attempt is made to line up identifiers in declarations.
108
109Multi\-line expressions
110.br
111Indent will not break up complicated expressions that extend over multiple
112lines, but it will usually correctly indent such expressions which have
113already been broken up. Such an expression might end up looking like this:
114.ne 10
115.in +4
116.nf
117x =
118 (
119 (Arbitrary parenthesized expression)
120 +
121 (
122 (Parenthesized expression)
123 *
124 (Parenthesized expression)
125 )
126 );
127
128.fi
129.PP
130Comments
131.br
132Indent recognizes four kinds of comments. They are straight text, "box" comments,
133UNIX\-style comments,
134and comments that should be passed thru unchanged. The action taken with these
135various types is as follows:
136
137 "Box" comments: The DSG documentation standards specify that boxes will be
138placed around section headers. Indent assumes that any comment with a dash
139immediately after the start of comment (i.e. "/*\-") is such a box. Each line
140of such a comment will be left unchanged, except that the first non\-blank
141character of each successive line will be lined up with the beginning
142slash of the first line. Box comments will be indented (see below).
143
144 Unix\-style comments: This is the type of section header which is used
145extensively in the UNIX system source. If the start of comment ('/*') appears on a
146line by itself, indent assumes that it is a UNIX\-style comment. These will be
147treated similarly to box comments, except the first non\-blank character on each
148line will be lined up with the '*' of the '/*'.
149
150 Unchanged comments: Any comment which starts in column 1 will be left completely
151unchanged. This is intended primarily for documentation header pages.
152The check for unchanged comments is made before the check for UNIX\-style comments.
153
154 Straight text: All other comments are treated as straight text. Indent will fit
155as many words (separated by blanks, tabs, or newlines) on a line as possible.
156Straight text comments will be indented.
157
158Comment indentation
159Box, UNIX\-style, and straight text comments may be indented.
160If a comment is on a line
161with code it will be started in the "comment
162column", which is set by the \-cnnn command line parameter.
163Otherwise, the
164comment will be started at nnn indentation levels less than where code is
165currently being placed, where nnn is specified by the \-dnnn command line parameter. (Indented
166comments will never be placed in column 1.)
167If the code on a line extends past the comment column, the comment will be moved
168to the next line.
169
170.SH DIAGNOSTICS
171Diagnostic error messsages, mostly to tell that a text line has been broken
172or is too long for the output line, will be printed on the controlling tty.
173.SH FILES
174/usr/your\-name/.indent.pro \- profile file
175.SH BUGS
176Doesn't know how to format "long" declarations.