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 2008 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
32 $USAGE = "Usage: $PNAME [file ...]\n";
39 print "$file: $lineno: $msg\n";
61 # Amazingly, some ident strings are longer than 80 characters!
63 if (/^#pragma ident/) {
68 # The algorithm to calculate line length from cstyle.
71 if ($line =~ tr/\t/\t/ * 7 + length($line) > 80) {
72 # yes, there is a chance.
73 # replace tabs with spaces and check again.
76 s/\t+/' ' x (length($&) * 8 - length($`) % 8)/e;
78 if (length($eline) > 80) {
79 err "line > 80 characters";
83 if (/\/\*DSTYLED\*\//) {
97 # Before we do any more analysis, we want to prune out any
98 # quoted strings. This is a bit tricky because we need
99 # to be careful of backslashed quotes within quoted strings.
100 # I'm sure there is a very crafty way to do this with a
101 # single regular expression, but that will have to wait for
102 # somone with better regex juju that I; we do this by first
103 # eliminating the backslashed quotes, and then eliminating
104 # whatever quoted strings are left. Note that we eliminate
105 # the string by replacing it with "quotedstr"; this is to
106 # allow lines to end with a quoted string. (If we simply
107 # eliminated the quoted string, dstyle might complain about
108 # the line ending in a space or tab.)
111 s/\"[^\"]*\"/quotedstr/g;
114 err "space or tab at end of line";
117 if (/^[\t]+[ ]+[\t]+/) {
118 err "spaces between tabs";
126 err "indented by spaces not tabs";
133 if (!/^enum/ && !/^\t*struct/ && !/^\t*union/ && !/^typedef/ &&
134 !/^translator/ && !/^provider/) {
136 err "left brace not on its own line";
140 err "left brace not on its own line";
146 err "right brace not on its own line";
150 err "right brace not on its own line";
158 if (!$inclause && /^[\w ]+\//) {
159 err "predicate not at beginning of line";
162 if (!$inclause && /^\/[ \t]+\w/) {
163 err "space between '/' and expression in predicate";
166 if (!$inclause && /\w[ \t]+\/$/) {
167 err "space between expression and '/' in predicate";
170 if (!$inclause && /\s,/) {
171 err "space before comma in probe description";
174 if (!$inclause && /\w,[\w\s]/ && !/;$/) {
175 if (!/extern/ && !/\(/ && !/inline/) {
176 err "multiple probe descriptions on same line";
180 if ($inclause && /sizeof\(/) {
181 err "missing space after sizeof";
184 if ($inclause && /^[\w ]/) {
185 err "line doesn't begin with a tab";
188 if ($inclause && /,[\w]/) {
189 err "comma without trailing space";
192 if (/\w&&/ || /&&\w/ || /\w\|\|/ || /\|\|\w/) {
193 err "logical operator not set off with spaces";
197 # We want to catch "i<0" variants, but we don't want to
198 # erroneously flag translators.
201 if (/\w>/ || / >\w/ || /\w</ || /<\w/) {
202 err "comparison operator not set " .
207 if (/\w==/ || /==\w/ || /\w<=/ || />=\w/ || /\w!=/ || /!=\w/) {
208 err "comparison operator not set off with spaces";
211 if (/\w=/ || /=\w/) {
212 err "assignment operator not set off with spaces";
221 foreach $arg (@ARGV) {
225 die "$PNAME: $arg is not a valid file\n";
229 die $USAGE if (scalar(@files) == 0);
231 foreach $file (@files) {