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

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.47

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

CVSweb