6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22 #
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # @(#)cstyle 1.58 98/09/09 (from shannon)
27 #ident "%Z%%M% %I% %E% SMI"
28 #
29 # cstyle - check for some common stylistic errors.
30 #
31 # cstyle is a sort of "lint" for C coding style.
32 # It attempts to check for the style used in the
33 # kernel, sometimes known as "Bill Joy Normal Form".
34 #
35 # There's a lot this can't check for, like proper indentation
36 # of code blocks. There's also a lot more this could check for.
37 #
38 # A note to the non perl literate:
39 #
40 # perl regular expressions are pretty much like egrep
41 # regular expressions, with the following special symbols
42 #
43 # \s any space character
44 # \S any non-space character
45 # \w any "word" character [a-zA-Z0-9_]
46 # \W any non-word character
47 # \d a digit [0-9]
48 # \D a non-digit
614 if (/}(else|while)/) {
615 err("missing space after right brace");
616 }
617 if (/}\s\s+(else|while)/) {
618 err("extra space after right brace");
619 }
620 if (/\b_VOID\b|\bVOID\b|\bSTATIC\b/) {
621 err("obsolete use of VOID or STATIC");
622 }
623 if (/\b$typename\*/o) {
624 err("missing space between type name and *");
625 }
626 if (/^\s+#/) {
627 err("preprocessor statement not in column 1");
628 }
629 if (/^#\s/) {
630 err("blank after preprocessor #");
631 }
632 if (/!\s*(strcmp|strncmp|bcmp)\s*\(/) {
633 err("don't use boolean ! with comparison functions");
634 }
635
636 #
637 # We completely ignore, for purposes of indentation:
638 # * lines outside of functions
639 # * preprocessor lines
640 #
641 if ($check_continuation && $in_function && !$in_cpp) {
642 process_indent($_);
643 }
644 if ($picky) {
645 # try to detect spaces after casts, but allow (e.g.)
646 # "sizeof (int) + 1", "void (*funcptr)(int) = foo;", and
647 # "int foo(int) __NORETURN;"
648 if ((/^\($typename( \*+)?\)\s/o ||
649 /\W\($typename( \*+)?\)\s/o) &&
650 !/sizeof\s*\($typename( \*)?\)\s/o &&
651 !/\($typename( \*+)?\)\s+=[^=]/o) {
652 err("space after cast");
653 }
|
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
8 #
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
13 #
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
19 #
20 # CDDL HEADER END
21 #
22 #
23 # Copyright 2008 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26 # cstyle - check for some common stylistic errors.
27 #
28 # cstyle is a sort of "lint" for C coding style.
29 # It attempts to check for the style used in the
30 # kernel, sometimes known as "Bill Joy Normal Form".
31 #
32 # There's a lot this can't check for, like proper indentation
33 # of code blocks. There's also a lot more this could check for.
34 #
35 # A note to the non perl literate:
36 #
37 # perl regular expressions are pretty much like egrep
38 # regular expressions, with the following special symbols
39 #
40 # \s any space character
41 # \S any non-space character
42 # \w any "word" character [a-zA-Z0-9_]
43 # \W any non-word character
44 # \d a digit [0-9]
45 # \D a non-digit
611 if (/}(else|while)/) {
612 err("missing space after right brace");
613 }
614 if (/}\s\s+(else|while)/) {
615 err("extra space after right brace");
616 }
617 if (/\b_VOID\b|\bVOID\b|\bSTATIC\b/) {
618 err("obsolete use of VOID or STATIC");
619 }
620 if (/\b$typename\*/o) {
621 err("missing space between type name and *");
622 }
623 if (/^\s+#/) {
624 err("preprocessor statement not in column 1");
625 }
626 if (/^#\s/) {
627 err("blank after preprocessor #");
628 }
629 if (/!\s*(strcmp|strncmp|bcmp)\s*\(/) {
630 err("don't use boolean ! with comparison functions");
631 }
632 if (/\batomic_add_(8|16|32|64|char|short|int|long)\([^,]*,\s*1\)/) {
633 err("use atomic_inc_*(...) instead of atomic_add_*(..., 1)");
634 }
635 if (/\batomic_add_(8|16|32|64|char|short|int|long)\([^,]*,\s*-1\)/) {
636 err("use atomic_dec_*(...) instead of atomic_add_*(..., -1)");
637 }
638
639 #
640 # We completely ignore, for purposes of indentation:
641 # * lines outside of functions
642 # * preprocessor lines
643 #
644 if ($check_continuation && $in_function && !$in_cpp) {
645 process_indent($_);
646 }
647 if ($picky) {
648 # try to detect spaces after casts, but allow (e.g.)
649 # "sizeof (int) + 1", "void (*funcptr)(int) = foo;", and
650 # "int foo(int) __NORETURN;"
651 if ((/^\($typename( \*+)?\)\s/o ||
652 /\W\($typename( \*+)?\)\s/o) &&
653 !/sizeof\s*\($typename( \*)?\)\s/o &&
654 !/\($typename( \*+)?\)\s+=[^=]/o) {
655 err("space after cast");
656 }
|