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 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306
#!/usr/bin/perl
# $Id: source,v 1.18 2006/12/07 04:59:38 reed%reedloden.com Exp $
# source --	Present sourcecode as html, complete with references
#
#	Arne Georg Gleditsch <argggh@ifi.uio.no>
#	Per Kristian Gjermshus <pergj@ifi.uio.no>
#
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

######################################################################

use Local;
use lib 'lib/';
use SimpleParse;
use LXR::Common;
use LXR::Config;
use File::Basename;

sub diricon {
    my $img, $link;
    if ($filename eq '..') {
	$img = "/icons/back.gif";
	$link = $parentdir;
    } else {
#	$img = "/icons/folder.gif";
	$img = "internal-gopher-menu";
	$link = $Path->{'virt'}.$filename;
    }
    return(&fileref("<IMG ALIGN=ABSBOTTOM BORDER=0 SRC=\"$img\">", $link));
}

sub dirname {
    if ($filename eq '..') {
	return(&fileref("Parent directory", $parentdir));
    } else {
	return(&fileref($filename, $Path->{'virt'}.$filename));
    }
}


sub fileicon {
    my $img;

    if ($filename =~ /^.*\.[ch]$/) {
#	$img = "/icons/c.gif";
	$img = "internal-gopher-text";
    } elsif ($filename =~ /^.*\.(idl|cpp?|cc|java)$/) {
	# TODO: Find a nice icon for c++ files (KDE?)
#	$img = "/icons/c.gif";
	$img = "internal-gopher-text";
    } else {		
#	$img = "/icons/text.gif";
	$img = "internal-gopher-unknown";
    }

    return(&fileref("<IMG ALIGN=ABSBOTTOM BORDER=0 SRC=\"$img\">",
		    $Path->{'virt'}.$filename));
}


sub filename {
    return(&fileref($filename, $Path->{'virt'}.$filename));
}


sub filesize {
    my $templ = shift;
    my $s = (-s $Path->{'real'}.$filename);
    my $str;
    if ($s < 1<<10) {
	$str = "$s";
    } else {
#	if ($s < 1<<20) {
	    $str = ($s>>10) . "k";
#	} else {
#	    $str = ($s>>20) . "M";
#	}
    }
    return(&expandtemplate($templ,
			   ('bytes',	sub {return($str)}),
			   ('kbytes',	sub {return($str)}),
			   ('mbytes',	sub {return($str)})
			   ));
}


