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

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.77

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

CVSweb