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

Annotation of cvsweb/cvsweb.cgi, Revision 3.119.2.24

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

CVSweb