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

Annotation of cvsweb/cvsweb.cgi, Revision 3.119.2.13

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