sub modtime {

    my $current_time = time;
    my $file_time = (stat($Path->{'real'}.$filename))[9];

    my @t = gmtime($file_time);

    my @months = ("Jan", "Feb", "Mar", "Apr", "May", "Jun",
		  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
    my ($sec, $min, $hour, $mday, $mon, $year) = @t;
    $year += 1900;
    $mon = $months[$mon];

    my $one_hour = (60 * 60);
    my $six_months = $one_hour * 24 * int(365/2);

    if ($file_time <= ($current_time - $six_months) ||
	$file_time >= ($current_time + $one_hour)) {
	return sprintf("%s %2d  %04d", $mon, $mday, $year);
    } else {
	return sprintf("%s %2d %02d:%02d", $mon, $mday, $hour, $min);
    }
}

sub bgcolor {
    if (!($line % 3)) {
	$color = ($color eq "#EEEEEE")? "#FFFFFF": "#EEEEEE";
    }
    return($color);
}


sub direxpand {
    my $templ = shift;
    my $direx = '';
    local $line = 0;
    local $filename;
    local $filestat;
    local $color="#FFFFFF";
    my $virtpath = $Path->{'virt'};
    my $realpath = $Path->{'real'};

    foreach $filename (@dirs) {
	$line++;
	$direx .= &expandtemplate($templ,
	    ('iconlink',		\&diricon),
	    ('namelink',		\&dirname),
	    ('filesize',		sub {return('-')}),
	    ('modtime',		\&modtime),
	    ('bgcolor',		\&bgcolor),
	    ('description',	\&descexpand));
    }
	
    foreach $filename (@files) {
	$line++;
	next if $filename =~ /^.*\.[oa]$|^core$|^00-INDEX$/;
	$direx .= &expandtemplate($templ,
	    ('iconlink',	\&fileicon),
	    ('namelink',	\&filename),
	    ('filesize',	\&filesize),
	    ('modtime',		\&modtime),
	    ('bgcolor',		\&bgcolor),
	    ('description',	\&fdescexpand));
    }

    return($direx);
}

sub printdir {
    my $template;
    my $index;
    local %index;
    local @dirs;
    local @files;
    local $parentdir;


    $template = "<ul>\n\$files{\n<li>\$iconlink \$namelink\n}</ul>\n";
    if ($Conf->htmldir) {
	unless (open(TEMPL, $Conf->htmldir)) {
	    &warning("Template ".$Conf->htmldir." does not exist.");
	} else {
	    $save = $/; undef($/);
	    $template = <TEMPL>;
	    $/ = $save;
	    close(TEMPL);
	}
    }
	
    if (opendir(DIR, $Path->{'real'})) {
	foreach $f (sort(grep/^[^\.]/,readdir(DIR))) {
	    if ($f eq "CVS") {
		# skip it
	    } elsif (-d $Path->{'real'}.$f) {
		push(@dirs,"$f/");
	    } else {
		push(@files,$f);
	    }
	}
	closedir(DIR);
    } else {
	print("<p align=center>\n<i>This directory does not exist.</i>\n");
	if ($Path->{'real'} =~ m#(.+[^/])[/]*$#) {
	    if (-e $1) {
		&warning("Unable to open ".$Path->{'real'});
	    }
	}
	return;
    }
 
    if (-f $Path->{'real'}."00-INDEX") {
	open(INDEX,$Path->{'real'}."00-INDEX") ||
	    &warning("Existing \"00-INDEX\" could not be opened.");
	$save = $/; undef($/);
	$index = <INDEX>;
	$/ = $save;
	
	%index = $index =~ /\n(\S*)\s*\n\t-\s*([^\n]*)/gs;
    }

    if ($Path->{'virt'} =~ m#^(.*/)[^/]*/$#) {
	$parentdir = $1;
	unshift(@dirs, '..');
    }

    # print the description of the current directory
    dirdesc($Path->{'virt'});

    #print the listing itself
    print(&expandtemplate($template,
			  ('files',	\&direxpand)));
}

sub printfile {
    my $string;

    unless ($Path->{'file'}) {
	&printdir;
    } else {
	if (open(SRCFILE, $Path->{'realf'})) {
	    if (($Path->{'file'} =~ /\.(html)$/)) {
		print <SRCFILE>;
	    } elsif ($Path->{'file'} =~ /README$/i) {
		print("<pre lang='en'>");
		while(<SRCFILE>) {
            	    $string = $string . $_;
        	}
                print(markupstring($string, $Path->{'virt'}));
		print("</pre>");
	    } else {
	        if (($Path->{'file'} =~ /nsI\w*\.idl$/)) {
	          my $base = basename($Path->{'file'}, ".idl"); 
                  my $dir = $Path->{'virt'};
                  $dir =~ s#([^/]+)(.*)#$1#;
                  my $doxRoot = "http://unstable.elemental.com/mozilla/build/latest/mozilla/" . $dir . "/dox/";
                  print("<P>Inheritance diagram for " . $base . ":</P>\n");
                  print("<P ALIGN=\"CENTER\">\n");
                  print("<IMG SRC=\"" . $doxRoot . "interface" . $base . "__inherit__graph.gif\"");
		  print(" ALIGN=\"CENTER\" BORDER=\"0\" ALT=\"Inheritance graph\">\n");
                  print("</P>\n");
                  print("<P>Collaboration diagram for " . $base . ":</P>\n");
                  print("<P ALIGN=\"CENTER\">\n");
                  print("<IMG SRC=\"" . $doxRoot . "interface" . $base . "__coll__graph.gif\"");
		  print(" ALIGN=\"CENTER\" BORDER=\"0\" ALT=\"Collaboration graph\">\n");
                  print("</P>\n");
                  print("<P ALIGN=\"CENTER\">\n");
                  print("[ <A HREF=\"" .$doxRoot . "interface" . $base . ".html\">\n");
                  print("<I>" . $base . "</I> Interface Reference</A> |");
                  print(" <a href=\"" . $doxRoot . "graph_legend.html\">Graph Legend</a> ]\n");
                  print("</P>\n");
                }
		print("<pre lang='en'>");
		&markupfile(\*SRCFILE, $Path->{'virt'}, $Path->{'file'},
                             sub { print shift });
		print("</pre>");
	    }
	    close(SRCFILE);
	} else {
	    print("<p align=center>\n<i>This file does not exist.</i>\n");
	    if (-f $Path->{'real'}.$Path->{'file'}) {
		&warning("Unable to open ".$Path->{'realf'});
	    }
	}
    }
}

($Conf, $HTTP, $Path) = &init($0);

#if the file is html then don't print a header because the file
#has its own -dme
if (!($Path->{'file'} =~ /\.(html)$/)) {
    if ($Path->{'file'}) {
	&makeheader('source');
    } else {
	&makeheader('sourcedir');
    }
}

&printfile;

if (!($Path->{'file'} =~ /\.(html)$/)) {
    if ($Path->{'file'}) {
	&makefooter('source');
    } else {
	&makefooter('sourcedir');
    }
}