Bug 480318. Fix getting of content-disposition for the document save-as case. r...
[mozilla-central.git] / config / module2dir.pl
blob5c19d305a1228f19c41d6ad5286666aad4f148d9
1 #!/usr/bin/perl -w
4 # Create a mapping from symbolic component name to directory name(s).
6 # Tue Oct 16 16:48:36 PDT 2001
7 # <mcafee@netscape.com>
9 use strict;
11 # For --option1, --option2, ...
12 use Getopt::Long;
13 Getopt::Long::Configure("bundling_override");
14 Getopt::Long::Configure("auto_abbrev");
16 # Globals
17 my $list_only_mode = 0;
18 my $opt_list_only;
19 my $mapfile = "";
20 my %map;
22 sub PrintUsage {
23 die <<END_USAGE
24 Prints out directories needed for a given list of components.
25 usage: module2dir.pl [--list-only] [--mapfile mapfile] <component-name1> <component-name2> ...
26 END_USAGE
29 sub parse_map_file($) {
30 my ($mapfile) = @_;
31 my (%mod_map, $tmp, $dir, $mod, @mod_list);
33 undef %mod_map;
34 open (MAPFILE, "$mapfile") || die ("$mapfile: $!\n");
35 while ($tmp=<MAPFILE>) {
36 chomp ($tmp);
37 ($dir, $mod, @mod_list) = split(/:/, $tmp, 3);
38 $mod =~ s/[\s]*(\S+)[\s]*/$1/;
39 $mod_map{$mod} .= "$dir ";
41 close(MAPFILE);
42 foreach $mod (sort(keys %mod_map)) {
43 my (@dirlist, @trimlist, $found, $tdir);
44 @dirlist = split(/\s+/, $mod_map{$mod});
45 $mod_map{$mod} = "";
46 foreach $dir (@dirlist) {
47 $found = 0;
48 foreach $tdir (@trimlist) {
49 $found++, last if ($dir =~ m/^$tdir\// || $dir eq $tdir);
51 push @trimlist, $dir if (!$found);
53 $map{$mod} = join(" ", @trimlist);
54 #print "$mod: $map{$mod}\n";
58 sub dir_for_required_component {
59 my ($component) = @_;
60 my $rv;
61 my $dir;
63 $dir = $map{$component};
64 if($dir) {
65 # prepend "mozilla/" in front of directory names.
66 $rv = "mozilla/$dir";
67 $rv =~ s/\s+/ mozilla\//g; # Hack for 2 or more directories.
68 } else {
69 $rv = 0;
71 return $rv;
76 # Add stdin to the commandline. This makes commandline-only mode hang,
77 # call it a bug. Not sure how to get around this.
78 push (@ARGV, split(' ',<STDIN>));
80 PrintUsage() if !GetOptions('list-only' => \$opt_list_only,
81 'mapfile=s' => \$mapfile);
83 # Pick up arguments, if any.
84 if($opt_list_only) {
85 $list_only_mode = 1;
88 &parse_map_file($mapfile);
90 my $arg;
91 my $dir;
92 while ($arg = shift @ARGV) {
93 $dir = dir_for_required_component($arg);
94 if($dir) {
95 if($list_only_mode) {
96 print $dir, " ";
97 } else {
98 print "$arg: ", $dir, "\n";
100 } else {
101 # do nothing
104 if($dir && $list_only_mode) {
105 print "\n";