1 #!/bin/sh 2 # 3 # CDDL HEADER START 4 # 5 # The contents of this file are subject to the terms of the 6 # Common Development and Distribution License, Version 1.0 only 7 # (the "License"). You may not use this file except in compliance 8 # with the License. 9 # 10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11 # or http://www.opensolaris.org/os/licensing. 12 # See the License for the specific language governing permissions 13 # and limitations under the License. 14 # 15 # When distributing Covered Code, include this CDDL HEADER in each 16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17 # If applicable, add the following below this CDDL HEADER, with the 18 # fields enclosed by brackets "[]" replaced with your own identifying 19 # information: Portions Copyright [yyyy] [name of copyright owner] 20 # 21 # CDDL HEADER END 22 # 23 # 24 # Copyright 2005 Sun Microsystems, Inc. All rights reserved. 25 # Use is subject to license terms. 26 # 27 #ident "%Z%%M% %I% %E% SMI" 28 # 29 # Checks the list of files to make sure that each given file has a SMI 30 # standard ident string. 31 # 32 # It checks that keywords exist, and verifies the string. By default, 33 # all allowable forms of keywords (according to the ON documentation) 34 # are acceptable. The '-p' option (pedantic) allows only the canonical 35 # form of keywords. See below for allowable forms. 36 # 37 # Use as "keywords filelist" where filelist is the list of plain files. 38 # 39 # However, in general, this utility should not need to be directly 40 # invoked, but instead used through wx(1) -- e.g., `wx keywords'. 41 # 42 # Output consists of filenames with expanded, incorrect or missing 43 # sccs keywords and/or filenames that were not SCCS files. 44 # 45 # Exits with status 0 if all files are sccs files and all files have 46 # unexpanded, correct keywords. Otherwise, exits with a non-zero status. 47 48 # 49 # The CDPATH variable causes ksh's `cd' builtin to emit messages to stdout 50 # under certain circumstances, which can really screw things up; unset it. 51 # 52 unset CDPATH 53 54 PATH=/usr/bin:/usr/ccs/bin 55 56 USAGE="usage: `basename $0` [-p] <filename> ..." 57 58 # Canonical form for .c and .h files 59 CANON_C_H="^#pragma ident \"\%\Z\%\%\M\% \%\I\% \%\E\% SMI\"" 60 # Canonical form for other files 61 CANON_OTHER="ident \"\%\Z\%\%\M\% \%\I\% \%\E\% SMI\"" 62 STANDARD="ident \"(\%\Z\%\%\M\% +\%\I\%|\%W\%) +\%\E\% SMI\"" 63 EXPANDED="@\(#\).*[ ]+[1-9]+(\.[0-9]+)+[ ]+(-[ ]+)?[0-9][0-9]/[01][0-9]/[0-3][0-9][ ]+.*(SMI|Sun)" 64 LIBERAL="(\%\Z\%\%\M\%[ ]+\%\I\%|\%W\%)[ ]+\%\E\%[ ]+.*(SMI|Sun)" 65 66 check_file() { 67 fname=$1 68 bname=$2 69 canon_str=$3 70 if [ $pedantic -eq 1 ]; then 71 egrep -s "$canon_str" $bname 72 if [ $? -ne 0 ]; then 73 echo "Incorrect ident string in $fname" 74 exitcode=1 75 fi 76 elif [ $liberal -eq 1 ]; then 77 egrep -s "$LIBERAL" $bname 78 if [ $? -ne 0 ]; then 79 egrep -s "$EXPANDED" $bname 80 if [ $? -eq 0 ]; then 81 echo "Expanded keywords in $fname" 82 else 83 echo "Incorrect ident string in $fname" 84 fi 85 exitcode=1 86 fi 87 else 88 egrep -s "$STANDARD" $bname 89 if [ $? -ne 0 ]; then 90 egrep -s "$EXPANDED" $bname 91 if [ $? -eq 0 ]; then 92 echo "Expanded keywords in $fname" 93 else 94 echo "Incorrect ident string in $fname" 95 fi 96 exitcode=1 97 fi 98 fi 99 } 100 101 pedantic=0 102 liberal=0 103 cwd=`pwd` 104 exitcode=0 105 rm -f /tmp/xxx$$ /tmp/kywrds.$$ 106 trap "rm -f /tmp/xxx$$ /tmp/kywrds.$$" 0 107 108 while getopts lp c 109 do 110 case $c in 111 l) liberal=1;; 112 p) pedantic=1;; 113 \?) echo $USAGE 114 exit 2;; 115 esac 116 done 117 shift `expr $OPTIND - 1` 118 119 for i 120 do 121 dir=`dirname $i` 122 file=`basename $i` 123 124 # Try to build the full path to the file argument 125 echo $dir | egrep -s '^/' 126 if [ ! $? -eq 0 ]; then 127 dir=`pwd`/$dir 128 fi 129 130 cd $dir 131 132 if [ -f SCCS/s.$file ]; then 133 if [ -f SCCS/p.$file ]; then 134 case "$file" in 135 *.cxx|*.cc|*.c|*.hh|*.h) 136 canon_str="$CANON_C_H";; 137 *) 138 canon_str="$CANON_OTHER";; 139 esac 140 check_file $i $file "$canon_str" 141 else 142 sccs get -p $file > /dev/null 2>/tmp/xxx$$ 143 if [ $? -ne 0 ]; then 144 echo "Cannot access SCCS information: $i" 145 exitcode=1 146 continue 147 fi 148 egrep -s "cm7" /tmp/xxx$$ 149 if [ $? -eq 0 ]; then 150 egrep -s "$EXPANDED" $file 151 if [ $? -eq 0 ]; then 152 echo "Expanded keywords in $i" 153 else 154 echo "Missing keywords in $i" 155 fi 156 exitcode=1 157 else 158 sccs get -p -k $file > /tmp/kywrds.$$ 2>/tmp/xxx$$ 159 case "$file" in 160 *.cxx|*.cc|*.c|*.hh|*.h) 161 canon_str="$CANON_C_H";; 162 *) 163 canon_str="$CANON_OTHER";; 164 esac 165 check_file $i /tmp/kywrds.$$ "$canon_str" 166 fi 167 fi 168 else 169 echo "Not an SCCS file: $i" 170 exitcode=1 171 fi 172 cd $cwd 173 done 174 175 exit $exitcode 176