xref: /titanic_44/usr/src/tools/scripts/cstyle.1 (revision c28749e97052f09388969427adf7df641cdcdc22)
ident "%Z%%M% %I% %E% SMI"
Copyright 2005 Sun Microsystems, Inc. All rights reserved.
Use is subject to license terms.

CDDL HEADER START

The contents of this file are subject to the terms of the
Common Development and Distribution License, Version 1.0 only
(the "License"). You may not use this file except in compliance
with the License.

You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
or http://www.opensolaris.org/os/licensing.
See the License for the specific language governing permissions
and limitations under the License.

When distributing Covered Code, include this CDDL HEADER in each
file and include the License file at usr/src/OPENSOLARIS.LICENSE.
If applicable, add the following below this CDDL HEADER, with the
fields enclosed by brackets "[]" replaced with your own identifying
information: Portions Copyright [yyyy] [name of copyright owner]

CDDL HEADER END

cstyle 1 "28 March 2005"
NAME
cstyle - check for some common stylistic errors in C source files
SYNOPSIS
cstyle [-chpvCP] [-o constructs] [file...]

DESCRIPTION
"OS-Net build tools" "cstyle" "" "cstyle"

cstyle inspects C source files (*.c and *.h) for common sylistic errors. It attempts to check for the cstyle documented in /shared/ON/general_docs/cstyle.ms.pdf. Note that there is much in that document that cannot be checked for; just because your code is cstyle(1) clean does not mean that you've followed Sun's C style. Caveat emptor.

OPTIONS

The following options are supported:

4 -c Check continuation line indentation inside of functions. Sun's C style states that all statements must be indented to an appropriate tab stop, and any continuation lines after them must be indented exactly four spaces from the start line. This option enables a series of checks designed to find contination line problems within functions only. The checks have some limitations; see CONTINUATION CHECKING, below.

4 -h Performs heuristic checks that are sometimes wrong. Not generally used.

4 -p Performs some of the more picky checks. Includes ANSI #else and #endif rules, and tries to detect spaces after casts. Used as part of the putback checks.

4 -v Verbose output; includes the text of the line of error, and, for -c, the first statement in the current continuation block.

4 -C Ignore errors in header comments (i.e. block comments starting in the first column). Not generally used.

4 -P Check for use of non-POSIX types. Historically, types like "u_int" and "u_long" were used, but they are now deprecated in favor of the POSIX types uint_t, ulong_t, etc. This detects any use of the deprecated types. Used as part of the putback checks.

4 -o constructs Allow a comma-seperated list of additional constructs. Available constructs include:

10 doxygen Allow doxygen-style block comments (\fT/** and \fT/*!)

10 splint Allow splint-style lint comments (\fT/*@...@*/)

NOTES

The cstyle rule for the OS/Net consolidation is that all new files must be -pP clean. For existing files, the following invocations are run against both the old and new files:

4 cstyle file

4 cstyle -p file

4 cstyle -pP file

If the old file gave no errors for one of the invocations, the new file must also give no errors. This way, files can only become more clean.

CONTINUATION CHECKING

The continuation checker is a resonably simple state machine that knows something about how C is layed out, and can match parenthesis, etc. over multiple lines. It does have some limitations:

4 1. Preprocessor macros which cause unmatched parenthesis will confuse the checker for that line. To fix this, you'll need to make sure that each branch of the #if statement has balanced parenthesis.

4 2. Some cpp macros do not require ;s after them. Any such macros *must* be ALL_CAPS; any lower case letters will cause bad output.

The bad output will generally be corrected after the next ;, {, or }.

Some continuation error messages deserve some additional explanation

4 multiple statements continued over multiple lines A multi-line statement which is not broken at statement boundries. For example:

4 if (this_is_a_long_variable == another_variable) a =

b + c;

Will trigger this error. Instead, do:

8 if (this_is_a_long_variable == another_variable)

a = b + c;

4 empty if/for/while body not on its own line For visibility, empty bodies for if, for, and while statements should be on their own line. For example:

4 while (do_something(&x) == 0);

Will trigger this error. Instead, do:

8 while (do_something(&x) == 0)

;