Skip to content
This repository
tag: REL_5_0_0_RC1
Fetching contributors…

Cannot retrieve contributors at this time

file 362 lines (274 sloc) 7.401 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362
#!/usr/bin/perl
##!~_~perlpath~_~
#
# findtags - Find ITL tags in Interchange catalogs and directories
#
# $Id: findtags.PL,v 1.4 2003-09-24 18:53:24 jon Exp $
#
# Copyright (C) 2002-2003 Interchange Development Group
# Copyright (C) 1996-2002 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.

use lib '/work/interchange/lib';
#use lib '~_~INSTALLPRIVLIB~_~';
use lib '/work/interchange';
#use lib '~_~INSTALLARCHLIB~_~';

use strict;


BEGIN {
($Global::VendRoot = $ENV{MINIVEND_ROOT})
if defined $ENV{MINIVEND_ROOT};

$Global::VendRoot = $Global::VendRoot || '/work/interchange';
# $Global::VendRoot = $Global::VendRoot || '~_~INSTALLARCHLIB~_~';

if(-f "$Global::VendRoot/interchange.cfg") {
$Global::ExeName = 'interchange';
$Global::ConfigFile = 'interchange.cfg';
}
elsif(-f "$Global::VendRoot/minivend.cfg") {
$Global::ExeName = 'minivend';
$Global::ConfigFile = 'minivend.cfg';
}
elsif(-f "$Global::VendRoot/interchange.cfg.dist") {
$Global::ExeName = 'interchange';
$Global::ConfigFile = 'interchange.cfg';
}
}

### END CONFIGURATION VARIABLES

my $prog = $0;
$prog =~ s:.*/::;

my $USAGE = <<EOF;
usage: $prog [-r] [-f file]

-a Look in all catalogs
-c CAT Only look in catalog CAT
-d "dir1 dir2 .." Look in dirs
-f Alternate interchange.cfg file
-h Print this message and exit
-n Don't report SystemTag
-t "TagInclude" directive output
-u Report unseen tags
-v Slightly verbose, report directories scanned
-x "dirs" Don't look for tags in dir (default "session tmp")

Find tags in Interchange catalogs and directories -- intended to develop
a list for TagInclude.

WARNING: This is not 100%, for developing tag names from Variable definitions
and other sources can fool it. If you include all directories, make sure you
don't include documentation files or the usertags themselves.

With the standard distribution, this should find just about all
tags needed for foundation:

findtags -a -d lib/UI

To develop a TagInclude statement which excludes unused tags, try:

findtags -a -d lib/UI -t -u

If you don't want to use the UI, then do:

findtags -a -u -t

EOF

use Vend::Config;

$Vend::ExternalProgram = 1;
$Vend::Quiet = 1;

use Getopt::Std;
use vars qw/
$opt_a
$opt_c
$opt_d
$opt_f
$opt_h
$opt_n
$opt_t
$opt_u
$opt_v
$opt_x
/;

if($ARGV[0] eq '--help') {
print $USAGE;
exit 2;
}

getopts('ac:d:f:hntuvx') or die "$@\n$USAGE\n";

if($opt_h) {
print $USAGE;
exit 2;
}

sub logGlobal { shift(@_) if ref $_[0]; printf @_; print "\n" }
sub logError { }
sub logDebug { }

my $flag = '';

if($opt_f) {
$Global::ConfigFile = $opt_f;
$flag .= qq{ -f "$opt_f"};
}
else {
$Global::ConfigFile = "$Global::VendRoot/$Global::ConfigFile";
}

# Parse the interchange.cfg file to look for script/catalog info
# but don't read in the core tags
$Vend::ControllingInterchange = 1;
chdir $Global::VendRoot or die "Couldn't change to $Global::VendRoot: $!\n";
global_config();

my @cats;

if($opt_a) {
while( my($name, $cat) = each %Global::Catalog ) {
next if $cat->{base};
push @cats, $name;
}
}
elsif($opt_c) {
@cats = split /[\s,]+/, $opt_c;
}

my @exclude = qw/session tmp/;
my %exclude;

if($opt_x) {
@exclude = split /[\s,]+/, $opt_x;
}

