DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (b66b287a2650)

VCS Links

Line Code
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
#!/usr/bin/perl -w

#
# Create a mapping from symbolic component name to directory name(s).
#
# Tue Oct 16 16:48:36 PDT 2001
# <mcafee@netscape.com>

use strict;

# For --option1, --option2, ...
use Getopt::Long;
Getopt::Long::Configure("bundling_override");
Getopt::Long::Configure("auto_abbrev");

# Globals
my $list_only_mode = 0;
my $opt_list_only;
my $mapfile = "";
my %map;

sub PrintUsage {
  die <<END_USAGE
  Prints out directories needed for a given list of components.
  usage: module2dir.pl [--list-only] [--mapfile mapfile] <component-name1> <component-name2> ...
END_USAGE
}

sub parse_map_file($) {
    my ($mapfile) = @_;
    my (%mod_map, $tmp, $dir, $mod, @mod_list);

    undef %mod_map;
    open (MAPFILE, "$mapfile") || die ("$mapfile: $!\n");
    while ($tmp=<MAPFILE>) {
	chomp ($tmp);
	($dir, $mod, @mod_list) = split(/:/, $tmp, 3);
	$mod =~ s/[\s]*(\S+)[\s]*/$1/;
	$mod_map{$mod} .= "$dir ";
    }
    close(MAPFILE);
    foreach $mod (sort(keys %mod_map)) {
	my (@dirlist, @trimlist, $found, $tdir);
	@dirlist = split(/\s+/, $mod_map{$mod});
	$mod_map{$mod} = "";
	foreach $dir (@dirlist) {
	    $found = 0; 
	    foreach $tdir (@trimlist) {
		$found++, last if ($dir =~ m/^$tdir\// || $dir eq $tdir);
	    }
	    push @trimlist, $dir if (!$found);
        }
	$map{$mod} = join(" ", @trimlist);
	#print "$mod: $map{$mod}\n";
    }
}

sub dir_for_required_component {
  my ($component) = @_;
  my $rv;
  my $dir;

  $dir = $map{$component};
  if($dir) {
	# prepend "mozilla/" in front of directory names.
	$rv = "mozilla/$dir";
	$rv =~ s/\s+/ mozilla\//g;  # Hack for 2 or more directories.
  } else {
	$rv = 0;
  }
  return $rv;
}

{

  # Add stdin to the commandline.  This makes commandline-only mode hang,
  # call it a bug.  Not sure how to get around this.
  push (@ARGV, split(' ',<STDIN>));

  PrintUsage() if !GetOptions('list-only' => \$opt_list_only,
			      'mapfile=s' => \$mapfile);

  # Pick up arguments, if any.
  if($opt_list_only) {
  	$list_only_mode = 1;
  }

  &parse_map_file($mapfile);

  my $arg;
  my $dir;
  while ($arg = shift @ARGV) {
	$dir = dir_for_required_component($arg);
	if($dir) {
      if($list_only_mode) {
		print $dir, " ";
	  } else {
		print "$arg: ", $dir, "\n";
	  }
	} else {
	  # do nothing
	}
  }
  if($dir && $list_only_mode) {
	print "\n";
  }
}