Print this page
7085 add support for "if" and "else" statements in dtrace


   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 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 




  28 require 5.8.4;
  29 
  30 $PNAME = $0;
  31 $PNAME =~ s:.*/::;
  32 $USAGE = "Usage: $PNAME [file ...]\n";
  33 $errs = 0;
  34 
  35 sub err
  36 {
  37         my($msg) = @_;
  38 
  39         print "$file: $lineno: $msg\n";
  40         $errs++;
  41 }
  42 
  43 sub dstyle
  44 {
  45         open(FILE, "$file");
  46         $lineno = 0;
  47         $inclause = 0;


 114                         err "space or tab at end of line";
 115                 }
 116 
 117                 if (/^[\t]+[ ]+[\t]+/) {
 118                         err "spaces between tabs";
 119                 }
 120 
 121                 if (/^[\t]* \*/) {
 122                         next;
 123                 }
 124 
 125                 if (/^        /) {
 126                         err "indented by spaces not tabs";
 127                 }
 128 
 129                 if (/^{}$/) {
 130                         next;
 131                 }
 132 
 133                 if (!/^enum/ && !/^\t*struct/ && !/^\t*union/ && !/^typedef/ &&
 134                     !/^translator/ && !/^provider/) {

 135                         if (/[\w\s]+{/) {
 136                                 err "left brace not on its own line";
 137                         }
 138 
 139                         if (/{[\w\s]+/) {
 140                                 err "left brace not on its own line";
 141                         }
 142                 }
 143 
 144                 if (!/;$/) {
 145                         if (/[\w\s]+}/) {
 146                                 err "right brace not on its own line";
 147                         }
 148 
 149                         if (/}[\w\s]+/) {
 150                                 err "right brace not on its own line";
 151                         }
 152                 }
 153 
 154                 if (/^}/) {
 155                         $inclause = 0;
 156                 }
 157 
 158                 if (!$inclause && /^[\w ]+\//) {
 159                         err "predicate not at beginning of line";
 160                 }
 161 
 162                 if (!$inclause && /^\/[ \t]+\w/) {
 163                         err "space between '/' and expression in predicate";
 164                 }




   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 #
  24 # Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25 # Use is subject to license terms.
  26 #
  27 
  28 #
  29 # Copyright (c) 2014 by Delphix. All rights reserved.
  30 #
  31 
  32 require 5.8.4;
  33 
  34 $PNAME = $0;
  35 $PNAME =~ s:.*/::;
  36 $USAGE = "Usage: $PNAME [file ...]\n";
  37 $errs = 0;
  38 
  39 sub err
  40 {
  41         my($msg) = @_;
  42 
  43         print "$file: $lineno: $msg\n";
  44         $errs++;
  45 }
  46 
  47 sub dstyle
  48 {
  49         open(FILE, "$file");
  50         $lineno = 0;
  51         $inclause = 0;


 118                         err "space or tab at end of line";
 119                 }
 120 
 121                 if (/^[\t]+[ ]+[\t]+/) {
 122                         err "spaces between tabs";
 123                 }
 124 
 125                 if (/^[\t]* \*/) {
 126                         next;
 127                 }
 128 
 129                 if (/^        /) {
 130                         err "indented by spaces not tabs";
 131                 }
 132 
 133                 if (/^{}$/) {
 134                         next;
 135                 }
 136 
 137                 if (!/^enum/ && !/^\t*struct/ && !/^\t*union/ && !/^typedef/ &&
 138                     !/^translator/ && !/^provider/ && !/\tif / &&
 139                     !/ else /) {
 140                         if (/[\w\s]+{/) {
 141                                 err "left brace not on its own line";
 142                         }
 143 
 144                         if (/{[\w\s]+/) {
 145                                 err "left brace not on its own line";
 146                         }
 147                 }
 148 
 149                 if (!/;$/ && !/\t*}$/ && !/ else /) {
 150                         if (/[\w\s]+}/) {
 151                                 err "right brace not on its own line";
 152                         }
 153 
 154                         if (/}[\w\s]+/) {
 155                                 err "right brace not on its own line";
 156                         }
 157                 }
 158 
 159                 if (/^}/) {
 160                         $inclause = 0;
 161                 }
 162 
 163                 if (!$inclause && /^[\w ]+\//) {
 164                         err "predicate not at beginning of line";
 165                 }
 166 
 167                 if (!$inclause && /^\/[ \t]+\w/) {
 168                         err "space between '/' and expression in predicate";
 169                 }