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

Annotation of cvsweb/cvsweb.cgi, Revision 3.102

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

CVSweb