X-Git-Url: http://git.jankratochvil.net/?p=MyWeb.git;a=blobdiff_plain;f=Web.pm;h=e41a314f3d09e47f2d524abca9ba690d5df97d32;hp=957507fa52aa2700fee2095d8cb0b39339a1139e;hb=633dc05b0519d86762bd084d872d34f9183237e0;hpb=b04e153c27986d315a3eacae5440b2bdc554c40d;ds=sidebyside
diff --git a/Web.pm b/Web.pm
index 957507f..e41a314 100644
--- a/Web.pm
+++ b/Web.pm
@@ -1,5 +1,3 @@
-#! /usr/bin/perl
-#
# $Id$
# Common functions for HTML/XHTML output generation
# Copyright (C) 2003 Jan Kratochvil You can report this problem's details to"
- ." admin of this website.".$ListItem->{"name"}."
\n";
- print $ListItem->{"description"};
- print "
\n";
- my @table=(
- {"key"=>qr(^download\b.*),"text"=>sub ($) {
- $_[0]=~s/^download//;
- $_[0]=~s/^-/ /;
- return "Download".$_[0];
- },
- "format"=>sub ($) {
- my $r;
- if ($_[0]=~m#^[a-z]+://#) {
- $r="".CGI::escapeHTML($_[0])."";
- }
- else {
- $r="".CGI::escapeHTML(basename($_[0]))."";
- my $size=(stat $_[0])[7];
- die "Cannot stat \"".$_[0]."\": $!" if !defined $size;
- if ($size>=1024*1024) { $size=int($size/(1024*1024))." MB"; }
- elsif ($size>=1024 ) { $size=int($size/(1024 ))." KB"; }
- else { $size=int($size )." B"; }
- $r.=" ($size)";
- }
- return $r;
- }},
- {"key"=>qr(^link\b.*),"text"=>sub ($) {
- $_[0]=~s/^link-//;
- return $_[0];
- },
- "format"=>sub ($) {
- return "".CGI::escapeHTML($_[0])."";
- }},
- {"key"=>"summary","text"=>"Summary"},
- {"key"=>"ownership","text"=>"Ownership"},
- {"key"=>"license","text"=>"License","format"=>sub ($) {
- my %known=(
- "PD"=>"Public Domain",
- "GPL"=>"GNU General Public License",
- "LGPL"=>"GNU Lesser General Public License",
- );
- return $known{$_[0]};
- }},
- {"key"=>"maintenance","text"=>"Currently maintained?","format"=>sub ($) {
- my %known=(
- "finished"=>"Project is finished. Possible bug reports welcome although project not actively developed.",
- "dead"=>"Project became dead code, some updates would be required. It is no longer used, project is not supported.",
- "obsolete"=>"Obsolete as some other existing package superseded this one.",
- "merge"=>"Functions of this package should be merged to some other one.",
- "update"=>"Package needs updating to be fully usable, patches welcome.",
- "accepted"=>"This patch was accepted by the original package author. It has no longer any separate meaning.",
- );
- return $known{$_[0]};
- }},
- {"key"=>"reason","text"=>"Reason"},
- {"key"=>"sponsorship","text"=>"Sponsoring Company"},
- {"key"=>"language","text"=>"Programming language","format"=>sub ($) {
- return "".CGI::escapeHTML($_[0]).""
- if $_[0]=~/^Java\b/;
- return "".CGI::escapeHTML($_[0]).""
- if $_[0]=~/^PHP\b/;
- return undef();
- }},
- );
- print ''."\n";
+ do { return $_ if $_; } for ($W->{"top_dir"});
+ return $INC[0]; # fallback
+}
-sub tableit_func
+sub top_dir (;$)
{
-my($tableit,$val,$key,$ListItem)=@_;
-
- print "
\n";
- print " \n";
- delete $ListItem->{$key};
+ return top_dir_disk().$in;
}
- for my $tableit (@table) {
- if (!ref $tableit->{"key"}) {
- tableit_func($tableit,$ListItem->{$tableit->{"key"}},$tableit->{"key"},$ListItem) if $ListItem->{$tableit->{"key"}};
- }
- else {
- for my $key (keys(%$ListItem)) {
- my $keyregex=$tableit->{"key"};
- next if $key!~/$keyregex/;
- tableit_func($tableit,$ListItem->{$key},$key,$ListItem);
- }
+sub fatal (;$);
+
+sub args_check (%)
+{
+my(%tmpl)=@_;
+
+ while (my($name,$regex)=each(%tmpl)) {
+ my $name_html="Parameter ".CGI::escapeHTML($name)."";
+ $W->{"args"}{$name}="" if !defined $W->{"args"}{$name};
+ $W->{"args"}{$name}=[ $W->{"args"}{$name} ] if !ref $W->{"args"}{$name} && ref $regex;
+ fatal "$name_html passed as multivar although singlevar expected"
+ if ref $W->{"args"}{$name} && !ref $regex;
+ $regex=${$regex}[0] if ref $regex;
+ for my $val (!ref $W->{"args"}{$name} ? $W->{"args"}{$name} : @{$W->{"args"}{$name}}) {
+ $val="" if !defined $val;
+ fatal "$name_html ".CGI::escapeHTML($val).""
+ ." does not match the required regex ".CGI::escapeHTML($regex)." "
+ if $regex ne "" && $val!~/$regex/;
}
}
- print "";
- if (!ref $tableit->{"text"}) {
- print $tableit->{"text"};
- }
- else {
- my $textfunc=$tableit->{"text"};
- my $key=$key;
- print &$textfunc($key);
- }
- print ": ";
- if ($tableit->{"format"}) {
- my $format=$tableit->{"format"};
- my $valn=&$format($val);
- $val=$valn if defined $valn;
+my($in)=@_;
+
+ if (my $uri=$ENV{"REQUEST_URI"}) {
+ $uri.="Index" if $uri=~m#/$#;
+ if (defined $in) {
+ my($inpath,$inquery)=split /[?]/,$in,2;
+ $inpath=~tr///cs;
+ $uri=~tr///cs;
+ for (;;) {
+ my($in1 ,$in2 )=($in =~m#^(/[^/]+)(/.*)$#);
+ my($uri1,$uri2)=($uri=~m#^(/[^/]+)(/.*)$#);
+ last if !defined $in1 || !defined $uri1 || $in1 ne $uri1;
+ $in=$in2;
+ $uri=$uri2;
+ }
+ }
+ $uri=~s#^/*##;
+ $uri=~s#[^/]+#..#g;
+ $uri=File::Basename::dirname($uri);
+ my $r=$uri.(defined $in ? $in : "");
+# 1 while $r=~s#^[.]/##;
+# $r="./$r" if $r=~m#^(?:?.*)$#; # empty pathname?
+ return $r;
}
- print "$val
FATAL ERROR: $msg!
\n"
+ $W->{"indexme"}=0; # For the case no heading was sent yet.
+ My::Web->heading();
+ print "\n".vskip("3ex")."FATAL ERROR: $msg!
\n"
."
\n" if $delimit; - print "
$cvs_id_html
\n"; + print "';
+ print join("
\n",map({ my $package=$_;
+ my $cvs_id=(eval('$'.$package."::CVS_ID")
+# || $package # debug
+ );
+ if (!$cvs_id) {
+ ();
+ }
+ else {
+ $cvs_id='$'.$cvs_id.'$'; # Eaten by 'q' operator.
+ my @cvs_id_split=split / +/,$cvs_id;
+ if (@cvs_id_split==8) {
+ my $file=$package;
+ $file=~s#::#/#g;
+ my $ext;
+ for (qw(.html.pl .pl .pm),"") {
+ $ext=$_;
+ last if -r top_dir_disk()."/$file$ext";
+ cluck "Class file $file not found" if !$ext;
+ }
+ $file.=$ext;
+ $cvs_id_split[2]=""
+ .a_href((map({ my $s=$_; $s=~s#/viewcvs/#$&~checkout~/#; $s; } $W->{"viewcvs"}))[0]."$file?rev=".$cvs_id_split[2],
+ $cvs_id_split[2]);
+ $cvs_id_split[1]=a_href($W->{"viewcvs"}.$file,
+ ($package!~/^Apache::/ ? $package : $cvs_id_split[1]));
+ $cvs_id_split[5]=&{$W->{"cvs_id_author"}}($cvs_id_split[5]);
+ }
+ join " ",@cvs_id_split;
+ }
+ } (
+ $W->{"__PACKAGE__"},
+ __PACKAGE__,
+ @{$W->{"packages_used"}{$Apache::Registry::curstash}},
+ )));
+ print "