CVS update: lxr/http

From: Date: Tue, 29 Jun 1999 02:05:35 +0000
Subject: CVS update: lxr/http
Groups: php.dev 
Request: Send a blank email to php-dev+get-7785@lists.php.net to get a copy of this message
Date: Monday June 28, 1999 @ 22:05 Author: jim Update of /repository/lxr/http In directory php:/tmp/cvs-serv14055 Modified Files: find ident lxr.conf search source template-dir template-head template-tail Removed Files: diff valid_html3.2.gif Log Message: Clean up LXR stuff. This was largely an exercise in playing with perl again and making the LXR code "neater". Index: lxr/http/find diff -u lxr/http/find:1.1 lxr/http/find:1.2 --- lxr/http/find:1.1 Sun Jun 13 01:54:09 1999 +++ lxr/http/find Mon Jun 28 22:05:35 1999 @@ -1,11 +1,12 @@ #!/usr/bin/perl -# $Id: find,v 1.1 1999/06/13 05:54:09 jim Exp $ +# $Id: find,v 1.2 1999/06/29 02:05:35 jim Exp $ # find -- Find files # # Arne Georg Gleditsch <argggh@ifi.uio.no> # Per Kristian Gjermshus <pergj@ifi.uio.no> # +# Modified for the PHP project by Jim Winstead <jimw@php.net> # # 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 @@ -23,49 +24,41 @@ ###################################################################### -use lib 'lib/'; +use lib 'lib'; +use LXR; use LXR::Common; -use LXR::Config; sub find { + my $string = shift || 'search'; + print("<p align=center>\n", "Search for files using regular expressions\n", "<form method=get action=\"find\">\n"); - foreach ($Conf->allvariables) { - if ($Conf->variable($_) ne $Conf->vardefault($_)) { - print("<input type=hidden name=\"",$_, "\" ", - "value=\"", $Conf->variable($_), "\">\n"); - } - } - print("Find file: <input type=text name=\"string\" ", - "value=\"",$searchtext,"\" size =60>\n", + "value=\"",$string,"\" size =60>\n", "<input type=submit value=\"search\">\n", "</form>\n"); - if ($searchtext ne "") { - unless (open(FILELLISTING,$Conf->dbdir."/.glimpse_filenames")) { + if ($string ne '') { + unless (open(FILELLISTING,$LXR->config->dbdir."/filelist")) { &warning("Could not open file listing"); return; } + print("<hr>\n"); - $sourceroot = $Conf->sourceroot; + $sourceroot = $LXR->config->sourceroot; while($file = <FILELLISTING>) { - $file =~ s/^$sourceroot//; - if($file =~ /$searchtext/) { + $file =~ s/^$sourceroot\///; + if($file =~ /$string/i) { print(&fileref("$file", "/$file"),"<br>\n"); } } } } - - -($Conf, $HTTP, $Path) = &init; -$searchtext = $HTTP->{'param'}->{'string'}; - -&makeheader('find'); -&find; -&makefooter('find'); +$LXR = new LXR; +print $LXR->header('find'); +find($LXR->cgi->param('string')); +print $LXR->footer('find'); Index: lxr/http/ident diff -u lxr/http/ident:1.1 lxr/http/ident:1.2 --- lxr/http/ident:1.1 Sun Jun 13 01:54:09 1999 +++ lxr/http/ident Mon Jun 28 22:05:35 1999 @@ -1,11 +1,12 @@ #!/usr/bin/perl -# $Id: ident,v 1.1 1999/06/13 05:54:09 jim Exp $ +# $Id: ident,v 1.2 1999/06/29 02:05:35 jim Exp $ # ident -- Look up identifiers # # Arne Georg Gleditsch <argggh@ifi.uio.no> # Per Kristian Gjermshus <pergj@ifi.uio.no> # +# Modified for the PHP project by Jim Winstead <jimw@php.net> # # 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 @@ -23,9 +24,9 @@ ###################################################################### -use lib 'lib/'; +use lib 'lib'; +use LXR; use LXR::Common; -use LXR::Config; use DB_File; %ty = (('M', 'preprocessor macro'), @@ -43,13 +44,6 @@ sub ident { print("<form method=get action=\"ident\">\n"); - foreach ($Conf->allvariables) { - if ($Conf->variable($_) ne $Conf->vardefault($_)) { - print("<input type=hidden name=\"",$_, "\" ", - "value=\"", $Conf->variable($_), "\">\n"); - } - } - print("Identifier: <input type=text name=\"i\" ", "value=\"",$identifier,"\" size=60>\n", "<input type=submit value=\"Go get it\">\n", @@ -57,8 +51,8 @@ if ($identifier) { - tie(%xref, "DB_File", $Conf->dbdir."/xref", - O_RDONLY, undef, $DB_HASH) || + tie(%xref, "DB_File", $LXR->config->dbdir."/xref", + O_RDONLY, undef, $DB_HASH) or &fatal("Could not open \"".$Conf->dbdir."/xref\""); @refs = split(/\t/,$xref{$identifier}); @@ -66,7 +60,7 @@ print("<h1>$identifier</h1>\n"); if (@refs) { - tie(%fileidx, "DB_File", $Conf->dbdir."/fileidx", + tie(%fileidx, "DB_File", $LXR->config->dbdir."/fileidx", O_RDONLY, undef, $DB_HASH) || &fatal("Could not open \"".$Conf->dbdir."/fileidx\""); @@ -152,10 +146,10 @@ } } -($Conf, $HTTP, $Path) = &init; -$identifier = $HTTP->{'param'}->{'i'}; +$LXR = new LXR; -&makeheader('ident'); -&ident; -&makefooter('ident'); +$identifier = $LXR->cgi->param('i'); +print $LXR->header('ident'); +ident(); +print $LXR->footer('ident'); Index: lxr/http/lxr.conf diff -u lxr/http/lxr.conf:1.1 lxr/http/lxr.conf:1.2 --- lxr/http/lxr.conf:1.1 Sun Jun 13 01:54:09 1999 +++ lxr/http/lxr.conf Mon Jun 28 22:05:35 1999 @@ -9,6 +9,10 @@ # Define the base url for the LXR files. baseurl: http://lxr.php.net/ +# Table colors +theadcolor: #ccccff +tbodycolor: #ffffff #ffffff #ffffff #dddddd #dddddd #dddddd + # These are the templates for the HTML heading, directory listing and # footer, respectively. htmlhead: /local/Web/sites/lxr/http/template-head @@ -16,22 +20,22 @@ htmldir: /local/Web/sites/lxr/http/template-dir # The source is here. -sourceroot: /local/Web/sites/lxr/source/php3/ +sourceroot: /local/Web/sites/lxr/source/php3 srcrootname: php3 # "#include <foo.h>" is mapped to this directory (in the LXR source # tree) incprefix: /include -# Glimpse can be found here. -#glimpsebin: /usr/glimpse/bin - # The database files go here. -#dbdir: /local/Web/sites/lxr/source +dbdir: /local/Web/sites/lxr/source # ht://Dig can be found here. htdigbin: /local/htdig/bin htdigconf: /local/Web/sites/lxr/source/htdig.conf + +# Glimpse can be found here. +#glimpsebin: /usr/glimpse/bin # The power of regexps. This is pretty Linux-specific, but quite # useful. Tinker with it and see what it does. (How's that for Index: lxr/http/search diff -u lxr/http/search:1.1 lxr/http/search:1.2 --- lxr/http/search:1.1 Sun Jun 13 01:54:09 1999 +++ lxr/http/search Mon Jun 28 22:05:35 1999 @@ -1,11 +1,12 @@ #!/usr/bin/perl -# $Id: search,v 1.1 1999/06/13 05:54:09 jim Exp $ +# $Id: search,v 1.2 1999/06/29 02:05:35 jim Exp $ # search -- Freetext search # # Arne Georg Gleditsch <argggh@ifi.uio.no> # Per Kristian Gjermshus <pergj@ifi.uio.no> # +# Modified for the PHP project by Jim Winstead <jimw@php.net> # # 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 @@ -23,9 +24,9 @@ ###################################################################### -use lib 'lib/'; +use lib 'lib'; +use LXR; use LXR::Common; -use LXR::Config; $maxhits = 1000; @@ -36,38 +37,28 @@ print("<form method=get action=\"search\">\n"); - foreach ($Conf->allvariables) { - if ($Conf->variable($_) ne $Conf->vardefault($_)) { - print("<input type=hidden name=\"",$_, "\" ", - "value=\"", $Conf->variable($_), "\">\n"); - } - } - print "Search for: <input type=text name=\"string\" ", "value=\"",$searchtext,"\" size=60>\n", "<input type=submit value=\"search\">\n", -# $Query->checkbox("case",0,0,"Case sensitive search"), -# $Query->checkbox("regexp",1,0,"Regular expression search"), -# $Query->popup_menu("fuzz",[0,1,2,3,4,5,6,7],0), "</form>\n"; $| = 1; print(''); if ($searchtext ne "") { print("<hr>\n"); - unless (open(GLIMPSE, "-|")) { + unless (open(HTDIG, "-|")) { open(STDERR, ">&STDOUT"); $!=''; $ENV{'REQUEST_METHOD'} = 'GET'; # really should encode HTML entities here $ENV{'QUERY_STRING'} = "words=$searchtext".($page?"&page=$page":""); - exec($Conf->htdigbin."/htsearch","-c".$Conf->htdigconf); + exec($LXR->config->htdigbin."/htsearch","-c".$LXR->config->htdigconf); print("ht://Dig subprocess died unexpectedly: $!\n"); exit; } $print = 0; - while (<GLIMPSE>) { + while (<HTDIG>) { if (!$print) { $print = m/<dl>/i; } s/backdoor/source/g; s/<img.+?>//g; @@ -82,18 +73,16 @@ } } - close(GLIMPSE); + close(HTDIG); return; } } -($Conf, $HTTP, $Path) = &init; -$searchtext = $HTTP->{'param'}->{'string'}; -$page = $HTTP->{'param'}->{'page'}; - -&makeheader('search'); -&search; -&makefooter('search'); - +$LXR = new LXR; +$searchtext = $LXR->cgi->param('string'); +$page = $LXR->cgi->param('page'); +print $LXR->header('search'); +search(); +print $LXR->footer('find'); Index: lxr/http/source diff -u lxr/http/source:1.1 lxr/http/source:1.2 --- lxr/http/source:1.1 Sun Jun 13 01:58:03 1999 +++ lxr/http/source Mon Jun 28 22:05:35 1999 @@ -1,11 +1,12 @@ #!/usr/bin/perl -# $Id: source,v 1.1 1999/06/13 05:58:03 jim Exp $ +# $Id: source,v 1.2 1999/06/29 02:05:35 jim Exp $ # source -- Present sourcecode as html, complete with references # # Arne Georg Gleditsch <argggh@ifi.uio.no> # Per Kristian Gjermshus <pergj@ifi.uio.no> # +# Modified for the PHP project by Jim Winstead <jimw@php.net> # # 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 @@ -23,222 +24,164 @@ ###################################################################### -use lib 'lib/'; +use lib 'lib'; use SimpleParse; -use LXR::Common; -use LXR::Config; +use LXR; +use LXR::Common; # getting rid of this... - -sub descexpand { - my $templ = shift; - - if ($index{$filename}) { - return(&expandtemplate($templ, - ('desctext', sub {return($index{$filename})}) - )); - } else { - return(''); - } -} - - -sub diricon { - if ($filename eq '..') { - return(&fileref("<img src=\"/icons/back.gif\"". - " border=0 alt=\"Back\">", - $parentdir)); - } else { - return(&fileref("<img src=\"/icons/folder.gif\"". - " border=0 alt=\"Folder\">", - $Path->{'virt'}.$filename)); - } -} - - -sub dirname { - if ($filename eq '..') { - return(&fileref("Parent directory", $parentdir)); +sub color { + my $colors = $LXR->config->tbodycolor; + my @colors = split /\s+/, $colors; + my $color = shift @colors; + push @colors, $color; + $LXR->config->tbodycolor(join " ", @colors); + return qq|"$color"|; +} + +sub icon { + my $file = shift; + my $ret; + + #XXX make the icons be links + if (-d $LXR->path($file)) { + if ($file eq '..') { + $ret = qq|<img src="/icons/back.gif" border=0 alt="Back">|; } else { - return(&fileref($filename, $Path->{'virt'}.$filename)); + $ret = qq|<img src="/icons/folder.gif" border=0 alt="Folder"> |; } -} - - -sub fileicon { - if ($filename =~ /^.*\.[ch]$/) { - return(&fileref("<img src=\"/icons/c.gif\"". - " border=0 alt=\"C file\">", - $Path->{'virt'}.$filename)); - } elsif ($filename =~ /^.*\.(cpp|cc)$/) { + } + else { + if ($file =~ /^.*\.[ch]$/) { + $ret = qq|<img src="/icons/c.gif" border=0 alt="C file">|; + } elsif ($file =~ /^.*\.(cpp|cc)$/) { # TODO: Find a nice icon for c++ files (KDE?) - return(&fileref("<img src=\"/icons/c.gif\"". - " border=0 alt=\"C++ file\">", - $Path->{'virt'}.$filename)); - } elsif ($filename =~ /^.*\.(y|lex)$/) { + $ret = qq|<img src="/icons/c.gif" border=0 alt="C++ file">|; + } elsif ($file =~ /^.*\.(y|lex)$/) { # TODO: Find a nice icon for parser/scanner files - return(&fileref("<img src=\"/icons/c.gif\"". - " border=0 alt=\"C++ file\">", - $Path->{'virt'}.$filename)); + $ret = qq|<img src="/icons/c.gif" border=0 alt="Lex/Yacc file">|; } else { - return(&fileref("<img src=\"/icons/text.gif\"". - " border=0 alt=\"File\">", - $Path->{'virt'}.$filename)); + $ret = qq|<img src="/icons/text.gif" border=0 alt="Unknown file">|; } -} - + } -sub filename { - return(&fileref($filename, - $Path->{'virt'}.$filename)); + return qq|<a href="source|.$LXR->url($file).qq|">$ret</a>|; } +sub name { + my $file = shift; + my $ret = $file eq '..' ? "Parent Directory" : $file; + return qq|<a href="source|.$LXR->url($file).qq|">$ret</a>|; +} sub filesize { - my $templ = shift; - my $s = (-s $Path->{'real'}.$filename); - - return(&expandtemplate($templ, - ('bytes', sub {return($s)}), - ('kbytes', sub {return($s/1024)}), - ('mbytes', sub {return($s/1048576)}) - )); + my $file = $LXR->path(shift); + my $size = -d $file ? '' : ((stat $file)[7]); + return $size; } - sub modtime { - my @t = gmtime((stat($Path->{'real'}.$filename))[9]); - $t[5] += 1900; - $t[4]++; - return(sprintf("%04d-%02d-%02d %02d:%02d:%02d", reverse(splice(@t, 0, 6)))); + my $file = $LXR->path(shift); + my $modtime = (stat $file)[9]; + return scalar gmtime $modtime; } - -sub direxpand { - my $templ = shift; - my $direx = ''; - local $filename; - local $filestat; - - foreach $filename (@dirs) { - $direx .= &expandtemplate($templ, - ('iconlink', \&diricon), - ('namelink', \&dirname), - ('filesize', sub {return('')}), - ('modtime', \&modtime), - ('description', \&descexpand)); - } - - foreach $filename (@files) { - next if $filename =~ /^.*\.[oa]$|^core$|^00-INDEX$/; - $direx .= &expandtemplate($templ, - ('iconlink', \&fileicon), - ('namelink', \&filename), - ('filesize', \&filesize), - ('modtime', \&modtime), - ('description', \&descexpand)); - } - - return($direx); +sub describe { + my $file = shift; + return ""; } 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); - } - } + my $index; + local %index; + my @dirs; + my @files; + local $parentdir; + +# XXX builtin template needs updating. +# $template = "<ul>\n\$files{\n<li>\$iconlink \$namelink\n}</ul>\n"; + my $template = ''; + if ($LXR->config->htmldir && !open TEMPLATE, $LXR->config->htmldir) { + &warning("Template ".$LXR->config->htmldir." does not exist."); + } else { + $template = join '', <TEMPLATE>; + close TEMPLATE; + } - if (opendir(DIR, $Path->{'real'})) { - foreach $f (sort(grep/^[^\.]/,readdir(DIR))) { - if (-d $Path->{'real'}.$f) { - next if $f=~/^CVS$/; # don't include CVS directories - push(@dirs,"$f/"); - } else { - next if $f=~/\.(dsp|mak|dsw|libdir|tmpl|bat)$/; - 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 (opendir DIR, $LXR->path) { + foreach $f (sort(grep /^[^\.]/, readdir DIR)) { + if (-d $LXR->path($f)) { + # XXX should be doing this based on config setting + next if $f=~/^CVS$/; # don't include CVS directories + push @dirs, "$f/"; + } else { + # XXX should be doing this based on config setting + next if $f=~/\.(dsp|mak|dsw|libdir|tmpl|bat)$/; + push @files, $f; + } + } + closedir DIR; + } else { + print("<p align=center>\n<i>The specified directory does not exist.</i>\n"); + 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(&expandtemplate($template, - ('files', \&direxpand))); + # index file should be a config setting + if (-f $LXR->path("00-INDEX")) { + open INDEX, $LXR->path("00-INDEX") + or &warning("Existing \"00-INDEX\" could not be opened."); + $index = join '', <INDEX>; + %index = $index =~ /\n(\S*)\s*\n\t-\s*([^\n]*)/gs; + } + + if ($LXR->url ne '/') { + $parentdir = $LXR->url; + $parentdir =~ s![^/]+/[^/]*$!!; # remove last directory (and file) + unshift @dirs, '..'; + } + + print LXR::Template::expand($template, { + 'theadcolor' => $LXR->config->theadcolor, + 'dirs' => \@dirs, + 'files' => \@files, + 'color'=>\&color, + 'icon'=>\&icon, + 'name'=>\&name, + 'filesize'=>\&filesize, + 'modtime'=>\&modtime, + 'describe'=>\&describe, + }); + + if (open(SRCFILE, $LXR->path("README"))) { + print("<hr><pre>"); + $LXR->markup(\*SRCFILE, $LXR->path('README'), sub { print shift; }); + print("</pre>"); + close(SRCFILE); + } } - sub printfile { + if (open SRCFILE, $LXR->file) { + print "<a href=\"http://cvs.php.net/cvsweb.cgi", + $LXR->url($file), "\">History</a>"; + print("<pre>"); + $LXR->markup(\*SRCFILE, $LXR->url($file), sub { print shift; }); + print("</pre>"); + close SRCFILE; + } else { + print("<p align=center>\n<i>The specified file does not exist.</i>\n"); + } +} - unless ($Path->{'file'}) { - &printdir; +$LXR = new LXR; - if (open(SRCFILE, $Path->{'real'}.README)) { - print("<hr><pre>"); - &markupfile(\*SRCFILE, $Path->{'virt'}, 'README', - sub { print shift }); - print("</pre>"); - close(SRCFILE); - } +print $LXR->header('source'); - } else { - if (open(SRCFILE, $Path->{'realf'})) { - print "<a href=\"http://cvs.php.net/cvsweb.cgi", - $Path->{'virt'}, $Path->{'file'}, "\">History</a>"; - 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'}); - } - } - } +if (-d $LXR->file) { + printdir(); } - -($Conf, $HTTP, $Path) = &init; +else { + printfile(); +} -&makeheader('source'); -&printfile; -&makefooter('source'); +print $LXR->footer('source'); Index: lxr/http/template-dir diff -u lxr/http/template-dir:1.1 lxr/http/template-dir:1.2 --- lxr/http/template-dir:1.1 Sun Jun 13 01:54:09 1999 +++ lxr/http/template-dir Mon Jun 28 22:05:35 1999 @@ -1,15 +1,25 @@ -<table border=0 cellspacing=4> - <tr valign=middle> - <td> +<table border=0 width="100%" cellspacing=0 cellpadding=3> + <tr valign=middle bgcolor=$theadcolor> + <td>&nbsp;</td> <td nowrap><b>Name</b> <td nowrap><b>Size</b> <td nowrap><b>Last modified (GMT)</b> <td nowrap><b>Description</b> + </tr> + $dirs{ + <tr valign=middle bgcolor=&color()> + <td nowrap>&icon($dir)</td> + <td nowrap>&name($dir)</td> + <td nowrap align=right>&nbsp;</td> + <td nowrap>&modtime($dir)</td> + <td></i>&describe($dir)&nbsp;</i></td> + </tr>} $files{ - <tr valign=middle> - <td nowrap>$iconlink - <td nowrap>$namelink - <td nowrap align=right>$filesize{$bytes bytes} - <td nowrap>$modtime - <td>$description{<i>$desctext</i>}} + <tr valign=middle bgcolor=&color()> + <td nowrap>&icon($file)</td> + <td nowrap>&name($file)</td> + <td nowrap align=right>&filesize($file)</td> + <td nowrap>&modtime($file)</td> + <td></i>&describe($file)</i>&nbsp;</td> + </tr>} </table> Index: lxr/http/template-head diff -u lxr/http/template-head:1.1 lxr/http/template-head:1.2 --- lxr/http/template-head:1.1 Sun Jun 13 01:54:09 1999 +++ lxr/http/template-head Mon Jun 28 22:05:35 1999 @@ -7,7 +7,7 @@ <body bgcolor=white> <div align=center> - $modes{ ~ <b>[</b>&nbsp;$modelink&nbsp;<b>]</b>} ~ + $modes{ ~ <b>[</b>&nbsp;$mode&nbsp;<b>]</b>} ~ </div> <h1 align=center> @@ -18,10 +18,4 @@ $banner </h1> -<div align=center> - $variables{ - <b>$varname:</b> - $varlinks{ ~ <b>[</b>&nbsp;$varvalue&nbsp;<b>]</b>} ~ - <br>} -</div> <hr> Index: lxr/http/template-tail diff -u lxr/http/template-tail:1.1 lxr/http/template-tail:1.2 --- lxr/http/template-tail:1.1 Sun Jun 13 01:54:09 1999 +++ lxr/http/template-tail Mon Jun 28 22:05:35 1999 @@ -1,6 +1,6 @@ <hr> <div align=center> - $modes{ ~ <b>[</b>&nbsp;$modelink&nbsp;<b>]</b>} ~ + $modes{ ~ <b>[</b>&nbsp;$mode&nbsp;<b>]</b>} ~ </div> <hr>

« previous php.dev (#7785) next »