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

Annotation of cvsweb/cvsweb.cgi, Revision 3.100

3.55      knu         1: #!/usr/bin/perl -wT
1.1       jfieber     2: #
3.1       knu         3: # cvsweb - a CGI interface to CVS trees.
1.1       jfieber     4: #
3.12      knu         5: # Written in their spare time by
3.1       knu         6: #             Bill Fenner      <fenner@FreeBSD.org>   (original work)
                      7: # extended by Henner Zeller    <zeller@think.de>,
3.12      knu         8: #             Henrik Nordstrom <hno@hem.passagen.se>
3.1       knu         9: #             Ken Coar         <coar@Apache.Org>
                     10: #             Dick Balaska     <dick@buckosoft.com>
                     11: #             Akinori MUSHA    <knu@FreeBSD.org>
3.23      knu        12: #             Jens-Uwe Mager   <jum@helios.de>
3.89      knu        13: #             Ville Skyttä     <ville.skytta@iki.fi> (html cleanup)
3.1       knu        14: #
                     15: # Based on:
                     16: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
3.5       knu        17: #   http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1       jfieber    18: #
1.21      wosch      19: # Copyright (c) 1996-1998 Bill Fenner
3.1       knu        20: #           (c) 1998-1999 Henner Zeller
                     21: #          (c) 1999      Henrik Nordstrom
3.89      knu        22: #          (c) 2000-2002 Akinori MUSHA
1.21      wosch      23: # All rights reserved.
                     24: #
                     25: # Redistribution and use in source and binary forms, with or without
                     26: # modification, are permitted provided that the following conditions
                     27: # are met:
                     28: # 1. Redistributions of source code must retain the above copyright
                     29: #    notice, this list of conditions and the following disclaimer.
                     30: # 2. Redistributions in binary form must reproduce the above copyright
                     31: #    notice, this list of conditions and the following disclaimer in the
                     32: #    documentation and/or other materials provided with the distribution.
                     33: #
                     34: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     35: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     36: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     37: # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     38: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     39: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     40: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     41: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     42: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     43: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     44: # SUCH DAMAGE.
                     45: #
3.87      knu        46: # $FreeBSD$
3.82      knu        47: # $Id: cvsweb.cgi,v 1.112 2001/07/24 13:03:16 hzeller Exp $
3.85      knu        48: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 3.84 2001/10/07 20:50:10 knu Exp $
1.21      wosch      49: #
3.1       knu        50: ###
                     51:
3.55      knu        52: require 5.000;
                     53:
3.1       knu        54: use strict;
1.21      wosch      55:
3.1       knu        56: use vars qw (
3.64      knu        57:     $cvsweb_revision
3.60      knu        58:     $mydir $uname $config $allow_version_select $verbose
3.56      knu        59:     @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr
                     60:     %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
3.37      knu        61:     @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS
3.1       knu        62:     %alltags @tabcolors %fileinfo %tags @branchnames %nameprinted
                     63:     %symrev %revsym @allrevisions %date %author @revdisplayorder
3.17      knu        64:     @revisions %state %difflines %log %branchpoint @revorder
3.54      knu        65:     $prcgi @prcategories $re_prcategories $prkeyword $re_prkeyword $mancgi
3.1       knu        66:     $checkoutMagic $doCheckout $scriptname $scriptwhere
3.99      knu        67:     $where $pathinfo $Browser $nofilelinks $maycompress
                     68:     @stickyvars @unsafevars
3.3       knu        69:     %funcline_regexp $is_mod_perl
3.34      knu        70:     $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
3.1       knu        71:     %input $query $barequery $sortby $bydate $byrev $byauthor
3.37      knu        72:     $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot
3.86      knu        73:     $mimetype $charset $output_filter $defaultTextPlain $defaultViewable
3.58      knu        74:     $command_path %CMD $allow_compress
                     75:     $backicon $diricon $fileicon
3.40      knu        76:     $fullname $newname $cvstreedefault
                     77:     $body_tag $body_tag_for_src $logo $defaulttitle $address
3.26      knu        78:     $long_intro $short_instruction $shortLogLen
3.1       knu        79:     $show_author $dirtable $tablepadding $columnHeaderColorDefault
3.3       knu        80:     $columnHeaderColorSorted $hr_breakable $showfunc $hr_ignwhite
3.1       knu        81:     $hr_ignkeysubst $diffcolorHeading $diffcolorEmpty $diffcolorRemove
                     82:     $diffcolorChange $diffcolorAdd $diffcolorDarkChange $difffontface
                     83:     $difffontsize $inputTextSize $mime_types $allow_annotate
                     84:     $allow_markup $use_java_script $open_extern_window
                     85:     $extern_window_width $extern_window_height $edit_option_form
3.51      knu        86:     $show_subdir_lastmod $show_log_in_markup $preformat_in_markup $v
3.1       knu        87:     $navigationHeaderColor $tableBorderColor $markupLogColor
3.81      knu        88:     $tabstop $state $annTable $sel $curbranch @HideModules @ForbiddenFiles
3.1       knu        89:     $module $use_descriptions %descriptions @mytz $dwhere $moddate
3.61      knu        90:     $use_moddate $has_zlib $gzip_open
3.77      knu        91:     $allow_tar @tar_options @gzip_options @zip_options @cvs_options
3.32      knu        92:     $LOG_FILESEPARATOR $LOG_REVSEPARATOR
3.100   ! knu        93:     $tmpdir $HTML_DOCTYPE
3.1       knu        94: );
                     95:
3.12      knu        96: sub printDiffSelect($);
3.37      knu        97: sub printDiffLinks($$);
                     98: sub printLogSortSelect($);
3.12      knu        99: sub findLastModifiedSubdirs(@);
3.36      knu       100: sub htmlify_sub(&$);
3.12      knu       101: sub htmlify($;$);
3.20      knu       102: sub spacedHtmlText($;$);
3.12      knu       103: sub link($$);
                    104: sub revcmp($$);
                    105: sub fatal($$);
                    106: sub redirect($);
                    107: sub safeglob($);
3.58      knu       108: sub search_path($);
3.12      knu       109: sub getMimeTypeFromSuffix($);
3.24      knu       110: sub head($;$);
                    111: sub scan_directives(@);
3.86      knu       112: sub openOutputFilter();
3.12      knu       113: sub doAnnotate($$);
                    114: sub doCheckout($$);
                    115: sub cvswebMarkup($$$);
                    116: sub viewable($);
                    117: sub doDiff($$$$$$);
                    118: sub getDirLogs($$@);
                    119: sub readLog($;$);
                    120: sub printLog($;$);
                    121: sub doLog($);
                    122: sub flush_diff_rows($$$$);
                    123: sub human_readable_diff($);
                    124: sub navigateHeader($$$$$);
                    125: sub plural_write($$);
                    126: sub readableTime($$);
                    127: sub clickablePath($$);
                    128: sub chooseCVSRoot();
                    129: sub chooseMirror();
                    130: sub fileSortCmp();
                    131: sub download_url($$;$);
                    132: sub download_link($$$;$);
                    133: sub toggleQuery($$);
                    134: sub urlencode($);
3.35      knu       135: sub htmlquote($);
3.36      knu       136: sub htmlunquote($);
3.48      knu       137: sub hrefquote($);
3.12      knu       138: sub http_header(;$);
                    139: sub html_header($);
                    140: sub html_footer();
                    141: sub link_tags($);
3.81      knu       142: sub forbidden_file($);
3.12      knu       143: sub forbidden_module($);
                    144:
3.1       knu       145: ##### Start of Configuration Area ########
3.59      knu       146: delete $ENV{PATH};
                    147:
3.90      knu       148: $cvsweb_revision = '2.0.1';
3.64      knu       149:
3.100   ! knu       150: use File::Basename ();
3.11      knu       151:
3.100   ! knu       152: ($mydir) = (File::Basename::dirname($0) =~ /(.*)/);    # untaint
3.58      knu       153:
3.12      knu       154: # == EDIT this ==
3.28      knu       155: # Locations to search for user configuration, in order:
3.80      knu       156: for ("$mydir/cvsweb.conf", '/usr/local/etc/cvsweb/cvsweb.conf') {
                    157:        if (defined($_) && -r $_) {
                    158:                $config = $_;
                    159:                last;
                    160:        }
3.11      knu       161: }
3.1       knu       162:
                    163: # == Configuration defaults ==
                    164: # Defaults for configuration variables that shouldn't need
                    165: # to be configured..
                    166: $allow_version_select = 1;
                    167:
                    168: ##### End of Configuration Area   ########
                    169:
                    170: ######## Configuration variables #########
                    171: # These are defined to allow checking with perl -cw
3.80      knu       172: @CVSrepositories = @CVSROOT = %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS =
                    173:     %MTYPES = %tags = %alltags = @tabcolors = %fileinfo = ();
                    174: $cvstreedefault = $body_tag = $body_tag_for_src = $logo = $defaulttitle =
                    175:     $address = $long_intro = $short_instruction = $shortLogLen = $show_author =
                    176:     $dirtable = $tablepadding = $columnHeaderColorDefault =
                    177:     $columnHeaderColorSorted = $hr_breakable = $showfunc = $hr_ignwhite =
                    178:     $hr_ignkeysubst = $diffcolorHeading = $diffcolorEmpty = $diffcolorRemove =
                    179:     $diffcolorChange = $diffcolorAdd  = $diffcolorDarkChange = $difffontface   =
                    180:     $difffontsize    = $inputTextSize = $mime_types          = $allow_annotate =
                    181:     $allow_markup        = $use_java_script      = $open_extern_window =
                    182:     $extern_window_width = $extern_window_height = $edit_option_form   =
                    183:     $show_subdir_lastmod = $show_log_in_markup = $v = $navigationHeaderColor =
                    184:     $tableBorderColor = $markupLogColor = $tabstop = $use_moddate = $moddate =
3.100   ! knu       185:     $gzip_open = $HTML_DOCTYPE = undef;
3.80      knu       186: $tmpdir = defined($ENV{TMPDIR}) ? $ENV{TMPDIR} : "/var/tmp";
1.21      wosch     187:
3.32      knu       188: $LOG_FILESEPARATOR = q/^={77}$/;
3.80      knu       189: $LOG_REVSEPARATOR  = q/^-{28}$/;
3.32      knu       190:
3.37      knu       191: @DIFFTYPES = qw(h H u c s);
                    192: @DIFFTYPES{@DIFFTYPES} = (
3.80      knu       193:        {
                    194:                'descr'   => 'colored',
                    195:                'opts'    => ['-u'],
                    196:                'colored' => 1,
                    197:        },
                    198:        {
                    199:                'descr'   => 'long colored',
                    200:                'opts'    => ['--unified=15'],
                    201:                'colored' => 1,
                    202:        },
                    203:        {
                    204:                'descr'   => 'unified',
                    205:                'opts'    => ['-u'],
                    206:                'colored' => 0,
                    207:        },
                    208:        {
                    209:                'descr'   => 'context',
                    210:                'opts'    => ['-c'],
                    211:                'colored' => 0,
                    212:        },
                    213:        {
                    214:                'descr'   => 'side by side',
                    215:                'opts'    => ['--side-by-side', '--width=164'],
                    216:                'colored' => 0,
                    217:        },
                    218: );
3.37      knu       219:
                    220: @LOGSORTKEYS = qw(cvs date rev);
                    221: @LOGSORTKEYS{@LOGSORTKEYS} = (
3.80      knu       222:        {
                    223:                'descr' => 'Not sorted',
                    224:        },
                    225:        {
                    226:                'descr' => 'Commit date',
                    227:        },
                    228:        {
                    229:                'descr' => 'Revision',
                    230:        },
                    231: );
3.37      knu       232:
3.100   ! knu       233: $HTML_DOCTYPE =
        !           234:   '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">';
        !           235:
3.1       knu       236: ##### End of configuration variables #####
                    237:
3.100   ! knu       238: use Time::Local ();
        !           239: use IPC::Open2 qw(open2);
1.1       jfieber   240:
3.23      knu       241: # Check if the zlib C library interface is installed, and if yes
                    242: # we can avoid using the extra gzip process.
3.80      knu       243: eval { require Compress::Zlib; };
3.23      knu       244: $has_zlib = !$@;
                    245:
3.80      knu       246: $verbose       = $v;
3.1       knu       247: $checkoutMagic = "~checkout~";
3.80      knu       248: $pathinfo      = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
                    249: $where         = $pathinfo;
3.63      knu       250: $doCheckout = ($where =~ m|^/$checkoutMagic/|);
                    251: $where =~ s|^/$checkoutMagic/|/|;
                    252: $where =~ s|^/||;
