[BACK]Return to cvsweb.cgi CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / cvsweb

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.46

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

CVSweb