From: Tim Bishop Date: Wed, 24 Mar 2004 20:57:27 +0000 (+0000) Subject: Final round of XHTML/tidy'ing CGI scripts. They both produce XHTML that X-Git-Url: http://git.i-scream.org/?a=commitdiff_plain;h=6567070dd93dd5ce4196d04dd15c588080b5b604;p=www.i-scream.org.git Final round of XHTML/tidy'ing CGI scripts. They both produce XHTML that validates correctly. The code is a little better, but a touch more messy in a few places. --- diff --git a/cgi-bin/cvslog.cgi b/cgi-bin/cvslog.cgi index 337bc05..3c8cf71 100755 --- a/cgi-bin/cvslog.cgi +++ b/cgi-bin/cvslog.cgi @@ -1,8 +1,6 @@ #!/usr/bin/perl -w -# TODO: remove tables, and use CSS instead - -use CGI; +use CGI qw/:standard/; $query=new CGI; my($period)=$query->param('period'); $period = "today" unless defined $period; @@ -50,42 +48,56 @@ my($cvs2clargs) = "--stdout --no-wrap --no-common-dir -r -t -w -S -U $cvsroot/CV my($updatecmd) = "/home/iscream/bin/fullcvsupdate.sh $modulelist"; my($logcmd) = "cd /tmp/i-scream/cvstmp && $cvs2clpath $cvs2clargs"; -my ($menu) = "../nwww/menu.inc" ; -my ($header) = "../nwww/header.inc"; -my ($footer) = "../nwww/footer.inc"; -my ($style) = "../nwww/style.inc"; +my ($incdir) = "../nwww"; + +# Include files +my ($doctype) = "$incdir/doctype.inc"; +my ($style) = "$incdir/style.inc"; +my ($header) = "$incdir/header.inc"; +my ($footer) = "$incdir/footer.inc"; +my ($menu) = "$incdir/menu.inc" ; +# Section markers +my ($sec) = 0; +my ($secwho) = 1; +my ($secfiles) = 2; +my ($seclog) = 3; + +# This should be application/xhtml+xml print "Content-type: text/html\n\n"; -print <<"END"; - +&print_html($doctype); - +print <<"END"; - - i-scream CVS Commit Logs + + + i-scream CVS Commit Logs + END &print_html($style); print <<"END"; - - - - -
-
+ + +
+
END &print_html($header); print <<"END"; -
-

i-scream CVS Commit Logs

-

$heading

+
+

+ i-scream CVS Commit Logs +

+

+ $heading +