3.3       knu       253: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
3.63      knu       254: $scriptname =~ s|^/*|/|;
                    255:
3.64      knu       256: # Let's workaround thttpd's stupidity..
3.63      knu       257: if ($scriptname =~ m|/$|) {
3.80      knu       258:        $pathinfo .= '/';
                    259:        my $re = quotemeta $pathinfo;
                    260:        $scriptname =~ s/$re$//;
3.63      knu       261: }
                    262:
3.3       knu       263: $scriptwhere = $scriptname;
3.63      knu       264: $scriptwhere .= '/' . urlencode($where);
                    265: $where = '/' if ($where eq '');
3.3       knu       266:
                    267: $is_mod_perl = defined($ENV{MOD_PERL});
3.1       knu       268:
                    269: # in lynx, it it very annoying to have two links
                    270: # per file, so disable the link at the icon
                    271: # in this case:
3.44      knu       272: $Browser = $ENV{HTTP_USER_AGENT} || '';
3.80      knu       273: $is_links    = ($Browser =~ m`^Links `);
                    274: $is_lynx     = ($Browser =~ m`^Lynx/`i);
                    275: $is_w3m      = ($Browser =~ m`^w3m/`i);
                    276: $is_msie     = ($Browser =~ m`MSIE`);
3.5       knu       277: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
3.3       knu       278:
3.34      knu       279: $is_textbased = ($is_links || $is_lynx || $is_w3m);
3.5       knu       280:
                    281: $nofilelinks = $is_textbased;
3.1       knu       282:
                    283: # newer browsers accept gzip content encoding
                    284: # and state this in a header
                    285: # (netscape did always but didn't state it)
                    286: # It has been reported that these
                    287: #  braindamaged MS-Internet Exploders claim that they
                    288: # accept gzip .. but don't in fact and
                    289: # display garbage then :-/
3.23      knu       290: # Turn off gzip if running under mod_perl and no zlib is available,
                    291: # piping does not work as expected inside the server.
3.80      knu       292: $maycompress =
                    293:     (((defined($ENV{HTTP_ACCEPT_ENCODING})
                    294:     && $ENV{HTTP_ACCEPT_ENCODING} =~ m`gzip`) || $is_mozilla3) && !$is_msie
                    295:     && !($is_mod_perl && !$has_zlib));
3.1       knu       296:
                    297: # put here the variables we need in order
                    298: # to hold our state - they will be added (with
3.12      knu       299: # their current value) to any link/query string
3.1       knu       300: # you construct
3.6       knu       301: @stickyvars = qw(cvsroot hideattic sortby logsort f only_with_tag);
3.97      knu       302: @unsafevars = qw(logsort only_with_tag r1 r2 rev sortby tr1 tr2);
1.1       jfieber   303:
3.1       knu       304: if (-f $config) {
3.95      knu       305:        do "$config" or &fatal(
3.80      knu       306:                "500 Internal Error",
                    307:                sprintf(
3.89      knu       308:                        'Error in loading configuration file: %s<br><br>%s<br>',
3.80      knu       309:                        $config,
                    310:                        &htmlify($@)
                    311:                )
                    312:        );
3.27      knu       313: } else {
3.80      knu       314:        &fatal("500 Internal Error",
                    315:                'Configuration not found.  Set the variable <code>$config</code> '
                    316:                . 'in cvsweb.cgi to your <b>cvsweb.conf</b> configuration file first.'
                    317:        );
3.1       knu       318: }
                    319:
                    320: undef %input;
3.3       knu       321: $query = $ENV{QUERY_STRING};
                    322:
3.12      knu       323: if (defined($query) && $query ne '') {
3.80      knu       324:        foreach (split (/&/, $query)) {
                    325:                y/+/ /;
                    326:                s/%(..)/sprintf("%c", hex($1))/ge;    # unquote %-quoted
                    327:                if (/(\S+)=(.*)/) {
                    328:                        $input{$1} = $2 if ($2 ne "");
                    329:                } else {
                    330:                        $input{$_}++;
                    331:                }
3.1       knu       332:        }
1.7       fenner    333: }
1.10      wosch     334:
3.12      knu       335: # For backwards compability, set only_with_tag to only_on_branch if set.
3.1       knu       336: $input{only_with_tag} = $input{only_on_branch}
                    337:     if (defined($input{only_on_branch}));
3.97      knu       338:
                    339: # Prevent cross-site scripting
                    340: foreach (@unsafevars) {
                    341:     if (defined($input{$_}) && $input{$_} =~ /[^\w\-.]/) {
                    342:        fatal("500 Internal Error", "Malformed query string ($_)");
                    343:     }
                    344: }
                    345:
                    346: if (defined($input{"content-type"})) {
                    347:        fatal("500 Internal Error", "Unsupported content-type")
                    348:            if ($input{"content-type"} !~ /^[-0-9A-Za-z]+\/[-0-9A-Za-z]+$/);
                    349: }
1.10      wosch     350:
3.1       knu       351: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
1.10      wosch     352:
3.80      knu       353: foreach (keys %DEFAULTVALUE) {
                    354:
                    355:        # replace not given parameters with the default parameters
                    356:        if (!defined($input{$_}) || $input{$_} eq "") {
                    357:
                    358:                # Empty Checkboxes in forms return -- nothing. So we define a helper
                    359:                # variable in these forms (copt) which indicates that we just set
                    360:                # parameters with a checkbox
                    361:                if (!defined($input{"copt"})) {
                    362:
                    363:                        # 'copt' isn't defined --> empty input is not the result
                    364:                        # of empty input checkbox --> set default
                    365:                        $input{$_} = $DEFAULTVALUE{$_}
                    366:                            if (defined($DEFAULTVALUE{$_}));
                    367:                } else {
                    368:
                    369:                        # 'copt' is defined -> the result of empty input checkbox
                    370:                        # -> set to zero (disable) if default is a boolean (0|1).
                    371:                        $input{$_} = 0
                    372:                            if (defined($DEFAULTVALUE{$_})
                    373:                            && ($DEFAULTVALUE{$_} eq "0"
                    374:                            || $DEFAULTVALUE{$_} eq "1"));
                    375:                }
3.1       knu       376:        }
1.10      wosch     377: }
3.12      knu       378:
3.1       knu       379: $barequery = "";
3.31      knu       380: my @barequery;
3.1       knu       381: foreach (@stickyvars) {
3.80      knu       382:
                    383:        # construct a query string with the sticky non default parameters set
                    384:        if (defined($input{$_}) && $input{$_} ne ''
                    385:            && !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_}))
                    386:        {
                    387:                push @barequery,
                    388:                    join ('=', urlencode($_), urlencode($input{$_}));
                    389:        }
3.1       knu       390: }
3.80      knu       391:
3.1       knu       392: # is there any query ?
3.31      knu       393: if (@barequery) {
3.80      knu       394:        $barequery = join ('&', @barequery);
                    395:        $query     = "?$barequery";
                    396:        $barequery = "&$barequery";
                    397: } else {
                    398:        $query = "";
3.1       knu       399: }
3.31      knu       400: undef @barequery;
3.1       knu       401:
3.57      knu       402: if (defined($input{path})) {
3.80      knu       403:        redirect("$scriptname/$input{path}$query");
3.57      knu       404: }
                    405:
3.1       knu       406: # get actual parameters
3.80      knu       407: $sortby   = $input{"sortby"};
                    408: $bydate   = 0;
                    409: $byrev    = 0;
3.1       knu       410: $byauthor = 0;
3.80      knu       411: $bylog    = 0;
                    412: $byfile   = 0;
3.1       knu       413: if ($sortby eq "date") {
3.80      knu       414:        $bydate = 1;
                    415: } elsif ($sortby eq "rev") {
                    416:        $byrev = 1;
                    417: } elsif ($sortby eq "author") {
                    418:        $byauthor = 1;
                    419: } elsif ($sortby eq "log") {
                    420:        $bylog = 1;
                    421: } else {
                    422:        $byfile = 1;
3.1       knu       423: }
                    424:
3.37      knu       425: $defaultDiffType = $input{'f'};
3.1       knu       426:
3.3       knu       427: $logsort = $input{'logsort'};
1.10      wosch     428:
3.95      knu       429: {
                    430:        my @tmp = @CVSrepositories;
                    431:        my @pair;
3.56      knu       432:
3.95      knu       433:        while (@pair = splice(@tmp, 0, 2)) {
                    434:                my ($key,   $val)     = @pair;
                    435:                my ($descr, $cvsroot) = @$val;
                    436:
                    437:                next if !-d $cvsroot;
                    438:
                    439:                $CVSROOTdescr{$key} = $descr;
                    440:                $CVSROOT{$key}      = $cvsroot;
                    441:                push @CVSROOT, $key;
                    442:        }
3.56      knu       443: }
1.12      fenner    444:
3.1       knu       445: ## Default CVS-Tree
                    446: if (!defined($CVSROOT{$cvstreedefault})) {
3.80      knu       447:        &fatal("500 Internal Error",
3.81      knu       448:                "<code>\$cvstreedefault</code> points to a repository ($cvstreedefault) "
3.80      knu       449:                . "not defined in <code>%CVSROOT</code> "
                    450:                . "(edit your configuration file $config)");
3.1       knu       451: }
                    452:
                    453: # alternate CVS-Tree, configured in cvsweb.conf
                    454: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
3.80      knu       455:        $cvstree = $input{'cvsroot'};
3.1       knu       456: } else {
3.80      knu       457:        $cvstree = $cvstreedefault;
1.10      wosch     458: }
                    459:
3.1       knu       460: $cvsroot = $CVSROOT{$cvstree};
1.10      wosch     461:
3.1       knu       462: # create icons out of description
3.32      knu       463: my $k;
3.31      knu       464: foreach $k (keys %ICONS) {
3.80      knu       465:        no strict 'refs';
                    466:        my ($itxt, $ipath, $iwidth, $iheight) = @{$ICONS{$k}};
                    467:        if ($ipath) {
                    468:                ${"${k}icon"} =
                    469:                    sprintf(
3.89      knu       470:                        '<img src="%s" alt="%s" border="0" width="%d" height="%d">',
3.80      knu       471:                        hrefquote($ipath), htmlquote($itxt), $iwidth, $iheight)
                    472:        } else {
                    473:                ${"${k}icon"} = $itxt;
                    474:        }
1.24      wosch     475: }
3.31      knu       476: undef $k;
1.24      wosch     477:
3.27      knu       478: my $config_cvstree = "$config-$cvstree";
                    479:
3.1       knu       480: # Do some special configuration for cvstrees
3.27      knu       481: if (-f $config_cvstree) {
3.95      knu       482:        do "$config_cvstree" or &fatal(
3.80      knu       483:                "500 Internal Error",
                    484:                sprintf(
3.89      knu       485:                        'Error in loading configuration file: %s<br><br>%s<br>',
3.80      knu       486:                        $config_cvstree,
                    487:                        &htmlify($@)
                    488:                )
                    489:        );
3.27      knu       490: }
3.31      knu       491: undef $config_cvstree;
3.1       knu       492:
3.80      knu       493: $re_prcategories = '(?:' . join ('|', @prcategories) . ')' if @prcategories;
3.54      knu       494: $re_prkeyword = quotemeta($prkeyword) if defined($prkeyword);
3.17      knu       495: $prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.24      wosch     496:
3.80      knu       497: $fullname         = "$cvsroot/$where";
                    498: $mimetype         = &getMimeTypeFromSuffix($fullname);
3.1       knu       499: $defaultTextPlain = ($mimetype eq "text/plain");
3.80      knu       500: $defaultViewable  = $allow_markup && viewable($mimetype);
3.1       knu       501:
3.63      knu       502: my $rewrite = 0;
                    503:
                    504: if ($pathinfo =~ m|//|) {
3.80      knu       505:        $pathinfo =~ y|/|/|s;
                    506:        $rewrite = 1;
3.63      knu       507: }
                    508:
                    509: if (-d $fullname && $pathinfo !~ m|/$|) {
3.80      knu       510:        $pathinfo .= '/';
                    511:        $rewrite = 1;
3.63      knu       512: }
                    513:
                    514: if (!-d $fullname && $pathinfo =~ m|/$|) {
3.80      knu       515:        chop $pathinfo;
                    516:        $rewrite = 1;
3.63      knu       517: }
                    518:
                    519: if ($rewrite) {
3.80      knu       520:        redirect($scriptname . urlencode($pathinfo) . $query);
3.1       knu       521: }
                    522:
3.63      knu       523: undef $rewrite;
                    524:
3.1       knu       525: if (!-d $cvsroot) {
3.80      knu       526:        &fatal("500 Internal Error",
3.89      knu       527:                '$CVSROOT not found!<p>The server on which the CVS tree lives is probably down.  Please try again in a few minutes.'
3.80      knu       528:        );
3.1       knu       529: }
                    530:
                    531: #
                    532: # See if the module is in our forbidden list.
                    533: #
                    534: $where =~ m:([^/]*):;
                    535: $module = $1;
                    536: if ($module && &forbidden_module($module)) {
3.80      knu       537:        &fatal("403 Forbidden", "Access to $where forbidden.");
3.1       knu       538: }
3.46      knu       539:
                    540: #
                    541: # Handle tarball downloads before any headers are output.
                    542: #
                    543: if ($input{tarball}) {
3.80      knu       544:        &fatal("403 Forbidden", "Downloading tarballs is prohibited.")
                    545:            unless $allow_tar;
                    546:        my ($module) = ($where =~ m,^/?(.*),);    # untaint
                    547:        $module =~ s,/([^/]*)$,,;
                    548:        my ($ext)     = ($1      =~ /(\.tar\.gz|\.zip)$/);
                    549:        my ($basedir) = ($module =~ m,([^/]+)$,);
                    550:
                    551:        if ($basedir eq '' || $module eq '') {
                    552:                &fatal("500 Internal Error",
                    553:                        "You cannot download the top level directory.");
                    554:        }
                    555:
3.88      knu       556:        my $tmpexportdir = "$tmpdir/.cvsweb.$$." . int(time);
3.80      knu       557:
3.88      knu       558:        mkdir($tmpexportdir, 0700)
3.80      knu       559:            or &fatal("500 Internal Error",
                    560:                "Unable to make temporary directory: $!");
                    561:
                    562:        my @fatal;
                    563:
                    564:        my $tag =
                    565:            (exists $input{only_with_tag} && length $input{only_with_tag}) ?
                    566:            $input{only_with_tag} : "HEAD";
                    567:
3.88      knu       568:        if ($tag eq 'MAIN') {
                    569:            $tag = 'HEAD';
                    570:        }
                    571:
3.80      knu       572:        if (system $CMD{cvs}, @cvs_options, '-Qd', $cvsroot, 'export', '-r',
3.88      knu       573:            $tag, '-d', "$tmpexportdir/$basedir", $module)
3.80      knu       574:        {
                    575:                @fatal = ("500 Internal Error", "cvs co failure: $!: $module");
                    576:        } else {
                    577:                $| = 1;    # Essential to get the buffering right.
3.46      knu       578:
3.80      knu       579:                if ($ext eq '.tar.gz') {
3.89      knu       580:                        print "Content-Type: application/x-gzip\r\n\r\n";
3.46      knu       581:
3.80      knu       582:                        system
3.88      knu       583:                            "$CMD{tar} @tar_options -cf - -C $tmpexportdir $basedir | $CMD{gzip} @gzip_options -c"
3.80      knu       584:                            and @fatal =
                    585:                            ("500 Internal Error",
                    586:                                "tar zc failure: $!: $basedir");
                    587:                } elsif ($ext eq '.zip' && $CMD{zip}) {
3.89      knu       588:                        print "Content-Type: application/zip\r\n\r\n";
3.80      knu       589:
                    590:                        system
3.88      knu       591:                            "cd $tmpexportdir && $CMD{zip} @zip_options -r - $basedir"
3.80      knu       592:                            and @fatal =
                    593:                            ("500 Internal Error", "zip failure: $!: $basedir");
                    594:                } else {
                    595:                        @fatal =
                    596:                            ("500 Internal Error", "unsupported file type");
                    597:                }
3.77      knu       598:        }
3.46      knu       599:
3.88      knu       600:        system $CMD{rm}, '-rf', $tmpexportdir if -d $tmpexportdir;
3.46      knu       601:
3.80      knu       602:        &fatal(@fatal) if @fatal;
3.46      knu       603:
3.80      knu       604:        exit;
3.46      knu       605: }
                    606:
3.1       knu       607: ##############################
                    608: # View a directory
                    609: ###############################
3.46      knu       610: if (-d $fullname) {
3.80      knu       611:        my $dh = do { local (*DH); };
3.95      knu       612:        opendir($dh, $fullname) or &fatal("404 Not Found", "$where: $!");
3.1       knu       613:        my @dir = readdir($dh);
                    614:        closedir($dh);
                    615:        my @subLevelFiles = findLastModifiedSubdirs(@dir)
                    616:            if ($show_subdir_lastmod);
3.80      knu       617:        getDirLogs($cvsroot, $where, @subLevelFiles);
3.1       knu       618:
                    619:        if ($where eq '/') {
3.80      knu       620:                html_header($defaulttitle);
                    621:                $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
                    622:                print $long_intro;
                    623:        } else {
                    624:                html_header($where);
                    625:                print $short_instruction;
3.1       knu       626:        }
                    627:
                    628:        my $descriptions;
3.80      knu       629:        if (($use_descriptions) && open(DESC, "<$cvsroot/CVSROOT/descriptions"))
                    630:        {
                    631:                while (<DESC>) {
                    632:                        chomp;
                    633:                        my ($dir, $description) = /(\S+)\s+(.*)/;
                    634:                        $descriptions{$dir} = $description;
                    635:                }
3.1       knu       636:        }
                    637:
3.89      knu       638:        print "<p><a name=\"dirlist\"></a></p>\n";
3.80      knu       639:
3.1       knu       640:        # give direct access to dirs
                    641:        if ($where eq '/') {
3.80      knu       642:                chooseMirror ();
                    643:                chooseCVSRoot ();
                    644:        } else {
                    645:                print "<p>Current directory: <b>", &clickablePath($where, 0),
3.89      knu       646:                    "</b></p>\n";
3.1       knu       647:
3.89      knu       648:                print "<p>Current tag: <b>", $input{only_with_tag},"</b></p>\n"
3.80      knu       649:                    if $input{only_with_tag};
1.16      wosch     650:
1.1       jfieber   651:        }
3.12      knu       652:
3.89      knu       653:        print "<hr noshade>\n";
3.1       knu       654:
3.89      knu       655:        # Using <menu> in this manner violates the HTML2.0 spec but
1.1       jfieber   656:        # provides the results that I want in most browsers.  Another
                    657:        # case of layout spooging up HTML.
3.12      knu       658:
3.1       knu       659:        my $infocols = 0;
                    660:        if ($dirtable) {
3.100   ! knu       661:                print "<table style=\"border-width: 0";
        !           662:                print "; background-color: $tableBorderColor"
        !           663:                    if (defined $tableBorderColor);
        !           664:                print "\" width=\"100%\" cellspacing=\"1\" cellpadding=\"$tablepadding\">\n";
3.1       knu       665:                $infocols++;
3.100   ! knu       666:                printf "<tr>\n<th style=\"text-align: left; background-color: %s\">",
3.80      knu       667:                    $byfile ? $columnHeaderColorSorted :
                    668:                    $columnHeaderColorDefault;
                    669:
                    670:                if ($byfile) {
                    671:                        print 'File';
3.35      knu       672:                } else {
3.80      knu       673:                        print &link(
                    674:                                'File',
                    675:                                sprintf(
                    676:                                        './%s#dirlist',
                    677:                                        &toggleQuery("sortby", "file")
                    678:                                )
                    679:                        );
3.35      knu       680:                }
3.100   ! knu       681:                print "</th>\n";
3.80      knu       682:
                    683:                # do not display the other column-headers, if we do not have any files
                    684:                # with revision information:
                    685:                if (scalar(%fileinfo)) {
                    686:                        $infocols++;
3.100   ! knu       687:                        printf '<th style="text-align: left; background-color: %s">',
3.80      knu       688:                            $byrev ? $columnHeaderColorSorted :
                    689:                            $columnHeaderColorDefault;
                    690:
                    691:                        if ($byrev) {
                    692:                                print 'Rev.';
                    693:                        } else {
                    694:                                print &link(
                    695:                                        'Rev.',
                    696:                                        sprintf(
                    697:                                                './%s#dirlist',
                    698:                                                &toggleQuery("sortby", "rev")
                    699:                                        )
                    700:                                );
                    701:                        }
3.100   ! knu       702:                        print "</th>\n";
3.80      knu       703:                        $infocols++;
3.100   ! knu       704:                        printf '<th style="text-align: left; background-color: %s">',
3.80      knu       705:                            $bydate ? $columnHeaderColorSorted :
                    706:                            $columnHeaderColorDefault;
                    707:
                    708:                        if ($bydate) {
                    709:                                print 'Age';
                    710:                        } else {
                    711:                                print &link(
                    712:                                        'Age',
                    713:                                        sprintf(
                    714:                                                './%s#dirlist',
                    715:                                                &toggleQuery("sortby", "date")
                    716:                                        )
                    717:                                );
                    718:                        }
3.100   ! knu       719:                        print "</th>\n";
3.80      knu       720:
                    721:                        if ($show_author) {
                    722:                                $infocols++;
3.100   ! knu       723:                                printf '<th style="text-align: left; background-color: %s">',
3.80      knu       724:                                    $byauthor ? $columnHeaderColorSorted :
                    725:                                    $columnHeaderColorDefault;
                    726:
                    727:                                if ($byauthor) {
                    728:                                        print 'Author';
                    729:                                } else {
                    730:                                        print &link(
                    731:                                                'Author',
                    732:                                                sprintf(
                    733:                                                        './%s#dirlist',
                    734:                                                        &toggleQuery(
                    735:                                                                "sortby",
                    736:                                                                "author"
                    737:                                                        )
                    738:                                                )
                    739:                                        );
                    740:                                }
3.100   ! knu       741:                                print "</th>\n";
3.80      knu       742:                        }
                    743:                        $infocols++;
3.100   ! knu       744:                        printf '<th style="text-align: left; background-color: %s">',
3.80      knu       745:                            $bylog ? $columnHeaderColorSorted :
                    746:                            $columnHeaderColorDefault;
                    747:
                    748:                        if ($bylog) {
                    749:                                print 'Last log entry';
                    750:                        } else {
                    751:                                print &link(
                    752:                                        'Last log entry',
                    753:                                        sprintf(
                    754:                                                './%s#dirlist',
                    755:                                                &toggleQuery("sortby", "log")
                    756:                                        )
                    757:                                );
                    758:                        }
3.100   ! knu       759:                        print "</th>\n";
3.80      knu       760:                } elsif ($use_descriptions) {
3.100   ! knu       761:                        printf '<th style="text-align: left; background-color: s">',
3.80      knu       762:                            $columnHeaderColorDefault;
3.100   ! knu       763:                        print "Description</th>\n";
3.80      knu       764:                        $infocols++;
3.1       knu       765:                }
3.80      knu       766:                print "</tr>\n";
                    767:        } else {
                    768:                print "<menu>\n";
3.1       knu       769:        }
                    770:        my $dirrow = 0;
3.12      knu       771:
3.1       knu       772:        my $i;
1.9       fenner    773:        lookingforattic:
3.80      knu       774:        for ($i = 0 ; $i <= $#dir ; $i++) {
1.9       fenner    775:                if ($dir[$i] eq "Attic") {
3.80      knu       776:                        last lookingforattic;
1.9       fenner    777:                }
                    778:        }
3.80      knu       779:
                    780:        if (!$input{'hideattic'} && ($i <= $#dir)
                    781:            && opendir($dh, $fullname . "/Attic"))
                    782:        {
                    783:                splice(@dir, $i, 1, grep((s|^|Attic/|, !m|/\.|), readdir($dh)));
                    784:                closedir($dh);
1.9       fenner    785:        }
3.1       knu       786:
3.80      knu       787:        my $hideAtticToggleLink =
                    788:            $input{'hideattic'} ? '' :
                    789:            &link('[Hide]', sprintf('./%s#dirlist', &toggleQuery("hideattic")));
3.1       knu       790:
1.9       fenner    791:        # Sort without the Attic/ pathname.
3.1       knu       792:        # place directories first
                    793:
                    794:        my $attic;
                    795:        my $url;
                    796:        my $fileurl;
                    797:        my $filesexists;
                    798:        my $filesfound;
                    799:
                    800:        foreach (sort { &fileSortCmp } @dir) {
3.80      knu       801:                if ($_ eq '.') {
                    802:                        next;
                    803:                }
                    804:
                    805:                # ignore CVS lock and stale NFS files
                    806:                next if (/^#cvs\.|^,|^\.nfs/);
                    807:
                    808:                # Check whether to show the CVSROOT path
                    809:                next if ($input{'hidecvsroot'} && ($_ eq 'CVSROOT'));
                    810:
                    811:                # Check whether the module is in the restricted list
                    812:                next if ($_ && &forbidden_module($_));
                    813:
                    814:                # Ignore non-readable files
                    815:                next if ($input{'hidenonreadable'} && !(-r "$fullname/$_"));
3.1       knu       816:
3.80      knu       817:                if (s|^Attic/||) {
                    818:                        $attic = " (in the Attic)&nbsp;" . $hideAtticToggleLink;
                    819:                } else {
                    820:                        $attic = "";
                    821:                }
3.1       knu       822:
3.80      knu       823:                if ($_ eq '..' || -d "$fullname/$_") {
                    824:                        next if ($_ eq '..' && $where eq '/');
                    825:                        my ($rev, $date, $log, $author, $filename);
                    826:                        ($rev, $date, $log, $author, $filename) =
                    827:                            @{$fileinfo{$_}}
                    828:                            if (defined($fileinfo{$_}));
3.100   ! knu       829:                        printf "<tr style=\"background-color: %s\">\n<td>",
        !           830:                             $tabcolors[$dirrow % 2] if $dirtable;
3.80      knu       831:
                    832:                        if ($_ eq '..') {
                    833:                                $url = "../$query";
                    834:                                if ($nofilelinks) {
                    835:                                        print $backicon;
                    836:                                } else {
                    837:                                        print &link($backicon, $url);
                    838:                                }
3.100   ! knu       839:                                print '&nbsp;', &link("Parent Directory", $url);
3.80      knu       840:                        } else {
                    841:                                $url = './' . urlencode($_) . "/$query";
3.89      knu       842:                                print "<a name=\"$_\"></a>";
3.80      knu       843:
                    844:                                if ($nofilelinks) {
                    845:                                        print $diricon;
                    846:                                } else {
                    847:                                        print &link($diricon, $url);
                    848:                                }
3.100   ! knu       849:                                print '&nbsp;', &link("$_/", $url), $attic;
3.80      knu       850:
                    851:                                if ($_ eq "Attic") {
                    852:                                        print "&nbsp; ";
                    853:                                        print &link(
                    854:                                                "[Don't hide]",
                    855:                                                sprintf(
                    856:                                                        './%s#dirlist',
                    857:                                                        &toggleQuery(
                    858:                                                                "hideattic")
                    859:                                                )
                    860:                                        );
                    861:                                }
                    862:                        }
3.1       knu       863:
3.80      knu       864:                        # Show last change in dir
                    865:                        if ($filename) {
3.100   ! knu       866:                                print "</td>\n<td>&nbsp;</td>\n<td>&nbsp;"
3.80      knu       867:                                    if ($dirtable);
                    868:                                if ($date) {
                    869:                                        print " <i>",
                    870:                                            readableTime(time() - $date, 0),
                    871:                                            "</i>";
                    872:                                }
                    873:
                    874:                                if ($show_author) {
3.100   ! knu       875:                                        print "</td>\n<td>&nbsp;" if ($dirtable);
3.80      knu       876:                                        print $author;
                    877:                                }
3.100   ! knu       878:                                print "</td>\n<td>&nbsp;" if ($dirtable);
3.80      knu       879:                                $filename =~ s%^[^/]+/%%;
                    880:                                print "$filename/$rev";
3.89      knu       881:                                print "<br>" if ($dirtable);
3.80      knu       882:
                    883:                                if ($log) {
3.100   ! knu       884:                                        print "&nbsp;<span style=\"font-size: smaller\">",
3.89      knu       885:                                          &htmlify(
3.80      knu       886:                                                substr($log, 0, $shortLogLen));
                    887:                                        if (length $log > 80) {
                    888:                                                print "...";
                    889:                                        }
3.100   ! knu       890:                                        print "</span>";
3.80      knu       891:                                }
                    892:                        } else {
                    893:                                my ($dwhere) =
                    894:                                    ($where ne "/" ? $where : "") . $_;
                    895:
                    896:                                if ($use_descriptions
                    897:                                    && defined $descriptions{$dwhere})
                    898:                                {
3.89      knu       899:                                        print "<td colspan=\"",($infocols - 1),
                    900:                                            "\">&nbsp;"
3.80      knu       901:                                            if $dirtable;
                    902:                                        print $descriptions{$dwhere};
                    903:                                } elsif ($dirtable && $infocols > 1) {
                    904:
                    905:                                        # close the row with the appropriate number of
                    906:                                        # columns, so that the vertical seperators are visible
                    907:                                        my ($cols) = $infocols;
                    908:                                        while ($cols > 1) {
3.100   ! knu       909:                                                print "</td>\n<td>&nbsp;";
3.80      knu       910:                                                $cols--;
                    911:                                        }
                    912:                                }
                    913:                        }
1.18      wosch     914:
3.80      knu       915:                        if ($dirtable) {
3.100   ! knu       916:                                print "</td>\n</tr>\n";
3.80      knu       917:                        } else {
                    918:                                print "<br>\n";
                    919:                        }
                    920:                        $dirrow++;
                    921:                } elsif (s/,v$//) {
                    922:                        $fileurl = ($attic ? "Attic/" : "") . urlencode($_);
                    923:                        $url = './' . $fileurl . $query;
                    924:                        my $rev    = '';
                    925:                        my $date   = '';
                    926:                        my $log    = '';
                    927:                        my $author = '';
                    928:                        $filesexists++;
                    929:                        next if (!defined($fileinfo{$_}));
                    930:                        ($rev, $date, $log, $author) = @{$fileinfo{$_}};
                    931:                        $filesfound++;
3.100   ! knu       932:                        printf "<tr style=\"background-color: %s\">\n<td>",
        !           933:                            $tabcolors[$dirrow % 2] if $dirtable;
3.89      knu       934:                        print "<a name=\"$_\"></a>";
3.80      knu       935:
                    936:                        if ($nofilelinks) {
                    937:                                print $fileicon;
                    938:                        } else {
                    939:                                print &link($fileicon, $url);
                    940:                        }
3.100   ! knu       941:                        print '&nbsp;', &link($_, $url), $attic;
        !           942:                        print "</td>\n<td>&nbsp;" if ($dirtable);
3.80      knu       943:                        download_link($fileurl, $rev, $rev,
                    944:                                $defaultViewable ? "text/x-cvsweb-markup" :
                    945:                                undef);
3.100   ! knu       946:                        print "</td>\n<td>&nbsp;" if ($dirtable);
3.1       knu       947:
3.80      knu       948:                        if ($date) {
                    949:                                print " <i>", readableTime(time() - $date, 0),
                    950:                                    "</i>";
                    951:                        }
                    952:                        if ($show_author) {
3.100   ! knu       953:                                print "</td>\n<td>&nbsp;" if ($dirtable);
3.80      knu       954:                                print $author;
                    955:                        }
3.100   ! knu       956:                        print "</td>\n<td>&nbsp;" if ($dirtable);
3.80      knu       957:
                    958:                        if ($log) {
3.100   ! knu       959:                                print " <span style=\"font-size: smaller\">",
3.80      knu       960:                                    &htmlify(substr($log, 0, $shortLogLen));
                    961:                                if (length $log > 80) {
                    962:                                        print "...";
                    963:                                }
3.100   ! knu       964:                                print "</span>";
3.80      knu       965:                        }
3.100   ! knu       966:                        print "</td>\n" if ($dirtable);
3.80      knu       967:                        print(($dirtable) ? "</tr>" : "<br>");
                    968:                        $dirrow++;
3.1       knu       969:                }
3.80      knu       970:                print "\n";
3.1       knu       971:        }
3.80      knu       972:
3.89      knu       973:        print($dirtable ? "</table>\n" : "</menu>\n");
                    974:
3.1       knu       975:        if ($filesexists && !$filesfound) {
3.80      knu       976:                print
3.89      knu       977:                    "<p><b>NOTE:</b> There are $filesexists files, but none matches the current tag ($input{only_with_tag}).</p>\n";
3.1       knu       978:        }
3.80      knu       979:        if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}}))
                    980:        {
                    981:                %tags = %alltags
3.1       knu       982:        }
3.80      knu       983:
                    984:        if (scalar %tags || $input{only_with_tag} || $edit_option_form
                    985:            || defined($input{"options"}))
                    986:        {
3.100   ! knu       987:                print "<hr size=\"1\" noshade>\n";
3.1       knu       988:        }
                    989:
                    990:        if (scalar %tags || $input{only_with_tag}) {
3.89      knu       991:                print "<form method=\"get\" action=\"./\">\n";
3.80      knu       992:                foreach my $var (@stickyvars) {
                    993:                        print
3.89      knu       994:                            "<input type=\"hidden\" name=\"$var\" value=\"$input{$var}\">\n"
3.80      knu       995:                            if (defined($input{$var})
                    996:                            && (!defined($DEFAULTVALUE{$var})
3.23      knu       997:                            || $input{$var} ne $DEFAULTVALUE{$var})
3.80      knu       998:                            && $input{$var} ne "" && $var ne "only_with_tag");
                    999:                }
3.89      knu      1000:                print "<p>Show only files with tag:\n";
                   1001:                print "<select name=\"only_with_tag\"";
                   1002:                print " onchange=\"this.form.submit()\"" if $use_java_script;
3.80      knu      1003:                print ">";
3.89      knu      1004:                print "<option value=\"\">All tags / default branch</option>\n";
3.80      knu      1005:
                   1006:                foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
3.89      knu      1007:                        print "<option",
3.80      knu      1008:                            defined($input{only_with_tag})
3.89      knu      1009:                            && $input{only_with_tag} eq $tag ? " selected" : "",
                   1010:                            ">$tag</option>\n";
3.80      knu      1011:                }
3.89      knu      1012:                print "</select>\n";
3.80      knu      1013:                print " Module path or alias:\n";
3.89      knu      1014:                printf "<input type=\"text\" name=\"path\" value=\"%s\" size=\"15\">\n",
3.80      knu      1015:                    htmlquote($where);
3.89      knu      1016:                print "<input type=\"submit\" value=\"Go\"></p>\n";
                   1017:                print "</form>\n";
1.9       fenner   1018:        }
3.46      knu      1019:
                   1020:        if ($allow_tar) {
3.80      knu      1021:                my ($basefile) = ($where =~ m,(?:.*/)?([^/]+),);
3.46      knu      1022:
3.80      knu      1023:                if (defined($basefile) && $basefile ne '') {
3.89      knu      1024:                        print "<hr noshade>\n",
                   1025:                            "<div align=\"center\">Download this directory in ";
3.80      knu      1026:
                   1027:                        # Mangle the filename so browsers show a reasonable
                   1028:                        # filename to download.
                   1029:                        print &link("tarball", "./$basefile.tar.gz$query"
                   1030:                                . ($query ? "&" : "?") . "tarball=1");
                   1031:                        if ($CMD{zip}) {
                   1032:                                print " or ",
                   1033:                                    &link("zip archive", "./$basefile.zip$query"
                   1034:                                        . ($query ? "&" : "?") . "tarball=1");
                   1035:                        }
3.100   ! knu      1036:                        print "</div>\n";
3.77      knu      1037:                }
3.46      knu      1038:        }
                   1039:
