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

Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.34

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

CVSweb