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

Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.1

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

CVSweb