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 https://opensource.org/licenses/CDDL-1.0.
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]
29 .Nd check for some common stylistic errors in C source files
36 inspects C source files (*.c and *.h) for common stylistic errors.
37 It attempts to check for the cstyle documented in
38 .Lk http://www.cis.upenn.edu/~lee/06cse480/data/cstyle.ms.pdf .
39 Note that there is much in that document that
41 be checked for; just because your code is
43 does not mean that you've followed Sun's C style.
49 Check continuation line indentation inside of functions.
51 states that all statements must be indented to an appropriate tab stop,
52 and any continuation lines after them must be indented
54 four spaces from the start line.
55 This option enables a series of checks designed to find
56 continuation line problems within functions only.
57 The checks have some limitations; see
58 .Sy CONTINUATION CHECKING ,
61 Performs some of the more picky checks.
66 rules, and tries to detect spaces after casts.
67 Used as part of the putback checks.
69 Verbose output; includes the text of the line of error, and, for
71 the first statement in the current continuation block.
73 Check for use of non-POSIX types.
74 Historically, types like
78 were used, but they are now deprecated in favor of the POSIX
83 This detects any use of the deprecated types.
84 Used as part of the putback checks.
86 Also print GitHub-Actions-style
92 .Bl -tag -compact -width ".Ev CI"
94 If set and nonempty, equivalent to
98 .Sh CONTINUATION CHECKING
99 The continuation checker is a reasonably simple state machine that knows
100 something about how C is laid out, and can match parenthesis, etc. over
102 It does have some limitations:
105 Preprocessor macros which cause unmatched parenthesis will confuse the
106 checker for that line.
107 To fix this, you'll need to make sure that each branch of the
109 statement has balanced parenthesis.
113 macros do not require
114 .Sy ;\& Ns s after them.
117 be ALL_CAPS; any lower case letters will cause bad output.
119 The bad output will generally be corrected after the next
120 .Sy ;\& , { , No or Sy } .
122 Some continuation error messages deserve some additional explanation:
124 .It Sy multiple statements continued over multiple lines
125 A multi-line statement which is not broken at statement boundaries.
127 .Bd -literal -compact -offset Ds
128 if (this_is_a_long_variable == another_variable) a =
132 Will trigger this error.
134 .Bd -literal -compact -offset Ds
135 if (this_is_a_long_variable == another_variable)
138 .It Sy empty if/for/while body not on its own line
139 For visibility, empty bodies for if, for, and while statements should be
142 .Bd -literal -compact -offset Ds
143 while (do_something(&x) == 0);
146 Will trigger this error.
148 .Bd -literal -compact -offset Ds
149 while (do_something(&x) == 0)