3.100   ! knu      1040:        if ($edit_option_form || defined($input{"options"})) {
        !          1041:
        !          1042:                my $formwhere = $scriptwhere;
        !          1043:                $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
3.1       knu      1044:
3.89      knu      1045:                print "<form method=\"get\" action=\"${formwhere}\">\n";
                   1046:                print "<input type=\"hidden\" name=\"copt\" value=\"1\">\n";
3.80      knu      1047:                if ($cvstree ne $cvstreedefault) {
                   1048:                        print
3.89      knu      1049:                            "<input type=\"hidden\" name=\"cvsroot\" value=\"$cvstree\">\n";
3.80      knu      1050:                }
3.100   ! knu      1051:                print "<center>\n<table cellpadding=\"0\" cellspacing=\"0\">";
        !          1052:                print "\n<tr style=\"background-color: $columnHeaderColorDefault\">\n";
        !          1053:                print "<th colspan=\"2\">Preferences</th>\n</tr>\n";
        !          1054:                print "<tr>\n<td>Sort files by <select name=\"sortby\">\n";
        !          1055:                print "<option value=\"\">File</option>\n";
3.89      knu      1056:                print "<option", $bydate ? " selected" : "",
3.100   ! knu      1057:                    " value=\"date\">Age</option>\n";
3.89      knu      1058:                print "<option", $byauthor ? " selected" : "",
3.100   ! knu      1059:                    " value=\"author\">Author</option>\n"
3.80      knu      1060:                    if ($show_author);
3.89      knu      1061:                print "<option", $byrev ? " selected" : "",
3.100   ! knu      1062:                    " value=\"rev\">Revision</option>\n";
3.89      knu      1063:                print "<option", $bylog ? " selected" : "",
3.100   ! knu      1064:                    " value=\"log\">Log message</option>\n";
        !          1065:                print "</select>\n</td>\n";
3.80      knu      1066:                print "<td>Sort log by: ";
                   1067:                printLogSortSelect(0);
3.100   ! knu      1068:                print "</td>\n</tr>\n";
        !          1069:                print "<tr>\n<td>Diff format: ";
3.80      knu      1070:                printDiffSelect(0);
3.100   ! knu      1071:                print "</td>\n";
3.89      knu      1072:                print "<td><label>Show Attic files: ";
                   1073:                print "<input name=\"hideattic\" type=\"checkbox\"",
3.100   ! knu      1074:                    $input{'hideattic'} ? " checked" : "",
        !          1075:                     "></label></td>\n</tr>\n";
        !          1076:                print "<tr>\n<td align=\"center\" colspan=\"2\">";
        !          1077:                print "<input type=\"submit\" value=\"Change Options\">";
        !          1078:                print "</td>\n</tr>\n</table>\n</center>\n</form>\n";
1.12      fenner   1079:        }
3.100   ! knu      1080:        html_footer();
3.80      knu      1081: }
3.1       knu      1082:
                   1083: ###############################
                   1084: # View Files
                   1085: ###############################
3.80      knu      1086: elsif (-f $fullname . ',v') {
3.1       knu      1087:        if (defined($input{'rev'}) || $doCheckout) {
3.80      knu      1088:                &doCheckout($fullname, $input{'rev'});
                   1089:                gzipclose();
                   1090:                exit;
3.1       knu      1091:        }
3.80      knu      1092:
3.1       knu      1093:        if (defined($input{'annotate'}) && $allow_annotate) {
3.80      knu      1094:                &doAnnotate($input{'annotate'});
                   1095:                gzipclose();
                   1096:                exit;
3.1       knu      1097:        }
3.80      knu      1098:
3.1       knu      1099:        if (defined($input{'r1'}) && defined($input{'r2'})) {
3.80      knu      1100:                &doDiff(
                   1101:                        $fullname,     $input{'r1'},
                   1102:                        $input{'tr1'}, $input{'r2'},
                   1103:                        $input{'tr2'}, $input{'f'}
                   1104:                );
                   1105:                gzipclose();
                   1106:                exit;
3.1       knu      1107:        }
                   1108:        print("going to dolog($fullname)\n") if ($verbose);
                   1109:        &doLog($fullname);
3.80      knu      1110:
                   1111:        ##############################
                   1112:        # View Diff
                   1113:        ##############################
                   1114: } elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" && $input{'r1'}
                   1115:     && $input{'r2'})
                   1116: {
3.1       knu      1117:
                   1118:        # $where-diff-removal if 'cvs rdiff' is used
                   1119:        # .. but 'cvs rdiff'doesn't support some options
                   1120:        # rcsdiff does (-w and -p), so it is disabled
                   1121:        # $where =~ s/\.diff$//;
                   1122:
1.12      fenner   1123:        # Allow diffs using the ".diff" extension
                   1124:        # so that browsers that default to the URL
                   1125:        # for a save filename don't save diff's as
                   1126:        # e.g. foo.c
3.80      knu      1127:        &doDiff(
                   1128:                $fullname,     $input{'r1'}, $input{'tr1'}, $input{'r2'},
                   1129:                $input{'tr2'}, $input{'f'}
                   1130:        );
3.25      knu      1131:        gzipclose();
1.12      fenner   1132:        exit;
3.80      knu      1133: } elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| && -f $newname . ",v")
                   1134: {
                   1135:
1.12      fenner   1136:        # The file has been removed and is in the Attic.
                   1137:        # Send a redirect pointing to the file in the Attic.
3.1       knu      1138:        (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
3.83      knu      1139:        if ($ENV{QUERY_STRING} ne "") {
                   1140:                redirect("${newplace}?$ENV{QUERY_STRING}");
                   1141:        } else {
                   1142:                redirect($newplace);
                   1143:        }
1.12      fenner   1144:        exit;
3.80      knu      1145: } elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
3.1       knu      1146:        http_header("text/plain");
1.12      fenner   1147:        print "You matched the following files:\n";
3.80      knu      1148:        print join ("\n", @files);
                   1149:
1.12      fenner   1150:        # Find the tags from each file
                   1151:        # Display a form offering diffs between said tags
3.80      knu      1152: } else {
                   1153:        my $fh = do { local (*FH); };
3.1       knu      1154:        my ($xtra, $module);
3.80      knu      1155:
1.12      fenner   1156:        # Assume it's a module name with a potential path following it.
3.44      knu      1157:        $xtra = (($module = $where) =~ s|/.*||) ? $& : '';
3.80      knu      1158:
1.12      fenner   1159:        # Is there an indexed version of modules?
3.60      knu      1160:        if (open($fh, "< $cvsroot/CVSROOT/modules")) {
3.80      knu      1161:                while (<$fh>) {
                   1162:                        if (/^(\S+)\s+(\S+)/o && $module eq $1
                   1163:                            && -d "$cvsroot/$2" && $module ne $2)
                   1164:                        {
                   1165:                                redirect("$scriptname/$2$xtra$query");
                   1166:                        }
1.12      fenner   1167:                }
                   1168:        }
3.80      knu      1169:        &fatal("404 Not Found", "$where: no such file or directory");
                   1170: }
3.23      knu      1171:
3.25      knu      1172: gzipclose();
3.80      knu      1173:
3.1       knu      1174: ## End MAIN
                   1175:
3.12      knu      1176: sub printDiffSelect($) {
3.80      knu      1177:        my ($use_java_script) = @_;
                   1178:        my $f = $input{'f'};
3.37      knu      1179:
3.89      knu      1180:        print '<select name="f"';
                   1181:        print ' onchange="this.form.submit()"' if $use_java_script;
3.100   ! knu      1182:        print ">\n";
3.80      knu      1183:
                   1184:        local $_;
                   1185:        for (@DIFFTYPES) {
3.100   ! knu      1186:                printf("<option value=\"%s\"%s>%s</option>\n", $_,
3.89      knu      1187:                    $f eq $_ ? ' selected' : '', "\u$DIFFTYPES{$_}{'descr'}");
3.80      knu      1188:        }
3.37      knu      1189:
3.89      knu      1190:        print "</select>";
3.37      knu      1191: }
                   1192:
                   1193: sub printLogSortSelect($) {
3.80      knu      1194:        my ($use_java_script) = @_;
3.37      knu      1195:
3.89      knu      1196:        print '<select name="logsort"';
                   1197:        print ' onchange="this.form.submit()"' if $use_java_script;
3.100   ! knu      1198:        print ">\n";
3.37      knu      1199:
3.80      knu      1200:        local $_;
                   1201:        for (@LOGSORTKEYS) {
3.100   ! knu      1202:                printf("<option value=\"%s\"%s>%s</option>\n", $_,
3.89      knu      1203:                    $logsort eq $_ ? ' selected' : '',
3.80      knu      1204:                    "\u$LOGSORTKEYS{$_}{'descr'}");
                   1205:        }
                   1206:
3.89      knu      1207:        print "</select>";
3.1       knu      1208: }
                   1209:
3.12      knu      1210: sub findLastModifiedSubdirs(@) {
3.80      knu      1211:        my (@dirs) = @_;
                   1212:        my ($dirname, @files);
3.1       knu      1213:
3.80      knu      1214:        foreach $dirname (@dirs) {
                   1215:                next if ($dirname eq ".");
                   1216:                next if ($dirname eq "..");
                   1217:                my ($dir) = "$fullname/$dirname";
                   1218:                next if (!-d $dir);
                   1219:
                   1220:                my ($lastmod)     = undef;
                   1221:                my ($lastmodtime) = undef;
                   1222:                my $dh = do { local (*DH); };
                   1223:
3.95      knu      1224:                opendir($dh, $dir) or next;
3.80      knu      1225:                my (@filenames) = readdir($dh);
                   1226:                closedir($dh);
                   1227:
                   1228:                foreach my $filename (@filenames) {
                   1229:                        $filename = "$dirname/$filename";
                   1230:                        my ($file) = "$fullname/$filename";
                   1231:                        next if ($filename !~ /,v$/ || !-f $file);
                   1232:                        $filename =~ s/,v$//;
                   1233:                        my $modtime = -M $file;
                   1234:
                   1235:                        if (!defined($lastmod) || $modtime < $lastmodtime) {
                   1236:                                $lastmod     = $filename;
                   1237:                                $lastmodtime = $modtime;
                   1238:                        }
                   1239:                }
                   1240:                push (@files, $lastmod) if (defined($lastmod));
3.1       knu      1241:        }
3.80      knu      1242:        return @files;
1.12      fenner   1243: }
                   1244:
