[BACK]Return to cvsweb.cgi CVS log [TXT][DIR] Up to [local] / CVSROOT

Annotation of CVSROOT/cvsweb.cgi, Revision 1.2

1.1       maekawa     1: #!/usr/bin/perl -ws
                      2: #
                      3: # cvsweb - a CGI interface to CVS trees.
                      4: #
                      5: # Written in their spare time by
                      6: #             Bill Fenner      <fenner@freebsd.org>   (original work)
                      7: # extended by Henner Zeller    <zeller@think.de>,
                      8: #             Henrik Nordström <hno@hem.passagen.se>
                      9: #             Ken Coar         <coar@Apache.Org>
                     10: #
                     11: # Based on:
                     12: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
                     13: #   http://www.freebsd.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
                     14: #
                     15: # Copyright (c) 1996-1998 Bill Fenner
                     16: #           (c) 1998-1999 Henner Zeller
                     17: #          (c) 1999      Henrik Nordström
                     18: # All rights reserved.
                     19: #
                     20: # Redistribution and use in source and binary forms, with or without
                     21: # modification, are permitted provided that the following conditions
                     22: # are met:
                     23: # 1. Redistributions of source code must retain the above copyright
                     24: #    notice, this list of conditions and the following disclaimer.
                     25: # 2. Redistributions in binary form must reproduce the above copyright
                     26: #    notice, this list of conditions and the following disclaimer in the
                     27: #    documentation and/or other materials provided with the distribution.
                     28: #
                     29: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     30: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     31: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     32: # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     33: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     34: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     35: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     36: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     37: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     38: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     39: # SUCH DAMAGE.
                     40: #
                     41: # $Id: cvsweb.cgi,v 1.79 1999/11/03 08:05:29 hzeller Exp $
                     42: #
                     43: ###
                     44:
                     45: use strict;
                     46:
                     47: use vars qw (
                     48:     $config $allow_version_select $verbose
                     49:     %CVSROOT %CVSROOTdescr %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
                     50:     %alltags @tabcolors %fileinfo %tags @branchnames %nameprinted
                     51:     %symrev %revsym @allrevisions %date %author @revdisplayorder
                     52:     @revisions %state %difflines %log %branchpoint @revorder $prcgi
                     53:     $checkoutMagic $doCheckout $scriptname $scriptwhere
                     54:     $where $Browser $nofilelinks $maycompress @stickyvars
                     55:     %input $query $barequery $sortby $bydate $byrev $byauthor
                     56:     $bylog $byfile $hr_default $logsort $cvstree $cvsroot
                     57:     $mimetype $defaultTextPlain $defaultViewable $allow_compress
                     58:     $GZIPBIN $backicon $diricon $fileicon $fullname $newname
                     59:     $cvstreedefault $body_tag $logo $defaulttitle $address
                     60:     $backcolor $long_intro $short_instruction $shortLogLen
                     61:     $show_author $dirtable $tablepadding $columnHeaderColorDefault
                     62:     $columnHeaderColorSorted $hr_breakable $hr_funout $hr_ignwhite
                     63:     $hr_ignkeysubst $diffcolorHeading $diffcolorEmpty $diffcolorRemove
                     64:     $diffcolorChange $diffcolorAdd $diffcolorDarkChange $difffontface
                     65:     $difffontsize $inputTextSize $mime_types $allow_annotate
                     66:     $allow_markup $use_java_script $open_extern_window
                     67:     $extern_window_width $extern_window_height $edit_option_form
                     68:     $checkout_magic $show_subdir_lastmod $show_log_in_markup $v
                     69:     $navigationHeaderColor $tableBorderColor $markupLogColor
                     70:     $tabstop $state $annTable $sel $curbranch $HideModules @HideModules
                     71:     $module
                     72: );
                     73:
                     74: ##### Start of Configuration Area ########
                     75: # == EDIT this ==
                     76: # User configuration is stored in
