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

Annotation of cvsweb/cvsweb.cgi, Revision 3.119.2.10

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

CVSweb