+
END print `$updatecmd >/dev/null 2>&1`; @@ -93,40 +105,92 @@ print `$updatecmd >/dev/null 2>&1`; my(@modules) = split (/\s+/, $modulelist); foreach my $module (@modules) { - - print "\n\n"; - print "\n\n"; - print "\n"; - - print "
\n$module module\n
\n"; + my($firstentry) = 1; + print <<"END"; +
+

+ $module module +

+END my(@lines) = `$logcmd $module 2>&1`; if(@lines == 0) { - print "There have been no commits in this module during this period.\n"; + print <<"END"; +

+ There have been no commits in this module during this period. +

+END } else { + my(@log) = (); foreach my $line (@lines) { - if ($line =~ /^([0-9]{4}-[0-9]{2}-[0-9]{2}.*?)\s+([^\s]+)\s+<([^\s]+)>$/) { - print "\n\n"; - print HTML_encode($1); - print "\n"; - print " committed by "; - print HTML_encode("$2"); - print "\n\n" - } - elsif ($line =~ /^([0-9]{4}-[0-9]{2}-[0-9]{2}.*?)\s+([^\s]+)$/) { - print "\n\n"; - print HTML_encode($1); - print "\n"; - print " committed by "; - print HTML_encode("$2"); - print "\n\n" + if ($line =~ /^([0-9]{4}-[0-9]{2}-[0-9]{2}.*?)\s+([^\s]+)(\s+<([^\s]+)>)?$/) { + my($datetime) = escapeHTML($1); + my($committer) = escapeHTML($2); + my($email) = $4; + + if($sec != $secwho) { + if($sec == $seclog) { + @log = &trim_array(@log); + foreach my $logline (@log) { + $logline =~ s/^\t//; + print "$logline\n"; + } + @log = (); + print <<"END"; + +
+END + } + if($firstentry) { + $firstentry = 0; + print <<"END"; +
+END + } + else { + print <<"END"; +
+END + } + $sec = $secwho; + } + + print <<"END"; +

+ + $datetime + + committed by +END + if(defined $email) { + print <<"END"; + $committer +END + } + else { + print <<"END"; + $committer +END + } + print <<"END"; +

+END } elsif($line =~ /([^\s]+) (\([^,^\)]+(,[^\)]+)?\))([,:])/) { my ($file, $rev, $tags, $ext) = ($1, $2, $3, $4); - print ""; - print ""; - print HTML_encode($file); - print " "; + $ext = escapeHTML($ext); + if($sec != $secfiles) { + $sec = $secfiles; + print <<"END"; +

+END + } + $file = escapeHTML($file); + print <<"END"; + $file +END if($rev =~ /\(([^\s]+)\.(\d+)(.*)\)/) { my $start = $1; my $end = $2; @@ -143,69 +207,111 @@ foreach my $module (@modules) { chop $oldrev; } if(defined $oldrev) { - my $diff = ".diff?r1=$oldrev&r2=$newrev"; - print "("; - print HTML_encode("$start.$end"); - print ""; - print HTML_encode("$other)"); + my $diff = ".diff?r1=$oldrev&r2=$newrev"; + my $startend = escapeHTML("$start.$end"); + $other = escapeHTML($other); + chomp $other; + print <<"END"; + ($startend$other)$ext +END } else { - print HTML_encode($rev); + $rev = escapeHTML($rev); + print <<"END"; + $rev$ext +END } } else { - print HTML_encode($rev); + $rev = escapeHTML($rev); + print <<"END"; + $rev$ext +END + } + if($ext !~ /:$/) { + print <<"END"; +
+END } - print HTML_encode($ext); - print "

\n" } else { + next if $sec == $secwho; # not done secfiles yet + if($sec != $seclog) { + $sec = $seclog; + print <<"END"; +

+
+END
+                }
                 chomp $line;
-                print "";
-                print HTML_encode($line);
-                print "
\n" + push(@log, $line); } } + if($sec == $seclog) { + @log = &trim_array(@log); + foreach my $logline (@log) { + $logline =~ s/^\t//; + print "$logline\n"; + } + @log = (); + print <<"END"; +
+
+END + } } - print "

\n\n"; + print <<"END"; +

+END } -print "
"; +print <<"END"; +
+
+END &print_html($footer); -print "
"; +print <<"END"; + +
+END &print_html($menu); print <<"END"; -
- + + END exit 0; -#------------------------------------------------------ -# sub HTML_encode -# -# escape HTML characters that may cause problems when -# shown either in the or within text fields. -#------------------------------------------------------ -sub HTML_encode ($){ - my ($encoded) = @_; - $encoded =~ s/&/&/g; - $encoded =~ s/"/"/g; - $encoded =~ s//>/g; - return $encoded; +# Print the contents of a file containing html +sub print_html { + my ($filename) = @_; + open(FILE, $filename); + while() { + print; + } + close FILE; } -# Print a file without escaping HTML: - -sub print_html ($) { - my ($filename) = @_; - print `cat $filename 2>&1`; +# Trim an array (remove beginning and end emptry entries) +sub trim_array { + my (@array) = @_; + for(my $i = 0; $i < scalar @array; $i++) { + if($array[$i] ne "") { + splice @array, 0, $i; + last; + } + } + for(my $i = scalar @array - 1; $i >= 0; $i--) { + if($array[$i] ne "") { + splice @array, $i+1; + last; + } + } + return @array; } diff --git a/cgi-bin/docs.cgi b/cgi-bin/docs.cgi index bdcd3f9..479adc9 100755 --- a/cgi-bin/docs.cgi +++ b/cgi-bin/docs.cgi @@ -98,7 +98,7 @@ END exit 0; # Print a file, whilst escaping HTML: - -sub print_file ($) { +sub print_file { my ($urls) = '(' . join ('|', qw{ http telnet @@ -109,32 +109,36 @@ my ($urls) = '(' . join ('|', qw{ } ) . ')'; -my ($ltrs) = '\w'; -my ($gunk) = '/#~:.?+=&%@!\-'; -my ($punc) = '.:?\-'; -my ($any) = "${ltrs}${gunk}${punc}"; -my ($filename) = @_; -if(open(FILE, $filename)) { - print "
\n";
-    # Use $_ implicitly throughout.
-    while () {
-        # Must do the next line first!
-        s/&/&/g;
-        s//>/g;
-        s/"/"/g;
-        s/\b($urls:[$any]+?)(?=[$punc]*[^$any]|$)/$1<\/a>/igox;
-        print;
+    my ($ltrs) = '\w';
+    my ($gunk) = '/#~:.?+=&%@!\-';
+    my ($punc) = '.:?\-';
+    my ($any) = "${ltrs}${gunk}${punc}";
+    my ($filename) = @_;
+    if(open(FILE, $filename)) {
+        print "          
\n";
+        # Use $_ implicitly throughout.
+        while () {
+            # Must do the next line first!
+            s/&/&/g;
+            s//>/g;
+            s/"/"/g;
+            s/\b($urls:[$any]+?)(?=[$punc]*[^$any]|$)/$1<\/a>/igox;
+            print;
+        }
+        print "\n
"; + } + else { + print "Failed to open $docname."; } - print "\n
"; -} -else { - print "Failed to open $docname."; -} } -# Print a file without escaping HTML: - +# Print the contents of a file containing html sub print_html ($) { -my ($filename) = @_; -print `cat $filename 2>&1`; + my ($filename) = @_; + open(FILE, $filename); + while() { + print; + } + close FILE; }