3.36      knu      1245: sub htmlify_sub(&$) {
3.80      knu      1246:        (my $proc, local $_) = @_;
                   1247:        my @a = split (m`(<a [^>]+>[^<]*</a>)`i);
                   1248:        my $linked;
                   1249:        my $result = '';
                   1250:
                   1251:        while (($_, $linked) = splice(@a, 0, 2)) {
                   1252:                &$proc();
                   1253:                $result .= $_      if defined($_);
                   1254:                $result .= $linked if defined($linked);
                   1255:        }
1.12      fenner   1256:
3.80      knu      1257:        $result;
3.36      knu      1258: }
1.12      fenner   1259:
3.36      knu      1260: sub htmlify($;$) {
3.80      knu      1261:        (local $_, my $extra) = @_;
3.1       knu      1262:
3.80      knu      1263:        $_ = htmlquote($_);
3.17      knu      1264:
3.80      knu      1265:        # get URL's as link
                   1266:        s{
3.36      knu      1267:       (http|ftp|https)://\S+
                   1268:      }{
                   1269:         &link($&, htmlunquote($&))
                   1270:      }egx;
                   1271:
3.80      knu      1272:        # get e-mails as link
                   1273:        $_ = htmlify_sub {
                   1274:                s<
3.36      knu      1275:          [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
                   1276:            ><
                   1277:              &link($&, "mailto:$&")
                   1278:                >egix;
3.80      knu      1279:            }
                   1280:            $_;
3.36      knu      1281:
3.80      knu      1282:        if ($extra) {
3.36      knu      1283:
3.80      knu      1284:                # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
                   1285:                if (defined($prcgi) && defined($re_prcategories)
                   1286:                    && defined($re_prkeyword))
                   1287:                {
                   1288:                        my $prev;
3.36      knu      1289:
3.80      knu      1290:                        do {
                   1291:                                $prev = $_;
                   1292:
                   1293:                                $_ = htmlify_sub {
                   1294:                                        s{
3.54      knu      1295:                      (\b$re_prkeyword[:\#]?\s*
3.36      knu      1296:                       (?:
                   1297:                        \#?
                   1298:                        \d+[,\s]\s*
                   1299:                       )*
                   1300:                       \#?)
                   1301:                      (\d+)\b
                   1302:                     }{
3.42      knu      1303:                         $1 . &link($2, sprintf($prcgi, $2))
3.36      knu      1304:                     }egix;
3.80      knu      1305:                                    }
                   1306:                                    $_;
                   1307:                        } while ($_ ne $prev);
3.36      knu      1308:
3.80      knu      1309:                        $_ = htmlify_sub {
                   1310:                                s{
3.54      knu      1311:                  (\b$re_prcategories/(\d+)\b)
3.36      knu      1312:                 }{
3.42      knu      1313:                     &link($1, sprintf($prcgi, $2))
3.36      knu      1314:                 }egox;
3.80      knu      1315:                            }
                   1316:                            $_;
                   1317:                }
3.36      knu      1318:
3.80      knu      1319:                # get manpage specs as link: "foo.1" "foo(1)"
                   1320:                if (defined($mancgi)) {
                   1321:                        $_ = htmlify_sub {
                   1322:                                s{
3.53      knu      1323:                  (\b([a-zA-Z][\w.]+)
3.36      knu      1324:                   (?:
                   1325:                    \( ([0-9n]) \)\B
                   1326:                    |
                   1327:                    \.([0-9n])\b
                   1328:                   )
                   1329:                  )
                   1330:                 }{
3.53      knu      1331:                     &link($1, sprintf($mancgi, defined($3) ? $3 : $4, $2))
3.36      knu      1332:                 }egx;
3.80      knu      1333:                            }
                   1334:                            $_;
                   1335:                }
3.1       knu      1336:        }
                   1337:
3.80      knu      1338:        $_;
3.1       knu      1339: }
                   1340:
3.20      knu      1341: sub spacedHtmlText($;$) {
3.12      knu      1342:        local $_ = $_[0];
3.20      knu      1343:        my $ts = $_[1] || $tabstop;
3.1       knu      1344:
3.20      knu      1345:        # Cut trailing spaces and tabs
                   1346:        s/[ \t]+$//;
3.1       knu      1347:
3.80      knu      1348:        if (defined($ts)) {
                   1349:
                   1350:                # Expand tabs
                   1351:                1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e
3.20      knu      1352:        }
3.1       knu      1353:
                   1354:        # replace <tab> and <space> (\001 is to protect us from htmlify)
                   1355:        # gzip can make excellent use of this repeating pattern :-)
                   1356:        if ($hr_breakable) {
3.80      knu      1357:
                   1358:                # make every other space 'breakable'
                   1359:                s/  / \001nbsp;/g;    # 2 * <space>
                   1360:                                      # leave single space as it is
3.20      knu      1361:        } else {
3.80      knu      1362:                s/ /\001nbsp;/g;
1.12      fenner   1363:        }
                   1364:
3.12      knu      1365:        $_ = htmlify($_);
3.1       knu      1366:
                   1367:        # unescape
3.20      knu      1368:        y/\001/&/;
3.1       knu      1369:
3.12      knu      1370:        return $_;
1.12      fenner   1371: }
                   1372:
3.12      knu      1373: sub link($$) {
3.80      knu      1374:        my ($name, $url) = @_;
1.12      fenner   1375:
3.80      knu      1376:        $url =~ s/:/sprintf("%%%02x", ord($&))/eg
                   1377:            if $url =~ /^[^a-z]/;    # relative
3.67      knu      1378:
3.89      knu      1379:        sprintf '<a href="%s">%s</a>', hrefquote($url), $name;
1.12      fenner   1380: }
                   1381:
3.12      knu      1382: sub revcmp($$) {
3.80      knu      1383:        my ($rev1, $rev2) = @_;
3.15      knu      1384:
                   1385:        # make no comparison for a tag or a branch
                   1386:        return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
                   1387:
3.80      knu      1388:        my (@r1) = split (/\./, $rev1);
                   1389:        my (@r2) = split (/\./, $rev2);
                   1390:        my ($a, $b);
                   1391:
                   1392:        while (($a = shift (@r1)) && ($b = shift (@r2))) {
                   1393:                if ($a != $b) {
                   1394:                        return $a <=> $b;
                   1395:                }
1.12      fenner   1396:        }
                   1397:        if (@r1) { return 1; }
                   1398:        if (@r2) { return -1; }
                   1399:        return 0;
                   1400: }
                   1401:
3.12      knu      1402: sub fatal($$) {
3.80      knu      1403:        my ($errcode, $errmsg) = @_;
3.3       knu      1404:        if ($is_mod_perl) {
3.80      knu      1405:                Apache->request->status((split (/ /, $errcode))[0]);
                   1406:        } else {
3.4       knu      1407:                print "Status: $errcode\r\n";
3.1       knu      1408:        }
                   1409:        html_header("Error");
3.100   ! knu      1410:        print "<p>Error: ", htmlquote($errmsg), "</p>\n";
        !          1411:        html_footer();
1.12      fenner   1412:        exit(1);
                   1413: }
                   1414:
3.12      knu      1415: sub redirect($) {
3.80      knu      1416:        my ($url) = @_;
3.3       knu      1417:        if ($is_mod_perl) {
3.1       knu      1418:                Apache->request->status(301);
                   1419:                Apache->request->header_out(Location => $url);
3.80      knu      1420:        } else {
3.4       knu      1421:                print "Status: 301 Moved\r\n";
                   1422:                print "Location: $url\r\n";
3.1       knu      1423:        }
                   1424:        html_header("Moved");
3.100   ! knu      1425:        print "<p>This document is located ", &link('here', $url), "</p>\n";
        !          1426:        html_footer();
1.12      fenner   1427:        exit(1);
                   1428: }
                   1429:
3.12      knu      1430: sub safeglob($) {
3.1       knu      1431:        my ($filename) = @_;
                   1432:        my ($dirname);
                   1433:        my (@results);
3.80      knu      1434:        my $dh = do { local (*DH); };
1.12      fenner   1435:
                   1436:        ($dirname = $filename) =~ s|/[^/]+$||;
                   1437:        $filename =~ s|.*/||;
                   1438:
3.1       knu      1439:        if (opendir($dh, $dirname)) {
                   1440:                my $glob = $filename;
                   1441:                my $t;
3.80      knu      1442:
                   1443:                #       transform filename from glob to regex.  Deal with:
                   1444:                #       [, {, ?, * as glob chars
                   1445:                #       make sure to escape all other regex chars
1.12      fenner   1446:                $glob =~ s/([\.\(\)\|\+])/\\$1/g;
                   1447:                $glob =~ s/\*/.*/g;
                   1448:                $glob =~ s/\?/./g;
                   1449:                $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
3.1       knu      1450:                foreach (readdir($dh)) {
3.80      knu      1451:
1.12      fenner   1452:                        if (/^${glob}$/) {
3.80      knu      1453:                                push (@results, "$dirname/" . $_);
1.12      fenner   1454:                        }
                   1455:                }
3.80      knu      1456:                closedir($dh);
1.12      fenner   1457:        }
                   1458:
                   1459:        @results;
                   1460: }
                   1461:
3.58      knu      1462: sub search_path($) {
3.80      knu      1463:        my ($command) = @_;
                   1464:        my $d;
3.58      knu      1465:
3.80      knu      1466:        for $d (split (/:/, $command_path)) {
                   1467:                return "$d/$command" if -x "$d/$command";
                   1468:        }
3.58      knu      1469:
3.80      knu      1470:        '';
3.58      knu      1471: }
                   1472:
3.12      knu      1473: sub getMimeTypeFromSuffix($) {
3.80      knu      1474:        my ($fullname) = @_;
                   1475:        my ($mimetype, $suffix);
                   1476:        my $fh = do { local (*FH); };
                   1477:
                   1478:        ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
                   1479:        $mimetype = $MTYPES{$suffix};
                   1480:        $mimetype = $MTYPES{'*'} if (!$mimetype);
                   1481:
                   1482:        if (!$mimetype && -f $mime_types) {
                   1483:
                   1484:                # okey, this is something special - search the
                   1485:                # mime.types database
                   1486:                open($fh, "<$mime_types");
                   1487:                while (<$fh>) {
                   1488:                        if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
                   1489:                                $mimetype = $1;
                   1490:                                last;
                   1491:                        }
                   1492:                }
                   1493:                close($fh);
3.1       knu      1494:        }
3.12      knu      1495:
3.80      knu      1496:        # okey, didn't find anything useful ..
                   1497:        if (!($mimetype =~ /\S\/\S/)) {
                   1498:                $mimetype = "text/plain";
                   1499:        }
                   1500:        return $mimetype;
3.1       knu      1501: }
                   1502:
                   1503: ###############################
3.24      knu      1504: # read first lines like head(1)
                   1505: ###############################
                   1506: sub head($;$) {
3.80      knu      1507:        my $fh        = $_[0];
                   1508:        my $linecount = $_[1] || 10;
3.24      knu      1509:
3.80      knu      1510:        my @buf;
3.24      knu      1511:
3.80      knu      1512:        if ($linecount > 0) {
                   1513:                my $i;
                   1514:                for ($i = 0 ; !eof($fh) && $i < $linecount ; $i++) {
                   1515:                        push @buf, scalar <$fh>;
                   1516:                }
                   1517:        } else {
                   1518:                @buf = <$fh>;
3.24      knu      1519:        }
                   1520:
3.80      knu      1521:        @buf;
3.24      knu      1522: }
                   1523:
                   1524: ###############################
                   1525: # scan vim and Emacs directives
                   1526: ###############################
                   1527: sub scan_directives(@) {
3.80      knu      1528:        my $ts = undef;
3.24      knu      1529:
3.80      knu      1530:        for (@_) {
                   1531:                $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
                   1532:        }
3.24      knu      1533:
3.80      knu      1534:        ('tabstop' => $ts);
3.24      knu      1535: }
                   1536:
3.86      knu      1537: sub openOutputFilter() {
                   1538:        return if !defined($output_filter) || $output_filter eq '';
                   1539:
3.95      knu      1540:        open(STDOUT, "|-") and return;
3.86      knu      1541:
                   1542:        # child of child
                   1543:        open(STDERR, '>/dev/null');
3.95      knu      1544:        exec($output_filter) or exit -1;
3.86      knu      1545: }
                   1546:
3.24      knu      1547: ###############################
3.1       knu      1548: # show Annotation
                   1549: ###############################
3.12      knu      1550: sub doAnnotate($$) {
3.80      knu      1551:        my ($rev) = @_;
                   1552:        my ($pid);
                   1553:        my ($pathname, $filename);
                   1554:        my $reader = do { local (*FH); };
                   1555:        my $writer = do { local (*FH); };
                   1556:
                   1557:        # make sure the revisions are wellformed, for security
                   1558:        # reasons ..
                   1559:        if ($rev =~ /[^\w.]/) {
                   1560:                &fatal("404 Not Found",
                   1561:                        "Malformed query \"$ENV{QUERY_STRING}\"");
                   1562:        }
                   1563:
3.81      knu      1564:        if (&forbidden_file($fullname)) {
                   1565:                &fatal("403 Forbidden",
                   1566:                        "Access forbidden.  This file is mentioned in \@ForbiddenFiles"
                   1567:                );
                   1568:                return;
                   1569:        }
                   1570:
3.80      knu      1571:        ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
                   1572:        ($filename = $where) =~ s/^.*\///;
                   1573:
                   1574:        # this seems to be necessary
                   1575:        $| = 1;
                   1576:        $| = 0;    # Flush
                   1577:
                   1578:        # this annotate version is based on the
                   1579:        # cvs annotate-demo Perl script by Cyclic Software
                   1580:        # It was written by Cyclic Software, http://www.cyclic.com/, and is in
                   1581:        # the public domain.
                   1582:        # we could abandon the use of rlog, rcsdiff and co using
                   1583:        # the cvsserver in a similiar way one day (..after rewrite)
                   1584:        $pid = open2($reader, $writer, $CMD{cvs}, @cvs_options, "server")
3.95      knu      1585:            or fatal("500 Internal Error",
3.80      knu      1586:                "Fatal Error - unable to open cvs for annotation");
                   1587:
                   1588:        # OK, first send the request to the server.  A simplified example is:
                   1589:        #     Root /home/kingdon/zwork/cvsroot
                   1590:        #     Argument foo/xx
                   1591:        #     Directory foo
                   1592:        #     /home/kingdon/zwork/cvsroot/foo
                   1593:        #     Directory .
                   1594:        #     /home/kingdon/zwork/cvsroot
                   1595:        #     annotate
                   1596:        # although as you can see there are a few more details.
                   1597:
                   1598:        print $writer "Root $cvsroot\n";
                   1599:        print $writer
                   1600:            "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
                   1601:
                   1602:        # Don't worry about sending valid-requests, the server just needs to
                   1603:        # support "annotate" and if it doesn't, there isn't anything to be done.
                   1604:        print $writer "UseUnchanged\n";
                   1605:        print $writer "Argument -r\n";
                   1606:        print $writer "Argument $rev\n";
                   1607:        print $writer "Argument $where\n";
                   1608:
                   1609:        # The protocol requires us to fully fake a working directory (at
                   1610:        # least to the point of including the directories down to the one
                   1611:        # containing the file in question).
                   1612:        # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
                   1613:        my @dirs = split ('/', $where);
                   1614:        my $path = "";
                   1615:        foreach (@dirs) {
                   1616:
                   1617:                if ($path eq "") {
                   1618:
                   1619:                        # In our example, $_ is "dir".
                   1620:                        $path = $_;
                   1621:                } else {
                   1622:                        print $writer "Directory $path\n";
                   1623:                        print $writer "$cvsroot/$path\n";
                   1624:
                   1625:                        # In our example, $_ is "sdir" and $path becomes "dir/sdir"
                   1626:                        # And the next time, "file" and "dir/sdir/file" (which then gets
                   1627:                        # ignored, because we don't need to send Directory for the file).
                   1628:                        $path .= "/$_";
                   1629:                }
                   1630:        }
                   1631:
                   1632:        # And the last "Directory" before "annotate" is the top level.
                   1633:        print $writer "Directory .\n";
                   1634:        print $writer "$cvsroot\n";
                   1635:
                   1636:        print $writer "annotate\n";
                   1637:
                   1638:        # OK, we've sent our command to the server.  Thing to do is to
                   1639:        # close the writer side and get all the responses.  If "cvs server"
                   1640:        # were nicer about buffering, then we could just leave it open, I think.
3.95      knu      1641:        close($writer) or die "cannot close: $!";
3.80      knu      1642:
                   1643:        http_header();
                   1644:
                   1645:        navigateHeader($scriptwhere, $pathname, $filename, $rev, "annotate");
                   1646:        print
3.100   ! knu      1647:            "<h3 style=\"text-align: center\">Annotation of $pathname$filename, Revision $rev</h3>\n";
3.80      knu      1648:
                   1649:        # Ready to get the responses from the server.
                   1650:        # For example:
                   1651:        #     E Annotations for foo/xx
                   1652:        #     E ***************
                   1653:        #     M 1.3          (kingdon  06-Sep-97): hello
                   1654:        #     ok
                   1655:        my ($lineNr) = 0;
                   1656:        my ($oldLrev, $oldLusr) = ("", "");
                   1657:        my ($revprint, $usrprint);
                   1658:
                   1659:        if ($annTable) {
3.100   ! knu      1660:                print "<table style=\"border: none\" cellspacing=\"0\" cellpadding=\"0\">\n";
3.80      knu      1661:        } else {
                   1662:                print "<pre>";
                   1663:        }
                   1664:
                   1665:        # prefetch several lines
                   1666:        my @buf = head($reader);
                   1667:
                   1668:        my %d = scan_directives(@buf);
                   1669:
                   1670:        while (@buf || !eof($reader)) {
                   1671:                $_ = @buf ? shift @buf : <$reader>;
                   1672:
                   1673:                my @words = split;
                   1674:
                   1675:                # Adding one is for the (single) space which follows $words[0].
                   1676:                my $rest = substr($_, length($words[0]) + 1);
                   1677:                if ($words[0] eq "E") {
                   1678:                        next;
                   1679:                } elsif ($words[0] eq "M") {
                   1680:                        $lineNr++;
                   1681:                        (my $lrev = substr($_, 2,  13)) =~ y/ //d;
                   1682:                        (my $lusr = substr($_, 16, 9))  =~ y/ //d;
                   1683:                        my $line = substr($_, 36);
                   1684:                        my $isCurrentRev = ($rev eq $lrev);
                   1685:
                   1686:                        # we should parse the date here ..
                   1687:                        if ($lrev eq $oldLrev) {
                   1688:                                $revprint = sprintf('%-8s', '');
                   1689:                        } else {
                   1690:                                $revprint = sprintf('%-8s', $lrev);
                   1691:                                $revprint =~
                   1692:                                    s`\S+`&link($&, "$scriptwhere$query#rev$&")`e
                   1693:                                    ;    # `
                   1694:                                $oldLusr = '';
                   1695:                        }
                   1696:
                   1697:                        if ($lusr eq $oldLusr) {
                   1698:                                $usrprint = '';
                   1699:                        } else {
                   1700:                                $usrprint = $lusr;
                   1701:                        }
                   1702:                        $oldLrev = $lrev;
                   1703:                        $oldLusr = $lusr;
                   1704:
                   1705:                        # Set bold for text-based browsers only - graphical
                   1706:                        # browsers show bold fonts a bit wider than regular fonts,
                   1707:                        # so it looks irregular.
                   1708:                        print "<b>" if ($isCurrentRev && $is_textbased);
                   1709:
                   1710:                        printf "%s%s %-8s %4d:", $revprint,
                   1711:                            $isCurrentRev ? '!' : ' ', $usrprint, $lineNr;
                   1712:                        print spacedHtmlText($line, $d{'tabstop'});
                   1713:
                   1714:                        print "</b>" if ($isCurrentRev && $is_textbased);
                   1715:                } elsif ($words[0] eq "ok") {
3.12      knu      1716:
3.80      knu      1717:                        # We could complain about any text received after this, like the
                   1718:                        # CVS command line client.  But for simplicity, we don't.
                   1719:                } elsif ($words[0] eq "error") {
                   1720:                        fatal("500 Internal Error",
                   1721:                                "Error occured during annotate: <b>$_</b>");
                   1722:                }
3.1       knu      1723:        }
3.80      knu      1724:
                   1725:        if ($annTable) {
                   1726:                print "</table>";
                   1727:        } else {
                   1728:                print "</pre>";
3.1       knu      1729:        }
3.95      knu      1730:        close($reader) or warn "cannot close: $!";
3.80      knu      1731:        wait;
3.1       knu      1732: }
                   1733:
                   1734: ###############################
                   1735: # make Checkout
                   1736: ###############################
3.12      knu      1737: sub doCheckout($$) {
3.80      knu      1738:        my ($fullname, $rev) = @_;
                   1739:        my ($mimetype, $revopt);
                   1740:        my $fh = do { local (*FH); };
                   1741:
                   1742:        if ($rev eq 'HEAD' || $rev eq '.') {
                   1743:                $rev = undef;
                   1744:        }
                   1745:
                   1746:        # make sure the revisions a wellformed, for security
                   1747:        # reasons ..
                   1748:        if (defined($rev) && $rev =~ /[^\w.]/) {
                   1749:                &fatal("404 Not Found",
                   1750:                        "Malformed query \"$ENV{QUERY_STRING}\"");
                   1751:        }
                   1752:
3.81      knu      1753:        if (&forbidden_file($fullname)) {
                   1754:                &fatal("403 Forbidden",
                   1755:                        "Access forbidden. This file is mentioned in \@ForbiddenFiles"
                   1756:                );
                   1757:                return;
                   1758:        }
                   1759:
3.80      knu      1760:        # get mimetype
                   1761:        if (defined($input{"content-type"})
                   1762:            && ($input{"content-type"} =~ /\S\/\S/))
                   1763:        {
                   1764:                $mimetype = $input{"content-type"}
                   1765:        } else {
                   1766:                $mimetype = &getMimeTypeFromSuffix($fullname);
                   1767:        }
                   1768:
                   1769:        if (defined($rev)) {
                   1770:                $revopt = "-r$rev";
                   1771:                if ($use_moddate) {
                   1772:                        readLog($fullname, $rev);
                   1773:                        $moddate = $date{$rev};
                   1774:                }
                   1775:        } else {
                   1776:                $revopt = "-rHEAD";
                   1777:
                   1778:                if ($use_moddate) {
                   1779:                        readLog($fullname);
                   1780:                        $moddate = $date{$symrev{HEAD}};
                   1781:                }
                   1782:        }
                   1783:
                   1784:        ### just for the record:
                   1785:        ### 'cvs co' seems to have a bug regarding single checkout of
                   1786:        ### directories/files having spaces in it;
                   1787:        ### this is an issue that should be resolved on cvs's side
                   1788:        #
                   1789:        # Safely for a child process to read from.
                   1790:        if (!open($fh, "-|")) {    # child
                   1791:                 # chdir to $tmpdir before to avoid non-readable cgi-bin directories
                   1792:                chdir($tmpdir);
                   1793:                open(STDERR, ">&STDOUT");    # Redirect stderr to stdout
3.91      knu      1794:
                   1795:                # work around a bug of cvs -p; expand symlinks
                   1796:                use Cwd 'abs_path';
                   1797:                exec($CMD{cvs}, @cvs_options,
                   1798:                     '-d', abs_path($cvsroot),
                   1799:                     'co', '-p',
3.95      knu      1800:                     $revopt, $where) or exit -1;
3.80      knu      1801:        }
                   1802:
                   1803:        if (eof($fh)) {
                   1804:                &fatal("404 Not Found", "$where is not (any longer) pertinent");
                   1805:        }
                   1806:
                   1807:        #===================================================================
                   1808:        #Checking out squid/src/ftp.c
                   1809:        #RCS:  /usr/src/CVS/squid/src/ftp.c,v
                   1810:        #VERS: 1.1.1.28.6.2
                   1811:        #***************
                   1812:
                   1813:        # Parse CVS header
                   1814:        my ($revision, $filename, $cvsheader);
                   1815:        $filename = "";
                   1816:        while (<$fh>) {
                   1817:                last if (/^\*\*\*\*/);
                   1818:                $revision = $1 if (/^VERS: (.*)$/);
                   1819:
                   1820:                if (/^Checking out (.*)$/) {
                   1821:                        $filename = $1;
                   1822:                        $filename =~ s/^\.\/*//;
                   1823:                }
                   1824:                $cvsheader .= $_;
                   1825:        }
                   1826:
                   1827:        if ($filename ne $where) {
                   1828:                &fatal("500 Internal Error",
                   1829:                        "Unexpected output from cvs co: $cvsheader");
                   1830:        }
                   1831:        $| = 1;
                   1832:
                   1833:        if ($mimetype eq "text/x-cvsweb-markup") {
                   1834:                &cvswebMarkup($fh, $fullname, $revision);
                   1835:        } else {
                   1836:                http_header($mimetype);
                   1837:                print <$fh>;
                   1838:        }
                   1839:        close($fh);
3.1       knu      1840: }
                   1841:
3.12      knu      1842: sub cvswebMarkup($$$) {
3.80      knu      1843:        my ($filehandle, $fullname, $revision) = @_;
                   1844:        my ($pathname,   $filename);
3.1       knu      1845:
3.80      knu      1846:        ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
                   1847:        ($filename = $where) =~ s/^.*\///;
                   1848:        my ($fileurl) = urlencode($filename);
                   1849:
                   1850:        http_header();
                   1851:
                   1852:        navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
3.89      knu      1853:        print "<hr noshade>";
3.100   ! knu      1854:        print "<table width=\"100%\">\n<tr>\n<td style=\"background-color: $markupLogColor\">";
3.80      knu      1855:        print "File: ", &clickablePath($where, 1);
3.35      knu      1856:        print "&nbsp;(";
3.80      knu      1857:        &download_link($fileurl, $revision, "download");
3.35      knu      1858:        print ")";
3.24      knu      1859:
3.80      knu      1860:        if (!$defaultTextPlain) {
                   1861:                print "&nbsp;(";
                   1862:                &download_link($fileurl, $revision, "as text", "text/plain");
                   1863:                print ")";
                   1864:        }
3.89      knu      1865:        print "<br>\n";
3.80      knu      1866:
                   1867:        if ($show_log_in_markup) {
                   1868:                readLog($fullname);    #,$revision);
                   1869:                printLog($revision, 0);
                   1870:        } else {
3.89      knu      1871:                print "Version: <b>$revision</b><br>\n";
                   1872:                print "Tag: <b>", $input{only_with_tag}, "</b><br>\n"
3.80      knu      1873:                    if $input{only_with_tag};
                   1874:        }
3.100   ! knu      1875:        print "</td>\n</tr>\n</table>";
3.80      knu      1876:        my $url = download_url($fileurl, $revision, $mimetype);
3.89      knu      1877:        print "<hr noshade>";
3.80      knu      1878:
                   1879:        if ($mimetype =~ /^image/) {
3.89      knu      1880:                printf '<img src="%s" alt=""><br>', hrefquote("$url$barequery");
3.80      knu      1881:        } elsif ($mimetype =~ m%^application/pdf%) {
3.89      knu      1882:                printf '<embed src="%s" width="100%"><br>',
3.80      knu      1883:                    hrefquote("$url$barequery");
                   1884:        } elsif ($preformat_in_markup) {
3.89      knu      1885:                print "<pre>";
3.80      knu      1886:
                   1887:                # prefetch several lines
                   1888:                my @buf = head($filehandle);
                   1889:
                   1890:                my %d = scan_directives(@buf);
3.24      knu      1891:
3.80      knu      1892:                while (@buf || !eof($filehandle)) {
                   1893:                        $_ = @buf ? shift @buf : <$filehandle>;
3.24      knu      1894:
3.80      knu      1895:                        print spacedHtmlText($_, $d{'tabstop'});
                   1896:                }
3.89      knu      1897:                print "</pre>";
3.80      knu      1898:        } else {
3.89      knu      1899:                print "<pre>";
3.24      knu      1900:
3.80      knu      1901:                while (<$filehandle>) {
                   1902:                        print htmlquote($_);
                   1903:                }
3.89      knu      1904:                print "</pre>";
3.69      knu      1905:        }
1.12      fenner   1906: }
                   1907:
3.1       knu      1908: sub viewable($) {
3.80      knu      1909:        my ($mimetype) = @_;
3.1       knu      1910:
3.80      knu      1911:        $mimetype =~ m%^((text|image)/|application/pdf)%;
3.1       knu      1912: }
                   1913:
                   1914: ###############################
                   1915: # Show Colored Diff
                   1916: ###############################
3.12      knu      1917: sub doDiff($$$$$$) {
3.80      knu      1918:        my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
                   1919:        my $fh = do { local (*FH); };
3.37      knu      1920:        my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1.12      fenner   1921:
3.81      knu      1922:        if (&forbidden_file($fullname)) {
                   1923:                &fatal("403 Forbidden",
                   1924:                        "Access forbidden. This file is mentioned in \@ForbiddenFiles"
                   1925:                );
                   1926:                return;
                   1927:        }
                   1928:
1.12      fenner   1929:        if ($r1 =~ /([^:]+)(:(.+))?/) {
3.80      knu      1930:                $rev1 = $1;
                   1931:                $sym1 = $3;
1.12      fenner   1932:        }
3.1       knu      1933:        if ($r1 eq 'text') {
3.80      knu      1934:                $rev1 = $tr1;
                   1935:                $sym1 = "";
1.12      fenner   1936:        }
3.80      knu      1937:
1.12      fenner   1938:        if ($r2 =~ /([^:]+)(:(.+))?/) {
3.80      knu      1939:                $rev2 = $1;
                   1940:                $sym2 = $3;
1.12      fenner   1941:        }
3.1       knu      1942:        if ($r2 eq 'text') {
3.80      knu      1943:                $rev2 = $tr2;
                   1944:                $sym2 = "";
1.12      fenner   1945:        }
3.15      knu      1946:
3.1       knu      1947:        # make sure the revisions a wellformed, for security
                   1948:        # reasons ..
3.15      knu      1949:        if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
3.80      knu      1950:                &fatal("404 Not Found",
                   1951:                        "Malformed query \"$ENV{QUERY_STRING}\"");
1.12      fenner   1952:        }
3.80      knu      1953:
                   1954:        #
                   1955:        # rev1 and rev2 are now both numeric revisions.
                   1956:        # Thus we do a DWIM here and swap them if rev1 is after rev2.
                   1957:        # XXX should we warn about the fact that we do this?
                   1958:        if (&revcmp($rev1, $rev2) > 0) {
                   1959:                my ($tmp1, $tmp2) = ($rev1, $sym1);
                   1960:                ($rev1, $sym1) = ($rev2, $sym2);
                   1961:                ($rev2, $sym2) = ($tmp1, $tmp2);
1.12      fenner   1962:        }
3.37      knu      1963:        my $difftype = $DIFFTYPES{$f};
                   1964:
                   1965:        if (!$difftype) {
3.80      knu      1966:                fatal("400 Bad arguments", "Diff format $f not understood");
3.1       knu      1967:        }
                   1968:
3.37      knu      1969:        my @difftype       = @{$difftype->{'opts'}};
                   1970:        my $human_readable = $difftype->{'colored'};
                   1971:
3.1       knu      1972:        # apply special options
3.3       knu      1973:        if ($showfunc) {
3.80      knu      1974:                push @difftype, '-p' if $f ne 's';
3.1       knu      1975:
3.80      knu      1976:                my ($re1, $re2);
3.1       knu      1977:
3.80      knu      1978:                while (($re1, $re2) = each %funcline_regexp) {
                   1979:                        if ($fullname =~ /$re1/) {
                   1980:                                push @difftype, '-F', $re2;
                   1981:                                last;
                   1982:                        }
3.1       knu      1983:                }
3.3       knu      1984:        }
3.80      knu      1985:
3.3       knu      1986:        if ($human_readable) {
3.80      knu      1987:                if ($hr_ignwhite) {
                   1988:                        push @difftype, '-w';
                   1989:                }
                   1990:                if ($hr_ignkeysubst) {
                   1991:                        push @difftype, '-kk';
                   1992:                }
3.1       knu      1993:        }
3.80      knu      1994:
                   1995:        if (!open($fh, "-|")) {    # child
                   1996:                open(STDERR, ">&STDOUT");    # Redirect stderr to stdout
3.86      knu      1997:                openOutputFilter();
3.95      knu      1998:                exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname) or exit -1;
3.1       knu      1999:        }
                   2000:        if ($human_readable) {
3.80      knu      2001:                http_header();
                   2002:                &human_readable_diff($fh, $rev2);
3.100   ! knu      2003:                html_footer();
3.80      knu      2004:                gzipclose();
                   2005:                exit;
                   2006:        } else {
                   2007:                http_header("text/plain");
3.1       knu      2008:        }
3.80      knu      2009:
                   2010:        #
                   2011:        #===================================================================
                   2012:        #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
                   2013:        #retrieving revision 1.16
                   2014:        #retrieving revision 1.17
                   2015:        #diff -c -r1.16 -r1.17
                   2016:        #*** /home/ncvs/src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
                   2017:        #--- /home/ncvs/src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17
                   2018:        #
                   2019:        # Ideas:
                   2020:        # - nuke the stderr output if it's what we expect it to be
                   2021:        # - Add "no differences found" if the diff command supplied no output.
                   2022:        #
                   2023:        #*** src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
                   2024:        #--- src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17 RELENG_2_1_0
                   2025:        # (bogus example, but...)
                   2026:        #
                   2027:        if (grep { $_ eq '-u' } @difftype) {
                   2028:                $f1 = '---';
                   2029:                $f2 = '\+\+\+';
                   2030:        } else {
                   2031:                $f1 = '\*\*\*';
                   2032:                $f2 = '---';
1.12      fenner   2033:        }
3.80      knu      2034:
3.1       knu      2035:        while (<$fh>) {
3.80      knu      2036:                if (m|^$f1 $cvsroot|o) {
                   2037:                        s|$cvsroot/||o;
                   2038:                        if ($sym1) {
                   2039:                                chop;
                   2040:                                $_ .= " $sym1\n";
                   2041:                        }
                   2042:                } elsif (m|^$f2 $cvsroot|o) {
                   2043:                        s|$cvsroot/||o;
                   2044:
                   2045:                        if ($sym2) {
                   2046:                                chop;
                   2047:                                $_ .= " $sym2\n";
                   2048:                        }
1.12      fenner   2049:                }
3.80      knu      2050:                print $_;
1.12      fenner   2051:        }
3.1       knu      2052:        close($fh);
1.12      fenner   2053: }
                   2054:
3.1       knu      2055: ###############################
                   2056: # Show Logs ..
                   2057: ###############################
3.12      knu      2058: sub getDirLogs($$@) {
3.80      knu      2059:        my ($cvsroot, $dirname, @otherFiles) = @_;
                   2060:        my ($state, $otherFiles, $tag, $file, $date, $branchpoint, $branch,
                   2061:            $log);
                   2062:        my ($rev, $revision, $revwanted, $filename, $head, $author);
                   2063:
                   2064:        $tag = $input{only_with_tag};
                   2065:
                   2066:        my ($DirName) = "$cvsroot/$where";
                   2067:        my (@files, @filetags);
                   2068:        my $fh = do { local (*FH); };
                   2069:
                   2070:        push (@files, &safeglob("$DirName/*,v"));
                   2071:        push (@files, &safeglob("$DirName/Attic/*,v"))
                   2072:            if (!$input{'hideattic'});
                   2073:        foreach $file (@otherFiles) {
                   2074:                push (@files, "$DirName/$file");
                   2075:        }
                   2076:
                   2077:        # just execute rlog if there are any files
                   2078:        if ($#files < 0) {
                   2079:                return;
                   2080:        }
                   2081:
                   2082:        if (defined($tag)) {
                   2083:
                   2084:                #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
3.86      knu      2085:                if (!open($fh, "-|")) {    # child
3.80      knu      2086:                        open(STDERR, '>/dev/null'); # rlog may complain; ignore.
3.86      knu      2087:                        openOutputFilter();
3.95      knu      2088:                        exec($CMD{rlog}, @files) or exit -1;
3.80      knu      2089:                }
                   2090:        } else {
                   2091:
3.86      knu      2092:                if (!open($fh, "-|")) {    # child
3.80      knu      2093:                        open(STDERR, '>/dev/null'); # rlog may complain; ignore.
3.86      knu      2094:                        openOutputFilter();
3.95      knu      2095:                        exec($CMD{rlog}, '-r', @files) or exit -1;
3.80      knu      2096:                }
3.1       knu      2097:        }
3.80      knu      2098:        $state = "start";
                   2099:
                   2100:        while (<$fh>) {
                   2101:                if ($state eq "start") {
                   2102:
                   2103:                        #Next file. Initialize file variables
                   2104:                        $rev         = '';
                   2105:                        $revwanted   = '';
                   2106:                        $branch      = '';
                   2107:                        $branchpoint = '';
                   2108:                        $filename    = '';
                   2109:                        $log         = '';
                   2110:                        $revision    = '';
                   2111:                        %symrev      = ();
                   2112:                        @filetags    = ();
                   2113:
                   2114:                        #jump to head state
                   2115:                        $state = "head";
                   2116:                }
                   2117:                print "$state:$_" if ($verbose);
                   2118:                again:
                   2119:
                   2120:                if ($state eq "head") {
                   2121:
                   2122:                        #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
                   2123:
                   2124:                        if (/^Working file: (.+)$/) {
                   2125:                                $filename = $1;
                   2126:                        } elsif (/^head: (.+)$/) {
                   2127:                                $head = $1;
                   2128:                        } elsif (/^branch: (.+)$/) {
                   2129:                                $branch = $1
                   2130:                        } elsif (/^symbolic names:/) {
                   2131:                                $state = "tags";
                   2132:                                ($branch = $head) =~ s/\.\d+$//
                   2133:                                    if $branch eq '';
                   2134:                                $branch =~ s/(\d+)$/0.$1/;
                   2135:                                $symrev{MAIN}  = $branch;
                   2136:                                $symrev{HEAD}  = $branch;
                   2137:                                $alltags{MAIN} = 1;
                   2138:                                $alltags{HEAD} = 1;
                   2139:                                push (@filetags, "MAIN", "HEAD");
                   2140:                        } elsif (/$LOG_REVSEPARATOR/o) {
                   2141:                                $state = "log";
                   2142:                                $rev   = '';
                   2143:                                $date  = '';
                   2144:                                $log   = '';
                   2145:
                   2146:                                # Try to reconstruct the relative filename if RCS spits out a full path
                   2147:                                $filename =~ s%^\Q$DirName\E/%%;
                   2148:                        }
3.41      knu      2149:                        next;
                   2150:                }
3.80      knu      2151:
                   2152:                if ($state eq "tags") {
3.94      knu      2153:                        if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
3.80      knu      2154:                                push (@filetags, $1);
                   2155:                                $symrev{$1}  = $2;
                   2156:                                $alltags{$1} = 1;
                   2157:                                next;
                   2158:                        } elsif (/^\S/) {
                   2159:
                   2160:                                if (defined($tag)) {
                   2161:                                        if (defined($symrev{$tag})
                   2162:                                            || $tag eq "HEAD")
                   2163:                                        {
                   2164:                                                $revwanted =
                   2165:                                                    $symrev{$tag eq "HEAD" ?
                   2166:                                                    "MAIN" : $tag};
                   2167:                                                ($branch = $revwanted) =~
                   2168:                                                    s/\b0\.//;
                   2169:                                                ($branchpoint = $branch) =~
                   2170:                                                    s/\.?\d+$//;
                   2171:                                                $revwanted = ''
                   2172:                                                    if ($revwanted ne $branch);
                   2173:                                        } elsif ($tag ne "HEAD") {
                   2174:                                                print
                   2175:                                                    "Tag not found, skip this file"
                   2176:                                                    if ($verbose);
                   2177:                                                $state = "skip";
                   2178:                                                next;
                   2179:                                        }
                   2180:                                }
                   2181:
                   2182:                                foreach my $tagfound (@filetags) {
                   2183:                                        $tags{$tagfound} = 1;
                   2184:                                }
                   2185:                                $state = "head";
                   2186:                                goto again;
                   2187:                        }
                   2188:                }
                   2189:
                   2190:                if ($state eq "log") {
                   2191:                        if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
                   2192:
                   2193:                                # End of a log entry.
                   2194:                                my $revbranch = $rev;
                   2195:                                $revbranch =~ s/\.\d+$//;
                   2196:                                print "$filename $rev Wanted: $revwanted ",
                   2197:                                    "Revbranch: $revbranch Branch: $branch ",
                   2198:                                    "Branchpoint: $branchpoint\n"
                   2199:                                    if ($verbose);
                   2200:
                   2201:                                if ($revwanted eq '' && $branch ne ''
                   2202:                                    && $branch eq $revbranch || !defined($tag))
                   2203:                                {
                   2204:                                        print
                   2205:                                            "File revision $rev found for branch $branch\n"
                   2206:                                            if ($verbose);
                   2207:                                        $revwanted = $rev;
                   2208:                                }
                   2209:
                   2210:                                if ($revwanted ne '' ? $rev eq $revwanted :
                   2211:                                    $branchpoint ne '' ? $rev eq $branchpoint :
                   2212:                                    0 && ($rev eq $head))
                   2213:                                {    # Don't think head is needed here..
                   2214:                                        print
                   2215:                                            "File info $rev found for $filename\n"
                   2216:                                            if ($verbose);
                   2217:                                        my @finfo =
                   2218:                                            ($rev, $date, $log, $author,
                   2219:                                                $filename);
                   2220:                                        my ($name);
                   2221:                                        ($name = $filename) =~ s%/.*%%;
                   2222:                                        $fileinfo{$name} = [@finfo];
                   2223:                                        $state = "done" if ($rev eq $revwanted);
                   2224:                                }
                   2225:                                $rev  = '';
                   2226:                                $date = '';
                   2227:                                $log  = '';
                   2228:                        } elsif ($date eq ''
                   2229:                            && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|
                   2230:                            )
                   2231:                        {
                   2232:                                my $yr = $1;
                   2233:
                   2234:                                # damn 2-digit year routines :-)
                   2235:                                if ($yr > 100) {
                   2236:                                        $yr -= 1900;
                   2237:                                }
                   2238:                                $date =
                   2239:                                    &Time::Local::timegm($6, $5, $4, $3, $2 - 1,
                   2240:                                        $yr);
                   2241:                                ($author) = /author: ([^;]+)/;
                   2242:                                $state = "log";
                   2243:                                $log   = '';
                   2244:                                next;
3.98      knu      2245:                        } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
                   2246:                                $rev = $1; # .*$ eats up the locker(lockers?) info, if any
3.80      knu      2247:                                next;
                   2248:                        } else {
                   2249:                                $log .= $_;
                   2250:                        }
                   2251:                }
                   2252:
                   2253:                if (/$LOG_FILESEPARATOR/o) {
                   2254:                        $state = "start";
                   2255:                        next;
3.41      knu      2256:                }
3.1       knu      2257:        }
3.80      knu      2258:
                   2259:        if ($. == 0) {
                   2260:                fatal("500 Internal Error", "Failed to spawn GNU rlog on <em>'"
                   2261:                        . join (", ", @files)
                   2262:                        . "'</em><p>Did you set the <b>\$command_path</b> in your configuration file correctly ? (Currently '$command_path'"
                   2263:                );
3.1       knu      2264:        }
3.80      knu      2265:        close($fh);
3.1       knu      2266: }
                   2267:
3.12      knu      2268: sub readLog($;$) {
3.80      knu      2269:        my ($fullname, $revision) = @_;
3.1       knu      2270:        my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
3.80      knu      2271:        my $fh = do { local (*FH); };
3.1       knu      2272:
                   2273:        if (defined($revision)) {
3.80      knu      2274:                $revision = "-r$revision";
                   2275:        } else {
                   2276:                $revision = "";
3.1       knu      2277:        }
                   2278:
                   2279:        undef %symrev;
                   2280:        undef %revsym;
                   2281:        undef @allrevisions;
                   2282:        undef %date;
                   2283:        undef %author;
                   2284:        undef %state;
                   2285:        undef %difflines;
                   2286:        undef %log;
1.12      fenner   2287:
                   2288:        print("Going to rlog '$fullname'\n") if ($verbose);
3.80      knu      2289:        if (!open($fh, "-|")) {    # child
                   2290:                if ($revision ne '') {
3.86      knu      2291:                        openOutputFilter();
3.95      knu      2292:                        exec($CMD{rlog}, $revision, $fullname) or exit -1;
3.80      knu      2293:                } else {
3.86      knu      2294:                        openOutputFilter();
3.95      knu      2295:                        exec($CMD{rlog}, $fullname) or exit -1;
3.80      knu      2296:                }
1.44      knu      2297:        }
3.80      knu      2298:
3.1       knu      2299:        while (<$fh>) {
3.80      knu      2300:                print if ($verbose);
                   2301:                if ($symnames) {
                   2302:                        if (/^\s+([^:]+):\s+([\d\.]+)/) {
                   2303:                                $symrev{$1} = $2;
                   2304:                        } else {
                   2305:                                $symnames = 0;
                   2306:                        }
                   2307:                } elsif (/^head:\s+([\d\.]+)/) {
                   2308:                        $head = $1;
                   2309:                } elsif (/^branch:\s+([\d\.]+)/) {
                   2310:                        $curbranch = $1;
                   2311:                } elsif (/^symbolic names/) {
                   2312:                        $symnames = 1;
                   2313:                } elsif (/^-----/) {
                   2314:                        last;
1.1       jfieber  2315:                }
                   2316:        }
3.1       knu      2317:        ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7       fenner   2318:
3.80      knu      2319:        # each log entry is of the form:
                   2320:        # ----------------------------
                   2321:        # revision 3.7.1.1
                   2322:        # date: 1995/11/29 22:15:52;  author: fenner;  state: Exp;  lines: +5 -3
                   2323:        # log info
                   2324:        # ----------------------------
3.98      knu      2325:
                   2326:        # For a locked revision, the first line after the separator
                   2327:        # becomes smth like
                   2328:        # revision 9.19 locked by: vassilii;
                   2329:
1.1       jfieber  2330:        logentry:
3.80      knu      2331:
3.32      knu      2332:        while (!/$LOG_FILESEPARATOR/o) {
3.80      knu      2333:                $_ = <$fh>;
                   2334:                last logentry if (!defined($_));    # EOF
                   2335:                print "R:", $_ if ($verbose);
3.98      knu      2336:                if (/^revision (\d+(?:\.\d+)+)/) {
3.80      knu      2337:                        $rev = $1;
                   2338:                        unshift (@allrevisions, $rev);
                   2339:                } elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
                   2340:                        next logentry;
                   2341:                } else {
                   2342:
                   2343:                        # The rlog output is syntactically ambiguous.  We must
                   2344:                        # have guessed wrong about where the end of the last log
                   2345:                        # message was.
                   2346:                        # Since this is likely to happen when people put rlog output
                   2347:                        # in their commit messages, don't even bother keeping
                   2348:                        # these lines since we don't know what revision they go with
                   2349:                        # any more.
                   2350:                        next logentry;
                   2351:
                   2352:                        #               &fatal("500 Internal Error","Error parsing RCS output: $_");
                   2353:                }
                   2354:                $_ = <$fh>;
                   2355:                print "D:", $_ if ($verbose);
                   2356:                if (
                   2357:                    m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
                   2358:                    )
                   2359:                {
                   2360:                        my $yr = $1;
                   2361:
                   2362:                        # damn 2-digit year routines :-)
                   2363:                        if ($yr > 100) {
                   2364:                                $yr -= 1900;
                   2365:                        }
                   2366:                        $date{$rev} =
                   2367:                            &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
                   2368:                        $author{$rev}    = $7;
                   2369:                        $state{$rev}     = $8;
                   2370:                        $difflines{$rev} = $10;
                   2371:                } else {
                   2372:                        &fatal("500 Internal Error",
                   2373:                                "Error parsing RCS output: $_");
                   2374:                }
                   2375:                line:
                   2376:
                   2377:                while (<$fh>) {
                   2378:                        print "L:", $_ if ($verbose);
                   2379:                        next line if (/^branches:\s/);
                   2380:                        last line
                   2381:                            if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
                   2382:                        $log{$rev} .= $_;
                   2383:                }
                   2384:                print "E:", $_ if ($verbose);
1.1       jfieber  2385:        }
3.1       knu      2386:        close($fh);
1.1       jfieber  2387:        print "Done reading RCS file\n" if ($verbose);
3.1       knu      2388:
3.80      knu      2389:        @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
                   2390:        print "Done sorting revisions", join (" ", @revorder), "\n"
                   2391:            if ($verbose);
                   2392:
                   2393:        #
                   2394:        # HEAD is an artificial tag which is simply the highest tag number on the main
                   2395:        # branch, unless there is a branch tag in the RCS file in which case it's the
                   2396:        # highest revision on that branch.  Find it by looking through @revorder; it
                   2397:        # is the first commit listed on the appropriate branch.
                   2398:        # This is not neccesary the same revision as marked as head in the RCS file.
3.1       knu      2399:        my $headrev = $curbranch || "1";
3.45      knu      2400:        ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
3.80      knu      2401:
3.1       knu      2402:        foreach $rev (@revorder) {
3.80      knu      2403:                if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
                   2404:                        $symrev{"HEAD"} = $rev;
                   2405:                        last;
                   2406:                }
1.1       jfieber  2407:        }
3.1       knu      2408:        ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
3.80      knu      2409:            if (!defined($symrev{"HEAD"}));
1.1       jfieber  2410:        print "Done finding HEAD\n" if ($verbose);
3.80      knu      2411:
                   2412:        #
                   2413:        # Now that we know all of the revision numbers, we can associate
                   2414:        # absolute revision numbers with all of the symbolic names, and
                   2415:        # pass them to the form so that the same association doesn't have
                   2416:        # to be built then.
                   2417:        #
3.1       knu      2418:        undef @branchnames;
                   2419:        undef %branchpoint;
                   2420:        undef $sel;
                   2421:
                   2422:        foreach (reverse sort keys %symrev) {
3.80      knu      2423:                $rev = $symrev{$_};
                   2424:                if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
                   2425:                        push (@branchnames, $_);
                   2426:
                   2427:                        #
                   2428:                        # A revision number of A.B.0.D really translates into
                   2429:                        # "the highest current revision on branch A.B.D".
                   2430:                        #
                   2431:                        # If there is no branch A.B.D, then it translates into
                   2432:                        # the head A.B .
                   2433:                        #
                   2434:                        # This reasoning also applies to the main branch A.B,
                   2435:                        # with the branch number 0.A, with the exception that
                   2436:                        # it has no head to translate to if there is nothing on
                   2437:                        # the branch, but I guess this can never happen?
                   2438:                        #
                   2439:                        # (the code below gracefully forgets about the branch
                   2440:                        # if it should happen)
                   2441:                        #
                   2442:                        $head = defined($2) ? $2 : "";
                   2443:                        $branch = $3;
                   2444:                        $branchrev = $head . ($head ne "" ? "." : "") . $branch;
                   2445:                        my $regex;
                   2446:                        $regex = quotemeta $branchrev;
                   2447:                        $rev   = $head;
                   2448:
                   2449:                        foreach my $r (@revorder) {
                   2450:                                if ($r =~ /^${regex}\b/) {
                   2451:                                        $rev = $branchrev;
                   2452:                                        last;
                   2453:                                }
                   2454:                        }
                   2455:                        next if ($rev eq "");
                   2456:
                   2457:                        if ($rev ne $head && $head ne "") {
                   2458:                                $branchpoint{$head} .= ", "
                   2459:                                    if ($branchpoint{$head});
                   2460:                                $branchpoint{$head} .= $_;
                   2461:                        }
1.8       fenner   2462:                }
3.80      knu      2463:                $revsym{$rev} .= ", " if ($revsym{$rev});
                   2464:                $revsym{$rev} .= $_;
3.89      knu      2465:                $sel .= "<option value=\"${rev}:${_}\">$_</option>\n";
1.1       jfieber  2466:        }
                   2467:        print "Done associating revisions with branches\n" if ($verbose);
3.1       knu      2468:
                   2469:        my ($onlyonbranch, $onlybranchpoint);
                   2470:        if ($onlyonbranch = $input{'only_with_tag'}) {
3.80      knu      2471:                $onlyonbranch = $symrev{$onlyonbranch};
                   2472:                if ($onlyonbranch =~ s/\b0\.//) {
                   2473:                        ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
                   2474:                } else {
                   2475:                        $onlybranchpoint = $onlyonbranch;
                   2476:                }
                   2477:
                   2478:                if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
                   2479:                        fatal("404 Tag not found",
                   2480:                                "Tag $input{'only_with_tag'} not defined");
                   2481:                }
1.8       fenner   2482:        }
1.1       jfieber  2483:
3.1       knu      2484:        undef @revisions;
                   2485:
                   2486:        foreach (@allrevisions) {
3.80      knu      2487:                ($br  = $_)  =~ s/\.\d+$//;
                   2488:                ($brp = $br) =~ s/\.\d+$//;
                   2489:                next
                   2490:                    if ($onlyonbranch && $br ne $onlyonbranch
                   2491:                    && $_ ne $onlybranchpoint);
                   2492:                unshift (@revisions, $_);
3.1       knu      2493:        }
                   2494:
                   2495:        if ($logsort eq "date") {
3.80      knu      2496:
                   2497:                # Sort the revisions in commit order an secondary sort on revision
                   2498:                # (secondary sort needed for imported sources, or the first main
                   2499:                # revision gets before the same revision on the 1.1.1 branch)
                   2500:                @revdisplayorder =
                   2501:                    sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) }
                   2502:                    @revisions;
                   2503:        } elsif ($logsort eq "rev") {
                   2504:
                   2505:                # Sort the revisions in revision order, highest first
                   2506:                @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
                   2507:        } else {
                   2508:
                   2509:                # No sorting. Present in the same order as rlog / cvs log
                   2510:                @revdisplayorder = @revisions;
3.1       knu      2511:        }
                   2512:
                   2513: }
                   2514:
3.37      knu      2515: sub printDiffLinks($$) {
3.80      knu      2516:        my ($text, $url) = @_;
                   2517:        my @extra;
3.37      knu      2518:
3.80      knu      2519:        local $_;
                   2520:        for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
                   2521:                my $f = $_ eq $defaultDiffType ? '' : $_;
3.37      knu      2522:
3.80      knu      2523:                push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
                   2524:        }
3.37      knu      2525:
3.80      knu      2526:        print &link($text, $url), ' (', join (', ', @extra), ')';
3.37      knu      2527: }
                   2528:
3.1       knu      2529: sub printLog($;$) {
                   2530:        my ($link, $br, $brp);
3.80      knu      2531:        ($_, $link) = @_;
                   2532:        ($br  = $_)  =~ s/\.\d+$//;
3.1       knu      2533:        ($brp = $br) =~ s/\.?\d+$//;
                   2534:        my ($isDead, $prev);
                   2535:
                   2536:        $link = 1 if (!defined($link));
                   2537:        $isDead = ($state{$_} eq "dead");
                   2538:
3.100   ! knu      2539:        print "<p>\n";
3.1       knu      2540:        if ($link && !$isDead) {
3.80      knu      2541:                my ($filename);
                   2542:                ($filename = $where) =~ s/^.*\///;
                   2543:                my ($fileurl) = urlencode($filename);
3.89      knu      2544:                print "<a name=\"rev$_\"></a>";
3.80      knu      2545:
                   2546:                if (defined($revsym{$_})) {
                   2547:                        foreach my $sym (split (", ", $revsym{$_})) {
3.89      knu      2548:                                print "<a name=\"$sym\"></a>";
3.80      knu      2549:                        }
3.1       knu      2550:                }
3.80      knu      2551:
                   2552:                if (defined($revsym{$br}) && $revsym{$br}
                   2553:                    && !defined($nameprinted{$br}))
                   2554:                {
                   2555:                        foreach my $sym (split (", ", $revsym{$br})) {
3.89      knu      2556:                                print "<a name=\"$sym\"></a>";
3.80      knu      2557:                        }
                   2558:                        $nameprinted{$br} = 1;
1.4       fenner   2559:                }
3.80      knu      2560:                print "\n Revision ";
                   2561:                &download_link($fileurl, $_, $_,
                   2562:                        $defaultViewable ? "text/x-cvsweb-markup" : undef);
                   2563:
                   2564:                if ($defaultViewable) {
                   2565:                        print " / (";
                   2566:                        &download_link($fileurl, $_, "download", $mimetype);
                   2567:                        print ")";
                   2568:                }
                   2569:
                   2570:                if (not $defaultTextPlain) {
                   2571:                        print " / (";
                   2572:                        &download_link($fileurl, $_, "as text", "text/plain");
                   2573:                        print ")";
                   2574:                }
                   2575:
                   2576:                if (!$defaultViewable) {
                   2577:                        print " / (";
                   2578:                        &download_link($fileurl, $_, "view",
                   2579:                                "text/x-cvsweb-markup");
                   2580:                        print ")";
                   2581:                }
                   2582:
                   2583:                if ($allow_annotate) {
                   2584:                        print " - ";
                   2585:                        print &link(
                   2586:                                'annotate',
                   2587:                                sprintf(
                   2588:                                        '%s/%s?annotate=%s%s', $scriptname,
                   2589:                                        urlencode($where),     $_,
                   2590:                                        $barequery
                   2591:                                )
                   2592:                        );
                   2593:                }
                   2594:
                   2595:                # Plus a select link if enabled, and this version isn't selected
                   2596:                if ($allow_version_select) {
                   2597:                        if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
                   2598:                                print " - ";
                   2599:                                print &link(
                   2600:                                        '[select for diffs]',
                   2601:                                        sprintf(
                   2602:                                                '%s?r1=%s%s', $scriptwhere,
                   2603:                                                $_,           $barequery
                   2604:                                        )
                   2605:                                );
                   2606:                        } else {
                   2607:                                print " - <b>[selected]</b>";
                   2608:                        }
3.1       knu      2609:                }
3.80      knu      2610:        } else {
3.89      knu      2611:                print "Revision <b>$_</b>";
3.1       knu      2612:        }
3.80      knu      2613:
3.1       knu      2614:        if (/^1\.1\.1\.\d+$/) {
3.80      knu      2615:                print " <i>(vendor branch)</i>";
3.1       knu      2616:        }
                   2617:        if (defined @mytz) {
3.80      knu      2618:                my ($est) = $mytz[(localtime($date{$_}))[8]];
                   2619:                print ", <i>", scalar localtime($date{$_}), " $est</i> (";
3.1       knu      2620:        } else {
3.80      knu      2621:                print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
3.1       knu      2622:        }
3.80      knu      2623:        print readableTime(time() - $date{$_}, 1), " ago)";
3.1       knu      2624:        print " by ";
3.36      knu      2625:        print "<i>", $author{$_}, "</i>\n";
3.89      knu      2626:        print "<br>Branch: <b>", $link ? link_tags($revsym{$br}) : $revsym{$br},
3.80      knu      2627:            "</b>\n"
3.1       knu      2628:            if ($revsym{$br});
3.89      knu      2629:        print "<br>CVS Tags: <b>", $link ? link_tags($revsym{$_}) : $revsym{$_},
3.80      knu      2630:            "</b>"
3.1       knu      2631:            if ($revsym{$_});
3.89      knu      2632:        print "<br>Branch point for: <b>",
3.80      knu      2633:            $link ? link_tags($branchpoint{$_}) : $branchpoint{$_}, "</b>\n"
3.1       knu      2634:            if ($branchpoint{$_});
3.80      knu      2635:
3.1       knu      2636:        # Find the previous revision
3.80      knu      2637:        my @prevrev = split (/\./, $_);
3.1       knu      2638:        do {
3.80      knu      2639:                if (--$prevrev[$#prevrev] <= 0) {
                   2640:
                   2641:                        # If it was X.Y.Z.1, just make it X.Y
                   2642:                        pop (@prevrev);
                   2643:                        pop (@prevrev);
                   2644:                }
                   2645:                $prev = join (".", @prevrev);
3.1       knu      2646:        } until (defined($date{$prev}) || $prev eq "");
3.80      knu      2647:
3.1       knu      2648:        if ($prev ne "") {
3.80      knu      2649:                if ($difflines{$_}) {
                   2650:                        print
3.89      knu      2651:                            "<br>Changes since <b>$prev: $difflines{$_} lines</b>";
3.80      knu      2652:                }
3.1       knu      2653:        }
3.80      knu      2654:
3.1       knu      2655:        if ($isDead) {
3.89      knu      2656:                print "<br><b><i>FILE REMOVED</i></b>\n";
3.80      knu      2657:        } elsif ($link) {
                   2658:                my %diffrev = ();
                   2659:                $diffrev{$_} = 1;
                   2660:                $diffrev{""} = 1;
3.96      knu      2661:                print '<br>';
                   2662:                my $diff = 'Diff';
3.80      knu      2663:
                   2664:                #
                   2665:                # Offer diff to previous revision
                   2666:                if ($prev) {
                   2667:                        $diffrev{$prev} = 1;
                   2668:
                   2669:                        my $url =
                   2670:                            sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere,
                   2671:                                $prev, $_, $barequery);
                   2672:
3.96      knu      2673:                        print $diff, " to previous ";
                   2674:                        $diff = '';
3.80      knu      2675:                        printDiffLinks($prev, $url);
                   2676:                }
                   2677:
                   2678:                #
                   2679:                # Plus, if it's on a branch, and it's not a vendor branch,
                   2680:                # offer a diff with the branch point.
                   2681:                if ($revsym{$brp} && !/^1\.1\.1\.\d+$/
                   2682:                    && !defined($diffrev{$brp}))
                   2683:                {
                   2684:                        my $url =
                   2685:                            sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $brp,
                   2686:                                $_, $barequery);
                   2687:
3.96      knu      2688:                        print $diff, " to branchpoint ";
                   2689:                        $diff = '';
3.80      knu      2690:                        printDiffLinks($brp, $url);
                   2691:                }
                   2692:
                   2693:                #
                   2694:                # Plus, if it's on a branch, and it's not a vendor branch,
                   2695:                # offer to diff with the next revision of the higher branch.
                   2696:                # (e.g. change gets committed and then brought
                   2697:                # over to -stable)
                   2698:                if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
                   2699:                        my ($i, $nextmain);
                   2700:
                   2701:                        for ($i = 0 ; $i < $#revorder && $revorder[$i] ne $_ ;
                   2702:                            $i++)
                   2703:                        {
                   2704:                        }
                   2705:                        my @tmp2 = split (/\./, $_);
                   2706:                        for ($nextmain = "" ; $i > 0 ; $i--) {
                   2707:                                my $next = $revorder[$i - 1];
                   2708:                                my @tmp1 = split (/\./, $next);
                   2709:
                   2710:                                if (@tmp1 < @tmp2) {
                   2711:                                        $nextmain = $next;
                   2712:                                        last;
                   2713:                                }
                   2714:
                   2715:                                # Only the highest version on a branch should have
                   2716:                                # a diff for the "next main".
                   2717:                                last
                   2718:                                    if (@tmp1 - 1 <= @tmp2
                   2719:                                    && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
                   2720:                                    join (".", @tmp2[0 .. $#tmp1 - 1]));
                   2721:                        }
3.35      knu      2722:
3.80      knu      2723:                        if (!defined($diffrev{$nextmain})) {
                   2724:                                $diffrev{$nextmain} = 1;
3.35      knu      2725:
3.80      knu      2726:                                my $url =
                   2727:                                    sprintf('%s.diff?r1=%s&r2=%s%s',
                   2728:                                        $scriptwhere, $nextmain, $_,
                   2729:                                        $barequery);
3.35      knu      2730:
3.96      knu      2731:                                print $diff, " next main ";
                   2732:                                $diff = '';
3.80      knu      2733:                                printDiffLinks($nextmain, $url);
                   2734:                        }
1.1       jfieber  2735:                }
3.35      knu      2736:
3.80      knu      2737:                # Plus if user has selected only r1, then present a link
                   2738:                # to make a diff to that revision
                   2739:                if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
                   2740:                        $diffrev{$input{"r1"}} = 1;
                   2741:
                   2742:                        my $url =
                   2743:                            sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere,
                   2744:                                $input{'r1'}, $_, $barequery);
                   2745:
3.96      knu      2746:                        print $diff, " to selected ";
                   2747:                        $diff = '';
3.80      knu      2748:                        printDiffLinks($input{'r1'}, $url);
                   2749:                }
3.96      knu      2750:
                   2751:                print '<br>' if $diff;
1.1       jfieber  2752:        }
3.100   ! knu      2753:        print "\n</p>\n<pre>\n";
3.1       knu      2754:        print &htmlify($log{$_}, 1);
3.89      knu      2755:        print "</pre>\n";
3.1       knu      2756: }
                   2757:
3.12      knu      2758: sub doLog($) {
3.80      knu      2759:        my ($fullname) = @_;
3.1       knu      2760:        my ($diffrev, $upwhere, $filename, $backurl);
3.12      knu      2761:
3.1       knu      2762:        readLog($fullname);
                   2763:
3.80      knu      2764:        html_header("CVS log for $where");
                   2765:        ($upwhere  = $where) =~ s|(Attic/)?[^/]+$||;
                   2766:        ($filename = $where) =~ s|^.*/||;
                   2767:        $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
3.100   ! knu      2768:        print "<p>\n ";
3.80      knu      2769:        print &link($backicon, "$backurl#$filename"), " <b>Up to ",
3.100   ! knu      2770:            &clickablePath($upwhere, 1), "</b>\n</p>\n";
        !          2771:        print "<p>\n ";
3.35      knu      2772:        print &link('Request diff between arbitrary revisions', '#diff');
3.100   ! knu      2773:        print "\n</p>\n<hr noshade>\n";
3.35      knu      2774:
3.100   ! knu      2775:        print "<p>\n";
3.1       knu      2776:        if ($curbranch) {
3.80      knu      2777:                print "Default branch: ", ($revsym{$curbranch} || $curbranch);
                   2778:        } else {
                   2779:                print "No default branch";
3.1       knu      2780:        }
3.89      knu      2781:        print "<br>\n";
3.80      knu      2782:
3.1       knu      2783:        if ($input{only_with_tag}) {
3.89      knu      2784:                print "Current tag: $input{only_with_tag}<br>\n";
3.1       knu      2785:        }
3.100   ! knu      2786:        print "</p>\n";
3.1       knu      2787:
                   2788:        undef %nameprinted;
                   2789:
3.80      knu      2790:        for (my $i = 0 ; $i <= $#revdisplayorder ; $i++) {
3.100   ! knu      2791:                print "<hr size=\"1\" noshade>\n";
3.80      knu      2792:                printLog($revdisplayorder[$i]);
3.1       knu      2793:        }
                   2794:
3.100   ! knu      2795:        print "<hr noshade>\n<p>\n";
3.89      knu      2796:        print "<a name=\"diff\">\n";
1.1       jfieber  2797:        print "This form allows you to request diff's between any two\n";
                   2798:        print "revisions of a file.  You may select a symbolic revision\n";
                   2799:        print "name using the selection box or you may type in a numeric\n";
                   2800:        print "name using the type-in text box.\n";
3.100   ! knu      2801:        print "</a>\n</p>\n";
3.80      knu      2802:        print
3.89      knu      2803:            "<form method=\"get\" action=\"${scriptwhere}.diff\" name=\"diff_select\">\n";
3.80      knu      2804:
                   2805:        foreach (@stickyvars) {
3.89      knu      2806:                printf('<input type="hidden" name="%s" value="%s">', $_,
3.80      knu      2807:                    $input{$_})
                   2808:                    if (defined($input{$_})
3.23      knu      2809:                    && ((!defined($DEFAULTVALUE{$_})
3.80      knu      2810:                    || $input{$_} ne $DEFAULTVALUE{$_}) && $input{$_} ne ""));
3.1       knu      2811:        }
3.100   ! knu      2812:        print "<table style=\"border: none\">\n<tr>\n";
3.89      knu      2813:        print "<td align=\"right\">Diffs between \n";
                   2814:        print "<select name=\"r1\">\n";
                   2815:        print "<option value=\"text\" selected>Use Text Field</option>\n";
1.1       jfieber  2816:        print $sel;
3.89      knu      2817:        print "</select>\n";
3.1       knu      2818:        $diffrev = $revdisplayorder[$#revdisplayorder];
                   2819:        $diffrev = $input{"r1"} if (defined($input{"r1"}));
3.80      knu      2820:        print
3.100   ! knu      2821:            "<input type=\"text\" size=\"$inputTextSize\" name=\"tr1\" value=\"$diffrev\" onchange=\"document.diff_select.r1.selectedIndex=0\"></td>\n";
        !          2822:        print "<td><br></td>\n</tr>\n";
        !          2823:        print "<tr>\n<td align=\"right\">and \n";
3.89      knu      2824:        print "<select name=\"r2\">\n";
                   2825:        print "<option value=\"text\" selected>Use Text Field</option>\n";
1.1       jfieber  2826:        print $sel;
3.89      knu      2827:        print "</select>\n";
3.1       knu      2828:        $diffrev = $revdisplayorder[0];
                   2829:        $diffrev = $input{"r2"} if (defined($input{"r2"}));
3.80      knu      2830:        print
3.100   ! knu      2831:            "<input type=\"text\" size=\"$inputTextSize\" name=\"tr2\" value=\"$diffrev\" onchange=\"document.diff_select.r2.selectedIndex=0\"></td>\n";
3.89      knu      2832:        print "<td><input type=\"submit\" value=\"  Get Diffs  \"></td>\n";
3.100   ! knu      2833:        print "</tr>\n</table>\n";
3.89      knu      2834:        print "</form>\n";
                   2835:        print "<hr noshade>\n";
                   2836:        print "<form method=\"get\" action=\"$scriptwhere\">\n";
3.100   ! knu      2837:        print "<table style=\"border: none\">\n";
        !          2838:        print "<tr>\n<td align=\"right\">Preferred Diff type:</td>\n";
3.89      knu      2839:        print "<td>";
3.21      knu      2840:        printDiffSelect($use_java_script);
3.100   ! knu      2841:        print "</td>\n<td></td>\n</tr>\n";
3.80      knu      2842:
                   2843:        if (@branchnames) {
3.100   ! knu      2844:                print "<tr>\n<td align=\"right\">View only Branch:</td>\n";
3.89      knu      2845:                print "<td>";
                   2846:                print "<a name=\"branch\"></a>\n";
                   2847:                print "<select name=\"only_with_tag\"";
                   2848:                print " onchange=\"this.form.submit()\"" if $use_java_script;
3.80      knu      2849:                print ">\n";
3.89      knu      2850:                print "<option value=\"\"";
                   2851:                print " selected"
3.80      knu      2852:                    if (defined($input{"only_with_tag"})
                   2853:                    && $input{"only_with_tag"} eq "");
3.89      knu      2854:                print ">Show all branches</option>\n";
3.80      knu      2855:
                   2856:                foreach (reverse sort @branchnames) {
3.89      knu      2857:                        print "<option";
                   2858:                        print " selected"
3.80      knu      2859:                            if (defined($input{"only_with_tag"})
                   2860:                            && $input{"only_with_tag"} eq $_);
3.89      knu      2861:                        print ">${_}</option>\n";
3.80      knu      2862:                }
3.100   ! knu      2863:                print "</select></td>\n<td></td>\n</tr>\n";
1.7       fenner   2864:        }
3.80      knu      2865:
3.1       knu      2866:        foreach (@stickyvars) {
3.80      knu      2867:                next if ($_ eq "f");
                   2868:                next if ($_ eq "only_with_tag");
                   2869:                next if ($_ eq "logsort");
3.89      knu      2870:                print "<input type=\"hidden\" name=\"$_\" value=\"$input{$_}\">\n"
3.80      knu      2871:                    if (defined($input{$_})
3.23      knu      2872:                    && (!defined($DEFAULTVALUE{$_})
3.80      knu      2873:                    || $input{$_} ne $DEFAULTVALUE{$_}) && $input{$_} ne "");
3.1       knu      2874:        }
3.100   ! knu      2875:        print "<tr>\n<td align=\"right\">";
3.89      knu      2876:        print "<a name=\"logsort\"></a>\n";
3.100   ! knu      2877:        print "Sort log by:</td>\n";
3.89      knu      2878:        print "<td>";
3.37      knu      2879:        printLogSortSelect($use_java_script);
3.100   ! knu      2880:        print "</td>\n";
        !          2881:        print "<td><input type=\"submit\" value=\"  Set  \"></td>\n";
        !          2882:        print "</tr>\n</table>\n";
3.89      knu      2883:        print "</form>\n";
3.100   ! knu      2884:        html_footer();
1.10      wosch    2885: }
                   2886:
3.12      knu      2887: sub flush_diff_rows($$$$) {
3.80      knu      2888:        my $j;
                   2889:        my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
3.82      knu      2890:
                   2891:        if (!defined($state)) {
                   2892:                return;
                   2893:        }
                   2894:
3.80      knu      2895:        if ($state eq "PreChangeRemove") {    # we just got remove-lines before
                   2896:                for ($j = 0 ; $j < $leftRow ; $j++) {
                   2897:                        print
3.100   ! knu      2898:                            "<tr>\n<td class=\"diff-removed\">&nbsp;@$leftColRef[$j]</td>\n";
3.80      knu      2899:                        print
3.100   ! knu      2900:                            "<td class=\"diff-empty\">&nbsp;</td>\n</tr>\n";
3.80      knu      2901:                }
                   2902:        } elsif ($state eq "PreChange") {    # state eq "PreChange"
                   2903:                    # we got removes with subsequent adds
                   2904:
                   2905:                for ($j = 0 ; $j < $leftRow || $j < $rightRow ; $j++)
                   2906:                {    # dump out both cols
3.100   ! knu      2907:                        print "<tr>\n";
3.80      knu      2908:                        if ($j < $leftRow) {
                   2909:                                print
3.100   ! knu      2910:                                    "<td class=\"diff-changed\">&nbsp;@$leftColRef[$j]</td>";
3.80      knu      2911:                        } else {
                   2912:                                print
3.100   ! knu      2913:                                    "<td class=\"diff-changed-missing\">&nbsp;</td>";
3.80      knu      2914:                        }
3.100   ! knu      2915:                        print "\n";
3.80      knu      2916:
                   2917:                        if ($j < $rightRow) {
                   2918:                                print
3.100   ! knu      2919:                                    "<td class=\"diff-changed\">&nbsp;@$rightColRef[$j]</td>";
3.80      knu      2920:                        } else {
                   2921:                                print
3.100   ! knu      2922:                                    "<td class=\"diff-changed-missing\">&nbsp;</td>";
3.80      knu      2923:                        }
3.100   ! knu      2924:                        print "\n</tr>\n";
3.80      knu      2925:                }
                   2926:        }
3.1       knu      2927: }
                   2928:
                   2929: ##
                   2930: # Function to generate Human readable diff-files
                   2931: # human_readable_diff(String revision_to_return_to);
                   2932: ##
3.80      knu      2933: sub human_readable_diff($) {
                   2934:        my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
                   2935:        my ($fh, $rev) = @_;
                   2936:        my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
                   2937:        my (@rightCol, @leftCol);
                   2938:
                   2939:        ($where_nd       = $where)       =~ s/.diff$//;
                   2940:        ($filename       = $where_nd)    =~ s/^.*\///;
                   2941:        ($pathname       = $where_nd)    =~ s/(Attic\/)?[^\/]*$//;
                   2942:        ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
                   2943:
                   2944:        navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
                   2945:
                   2946:        # Read header to pick up read revision and date, if possible
                   2947:        while (<$fh>) {
                   2948:                ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
                   2949:                ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
                   2950:                last if (/^\+\+\+ /);
                   2951:        }
                   2952:
                   2953:        if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
                   2954:                $rev1  = $r1r;
                   2955:                $date1 = $r1d;
                   2956:        }
                   2957:        if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
                   2958:                $rev2  = $r2r;
                   2959:                $date2 = $r2d;
                   2960:        }
                   2961:
                   2962:        print
3.100   ! knu      2963:            "<h3 style=\"text-align: center\">Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
        !          2964:            # Using style=\"border: none\" here breaks NS 4.x badly...
3.89      knu      2965:            "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n",
3.100   ! knu      2966:            "<tr style=\"background-color: #ffffff\">\n", "<th width=\"50%\" valign=\"top\">",
3.80      knu      2967:            "version $rev1";
                   2968:        print ", $date1"         if (defined($date1));
                   2969:        print "<br>Tag: $sym1\n" if ($sym1);
3.89      knu      2970:        print "</th>\n", "<th width=\"50%\" valign=\"top\">", "version $rev2";
3.80      knu      2971:        print ", $date2"         if (defined($date2));
                   2972:        print "<br>Tag: $sym2\n" if ($sym1);
                   2973:        print "</th>\n";
                   2974:
                   2975:        my $leftRow  = 0;
                   2976:        my $rightRow = 0;
                   2977:        my ($oldline, $newline, $funname, $diffcode, $rest);
                   2978:
                   2979:        # Process diff text
                   2980:
                   2981:        # prefetch several lines
                   2982:        my @buf = head($fh);
                   2983:
                   2984:        my %d = scan_directives(@buf);
                   2985:
                   2986:        while (@buf || !eof($fh)) {
                   2987:                $difftxt = @buf ? shift @buf : <$fh>;
                   2988:
                   2989:                if ($difftxt =~ /^@@/) {
                   2990:                        ($oldline, $newline, $funname) =
                   2991:                            $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
                   2992:                        $funname = htmlquote($funname);
3.100   ! knu      2993:                        $funname =~ s/\s/&nbsp;/go;
3.80      knu      2994:                        print
3.100   ! knu      2995:                            "<tr class=\"diff-heading\">\n<td width=\"50%\">";
3.80      knu      2996:                        print
3.100   ! knu      2997:                            "<table width=\"100%\" border=\"1\" cellpadding=\"5\">\n<tr>\n<td><b>Line&nbsp;$oldline</b>";
3.80      knu      2998:                        print
3.100   ! knu      2999:                            "&nbsp;<span style=\"font-size: smaller\">$funname</span></td>\n</tr>\n</table>";
        !          3000:                        print "</td>\n<td width=\"50%\">";
3.80      knu      3001:                        print
3.100   ! knu      3002:                            "<table width=\"100%\" border=\"1\" cellpadding=\"5\">\n<tr>\n<td><b>Line&nbsp;$newline</b>";
3.80      knu      3003:                        print
3.100   ! knu      3004:                            "&nbsp;<span style=\"font-size: smaller\">$funname</span></td>\n</tr>\n</table>\n";
3.80      knu      3005:                        print "</td>\n";
                   3006:                        $state    = "dump";
                   3007:                        $leftRow  = 0;
                   3008:                        $rightRow = 0;
                   3009:                } else {
                   3010:                        ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
                   3011:                        $_ = spacedHtmlText($rest, $d{'tabstop'});
                   3012:
                   3013:                        #########
                   3014:                        # little state machine to parse unified-diff output (Hen, zeller@think.de)
                   3015:                        # in order to get some nice 'ediff'-mode output
                   3016:                        # states:
                   3017:                        #  "dump"             - just dump the value
                   3018:                        #  "PreChangeRemove"  - we began with '-' .. so this could be the start of a 'change' area or just remove
                   3019:                        #  "PreChange"        - okey, we got several '-' lines and moved to '+' lines -> this is a change block
                   3020:                        ##########
                   3021:
                   3022:                        if ($diffcode eq '+') {
                   3023:                                if ($state eq "dump")
                   3024:                                { # 'change' never begins with '+': just dump out value
                   3025:                                        print
3.100   ! knu      3026:                                            "<tr>\n<td class=\"diff-empty\">&nbsp;</td>\n<td class=\"diff-added\">&nbsp;$_</td>\n</tr>\n";
3.80      knu      3027:                                } else {    # we got minus before
                   3028:                                        $state = "PreChange";
                   3029:                                        $rightCol[$rightRow++] = $_;
                   3030:                                }
                   3031:                        } elsif ($diffcode eq '-') {
                   3032:                                $state = "PreChangeRemove";
                   3033:                                $leftCol[$leftRow++] = $_;
                   3034:                        } else {    # empty diffcode
                   3035:                                flush_diff_rows \@leftCol, \@rightCol, $leftRow,
                   3036:                                    $rightRow;
3.100   ! knu      3037:                                print "<tr>\n<td class=\"diff-same\">&nbsp;$_</td>\n<td class=\"diff-same\">&nbsp;$_</td>\n</tr>\n";
3.80      knu      3038:                                $state    = "dump";
                   3039:                                $leftRow  = 0;
                   3040:                                $rightRow = 0;
                   3041:                        }
                   3042:                }
                   3043:        }
3.89      knu      3044:        close($fh);
                   3045:
3.80      knu      3046:        flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
                   3047:
                   3048:        # state is empty if we didn't have any change
                   3049:        if (!$state) {
3.100   ! knu      3050:                print "<tr>\n<td colspan=\"2\">&nbsp;</td>\n</tr>\n";
        !          3051:                print "<tr class=\"diff-empty\">\n";
3.80      knu      3052:                print
3.100   ! knu      3053:                    "<td colspan=\"2\" align=\"center\"><b>- No viewable change -</b></td>\n</tr>\n";
3.80      knu      3054:        }
3.100   ! knu      3055:        print "</table>\n";
3.80      knu      3056:
3.100   ! knu      3057:        print "<hr style=\"width: 100%\" noshade>\n";
        !          3058:        print "<form method=\"get\" action=\"${scriptwhere}\">\n";
        !          3059:        print "<table style=\"border: none\">\n<tr>\n<td>\n";
3.80      knu      3060:
                   3061:        # print legend
3.100   ! knu      3062:        print "<table border=\"1\">\n<tr>\n<td>";
        !          3063:        print "Legend:<br><table style=\"border: none\" cellspacing=\"0\" cellpadding=\"1\">\n";
3.80      knu      3064:        print
3.100   ! knu      3065:            "<tr>\n<td align=\"center\" class=\"diff-removed\">Removed from v.$rev1</td>\n<td class=\"diff-empty\">&nbsp;</td>\n</tr>\n";
3.80      knu      3066:        print
3.100   ! knu      3067:            "<tr class=\"diff-changed\">\n<td align=\"center\" colspan=\"2\">changed lines</td>\n</tr>\n";
3.80      knu      3068:        print
3.100   ! knu      3069:            "<tr>\n<td class=\"diff-empty\">&nbsp;</td>\n<td align=\"center\" class=\"diff-added\">Added in v.$rev2</td>\n</tr>\n";
        !          3070:        print "</table>\n</td>\n</tr>\n</table>\n</td>\n<td>";
3.80      knu      3071:
                   3072:        # Print format selector
                   3073:        foreach my $var (keys %input) {
                   3074:                next if ($var eq "f");
                   3075:                next
                   3076:                    if (defined($DEFAULTVALUE{$var})
                   3077:                    && $DEFAULTVALUE{$var} eq $input{$var});
3.89      knu      3078:                print "<input type=\"hidden\" name=\"", urlencode($var),
                   3079:                    "\" value=\"", urlencode($input{$var}), "\">\n";
3.80      knu      3080:        }
                   3081:        printDiffSelect($use_java_script);
3.89      knu      3082:        print "<input type=\"submit\" value=\"Show\">\n";
3.100   ! knu      3083:        print "</td>\n";
        !          3084:
        !          3085:        print "</tr>\n</table>\n";
3.89      knu      3086:        print "</form>\n";
3.1       knu      3087: }
                   3088:
3.12      knu      3089: sub navigateHeader($$$$$) {
3.80      knu      3090:        my ($swhere, $path, $filename, $rev, $title) = @_;
                   3091:        $swhere = "" if ($swhere eq $scriptwhere);
                   3092:        $swhere = './' . urlencode($filename) if ($swhere eq "");
3.64      knu      3093:
3.100   ! knu      3094:        # TODO: this should be moved into external CSS file.
        !          3095:        my $css = '';
        !          3096:        if ($title eq 'diff') {
        !          3097:            $css = "
        !          3098: <style type=\"text/css\">
        !          3099: .diff-heading {
        !          3100:   background-color: $diffcolorHeading;
        !          3101: }
        !          3102: .diff-same {
        !          3103:   font-family: $difffontface;
        !          3104:   font-size: smaller;
        !          3105: }
        !          3106: .diff-empty {
        !          3107:   background-color: $diffcolorEmpty;
        !          3108: }
        !          3109: .diff-added {
        !          3110:   background-color: $diffcolorAdd;
        !          3111:   font-family: $difffontface;
        !          3112:   font-size: smaller;
        !          3113: }
        !          3114: .diff-removed {
        !          3115:   background-color: $diffcolorRemove;
        !          3116:   font-family: $difffontface;
        !          3117:   font-size: smaller;
        !          3118: }
        !          3119: .diff-changed {
        !          3120:   background-color: $diffcolorChange;
        !          3121:   font-family: $difffontface;
        !          3122:   font-size: smaller;
        !          3123: }
        !          3124: .diff-changed-missing {
        !          3125:   background-color: $diffcolorDarkChange;
        !          3126: }
        !          3127: </style>";
        !          3128:        }
        !          3129:
3.80      knu      3130:        print <<EOF;
3.100   ! knu      3131: $HTML_DOCTYPE
3.89      knu      3132: <html>
                   3133: <head>
                   3134: <meta name="robots" content="nofollow">
3.100   ! knu      3135: <meta http-equiv="Content-Script-Type" content="application/x-javascript">
        !          3136: <meta http-equiv="Content-Style-Type" content="text/css">
3.87      knu      3137: <!-- FreeBSD-cvsweb $cvsweb_revision -->
3.100   ! knu      3138: <title>$path$filename - $title - $rev</title>$css
3.89      knu      3139: </head>
3.64      knu      3140: $body_tag_for_src
3.100   ! knu      3141: <table width="100%" style="border: none; background-color: $navigationHeaderColor" cellspacing="0" cellpadding="1">
3.89      knu      3142: <tr valign="bottom"><td>
3.64      knu      3143: EOF
                   3144:
3.80      knu      3145:        print &link($backicon, "$swhere$query#rev$rev");
                   3146:        print "<b>Return to ", &link($filename, "$swhere$query#rev$rev"),
                   3147:            " CVS log";
                   3148:        print "</b> $fileicon</td>";
                   3149:
3.89      knu      3150:        print "<td align=\"right\">$diricon <b>Up to ",
                   3151:          &clickablePath($path, 1),
3.80      knu      3152:            "</b></td>";
                   3153:        print "</tr></table>";
3.1       knu      3154: }
                   3155:
3.12      knu      3156: sub plural_write($$) {
3.80      knu      3157:        my ($num, $text) = @_;
                   3158:        if ($num != 1) {
                   3159:                $text .= "s";
                   3160:        }
                   3161:
                   3162:        if ($num > 0) {
                   3163:                return join (' ', $num, $text);
                   3164:        } else {
                   3165:                return "";
                   3166:        }
3.1       knu      3167: }
                   3168:
                   3169: ##
                   3170: # print readable timestamp in terms of
                   3171: # '..time ago'
                   3172: # H. Zeller <zeller@think.de>
                   3173: ##
3.12      knu      3174: sub readableTime($$) {
3.80      knu      3175:        my ($i, $break, $retval);
                   3176:        my ($secs, $long) = @_;
3.1       knu      3177:
3.80      knu      3178:        # this function works correct for time >= 2 seconds
                   3179:        if ($secs < 2) {
                   3180:                return "very little time";
                   3181:        }
                   3182:
                   3183:        my %desc = (
                   3184:                1,        'second', 60,     'minute', 3600,    'hour',
                   3185:                86400,    'day',    604800, 'week',   2628000, 'month',
                   3186:                31536000, 'year'
                   3187:        );
                   3188:        my @breaks = sort { $a <=> $b } keys %desc;
                   3189:        $i = 0;
3.1       knu      3190:
3.80      knu      3191:        while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
                   3192:                $i++;
                   3193:        }
3.1       knu      3194:        $i--;
3.80      knu      3195:        $break  = $breaks[$i];
                   3196:        $retval = plural_write(int($secs / $break), $desc{$break});
                   3197:
                   3198:        if ($long == 1 && $i > 0) {
                   3199:                my $rest = $secs % $break;
                   3200:                $i--;
                   3201:                $break = $breaks[$i];
                   3202:                my $resttime = plural_write(int($rest / $break), $desc{$break});
                   3203:                if ($resttime) {
                   3204:                        $retval .= ", $resttime";
                   3205:                }
3.1       knu      3206:        }
                   3207:
3.80      knu      3208:        return $retval;
3.1       knu      3209: }
                   3210:
                   3211: ##
                   3212: # clickablePath(String pathname, boolean last_item_clickable)
                   3213: #
                   3214: # returns a html-ified path whereas each directory is a link for
                   3215: # faster navigation. last_item_clickable controls whether the
                   3216: # basename (last directory/file) is a link as well
                   3217: ##
                   3218: sub clickablePath($$) {
3.80      knu      3219:        my ($pathname, $clickLast) = @_;
                   3220:        my $retval = '';
3.12      knu      3221:
3.80      knu      3222:        if ($pathname eq '/') {
                   3223:
                   3224:                # this should never happen - chooseCVSRoot() is
                   3225:                # intended to do this
                   3226:                $retval = "[$cvstree]";
                   3227:        } else {
                   3228:                $retval .= ' ' . &link("[$cvstree]",
                   3229:                        sprintf('%s/%s#dirlist', $scriptname, $query));
                   3230:                my $wherepath = '';
                   3231:                my ($lastslash) = $pathname =~ m|/$|;
                   3232:
                   3233:                foreach (split (/\//, $pathname)) {
                   3234:                        $retval .= " / ";
                   3235:                        $wherepath .= "/$_";
                   3236:                        my ($last) = "$wherepath/" eq "/$pathname"
                   3237:                            || $wherepath eq "/$pathname";
                   3238:
                   3239:                        if ($clickLast || !$last) {
                   3240:                                $retval .= &link($_,
                   3241:                                        join ('', $scriptname,
                   3242:                                        urlencode($wherepath),
                   3243:                                        (!$last || $lastslash ? '/' : ''),
                   3244:                                        $query,
                   3245:                                        (!$last || $lastslash ? "#dirlist" : "")
                   3246:                                ));
                   3247:                        } else {    # do not make a link to the current dir
                   3248:                                $retval .= $_;
                   3249:                        }
                   3250:                }
3.1       knu      3251:        }
3.80      knu      3252:        return $retval;
3.1       knu      3253: }
                   3254:
                   3255: sub chooseCVSRoot() {
3.100   ! knu      3256:
        !          3257:        print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3.80      knu      3258:        if (2 <= @CVSROOT) {
                   3259:                my ($k);
                   3260:                foreach $k (keys %input) {
3.89      knu      3261:                        print "<input type=\"hidden\" name=\"$k\" value=\"$input{$k}\">\n"
3.80      knu      3262:                            if ($input{$k}) && ($k ne "cvsroot");
                   3263:                }
                   3264:
                   3265:                # Form-Elements look wierd in Netscape if the background
                   3266:                # isn't gray and the form elements are not placed
                   3267:                # within a table ...
3.100   ! knu      3268:                print "<table style=\"border: none\">\n<tr>\n";
        !          3269:                print "<td>CVS Root:</td>\n";
3.80      knu      3270:                print "<td>\n<select name=\"cvsroot\"";
3.89      knu      3271:                print " onchange=\"this.form.submit()\"" if $use_java_script;
3.80      knu      3272:                print ">\n";
                   3273:
                   3274:                foreach $k (@CVSROOT) {
                   3275:                        print "<option value=\"$k\"";
                   3276:                        print " selected" if ($k eq $cvstree);
3.89      knu      3277:                        print ">",($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k),
3.80      knu      3278:                            "</option>\n";
                   3279:                }
3.100   ! knu      3280:                print "</select>\n</td>\n<td>";
3.80      knu      3281:        } else {
                   3282:
3.100   ! knu      3283:                # no choice -- but we need the form to select module/path,
        !          3284:                # at least for Netscape
        !          3285:                print "<p>\n";
3.80      knu      3286:                print "CVS Root: <b>[$cvstree]</b>";
3.1       knu      3287:        }
3.57      knu      3288:
3.80      knu      3289:        print " Module path or alias:\n";
3.89      knu      3290:        print "<input type=\"text\" name=\"path\" value=\"\" size=\"15\">\n";
                   3291:        print "<input type=\"submit\" value=\"Go\">";
3.80      knu      3292:
                   3293:        if (2 <= @CVSROOT) {
3.100   ! knu      3294:                print "</td>\n</tr>\n</table>";
        !          3295:        } else {
        !          3296:                print "</p>";
3.80      knu      3297:        }
3.100   ! knu      3298:        print "\n</form>";
3.1       knu      3299: }
                   3300:
                   3301: sub chooseMirror() {
3.80      knu      3302:        my ($mirror, $moremirrors);
                   3303:        $moremirrors = 0;
                   3304:
                   3305:        # This code comes from the original BSD-cvsweb
                   3306:        # and may not be useful for your site; If you don't
                   3307:        # set %MIRRORS this won't show up, anyway
                   3308:        #
                   3309:        # Should perhaps exlude the current site somehow..
                   3310:        if (keys %MIRRORS) {
                   3311:                print "\nThis cvsweb is mirrored in:\n";
                   3312:
                   3313:                foreach $mirror (keys %MIRRORS) {
                   3314:                        print ", " if ($moremirrors);
                   3315:                        print &link(htmlquote($mirror), $MIRRORS{$mirror});
                   3316:                        $moremirrors = 1;
                   3317:                }
                   3318:                print "<p>\n";
3.1       knu      3319:        }
                   3320: }
                   3321:
3.12      knu      3322: sub fileSortCmp() {
3.80      knu      3323:        my ($comp) = 0;
                   3324:        my ($c, $d, $af, $bf);
3.1       knu      3325:
3.80      knu      3326:        ($af = $a) =~ s/,v$//;
                   3327:        ($bf = $b) =~ s/,v$//;
                   3328:        my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
                   3329:            if (defined($fileinfo{$af}));
                   3330:        my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
                   3331:            if (defined($fileinfo{$bf}));
                   3332:
                   3333:        if (defined($filename1) && defined($filename2) && $af eq $filename1
                   3334:            && $bf eq $filename2)
                   3335:        {
                   3336:
                   3337:                # Two files
                   3338:                $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
                   3339:                $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
                   3340:                $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
                   3341:                $comp = ($author1 cmp $author2)
                   3342:                    if ($byauthor && $author1 && $author2);
                   3343:        }
                   3344:
                   3345:        if ($comp == 0) {
                   3346:
                   3347:                # Directories first, then sorted on name if no other sort critera
                   3348:                # available.
                   3349:                my $ad = ((-d "$fullname/$a") ? "D" : "F");
                   3350:                my $bd = ((-d "$fullname/$b") ? "D" : "F");
                   3351:                ($c = $a) =~ s|.*/||;
                   3352:                ($d = $b) =~ s|.*/||;
                   3353:                $comp = ("$ad$c" cmp "$bd$d");
                   3354:        }
                   3355:        return $comp;
3.1       knu      3356: }
                   3357:
                   3358: # make A url for downloading
3.12      knu      3359: sub download_url($$;$) {
3.80      knu      3360:        my ($url, $revision, $mimetype) = @_;
3.1       knu      3361:
3.80      knu      3362:        $revision =~ s/\b0\.//;
3.1       knu      3363:
3.80      knu      3364:        if (defined($checkoutMagic)
                   3365:            && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
                   3366:        {
                   3367:                my $path = $where;
3.84      knu      3368:                $path =~ s|[^/]+$||;
3.80      knu      3369:                $url = "$scriptname/$checkoutMagic/${path}$url";
                   3370:        }
                   3371:        $url .= "?rev=$revision";
                   3372:        $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.67      knu      3373:
3.80      knu      3374:        $url;
3.1       knu      3375: }
                   3376:
3.12      knu      3377: # Presents a link to download the
3.1       knu      3378: # selected revision
3.12      knu      3379: sub download_link($$$;$) {
3.80      knu      3380:        my ($url, $revision, $textlink, $mimetype) = @_;
                   3381:        my ($fullurl) = download_url($url, $revision, $mimetype);
3.35      knu      3382:
3.80      knu      3383:        $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
3.70      knu      3384:
3.89      knu      3385:        printf '<a href="%s"', hrefquote("$fullurl$barequery");
3.35      knu      3386:
3.80      knu      3387:        if ($open_extern_window
                   3388:            && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
                   3389:        {
                   3390:                print ' target="cvs_checkout"';
                   3391:
                   3392:                # we should have
                   3393:                #   'if (document.cvswin==null) document.cvswin=window.open(...'
                   3394:                # in order to allow the user to resize the window; otherwise
                   3395:                # the user may resize the window, but on next checkout - zap -
                   3396:                # its original (configured s. cvsweb.conf) size is back again
                   3397:                # .. annoying (if $extern_window_(width|height) is defined)
                   3398:                # but this if (..) solution is far from perfect
                   3399:                # what we need to do as well is
                   3400:                # 1) save cvswin in an invisible frame that always exists
                   3401:                #    (document.cvswin will be void on next load)
                   3402:                # 2) on close of the cvs_checkout - window set the cvswin
                   3403:                #    variable to 'null' again - so that it will be
                   3404:                #    reopenend with the configured size
                   3405:                # anyone a JavaScript programmer ?
                   3406:                # .. so here without if (..):
                   3407:                # currently, the best way is to comment out the size parameters
                   3408:                # ($extern_window...) in cvsweb.conf.
                   3409:                if ($use_java_script) {
                   3410:                        my @attr = qw(resizeable scrollbars);
                   3411:
                   3412:                        push @attr, qw(status toolbar)
                   3413:                            if (defined($mimetype) && $mimetype eq "text/html");
                   3414:
                   3415:                        push @attr, "width=$extern_window_width"
                   3416:                            if (defined($extern_window_width));
                   3417:
                   3418:                        push @attr, "height=$extern_window_height"
                   3419:                            if (defined($extern_window_height));
                   3420:
3.89      knu      3421:                        # We need the "return false" here to prevent browsers
                   3422:                        # from following the href after the onclick handler.
                   3423:                        # This would effectively load the same document in
                   3424:                        # the same window *twice*.
3.80      knu      3425:                        printf
3.89      knu      3426:                            q` onclick="window.open('%s','cvs_checkout','%s');return false"`,
3.80      knu      3427:                            hrefquote($fullurl), join (',', @attr);
                   3428:                }
3.1       knu      3429:        }
3.89      knu      3430:        print "><b>$textlink</b></a>";
3.1       knu      3431: }
                   3432:
                   3433: # Returns a Query string with the
                   3434: # specified parameter toggled
                   3435: sub toggleQuery($$) {
3.80      knu      3436:        my ($toggle, $value) = @_;
                   3437:        my ($newquery, $var);
                   3438:        my (%vars);
                   3439:        %vars = %input;
                   3440:
                   3441:        if (defined($value)) {
                   3442:                $vars{$toggle} = $value;
                   3443:        } else {
                   3444:                $vars{$toggle} = $vars{$toggle} ? 0 : 1;
                   3445:        }
                   3446:
                   3447:        # Build a new query of non-default paramenters
                   3448:        $newquery = "";
                   3449:        foreach $var (@stickyvars) {
                   3450:                my ($value) = defined($vars{$var}) ? $vars{$var} : "";
                   3451:                my ($default) =
                   3452:                    defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
                   3453:
                   3454:                if ($value ne $default) {
                   3455:                        $newquery .= "&" if ($newquery ne "");
                   3456:                        $newquery .= urlencode($var) . "=" . urlencode($value);
                   3457:                }
                   3458:        }
                   3459:
                   3460:        if ($newquery) {
                   3461:                return '?' . $newquery;
                   3462:        }
                   3463:        return "";
3.1       knu      3464: }
                   3465:
3.12      knu      3466: sub urlencode($) {
3.80      knu      3467:        local ($_) = @_;
3.35      knu      3468:
3.80      knu      3469:        s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3.35      knu      3470:
3.80      knu      3471:        $_;
3.35      knu      3472: }
                   3473:
                   3474: sub htmlquote($) {
3.80      knu      3475:        local ($_) = @_;
3.35      knu      3476:
3.80      knu      3477:        # Special Characters; RFC 1866
                   3478:        s/&/&amp;/g;
                   3479:        s/\"/&quot;/g;
                   3480:        s/</&lt;/g;
                   3481:        s/>/&gt;/g;
3.35      knu      3482:
3.80      knu      3483:        $_;
3.1       knu      3484: }
                   3485:
3.36      knu      3486: sub htmlunquote($) {
3.80      knu      3487:        local ($_) = @_;
3.36      knu      3488:
3.80      knu      3489:        # Special Characters; RFC 1866
                   3490:        s/&quot;/\"/g;
                   3491:        s/&lt;/</g;
                   3492:        s/&gt;/>/g;
                   3493:        s/&amp;/&/g;
3.36      knu      3494:
3.80      knu      3495:        $_;
3.36      knu      3496: }
                   3497:
3.46      knu      3498: sub hrefquote($) {
3.80      knu      3499:        local ($_) = @_;
3.46      knu      3500:
3.80      knu      3501:        y/ /+/;
3.46      knu      3502:
3.80      knu      3503:        htmlquote($_)
3.46      knu      3504: }
                   3505:
3.12      knu      3506: sub http_header(;$) {
3.80      knu      3507:        my $content_type = shift || "text/html";
3.50      knu      3508:
3.80      knu      3509:        $content_type .= "; charset=$charset"
                   3510:            if $content_type =~ m,^text/, && defined($charset) && $charset;
                   3511:
                   3512:        if (defined($moddate)) {
                   3513:                if ($is_mod_perl) {
                   3514:                        Apache->request->header_out(
                   3515:                                "Last-Modified" => scalar gmtime($moddate)
                   3516:                                . " GMT");
                   3517:                } else {
                   3518:                        print "Last-Modified: ", scalar gmtime($moddate),
                   3519:                            " GMT\r\n";
                   3520:                }
                   3521:        }
3.50      knu      3522:
3.1       knu      3523:        if ($is_mod_perl) {
3.80      knu      3524:                Apache->request->content_type($content_type);
                   3525:        } else {
3.89      knu      3526:                print "Content-Type: $content_type\r\n";
3.1       knu      3527:        }
3.80      knu      3528:
                   3529:        if ($allow_compress && $maycompress) {
                   3530:                if ($has_zlib
                   3531:                    || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c"))
                   3532:                    )
                   3533:                {
                   3534:
                   3535:                        if ($is_mod_perl) {
                   3536:                                Apache->request->content_encoding("x-gzip");
                   3537:                                Apache->request->header_out(
                   3538:                                        Vary => "Accept-Encoding");
                   3539:                                Apache->request->send_http_header;
                   3540:                        } else {
3.89      knu      3541:                                print "Content-Encoding: x-gzip\r\n";
3.80      knu      3542:                                print "Vary: Accept-Encoding\r\n"
                   3543:                                    ;            #RFC 2068, 14.43
                   3544:                                print "\r\n";    # Close headers
                   3545:                        }
                   3546:                        $| = 1;
                   3547:                        $| = 0;    # Flush header output
                   3548:
                   3549:                        if ($has_zlib) {
                   3550:                                tie *GZIP, __PACKAGE__, \*STDOUT;
                   3551:                        }
                   3552:                        select(GZIP);
                   3553:                        $gzip_open = 1;
                   3554:
                   3555:                        #           print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
                   3556:                } else {
                   3557:                        if ($is_mod_perl) {
                   3558:                                Apache->request->send_http_header;
                   3559:                        } else {
                   3560:                                print "\r\n";    # Close headers
                   3561:                        }
                   3562:                        print
3.100   ! knu      3563:                            "<span style=\"font-size: smaller\">Unable to find gzip binary in the <b>\$command_path</b> ($command_path) to compress output</span><br>";
3.80      knu      3564:                }
                   3565:        } else {
                   3566:
                   3567:                if ($is_mod_perl) {
                   3568:                        Apache->request->send_http_header;
                   3569:                } else {
                   3570:                        print "\r\n";    # Close headers
                   3571:                }
3.1       knu      3572:        }
                   3573: }
                   3574:
                   3575: sub html_header($) {
3.80      knu      3576:        my ($title) = @_;
                   3577:        http_header("text/html");
                   3578:        print <<EOH;
3.100   ! knu      3579: $HTML_DOCTYPE
3.1       knu      3580: <html>
3.40      knu      3581: <head>
3.43      knu      3582: <meta name="robots" content="nofollow">
3.100   ! knu      3583: <meta http-equiv="Content-Script-Type" content="application/x-javascript">
        !          3584: <meta http-equiv="Content-Style-Type" content="text/css">
3.1       knu      3585: <title>$title</title>
3.87      knu      3586: <!-- FreeBSD-cvsweb $cvsweb_revision -->
3.1       knu      3587: </head>
                   3588: $body_tag
                   3589: $logo <h1 align="center">$title</h1>
                   3590: EOH
                   3591: }
                   3592:
3.12      knu      3593: sub html_footer() {
3.100   ! knu      3594:        print "<hr noshade>\n<address>$address</address>\n</body>\n</html>\n";
3.1       knu      3595: }
                   3596:
3.12      knu      3597: sub link_tags($) {
3.80      knu      3598:        my ($tags) = @_;
                   3599:        my ($ret)  = "";
                   3600:        my ($fileurl, $filename);
                   3601:
                   3602:        ($filename = $where) =~ s/^.*\///;
                   3603:        $fileurl = './' . urlencode($filename);
                   3604:
                   3605:        foreach my $sym (split (", ", $tags)) {
                   3606:                $ret .= ",\n" if ($ret ne "");
                   3607:                $ret .=
                   3608:                    &link($sym, $fileurl . toggleQuery('only_with_tag', $sym));
                   3609:        }
                   3610:        return "$ret\n";
3.1       knu      3611: }
                   3612:
                   3613: #
3.81      knu      3614: # See if a module is listed in the config file's @HideModules list.
3.1       knu      3615: #
3.12      knu      3616: sub forbidden_module($) {
3.80      knu      3617:        my ($module) = @_;
3.81      knu      3618:        local $_;
3.12      knu      3619:
3.81      knu      3620:        for (@HideModules) {
                   3621:                return 1 if $module =~ $_;
3.80      knu      3622:        }
3.81      knu      3623:        return 0;
                   3624: }
3.1       knu      3625:
3.81      knu      3626: sub forbidden_file($) {
                   3627:        my ($path) = @_;
                   3628:        $path =  substr($path, length($cvsroot) + 1);
                   3629:        local $_;
                   3630:        for (@ForbiddenFiles) {
                   3631:                return 1 if $path =~ $_;
                   3632:        }
3.80      knu      3633:        return 0;
3.25      knu      3634: }
                   3635:
                   3636: # Close the GZIP handle remove the tie.
                   3637:
                   3638: sub gzipclose {
                   3639:        if ($gzip_open) {
3.80      knu      3640:                select(STDOUT);
                   3641:                close(GZIP);
                   3642:                untie *GZIP;
                   3643:                $gzip_open = 0;
3.25      knu      3644:        }
3.23      knu      3645: }
                   3646:
                   3647: # implement a gzipped file handle via the Compress:Zlib compression
                   3648: # library.
                   3649:
                   3650: sub MAGIC1() { 0x1f }
                   3651: sub MAGIC2() { 0x8b }
3.80      knu      3652: sub OSCODE() { 3 }
3.23      knu      3653:
                   3654: sub TIEHANDLE {
                   3655:        my ($class, $out) = @_;
3.80      knu      3656:        my ($d) = Compress::Zlib::deflateInit(
                   3657:                -Level      => Compress::Zlib::Z_BEST_COMPRESSION(),
                   3658:                -WindowBits => -Compress::Zlib::MAX_WBITS()
                   3659:        ) or return undef;
3.23      knu      3660:        my ($o) = {
                   3661:                handle => $out,
3.80      knu      3662:                dh     => $d,
                   3663:                crc    => 0,
                   3664:                len    => 0,
3.23      knu      3665:        };
3.80      knu      3666:        my ($header) =
                   3667:            pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0, 0, 0,
                   3668:            0, 0, 0, OSCODE);
3.23      knu      3669:        print {$o->{handle}} $header;
                   3670:        return bless($o, $class);
                   3671: }
                   3672:
                   3673: sub PRINT {
3.80      knu      3674:        my ($o)   = shift;
                   3675:        my ($buf) = join (defined $, ? $, : "", @_);
3.23      knu      3676:        my ($len) = length($buf);
                   3677:        my ($compressed, $status) = $o->{dh}->deflate($buf);
                   3678:        print {$o->{handle}} $compressed if defined($compressed);
                   3679:        $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
                   3680:        $o->{len} += $len;
                   3681:        return $len;
                   3682: }
                   3683:
                   3684: sub PRINTF {
3.80      knu      3685:        my ($o)   = shift;
3.23      knu      3686:        my ($fmt) = shift;
                   3687:        my ($buf) = sprintf($fmt, @_);
                   3688:        my ($len) = length($buf);
                   3689:        my ($compressed, $status) = $o->{dh}->deflate($buf);
                   3690:        print {$o->{handle}} $compressed if defined($compressed);
                   3691:        $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
                   3692:        $o->{len} += $len;
                   3693:        return $len;
                   3694: }
                   3695:
                   3696: sub WRITE {
                   3697:        my ($o, $buf, $len, $off) = @_;
                   3698:        my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
                   3699:        print {$o->{handle}} $compressed if defined($compressed);
                   3700:        $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
                   3701:        $o->{len} += $len;
                   3702:        return $len;
                   3703: }
                   3704:
                   3705: sub CLOSE {
                   3706:        my ($o) = @_;
3.80      knu      3707:        return if !defined($o->{dh});
3.23      knu      3708:        my ($buf) = $o->{dh}->flush();
                   3709:        $buf .= pack("V V", $o->{crc}, $o->{len});
                   3710:        print {$o->{handle}} $buf;
                   3711:        undef $o->{dh};
                   3712: }
                   3713:
                   3714: sub DESTROY {
                   3715:        my ($o) = @_;
                   3716:        CLOSE($o);
1.1       jfieber  3717: }

CVSweb