@exclude{@exclude} = @exclude;

my @dirs;

for(@$Global::TagDir) {
push @dirs, glob("$_/*");
}

#warn "Dirs are " . join (" ", @dirs) . "\n";

if ($opt_n) {
@dirs = grep $_ !~ '/SystemTag$', @dirs;
}

my %tag;

use File::Find;

GETTAGS: {
my @tags;
my $wanted = sub {
return unless -f $_;
return unless /^(\w[-\w]*)\.[a-z_]*tag$/;
my $tname = $1;
$tname = lc $tname;
$tname =~ tr/-/_/;
push @tags, $tname;
};
File::Find::find($wanted, @dirs);
my %seen;
@tags = grep !$seen{$_}++, @tags;
@tag{@tags} = @tags;
}

my @targdirs;

if($opt_d) {
my @d = split /[\s,]+/, $opt_d;
for(@d) {
warn "Doing directory $_\n" if $opt_v;
push @targdirs, $_;
}
}

my @tags;

foreach my $catname (@cats) {
warn "Doing catalog $catname\n" if $opt_v;
my $dir = $Global::Catalog{$catname}->{dir};
if(! $dir) {
warn errmsg("Unknown catalog '%s', skipping.\n", $catname);
}
push @targdirs, $dir;
}

if(! @targdirs) {
die "no directories to scan!\n";
}

foreach my $dir (@targdirs) {
chdir $dir
or die errmsg("chdir to directory %s: $!\n", $dir);
my @files;
my @binaries;
my $wanted = sub {
return unless -f $_;
if (-B $_) {
push @binaries, $File::Find::name;
}
push @files, $File::Find::name;
};

my @d = glob('*');
@d = grep !$exclude{$_}, @d;
File::Find::find($wanted, @d);

undef $/;
foreach my $f (@files) {
#print "Checking file $f\n";
open IT, "< $f" or die errmsg("open %s: %s", $f, $!);
$_ = <IT>;
close IT or die errmsg("close %s: %s", $f, $!);
while (m{(?:\[(\w[-\w]*)[\s\]]|\$Tag->(\w+))}g) {
my $tmp = $1 || $2;
next if $tmp =~ /^\d+$/;
$tmp =~ s/-/_/g;
$tmp = lc $tmp;
next unless $tag{$tmp};
if($opt_u) {
delete $tag{$tmp};
}
else {
push @tags, $tmp;
}
}
}
}

my %seen;

if($opt_u) {
@tags = keys %tag;
if($opt_t) {
@tags = map { "!$_" } @tags;
}
}
else {
@tags = grep !$seen{$_}++, @tags;
}

@tags = sort grep /\w/, @tags;

if($opt_t) {
print "TagInclude <<EOTI\n\t";
print join("\n\t", @tags);
print "\nEOTI\n";
}
else {
print join("\n", @tags);
}
__END__

=head1 NAME

findtags - find tags in Interchange catalogs and directories

=head1 SYNOPSIS

findtags -a -d lib/UI
findtags -a -d lib/UI -t -u
findtags -a -u -t

=head1 DESCRIPTION

Find tags in Interchange catalogs and directories -- intended to develop
a list for TagInclude.

WARNING: This is not 100%, for developing tag names from Variable definitions
and other sources can fool it. If you include all directories, make sure you
don't include documentation files or the usertags themselves.

With the standard distribution, this should find just about all
tags needed for foundation:

findtags -a -d lib/UI

To develop a TagInclude statement which excludes unused tags, try:

findtags -a -d lib/UI -t -u

If you don't want to use the UI, then do:

findtags -a -u -t

=head1 OPTIONS

=over 4

=item -a

Look in all catalogs.

=item -c CAT

Only look in catalog CAT.

=item -d DIR1 DIR2 ....

Look in given directories.

=item -f FILE

Use alternate interchange.cfg file FILE.

=item -h

Display help.

=item -n

Don't report system tags.

=item -t

Output suitable for TagInclude directive.

=item -u

Report unseen tags.

=item -v
Slightly verbose, report directories scanned.

=item -x DIR1 DIR2 ....

Exclude given directories from scanning. Default is session and tmp.
Something went wrong with that request. Please try again.