gecko-dev/webtools/bonsai/modules.pl

153 lines
3.6 KiB
Perl
Raw Normal View History

1998-06-16 21:43:24 +00:00
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
1999-11-01 23:33:56 +00:00
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
1998-06-16 21:43:24 +00:00
#
1999-11-01 23:33:56 +00:00
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
1998-06-16 21:43:24 +00:00
#
# The Original Code is the Bonsai CVS tool.
#
# The Initial Developer of the Original Code is Netscape Communications
1999-11-01 23:33:56 +00:00
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s):
1998-06-16 21:43:24 +00:00
use strict;
require 'get_line.pl';
1998-06-16 21:43:24 +00:00
my $NOT_LOCAL = 1;
my $IS_LOCAL = 2;
1998-06-16 21:43:24 +00:00
$::modules = {};
1998-06-16 21:43:24 +00:00
if( $::CVS_ROOT eq "" ){
$::CVS_ROOT = pickDefaultRepository();
1998-06-16 21:43:24 +00:00
}
&validateRepository($::CVS_ROOT);
1998-06-16 21:43:24 +00:00
my $CVS_MODULES;
if( defined($ENV{"OS"}) && $ENV{"OS"} eq "Windows_NT" ){
1998-06-16 21:43:24 +00:00
$CVS_MODULES='modules';
}
else {
$CVS_MODULES="$::CVS_ROOT/CVSROOT/modules";
1998-06-16 21:43:24 +00:00
}
open( MOD, "<$CVS_MODULES") || die "can't open $CVS_MODULES";
&parse_modules;
close( MOD );
1;
sub in_module {
my($mod_map, $dirname, $filename ) = @_;
my( @path );
my( $i, $fp, $local );
1998-06-16 21:43:24 +00:00
#
#quick check if it is already in there.
#
if( $mod_map->{$dirname} ){
1998-06-16 21:43:24 +00:00
return 1;
}
@path = split(/\//, $dirname);
$fp = '';
for( $i = 0; $i < @path; $i++){
$fp .= ($fp ne '' ? '/' : '') . $path[$i];
if( $local = $mod_map->{$fp} ){
if( $local == $IS_LOCAL ){
if( $i == (@path-1) ){
return 1;
}
}
else {
# Add directories to the map as we encounter them so we go
# faster
if( $mod_map->{$dirname} == 0 ){
$mod_map->{$dirname} = $IS_LOCAL;
1998-06-16 21:43:24 +00:00
}
return 1;
}
}
}
if( $mod_map->{ $fp . '/' . $filename} ) {
return 1;
}
else {
return 0;
}
}
sub get_module_map {
my($name) = @_;
my($mod_map);
1998-06-16 21:43:24 +00:00
$mod_map = {};
&build_map( $name, $mod_map );
return $mod_map;
}
sub parse_modules {
my @finaloptions=();
my $l;
1998-06-16 21:43:24 +00:00
while( $l = &get_line ){
@finaloptions=();
my ($mod_name, $flag, @params) = split(/[ \t]+/,$l);
while ( $flag =~ /^-.$/){
if( $flag eq '-a' ){
$flag="";
last;
}
if ( $flag eq '-l' ){ # then keep it
push @finaloptions, ($flag, shift @params);
$flag= @params ? shift @params : "";
next;
}
if( $flag =~ /^-.$/ ){
shift @params; # skip parameter's argument
$flag= @params ? shift @params : "";
next;
}
last; # No options found...
1998-06-16 21:43:24 +00:00
}
unshift @params, $flag if ( $flag ne "" );
$::modules->{$mod_name} = [(@finaloptions,@params)];
1998-06-16 21:43:24 +00:00
}
}
sub build_map {
my ($name,$mod_map) = @_;
my ($bFound, $local);
1998-06-16 21:43:24 +00:00
$local = $NOT_LOCAL;
$bFound = 0;
# printf "looking for $name in %s<br>\n",join(",", @{$::modules->{$name}});
for my $i ( @{$::modules->{$name}} ){
1998-06-16 21:43:24 +00:00
$bFound = 1;
if( $i eq '-l' ){
$local = $IS_LOCAL;
}
elsif( ($i eq $name) || !build_map($i, $mod_map )){
1998-06-16 21:43:24 +00:00
$mod_map->{$i} = $local;
}
}
return $bFound;
}