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

Annotation of cvsweb/cvsweb.cgi, Revision 3.119.2.25

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

CVSweb