5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
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.
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]
24 # Copyright 2006 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
33 $USAGE = "Usage: $PNAME [file ...]\n";
40 print "$file: $lineno: $msg\n";
62 # Amazingly, some ident strings are longer than 80 characters!
64 if (/^#pragma ident/) {
69 # The algorithm to calculate line length from cstyle.
72 if ($line =~ tr/\t/\t/ * 7 + length($line) > 80) {
73 # yes, there is a chance.
74 # replace tabs with spaces and check again.
77 s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
79 if (length($eline) > 80) {
80 err "line > 80 characters";
84 if (/\/\*DSTYLED\*\//) {
98 # Before we do any more analysis, we want to prune out any
99 # quoted strings. This is a bit tricky because we need
100 # to be careful of backslashed quotes within quoted strings.
101 # I'm sure there is a very crafty way to do this with a
102 # single regular expression, but that will have to wait for
103 # somone with better regex juju that I; we do this by first
104 # eliminating the backslashed quotes, and then eliminating
105 # whatever quoted strings are left. Note that we eliminate
106 # the string by replacing it with "quotedstr"; this is to
107 # allow lines to end with a quoted string. (If we simply
108 # eliminated the quoted string, dstyle might complain about
109 # the line ending in a space or tab.)
112 s/\"[^\"]*\"/quotedstr/g;
115 err "space or tab at end of line";
118 if (/^[\t]+[ ]+[\t]+/) {
119 err "spaces between tabs";
127 err "indented by spaces not tabs";
134 if (!/^enum/ && !/^\t*struct/ && !/^\t*union/ && !/^typedef/ &&
135 !/^translator/ && !/^provider/) {
137 err "left brace not on its own line";
141 err "left brace not on its own line";
147 err "right brace not on its own line";
151 err "right brace not on its own line";
159 if (!$inclause && /^[\w ]+\//) {
160 err "predicate not at beginning of line";
163 if (!$inclause && /^\/[ \t]+\w/) {
164 err "space between '/' and expression in predicate";
167 if (!$inclause && /\w[ \t]+\/$/) {
168 err "space between expression and '/' in predicate";
171 if (!$inclause && /\s,/) {
172 err "space before comma in probe description";
175 if (!$inclause && /\w,[\w\s]/ && !/;$/) {
176 if (!/extern/ && !/\(/ && !/inline/) {
177 err "multiple probe descriptions on same line";
181 if ($inclause && /sizeof\(/) {
182 err "missing space after sizeof";
185 if ($inclause && /^[\w ]/) {
186 err "line doesn't begin with a tab";
189 if ($inclause && /,[\w]/) {
190 err "comma without trailing space";
193 if (/\w&&/ || /&&\w/ || /\w\|\|/ || /\|\|\w/) {
194 err "logical operator not set off with spaces";
198 # We want to catch "i<0" variants, but we don't want to
199 # erroneously flag translators.
202 if (/\w>/ || / >\w/ || /\w</ || /<\w/) {
203 err "comparison operator not set " .
208 if (/\w==/ || /==\w/ || /\w<=/ || />=\w/ || /\w!=/ || /!=\w/) {
209 err "comparison operator not set off with spaces";
212 if (/\w=/ || /=\w/) {
213 err "assignment operator not set off with spaces";
222 foreach $arg (@ARGV) {
226 die "$PNAME: $arg is not a valid file\n";
230 die $USAGE if (scalar(@files) == 0);
232 foreach $file (@files) {