1*7c478bd9Sstevel@tonic-gate#!/usr/bin/perl 2*7c478bd9Sstevel@tonic-gate# 3*7c478bd9Sstevel@tonic-gate# CDDL HEADER START 4*7c478bd9Sstevel@tonic-gate# 5*7c478bd9Sstevel@tonic-gate# The contents of this file are subject to the terms of the 6*7c478bd9Sstevel@tonic-gate# Common Development and Distribution License, Version 1.0 only 7*7c478bd9Sstevel@tonic-gate# (the "License"). You may not use this file except in compliance 8*7c478bd9Sstevel@tonic-gate# with the License. 9*7c478bd9Sstevel@tonic-gate# 10*7c478bd9Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 11*7c478bd9Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 12*7c478bd9Sstevel@tonic-gate# See the License for the specific language governing permissions 13*7c478bd9Sstevel@tonic-gate# and limitations under the License. 14*7c478bd9Sstevel@tonic-gate# 15*7c478bd9Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 16*7c478bd9Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 17*7c478bd9Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 18*7c478bd9Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 19*7c478bd9Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 20*7c478bd9Sstevel@tonic-gate# 21*7c478bd9Sstevel@tonic-gate# CDDL HEADER END 22*7c478bd9Sstevel@tonic-gate# 23*7c478bd9Sstevel@tonic-gate 24*7c478bd9Sstevel@tonic-gate# Copyright 2003 Sun Microsystems, Inc. All rights reserved. 25*7c478bd9Sstevel@tonic-gate# Use is subject to license terms. 26*7c478bd9Sstevel@tonic-gate# 27*7c478bd9Sstevel@tonic-gate#ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gateuse strict; 30*7c478bd9Sstevel@tonic-gateuse File::Find (); 31*7c478bd9Sstevel@tonic-gaterequire v5.6.1; 32*7c478bd9Sstevel@tonic-gate 33*7c478bd9Sstevel@tonic-gateuse vars qw/$f_flg *name *dir @execlist $basedir/; 34*7c478bd9Sstevel@tonic-gate*name = *File::Find::name; 35*7c478bd9Sstevel@tonic-gate*dir = *File::Find::dir; 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate# Use the same mechanism as def.dir.flp to determine if there are any 38*7c478bd9Sstevel@tonic-gate# SCCS files matching the pattern supplied for a "find_files" 39*7c478bd9Sstevel@tonic-gate# statement. 40*7c478bd9Sstevel@tonic-gatesub sccs_empty { 41*7c478bd9Sstevel@tonic-gate my ($pat, $dir) = @_; 42*7c478bd9Sstevel@tonic-gate return 0 if $f_flg; 43*7c478bd9Sstevel@tonic-gate my $foo = `find $dir -name "$pat" -print | grep /SCCS/s.`; 44*7c478bd9Sstevel@tonic-gate $foo eq ""; 45*7c478bd9Sstevel@tonic-gate} 46*7c478bd9Sstevel@tonic-gate 47*7c478bd9Sstevel@tonic-gate# Not pretty, but simple enough to work for the known cases. 48*7c478bd9Sstevel@tonic-gate# Does not bother with curly braces or fancy substitutions. 49*7c478bd9Sstevel@tonic-gatesub expand { 50*7c478bd9Sstevel@tonic-gate my ($str) = @_; 51*7c478bd9Sstevel@tonic-gate while ($str =~ /\$(\w+)/) { 52*7c478bd9Sstevel@tonic-gate my $newstr = $ENV{$1}; 53*7c478bd9Sstevel@tonic-gate $str =~ s/\$$1/$newstr/g; 54*7c478bd9Sstevel@tonic-gate } 55*7c478bd9Sstevel@tonic-gate $str; 56*7c478bd9Sstevel@tonic-gate} 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate# Process a single inc.flg or req.flg file. 59*7c478bd9Sstevel@tonic-gatesub process_file { 60*7c478bd9Sstevel@tonic-gate my ($fname, $incpath) = @_; 61*7c478bd9Sstevel@tonic-gate my ($dname, $isincflg); 62*7c478bd9Sstevel@tonic-gate my ($expfile, $newpath, $line, $cont, $firstline, $text); 63*7c478bd9Sstevel@tonic-gate 64*7c478bd9Sstevel@tonic-gate $dname = $fname; 65*7c478bd9Sstevel@tonic-gate $dname =~ s+/[^/]*$++; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate $isincflg = $fname =~ /inc.flg$/; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate if (defined $incpath) { 70*7c478bd9Sstevel@tonic-gate $newpath = "$incpath, from $fname:"; 71*7c478bd9Sstevel@tonic-gate } else { 72*7c478bd9Sstevel@tonic-gate $newpath = "from $fname:"; 73*7c478bd9Sstevel@tonic-gate } 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate if (open INC, "<$fname") { 76*7c478bd9Sstevel@tonic-gate $line = 0; 77*7c478bd9Sstevel@tonic-gate $cont = 0; 78*7c478bd9Sstevel@tonic-gate while (<INC>) { 79*7c478bd9Sstevel@tonic-gate chomp; 80*7c478bd9Sstevel@tonic-gate $line++; 81*7c478bd9Sstevel@tonic-gate ( $cont = 0, next ) if /^\s*#/ || /^\s*$/; 82*7c478bd9Sstevel@tonic-gate if ($cont) { 83*7c478bd9Sstevel@tonic-gate $text = $text . $_; 84*7c478bd9Sstevel@tonic-gate } else { 85*7c478bd9Sstevel@tonic-gate $firstline = $line; 86*7c478bd9Sstevel@tonic-gate $text = $_; 87*7c478bd9Sstevel@tonic-gate } 88*7c478bd9Sstevel@tonic-gate if (/\\$/) { 89*7c478bd9Sstevel@tonic-gate $cont = 1; 90*7c478bd9Sstevel@tonic-gate $text =~ s/\\$//; 91*7c478bd9Sstevel@tonic-gate next; 92*7c478bd9Sstevel@tonic-gate } 93*7c478bd9Sstevel@tonic-gate $cont = 0; 94*7c478bd9Sstevel@tonic-gate if ($text =~ /\s*echo_file\s+(\S+)/) { 95*7c478bd9Sstevel@tonic-gate $expfile = expand($1); 96*7c478bd9Sstevel@tonic-gate warn "$fname:$firstline: $1 isn't a file\n" if ! -f $expfile; 97*7c478bd9Sstevel@tonic-gate } elsif ($text =~ /\s*find_files\s+['"]([^'"]+)['"]\s+(.*)/) { 98*7c478bd9Sstevel@tonic-gate foreach my $dir (split(/\s+/, "$2")) { 99*7c478bd9Sstevel@tonic-gate $expfile = expand($dir); 100*7c478bd9Sstevel@tonic-gate if (! -d $expfile) { 101*7c478bd9Sstevel@tonic-gate warn "$fname:$firstline: $dir isn't a directory\n"; 102*7c478bd9Sstevel@tonic-gate } elsif ($isincflg && $expfile eq $dname) { 103*7c478bd9Sstevel@tonic-gate warn "$fname:$firstline: $dir is unnecessary\n"; 104*7c478bd9Sstevel@tonic-gate } elsif (sccs_empty($1, $expfile)) { 105*7c478bd9Sstevel@tonic-gate warn "$fname:$firstline: $dir has no SCCS objects ", 106*7c478bd9Sstevel@tonic-gate "with '$1'\n"; 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate } 109*7c478bd9Sstevel@tonic-gate } elsif ($text =~ /\s*exec_file\s+(\S+)/) { 110*7c478bd9Sstevel@tonic-gate $expfile = expand($1); 111*7c478bd9Sstevel@tonic-gate if (-f $expfile) { 112*7c478bd9Sstevel@tonic-gate push @execlist, $expfile, "$newpath:$firstline"; 113*7c478bd9Sstevel@tonic-gate } else { 114*7c478bd9Sstevel@tonic-gate warn "$fname:$firstline: $1 isn't a file\n"; 115*7c478bd9Sstevel@tonic-gate warn "included $incpath\n" if defined $incpath; 116*7c478bd9Sstevel@tonic-gate } 117*7c478bd9Sstevel@tonic-gate } else { 118*7c478bd9Sstevel@tonic-gate warn "$0: $fname:$firstline: unknown entry: $text\n"; 119*7c478bd9Sstevel@tonic-gate warn "included $incpath\n" if defined $incpath; 120*7c478bd9Sstevel@tonic-gate } 121*7c478bd9Sstevel@tonic-gate } 122*7c478bd9Sstevel@tonic-gate close INC; 123*7c478bd9Sstevel@tonic-gate } else { 124*7c478bd9Sstevel@tonic-gate warn "$0: $fname: $!\n"; 125*7c478bd9Sstevel@tonic-gate } 126*7c478bd9Sstevel@tonic-gate} 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gatesub wanted { 129*7c478bd9Sstevel@tonic-gate process_file($_, undef) if /\/(inc|req)\.flg$/ && -f $_; 130*7c478bd9Sstevel@tonic-gate} 131*7c478bd9Sstevel@tonic-gate 132*7c478bd9Sstevel@tonic-gate$f_flg = $ARGV[0] eq "-f"; 133*7c478bd9Sstevel@tonic-gateshift @ARGV if $f_flg; 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate$basedir = "usr/src"; 136*7c478bd9Sstevel@tonic-gateif ($#ARGV == 0) { 137*7c478bd9Sstevel@tonic-gate $basedir = shift @ARGV; 138*7c478bd9Sstevel@tonic-gate} elsif ($#ARGV > 0) { 139*7c478bd9Sstevel@tonic-gate die "$0: unexpected arguments\n"; 140*7c478bd9Sstevel@tonic-gate} 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gatedie "$0: \$CODEMGR_WS must be set\n" if $ENV{CODEMGR_WS} eq ""; 143*7c478bd9Sstevel@tonic-gatechdir $ENV{CODEMGR_WS} or die "$0: chdir $ENV{CODEMGR_WS}: $!\n"; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gateFile::Find::find({wanted => \&wanted, no_chdir => 1}, $basedir); 146*7c478bd9Sstevel@tonic-gate 147*7c478bd9Sstevel@tonic-gate# After passing through the tree, process all of the included files. 148*7c478bd9Sstevel@tonic-gate# There aren't many of these, so don't bother trying to optimize the 149*7c478bd9Sstevel@tonic-gate# traversal. Just do them all. 150*7c478bd9Sstevel@tonic-gatewhile (@execlist) { 151*7c478bd9Sstevel@tonic-gate my $file = shift @execlist; 152*7c478bd9Sstevel@tonic-gate my $incpath = shift @execlist; 153*7c478bd9Sstevel@tonic-gate process_file($file, $incpath); 154*7c478bd9Sstevel@tonic-gate} 155*7c478bd9Sstevel@tonic-gate 156*7c478bd9Sstevel@tonic-gateexit 0; 157