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

Annotation of cvsweb/cvsweb.cgi, Revision 3.112

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

CVSweb