1998-06-12 03:56:23 +04:00
|
|
|
#!/usr/bonsaitools/bin/perl
|
1998-06-23 05:01:11 +04:00
|
|
|
# $Id: source,v 1.10 1998-06-23 01:01:11 jwz Exp $
|
1998-06-12 03:56:23 +04:00
|
|
|
|
|
|
|
# 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 lib 'lib/';
|
|
|
|
use SimpleParse;
|
|
|
|
use LXR::Common;
|
|
|
|
use LXR::Config;
|
|
|
|
|
|
|
|
|
1998-06-23 05:01:11 +04:00
|
|
|
# dme: Search the beginning of a source file for a short description
|
|
|
|
# to be displayed in directory listings. Not all files have
|
|
|
|
# them and the ones that do use different formats so there are
|
|
|
|
# lots of ways to end up with junk. The basic format is: a file
|
|
|
|
# name possibly followed by a colon or dash(es) with whitespace
|
|
|
|
# strewn in followed by the description and maybe some stray comment
|
|
|
|
# characters. Don't be confused by #includes or rcs comments
|
|
|
|
# at the beginning of the file.
|
|
|
|
# -dme
|
1998-06-12 03:56:23 +04:00
|
|
|
sub fdescexpand {
|
1998-06-23 05:01:11 +04:00
|
|
|
my $linecount=0;
|
|
|
|
local $desc= "";
|
|
|
|
|
|
|
|
#ignore files that aren't source code
|
|
|
|
if (!(
|
|
|
|
($filename =~ /\.c$/) |
|
|
|
|
($filename =~ /\.h$/) |
|
|
|
|
($filename =~ /\.cc$/) |
|
|
|
|
($filename =~ /\.cp$/) |
|
|
|
|
($filename =~ /\.cpp$/) |
|
|
|
|
($filename =~ /\.java$/)
|
|
|
|
)){
|
|
|
|
return("");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (open(FILE, $Path->{'real'}."/".$filename)) {
|
|
|
|
while(<FILE>){
|
|
|
|
if($linecount++ > 40) {
|
|
|
|
last;
|
|
|
|
}elsif (/Id: $filename/){
|
|
|
|
#ignore cvs headers
|
|
|
|
}elsif (/^#/){
|
|
|
|
#ignore cpp directives
|
|
|
|
}elsif (/$filename\s*- ?-*\s*/i){
|
|
|
|
$desc = (split(/ $filename\s*- ?-*\s*/i))[1];
|
|
|
|
if ($desc) {last};
|
|
|
|
}elsif (/$filename\s*:\s*/i){
|
|
|
|
$desc = (split(/ $filename\s*:\s*/i))[1];
|
|
|
|
if ($desc) {last};
|
|
|
|
}elsif (/$filename\s\s*/i){
|
|
|
|
$desc = (split(/ $filename\s\s*/i))[1];
|
|
|
|
if ($desc) {last};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(FILE);
|
|
|
|
}
|
|
|
|
if (!($desc)){
|
|
|
|
return("");
|
|
|
|
}
|
|
|
|
|
|
|
|
#strip trailing asterisks and "*/"
|
|
|
|
$desc =~ s#\*/?\s*$##;
|
|
|
|
|
|
|
|
#htmlify the comments making links to symbols and files
|
|
|
|
$desc = markupstring($desc, $Path->{'virt'});
|
1998-06-12 03:56:23 +04:00
|
|
|
|
|
|
|
return($desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub descexpand {
|
|
|
|
|
|
|
|
$desc= "";
|
|
|
|
if (open(DESC, $Path->{'real'}."/doc/".$filename.".short")) {
|
|
|
|
$desc=<DESC>;
|
|
|
|
close(DESC);
|
|
|
|
}
|
|
|
|
return($desc);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub diricon {
|
1998-06-16 01:51:41 +04:00
|
|
|
my $img, $link;
|
1998-06-12 03:56:23 +04:00
|
|
|
if ($filename eq '..') {
|
1998-06-16 01:51:41 +04:00
|
|
|
$img = "/icons/back.gif";
|
|
|
|
$link = $parentdir;
|
1998-06-12 03:56:23 +04:00
|
|
|
} else {
|
1998-06-16 01:51:41 +04:00
|
|
|
# $img = "/icons/folder.gif";
|
|
|
|
$img = "internal-gopher-menu";
|
|
|
|
$link = $Path->{'virt'}.$filename;
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
1998-06-16 01:51:41 +04:00
|
|
|
return(&fileref("<IMG ALIGN=ABSBOTTOM BORDER=0 SRC=\"$img\">", $link));
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
sub dirname {
|
|
|
|
if ($filename eq '..') {
|
|
|
|
return(&fileref("Parent directory", $parentdir));
|
|
|
|
} else {
|
1998-06-16 13:03:40 +04:00
|
|
|
return(&fileref($filename, $Path->{'virt'}.$filename));
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub fileicon {
|
1998-06-16 01:51:41 +04:00
|
|
|
my $img;
|
|
|
|
|
1998-06-12 03:56:23 +04:00
|
|
|
if ($filename =~ /^.*\.[ch]$/) {
|
1998-06-16 01:51:41 +04:00
|
|
|
# $img = "/icons/c.gif";
|
|
|
|
$img = "internal-gopher-text";
|
1998-06-12 03:56:23 +04:00
|
|
|
} elsif ($filename =~ /^.*\.(cpp|cc)$/) {
|
|
|
|
# TODO: Find a nice icon for c++ files (KDE?)
|
1998-06-16 01:51:41 +04:00
|
|
|
# $img = "/icons/c.gif";
|
|
|
|
$img = "internal-gopher-text";
|
1998-06-12 03:56:23 +04:00
|
|
|
} else {
|
1998-06-16 01:51:41 +04:00
|
|
|
# $img = "/icons/text.gif";
|
|
|
|
$img = "internal-gopher-unknown";
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
1998-06-16 01:51:41 +04:00
|
|
|
|
|
|
|
return(&fileref("<IMG ALIGN=ABSBOTTOM BORDER=0 SRC=\"$img\">",
|
|
|
|
$Path->{'virt'}.$filename));
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub filename {
|
1998-06-16 13:03:40 +04:00
|
|
|
return(&fileref($filename, $Path->{'virt'}.$filename));
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub filesize {
|
|
|
|
my $templ = shift;
|
|
|
|
my $s = (-s $Path->{'real'}.$filename);
|
1998-06-16 02:18:06 +04:00
|
|
|
my $str;
|
|
|
|
if ($s < 1<<10) {
|
|
|
|
$str = "$s";
|
|
|
|
} else {
|
|
|
|
# if ($s < 1<<20) {
|
|
|
|
$str = ($s>>10) . "k";
|
|
|
|
# } else {
|
|
|
|
# $str = ($s>>20) . "M";
|
|
|
|
# }
|
|
|
|
}
|
1998-06-12 03:56:23 +04:00
|
|
|
return(&expandtemplate($templ,
|
1998-06-16 02:18:06 +04:00
|
|
|
('bytes', sub {return($str)}),
|
|
|
|
('kbytes', sub {return($str)}),
|
|
|
|
('mbytes', sub {return($str)})
|
1998-06-12 03:56:23 +04:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub modtime {
|
1998-06-16 01:51:41 +04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
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";
|
|
|
|
|
|
|
|
foreach $filename (@dirs) {
|
|
|
|
$line++;
|
|
|
|
$direx .= &expandtemplate($templ,
|
|
|
|
('iconlink', \&diricon),
|
|
|
|
('namelink', \&dirname),
|
1998-06-16 01:51:41 +04:00
|
|
|
('filesize', sub {return('-')}),
|
1998-06-12 03:56:23 +04:00
|
|
|
('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))) {
|
1998-06-16 01:51:41 +04:00
|
|
|
if ($f eq "CVS") {
|
|
|
|
# skip it
|
|
|
|
} elsif (-d $Path->{'real'}.$f) {
|
1998-06-12 03:56:23 +04:00
|
|
|
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, '..');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (open(DESC, $Path->{'real'}."/doc/index.html")) {
|
|
|
|
print(<DESC>);
|
|
|
|
print("\n<p>\n");
|
|
|
|
close(DESC);
|
|
|
|
}
|
|
|
|
|
|
|
|
print(&expandtemplate($template,
|
|
|
|
('files', \&direxpand)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub printfile {
|
|
|
|
|
|
|
|
unless ($Path->{'file'}) {
|
|
|
|
&printdir;
|
|
|
|
|
1998-06-23 05:01:11 +04:00
|
|
|
if ( (-f $Path->{'real'}.README) &&
|
|
|
|
(open(SRCFILE, $Path->{'real'}.README)) ) {
|
1998-06-12 03:56:23 +04:00
|
|
|
print("<hr><pre>");
|
|
|
|
&markupfile(\*SRCFILE, $Path->{'virt'}, 'README',
|
|
|
|
sub { print shift });
|
|
|
|
print("</pre>");
|
|
|
|
close(SRCFILE);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
if (open(SRCFILE, $Path->{'realf'})) {
|
|
|
|
if (($Path->{'file'} =~ /\.(html)$/)) {
|
|
|
|
print <SRCFILE>;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(open(DESC, $Path->{'real'}."doc/".$Path->{'file'}.".long")){
|
|
|
|
print(<DESC>);
|
|
|
|
close(DESC);
|
|
|
|
}
|
|
|
|
print("<pre>");
|
|
|
|
&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'});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-06-17 00:23:42 +04:00
|
|
|
($Conf, $HTTP, $Path) = &init($0);
|
1998-06-12 03:56:23 +04:00
|
|
|
|
|
|
|
#if the file is html then don't print a header because the file
|
|
|
|
#has its own -dme
|
|
|
|
if (!($Path->{'file'} =~ /\.(html)$/)) {
|
1998-06-16 04:51:27 +04:00
|
|
|
if ($Path->{'file'}) {
|
|
|
|
&makeheader('source');
|
|
|
|
} else {
|
|
|
|
&makeheader('sourcedir');
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
1998-06-16 04:51:27 +04:00
|
|
|
}
|
|
|
|
|
1998-06-12 03:56:23 +04:00
|
|
|
&printfile;
|
1998-06-16 04:51:27 +04:00
|
|
|
|
1998-06-12 03:56:23 +04:00
|
|
|
if (!($Path->{'file'} =~ /\.(html)$/)) {
|
1998-06-16 04:51:27 +04:00
|
|
|
if ($Path->{'file'}) {
|
|
|
|
&makefooter('source');
|
|
|
|
} else {
|
|
|
|
&makefooter('sourcedir');
|
1998-06-12 03:56:23 +04:00
|
|
|
}
|
1998-06-16 04:51:27 +04:00
|
|
|
}
|
1998-06-20 05:29:23 +04:00
|
|
|
|
|
|
|
#$len = length($file);
|
|
|
|
#print ("length is: ", $len) ;
|