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.

Untracked file

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

# This script dumps out a list of all public Mozilla headers based on what the
# embedding samples use. It uses dependency generator tools to find all
# headers, sorts them removes duplicates and dumps them out to display.

use Getopt::Long;

$showhelp = 0;
$verbose = 0;
$nodefaults = 0;
$appname = "Gecko public header list generator";

# Configuration
$win32 = ($^O eq "MSWin32") ? 1 : 0; # ActiveState Perl
if ($win32) {
  $moz = "$ENV{'MOZ_SRC'}/mozilla";
  $makedepexe = "$moz/config/makedep.exe";
}
else {
  $moz = "/usr/local/src/mozilla";
  $makedepexe = "makedepend";
}

GetOptions('verbose!' => \$verbose,
	   'nodefaults' => \$nodefaults,
           'mozpath=s' => \$moz,
	   'deptool=s' => \$makedepexe,
	   'include=s' => \@cmd_incs,
	   'dir=s' => \@cmd_dirs,
	   'help' => \$showhelp);

if ($showhelp) {
  print STDERR "$appname\n",
               "Usage:\n",
               "--help            Show this help\n",
               "--verbose         Print out more information\n",
               "--nodefaults      Don't use the default include and directory settings\n",
               "--mozsrc  <path>  Specify the path to Mozilla source code (e.g. /usr/src/mozilla)\n",
               "--deptool <exe>   Specify the dependency tool path\n",
               "--include <path>  Add an include path\n",
               "--dir     <path>  Add a directory to be inspected\n";
  exit 1;
}

print STDERR "$appname\n",
             "Path to mozilla is \"$moz\"\n",
             "Dependency tool is \"$makedepexe\"\n" unless !$verbose;

# List of default include directories
@default_incs = (
  "$moz/dist/include/nspr",
  "$moz/dist/include",
);

# List of default directories to analyze
@default_dirs = (
  "$moz/embedding/tests/winEmbed",
  "$moz/embedding/tests/mfcembed",
  "$moz/embedding/browser/gtk/tests",
  "$moz/embedding/browser/activex/src/control",
  "$moz/embedding/browser/powerplant/source",
  "$moz/embedding/browser/gtk/src"
);

@deps = ();

if ($nodefaults) {
  @incs = ( @cmd_incs );
  @dirs = ( @cmd_dirs );
}
else {
  @incs = ( @default_incs, @cmd_incs );
  @dirs = ( @default_dirs, @cmd_dirs );
}

if ($verbose) {
  print "Include paths:\n";
  foreach $inc (@incs) {
    print "  ", $inc, "\n";
  }
}

# Analyze each embedding project in turn
foreach $dir (@dirs) {
  makedep($dir);
}

# Remove duplicate dependencies & sort alphabetically
$prev = 'nonesuch';
@out = grep($_ ne $prev && ($prev = $_), sort @deps);

# Output the list of headers
foreach $h (@out) {
  $printinfo{$h} = 0;
}
foreach $i (@incs) {
  $i =~ s/\\/\//g; # Back slash to forward slash
  foreach $h (@out) {
    # Compare lowercase portion of header to include dir
    $h =~ s/\\/\//g;
    $lci = lc($i);
    $lch = lc(substr($h, 0, length($i)));
    if ($lch eq $lci && $printinfo{$h} == 0) {
      print $h, "\n";
      $printinfo{$h} = 1; # Stops same header from matching two include dirs
    }
  }
}

sub makedep {
  my($dir) = @_;

  print STDERR "Analyzing dependencies for \"$dir\" ...\n" unless !$verbose;

  chdir $dir
    or die "Cannot change directory to \"$dir\"";

  # Search for .c, .cpp and .h files
  opendir(THISDIR, ".")
    or die "Cannot open directory \"$dir\"";
  @srcfiles = grep(/\.(cpp|c|h)$/i, readdir(THISDIR));
  closedir(THISDIR);

  # Construct the arguments for the dependency tool
  if ($win32) {
    @args = ($makedepexe);
    foreach $inc (@incs) {
      push(@args, "-I$inc");
    }
    foreach $src (@srcfiles) {
      push(@args, $src);
    }
  }
  else {
    @args = ($makedepexe);
    push(@args, "-f-"); # To stdout
    push(@args, "-w1"); # width = 1 forces one dependency per line
    foreach $inc (@incs) {
      push(@args, "-I$inc");
    }
    foreach $src (@srcfiles) {
      push(@args, $src);
    }
  }

  $cmd = join(' ', @args);

  if (!$win32) {
    open(OLDERR, ">&STDERR");
    open(STDERR, ">/dev/null");
  }

  # Run the dependency tool and read the output
  open(DATA, "$cmd |")
    or die("Cannot open output from dependency tool");

  # Filter out all lines not containing ".h"
  while (<DATA>) {
    foreach $inc (@incs) {
      if (/\.h/i) {
        # Remove whitespace and trailing backslash, newline
        chomp;
        s/^\s+//g;
	s/^[\w]+\.\w\:\s+//g;
        s/\s+\\$//g;
        # Store in list
        push @deps, $_;
      }
    }
  }

  if (!$win32) {
    close(STDERR);
    open(STDERR, ">&OLDERR");
  }
}