1 .\" Copyright 2009 Sun Microsystems, Inc. All rights reserved.
2 .\" Use is subject to license terms.
6 .\" The contents of this file are subject to the terms of the
7 .\" Common Development and Distribution License (the "License").
8 .\" You may not use this file except in compliance with the License.
10 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 .\" or http://www.opensolaris.org/os/licensing.
12 .\" See the License for the specific language governing permissions
13 .\" and limitations under the License.
15 .\" When distributing Covered Code, include this CDDL HEADER in each
16 .\" file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 .\" If applicable, add the following below this CDDL HEADER, with the
18 .\" fields enclosed by brackets "[]" replaced with your own identifying
19 .\" information: Portions Copyright [yyyy] [name of copyright owner]
23 .TH CSTYLE 1ONBLD "Feb 22, 2017"
26 \- check for some common stylistic errors in C source files
28 \fBcstyle [-chpvCP] [-o constructs] [file...]\fP
32 inspects C source files (*.c and *.h) for common stylistic errors. It
33 attempts to check for the cstyle documented in
34 \fIcstyle.ms.pdf\fP. Note that there is much
37 be checked for; just because your code is \fBcstyle(1ONBLD)\fP clean does not
38 mean that you've followed illumos C style. \fICaveat emptor\fP.
41 The following options are supported:
44 Check continuation line indentation inside of functions. illumos C style
45 states that all statements must be indented to an appropriate tab stop,
46 and any continuation lines after them must be indented \fIexactly\fP four
47 spaces from the start line. This option enables a series of checks
48 designed to find continuation line problems within functions only. The
49 checks have some limitations; see CONTINUATION CHECKING, below.
52 Performs heuristic checks that are sometimes wrong. Not generally used.
55 Performs some of the more picky checks. Includes ANSI #else and #endif
56 rules, and tries to detect spaces after casts. Used as part of the
60 Verbose output; includes the text of the line of error, and, for
61 \fB-c\fP, the first statement in the current continuation block.
64 Ignore errors in header comments (i.e. block comments starting in the
65 first column). Not generally used.
68 Check for use of non-POSIX types. Historically, types like "u_int" and
69 "u_long" were used, but they are now deprecated in favor of the POSIX
70 types uint_t, ulong_t, etc. This detects any use of the deprecated
71 types. Used as part of the putback checks.
73 .B \-o \fIconstructs\fP
74 Allow a comma-separated list of additional constructs. Available
78 Allow doxygen-style block comments (\fB/**\fP and \fB/*!\fP)
81 Allow splint-style lint comments (\fB/*@...@*/\fP)
84 The cstyle rule for the illumos gate is that all new files must
85 be \fB-pP\fP clean. For existing files, the following invocations are
86 run against both the old and new files:
94 If the old file gave no errors for one of the invocations, the new file
95 must also give no errors. This way, files can only become more clean.
96 .SH CONTINUATION CHECKING
98 The continuation checker is a resonably simple state machine that knows
99 something about how C is layed out, and can match parenthesis, etc. over
100 multiple lines. It does have some limitations:
103 Preprocessor macros which cause unmatched parenthesis will confuse the
104 checker for that line. To fix this, you'll need to make sure that each
105 branch of the #if statement has balanced parenthesis.
108 Some \fBcpp\fP macros do not require ;s after them. Any such macros
109 *must* be ALL_CAPS; any lower case letters will cause bad output.
111 The bad output will generally be corrected after the next \fB;\fP,
114 Some continuation error messages deserve some additional explanation
117 multiple statements continued over multiple lines
118 A multi-line statement which is not broken at statement
119 boundries. For example:
122 if (this_is_a_long_variable == another_variable) a =
126 Will trigger this error. Instead, do:
128 if (this_is_a_long_variable == another_variable)
134 empty if/for/while body not on its own line
135 For visibility, empty bodies for if, for, and while statements should be
136 on their own line. For example:
139 while (do_something(&x) == 0);
141 Will trigger this error. Instead, do:
143 while (do_something(&x) == 0)