]> i-scream Git - www.i-scream.org.git/commitdiff
Final round of XHTML/tidy'ing CGI scripts. They both produce XHTML that
authorTim Bishop <tim@bishnet.net>
Wed, 24 Mar 2004 20:57:27 +0000 (20:57 +0000)
committerTim Bishop <tim@bishnet.net>
Wed, 24 Mar 2004 20:57:27 +0000 (20:57 +0000)
validates correctly. The code is a little better, but a touch more messy
in a few places.

cgi-bin/cvslog.cgi
cgi-bin/docs.cgi

index 337bc05e6fb56e4e0954f1da6f862b65e35b2018..3c8cf7189ac6c20b7dd7fac1696e76e948d988f4 100755 (executable)
@@ -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";
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
-   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+&print_html($doctype);
 
-<html>
+print <<"END";
 
-<head>
- <title>i-scream CVS Commit Logs</title>
+  <head>
+    <title>
+      i-scream CVS Commit Logs
+    </title>
 END
 
 &print_html($style);
 
 print <<"END";
-</head>
-
-<body>
-
-<div id="container">
 
-<div id="main">
+  </head>
+  <body>
+    <div id="container">
+      <div id="main">
 END
 
 &print_html($header);
 
 print <<"END";
-<div id="contents">
-<h1 class="top">i-scream CVS Commit Logs</h1>
 
-<h2>$heading</h2>
+        <div id="contents">
+          <h1 class="top">
+            i-scream CVS Commit Logs
+          </h1>
+          <h2>
+            $heading
+          </h2>
+          <div id="cvslog">
 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 "<table border=\"0\" bgcolor=\"#000066\" cellpadding=\"5\" width=\"100%\">\n\n";
-    print "<tr><td>\n<font size=\"4\"><b><a href=\"http://cvs.i-scream.org/$module/\" style=\"color: white\">$module module</a></b></font>\n</td></tr>\n\n";
-    print "<tr><td bgcolor=\"white\">\n";
+    my($firstentry) = 1;
+    print <<"END";
+            <div>
+              <h3>
+                <a href="http://cvs.i-scream.org/$module/" class="cvsloghead">$module module</a>
+              </h3>
+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";
+              <p>
+                There have been no commits in this module during this period.
+              </p>
+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<font color=\"blue\">\n<b>";
-                print HTML_encode($1);
-                print "</b>\n<i>";
-                print " committed by <a href=\"mailto:$3\" style=\"text-decoration: none;\">";
-                print HTML_encode("$2");
-                print "</a></i>\n</font>\n"
-            }
-            elsif ($line =~ /^([0-9]{4}-[0-9]{2}-[0-9]{2}.*?)\s+([^\s]+)$/) {
-                print "\n<font color=\"blue\">\n<b>";
-                print HTML_encode($1);
-                print "</b>\n<i>";
-                print " committed by ";
-                print HTML_encode("$2");
-                print "</i>\n</font>\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";
+</pre>
+              </div>
+END
+                    }
+                    if($firstentry) {
+                        $firstentry = 0;
+                        print <<"END";
+              <div class="logitemfirst">
+END
+                    }
+                    else {
+                        print <<"END";
+              <div class="logitem">
+END
+                    }
+                    $sec = $secwho;
+                }
+
+                print <<"END";
+                <p>
+                  <b>
+                    $datetime
+                  </b>
+                  committed by
+END
+                if(defined $email) {
+                    print <<"END";
+                  <a href="mailto:$email">$committer</a>
+END
+                }
+                else {
+                    print <<"END";
+                  $committer
+END
+                }
+                print <<"END";
+                </p>
+END
             }
             elsif($line =~ /([^\s]+) (\([^,^\)]+(,[^\)]+)?\))([,:])/) {
                 my ($file, $rev, $tags, $ext) = ($1, $2, $3, $4);
-                print "<code>";
-                print "<a href=\"http://cvs.i-scream.org/$file\" style=\"text-decoration: none;\">";
-                print HTML_encode($file);
-                print "</a> ";
+                $ext = escapeHTML($ext);
+                if($sec != $secfiles) {
+                    $sec = $secfiles;
+                    print <<"END";
+                <p>
+END
+                }
+                $file = escapeHTML($file);
+                print <<"END";
+                  <a href="http://cvs.i-scream.org/$file">$file</a>
+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 "(<a href=\"http://cvs.i-scream.org/$file$diff\" style=\"text-decoration: none;\">";
-                        print HTML_encode("$start.$end");
-                        print "</a>";
-                        print HTML_encode("$other)");
+                        my $diff = ".diff?r1=$oldrev&amp;r2=$newrev";
+                        my $startend = escapeHTML("$start.$end");
+                        $other = escapeHTML($other);
+                        chomp $other;
+                        print <<"END";
+                  (<a href="http://cvs.i-scream.org/$file$diff">$startend</a>$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";
+                  <br />
+END
                 }
-                print HTML_encode($ext);
-                print "</code><br/>\n"
             }
             else {
+                next if $sec == $secwho; # not done secfiles yet
+                if($sec != $seclog) {
+                    $sec = $seclog;
+                    print <<"END";
+                </p>
+                <pre>
+END
+                }
                 chomp $line;
-                print "<code>";
-                print HTML_encode($line);
-                print "</code><br/>\n"
+                push(@log, $line);
             }
         }
