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 (920bcf17a9e1)

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 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
#!perl -w
package GenerateManifest;

require 5.004;

use strict;
use File::stat;
require Exporter;

use vars qw(@ISA @EXPORT);

# Package that generates a jar manifest from an input file

@ISA      = qw(Exporter);
@EXPORT   = qw(
                GenerateManifest
              );

my(%embed_files) = ();


sub GenerateManifest ($$$$$$$$) {
  my($moz, $manifest, $chrome, $locale, $platform, $out_desc, $dir_sep, $verbose) = @_;
  local(*OUTDESC) = $out_desc;  

  parse_input_manifest($moz, $manifest, $chrome, $locale, $verbose);
  dump_output_manifest($moz, $manifest, $chrome, $locale, $platform, *OUTDESC, $dir_sep, $verbose);
}


sub parse_input_manifest ($$$$$) {
  my($moz, $manifest, $chrome, $locale, $verbose) = @_;  

  print STDERR "Parsing \"$manifest\"\n" unless !$verbose;

  local(*MANIFEST);
  open(MANIFEST, "<$manifest") or die ("Error: Cannot open manifest \"$manifest\".\n");
  while(<MANIFEST>) {
    chomp;
    s/^\s+//;
    s/\s+$//;

    # Skip comments & blank lines
    next if (/^\#/);
    next if (/^\s*$/);

    # Read key & data
    my($key, $value) = split(/,/, $_);
    
    # Strip out any remaining whitespace from key & value
    for ($key) {
        s/\s+$//;
    }
    for ($value) {
        s/^\s+//;
    }

    $embed_files{$key} = $value;
  }
  close(MANIFEST);
}

sub dump_output_manifest ($$$$$$$$) {
  my($moz, $manifest, $chrome, $locale, $platform, $out_desc, $dir_sep, $verbose) = @_;
  local(*OUTDESC) = $out_desc;

  print OUTDESC "embed.jar:\n";
  while (my($key, $value) = each %embed_files) {

    $key =~ s/XXXX/$locale/g;
    $value =~ s/XXXX/$locale/g;
    $key =~ s/YYYY/$platform/g;
    $value =~ s/YYYY/$platform/g;
    if ( $dir_sep ne "/" ) {      # swap / for $dir_sep
      $value =~ s/\//$dir_sep/g;
    }

    # Run ls on the dir/file to ensure it's there and to get a file list back
    my($ls_path) = "$chrome$dir_sep$value";
    my($is_dir) = (-d $ls_path) ? 1 : 0;
    my($is_file) = (-f $ls_path) ? 1 : 0;

    print STDERR "Listing \"$ls_path\"\n" unless !$verbose;

    if (!$is_dir && !$is_file) {
      print STDERR "Warning: File or directory \"$ls_path\" does not exist.\n";
      next;
    }

    # this code previously used |ls -1| to get a dir listing, but that
    # doesn't work in MacPerl. Instead just use opendir() to get the 
    # file list (if it's a directory), or add the single file to our list
    # if it's called out individually in the manifest.
    my(@dirList) = ();
    if ( $is_file ) {
      @dirList = ($ls_path);
    }
    else {
      opendir(CHROMEDIR, $ls_path);
      @dirList = readdir(CHROMEDIR);
      closedir(CHROMEDIR);
    }
    
    my($chrome_file) = "";
    my($real_file) = "";
    foreach (@dirList) {
      if ($is_dir) {
        $chrome_file = "$key$dir_sep$_";
        $real_file = "$value$dir_sep$_";
      }
      else {
        $chrome_file = $key;
        $real_file = $value;
      }
      # Ignore directories which are returned by ls
      if (! -d "$chrome$dir_sep$real_file") {
        # before we put the file into the manifest, make sure it
        # uses '/' as the separator. That's what manifest files expect.
        $real_file =~ s/$dir_sep/\//g;
        $chrome_file =~ s/$dir_sep/\//g;
        print OUTDESC "  $chrome_file   ($real_file)\n";
      }
    }
  }
}

1;