1.2     ! maekawa    77: $config = $ENV{'CVSWEB_CONFIG'} || '/usr/local/etc/apache/cvsweb.conf';
1.1       maekawa    78:
                     79: # == Configuration defaults ==
                     80: # Defaults for configuration variables that shouldn't need
                     81: # to be configured..
                     82: $allow_version_select = 1;
                     83:
                     84: ##### End of Configuration Area   ########
                     85:
                     86: ######## Configuration variables #########
                     87: # These are defined to allow checking with perl -cw
                     88: %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS = %MTYPES =
                     89: %tags = %alltags = @tabcolors = ();
                     90: $cvstreedefault = $body_tag = $logo = $defaulttitle = $address =
                     91: $backcolor = $long_intro = $short_instruction = $shortLogLen =
                     92: $show_author = $dirtable = $tablepadding = $columnHeaderColorDefault =
                     93: $columnHeaderColorSorted = $hr_breakable = $hr_funout = $hr_ignwhite =
                     94: $hr_ignkeysubst = $diffcolorHeading = $diffcolorEmpty = $diffcolorRemove =
                     95: $diffcolorChange = $diffcolorAdd = $diffcolorDarkChange = $difffontface =
                     96: $difffontsize = $inputTextSize = $mime_types = $allow_annotate =
                     97: $allow_markup = $use_java_script = $open_extern_window =
                     98: $extern_window_width = $extern_window_height = $edit_option_form =
                     99: $checkout_magic = $show_subdir_lastmod = $show_log_in_markup = $v =
                    100: $navigationHeaderColor = $tableBorderColor = $markupLogColor =
                    101: $tabstop = undef;
                    102:
                    103: ##### End of configuration variables #####
                    104:
                    105: use Time::Local;
                    106: use IPC::Open2;
                    107:
                    108: $verbose = $v;
                    109: $checkoutMagic = "~checkout~";
                    110: $where = defined($ENV{'PATH_INFO'}) ? $ENV{'PATH_INFO'} : "";
                    111: $doCheckout = ($where =~ /^\/$checkoutMagic/);
                    112: $where =~ s|^/($checkoutMagic)?||;
                    113: $where =~ s|/+$||;
                    114: ($scriptname = $ENV{'SCRIPT_NAME'}) =~ s|^/?|/|;
                    115: $scriptname =~ s|/+$||;
                    116: if ($where) {
                    117:     $scriptwhere = $scriptname . '/' . urlencode($where);
                    118: }
                    119: else {
                    120:     $scriptwhere = $scriptname;
                    121: }
                    122: $scriptwhere =~ s|/+$||;
                    123:
                    124: # in lynx, it it very annoying to have two links
                    125: # per file, so disable the link at the icon
                    126: # in this case:
                    127: $Browser = $ENV{'HTTP_USER_AGENT'};
                    128: $nofilelinks = ($Browser =~ m'^Lynx/');
                    129:
                    130: # newer browsers accept gzip content encoding
                    131: # and state this in a header
                    132: # (netscape did always but didn't state it)
                    133: # It has been reported that these
                    134: #  braindamaged MS-Internet Exploders claim that they
                    135: # accept gzip .. but don't in fact and
                    136: # display garbage then :-/
                    137: # Turn off gzip if running under mod_perl. piping does
                    138: # not work as expected inside the server. One can probably
                    139: # achieve the same result using Apache::GZIPFilter.
                    140: $maycompress =(($ENV{'HTTP_ACCEPT_ENCODING'} =~ m|gzip|
                    141:                || $Browser =~ m%^Mozilla/3%)
                    142:               && ($Browser !~ m/MSIE/)
                    143:               && !defined($ENV{'MOD_PERL'}));
                    144:
                    145: # put here the variables we need in order
                    146: # to hold our state - they will be added (with
                    147: # their current value) to any link/query string
                    148: # you construct
                    149: @stickyvars = ('cvsroot','hideattic','sortby','logsort','f','only_with_tag');
                    150:
                    151: if (-f $config) {
                    152:     do "$config";
                    153:     $HideModules = "§" . join("§", @HideModules) . "§";
                    154: }
                    155: else {
                    156:    &fatal("500 Internal Error",
                    157:          'Configuration not found.  Set the variable <code>$config</code> '
                    158:           . 'in cvsweb.cgi, or the environment variable '
                    159:           . '<code>CVSWEB_CONFIG</code>, to your <b>cvsweb.conf</b> '
                    160:           . 'configuration file first.');
                    161: }
                    162:
                    163: undef %input;
                    164: if ($query = $ENV{'QUERY_STRING'}) {
                    165:     foreach (split(/&/, $query)) {
                    166:        s/%(..)/sprintf("%c", hex($1))/ge;      # unquote %-quoted
                    167:        if (/(\S+)=(.*)/) {
                    168:            $input{$1} = $2 if ($2 ne "");
                    169:        }
                    170:        else {
                    171:            $input{$_}++;
                    172:        }
                    173:     }
                    174: }
                    175:
                    176: # For backwards compability, set only_with_tag to only_on_branch if set.
                    177: $input{only_with_tag} = $input{only_on_branch}
                    178:     if (defined($input{only_on_branch}));
                    179:
                    180: foreach (keys %DEFAULTVALUE)
                    181: {
                    182:     # replace not given parameters with the default parameters
                    183:     if (!defined($input{$_}) || $input{$_} eq "") {
                    184:        # Empty Checkboxes in forms return -- nothing. So we define a helper
                    185:        # variable in these forms (copt) which indicates that we just set
                    186:        # parameters with a checkbox
                    187:        if (!defined($input{"copt"})) {
                    188:            # 'copt' isn't defined --> empty input is not the result
                    189:            # of empty input checkbox --> set default
                    190:            $input{$_} = $DEFAULTVALUE{$_} if (defined($DEFAULTVALUE{$_}));
                    191:        }
                    192:        else {
                    193:            # 'copt' is defined -> the result of empty input checkbox
                    194:            # -> set to zero (disable) if default is a boolean (0|1).
                    195:            $input{$_} = 0
                    196:                if (defined($DEFAULTVALUE{$_})
                    197:                    && ($DEFAULTVALUE{$_} eq "0" || $DEFAULTVALUE{$_} eq "1"));
                    198:        }
                    199:     }
                    200: }
                    201:
                    202: $barequery = "";
                    203: foreach (@stickyvars) {
                    204:     # construct a query string with the sticky non default parameters set
                    205:     if (defined($input{$_}) && $input{$_} ne "" && $input{$_} ne $DEFAULTVALUE{$_}) {
                    206:        if ($barequery) {
                    207:            $barequery = $barequery . "&";
                    208:        }
                    209:        my $thisval = urlencode($_) . "=" . urlencode($input{$_});
                    210:        $barequery .= $thisval;
                    211:     }
                    212: }
                    213: # is there any query ?
                    214: if ($barequery) {
                    215:     $query = "?$barequery";
                    216:     $barequery = "&" . $barequery;
                    217: }
                    218: else {
                    219:     $query = "";
                    220: }
                    221:
                    222: # get actual parameters
                    223: $sortby = $input{"sortby"};
                    224: $bydate = 0;
                    225: $byrev = 0;
                    226: $byauthor = 0;
                    227: $bylog = 0;
                    228: $byfile = 0;
                    229: if ($sortby eq "date") {
                    230:     $bydate = 1;
                    231: }
                    232: elsif ($sortby eq "rev") {
                    233:     $byrev = 1;
                    234: }
                    235: elsif ($sortby eq "author") {
                    236:     $byauthor = 1;
                    237: }
                    238: elsif ($sortby eq "log") {
                    239:     $bylog = 1;
                    240: }
                    241: else {
                    242:     $byfile = 1;
                    243: }
                    244:
                    245: $hr_default = $input{'f'} eq 'h';
                    246:
                    247: $logsort = $input{"logsort"};
                    248:
                    249:
                    250: ## Default CVS-Tree
                    251: if (!defined($CVSROOT{$cvstreedefault})) {
                    252:    &fatal("500 Internal Error",
                    253:          "<code>\$cvstreedefault</code> points to a repository "
                    254:          . "not defined in <code>%CVSROOT</code> "
                    255:          . "(edit your configuration file $config)");
                    256: }
                    257: $cvstree = $cvstreedefault;
                    258: $cvsroot = $CVSROOT{"$cvstree"};
                    259:
                    260: # alternate CVS-Tree, configured in cvsweb.conf
                    261: if ($input{'cvsroot'}) {
                    262:     if ($CVSROOT{$input{'cvsroot'}}) {
                    263:        $cvstree = $input{'cvsroot'};
                    264:        $cvsroot = $CVSROOT{"$cvstree"};
                    265:     }
                    266: }
                    267:
                    268: # create icons out of description
                    269: foreach my $k (keys %ICONS) {
                    270:     no strict 'refs';
                    271:     my ($itxt,$ipath,$iwidth,$iheight) = @{$ICONS{$k}};
                    272:     if ($ipath) {
                    273:        $ {"${k}icon"} = "<IMG SRC=\"$ipath\" ALT=\"$itxt\" BORDER=\"0\" WIDTH=\"$iwidth\" HEIGHT=\"$iheight\">";
                    274:     }
                    275:     else {
                    276:        $ {"${k}icon"} = $itxt;
                    277:     }
                    278: }
                    279:
                    280: # Do some special configuration for cvstrees
                    281: do "$config-$cvstree" if (-f "$config-$cvstree");
                    282:
                    283: $fullname = $cvsroot . '/' . $where;
                    284: $mimetype = &getMimeTypeFromSuffix ($fullname);
                    285: $defaultTextPlain = ($mimetype eq "text/plain");
                    286: $defaultViewable = $allow_markup && viewable($mimetype);
                    287:
                    288: # search for GZIP if compression allowed
                    289: # We've to find out if the GZIP-binary exists .. otherwise
                    290: # ge get an Internal Server Error if we try to pipe the
                    291: # output through the nonexistent gzip ..
                    292: # any more elegant ways to prevent this are welcome!
                    293: if ($allow_compress && $maycompress) {
                    294:     foreach (split(/:/, $ENV{PATH})) {
                    295:        if (-x "$_/gzip") {
                    296:            $GZIPBIN = "$_/gzip";
                    297:            last;
                    298:        }
                    299:     }
                    300: }
                    301:
                    302: if (-d $fullname) {
                    303:     #
                    304:     # ensure, that directories always end with (exactly) one '/'
                    305:     # to allow relative URL's. If they're not, make a redirect.
                    306:     ##
                    307:     my $pathinfo = defined($ENV{'PATH_INFO'}) ? $ENV{'PATH_INFO'} : "";
                    308:     if (!($pathinfo =~ m|/$|) || ($pathinfo =~ m |/{2,}$|)) {
                    309:        redirect ($scriptwhere . '/' . $query);
                    310:     }
                    311:     else {
                    312:        $where .= '/';
                    313:        $scriptwhere .= '/';
                    314:     }
                    315: }
                    316:
                    317: if (!-d $cvsroot) {
                    318:     &fatal("500 Internal Error",'$CVSROOT not found!<P>The server on which the CVS tree lives is probably down.  Please try again in a few minutes.');
                    319: }
                    320:
                    321: #
                    322: # See if the module is in our forbidden list.
                    323: #
                    324: $where =~ m:([^/]*):;
                    325: $module = $1;
                    326: if ($module && &forbidden_module($module)) {
                    327:     &fatal("403 Forbidden", "Access to $where forbidden.");
                    328: }
                    329: ##############################
                    330: # View a directory
                    331: ###############################
                    332: elsif (-d $fullname) {
                    333:        my $dh = do {local(*DH);};
                    334:        opendir($dh, $fullname) || &fatal("404 Not Found","$where: $!");
                    335:        my @dir = readdir($dh);
                    336:        closedir($dh);
                    337:        my @subLevelFiles = findLastModifiedSubdirs(@dir)
                    338:            if ($show_subdir_lastmod);
                    339:        getDirLogs($cvsroot,$where,@subLevelFiles);
                    340:
                    341:        if ($where eq '/') {
                    342:            html_header("$defaulttitle");
                    343:            print $long_intro;
                    344:        }
                    345:        else {
                    346:            html_header("$where");
                    347:            print $short_instruction;
                    348:        }
                    349:
                    350:        print "<P><a name=\"dirlist\">\n";
                    351:        # give direct access to dirs
                    352:        if ($where eq '/') {
                    353:            chooseMirror();
                    354:            chooseCVSRoot();
                    355:        }
                    356:        else {
                    357:            print "<p>Current directory: <b>", &clickablePath($where,0), "</b>\n";
                    358:
                    359:            print "<P>Current tag: <B>", $input{only_with_tag}, "</b>\n" if
                    360:                $input{only_with_tag};
                    361:
                    362:        }
                    363:
                    364:
                    365:        print "<P><HR NOSHADE>\n";
                    366:        # Using <MENU> in this manner violates the HTML2.0 spec but
                    367:        # provides the results that I want in most browsers.  Another
                    368:        # case of layout spooging up HTML.
                    369:
                    370:        my $infocols = 0;
                    371:        if ($dirtable) {
                    372:            if (defined($tableBorderColor)) {
                    373:                # Can't this be done by defining the border for the inner table?
                    374:                print "<table border=0 cellpadding=0 width=\"100%\"><tr><td bgcolor=\"$tableBorderColor\">";
                    375:            }
                    376:            print "<table  width=\"100%\" border=0 cellspacing=1 cellpadding=$tablepadding>\n";
                    377:            $infocols++;
                    378:            print "<tr><th align=left bgcolor=" . (($byfile) ?
                    379:                                                   $columnHeaderColorSorted :
                    380:                                                   $columnHeaderColorDefault) . ">";
                    381:            print "<a href=\"./" . &toggleQuery("sortby","file") .
                    382:                "#dirlist\">" if (!$byfile);
                    383:            print "File";
                    384:            print "</a>" if (!$byfile);
                    385:            print "</th>";
                    386:            # do not display the other column-headers, if we do not have any files
                    387:            # with revision information:
                    388:            if (scalar(%fileinfo)) {
                    389:                $infocols++;
                    390:                print "<th align=left bgcolor=" . (($byrev) ?
                    391:                                                   $columnHeaderColorSorted :
                    392:                                                   $columnHeaderColorDefault) . ">";
                    393:                print "<a href=\"./" . &toggleQuery ("sortby","rev") .
                    394:                    "#dirlist\">" if (!$byrev);
                    395:                print "Rev.";
                    396:                print "</a>" if (!$byrev);
                    397:                print "</th>";
                    398:                $infocols++;
                    399:                print "<th align=left bgcolor=" . (($bydate) ?
                    400:                                                   $columnHeaderColorSorted :
                    401:                                                   $columnHeaderColorDefault) . ">";
                    402:                print "<a href=\"./" . &toggleQuery ("sortby","date") .
                    403:                    "#dirlist\">" if (!$bydate);
                    404:                print "Age";
                    405:                print "</a>" if (!$bydate);
                    406:                print "</th>";
                    407:                if ($show_author) {
                    408:                    $infocols++;
                    409:                    print "<th align=left bgcolor=" . (($byauthor) ?
                    410:                                                   $columnHeaderColorSorted :
                    411:                                                   $columnHeaderColorDefault) . ">";
                    412:                    print "<a href=\"./" . &toggleQuery ("sortby","author") .
                    413:                            "#dirlist\">" if (!$byauthor);
                    414:                    print "Author";
                    415:                    print "</a>" if (!$byauthor);
                    416:                    print "</th>";
                    417:                }
                    418:                $infocols++;
                    419:                print "<th align=left bgcolor=" . (($bylog) ?
                    420:                                               $columnHeaderColorSorted :
                    421:                                               $columnHeaderColorDefault) . ">";
                    422:                print "<a href=\"./", toggleQuery("sortby","log"), "#dirlist\">" if (!$bylog);
                    423:                print "Last log entry";
                    424:                print "</a>" if (!$bylog);
                    425:                print "</th>";
                    426:            }
                    427:            print "</tr>\n";
                    428:        }
                    429:        else {
                    430:            print "<menu>\n";
                    431:        }
                    432:        my $dirrow = 0;
                    433:
                    434:        my $i;
                    435:        lookingforattic:
                    436:        for ($i = 0; $i <= $#dir; $i++) {
                    437:                if ($dir[$i] eq "Attic") {
                    438:                    last lookingforattic;
                    439:                }
                    440:        }
                    441:        if (!$input{'hideattic'} && ($i <= $#dir) &&
                    442:            opendir($dh, $fullname . "/Attic")) {
                    443:            splice(@dir, $i, 1,
                    444:                        grep((s|^|Attic/|,!m|/\.|), readdir($dh)));
                    445:            closedir($dh);
                    446:        }
                    447:
                    448:        my $hideAtticToggleLink = "<a href=\"./" .
                    449:                &toggleQuery ("hideattic") .
                    450:                "#dirlist\">[Hide]</a>" if (!$input{'hideattic'});
                    451:
                    452:        # Sort without the Attic/ pathname.
                    453:        # place directories first
                    454:
                    455:        my $attic;
                    456:        my $url;
                    457:        my $fileurl;
                    458:        my $filesexists;
                    459:        my $filesfound;
                    460:
                    461:        foreach (sort { &fileSortCmp } @dir) {
                    462:            if ($_ eq '.') {
                    463:                next;
                    464:            }
                    465:            # ignore CVS lock and stale NFS files
                    466:            next if (/^#cvs\.|^,|^\.nfs/);
                    467:
                    468:            # Check whether to show the CVSROOT path
                    469:            next if ($input{'hidecvsroot'} && ($_ eq 'CVSROOT'));
                    470:
                    471:            # Check whether the module is in the restricted list
                    472:            next if ($_ && &forbidden_module($_));
                    473:
                    474:            # Ignore non-readable files
                    475:            next if ($input{'hidenonreadable'} && !(-r "$fullname/$_"));
                    476:
                    477:            if (s|^Attic/||) {
                    478:                $attic  = " (in the Attic)&nbsp;" . $hideAtticToggleLink;
                    479:            }
                    480:            else {
                    481:                $attic = "";
                    482:            }
                    483:
                    484:            if ($_ eq '..' || -d "$fullname/$_") {
                    485:                next if ($_ eq '..' && $where eq '/');
                    486:                my ($rev,$date,$log,$author,$filename) = @{$fileinfo{$_}}
                    487:                    if (defined($fileinfo{$_}));
                    488:                print "<tr bgcolor=\"" . @tabcolors[$dirrow%2] . "\"><td>" if ($dirtable);
                    489:                if ($_ eq '..') {
                    490:                    $url = "../" . $query;
                    491:                    if ($nofilelinks) {
                    492:                        print $backicon;
                    493:                    }
                    494:                    else {
                    495:                        print &link($backicon,$url);
                    496:                    }
                    497:                    print " ", &link("Previous Directory",$url);
                    498:                }
                    499:                else {
                    500:                    $url = urlencode($_) . '/' . $query;
                    501:                    print "<A NAME=\"$_\">";
                    502:                    if ($nofilelinks) {
                    503:                        print $diricon;
                    504:                    }
                    505:                    else {
                    506:                        print &link($diricon,$url);
                    507:                    }
                    508:                    print " ", &link($_ . "/", $url), $attic;
                    509:                    if ($_ eq "Attic") {
                    510:                        print "&nbsp; <a href=\"./" .
                    511:                            &toggleQuery ("hideattic") .
                    512:                                "#dirlist\">[Don't hide]</a>";
                    513:                    }
                    514:                }
                    515:                # Show last change in dir
                    516:                if ($filename) {
                    517:                    print "</td><td>&nbsp</td><td>&nbsp;" if ($dirtable);
                    518:                    if ($date) {
                    519:                        print " <i>" . readableTime(time() - $date,0) . "</i>";
                    520:                    }
                    521:                    if ($show_author) {
                    522:                        print "</td><td>&nbsp;" if ($dirtable);
                    523:                        print $author;
                    524:                    }
                    525:                    print "</td><td>&nbsp;" if ($dirtable);
                    526:                    $filename =~ s%^[^/]+/%%;
                    527:                    print "$filename/$rev";
                    528:                    print "<BR>" if ($dirtable);
                    529:                    if ($log) {
                    530:                        print "&nbsp;<font size=-1>"
                    531:                            . &htmlify(substr($log,0,$shortLogLen));
                    532:                        if (length $log > 80) {
                    533:                            print "...";
                    534:                        }
                    535:                        print "</font>";
                    536:                    }
                    537:                }
                    538:                else {
                    539:                    # if there are any files (which require infocols), close the
                    540:                    # row with the appropriate number of columns, so that the
                    541:                    # vertical seperators are visible
                    542:                    if ($dirtable && scalar(%fileinfo)) {
                    543:                        print "</td>";
                    544:                        my($cols) = $infocols;
                    545:                        while ($cols > 1) {
                    546:                            print "<td>&nbsp;</td>";
                    547:                            $cols--;
                    548:                        }
                    549:                    }
                    550:                }
                    551:                if ($dirtable) {
                    552:                    print "</td></tr>\n";
                    553:                }
                    554:                else {
                    555:                    print "<br>\n";
                    556:                }
                    557:                $dirrow++;
                    558:            }
                    559:            elsif (s/,v$//) {
                    560:                $fileurl = ($attic ? "Attic/" : "") . urlencode($_);
                    561:                $url = $fileurl . $query;
                    562:                my $rev = '';
                    563:                my $date = '';
                    564:                my $log = '';
                    565:                my $author = '';
                    566:                $filesexists++;
                    567:                next if (!defined($fileinfo{$_}));
                    568:                ($rev,$date,$log,$author) = @{$fileinfo{$_}};
                    569:                $filesfound++;
                    570:                print "<tr bgcolor=\"" . @tabcolors[$dirrow%2] . "\"><td>" if ($dirtable);
                    571:                print "<A NAME=\"$_\">";
                    572:                if ($nofilelinks) {
                    573:                    print $fileicon;
                    574:                }
                    575:                else {
                    576:                    print &link($fileicon,$url);
                    577:                }
                    578:                print " ", &link($_, $url), $attic;
                    579:                print "</td><td>&nbsp;" if ($dirtable);
                    580:                download_link($fileurl,
                    581:                        $rev, $rev,
                    582:                        $defaultViewable ? "text/x-cvsweb-markup" : undef);
                    583:                print "</td><td>&nbsp;" if ($dirtable);
                    584:                if ($date) {
                    585:                    print " <i>" . readableTime(time() - $date,0) . "</i>";
                    586:                }
                    587:                if ($show_author) {
                    588:                    print "</td><td>&nbsp;" if ($dirtable);
                    589:                    print $author;
                    590:                }
                    591:                print "</td><td>&nbsp;" if ($dirtable);
                    592:                if ($log) {
                    593:                    print " <font size=-1>" . &htmlify(substr($log,0,$shortLogLen));
                    594:                    if (length $log > 80) {
                    595:                        print "...";
                    596:                    }
                    597:                    print "</font>";
                    598:                }
                    599:                print "</td>" if ($dirtable);
                    600:                print (($dirtable) ? "</tr>" : "<br>");
                    601:                $dirrow++;
                    602:            }
                    603:            print "\n";
                    604:        }
                    605:        if ($dirtable && defined($tableBorderColor)) {
                    606:            print "</td></tr></table>";
                    607:        }
                    608:        print "". ($dirtable == 1) ? "</table>" : "</menu>" . "\n";
                    609:
                    610:        if ($filesexists && !$filesfound) {
                    611:            print "<P><B>NOTE:</B> There are $filesexists files, but none matches the current tag ($input{only_with_tag})\n";
                    612:        }
                    613:        if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
                    614:            %tags = %alltags
                    615:        }
                    616:        if (scalar %tags
                    617:            || $input{only_with_tag}
                    618:            || $edit_option_form
                    619:            || defined($input{"options"})) {
                    620:            print "<hr size=1 NOSHADE>";
                    621:        }
                    622:
                    623:        if (scalar %tags || $input{only_with_tag}) {
                    624:            print "<FORM METHOD=\"GET\" ACTION=\"./\">\n";
                    625:            foreach my $var (@stickyvars) {
                    626:                print "<INPUT TYPE=HIDDEN NAME=\"$var\" VALUE=\"$input{$var}\">\n"
                    627:                    if (defined($input{$var})
                    628:                        && $input{$var} ne $DEFAULTVALUE{$var}
                    629:                        && $input{$var} ne ""
                    630:                        && $var ne "only_with_tag");
                    631:            }
                    632:            print "Show only files with tag:\n";
                    633:            print "<SELECT NAME=only_with_tag";
                    634:            print " onchange=\"submit()\"" if ($use_java_script);
                    635:            print ">";
                    636:            print "<OPTION VALUE=\"\">All tags / default branch\n";
                    637:            foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
                    638:                print "<OPTION",defined($input{only_with_tag}) &&
                    639:                       $input{only_with_tag} eq $tag ? " SELECTED":"",
                    640:                       ">$tag\n";
                    641:            }
                    642:            print "</SELECT>\n";
                    643:            print "<INPUT TYPE=SUBMIT VALUE=\"Go\">\n";
                    644:            print "</FORM>\n";
                    645:        }
                    646:        my $formwhere = $scriptwhere;
                    647:        $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
                    648:
                    649:        if ($edit_option_form || defined($input{"options"})) {
                    650:            print "<FORM METHOD=\"GET\" ACTION=\"${formwhere}\">\n";
                    651:            print "<INPUT TYPE=HIDDEN NAME=\"copt\" VALUE=\"1\">\n";
                    652:            if ($cvstree ne $cvstreedefault) {
                    653:                print "<INPUT TYPE=HIDDEN NAME=\"cvsroot\" VALUE=\"$cvstree\">\n";
                    654:            }
                    655:            print "<center><table cellpadding=0 cellspacing=0>";
                    656:            print "<tr bgcolor=\"$columnHeaderColorDefault\"><th colspan=2>Preferences</th></tr>";
                    657:            print "<tr><td>Sort files by <SELECT name=\"sortby\">";
                    658:            print "<OPTION VALUE=\"\">File";
                    659:            print "<OPTION",$bydate ? " SELECTED" : ""," VALUE=date>Age";
                    660:            print "<OPTION",$byauthor ? " SELECTED" : ""," VALUE=author>Author"
                    661:                if ($show_author);
                    662:            print "<OPTION",$byrev ? " SELECTED" : ""," VALUE=rev>Revision";
                    663:            print "<OPTION",$bylog ? " SELECTED" : ""," VALUE=log>Log message";
                    664:            print "</SELECT></td>";
                    665:            print "<td>revisions by: \n";
                    666:            print "<SELECT NAME=logsort>\n";
                    667:            print "<OPTION VALUE=cvs",$logsort eq "cvs" ? " SELECTED" : "", ">Not sorted";
                    668:            print "<OPTION VALUE=date",$logsort eq "date" ? " SELECTED" : "", ">Commit date";
                    669:            print "<OPTION VALUE=rev",$logsort eq "rev" ? " SELECTED" : "", ">Revision";
                    670:            print "</SELECT></td></tr>";
                    671:            print "<tr><td>Diff format: ";
                    672:            printDiffSelect();
                    673:            print "</td>";
                    674:            print "<td>Show Attic files: ";
                    675:            print "<INPUT NAME=hideattic TYPE=CHECKBOX", $input{'hideattic'}?" CHECKED":"",
                    676:            "></td></tr>\n";
                    677:            print "<tr><td align=center colspan=2><input type=submit value=\"Change Options\">";
                    678:            print "</td></tr></table></center></FORM>\n";
                    679:        }
                    680:        print &html_footer;
                    681:        print "</BODY></HTML>\n";
                    682:     }
                    683:
                    684: ###############################
                    685: # View Files
                    686: ###############################
                    687:     elsif (-f $fullname . ',v') {
                    688:        if (defined($input{'rev'}) || $doCheckout) {
                    689:            &doCheckout($fullname, $input{'rev'});
                    690:            exit;
                    691:        }
                    692:        if (defined($input{'annotate'}) && $allow_annotate) {
                    693:            &doAnnotate($input{'annotate'});
                    694:            exit;
                    695:        }
                    696:        if (defined($input{'r1'}) && defined($input{'r2'})) {
                    697:            &doDiff($fullname, $input{'r1'}, $input{'tr1'},
                    698:                    $input{'r2'}, $input{'tr2'}, $input{'f'});
                    699:            exit;
                    700:        }
                    701:        print("going to dolog($fullname)\n") if ($verbose);
                    702:        &doLog($fullname);
                    703: ##############################
                    704: # View Diff
                    705: ##############################
                    706:     }
                    707:     elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" &&
                    708:           $input{'r1'} && $input{'r2'}) {
                    709:
                    710:        # $where-diff-removal if 'cvs rdiff' is used
                    711:        # .. but 'cvs rdiff'doesn't support some options
                    712:        # rcsdiff does (-w and -p), so it is disabled
                    713:        # $where =~ s/\.diff$//;
                    714:
                    715:        # Allow diffs using the ".diff" extension
                    716:        # so that browsers that default to the URL
                    717:        # for a save filename don't save diff's as
                    718:        # e.g. foo.c
                    719:        &doDiff($fullname, $input{'r1'}, $input{'tr1'},
                    720:                $input{'r2'}, $input{'tr2'}, $input{'f'});
                    721:        exit;
                    722:     }
                    723:     elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| &&
                    724:           -f $newname . ",v") {
                    725:        # The file has been removed and is in the Attic.
                    726:        # Send a redirect pointing to the file in the Attic.
                    727:        (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
                    728:        &redirect($newplace);
                    729:        exit;
                    730:     }
                    731:     elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
                    732:        http_header("text/plain");
                    733:        print "You matched the following files:\n";
                    734:        print join("\n", @files);
                    735:        # Find the tags from each file
                    736:        # Display a form offering diffs between said tags
                    737:     }
                    738:     else {
                    739:        my $fh = do {local(*FH);};
                    740:        my ($xtra, $module);
                    741:        # Assume it's a module name with a potential path following it.
                    742:        $xtra = $& if (($module = $where) =~ s|/.*||);
                    743:        # Is there an indexed version of modules?
                    744:        if (open($fh, "$cvsroot/CVSROOT/modules")) {
                    745:            while (<$fh>) {
                    746:                if (/^(\S+)\s+(\S+)/o && $module eq $1
                    747:                    && -d "${cvsroot}/$2" && $module ne $2) {
                    748:                    &redirect($scriptname . '/' . $2 . $xtra);
                    749:                }
                    750:            }
                    751:        }
                    752:        &fatal("404 Not Found","$where: no such file or directory");
                    753:     }
                    754: ## End MAIN
                    755:
                    756: sub printDiffSelect {
                    757:     my ($use_java_script) = @_;
                    758:     $use_java_script = 0 if (!defined($use_java_script));
                    759:     my ($f) = $input{'f'};
                    760:     print "<SELECT NAME=\"f\"";
                    761:     print " onchange=\"submit()\"" if ($use_java_script);
                    762:     print ">\n";
                    763:     print "<OPTION VALUE=h",$f eq "h" ? " SELECTED" : "", ">Colored Diff";
                    764:     print "<OPTION VALUE=H",$f eq "H" ? " SELECTED" : "", ">Long Colored Diff";
                    765:     print "<OPTION VALUE=u",$f eq "u" ? " SELECTED" : "", ">Unidiff";
                    766:     print "<OPTION VALUE=c",$f eq "c" ? " SELECTED" : "", ">Context Diff";
                    767:     print "<OPTION VALUE=s",$f eq "s" ? " SELECTED" : "", ">Side by Side";
                    768:     print "</SELECT>";
                    769: }
                    770:
                    771: sub findLastModifiedSubdirs {
                    772:     my (@dirs) = @_;
                    773:     my ($dirname, @files);
                    774:
                    775:     foreach $dirname (@dirs) {
                    776:        next if ($dirname eq ".");
                    777:        next if ($dirname eq "..");
                    778:        my ($dir) = "$fullname/$dirname";
                    779:        next if (!-d $dir);
                    780:
                    781:        my ($lastmod) = undef;
                    782:        my ($lastmodtime) = undef;
                    783:        my $dh = do {local(*DH);};
                    784:
                    785:        opendir($dh,$dir) || next;
                    786:        my (@filenames) = readdir($dh);
                    787:        closedir($dh);
                    788:
                    789:        foreach my $filename (@filenames) {
                    790:            $filename = "$dirname/$filename";
                    791:            my ($file) = "$fullname/$filename";
                    792:            next if ($filename !~ /,v$/ || !-f $file);
                    793:            $filename =~ s/,v$//;
                    794:            my $modtime = -M $file;
                    795:            if (!defined($lastmod) || $modtime < $lastmodtime) {
                    796:                $lastmod = $filename;
                    797:                $lastmodtime = $modtime;
                    798:            }
                    799:        }
                    800:        push(@files, $lastmod) if (defined($lastmod));
                    801:     }
                    802:     return @files;
                    803: }
                    804:
                    805: sub htmlify {
                    806:        my($string, $pr) = @_;
                    807:
                    808:        # Special Characters; RFC 1866
                    809:        $string =~ s/&/&amp;/g;
                    810:        $string =~ s/\"/&quot;/g;
                    811:        $string =~ s/</&lt;/g;
                    812:        $string =~ s/>/&gt;/g;
                    813:
                    814:        # get URL's as link ..
                    815:        $string =~ s§(http|ftp)(://[-a-zA-Z0-9%.~:_/]+)([?&]([-a-zA-Z0-9%.~:_]+)=([-a-zA-Z0-9%.~:_])+)*§<A HREF="$1$2$3">$1$2$3</A>§;
                    816:        # get e-mails as link
                    817:        $string =~ s§([-a-zA-Z0-9_.]+@([-a-zA-Z0-9]+\.)+[A-Za-z]{2,4})§<A HREF="mailto:$1">$1</A>§;
                    818:
                    819:        # get #PR as link ..
                    820:        if ($pr && defined($prcgi)) {
                    821:            $string =~ s!\b((pr[:#]?\s*#?)|((bin|conf|docs|gnu|i386|kern|misc|ports)\/))(\d+)\b!<A HREF="$prcgi?pr=$5">$&</A>!ig;
                    822:        }
                    823:
                    824:        return $string;
                    825: }
                    826:
                    827: sub spacedHtmlText {
                    828:        my($string, $pr) = @_;
                    829:
                    830:        # Cut trailing spaces
                    831:        s/\s+$//;
                    832:
                    833:        # Expand tabs
                    834:        $string =~ s/\t+/' ' x (length($&) * $tabstop - length($`) % $tabstop)/e
                    835:            if (defined($tabstop));
                    836:
                    837:        # replace <tab> and <space> (§ is to protect us from htmlify)
                    838:        # gzip can make excellent use of this repeating pattern :-)
                    839:        $string =~ s/§/§%/g; #protect our & substitute
                    840:        if ($hr_breakable) {
                    841:            # make every other space 'breakable'
                    842:            $string =~ s/       / §nbsp; §nbsp; §nbsp; §nbsp;/g;    # <tab>
                    843:            $string =~ s/  / §nbsp;/g;                              # 2 * <space>
                    844:            # leave single space as it is
                    845:        }
                    846:        else {
                    847:            $string =~ s/       /§nbsp;§nbsp;§nbsp;§nbsp;§nbsp;§nbsp;§nbsp;§nbsp;/g;
                    848:            $string =~ s/ /§nbsp;/g;
                    849:        }
                    850:
                    851:        $string = htmlify($string);
                    852:
                    853:        # unescape
                    854:        $string =~ s/§([^%])/&$1/g;
                    855:        $string =~ s/§%/§/g;
                    856:
                    857:        return $string;
                    858: }
                    859:
                    860: sub link {
                    861:        my($name, $where) = @_;
                    862:
                    863:        return "<A HREF=\"$where\">$name</A>\n";
                    864: }
                    865:
                    866: sub revcmp {
                    867:        my($rev1, $rev2) = @_;
                    868:        my(@r1) = split(/\./, $rev1);
                    869:        my(@r2) = split(/\./, $rev2);
                    870:        my($a,$b);
                    871:
                    872:        while (($a = shift(@r1)) && ($b = shift(@r2))) {
                    873:            if ($a != $b) {
                    874:                return $a <=> $b;
                    875:            }
                    876:        }
                    877:        if (@r1) { return 1; }
                    878:        if (@r2) { return -1; }
                    879:        return 0;
                    880: }
                    881:
                    882: sub fatal {
                    883:        my($errcode, $errmsg) = @_;
                    884:        if (defined($ENV{'MOD_PERL'})) {
                    885:                Apache->request->status((split(/ /, $errcode))[0]);
                    886:        }
                    887:        else {
                    888:                print "Status: $errcode\n";
                    889:        }
                    890:        html_header("Error");
                    891:        print "Error: $errmsg\n";
                    892:        print &html_footer;
                    893:        exit(1);
                    894: }
                    895:
                    896: sub redirect {
                    897:        my($url) = @_;
                    898:        if (defined($ENV{'MOD_PERL'})) {
                    899:                Apache->request->status(301);
                    900:                Apache->request->header_out(Location => $url);
                    901:        }
                    902:        else {
                    903:                print "Status: 301 Moved\n";
                    904:                print "Location: $url\n";
                    905:        }
                    906:        html_header("Moved");
                    907:        print "This document is located <A HREF=$url>here</A>.\n";
                    908:        print &html_footer;
                    909:        exit(1);
                    910: }
                    911:
                    912: sub safeglob {
                    913:        my ($filename) = @_;
                    914:        my ($dirname);
                    915:        my (@results);
                    916:        my $dh = do {local(*DH);};
                    917:
                    918:        ($dirname = $filename) =~ s|/[^/]+$||;
                    919:        $filename =~ s|.*/||;
                    920:
                    921:        if (opendir($dh, $dirname)) {
                    922:                my $glob = $filename;
                    923:                my $t;
                    924:        #       transform filename from glob to regex.  Deal with:
                    925:        #       [, {, ?, * as glob chars
                    926:        #       make sure to escape all other regex chars
                    927:                $glob =~ s/([\.\(\)\|\+])/\\$1/g;
                    928:                $glob =~ s/\*/.*/g;
                    929:                $glob =~ s/\?/./g;
                    930:                $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
                    931:                foreach (readdir($dh)) {
                    932:                        if (/^${glob}$/) {
                    933:                                push(@results, $dirname . "/" .$_);
                    934:                        }
                    935:                }
                    936:        }
                    937:
                    938:        @results;
                    939: }
                    940:
                    941: sub getMimeTypeFromSuffix {
                    942:     my ($fullname) = @_;
                    943:     my ($mimetype, $suffix);
                    944:     my $fh = do {local(*FH);};
                    945:
                    946:     ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
                    947:     $mimetype = $MTYPES{$suffix};
                    948:     $mimetype = $MTYPES{'*'} if (!$mimetype);
                    949:
                    950:     if (!$mimetype && -f $mime_types) {
                    951:        # okey, this is something special - search the
                    952:        # mime.types database
                    953:        open ($fh, "<$mime_types");
                    954:        while (<$fh>) {
                    955:            if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
                    956:                $mimetype = $1;
                    957:                last;
                    958:            }
                    959:        }
                    960:        close ($fh);
                    961:     }
                    962:
                    963: # okey, didn't find anything useful ..
                    964:     if (!($mimetype =~ /\S\/\S/)) {
                    965:        $mimetype = "text/plain";
                    966:     }
                    967:     return $mimetype;
                    968: }
                    969:
                    970: ###############################
                    971: # show Annotation
                    972: ###############################
                    973: sub doAnnotate ($$) {
                    974:     my ($rev) = @_;
                    975:     my ($pid);
                    976:     my ($pathname, $filename);
                    977:     my $reader = do {local(*FH);};
                    978:     my $writer = do {local(*FH);};
                    979:
                    980:     # make sure the revisions a wellformed, for security
                    981:     # reasons ..
                    982:     if (!($rev =~ /^[\d\.]+$/)) {
                    983:        &fatal("404 Not Found",
                    984:                "Malformed query \"$ENV{'QUERY_STRING'}\"");
                    985:     }
                    986:
                    987:     ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
                    988:     ($filename = $where) =~ s/^.*\///;
                    989:
                    990:     http_header();
                    991:
                    992:     navigateHeader ($scriptwhere,$pathname,$filename,$rev, "annotate");
                    993:     print "<h3 align=center>Annotation of $pathname$filename, Revision $rev</h3>\n";
                    994:
                    995:     # this seems to be necessary
                    996:     $| = 1; $| = 0; # Flush
                    997:
                    998:     # this annotate version is based on the
                    999:     # cvs annotate-demo Perl script by Cyclic Software
                   1000:     # It was written by Cyclic Software, http://www.cyclic.com/, and is in
                   1001:     # the public domain.
                   1002:     # we could abandon the use of rlog, rcsdiff and co using
                   1003:     # the cvsserver in a similiar way one day (..after rewrite)
                   1004:     $pid = open2($reader, $writer, "cvs server") || fatal ("500 Internal Error",
                   1005:                                                               "Fatal Error - unable to open cvs for annotation");
                   1006:
                   1007:     # OK, first send the request to the server.  A simplified example is:
                   1008:     #     Root /home/kingdon/zwork/cvsroot
                   1009:     #     Argument foo/xx
                   1010:     #     Directory foo
                   1011:     #     /home/kingdon/zwork/cvsroot/foo
                   1012:     #     Directory .
                   1013:     #     /home/kingdon/zwork/cvsroot
                   1014:     #     annotate
                   1015:     # although as you can see there are a few more details.
                   1016:
                   1017:     print $writer "Root $cvsroot\n";
                   1018:     print $writer "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
                   1019:     # Don't worry about sending valid-requests, the server just needs to
                   1020:     # support "annotate" and if it doesn't, there isn't anything to be done.
                   1021:     print $writer "UseUnchanged\n";
                   1022:     print $writer "Argument -r\n";
                   1023:     print $writer "Argument $rev\n";
                   1024:     print $writer "Argument $where\n";
                   1025:
                   1026:     # The protocol requires us to fully fake a working directory (at
                   1027:     # least to the point of including the directories down to the one
                   1028:     # containing the file in question).
                   1029:     # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
                   1030:     my @dirs = split (/\//, $where);
                   1031:     my $path = "";
                   1032:     foreach (@dirs) {
                   1033:        if ($path eq "") {
                   1034:            # In our example, $_ is "dir".
                   1035:            $path = $_;
                   1036:        }
                   1037:        else {
                   1038:            print $writer "Directory " . $path . "\n";
                   1039:            print $writer "$cvsroot/" . $path ."\n";
                   1040:            # In our example, $_ is "sdir" and $path becomes "dir/sdir"
                   1041:            # And the next time, "file" and "dir/sdir/file" (which then gets
                   1042:            # ignored, because we don't need to send Directory for the file).
                   1043:             $path = $path . "/" . $_;
                   1044:        }
                   1045:     }
                   1046:     # And the last "Directory" before "annotate" is the top level.
                   1047:     print $writer "Directory .\n";
                   1048:     print $writer "$cvsroot\n";
                   1049:
                   1050:     print $writer "annotate\n";
                   1051:     # OK, we've sent our command to the server.  Thing to do is to
                   1052:     # close the writer side and get all the responses.  If "cvs server"
                   1053:     # were nicer about buffering, then we could just leave it open, I think.
                   1054:     close ($writer) || die "cannot close: $!";
                   1055:
                   1056:     # Ready to get the responses from the server.
                   1057:     # For example:
                   1058:     #     E Annotations for foo/xx
                   1059:     #     E ***************
                   1060:     #     M 1.3          (kingdon  06-Sep-97): hello
                   1061:     #     ok
                   1062:     my ($lineNr) = 0;
                   1063:     my ($oldLrev, $oldLusr) = ("", "");
                   1064:     my ($revprint, $usrprint);
                   1065:     if ($annTable) {
                   1066:        print "<table border=0 cellspacing=0 cellpadding=0>\n";
                   1067:     }
                   1068:     else {
                   1069:        print "<pre>";
                   1070:     }
                   1071:     while (<$reader>) {
                   1072:        my @words = split;
                   1073:        # Adding one is for the (single) space which follows $words[0].
                   1074:        my $rest = substr ($_, length ($words[0]) + 1);
                   1075:        if ($words[0] eq "E") {
                   1076:            next;
                   1077:        }
                   1078:        elsif ($words[0] eq "M") {
                   1079:            $lineNr++;
                   1080:            my $lrev = substr ($_, 2, 13);
                   1081:            my $lusr = substr ($_, 16,  9);
                   1082:            my $line = substr ($_, 36);
                   1083:            # we should parse the date here ..
                   1084:            if ($lrev eq $oldLrev) {
                   1085:                $revprint = "             ";
                   1086:            }
                   1087:            else {
                   1088:                $revprint = $lrev; $oldLusr = "";
                   1089:            }
                   1090:            if ($lusr eq $oldLusr) {
                   1091:                $usrprint = "         ";
                   1092:            }
                   1093:            else {
                   1094:                $usrprint = $lusr;
                   1095:            }
                   1096:            $oldLrev = $lrev;
                   1097:            $oldLusr = $lusr;
                   1098:            # is there a less timeconsuming way to strip spaces ?
                   1099:            ($lrev = $lrev) =~ s/\s+//g;
                   1100:            my $isCurrentRev = ("$rev" eq "$lrev");
                   1101:
                   1102:            print "<b>" if ($isCurrentRev);
                   1103:            printf ("%8s%s%8s %4d:", $revprint, ($isCurrentRev ? "|" : " "), $usrprint, $lineNr);
                   1104:            print spacedHtmlText($line);
                   1105:            print "</b>" if ($isCurrentRev);
                   1106:        }
                   1107:        elsif ($words[0] eq "ok") {
                   1108:            # We could complain about any text received after this, like the
                   1109:            # CVS command line client.  But for simplicity, we don't.
                   1110:        }
                   1111:        elsif ($words[0] eq "error") {
                   1112:            fatal ("500 Internal Error", "Error occured during annotate: <b>$_</b>");
                   1113:        }
                   1114:     }
                   1115:     if ($annTable) {
                   1116:        print "</table>";
                   1117:     }
                   1118:     else {
                   1119:        print "</pre>";
                   1120:     }
                   1121:     close ($reader) || warn "cannot close: $!";
                   1122:     wait;
                   1123: }
                   1124:
                   1125: ###############################
                   1126: # make Checkout
                   1127: ###############################
                   1128: sub doCheckout {
                   1129:     my ($fullname, $rev) = @_;
                   1130:     my ($mimetype,$revopt);
                   1131:     my $fh = do {local(*FH);};
                   1132:
                   1133:     # make sure the revisions a wellformed, for security
                   1134:     # reasons ..
                   1135:     if (defined($rev) && !($rev =~ /^[\d\.]+$/)) {
                   1136:        &fatal("404 Not Found",
                   1137:                "Malformed query \"$ENV{'QUERY_STRING'}\"");
                   1138:     }
                   1139:
                   1140:     # get mimetype
                   1141:     if (defined($input{"content-type"}) && ($input{"content-type"} =~ /\S\/\S/)) {
                   1142:        $mimetype = $input{"content-type"}
                   1143:     }
                   1144:     else {
                   1145:        $mimetype = &getMimeTypeFromSuffix($fullname);
                   1146:     }
                   1147:
                   1148:     if (defined($rev)) {
                   1149:        $revopt = "-r'$rev'";
                   1150:     }
                   1151:     else {
                   1152:        $revopt = "";
                   1153:     }
                   1154:
                   1155:     # this may not be quoted with single quotes
                   1156:     # in windows .. but should in U*nx. there
                   1157:     # is a function which allows for quoting `evil`
                   1158:     # characters somewhere, I know (buried in the Perl-manpage)
                   1159:     ##
                   1160:     ### just for the record:
                   1161:     ### 'cvs co' seems to have a bug regarding single checkout of
                   1162:     ### directories/files having spaces in it;
                   1163:     ### this is an issue that should be resolved on cvs's side
                   1164:     open($fh, "cvs -d'$cvsroot' co -p $revopt '$where' 2>&1 |") ||
                   1165:        &fatal("500 Internal Error", "Couldn't co: $!");
                   1166: #===================================================================
                   1167: #Checking out squid/src/ftp.c
                   1168: #RCS:  /usr/src/CVS/squid/src/ftp.c,v
                   1169: #VERS: 1.1.1.28.6.2
                   1170: #***************
                   1171:
                   1172:     # Parse CVS header
                   1173:     my ($revision, $filename, $cvsheader);
                   1174:     while(<$fh>) {
                   1175:        last if (/^\*\*\*\*/);
                   1176:        $revision = $1 if (/^VERS: (.*)$/);
                   1177:        $filename = $1 if (/^Checking out (.*)$/);
                   1178:        $cvsheader .= $_;
                   1179:     }
                   1180:     if ($filename ne $where) {
                   1181:        &fatal("500 Internal Error",
                   1182:               "Unexpected output from cvs co: $cvsheader"
                   1183:               . "<p><b>Check whether the directory $cvsroot/CVSROOT exists "
                   1184:               . "and the script has write-access to the CVSROOT/history "
                   1185:               . "file if it exists."
                   1186:               . "<br>The script needs to place lock files in the "
                   1187:               . "directory the file is in as well.</b>");
                   1188:     }
                   1189:     $| = 1;
                   1190:
                   1191:     if ($mimetype eq "text/x-cvsweb-markup") {
                   1192:        &cvswebMarkup($fh,$fullname,$revision);
                   1193:     }
                   1194:     else {
                   1195:        http_header($mimetype);
                   1196:        print <$fh>;
                   1197:     }
                   1198:     close($fh);
                   1199: }
                   1200:
                   1201: sub cvswebMarkup {
                   1202:     my ($filehandle,$fullname,$revision) = @_;
                   1203:     my ($pathname, $filename);
                   1204:
                   1205:     ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
                   1206:     ($filename = $where) =~ s/^.*\///;
                   1207:     my ($fileurl) = urlencode($filename);
                   1208:
                   1209:     http_header();
                   1210:
                   1211:     navigateHeader ($scriptwhere, $pathname, $filename, $revision, "view");
                   1212:     print "<HR noshade>";
                   1213:     print "<table width=\"100%\"><tr><td bgcolor=\"$markupLogColor\">";
                   1214:     print "File: ", &clickablePath($where, 1), "</b>";
                   1215:     print "&nbsp;";
                   1216:     &download_link(urlencode($fileurl), $revision, "(download)");
                   1217:     if (!$defaultTextPlain) {
                   1218:        print "&nbsp;";
                   1219:        &download_link(urlencode($fileurl), $revision, "(as text)",
                   1220:               "text/plain");
                   1221:     }
                   1222:     print "<BR>\n";
                   1223:     if ($show_log_in_markup) {
                   1224:        readLog($fullname); #,$revision);
                   1225:        printLog($revision,0);
                   1226:     }
                   1227:     else {
                   1228:        print "Version: <B>$revision</B><BR>\n";
                   1229:        print "Tag: <B>", $input{only_with_tag}, "</b><br>\n" if
                   1230:            $input{only_with_tag};
                   1231:     }
                   1232:     print "</td></tr></table>";
                   1233:     my @content = <$filehandle>;
                   1234:     my $url = download_url($fileurl, $revision, $mimetype);
                   1235:     print "<HR noshade>";
                   1236:     if ($mimetype =~ /^image/) {
                   1237:        print "<IMG SRC=\"$url$barequery\"><BR>";
                   1238:     }
                   1239:     else {
                   1240:        print "<PRE>";
                   1241:        foreach (@content) {
                   1242:            print htmlify($_);
                   1243:        }
                   1244:        print "</PRE>";
                   1245:     }
                   1246: }
                   1247:
                   1248: sub viewable($) {
                   1249:     my ($mimetype) = @_;
                   1250:
                   1251:     $mimetype =~ m%^text/% ||
                   1252:     $mimetype =~ m%^image/% ||
                   1253:     0;
                   1254: }
                   1255:
                   1256: ###############################
                   1257: # Show Colored Diff
                   1258: ###############################
                   1259: sub doDiff {
                   1260:        my($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
                   1261:         my $fh = do {local(*FH);};
                   1262:        my ($rev1, $rev2, $sym1, $sym2, $difftype, $diffname, $f1, $f2);
                   1263:
                   1264:        if ($r1 =~ /([^:]+)(:(.+))?/) {
                   1265:            $rev1 = $1;
                   1266:            $sym1 = $3;
                   1267:        }
                   1268:        if ($r1 eq 'text') {
                   1269:            $rev1 = $tr1;
                   1270:            $sym1 = "";
                   1271:        }
                   1272:        if ($r2 =~ /([^:]+)(:(.+))?/) {
                   1273:            $rev2 = $1;
                   1274:            $sym2 = $3;
                   1275:        }
                   1276:        if ($r2 eq 'text') {
                   1277:            $rev2 = $tr2;
                   1278:            $sym2 = "";
                   1279:        }
                   1280:        # make sure the revisions a wellformed, for security
                   1281:        # reasons ..
                   1282:        if (!($rev1 =~ /^[\d\.]+$/) || !($rev2 =~ /^[\d\.]+$/)) {
                   1283:            &fatal("404 Not Found",
                   1284:                    "Malformed query \"$ENV{'QUERY_STRING'}\"");
                   1285:        }
                   1286: #
                   1287: # rev1 and rev2 are now both numeric revisions.
                   1288: # Thus we do a DWIM here and swap them if rev1 is after rev2.
                   1289: # XXX should we warn about the fact that we do this?
                   1290:        if (&revcmp($rev1,$rev2) > 0) {
                   1291:            my ($tmp1, $tmp2) = ($rev1, $sym1);
                   1292:            ($rev1, $sym1) = ($rev2, $sym2);
                   1293:            ($rev2, $sym2) = ($tmp1, $tmp2);
                   1294:        }
                   1295:        my $human_readable = 0;
                   1296:        if ($f eq 'c') {
                   1297:            $difftype = '-c';
                   1298:            $diffname = "Context diff";
                   1299:        }
                   1300:        elsif ($f eq 's') {
                   1301:            $difftype = '--side-by-side --width=164';
                   1302:            $diffname = "Side by Side";
                   1303:        }
                   1304:        elsif ($f eq 'H') {
                   1305:            $human_readable = 1;
                   1306:            $difftype = '--unified=15';
                   1307:            $diffname = "Long Human readable";
                   1308:        }
                   1309:        elsif ($f eq 'h') {
                   1310:            $difftype = '-u';
                   1311:            $human_readable = 1;
                   1312:            $diffname = "Human readable";
                   1313:        }
                   1314:        elsif ($f eq 'u') {
                   1315:            $difftype = '-u';
                   1316:            $diffname = "Unidiff";
                   1317:        }
                   1318:        else {
                   1319:            fatal ("400 Bad arguments", "Diff format $f not understood");
                   1320:        }
                   1321:
                   1322:        # apply special options
                   1323:        if ($human_readable) {
                   1324:            if ($hr_funout) {
                   1325:                $difftype = $difftype . ' -p';
                   1326:            }
                   1327:            if ($hr_ignwhite) {
                   1328:                $difftype = $difftype . ' -w';
                   1329:            }
                   1330:            if ($hr_ignkeysubst) {
                   1331:                $difftype = $difftype . ' -kk';
                   1332:            }
                   1333:        }
                   1334: ## cvs rdiff doesn't support '-p' and '-w' option .. sad
                   1335: #      open($fh, "cvs -d $cvsroot rdiff $difftype " .
                   1336: #                    "-r$rev1 -r$rev2 '$where' 2>&1 |")
                   1337: #          || &fatal("500 Internal Error", "Couldn't cvs rdiff: $!");
                   1338: ###
                   1339:        open($fh, "rcsdiff $difftype -r$rev1 -r$rev2 '$fullname' 2>&1 |")
                   1340:            || &fatal("500 Internal Error", "Couldn't GNU rcsdiff: $!");
                   1341:        if ($human_readable) {
                   1342:            http_header();
                   1343:            &human_readable_diff($fh, $rev2);
                   1344:            exit;
                   1345:        }
                   1346:        else {
                   1347:            http_header("text/plain");
                   1348:        }
                   1349: #
                   1350: #===================================================================
                   1351: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
                   1352: #retrieving revision 1.16
                   1353: #retrieving revision 1.17
                   1354: #diff -c -r1.16 -r1.17
                   1355: #*** /home/ncvs/src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
                   1356: #--- /home/ncvs/src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17
                   1357: #
                   1358: # Ideas:
                   1359: # - nuke the stderr output if it's what we expect it to be
                   1360: # - Add "no differences found" if the diff command supplied no output.
                   1361: #
                   1362: #*** src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
                   1363: #--- src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17 RELENG_2_1_0
                   1364: # (bogus example, but...)
                   1365: #
                   1366:        if ($difftype eq '-u') {
                   1367:            $f1 = '---';
                   1368:            $f2 = '\+\+\+';
                   1369:        }
                   1370:        else {
                   1371:            $f1 = '\*\*\*';
                   1372:            $f2 = '---';
                   1373:        }
                   1374:        while (<$fh>) {
                   1375:            if (m|^$f1 $cvsroot|o) {
                   1376:                s|$cvsroot/||o;
                   1377:                if ($sym1) {
                   1378:                    chop;
                   1379:                    $_ .= " " . $sym1 . "\n";
                   1380:                }
                   1381:            }
                   1382:            elsif (m|^$f2 $cvsroot|o) {
                   1383:                s|$cvsroot/||o;
                   1384:                if ($sym2) {
                   1385:                    chop;
                   1386:                    $_ .= " " . $sym2 . "\n";
                   1387:                }
                   1388:            }
                   1389:            print $_;
                   1390:        }
                   1391:        close($fh);
                   1392: }
                   1393:
                   1394: ###############################
                   1395: # Show Logs ..
                   1396: ###############################
                   1397: sub getDirLogs {
                   1398:     my ($cvsroot,$dirname,@otherFiles) = @_;
                   1399:     my ($state,$otherFiles,$tag, $file, $date, $branchpoint, $branch, $log);
                   1400:     my ($rev, $revision, $revwanted, $filename, $head, $author);
                   1401:
                   1402:     $tag = $input{only_with_tag};
                   1403:
                   1404:     my ($DirName) = "$cvsroot/$where";
                   1405:     my (@files, @filetags);
                   1406:     my $fh = do {local(*FH);};
                   1407:
                   1408:     push(@files, &safeglob("$DirName/*,v"));
                   1409:     push(@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
                   1410:     foreach $file (@otherFiles) {
                   1411:        push(@files, "$DirName/$file");
                   1412:     }
                   1413:
                   1414:     # just execute rlog if there are any files
                   1415:     if ($#files < 0) {
                   1416:        return;
                   1417:     }
                   1418:
                   1419:     my ($filenames) = join("' '",@files);
                   1420:     if ($tag) {
                   1421:        #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
                   1422:        open($fh, "rlog '$filenames' 2>/dev/null |")
                   1423:            || &fatal("500 Internal Error", "Failed to spawn GNU rlog");
                   1424:     }
                   1425:     else {
                   1426:        open($fh, "rlog -r '$filenames' 2>/dev/null |")
                   1427:            || &fatal("500 Internal Error", "Failed to spawn GNU rlog");
                   1428:     }
                   1429:     $state = "start";
                   1430:     while (<$fh>) {
                   1431:        if ($state eq "start") {
                   1432:            #Next file. Initialize file variables
                   1433:            $rev = undef;
                   1434:            $revwanted = undef;
                   1435:            $branch = undef;
                   1436:            $branchpoint = undef;
                   1437:            $filename = undef;
                   1438:            $log = undef;
                   1439:            $revision = undef;
                   1440:            $branch = undef;
                   1441:            %symrev = ();
                   1442:            @filetags = ();
                   1443:            #jump to head state
                   1444:            $state = "head";
                   1445:        }
                   1446:        print "$state:$_" if ($verbose);
                   1447: again:
                   1448:        if ($state eq "head") {
                   1449:            #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
                   1450:            $filename = $1 if (/^Working file: (.+)$/);
                   1451:            $head = $1 if (/^head: (.+)$/);
                   1452:            $branch = $1 if (/^branch: (.+)$/);
                   1453:        }
                   1454:        if ($state eq "head" && /^symbolic names/) {
                   1455:            $state = "tags";
                   1456:            ($branch = $head) =~ s/\.\d+$// if (!defined($branch));
                   1457:            $branch =~ s/(\.?)(\d+)$/${1}0.$2/;
                   1458:            $symrev{MAIN} = $branch;
                   1459:            $symrev{HEAD} = $branch;
                   1460:            $alltags{MAIN} = 1;
                   1461:            $alltags{HEAD} = 1;
                   1462:            push (@filetags, "MAIN", "HEAD");
                   1463:            next;
                   1464:        }
                   1465:        if ($state eq "tags" &&
                   1466:                            /^\s+(.+):\s+([\d\.]+)\s+$/) {
                   1467:            push (@filetags, $1);
                   1468:            $symrev{$1} = $2;
                   1469:            $alltags{$1} = 1;
                   1470:            next;
                   1471:        }
                   1472:        if ($state eq "tags" && /^\S/) {
                   1473:            if (defined($tag) && (defined($symrev{$tag}) || $tag eq "HEAD")) {
                   1474:                $revwanted = $tag eq "HEAD" ? $symrev{"MAIN"} : $symrev{$tag};
                   1475:                ($branch = $revwanted) =~ s/\b0\.//;
                   1476:                ($branchpoint = $branch) =~ s/\.?\d+$//;
                   1477:                $revwanted = undef if ($revwanted ne $branch);
                   1478:            }
                   1479:            elsif (defined($tag) && $tag ne "HEAD") {
                   1480:                print "Tag not found, skip this file" if ($verbose);
                   1481:                $state = "skip";
                   1482:                next;
                   1483:            }
                   1484:            foreach my $tagfound (@filetags) {
                   1485:                $tags{$tagfound} = 1;
                   1486:            }
                   1487:            $state = "head";
                   1488:            goto again;
                   1489:        }
                   1490:        if ($state eq "head" && /^----------------------------$/) {
                   1491:            $state = "log";
                   1492:            $rev = undef;
                   1493:            $date = undef;
                   1494:            $log = "";
                   1495:            # Try to reconstruct the relative filename if RCS spits out a full path
                   1496:            $filename =~ s%^$DirName/%%;
                   1497:            next;
                   1498:        }
                   1499:        if ($state eq "log") {
                   1500:            if (/^----------------------------$/
                   1501:                || /^=============================/) {
                   1502:                # End of a log entry.
                   1503:                my $revbranch;
                   1504:                ($revbranch = $rev) =~ s/\.\d+$//;
                   1505:                print "$filename $rev Wanted: $revwanted "
                   1506:                    . "Revbranch: $revbranch Branch: $branch "
                   1507:                    . "Branchpoint: $branchpoint\n" if ($verbose);
                   1508:                if (!defined($revwanted) && defined($branch)
                   1509:                    && $branch eq $revbranch || !defined($tag)) {
                   1510:                    print "File revision $rev found for branch $branch\n"
                   1511:                        if ($verbose);
                   1512:                    $revwanted = $rev;
                   1513:                }
                   1514:                if (defined($revwanted) ? $rev eq $revwanted :
                   1515:                    defined($branchpoint) ? $rev eq $branchpoint :
                   1516:                    0 && ($rev eq $head)) { # Don't think head is needed here..
                   1517:                    print "File info $rev found for $filename\n" if ($verbose);
                   1518:                    my @finfo = ($rev,$date,$log,$author,$filename);
                   1519:                    my ($name);
                   1520:                    ($name = $filename) =~ s%/.*%%;
                   1521:                    $fileinfo{$name} = [ @finfo ];
                   1522:                    $state = "done" if ($rev eq $revwanted);
                   1523:                }
                   1524:                $rev = undef;
                   1525:                $date = undef;
                   1526:                $log = "";
                   1527:            }
                   1528:            elsif (!defined($date) && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
                   1529:                my $yr = $1;
                   1530:                # damn 2-digit year routines :-)
                   1531:                if ($yr > 100) {
                   1532:                    $yr -= 1900;
                   1533:                }
                   1534:                $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
                   1535:                ($author) = /author: ([^;]+)/;
                   1536:                $state = "log";
                   1537:                $log = '';
                   1538:                next;
                   1539:            }
                   1540:            elsif (!defined($rev) && m/^revision (.*)$/) {
                   1541:                $rev = $1;
                   1542:                next;
                   1543:            }
                   1544:            else {
                   1545:                $log = $log . $_;
                   1546:            }
                   1547:        }
                   1548:        if (/^===============/) {
                   1549:            $state = "start";
                   1550:            next;
                   1551:        }
                   1552:     }
                   1553:     if ($. == 0) {
                   1554:        fatal("500 Internal Error",
                   1555:              "Failed to spawn GNU rlog on <em>'$filenames'</em><p>did you set the <b>\$ENV{PATH}</b> in your configuration file correctly ?");
                   1556:     }
                   1557:     close($fh);
                   1558: }
                   1559:
                   1560: sub readLog {
                   1561:        my($fullname,$revision) = @_;
                   1562:        my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
                   1563:        my $fh = do {local(*FH);};
                   1564:
                   1565:        if (defined($revision)) {
                   1566:            $revision = "-r$revision";
                   1567:        }
                   1568:        else {
                   1569:            $revision = "";
                   1570:        }
                   1571:
                   1572:        undef %symrev;
                   1573:        undef %revsym;
                   1574:        undef @allrevisions;
                   1575:        undef %date;
                   1576:        undef %author;
                   1577:        undef %state;
                   1578:        undef %difflines;
                   1579:        undef %log;
                   1580:
                   1581:        print("Going to rlog '$fullname'\n") if ($verbose);
                   1582:        open($fh, "rlog $revision '$fullname'|")
                   1583:            || &fatal("500 Internal Error", "Failed to spawn rlog");
                   1584:
                   1585:        while (<$fh>) {
                   1586:            print if ($verbose);
                   1587:            if ($symnames) {
                   1588:                if (/^\s+([^:]+):\s+([\d\.]+)/) {
                   1589:                    $symrev{$1} = $2;
                   1590:                }
                   1591:                else {
                   1592:                    $symnames = 0;
                   1593:                }
                   1594:            }
                   1595:            elsif (/^head:\s+([\d\.]+)/) {
                   1596:                $head = $1;
                   1597:            }
                   1598:            elsif (/^branch:\s+([\d\.]+)/) {
                   1599:                $curbranch = $1;
                   1600:            }
                   1601:            elsif (/^symbolic names/) {
                   1602:                $symnames = 1;
                   1603:            }
                   1604:            elsif (/^-----/) {
                   1605:                last;
                   1606:            }
                   1607:        }
                   1608:        ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
                   1609:
                   1610: # each log entry is of the form:
                   1611: # ----------------------------
                   1612: # revision 3.7.1.1
                   1613: # date: 1995/11/29 22:15:52;  author: fenner;  state: Exp;  lines: +5 -3
                   1614: # log info
                   1615: # ----------------------------
                   1616:        logentry:
                   1617:        while (!/^=========/) {
                   1618:            $_ = <$fh>;
                   1619:            last logentry if (!defined($_));    # EOF
                   1620:            print "R:", $_ if ($verbose);
                   1621:            if (/^revision ([\d\.]+)/) {
                   1622:                $rev = $1;
                   1623:                unshift(@allrevisions,$rev);
                   1624:            }
                   1625:            elsif (/^========/ || /^----------------------------$/) {
                   1626:                next logentry;
                   1627:            }
                   1628:            else {
                   1629:                # The rlog output is syntactically ambiguous.  We must
                   1630:                # have guessed wrong about where the end of the last log
                   1631:                # message was.
                   1632:                # Since this is likely to happen when people put rlog output
                   1633:                # in their commit messages, don't even bother keeping
                   1634:                # these lines since we don't know what revision they go with
                   1635:                # any more.
                   1636:                next logentry;
                   1637: #              &fatal("500 Internal Error","Error parsing RCS output: $_");
                   1638:            }
                   1639:            $_ = <$fh>;
                   1640:            print "D:", $_ if ($verbose);
                   1641:            if (m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|) {
                   1642:                my $yr = $1;
                   1643:                 # damn 2-digit year routines :-)
                   1644:                 if ($yr > 100) {
                   1645:                     $yr -= 1900;
                   1646:                 }
                   1647:                $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
                   1648:                $author{$rev} = $7;
                   1649:                $state{$rev} = $8;
                   1650:                $difflines{$rev} = $10;
                   1651:            }
                   1652:            else {
                   1653:                &fatal("500 Internal Error", "Error parsing RCS output: $_");
                   1654:            }
                   1655:            line:
                   1656:            while (<$fh>) {
                   1657:                print "L:", $_ if ($verbose);
                   1658:                next line if (/^branches:\s/);
                   1659:                last line if (/^----------------------------$/ || /^=========/);
                   1660:                $log{$rev} .= $_;
                   1661:            }
                   1662:            print "E:", $_ if ($verbose);
                   1663:        }
                   1664:        close($fh);
                   1665:        print "Done reading RCS file\n" if ($verbose);
                   1666:
                   1667:        @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
                   1668:        print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
                   1669:
                   1670: #
                   1671: # HEAD is an artificial tag which is simply the highest tag number on the main
                   1672: # branch, unless there is a branch tag in the RCS file in which case it's the
                   1673: # highest revision on that branch.  Find it by looking through @revorder; it
                   1674: # is the first commit listed on the appropriate branch.
                   1675: # This is not neccesary the same revision as marked as head in the RCS file.
                   1676:        my $headrev = $curbranch || "1";
                   1677:        ($symrev{"MAIN"} = $headrev) =~ s/(\.?)(\d+)$/${1}0.$2/;
                   1678:        revision:
                   1679:        foreach $rev (@revorder) {
                   1680:            if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
                   1681:                $symrev{"HEAD"} = $rev;
                   1682:                last revision;
                   1683:            }
                   1684:        }
                   1685:        ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
                   1686:             if (!defined($symrev{"HEAD"}));
                   1687:        print "Done finding HEAD\n" if ($verbose);
                   1688: #
                   1689: # Now that we know all of the revision numbers, we can associate
                   1690: # absolute revision numbers with all of the symbolic names, and
                   1691: # pass them to the form so that the same association doesn't have
                   1692: # to be built then.
                   1693: #
                   1694:        undef @branchnames;
                   1695:        undef %branchpoint;
                   1696:        undef $sel;
                   1697:
                   1698:        foreach (reverse sort keys %symrev) {
                   1699:            $rev = $symrev{$_};
                   1700:            if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
                   1701:                push(@branchnames, $_);
                   1702:                #
                   1703:                # A revision number of A.B.0.D really translates into
                   1704:                # "the highest current revision on branch A.B.D".
                   1705:                #
                   1706:                # If there is no branch A.B.D, then it translates into
                   1707:                # the head A.B .
                   1708:                #
                   1709:                # This reasoning also applies to the main branch A.B,
                   1710:                # with the branch number 0.A, with the exception that
                   1711:                # it has no head to translate to if there is nothing on
                   1712:                # the branch, but I guess this can never happen?
                   1713:                # (the code below gracefully forgets about the branch
                   1714:                # if it should happen)
                   1715:                #
                   1716:                $head = defined($2) ? $2 : "";
                   1717:                $branch = $3;
                   1718:                $branchrev = $head . ($head ne "" ? "." : "") . $branch;
                   1719:                my $regex;
                   1720:                ($regex = $branchrev) =~ s/\./\\./g;
                   1721:                $rev = $head;
                   1722:
                   1723:                revision:
                   1724:                foreach my $r (@revorder) {
                   1725:                    if ($r =~ /^${regex}\b/) {
                   1726:                        $rev = $branchrev;
                   1727:                        last revision;
                   1728:                    }
                   1729:                }
                   1730:                next if ($rev eq "");
                   1731:                if ($rev ne $head && $head ne "") {
                   1732:                    $branchpoint{$head} .= ", " if ($branchpoint{$head});
                   1733:                    $branchpoint{$head} .= $_;
                   1734:                }
                   1735:            }
                   1736:            $revsym{$rev} .= ", " if ($revsym{$rev});
                   1737:            $revsym{$rev} .= $_;
                   1738:            $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
                   1739:        }
                   1740:        print "Done associating revisions with branches\n" if ($verbose);
                   1741:
                   1742:        my ($onlyonbranch, $onlybranchpoint);
                   1743:        if ($onlyonbranch = $input{'only_with_tag'}) {
                   1744:            $onlyonbranch = $symrev{$onlyonbranch};
                   1745:            if ($onlyonbranch =~ s/\b0\.//) {
                   1746:                ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
                   1747:            }
                   1748:             else {
                   1749:                $onlybranchpoint = $onlyonbranch;
                   1750:            }
                   1751:            if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
                   1752:                fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
                   1753:            }
                   1754:        }
                   1755:
                   1756:        undef @revisions;
                   1757:
                   1758:        foreach (@allrevisions) {
                   1759:            ($br = $_) =~ s/\.\d+$//;
                   1760:            ($brp = $br) =~ s/\.\d+$//;
                   1761:            next if ($onlyonbranch && $br ne $onlyonbranch &&
                   1762:                                        $_ ne $onlybranchpoint);
                   1763:            unshift(@revisions,$_);
                   1764:        }
                   1765:
                   1766:        if ($logsort eq "date") {
                   1767:            # Sort the revisions in commit order an secondary sort on revision
                   1768:            # (secondary sort needed for imported sources, or the first main
                   1769:            # revision gets before the same revision on the 1.1.1 branch)
                   1770:            @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
                   1771:        }
                   1772:         elsif ($logsort eq "rev") {
                   1773:            # Sort the revisions in revision order, highest first
                   1774:            @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
                   1775:        }
                   1776:         else {
                   1777:            # No sorting. Present in the same order as rlog / cvs log
                   1778:            @revdisplayorder = @revisions;
                   1779:        }
                   1780:
                   1781: }
                   1782:
                   1783: sub printLog($;$) {
                   1784:        my ($link, $br, $brp);
                   1785:        ($_,$link) = @_;
                   1786:        ($br = $_) =~ s/\.\d+$//;
                   1787:        ($brp = $br) =~ s/\.?\d+$//;
                   1788:        my ($isDead, $prev);
                   1789:
                   1790:        $link = 1 if (!defined($link));
                   1791:        $isDead = ($state{$_} eq "dead");
                   1792:
                   1793:        if ($link && !$isDead) {
                   1794:            my ($filename);
                   1795:            ($filename = $where) =~ s/^.*\///;
                   1796:            my ($fileurl) = urlencode($filename);
                   1797:            print "<a NAME=\"rev$_\"></a>";
                   1798:            if (defined($revsym{$_})) {
                   1799:                foreach my $sym (split(", ", $revsym{$_})) {
                   1800:                    print "<a NAME=\"$sym\"></a>";
                   1801:                }
                   1802:            }
                   1803:            if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
                   1804:                foreach my $sym (split(", ", $revsym{$br})) {
                   1805:                    print "<a NAME=\"$sym\"></a>";
                   1806:                }
                   1807:                $nameprinted{$br} = 1;
                   1808:            }
                   1809:            print "\n Revision ";
                   1810:            &download_link($fileurl, $_, $_,
                   1811:                $defaultViewable ? "text/x-cvsweb-markup" : undef);
                   1812:            if ($defaultViewable) {
                   1813:                print " / ";
                   1814:                &download_link($fileurl, $_, "(download)", $mimetype);
                   1815:            }
                   1816:            if (not $defaultTextPlain) {
                   1817:                print " / ";
                   1818:                &download_link($fileurl, $_, "(as text)",
                   1819:                           "text/plain");
                   1820:            }
                   1821:            if (!$defaultViewable) {
                   1822:                print " / ";
                   1823:                &download_link($fileurl, $_, "(view)", "text/x-cvsweb-markup");
                   1824:            }
                   1825:            if ($allow_annotate) {
                   1826:                print " - <a href=\"" . $scriptname . "/" . urlencode($where) . "?annotate=$_$barequery\">";
                   1827:                print "annotate</a>";
                   1828:            }
                   1829:            # Plus a select link if enabled, and this version isn't selected
                   1830:            if ($allow_version_select) {
                   1831:                if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
                   1832:                    print " - <A HREF=\"${scriptwhere}?r1=$_$barequery" .
                   1833:                        "\">[select for diffs]</A>\n";
                   1834:                }
                   1835:                else {
                   1836:                    print " - <b>[selected]</b>";
                   1837:                }
                   1838:            }
                   1839:        }
                   1840:        else {
                   1841:            print "Revision <B>$_</B>";
                   1842:        }
                   1843:        if (/^1\.1\.1\.\d+$/) {
                   1844:            print " <i>(vendor branch)</i>";
                   1845:        }
                   1846:        print ", <i>" . scalar gmtime($date{$_}) . " UTC</i> (";
                   1847:        print readableTime(time() - $date{$_},1) . " ago)";
                   1848:        print " by ";
                   1849:        print "<i>" . $author{$_} . "</i>\n";
                   1850:        print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
                   1851:            if ($revsym{$br});
                   1852:        print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
                   1853:            if ($revsym{$_});
                   1854:        print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
                   1855:            if ($branchpoint{$_});
                   1856:        # Find the previous revision
                   1857:        my @prevrev = split(/\./, $_);
                   1858:        do {
                   1859:            if (--$prevrev[$#prevrev] <= 0) {
                   1860:                # If it was X.Y.Z.1, just make it X.Y
                   1861:                pop(@prevrev);
                   1862:                pop(@prevrev);
                   1863:            }
                   1864:            $prev = join(".", @prevrev);
                   1865:        } until (defined($date{$prev}) || $prev eq "");
                   1866:        if ($prev ne "") {
                   1867:            if ($difflines{$_}) {
                   1868:                print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
                   1869:            }
                   1870:        }
                   1871:        if ($isDead) {
                   1872:            print "<BR><B><I>FILE REMOVED</I></B>\n";
                   1873:        }
                   1874:        elsif ($link) {
                   1875:            my %diffrev = ();
                   1876:            $diffrev{$_} = 1;
                   1877:            $diffrev{""} = 1;
                   1878:            print "<BR>Diff";
                   1879:            #
                   1880:            # Offer diff to previous revision
                   1881:            if ($prev) {
                   1882:                $diffrev{$prev} = 1;
                   1883:                print " to previous <A HREF=\"${scriptwhere}.diff?r1=$prev";
                   1884:                print "&r2=$_" . $barequery . "\">$prev</A>\n";
                   1885:                if (!$hr_default) { # offer a human readable version if not default
                   1886:                    print "(<A HREF=\"${scriptwhere}.diff?r1=$prev";
                   1887:                    print "&r2=$_" . $barequery . "&f=h\">colored</A>)\n";
                   1888:                }
                   1889:            }
                   1890:            #
                   1891:            # Plus, if it's on a branch, and it's not a vendor branch,
                   1892:            # offer a diff with the branch point.
                   1893:            if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
                   1894:                print " to branchpoint <A HREF=\"${scriptwhere}.diff?r1=$brp";
                   1895:                print "&r2=$_" . $barequery . "\">$brp</A>\n";
                   1896:                if (!$hr_default) { # offer a human readable version if not default
                   1897:                print "(<A HREF=\"${scriptwhere}.diff?r1=$brp";
                   1898:                print "&r2=$_" . $barequery . "&f=h\">colored</A>)\n";
                   1899:                }
                   1900:            }
                   1901:            #
                   1902:            # Plus, if it's on a branch, and it's not a vendor branch,
                   1903:            # offer to diff with the next revision of the higher branch.
                   1904:            # (e.g. change gets committed and then brought
                   1905:            # over to -stable)
                   1906:            if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
                   1907:                my ($i,$nextmain);
                   1908:                for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
                   1909:                my (@tmp2) = split(/\./, $_);
                   1910:                for ($nextmain = ""; $i > 0; $i--) {
                   1911:                    my ($next) = $revorder[$i-1];
                   1912:                    my (@tmp1) = split(/\./, $next);
                   1913:                    if ($#tmp1 < $#tmp2) {
                   1914:                        $nextmain = $next;
                   1915:                        last;
                   1916:                    }
                   1917:                    # Only the highest version on a branch should have
                   1918:                    # a diff for the "next main".
                   1919:                    last if (join(".",@tmp1[0..$#tmp1-1])
                   1920:                             eq join(".",@tmp2[0..$#tmp1-1]));
                   1921:                }
                   1922:                if (!defined($diffrev{$nextmain})) {
                   1923:                    $diffrev{$nextmain} = 1;
                   1924:                    print " next main <A HREF=\"${scriptwhere}.diff?r1=$nextmain";
                   1925:                    print "&r2=$_" . $barequery .
                   1926:                        "\">$nextmain</A>\n";
                   1927:                    if (!$hr_default) { # offer a human readable version if not default
                   1928:                        print "(<A HREF=\"${scriptwhere}.diff?r1=$nextmain";
                   1929:                        print "&r2=$_" . $barequery .
                   1930:                            "&f=h\">colored</A>)\n";
                   1931:                    }
                   1932:                }
                   1933:            }
                   1934:            # Plus if user has selected only r1, then present a link
                   1935:            # to make a diff to that revision
                   1936:            if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
                   1937:                $diffrev{$input{"r1"}} = 1;
                   1938:                print " to selected <A HREF=\"${scriptwhere}.diff?"
                   1939:                        . "r1=$input{'r1'}&r2=$_" . $barequery
                   1940:                        . "\">$input{'r1'}</A>\n";
                   1941:                if (!$hr_default) { # offer a human readable version if not default
                   1942:                    print "(<A HREF=\"${scriptwhere}.diff?r1=$input{'r1'}";
                   1943:                    print "&r2=$_" . $barequery .
                   1944:                        "&f=h\">colored</A>)\n";
                   1945:
                   1946:                }
                   1947:            }
                   1948:        }
                   1949:        print "<PRE>\n";
                   1950:        print &htmlify($log{$_}, 1);
                   1951:        print "</PRE>\n";
                   1952: }
                   1953:
                   1954: sub doLog {
                   1955:        my($fullname) = @_;
                   1956:        my ($diffrev, $upwhere, $filename, $backurl);
                   1957:
                   1958:        readLog($fullname);
                   1959:
                   1960:         html_header("CVS log for $where");
                   1961:        ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
                   1962:         ($filename = $where) =~ s|^.*/||;
                   1963:         $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
                   1964:        print &link($backicon, "$backurl#$filename"),
                   1965:               " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
                   1966:        print "<A HREF=\"#diff\">Request diff between arbitrary revisions</A>\n";
                   1967:        print "<HR NOSHADE>\n";
                   1968:        if ($curbranch) {
                   1969:            print "Default branch: ";
                   1970:            print ($revsym{$curbranch} || $curbranch);
                   1971:        }
                   1972:        else {
                   1973:            print "No default branch";
                   1974:        }
                   1975:        print "<BR>\n";
                   1976:        if ($input{only_with_tag}) {
                   1977:            print "Current tag: $input{only_with_tag}<BR>\n";
                   1978:        }
                   1979:
                   1980:        undef %nameprinted;
                   1981:
                   1982:        for (my $i = 0; $i <= $#revdisplayorder; $i++) {
                   1983:            print "<HR size=1 NOSHADE>";
                   1984:            printLog($revdisplayorder[$i]);
                   1985:        }
                   1986:
                   1987:        print "<A NAME=diff>\n";
                   1988:         print "<HR NOSHADE>";
                   1989:        print "This form allows you to request diff's between any two\n";
                   1990:        print "revisions of a file.  You may select a symbolic revision\n";
                   1991:        print "name using the selection box or you may type in a numeric\n";
                   1992:        print "name using the type-in text box.\n";
                   1993:        print "</A><P>\n";
                   1994:        print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
                   1995:         foreach (@stickyvars) {
                   1996:            print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
                   1997:                if (defined($input{$_})
                   1998:                    && ($input{$_} ne $DEFAULTVALUE{$_} && $input{$_} ne ""));
                   1999:        }
                   2000:        print "Diffs between \n";
                   2001:        print "<SELECT NAME=\"r1\">\n";
                   2002:        print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
                   2003:        print $sel;
                   2004:        print "</SELECT>\n";
                   2005:        $diffrev = $revdisplayorder[$#revdisplayorder];
                   2006:        $diffrev = $input{"r1"} if (defined($input{"r1"}));
                   2007:        print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'>\n";
                   2008:        print " and \n";
                   2009:        print "<SELECT NAME=\"r2\">\n";
                   2010:        print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
                   2011:        print $sel;
                   2012:        print "</SELECT>\n";
                   2013:        $diffrev = $revdisplayorder[0];
                   2014:        $diffrev = $input{"r2"} if (defined($input{"r2"}));
                   2015:        print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='docuement.diff_select.r2.selectedIndex=0'>\n";
                   2016:         print "<BR>Type of Diff should be a&nbsp;";
                   2017:        printDiffSelect();
                   2018:        print "<INPUT TYPE=SUBMIT VALUE=\"  Get Diffs  \">\n";
                   2019:        print "</FORM>\n";
                   2020:        print "<HR noshade>\n";
                   2021:         if (@branchnames) {
                   2022:            print "<A name=branch>\n";
                   2023:            print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
                   2024:            foreach (@stickyvars) {
                   2025:                next if ($_ eq "only_with_tag");
                   2026:                next if ($_ eq "logsort");
                   2027:                print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
                   2028:                    if (defined($input{$_}) && $input{$_} ne $DEFAULTVALUE{$_}
                   2029:                        && $input{$_} ne "");
                   2030:            }
                   2031:            print "View only Branch: \n";
                   2032:            print "<SELECT NAME=\"only_with_tag\"";
                   2033:            print " onchange=\"submit()\"" if ($use_java_script);
                   2034:            print ">\n";
                   2035:            print "<OPTION VALUE=\"\"";
                   2036:            print " SELECTED" if (defined($input{"only_with_tag"}) &&
                   2037:                $input{"only_with_tag"} eq "");
                   2038:            print ">Show all branches\n";
                   2039:            foreach (reverse sort @branchnames) {
                   2040:                print "<OPTION";
                   2041:                print " SELECTED" if (defined($input{"only_with_tag"})
                   2042:                        && $input{"only_with_tag"} eq $_);
                   2043:                print ">${_}\n";
                   2044:            }
                   2045:            print "</SELECT>\n";
                   2046:            print "<INPUT TYPE=SUBMIT VALUE=\"  View Branch  \">\n";
                   2047:            print "</FORM>\n";
                   2048:            print "</A>\n";
                   2049:        }
                   2050:        print "<A name=logsort>\n";
                   2051:        print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
                   2052:        foreach (@stickyvars) {
                   2053:            next if ($_ eq "only_with_tag");
                   2054:            next if ($_ eq "logsort");
                   2055:            print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
                   2056:                if (defined($input{$_}) && $input{$_} ne $DEFAULTVALUE{$_}
                   2057:                    && $input{$_} ne "");
                   2058:        }
                   2059:        print "Sort log by: \n";
                   2060:        print "<SELECT NAME=\"logsort\"";
                   2061:        print " onchange=\"submit()\"" if ($use_java_script);
                   2062:        print ">\n";
                   2063:        print "<OPTION VALUE=cvs",$logsort eq "cvs" ? " SELECTED" : "", ">Not sorted";
                   2064:        print "<OPTION VALUE=date",$logsort eq "date" ? " SELECTED" : "", ">Commit date";
                   2065:        print "<OPTION VALUE=rev",$logsort eq "rev" ? " SELECTED" : "", ">Revision";
                   2066:        print "</SELECT>\n";
                   2067:        print "<INPUT TYPE=SUBMIT VALUE=\"  Sort  \">\n";
                   2068:        print "</FORM>\n";
                   2069:        print "</A>";
                   2070:         print &html_footer;
                   2071:        print "</BODY></HTML>\n";
                   2072: }
                   2073:
                   2074: sub flush_diff_rows ($$$$)
                   2075: {
                   2076:     my $j;
                   2077:     my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
                   2078:     if ($state eq "PreChangeRemove") {          # we just got remove-lines before
                   2079:       for ($j = 0 ; $j < $leftRow; $j++) {
                   2080:           print  "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
                   2081:           print  "<td bgcolor=\"$diffcolorEmpty\">&nbsp;</td></tr>\n";
                   2082:       }
                   2083:     }
                   2084:     elsif ($state eq "PreChange") {             # state eq "PreChange"
                   2085:       # we got removes with subsequent adds
                   2086:       for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) {  # dump out both cols
                   2087:           print  "<tr>";
                   2088:           if ($j < $leftRow) {
                   2089:              print  "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
                   2090:          }
                   2091:           else {
                   2092:              print  "<td bgcolor=\"$diffcolorDarkChange\">&nbsp;</td>";
                   2093:          }
                   2094:           if ($j < $rightRow) {
                   2095:              print  "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
                   2096:          }
                   2097:           else {
                   2098:              print  "<td bgcolor=\"$diffcolorDarkChange\">&nbsp;</td>";
                   2099:          }
                   2100:           print  "</tr>\n";
                   2101:       }
                   2102:     }
                   2103: }
                   2104:
                   2105: ##
                   2106: # Function to generate Human readable diff-files
                   2107: # human_readable_diff(String revision_to_return_to);
                   2108: ##
                   2109: sub human_readable_diff($){
                   2110:   my ($i,$difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
                   2111:   my ($fh, $rev) = @_;
                   2112:   my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
                   2113:   my (@rightCol, @leftCol);
                   2114:
                   2115:   ($where_nd = $where) =~ s/.diff$//;
                   2116:   ($filename = $where_nd) =~ s/^.*\///;
                   2117:   ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
                   2118:   ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
                   2119:
                   2120:   navigateHeader ($scriptwhere_nd, $pathname, $filename, $rev, "diff");
                   2121:
                   2122:   # Read header to pick up read revision and date, if possible
                   2123:   while (<$fh>) {
                   2124:       ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
                   2125:       ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
                   2126:       last if (/^\+\+\+ /);
                   2127:   }
                   2128:   if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
                   2129:     $rev1 = $r1r;
                   2130:     $date1 = $r1d;
                   2131:   }
                   2132:   if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
                   2133:     $rev2 = $r2r;
                   2134:     $date2 = $r2d;
                   2135:   }
                   2136:
                   2137:   print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n";
                   2138:
                   2139:   print "<table border=0 cellspacing=0 cellpadding=0 width=100%>\n";
                   2140:   print "<tr bgcolor=#ffffff>\n";
                   2141:   print "<th width=\"50%\" valign=TOP>";
                   2142:   print "version $rev1";
                   2143:   print ", $date1" if (defined($date1));
                   2144:   print "<br>Tag: $sym1\n" if ($sym1);
                   2145:   print "</th>\n";
                   2146:   print "<th width=\"50%\" valign=TOP>";
                   2147:   print "version $rev2";
                   2148:   print ", $date2" if (defined($date2));
                   2149:   print "<br>Tag: $sym2\n" if ($sym1);
                   2150:   print "</th>\n";
                   2151:
                   2152:   my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\">";
                   2153:   my $fe = "</font>";
                   2154:
                   2155:   my $leftRow = 0;
                   2156:   my $rightRow = 0;
                   2157:   my ($oldline, $newline, $funname, $diffcode, $rest);
                   2158:
                   2159:   # Process diff text
                   2160:   # The diffrows are could make excellent use of
                   2161:   # cascading style sheets because we've to set the
                   2162:   # font and color for each row. anyone ...?
                   2163:   ####
                   2164:   while (<$fh>) {
                   2165:       $difftxt = $_;
                   2166:
                   2167:       if ($difftxt =~ /^@@/) {
                   2168:          ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
                   2169:           print  "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
                   2170:          print  "<table width=100% border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
                   2171:          print  "&nbsp;<font size=-1>$funname</font></td></tr></table>";
                   2172:           print  "</td><td width=\"50%\">";
                   2173:          print  "<table width=100% border=1 cellpadding=5><tr><td><b>Line $newline</b>";
                   2174:          print  "&nbsp;<font size=-1>$funname</font></td></tr></table>";
                   2175:          print  "</td><tr>\n";
                   2176:          $state = "dump";
                   2177:          $leftRow = 0;
                   2178:          $rightRow = 0;
                   2179:       }
                   2180:       else {
                   2181:          ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
                   2182:          $_ = spacedHtmlText ($rest);
                   2183:
                   2184:          # Add fontface, size
                   2185:          $_ = "$fs&nbsp;$_$fe";
                   2186:
                   2187:          #########
                   2188:          # little state machine to parse unified-diff output (Hen, zeller@think.de)
                   2189:          # in order to get some nice 'ediff'-mode output
                   2190:          # states:
                   2191:          #  "dump"             - just dump the value
                   2192:          #  "PreChangeRemove"  - we began with '-' .. so this could be the start of a 'change' area or just remove
                   2193:          #  "PreChange"        - okey, we got several '-' lines and moved to '+' lines -> this is a change block
                   2194:          ##########
                   2195:
                   2196:          if ($diffcode eq '+') {
                   2197:              if ($state eq "dump") {  # 'change' never begins with '+': just dump out value
                   2198:                  print  "<tr><td bgcolor=\"$diffcolorEmpty\">&nbsp;</td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
                   2199:              }
                   2200:              else {                   # we got minus before
                   2201:                  $state = "PreChange";
                   2202:                  $rightCol[$rightRow++] = $_;
                   2203:              }
                   2204:          }
                   2205:          elsif ($diffcode eq '-') {
                   2206:              $state = "PreChangeRemove";
                   2207:              $leftCol[$leftRow++] = $_;
                   2208:         }
                   2209:         else {  # empty diffcode
                   2210:             flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
                   2211:              print  "<tr><td>$_</td><td>$_</td></tr>\n";
                   2212:              $state = "dump";
                   2213:              $leftRow = 0;
                   2214:              $rightRow = 0;
                   2215:          }
                   2216:       }
                   2217:   }
                   2218:   flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
                   2219:
                   2220:   # state is empty if we didn't have any change
                   2221:   if (!$state) {
                   2222:       print "<tr><td colspan=2>&nbsp;</td></tr>";
                   2223:       print "<tr bgcolor=\"$diffcolorEmpty\" >";
                   2224:       print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
                   2225:   }
                   2226:   print  "</table>";
                   2227:   close($fh);
                   2228:
                   2229:   print "<br><hr noshade width=100%>\n";
                   2230:
                   2231:   print "<table border=0>";
                   2232:
                   2233:   print "<tr><td>";
                   2234:   # print legend
                   2235:   print "<table border=1><tr><td>";
                   2236:   print  "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
                   2237:   print  "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\">&nbsp;</td></tr>";
                   2238:   print  "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
                   2239:   print  "<tr><td bgcolor=\"$diffcolorEmpty\">&nbsp;</td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
                   2240:   print  "</table></td></tr></table>\n";
                   2241:   print  "</body>\n</html>\n";
                   2242:
                   2243:   print "<td>";
                   2244:   # Print format selector
                   2245:   print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
                   2246:   foreach my $var (keys %input) {
                   2247:     next if ($var eq "f");
                   2248:     next if (defined($DEFAULTVALUE{$var})
                   2249:             && $DEFAULTVALUE{$var} eq $input{$var});
                   2250:     print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
                   2251:            urlencode($input{$var}),"\">\n";
                   2252:   }
                   2253:   printDiffSelect($use_java_script);
                   2254:   print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
                   2255:   print "</FORM>\n";
                   2256:   print "</td>";
                   2257:
                   2258:   print "</tr></table>";
                   2259: }
                   2260:
                   2261: sub navigateHeader ($$$$$) {
                   2262:     my ($swhere,$path,$filename,$rev,$title) = @_;
                   2263:     $swhere = "" if ($swhere eq $scriptwhere);
                   2264:     $swhere = urlencode($filename) if ($swhere eq "");
                   2265:     print "<HTML>\n<HEAD>\n";
                   2266:     print '<!-- hennerik CVSweb $Revision: 1.79 $ -->';
                   2267:     print "\n<TITLE>$path$filename - $title - $rev</TITLE></HEAD>\n";
                   2268:     print  "<BODY BGCOLOR=\"$backcolor\">\n";
                   2269:     print "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$navigationHeaderColor\">";
                   2270:     print "<tr valign=bottom><td>";
                   2271:     print  "<a href=\"$swhere$query#rev$rev\">$backicon";
                   2272:     print "</a> <b>Return to ", &link("$filename","$swhere$query#rev$rev")," CVS log";
                   2273:     print "</b> $fileicon</td>";
                   2274:
                   2275:     print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
                   2276:     print "</tr></table>";
                   2277: }
                   2278:
                   2279: sub plural_write ($$)
                   2280: {
                   2281:     my ($num,$text) = @_;
                   2282:     if ($num != 1) {
                   2283:        $text = $text . "s";
                   2284:     }
                   2285:     if ($num > 0) {
                   2286:        return $num . " " . $text;
                   2287:     }
                   2288:     else {
                   2289:        return "";
                   2290:     }
                   2291: }
                   2292:
                   2293: ##
                   2294: # print readable timestamp in terms of
                   2295: # '..time ago'
                   2296: # H. Zeller <zeller@think.de>
                   2297: ##
                   2298: sub readableTime ($$)
                   2299: {
                   2300:     my ($i, $break, $retval);
                   2301:     my ($secs,$long) = @_;
                   2302:
                   2303:     # this function works correct for time >= 2 seconds
                   2304:     if ($secs < 2) {
                   2305:        return "very little time";
                   2306:     }
                   2307:
                   2308:     my %desc = (1 , 'second',
                   2309:                   60, 'minute',
                   2310:                   3600, 'hour',
                   2311:                   86400, 'day',
                   2312:                   604800, 'week',
                   2313:                   2628000, 'month',
                   2314:                   31536000, 'year');
                   2315:     my @breaks = sort {$a <=> $b} keys %desc;
                   2316:     $i = 0;
                   2317:     while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
                   2318:        $i++;
                   2319:     }
                   2320:     $i--;
                   2321:     $break = $breaks[$i];
                   2322:     $retval = plural_write(int ($secs / $break), $desc{"$break"});
                   2323:
                   2324:     if ($long == 1 && $i > 0) {
                   2325:        my $rest = $secs % $break;
                   2326:        $i--;
                   2327:        $break = $breaks[$i];
                   2328:        my $resttime = plural_write(int ($rest / $break),
                   2329:                                $desc{"$break"});
                   2330:        if ($resttime) {
                   2331:            $retval = $retval . ", " . $resttime;
                   2332:        }
                   2333:     }
                   2334:
                   2335:     return $retval;
                   2336: }
                   2337:
                   2338: ##
                   2339: # clickablePath(String pathname, boolean last_item_clickable)
                   2340: #
                   2341: # returns a html-ified path whereas each directory is a link for
                   2342: # faster navigation. last_item_clickable controls whether the
                   2343: # basename (last directory/file) is a link as well
                   2344: ##
                   2345: sub clickablePath($$) {
                   2346:     my ($pathname,$clickLast) = @_;
                   2347:     my $retval = '';
                   2348:
                   2349:     if ($pathname eq '/') {
                   2350:        # this should never happen - chooseCVSRoot() is
                   2351:        # intended to do this
                   2352:        $retval = "[$cvstree]";
                   2353:     }
                   2354:     else {
                   2355:        $retval = $retval . " <a href=\"${scriptname}/${query}#dirlist\">[$cvstree]</a>";
                   2356:        my $wherepath = '';
                   2357:        my ($lastslash) = $pathname =~ m|/$|;
                   2358:        foreach (split(/\//, $pathname)) {
                   2359:            $retval = $retval . " / ";
                   2360:            $wherepath = $wherepath . '/' . $_;
                   2361:            my ($last) = "$wherepath/" eq "/$pathname"
                   2362:                || "$wherepath" eq "/$pathname";
                   2363:            if ($clickLast || !$last) {
                   2364:                $retval = $retval . "<a href=\"${scriptname}"
                   2365:                    . urlencode($wherepath)
                   2366:                    . (!$last || $lastslash ? '/' : '')
                   2367:                    . ${query}
                   2368:                    . (!$last || $lastslash ? "#dirlist" : "")
                   2369:                    . "\">$_</a>";
                   2370:            }
                   2371:            else { # do not make a link to the current dir
                   2372:                $retval = $retval .  $_;
                   2373:            }
                   2374:        }
                   2375:     }
                   2376:     return $retval;
                   2377: }
                   2378:
                   2379: sub chooseCVSRoot() {
                   2380:     my @foo;
                   2381:     foreach (sort keys %CVSROOT) {
                   2382:        if (-d $CVSROOT{$_}) {
                   2383:            push(@foo, $_);
                   2384:        }
                   2385:     }
                   2386:     if (@foo > 1) {
                   2387:        my ($k);
                   2388:        print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
                   2389:        foreach $k (keys %input) {
                   2390:            print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
                   2391:                if ($input{$k}) && ($k ne "cvsroot");
                   2392:        }
                   2393:        # Form-Elements look wierd in Netscape if the background
                   2394:        # isn't gray and the form elements are not placed
                   2395:        # within a table ...
                   2396:        print "<table><tr>";
                   2397:        print "<td>CVS Root:</td>";
                   2398:        print "<td>\n<select name=\"cvsroot\"";
                   2399:        print " onchange=\"submit()\"" if ($use_java_script);
                   2400:        print ">\n";
                   2401:        foreach $k (@foo) {
                   2402:            print "<option value=\"$k\"";
                   2403:            print " selected" if ("$k" eq "$cvstree");
                   2404:            print ">" . ($CVSROOTdescr{"$k"} ? $CVSROOTdescr{"$k"} :
                   2405:                        $k). "</option>\n";
                   2406:        }
                   2407:        print "</select>\n</td>";
                   2408:        print "<td><input type=submit value=\"Go\"></td>";
                   2409:        print "</tr></table></form>";
                   2410:     }
                   2411:     else {
                   2412:        # no choice ..
                   2413:        print "CVS Root: <b>[$cvstree]</b>";
                   2414:     }
                   2415: }
                   2416:
                   2417: sub chooseMirror() {
                   2418:     my ($mirror,$moremirrors);
                   2419:     $moremirrors = 0;
                   2420:     # This code comes from the original BSD-cvsweb
                   2421:     # and may not be useful for your site; If you don't
                   2422:     # set %MIRRORS this won't show up, anyway
                   2423:     #
                   2424:     # Should perhaps exlude the current site somehow..
                   2425:     if (keys %MIRRORS) {
                   2426:        print "\nThis cvsweb is mirrored in:\n";
                   2427:        foreach $mirror (keys %MIRRORS) {
                   2428:            print ", " if ($moremirrors);
                   2429:            print qq(<a href="$MIRRORS{$mirror}">$mirror</A>\n);
                   2430:            $moremirrors = 1;
                   2431:        }
                   2432:        print "<p>\n";
                   2433:     }
                   2434: }
                   2435:
                   2436: sub fileSortCmp {
                   2437:     my ($comp) = 0;
                   2438:     my ($c,$d,$af,$bf);
                   2439:
                   2440:     ($af = $a) =~ s/,v$//;
                   2441:     ($bf = $b) =~ s/,v$//;
                   2442:     my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
                   2443:         if (defined($fileinfo{$af}));
                   2444:     my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
                   2445:         if (defined($fileinfo{$bf}));
                   2446:
                   2447:     if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
                   2448:        # Two files
                   2449:        $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
                   2450:        $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
                   2451:        $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
                   2452:        $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
                   2453:     }
                   2454:     if ($comp == 0) {
                   2455:        # Directories first, then sorted on name if no other sort critera
                   2456:        # available.
                   2457:        my $ad = ((-d "$fullname/$a")?"D":"F");
                   2458:        my $bd = ((-d "$fullname/$b")?"D":"F");
                   2459:        ($c=$a) =~ s|.*/||;
                   2460:        ($d=$b) =~ s|.*/||;
                   2461:        $comp = ("$ad$c" cmp "$bd$d");
                   2462:     }
                   2463:     return $comp;
                   2464: }
                   2465:
                   2466: # make A url for downloading
                   2467: sub download_url {
                   2468:     my ($url,$revision,$mimetype) = @_;
                   2469:
                   2470:     $revision =~ s/\b0\.//;
                   2471:
                   2472:     if (defined($checkout_magic)
                   2473:        && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
                   2474:        my ($path);
                   2475:        ($path = $where) =~ s|/[^/]*$|/|;
                   2476:        $url = "$scriptname/$checkoutMagic/${path}$url";
                   2477:     }
                   2478:     $url .= "?rev=$revision";
                   2479:     $url .= "&content-type=$mimetype" if (defined($mimetype));
                   2480:
                   2481:     return $url;
                   2482: }
                   2483:
                   2484: # Presents a link to download the
                   2485: # selected revision
                   2486: sub download_link {
                   2487:     my ($url,$revision,$textlink,$mimetype) = @_;
                   2488:     my ($fullurl) = download_url($url,$revision,$mimetype);
                   2489:     my ($paren) = $textlink =~ /^\(/;
                   2490:     $textlink =~ s/^\(// if ($paren);
                   2491:     $textlink =~ s/\)$// if ($paren);
                   2492:     print "(" if ($paren);
                   2493:     print "<A HREF=\"$fullurl";
                   2494:     print $barequery;
                   2495:     print "\"";
                   2496:     if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
                   2497:        print " target=\"cvs_checkout\"";
                   2498:        # we should have
                   2499:        #   'if (document.cvswin==null) document.cvswin=window.open(...'
                   2500:        # in order to allow the user to resize the window; otherwise
                   2501:        # the user may resize the window, but on next checkout - zap -
                   2502:        # its original (configured s. cvsweb.conf) size is back again
                   2503:        # .. annoying (if $extern_window_(width|height) is defined)
                   2504:        # but this if (..) solution is far from perfect
                   2505:        # what we need to do as well is
                   2506:        # 1) save cvswin in an invisible frame that always exists
                   2507:        #    (document.cvswin will be void on next load)
                   2508:        # 2) on close of the cvs_checkout - window set the cvswin
                   2509:        #    variable to 'null' again - so that it will be
                   2510:        #    reopenend with the configured size
                   2511:        # anyone a JavaScript programmer ?
                   2512:        # .. so here without if (..):
                   2513:        # currently, the best way is to comment out the size parameters
                   2514:        # ($extern_window...) in cvsweb.conf.
                   2515:        if ($use_java_script) {
                   2516:            print " onClick=\"window.open('$fullurl','cvs_checkout',";
                   2517:            print "'resizeable,scrollbars";
                   2518:            print ",status,toolbar" if (defined($mimetype)
                   2519:                && $mimetype eq "text/html");
                   2520:            print ",width=$extern_window_width" if (defined($extern_window_width));
                   2521:            print ",height=$extern_window_height" if (defined($extern_window_height));
                   2522:            print"');\"";
                   2523:        }
                   2524:     }
                   2525:     print "><b>$textlink</b></A>";
                   2526:     print ")" if ($paren);
                   2527: }
                   2528:
                   2529: # Returns a Query string with the
                   2530: # specified parameter toggled
                   2531: sub toggleQuery($$) {
                   2532:     my ($toggle,$value) = @_;
                   2533:     my ($newquery,$var);
                   2534:     my (%vars);
                   2535:     %vars = %input;
                   2536:     if (defined($value)) {
                   2537:        $vars{$toggle} = $value;
                   2538:     }
                   2539:     else {
                   2540:        $vars{$toggle} = $vars{$toggle} ? 0 : 1;
                   2541:     }
                   2542:     # Build a new query of non-default paramenters
                   2543:     $newquery = "";
                   2544:     foreach $var (@stickyvars) {
                   2545:        my ($value) = defined($vars{$var}) ? $vars{$var} : "";
                   2546:        my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
                   2547:        if ($value ne $default) {
                   2548:            $newquery .= "&" if ($newquery ne "");
                   2549:            $newquery .= urlencode($var) . "=" . urlencode($value);
                   2550:        }
                   2551:     }
                   2552:     if ($newquery) {
                   2553:        return '?' . $newquery;
                   2554:     }
                   2555:     return "";
                   2556: }
                   2557:
                   2558: sub urlencode {
                   2559:     my ($in) = @_;
                   2560:     my ($out);
                   2561:     ($out = $in) =~ s/([\000-+{-\377])/sprintf("%%%02x", ord($1))/ge;
                   2562:     return $out;
                   2563: }
                   2564:
                   2565: sub http_header {
                   2566:     my $content_type = shift || "text/html";
                   2567:     my $is_mod_perl = defined($ENV{'MOD_PERL'});
                   2568:     if ($is_mod_perl) {
                   2569:        Apache->request->content_type($content_type);
                   2570:     }
                   2571:     else {
                   2572:            print "Content-type: $content_type\n";
                   2573:     }
                   2574:     if ($allow_compress && $maycompress) {
                   2575:        my $fh = do {local(*FH);};
                   2576:        if (defined($GZIPBIN) && open($fh, "|$GZIPBIN -1 -c")) {
                   2577:            if ($is_mod_perl) {
                   2578:                    Apache->request->content_encoding("x-gzip");
                   2579:                    Apache->request->header_out(Vary => "Accept-Encoding");
                   2580:                    Apache->request->send_http_header;
                   2581:            }
                   2582:            else {
                   2583:                    print "Content-encoding: x-gzip\n";
                   2584:                    print "Vary: Accept-Encoding\n";  #RFC 2068, 14.43
                   2585:                    print "\n"; # Close headers
                   2586:            }
                   2587:            $| = 1; $| = 0; # Flush header output
                   2588:            select ($fh);
                   2589: #          print "<!-- gzipped -->" if ($content_type eq "text/html");
                   2590:        }
                   2591:        else {
                   2592:            if ($is_mod_perl) {
                   2593:                    Apache->request->send_http_header;
                   2594:            }
                   2595:            else {
                   2596:                    print "\n"; # Close headers
                   2597:            }
                   2598:            print "<font size=-1>Unable to find gzip binary in the \$PATH to compress output</font><br>";
                   2599:        }
                   2600:     }
                   2601:     else {
                   2602:            if ($is_mod_perl) {
                   2603:                    Apache->request->send_http_header;
                   2604:            }
                   2605:            else {
                   2606:                    print "\n"; # Close headers
                   2607:            }
                   2608:     }
                   2609: }
                   2610:
                   2611: sub html_header($) {
                   2612:     my ($title) = @_;
                   2613:     http_header();
                   2614:     print <<EOH;
                   2615: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
                   2616:  "http://www.w3.org/TR/REC-html40/loose.dtd">
                   2617: <html>
                   2618: <title>$title</title>
                   2619: <!-- hennerik CVSweb \$Revision: 1.79 $ \-->
                   2620: </head>
                   2621: $body_tag
                   2622: $logo <h1 align="center">$title</h1>
                   2623: EOH
                   2624: }
                   2625:
                   2626: sub html_footer {
                   2627:     return "<hr noshade><address>$address</address>\n";
                   2628: }
                   2629:
                   2630: sub link_tags
                   2631: {
                   2632:     my ($tags) = @_;
                   2633:     my ($ret) = "";
                   2634:     my ($fileurl,$filename);
                   2635:
                   2636:     ($filename = $where) =~ s/^.*\///;
                   2637:     $fileurl = urlencode($filename);
                   2638:
                   2639:     foreach my $sym (split(", ", $tags)) {
                   2640:        $ret .= ",\n" if ($ret ne "");
                   2641:        $ret .= "<A HREF=\"$fileurl"
                   2642:                . toggleQuery('only_with_tag',$sym) . "\">$sym</A>";
                   2643:     }
                   2644:     return $ret."\n";
                   2645: }
                   2646:
                   2647: #
                   2648: # See if a module is listed in the config file's @HideModule list.
                   2649: #
                   2650: sub forbidden_module {
                   2651:     my($module) = @_;
                   2652:
                   2653:     return ("§$module§" =~ /$HideModules/);
                   2654: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>