+        if($sec == $seclog) {
+            @log = &trim_array(@log);
+            foreach my $logline (@log) {
+                $logline =~ s/^\t//;
+                print "$logline\n";
+            }
+            @log = ();
+            print <<"END";
+</pre>
+              </div>
+END
+        }
     }
-    print "</td></tr>\n";
-
-    print "</table><p>\n\n";
+    print <<"END";
+            </div>
+END
 }
 
-print "</div>";
+print <<"END";
+          </div>
+        </div>
+END
 
 &print_html($footer);
 
-print "</div>";
+print <<"END";
+
+      </div>
+END
 
 &print_html($menu);
 
 print <<"END";
-</div>
 
-</body>
+    </div>
+  </body>
 </html>
 END
 
 exit 0;
 
-#------------------------------------------------------
-# sub HTML_encode
-#
-# escape HTML characters that may cause problems when
-# shown either in the <body> or within text fields.
-#------------------------------------------------------
-sub HTML_encode ($){
-    my ($encoded) = @_;
-    $encoded =~ s/&/&amp;/g;
-    $encoded =~ s/"/&quot;/g;
-    $encoded =~ s/</&lt;/g;
-    $encoded =~ s/>/&gt;/g;
-    return $encoded;
+# Print the contents of a file containing html
+sub print_html {
+    my ($filename) = @_;
+    open(FILE, $filename);
+    while(<FILE>) {
+        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;
 }
index bdcd3f9721a02bd3b757ddde93c58248f82bf44a..479adc995d23bdcee3180bc504dddbf41d61c8e5 100755 (executable)
@@ -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 "          <pre>\n";
-    # Use $_ implicitly throughout.
-    while (<FILE>) {
-        # Must do the next line first!
-        s/&/&amp;/g;
-        s/</&lt;/g;
-        s/>/&gt;/g;
-        s/"/&quot;/g;
-        s/\b($urls:[$any]+?)(?=[$punc]*[^$any]|$)/<a href="$1">$1<\/a>/igox;
-        print;
+    my ($ltrs) = '\w';
+    my ($gunk) = '/#~:.?+=&%@!\-';
+    my ($punc) = '.:?\-';
+    my ($any) = "${ltrs}${gunk}${punc}";
+    my ($filename) = @_;
+    if(open(FILE, $filename)) {
+        print "          <pre>\n";
+        # Use $_ implicitly throughout.
+        while (<FILE>) {
+            # Must do the next line first!
+            s/&/&amp;/g;
+            s/</&lt;/g;
+            s/>/&gt;/g;
+            s/"/&quot;/g;
+            s/\b($urls:[$any]+?)(?=[$punc]*[^$any]|$)/<a href="$1">$1<\/a>/igox;
+            print;
+        }
+        print "\n</pre>";
+    }
+    else {
+        print "Failed to open $docname.";
     }
-    print "\n</pre>";
-}
-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(<FILE>) {
+        print;
+    }
+    close FILE;
 }