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

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.75

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:
                     16: #   http://www.FreeBSD.org/cgi/cvsweb.cgi/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 $
        !            47: # $FreeBSD: www/en/cgi/cvsweb.cgi,v 1.74 2001/07/06 09:58:17 knu Exp $
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.75! knu       237: $_ = q$FreeBSD: www/en/cgi/cvsweb.cgi,v 1.74 2001/07/06 09:58:17 knu Exp $;
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.65  knu      1138:        redirect("$newplace$query");
1.12      fenner   1139:        exit;
1.45.2.75! knu      1140: } elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
1.45.2.46  knu      1141:        http_header("text/plain");
1.12      fenner   1142:        print "You matched the following files:\n";
1.45.2.75! knu      1143:        print join ("\n", @files);
        !          1144:
1.12      fenner   1145:        # Find the tags from each file
                   1146:        # Display a form offering diffs between said tags
1.45.2.75! knu      1147: } else {
        !          1148:        my $fh = do { local (*FH); };
1.45.2.46  knu      1149:        my ($xtra, $module);
1.45.2.75! knu      1150:
1.12      fenner   1151:        # Assume it's a module name with a potential path following it.
1.45.2.59  knu      1152:        $xtra = (($module = $where) =~ s|/.*||) ? $& : '';
1.45.2.75! knu      1153:
1.12      fenner   1154:        # Is there an indexed version of modules?
1.45.2.67  knu      1155:        if (open($fh, "< $cvsroot/CVSROOT/modules")) {
1.45.2.75! knu      1156:                while (<$fh>) {
        !          1157:                        if (/^(\S+)\s+(\S+)/o && $module eq $1
        !          1158:                            && -d "$cvsroot/$2" && $module ne $2)
        !          1159:                        {
        !          1160:                                redirect("$scriptname/$2$xtra$query");
        !          1161:                        }
1.12      fenner   1162:                }
                   1163:        }
1.45.2.75! knu      1164:        &fatal("404 Not Found", "$where: no such file or directory");
        !          1165: }
1.45.2.51  knu      1166:
1.45.2.52  knu      1167: gzipclose();
1.45.2.75! knu      1168:
1.45.2.46  knu      1169: ## End MAIN
                   1170:
1.45.2.47  knu      1171: sub printDiffSelect($) {
1.45.2.75! knu      1172:        my ($use_java_script) = @_;
        !          1173:        my $f = $input{'f'};
        !          1174:
        !          1175:        print '<SELECT NAME="f"';
        !          1176:        print ' onchange="submit()"' if $use_java_script;
        !          1177:        print '>';
1.45.2.56  knu      1178:
1.45.2.75! knu      1179:        local $_;
        !          1180:        for (@DIFFTYPES) {
        !          1181:                printf('<OPTION VALUE="%s"%s>%s', $_,
        !          1182:                    $f eq $_ ? ' SELECTED' : '', "\u$DIFFTYPES{$_}{'descr'}");
        !          1183:        }
1.45.2.56  knu      1184:
1.45.2.75! knu      1185:        print "</SELECT>";
1.45.2.56  knu      1186: }
                   1187:
                   1188: sub printLogSortSelect($) {
1.45.2.75! knu      1189:        my ($use_java_script) = @_;
        !          1190:
        !          1191:        print '<SELECT NAME="logsort"';
        !          1192:        print ' onchange="submit()"' if $use_java_script;
        !          1193:        print '>';
1.45.2.56  knu      1194:
1.45.2.75! knu      1195:        local $_;
        !          1196:        for (@LOGSORTKEYS) {
        !          1197:                printf('<OPTION VALUE="%s"%s>%s', $_,
        !          1198:                    $logsort eq $_ ? ' SELECTED' : '',
        !          1199:                    "\u$LOGSORTKEYS{$_}{'descr'}");
        !          1200:        }
1.45.2.56  knu      1201:
1.45.2.75! knu      1202:        print "</SELECT>";
1.45.2.46  knu      1203: }
                   1204:
1.45.2.47  knu      1205: sub findLastModifiedSubdirs(@) {
1.45.2.75! knu      1206:        my (@dirs) = @_;
        !          1207:        my ($dirname, @files);
1.45.2.46  knu      1208:
1.45.2.75! knu      1209:        foreach $dirname (@dirs) {
        !          1210:                next if ($dirname eq ".");
        !          1211:                next if ($dirname eq "..");
        !          1212:                my ($dir) = "$fullname/$dirname";
        !          1213:                next if (!-d $dir);
        !          1214:
        !          1215:                my ($lastmod)     = undef;
        !          1216:                my ($lastmodtime) = undef;
        !          1217:                my $dh = do { local (*DH); };
        !          1218:
        !          1219:                opendir($dh, $dir) || next;
        !          1220:                my (@filenames) = readdir($dh);
        !          1221:                closedir($dh);
        !          1222:
        !          1223:                foreach my $filename (@filenames) {
        !          1224:                        $filename = "$dirname/$filename";
        !          1225:                        my ($file) = "$fullname/$filename";
        !          1226:                        next if ($filename !~ /,v$/ || !-f $file);
        !          1227:                        $filename =~ s/,v$//;
        !          1228:                        my $modtime = -M $file;
        !          1229:
        !          1230:                        if (!defined($lastmod) || $modtime < $lastmodtime) {
        !          1231:                                $lastmod     = $filename;
        !          1232:                                $lastmodtime = $modtime;
        !          1233:                        }
        !          1234:                }
        !          1235:                push (@files, $lastmod) if (defined($lastmod));
1.45.2.46  knu      1236:        }
1.45.2.75! knu      1237:        return @files;
1.12      fenner   1238: }
                   1239:
1.45.2.56  knu      1240: sub htmlify_sub(&$) {
1.45.2.75! knu      1241:        (my $proc, local $_) = @_;
        !          1242:        my @a = split (m`(<a [^>]+>[^<]*</a>)`i);
        !          1243:        my $linked;
        !          1244:        my $result = '';
        !          1245:
        !          1246:        while (($_, $linked) = splice(@a, 0, 2)) {
        !          1247:                &$proc();
        !          1248:                $result .= $_      if defined($_);
        !          1249:                $result .= $linked if defined($linked);
        !          1250:        }
1.12      fenner   1251:
1.45.2.75! knu      1252:        $result;
1.45.2.56  knu      1253: }
1.12      fenner   1254:
1.45.2.56  knu      1255: sub htmlify($;$) {
1.45.2.75! knu      1256:        (local $_, my $extra) = @_;
1.45.2.46  knu      1257:
1.45.2.75! knu      1258:        $_ = htmlquote($_);
1.45.2.49  knu      1259:
1.45.2.75! knu      1260:        # get URL's as link
        !          1261:        s{
1.45.2.56  knu      1262:       (http|ftp|https)://\S+
                   1263:      }{
                   1264:         &link($&, htmlunquote($&))
                   1265:      }egx;
                   1266:
1.45.2.75! knu      1267:        # get e-mails as link
        !          1268:        $_ = htmlify_sub {
        !          1269:                s<
1.45.2.56  knu      1270:          [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
                   1271:            ><
                   1272:              &link($&, "mailto:$&")
                   1273:                >egix;
1.45.2.75! knu      1274:            }
        !          1275:            $_;
        !          1276:
        !          1277:        if ($extra) {
1.45.2.56  knu      1278:
1.45.2.75! knu      1279:                # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
        !          1280:                if (defined($prcgi) && defined($re_prcategories)
        !          1281:                    && defined($re_prkeyword))
        !          1282:                {
        !          1283:                        my $prev;
1.45.2.56  knu      1284:
1.45.2.75! knu      1285:                        do {
        !          1286:                                $prev = $_;
1.45.2.56  knu      1287:
1.45.2.75! knu      1288:                                $_ = htmlify_sub {
        !          1289:                                        s{
1.45.2.63  knu      1290:                      (\b$re_prkeyword[:\#]?\s*
1.45.2.56  knu      1291:                       (?:
                   1292:                        \#?
                   1293:                        \d+[,\s]\s*
                   1294:                       )*
                   1295:                       \#?)
                   1296:                      (\d+)\b
                   1297:                     }{
1.45.2.58  knu      1298:                         $1 . &link($2, sprintf($prcgi, $2))
1.45.2.56  knu      1299:                     }egix;
1.45.2.75! knu      1300:                                    }
        !          1301:                                    $_;
        !          1302:                        } while ($_ ne $prev);
1.45.2.56  knu      1303:
1.45.2.75! knu      1304:                        $_ = htmlify_sub {
        !          1305:                                s{
1.45.2.63  knu      1306:                  (\b$re_prcategories/(\d+)\b)
1.45.2.56  knu      1307:                 }{
1.45.2.58  knu      1308:                     &link($1, sprintf($prcgi, $2))
1.45.2.56  knu      1309:                 }egox;
1.45.2.75! knu      1310:                            }
        !          1311:                            $_;
        !          1312:                }
1.45.2.56  knu      1313:
1.45.2.75! knu      1314:                # get manpage specs as link: "foo.1" "foo(1)"
        !          1315:                if (defined($mancgi)) {
        !          1316:                        $_ = htmlify_sub {
        !          1317:                                s{
1.45.2.63  knu      1318:                  (\b([a-zA-Z][\w.]+)
1.45.2.56  knu      1319:                   (?:
                   1320:                    \( ([0-9n]) \)\B
                   1321:                    |
                   1322:                    \.([0-9n])\b
                   1323:                   )
                   1324:                  )
                   1325:                 }{
1.45.2.63  knu      1326:                     &link($1, sprintf($mancgi, defined($3) ? $3 : $4, $2))
1.45.2.56  knu      1327:                 }egx;
1.45.2.75! knu      1328:                            }
        !          1329:                            $_;
        !          1330:                }
1.12      fenner   1331:        }
                   1332:
1.45.2.75! knu      1333:        $_;
1.45.2.46  knu      1334: }
                   1335:
1.45.2.51  knu      1336: sub spacedHtmlText($;$) {
1.45.2.47  knu      1337:        local $_ = $_[0];
1.45.2.51  knu      1338:        my $ts = $_[1] || $tabstop;
1.45.2.46  knu      1339:
1.45.2.51  knu      1340:        # Cut trailing spaces and tabs
                   1341:        s/[ \t]+$//;
1.45.2.46  knu      1342:
1.45.2.75! knu      1343:        if (defined($ts)) {
        !          1344:
        !          1345:                # Expand tabs
        !          1346:                1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e
1.45.2.51  knu      1347:        }
1.45.2.46  knu      1348:
                   1349:        # replace <tab> and <space> (\001 is to protect us from htmlify)
                   1350:        # gzip can make excellent use of this repeating pattern :-)
                   1351:        if ($hr_breakable) {
1.45.2.75! knu      1352:
        !          1353:                # make every other space 'breakable'
        !          1354:                s/  / \001nbsp;/g;    # 2 * <space>
        !          1355:                                      # leave single space as it is
1.45.2.51  knu      1356:        } else {
1.45.2.75! knu      1357:                s/ /\001nbsp;/g;
1.45.2.46  knu      1358:        }
                   1359:
1.45.2.47  knu      1360:        $_ = htmlify($_);
1.45.2.46  knu      1361:
                   1362:        # unescape
1.45.2.51  knu      1363:        y/\001/&/;
1.45.2.46  knu      1364:
1.45.2.47  knu      1365:        return $_;
1.12      fenner   1366: }
                   1367:
1.45.2.47  knu      1368: sub link($$) {
1.45.2.75! knu      1369:        my ($name, $url) = @_;
1.12      fenner   1370:
1.45.2.75! knu      1371:        $url =~ s/:/sprintf("%%%02x", ord($&))/eg
        !          1372:            if $url =~ /^[^a-z]/;    # relative
1.45.2.69  knu      1373:
1.45.2.67  knu      1374:        sprintf '<A HREF="%s">%s</A>', hrefquote($url), $name;
1.12      fenner   1375: }
                   1376:
1.45.2.47  knu      1377: sub revcmp($$) {
1.45.2.75! knu      1378:        my ($rev1, $rev2) = @_;
1.45.2.48  knu      1379:
                   1380:        # make no comparison for a tag or a branch
                   1381:        return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
                   1382:
1.45.2.75! knu      1383:        my (@r1) = split (/\./, $rev1);
        !          1384:        my (@r2) = split (/\./, $rev2);
        !          1385:        my ($a, $b);
        !          1386:
        !          1387:        while (($a = shift (@r1)) && ($b = shift (@r2))) {
        !          1388:                if ($a != $b) {
        !          1389:                        return $a <=> $b;
        !          1390:                }
1.12      fenner   1391:        }
                   1392:        if (@r1) { return 1; }
                   1393:        if (@r2) { return -1; }
                   1394:        return 0;
                   1395: }
                   1396:
1.45.2.47  knu      1397: sub fatal($$) {
1.45.2.75! knu      1398:        my ($errcode, $errmsg) = @_;
1.45.2.46  knu      1399:        if ($is_mod_perl) {
1.45.2.75! knu      1400:                Apache->request->status((split (/ /, $errcode))[0]);
        !          1401:        } else {
1.45.2.46  knu      1402:                print "Status: $errcode\r\n";
                   1403:        }
                   1404:        html_header("Error");
1.12      fenner   1405:        print "Error: $errmsg\n";
                   1406:        print &html_footer;
                   1407:        exit(1);
                   1408: }
                   1409:
1.45.2.47  knu      1410: sub redirect($) {
1.45.2.75! knu      1411:        my ($url) = @_;
1.45.2.46  knu      1412:        if ($is_mod_perl) {
                   1413:                Apache->request->status(301);
                   1414:                Apache->request->header_out(Location => $url);
1.45.2.75! knu      1415:        } else {
1.45.2.46  knu      1416:                print "Status: 301 Moved\r\n";
                   1417:                print "Location: $url\r\n";
                   1418:        }
                   1419:        html_header("Moved");
1.45.2.56  knu      1420:        print "This document is located ", &link('here', $url), "\n";
1.12      fenner   1421:        print &html_footer;
                   1422:        exit(1);
                   1423: }
                   1424:
1.45.2.47  knu      1425: sub safeglob($) {
1.45.2.46  knu      1426:        my ($filename) = @_;
                   1427:        my ($dirname);
                   1428:        my (@results);
1.45.2.75! knu      1429:        my $dh = do { local (*DH); };
1.12      fenner   1430:
                   1431:        ($dirname = $filename) =~ s|/[^/]+$||;
                   1432:        $filename =~ s|.*/||;
                   1433:
1.45.2.46  knu      1434:        if (opendir($dh, $dirname)) {
                   1435:                my $glob = $filename;
                   1436:                my $t;
1.45.2.75! knu      1437:
        !          1438:                #       transform filename from glob to regex.  Deal with:
        !          1439:                #       [, {, ?, * as glob chars
        !          1440:                #       make sure to escape all other regex chars
1.12      fenner   1441:                $glob =~ s/([\.\(\)\|\+])/\\$1/g;
                   1442:                $glob =~ s/\*/.*/g;
                   1443:                $glob =~ s/\?/./g;
                   1444:                $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1.45.2.46  knu      1445:                foreach (readdir($dh)) {
1.45.2.75! knu      1446:
1.12      fenner   1447:                        if (/^${glob}$/) {
1.45.2.75! knu      1448:                                push (@results, "$dirname/" . $_);
1.12      fenner   1449:                        }
                   1450:                }
1.45.2.75! knu      1451:                closedir($dh);
1.12      fenner   1452:        }
                   1453:
                   1454:        @results;
                   1455: }
                   1456:
1.45.2.67  knu      1457: sub search_path($) {
1.45.2.75! knu      1458:        my ($command) = @_;
        !          1459:        my $d;
1.45.2.67  knu      1460:
1.45.2.75! knu      1461:        for $d (split (/:/, $command_path)) {
        !          1462:                return "$d/$command" if -x "$d/$command";
        !          1463:        }
1.45.2.67  knu      1464:
1.45.2.75! knu      1465:        '';
1.45.2.67  knu      1466: }
                   1467:
1.45.2.47  knu      1468: sub getMimeTypeFromSuffix($) {
1.45.2.75! knu      1469:        my ($fullname) = @_;
        !          1470:        my ($mimetype, $suffix);
        !          1471:        my $fh = do { local (*FH); };
        !          1472:
        !          1473:        ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
        !          1474:        $mimetype = $MTYPES{$suffix};
        !          1475:        $mimetype = $MTYPES{'*'} if (!$mimetype);
        !          1476:
        !          1477:        if (!$mimetype && -f $mime_types) {
        !          1478:
        !          1479:                # okey, this is something special - search the
        !          1480:                # mime.types database
        !          1481:                open($fh, "<$mime_types");
        !          1482:                while (<$fh>) {
        !          1483:                        if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
        !          1484:                                $mimetype = $1;
        !          1485:                                last;
        !          1486:                        }
        !          1487:                }
        !          1488:                close($fh);
1.45.2.46  knu      1489:        }
1.45.2.47  knu      1490:
1.45.2.75! knu      1491:        # okey, didn't find anything useful ..
        !          1492:        if (!($mimetype =~ /\S\/\S/)) {
        !          1493:                $mimetype = "text/plain";
        !          1494:        }
        !          1495:        return $mimetype;
1.45.2.46  knu      1496: }
1.12      fenner   1497:
1.45.2.46  knu      1498: ###############################
1.45.2.51  knu      1499: # read first lines like head(1)
                   1500: ###############################
                   1501: sub head($;$) {
1.45.2.75! knu      1502:        my $fh        = $_[0];
        !          1503:        my $linecount = $_[1] || 10;
1.45.2.51  knu      1504:
1.45.2.75! knu      1505:        my @buf;
1.45.2.51  knu      1506:
1.45.2.75! knu      1507:        if ($linecount > 0) {
        !          1508:                my $i;
        !          1509:                for ($i = 0 ; !eof($fh) && $i < $linecount ; $i++) {
        !          1510:                        push @buf, scalar <$fh>;
        !          1511:                }
        !          1512:        } else {
        !          1513:                @buf = <$fh>;
1.45.2.51  knu      1514:        }
                   1515:
1.45.2.75! knu      1516:        @buf;
1.45.2.51  knu      1517: }
                   1518:
                   1519: ###############################
                   1520: # scan vim and Emacs directives
                   1521: ###############################
                   1522: sub scan_directives(@) {
1.45.2.75! knu      1523:        my $ts = undef;
1.45.2.51  knu      1524:
1.45.2.75! knu      1525:        for (@_) {
        !          1526:                $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
        !          1527:        }
1.45.2.51  knu      1528:
1.45.2.75! knu      1529:        ('tabstop' => $ts);
1.45.2.51  knu      1530: }
                   1531:
                   1532: ###############################
1.45.2.46  knu      1533: # show Annotation
                   1534: ###############################
1.45.2.47  knu      1535: sub doAnnotate($$) {
1.45.2.75! knu      1536:        my ($rev) = @_;
        !          1537:        my ($pid);
        !          1538:        my ($pathname, $filename);
        !          1539:        my $reader = do { local (*FH); };
        !          1540:        my $writer = do { local (*FH); };
        !          1541:
        !          1542:        # make sure the revisions are wellformed, for security
        !          1543:        # reasons ..
        !          1544:        if ($rev =~ /[^\w.]/) {
        !          1545:                &fatal("404 Not Found",
        !          1546:                        "Malformed query \"$ENV{QUERY_STRING}\"");
        !          1547:        }
        !          1548:
        !          1549:        if (&forbidden_file($fullname)) {
        !          1550:                &fatal("403 Forbidden",
        !          1551:                        "Access forbidden.  This file is mentioned in \@ForbiddenFiles"
        !          1552:                );
        !          1553:                return;
        !          1554:        }
        !          1555:
        !          1556:        ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
        !          1557:        ($filename = $where) =~ s/^.*\///;
        !          1558:
        !          1559:        # this seems to be necessary
        !          1560:        $| = 1;
        !          1561:        $| = 0;    # Flush
        !          1562:
        !          1563:        # this annotate version is based on the
        !          1564:        # cvs annotate-demo Perl script by Cyclic Software
        !          1565:        # It was written by Cyclic Software, http://www.cyclic.com/, and is in
        !          1566:        # the public domain.
        !          1567:        # we could abandon the use of rlog, rcsdiff and co using
        !          1568:        # the cvsserver in a similiar way one day (..after rewrite)
        !          1569:        $pid = open2($reader, $writer, $CMD{cvs}, @cvs_options, "server")
        !          1570:            || fatal("500 Internal Error",
        !          1571:                "Fatal Error - unable to open cvs for annotation");
        !          1572:
        !          1573:        # OK, first send the request to the server.  A simplified example is:
        !          1574:        #     Root /home/kingdon/zwork/cvsroot
        !          1575:        #     Argument foo/xx
        !          1576:        #     Directory foo
        !          1577:        #     /home/kingdon/zwork/cvsroot/foo
        !          1578:        #     Directory .
        !          1579:        #     /home/kingdon/zwork/cvsroot
        !          1580:        #     annotate
        !          1581:        # although as you can see there are a few more details.
        !          1582:
        !          1583:        print $writer "Root $cvsroot\n";
        !          1584:        print $writer
        !          1585:            "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
        !          1586:
        !          1587:        # Don't worry about sending valid-requests, the server just needs to
        !          1588:        # support "annotate" and if it doesn't, there isn't anything to be done.
        !          1589:        print $writer "UseUnchanged\n";
        !          1590:        print $writer "Argument -r\n";
        !          1591:        print $writer "Argument $rev\n";
        !          1592:        print $writer "Argument $where\n";
        !          1593:
        !          1594:        # The protocol requires us to fully fake a working directory (at
        !          1595:        # least to the point of including the directories down to the one
        !          1596:        # containing the file in question).
        !          1597:        # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
        !          1598:        my @dirs = split ('/', $where);
        !          1599:        my $path = "";
        !          1600:        foreach (@dirs) {
1.45.2.47  knu      1601:
1.45.2.75! knu      1602:                if ($path eq "") {
        !          1603:
        !          1604:                        # In our example, $_ is "dir".
        !          1605:                        $path = $_;
        !          1606:                } else {
        !          1607:                        print $writer "Directory $path\n";
        !          1608:                        print $writer "$cvsroot/$path\n";
        !          1609:
        !          1610:                        # In our example, $_ is "sdir" and $path becomes "dir/sdir"
        !          1611:                        # And the next time, "file" and "dir/sdir/file" (which then gets
        !          1612:                        # ignored, because we don't need to send Directory for the file).
        !          1613:                        $path .= "/$_";
        !          1614:                }
1.45.2.46  knu      1615:        }
1.45.2.75! knu      1616:
        !          1617:        # And the last "Directory" before "annotate" is the top level.
        !          1618:        print $writer "Directory .\n";
        !          1619:        print $writer "$cvsroot\n";
        !          1620:
        !          1621:        print $writer "annotate\n";
        !          1622:
        !          1623:        # OK, we've sent our command to the server.  Thing to do is to
        !          1624:        # close the writer side and get all the responses.  If "cvs server"
        !          1625:        # were nicer about buffering, then we could just leave it open, I think.
        !          1626:        close($writer) || die "cannot close: $!";
        !          1627:
        !          1628:        http_header();
        !          1629:
        !          1630:        navigateHeader($scriptwhere, $pathname, $filename, $rev, "annotate");
        !          1631:        print
        !          1632:            "<h3 align=center>Annotation of $pathname$filename, Revision $rev</h3>\n";
        !          1633:
        !          1634:        # Ready to get the responses from the server.
        !          1635:        # For example:
        !          1636:        #     E Annotations for foo/xx
        !          1637:        #     E ***************
        !          1638:        #     M 1.3          (kingdon  06-Sep-97): hello
        !          1639:        #     ok
        !          1640:        my ($lineNr) = 0;
        !          1641:        my ($oldLrev, $oldLusr) = ("", "");
        !          1642:        my ($revprint, $usrprint);
        !          1643:
        !          1644:        if ($annTable) {
        !          1645:                print "<table border=0 cellspacing=0 cellpadding=0>\n";
        !          1646:        } else {
        !          1647:                print "<pre>";
1.45.2.46  knu      1648:        }
1.45.2.75! knu      1649:
        !          1650:        # prefetch several lines
        !          1651:        my @buf = head($reader);
        !          1652:
        !          1653:        my %d = scan_directives(@buf);
        !          1654:
        !          1655:        while (@buf || !eof($reader)) {
        !          1656:                $_ = @buf ? shift @buf : <$reader>;
        !          1657:
        !          1658:                my @words = split;
        !          1659:
        !          1660:                # Adding one is for the (single) space which follows $words[0].
        !          1661:                my $rest = substr($_, length($words[0]) + 1);
        !          1662:                if ($words[0] eq "E") {
        !          1663:                        next;
        !          1664:                } elsif ($words[0] eq "M") {
        !          1665:                        $lineNr++;
        !          1666:                        (my $lrev = substr($_, 2,  13)) =~ y/ //d;
        !          1667:                        (my $lusr = substr($_, 16, 9))  =~ y/ //d;
        !          1668:                        my $line = substr($_, 36);
        !          1669:                        my $isCurrentRev = ($rev eq $lrev);
        !          1670:
        !          1671:                        # we should parse the date here ..
        !          1672:                        if ($lrev eq $oldLrev) {
        !          1673:                                $revprint = sprintf('%-8s', '');
        !          1674:                        } else {
        !          1675:                                $revprint = sprintf('%-8s', $lrev);
        !          1676:                                $revprint =~
        !          1677:                                    s`\S+`&link($&, "$scriptwhere$query#rev$&")`e
        !          1678:                                    ;    # `
        !          1679:                                $oldLusr = '';
        !          1680:                        }
        !          1681:
        !          1682:                        if ($lusr eq $oldLusr) {
        !          1683:                                $usrprint = '';
        !          1684:                        } else {
        !          1685:                                $usrprint = $lusr;
        !          1686:                        }
        !          1687:                        $oldLrev = $lrev;
        !          1688:                        $oldLusr = $lusr;
        !          1689:
        !          1690:                        # Set bold for text-based browsers only - graphical
        !          1691:                        # browsers show bold fonts a bit wider than regular fonts,
        !          1692:                        # so it looks irregular.
        !          1693:                        print "<b>" if ($isCurrentRev && $is_textbased);
        !          1694:
        !          1695:                        printf "%s%s %-8s %4d:", $revprint,
        !          1696:                            $isCurrentRev ? '!' : ' ', $usrprint, $lineNr;
        !          1697:                        print spacedHtmlText($line, $d{'tabstop'});
        !          1698:
        !          1699:                        print "</b>" if ($isCurrentRev && $is_textbased);
        !          1700:                } elsif ($words[0] eq "ok") {
        !          1701:
        !          1702:                        # We could complain about any text received after this, like the
        !          1703:                        # CVS command line client.  But for simplicity, we don't.
        !          1704:                } elsif ($words[0] eq "error") {
        !          1705:                        fatal("500 Internal Error",
        !          1706:                                "Error occured during annotate: <b>$_</b>");
        !          1707:                }
        !          1708:        }
        !          1709:
        !          1710:        if ($annTable) {
        !          1711:                print "</table>";
        !          1712:        } else {
        !          1713:                print "</pre>";
        !          1714:        }
        !          1715:        close($reader) || warn "cannot close: $!";
        !          1716:        wait;
1.45.2.46  knu      1717: }
                   1718:
                   1719: ###############################
                   1720: # make Checkout
                   1721: ###############################
1.45.2.47  knu      1722: sub doCheckout($$) {
1.45.2.75! knu      1723:        my ($fullname, $rev) = @_;
        !          1724:        my ($mimetype, $revopt);
        !          1725:        my $fh = do { local (*FH); };
        !          1726:
        !          1727:        if ($rev eq 'HEAD' || $rev eq '.') {
        !          1728:                $rev = undef;
        !          1729:        }
        !          1730:
        !          1731:        # make sure the revisions a wellformed, for security
        !          1732:        # reasons ..
        !          1733:        if (defined($rev) && $rev =~ /[^\w.]/) {
        !          1734:                &fatal("404 Not Found",
        !          1735:                        "Malformed query \"$ENV{QUERY_STRING}\"");
        !          1736:        }
        !          1737:
        !          1738:        if (&forbidden_file($fullname)) {
        !          1739:                &fatal("403 Forbidden",
        !          1740:                        "Access forbidden. This file is mentioned in \@ForbiddenFiles"
        !          1741:                );
        !          1742:                return;
        !          1743:        }
        !          1744:
        !          1745:        # get mimetype
        !          1746:        if (defined($input{"content-type"})
        !          1747:            && ($input{"content-type"} =~ /\S\/\S/))
        !          1748:        {
        !          1749:                $mimetype = $input{"content-type"}
        !          1750:        } else {
        !          1751:                $mimetype = &getMimeTypeFromSuffix($fullname);
        !          1752:        }
        !          1753:
        !          1754:        if (defined($rev)) {
        !          1755:                $revopt = "-r$rev";
        !          1756:                if ($use_moddate) {
        !          1757:                        readLog($fullname, $rev);
        !          1758:                        $moddate = $date{$rev};
        !          1759:                }
        !          1760:        } else {
        !          1761:                $revopt = "-rHEAD";
        !          1762:
        !          1763:                if ($use_moddate) {
        !          1764:                        readLog($fullname);
        !          1765:                        $moddate = $date{$symrev{HEAD}};
        !          1766:                }
        !          1767:        }
        !          1768:
        !          1769:        ### just for the record:
        !          1770:        ### 'cvs co' seems to have a bug regarding single checkout of
        !          1771:        ### directories/files having spaces in it;
        !          1772:        ### this is an issue that should be resolved on cvs's side
        !          1773:        #
        !          1774:        # Safely for a child process to read from.
        !          1775:        if (!open($fh, "-|")) {    # child
        !          1776:                 # chdir to $tmpdir before to avoid non-readable cgi-bin directories
        !          1777:                chdir($tmpdir);
        !          1778:                open(STDERR, ">&STDOUT");    # Redirect stderr to stdout
        !          1779:                exec($CMD{cvs}, @cvs_options, '-d', $cvsroot, 'co', '-p',
        !          1780:                    $revopt, $where);
        !          1781:        }
        !          1782:
        !          1783:        if (eof($fh)) {
        !          1784:                &fatal("404 Not Found", "$where is not (any longer) pertinent");
        !          1785:        }
        !          1786:
        !          1787:        #===================================================================
        !          1788:        #Checking out squid/src/ftp.c
        !          1789:        #RCS:  /usr/src/CVS/squid/src/ftp.c,v
        !          1790:        #VERS: 1.1.1.28.6.2
        !          1791:        #***************
        !          1792:
        !          1793:        # Parse CVS header
        !          1794:        my ($revision, $filename, $cvsheader);
        !          1795:        $filename = "";
        !          1796:        while (<$fh>) {
        !          1797:                last if (/^\*\*\*\*/);
        !          1798:                $revision = $1 if (/^VERS: (.*)$/);
        !          1799:
        !          1800:                if (/^Checking out (.*)$/) {
        !          1801:                        $filename = $1;
        !          1802:                        $filename =~ s/^\.\/*//;
        !          1803:                }
        !          1804:                $cvsheader .= $_;
        !          1805:        }
        !          1806:
        !          1807:        if ($filename ne $where) {
        !          1808:                &fatal("500 Internal Error",
        !          1809:                        "Unexpected output from cvs co: $cvsheader");
        !          1810:        }
        !          1811:        $| = 1;
        !          1812:
        !          1813:        if ($mimetype eq "text/x-cvsweb-markup") {
        !          1814:                &cvswebMarkup($fh, $fullname, $revision);
        !          1815:        } else {
        !          1816:                http_header($mimetype);
        !          1817:                print <$fh>;
        !          1818:        }
        !          1819:        close($fh);
1.45.2.46  knu      1820: }
                   1821:
1.45.2.47  knu      1822: sub cvswebMarkup($$$) {
1.45.2.75! knu      1823:        my ($filehandle, $fullname, $revision) = @_;
        !          1824:        my ($pathname,   $filename);
1.45.2.46  knu      1825:
1.45.2.75! knu      1826:        ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
        !          1827:        ($filename = $where) =~ s/^.*\///;
        !          1828:        my ($fileurl) = urlencode($filename);
        !          1829:
        !          1830:        http_header();
        !          1831:
        !          1832:        navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
        !          1833:        print "<HR noshade>";
        !          1834:        print "<table width=\"100%\"><tr><td bgcolor=\"$markupLogColor\">";
        !          1835:        print "File: ", &clickablePath($where, 1);
1.45.2.56  knu      1836:        print "&nbsp;(";
1.45.2.75! knu      1837:        &download_link($fileurl, $revision, "download");
1.45.2.56  knu      1838:        print ")";
1.45.2.51  knu      1839:
1.45.2.75! knu      1840:        if (!$defaultTextPlain) {
        !          1841:                print "&nbsp;(";
        !          1842:                &download_link($fileurl, $revision, "as text", "text/plain");
        !          1843:                print ")";
        !          1844:        }
        !          1845:        print "<BR>\n";
1.45.2.51  knu      1846:
1.45.2.75! knu      1847:        if ($show_log_in_markup) {
        !          1848:                readLog($fullname);    #,$revision);
        !          1849:                printLog($revision, 0);
        !          1850:        } else {
        !          1851:                print "Version: <B>$revision</B><BR>\n";
        !          1852:                print "Tag: <B>", $input{only_with_tag}, "</b><br>\n"
        !          1853:                    if $input{only_with_tag};
        !          1854:        }
        !          1855:        print "</td></tr></table>";
        !          1856:        my $url = download_url($fileurl, $revision, $mimetype);
        !          1857:        print "<HR noshade>";
1.45.2.51  knu      1858:
1.45.2.75! knu      1859:        if ($mimetype =~ /^image/) {
        !          1860:                printf '<IMG SRC="%s"><BR>', hrefquote("$url$barequery");
        !          1861:        } elsif ($mimetype =~ m%^application/pdf%) {
        !          1862:                printf '<EMBED SRC="%s" WIDTH="100%"><BR>',
        !          1863:                    hrefquote("$url$barequery");
        !          1864:        } elsif ($preformat_in_markup) {
        !          1865:                print "<PRE>";
1.45.2.51  knu      1866:
1.45.2.75! knu      1867:                # prefetch several lines
        !          1868:                my @buf = head($filehandle);
        !          1869:
        !          1870:                my %d = scan_directives(@buf);
        !          1871:
        !          1872:                while (@buf || !eof($filehandle)) {
        !          1873:                        $_ = @buf ? shift @buf : <$filehandle>;
        !          1874:
        !          1875:                        print spacedHtmlText($_, $d{'tabstop'});
        !          1876:                }
        !          1877:                print "</PRE>";
        !          1878:        } else {
        !          1879:                print "<PRE>";
        !          1880:
        !          1881:                while (<$filehandle>) {
        !          1882:                        print htmlquote($_);
        !          1883:                }
        !          1884:                print "</PRE>";
1.45.2.70  knu      1885:        }
1.12      fenner   1886: }
                   1887:
1.45.2.46  knu      1888: sub viewable($) {
1.45.2.75! knu      1889:        my ($mimetype) = @_;
1.45.2.46  knu      1890:
1.45.2.75! knu      1891:        $mimetype =~ m%^((text|image)/|application/pdf)%;
1.45.2.46  knu      1892: }
                   1893:
                   1894: ###############################
                   1895: # Show Colored Diff
                   1896: ###############################
1.45.2.47  knu      1897: sub doDiff($$$$$$) {
1.45.2.75! knu      1898:        my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
        !          1899:        my $fh = do { local (*FH); };
1.45.2.56  knu      1900:        my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1.12      fenner   1901:
1.45.2.75! knu      1902:        if (&forbidden_file($fullname)) {
        !          1903:                &fatal("403 Forbidden",
        !          1904:                        "Access forbidden. This file is mentioned in \@ForbiddenFiles"
        !          1905:                );
        !          1906:                return;
        !          1907:        }
        !          1908:
1.12      fenner   1909:        if ($r1 =~ /([^:]+)(:(.+))?/) {
1.45.2.75! knu      1910:                $rev1 = $1;
        !          1911:                $sym1 = $3;
1.12      fenner   1912:        }
1.45.2.46  knu      1913:        if ($r1 eq 'text') {
1.45.2.75! knu      1914:                $rev1 = $tr1;
        !          1915:                $sym1 = "";
1.12      fenner   1916:        }
1.45.2.75! knu      1917:
1.12      fenner   1918:        if ($r2 =~ /([^:]+)(:(.+))?/) {
1.45.2.75! knu      1919:                $rev2 = $1;
        !          1920:                $sym2 = $3;
1.12      fenner   1921:        }
1.45.2.46  knu      1922:        if ($r2 eq 'text') {
1.45.2.75! knu      1923:                $rev2 = $tr2;
        !          1924:                $sym2 = "";
1.12      fenner   1925:        }
1.45.2.48  knu      1926:
1.45.2.46  knu      1927:        # make sure the revisions a wellformed, for security
                   1928:        # reasons ..
1.45.2.48  knu      1929:        if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1.45.2.75! knu      1930:                &fatal("404 Not Found",
        !          1931:                        "Malformed query \"$ENV{QUERY_STRING}\"");
1.12      fenner   1932:        }
1.45.2.75! knu      1933:
        !          1934:        #
        !          1935:        # rev1 and rev2 are now both numeric revisions.
        !          1936:        # Thus we do a DWIM here and swap them if rev1 is after rev2.
        !          1937:        # XXX should we warn about the fact that we do this?
        !          1938:        if (&revcmp($rev1, $rev2) > 0) {
        !          1939:                my ($tmp1, $tmp2) = ($rev1, $sym1);
        !          1940:                ($rev1, $sym1) = ($rev2, $sym2);
        !          1941:                ($rev2, $sym2) = ($tmp1, $tmp2);
1.12      fenner   1942:        }
1.45.2.56  knu      1943:        my $difftype = $DIFFTYPES{$f};
                   1944:
                   1945:        if (!$difftype) {
1.45.2.75! knu      1946:                fatal("400 Bad arguments", "Diff format $f not understood");
1.45.2.46  knu      1947:        }
                   1948:
1.45.2.56  knu      1949:        my @difftype       = @{$difftype->{'opts'}};
                   1950:        my $human_readable = $difftype->{'colored'};
                   1951:
1.45.2.46  knu      1952:        # apply special options
                   1953:        if ($showfunc) {
1.45.2.75! knu      1954:                push @difftype, '-p' if $f ne 's';
1.45.2.46  knu      1955:
1.45.2.75! knu      1956:                my ($re1, $re2);
1.45.2.46  knu      1957:
1.45.2.75! knu      1958:                while (($re1, $re2) = each %funcline_regexp) {
        !          1959:                        if ($fullname =~ /$re1/) {
        !          1960:                                push @difftype, '-F', $re2;
        !          1961:                                last;
        !          1962:                        }
1.45.2.46  knu      1963:                }
                   1964:        }
1.45.2.75! knu      1965:
1.45.2.46  knu      1966:        if ($human_readable) {
1.45.2.75! knu      1967:                if ($hr_ignwhite) {
        !          1968:                        push @difftype, '-w';
        !          1969:                }
        !          1970:                if ($hr_ignkeysubst) {
        !          1971:                        push @difftype, '-kk';
        !          1972:                }
1.45.2.46  knu      1973:        }
1.45.2.75! knu      1974:
        !          1975:        if (!open($fh, "-|")) {    # child
        !          1976:                open(STDERR, ">&STDOUT");    # Redirect stderr to stdout
        !          1977:                exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname);
1.45.2.46  knu      1978:        }
                   1979:        if ($human_readable) {
1.45.2.75! knu      1980:                http_header();
        !          1981:                &human_readable_diff($fh, $rev2);
        !          1982:                gzipclose();
        !          1983:                exit;
        !          1984:        } else {
        !          1985:                http_header("text/plain");
1.45.2.46  knu      1986:        }
1.45.2.75! knu      1987:
        !          1988:        #
        !          1989:        #===================================================================
        !          1990:        #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
        !          1991:        #retrieving revision 1.16
        !          1992:        #retrieving revision 1.17
        !          1993:        #diff -c -r1.16 -r1.17
        !          1994:        #*** /home/ncvs/src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
        !          1995:        #--- /home/ncvs/src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17
        !          1996:        #
        !          1997:        # Ideas:
        !          1998:        # - nuke the stderr output if it's what we expect it to be
        !          1999:        # - Add "no differences found" if the diff command supplied no output.
        !          2000:        #
        !          2001:        #*** src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
        !          2002:        #--- src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17 RELENG_2_1_0
        !          2003:        # (bogus example, but...)
        !          2004:        #
        !          2005:        if (grep { $_ eq '-u' } @difftype) {
        !          2006:                $f1 = '---';
        !          2007:                $f2 = '\+\+\+';
        !          2008:        } else {
        !          2009:                $f1 = '\*\*\*';
        !          2010:                $f2 = '---';
1.12      fenner   2011:        }
1.45.2.75! knu      2012:
1.45.2.46  knu      2013:        while (<$fh>) {
1.45.2.75! knu      2014:                if (m|^$f1 $cvsroot|o) {
        !          2015:                        s|$cvsroot/||o;
        !          2016:                        if ($sym1) {
        !          2017:                                chop;
        !          2018:                                $_ .= " $sym1\n";
        !          2019:                        }
        !          2020:                } elsif (m|^$f2 $cvsroot|o) {
        !          2021:                        s|$cvsroot/||o;
        !          2022:
        !          2023:                        if ($sym2) {
        !          2024:                                chop;
        !          2025:                                $_ .= " $sym2\n";
        !          2026:                        }
1.12      fenner   2027:                }
1.45.2.75! knu      2028:                print $_;
1.12      fenner   2029:        }
1.45.2.46  knu      2030:        close($fh);
1.12      fenner   2031: }
                   2032:
1.45.2.46  knu      2033: ###############################
                   2034: # Show Logs ..
                   2035: ###############################
1.45.2.47  knu      2036: sub getDirLogs($$@) {
1.45.2.75! knu      2037:        my ($cvsroot, $dirname, @otherFiles) = @_;
        !          2038:        my ($state, $otherFiles, $tag, $file, $date, $branchpoint, $branch,
        !          2039:            $log);
        !          2040:        my ($rev, $revision, $revwanted, $filename, $head, $author);
        !          2041:
        !          2042:        $tag = $input{only_with_tag};
        !          2043:
        !          2044:        my ($DirName) = "$cvsroot/$where";
        !          2045:        my (@files, @filetags);
        !          2046:        my $fh = do { local (*FH); };
        !          2047:
        !          2048:        push (@files, &safeglob("$DirName/*,v"));
        !          2049:        push (@files, &safeglob("$DirName/Attic/*,v"))
        !          2050:            if (!$input{'hideattic'});
        !          2051:        foreach $file (@otherFiles) {
        !          2052:                push (@files, "$DirName/$file");
1.45.2.46  knu      2053:        }
1.45.2.75! knu      2054:
        !          2055:        # just execute rlog if there are any files
        !          2056:        if ($#files < 0) {
        !          2057:                return;
        !          2058:        }
        !          2059:
        !          2060:        if (defined($tag)) {
        !          2061:
        !          2062:                #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
        !          2063:                if (!open($fh, "-|")) {
        !          2064:                        open(STDERR, '>/dev/null'); # rlog may complain; ignore.
        !          2065:                        exec($CMD{rlog}, @files);
        !          2066:                }
        !          2067:        } else {
        !          2068:
        !          2069:                if (!open($fh, "-|")) {
        !          2070:                        open(STDERR, '>/dev/null'); # rlog may complain; ignore.
        !          2071:                        exec($CMD{rlog}, '-r', @files);
        !          2072:                }
        !          2073:        }
        !          2074:        $state = "start";
        !          2075:
        !          2076:        while (<$fh>) {
        !          2077:                if ($state eq "start") {
        !          2078:
        !          2079:                        #Next file. Initialize file variables
        !          2080:                        $rev         = '';
        !          2081:                        $revwanted   = '';
        !          2082:                        $branch      = '';
        !          2083:                        $branchpoint = '';
        !          2084:                        $filename    = '';
        !          2085:                        $log         = '';
        !          2086:                        $revision    = '';
        !          2087:                        %symrev      = ();
        !          2088:                        @filetags    = ();
        !          2089:
        !          2090:                        #jump to head state
        !          2091:                        $state = "head";
        !          2092:                }
        !          2093:                print "$state:$_" if ($verbose);
        !          2094:                again:
        !          2095:
        !          2096:                if ($state eq "head") {
        !          2097:
        !          2098:                        #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
        !          2099:
        !          2100:                        if (/^Working file: (.+)$/) {
        !          2101:                                $filename = $1;
        !          2102:                        } elsif (/^head: (.+)$/) {
        !          2103:                                $head = $1;
        !          2104:                        } elsif (/^branch: (.+)$/) {
        !          2105:                                $branch = $1
        !          2106:                        } elsif (/^symbolic names:/) {
        !          2107:                                $state = "tags";
        !          2108:                                ($branch = $head) =~ s/\.\d+$//
        !          2109:                                    if $branch eq '';
        !          2110:                                $branch =~ s/(\d+)$/0.$1/;
        !          2111:                                $symrev{MAIN}  = $branch;
        !          2112:                                $symrev{HEAD}  = $branch;
        !          2113:                                $alltags{MAIN} = 1;
        !          2114:                                $alltags{HEAD} = 1;
        !          2115:                                push (@filetags, "MAIN", "HEAD");
        !          2116:                        } elsif (/$LOG_REVSEPARATOR/o) {
        !          2117:                                $state = "log";
        !          2118:                                $rev   = '';
        !          2119:                                $date  = '';
        !          2120:                                $log   = '';
        !          2121:
        !          2122:                                # Try to reconstruct the relative filename if RCS spits out a full path
        !          2123:                                $filename =~ s%^\Q$DirName\E/%%;
        !          2124:                        }
1.45.2.58  knu      2125:                        next;
                   2126:                }
1.45.2.75! knu      2127:
        !          2128:                if ($state eq "tags") {
        !          2129:                        if (/^\s+(.+):\s+([\d\.]+)\s+$/) {
        !          2130:                                push (@filetags, $1);
        !          2131:                                $symrev{$1}  = $2;
        !          2132:                                $alltags{$1} = 1;
        !          2133:                                next;
        !          2134:                        } elsif (/^\S/) {
        !          2135:
        !          2136:                                if (defined($tag)) {
        !          2137:                                        if (defined($symrev{$tag})
        !          2138:                                            || $tag eq "HEAD")
        !          2139:                                        {
        !          2140:                                                $revwanted =
        !          2141:                                                    $symrev{$tag eq "HEAD" ?
        !          2142:                                                    "MAIN" : $tag};
        !          2143:                                                ($branch = $revwanted) =~
        !          2144:                                                    s/\b0\.//;
        !          2145:                                                ($branchpoint = $branch) =~
        !          2146:                                                    s/\.?\d+$//;
        !          2147:                                                $revwanted = ''
        !          2148:                                                    if ($revwanted ne $branch);
        !          2149:                                        } elsif ($tag ne "HEAD") {
        !          2150:                                                print
        !          2151:                                                    "Tag not found, skip this file"
        !          2152:                                                    if ($verbose);
        !          2153:                                                $state = "skip";
        !          2154:                                                next;
        !          2155:                                        }
        !          2156:                                }
        !          2157:
        !          2158:                                foreach my $tagfound (@filetags) {
        !          2159:                                        $tags{$tagfound} = 1;
        !          2160:                                }
        !          2161:                                $state = "head";
        !          2162:                                goto again;
        !          2163:                        }
        !          2164:                }
        !          2165:
        !          2166:                if ($state eq "log") {
        !          2167:                        if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
        !          2168:
        !          2169:                                # End of a log entry.
        !          2170:                                my $revbranch = $rev;
        !          2171:                                $revbranch =~ s/\.\d+$//;
        !          2172:                                print "$filename $rev Wanted: $revwanted ",
        !          2173:                                    "Revbranch: $revbranch Branch: $branch ",
        !          2174:                                    "Branchpoint: $branchpoint\n"
        !          2175:                                    if ($verbose);
        !          2176:
        !          2177:                                if ($revwanted eq '' && $branch ne ''
        !          2178:                                    && $branch eq $revbranch || !defined($tag))
        !          2179:                                {
        !          2180:                                        print
        !          2181:                                            "File revision $rev found for branch $branch\n"
        !          2182:                                            if ($verbose);
        !          2183:                                        $revwanted = $rev;
        !          2184:                                }
        !          2185:
        !          2186:                                if ($revwanted ne '' ? $rev eq $revwanted :
        !          2187:                                    $branchpoint ne '' ? $rev eq $branchpoint :
        !          2188:                                    0 && ($rev eq $head))
        !          2189:                                {    # Don't think head is needed here..
        !          2190:                                        print
        !          2191:                                            "File info $rev found for $filename\n"
        !          2192:                                            if ($verbose);
        !          2193:                                        my @finfo =
        !          2194:                                            ($rev, $date, $log, $author,
        !          2195:                                                $filename);
        !          2196:                                        my ($name);
        !          2197:                                        ($name = $filename) =~ s%/.*%%;
        !          2198:                                        $fileinfo{$name} = [@finfo];
        !          2199:                                        $state = "done" if ($rev eq $revwanted);
        !          2200:                                }
        !          2201:                                $rev  = '';
        !          2202:                                $date = '';
        !          2203:                                $log  = '';
        !          2204:                        } elsif ($date eq ''
        !          2205:                            && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|
        !          2206:                            )
        !          2207:                        {
        !          2208:                                my $yr = $1;
        !          2209:
        !          2210:                                # damn 2-digit year routines :-)
        !          2211:                                if ($yr > 100) {
        !          2212:                                        $yr -= 1900;
        !          2213:                                }
        !          2214:                                $date =
        !          2215:                                    &Time::Local::timegm($6, $5, $4, $3, $2 - 1,
        !          2216:                                        $yr);
        !          2217:                                ($author) = /author: ([^;]+)/;
        !          2218:                                $state = "log";
        !          2219:                                $log   = '';
        !          2220:                                next;
        !          2221:                        } elsif ($rev eq '' && /^revision (.*)$/) {
        !          2222:                                $rev = $1;
        !          2223:                                next;
        !          2224:                        } else {
        !          2225:                                $log .= $_;
        !          2226:                        }
        !          2227:                }
        !          2228:
        !          2229:                if (/$LOG_FILESEPARATOR/o) {
        !          2230:                        $state = "start";
        !          2231:                        next;
1.45.2.58  knu      2232:                }
1.45.2.46  knu      2233:        }
1.45.2.75! knu      2234:
        !          2235:        if ($. == 0) {
        !          2236:                fatal("500 Internal Error", "Failed to spawn GNU rlog on <em>'"
        !          2237:                        . join (", ", @files)
        !          2238:                        . "'</em><p>Did you set the <b>\$command_path</b> in your configuration file correctly ? (Currently '$command_path'"
        !          2239:                );
1.45.2.46  knu      2240:        }
1.45.2.75! knu      2241:        close($fh);
1.45.2.46  knu      2242: }
                   2243:
1.45.2.47  knu      2244: sub readLog($;$) {
1.45.2.75! knu      2245:        my ($fullname, $revision) = @_;
1.45.2.46  knu      2246:        my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
1.45.2.75! knu      2247:        my $fh = do { local (*FH); };
1.45.2.46  knu      2248:
                   2249:        if (defined($revision)) {
1.45.2.75! knu      2250:                $revision = "-r$revision";
        !          2251:        } else {
        !          2252:                $revision = "";
1.45.2.46  knu      2253:        }
                   2254:
                   2255:        undef %symrev;
                   2256:        undef %revsym;
                   2257:        undef @allrevisions;
                   2258:        undef %date;
                   2259:        undef %author;
                   2260:        undef %state;
                   2261:        undef %difflines;
                   2262:        undef %log;
1.12      fenner   2263:
                   2264:        print("Going to rlog '$fullname'\n") if ($verbose);
1.45.2.75! knu      2265:        if (!open($fh, "-|")) {    # child
        !          2266:                if ($revision ne '') {
        !          2267:                        exec($CMD{rlog}, $revision, $fullname);
        !          2268:                } else {
        !          2269:                        exec($CMD{rlog}, $fullname);
        !          2270:                }
1.44      knu      2271:        }
1.45.2.75! knu      2272:
1.45.2.46  knu      2273:        while (<$fh>) {
1.45.2.75! knu      2274:                print if ($verbose);
        !          2275:                if ($symnames) {
        !          2276:                        if (/^\s+([^:]+):\s+([\d\.]+)/) {
        !          2277:                                $symrev{$1} = $2;
        !          2278:                        } else {
        !          2279:                                $symnames = 0;
        !          2280:                        }
        !          2281:                } elsif (/^head:\s+([\d\.]+)/) {
        !          2282:                        $head = $1;
        !          2283:                } elsif (/^branch:\s+([\d\.]+)/) {
        !          2284:                        $curbranch = $1;
        !          2285:                } elsif (/^symbolic names/) {
        !          2286:                        $symnames = 1;
        !          2287:                } elsif (/^-----/) {
        !          2288:                        last;
1.1       jfieber  2289:                }
                   2290:        }
1.45.2.46  knu      2291:        ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7       fenner   2292:
1.45.2.75! knu      2293:        # each log entry is of the form:
        !          2294:        # ----------------------------
        !          2295:        # revision 3.7.1.1
        !          2296:        # date: 1995/11/29 22:15:52;  author: fenner;  state: Exp;  lines: +5 -3
        !          2297:        # log info
        !          2298:        # ----------------------------
1.1       jfieber  2299:        logentry:
1.45.2.75! knu      2300:
1.45.2.55  knu      2301:        while (!/$LOG_FILESEPARATOR/o) {
1.45.2.75! knu      2302:                $_ = <$fh>;
        !          2303:                last logentry if (!defined($_));    # EOF
        !          2304:                print "R:", $_ if ($verbose);
        !          2305:                if (/^revision ([\d\.]+)/) {
        !          2306:                        $rev = $1;
        !          2307:                        unshift (@allrevisions, $rev);
        !          2308:                } elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
        !          2309:                        next logentry;
        !          2310:                } else {
        !          2311:
        !          2312:                        # The rlog output is syntactically ambiguous.  We must
        !          2313:                        # have guessed wrong about where the end of the last log
        !          2314:                        # message was.
        !          2315:                        # Since this is likely to happen when people put rlog output
        !          2316:                        # in their commit messages, don't even bother keeping
        !          2317:                        # these lines since we don't know what revision they go with
        !          2318:                        # any more.
        !          2319:                        next logentry;
        !          2320:
        !          2321:                        #               &fatal("500 Internal Error","Error parsing RCS output: $_");
        !          2322:                }
        !          2323:                $_ = <$fh>;
        !          2324:                print "D:", $_ if ($verbose);
        !          2325:                if (
        !          2326:                    m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
        !          2327:                    )
        !          2328:                {
        !          2329:                        my $yr = $1;
        !          2330:
        !          2331:                        # damn 2-digit year routines :-)
        !          2332:                        if ($yr > 100) {
        !          2333:                                $yr -= 1900;
        !          2334:                        }
        !          2335:                        $date{$rev} =
        !          2336:                            &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
        !          2337:                        $author{$rev}    = $7;
        !          2338:                        $state{$rev}     = $8;
        !          2339:                        $difflines{$rev} = $10;
        !          2340:                } else {
        !          2341:                        &fatal("500 Internal Error",
        !          2342:                                "Error parsing RCS output: $_");
        !          2343:                }
        !          2344:                line:
        !          2345:
        !          2346:                while (<$fh>) {
        !          2347:                        print "L:", $_ if ($verbose);
        !          2348:                        next line if (/^branches:\s/);
        !          2349:                        last line
        !          2350:                            if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
        !          2351:                        $log{$rev} .= $_;
        !          2352:                }
        !          2353:                print "E:", $_ if ($verbose);
1.1       jfieber  2354:        }
1.45.2.46  knu      2355:        close($fh);
1.1       jfieber  2356:        print "Done reading RCS file\n" if ($verbose);
1.45.2.46  knu      2357:
1.45.2.75! knu      2358:        @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
        !          2359:        print "Done sorting revisions", join (" ", @revorder), "\n"
        !          2360:            if ($verbose);
        !          2361:
        !          2362:        #
        !          2363:        # HEAD is an artificial tag which is simply the highest tag number on the main
        !          2364:        # branch, unless there is a branch tag in the RCS file in which case it's the
        !          2365:        # highest revision on that branch.  Find it by looking through @revorder; it
        !          2366:        # is the first commit listed on the appropriate branch.
        !          2367:        # This is not neccesary the same revision as marked as head in the RCS file.
1.45.2.46  knu      2368:        my $headrev = $curbranch || "1";
1.45.2.59  knu      2369:        ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
1.45.2.75! knu      2370:
1.45.2.46  knu      2371:        foreach $rev (@revorder) {
1.45.2.75! knu      2372:                if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
        !          2373:                        $symrev{"HEAD"} = $rev;
        !          2374:                        last;
        !          2375:                }
1.1       jfieber  2376:        }
1.45.2.46  knu      2377:        ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
1.45.2.75! knu      2378:            if (!defined($symrev{"HEAD"}));
1.1       jfieber  2379:        print "Done finding HEAD\n" if ($verbose);
1.45.2.75! knu      2380:
        !          2381:        #
        !          2382:        # Now that we know all of the revision numbers, we can associate
        !          2383:        # absolute revision numbers with all of the symbolic names, and
        !          2384:        # pass them to the form so that the same association doesn't have
        !          2385:        # to be built then.
        !          2386:        #
1.45.2.46  knu      2387:        undef @branchnames;
                   2388:        undef %branchpoint;
                   2389:        undef $sel;
                   2390:
                   2391:        foreach (reverse sort keys %symrev) {
1.45.2.75! knu      2392:                $rev = $symrev{$_};
        !          2393:                if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
        !          2394:                        push (@branchnames, $_);
        !          2395:
        !          2396:                        #
        !          2397:                        # A revision number of A.B.0.D really translates into
        !          2398:                        # "the highest current revision on branch A.B.D".
        !          2399:                        #
        !          2400:                        # If there is no branch A.B.D, then it translates into
        !          2401:                        # the head A.B .
        !          2402:                        #
        !          2403:                        # This reasoning also applies to the main branch A.B,
        !          2404:                        # with the branch number 0.A, with the exception that
        !          2405:                        # it has no head to translate to if there is nothing on
        !          2406:                        # the branch, but I guess this can never happen?
        !          2407:                        #
        !          2408:                        # (the code below gracefully forgets about the branch
        !          2409:                        # if it should happen)
        !          2410:                        #
        !          2411:                        $head = defined($2) ? $2 : "";
        !          2412:                        $branch = $3;
        !          2413:                        $branchrev = $head . ($head ne "" ? "." : "") . $branch;
        !          2414:                        my $regex;
        !          2415:                        $regex = quotemeta $branchrev;
        !          2416:                        $rev   = $head;
        !          2417:
        !          2418:                        foreach my $r (@revorder) {
        !          2419:                                if ($r =~ /^${regex}\b/) {
        !          2420:                                        $rev = $branchrev;
        !          2421:                                        last;
        !          2422:                                }
        !          2423:                        }
        !          2424:                        next if ($rev eq "");
        !          2425:
        !          2426:                        if ($rev ne $head && $head ne "") {
        !          2427:                                $branchpoint{$head} .= ", "
        !          2428:                                    if ($branchpoint{$head});
        !          2429:                                $branchpoint{$head} .= $_;
        !          2430:                        }
1.8       fenner   2431:                }
1.45.2.75! knu      2432:                $revsym{$rev} .= ", " if ($revsym{$rev});
        !          2433:                $revsym{$rev} .= $_;
        !          2434:                $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
1.1       jfieber  2435:        }
                   2436:        print "Done associating revisions with branches\n" if ($verbose);
1.45.2.46  knu      2437:
                   2438:        my ($onlyonbranch, $onlybranchpoint);
                   2439:        if ($onlyonbranch = $input{'only_with_tag'}) {
1.45.2.75! knu      2440:                $onlyonbranch = $symrev{$onlyonbranch};
        !          2441:                if ($onlyonbranch =~ s/\b0\.//) {
        !          2442:                        ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
        !          2443:                } else {
        !          2444:                        $onlybranchpoint = $onlyonbranch;
        !          2445:                }
        !          2446:
        !          2447:                if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
        !          2448:                        fatal("404 Tag not found",
        !          2449:                                "Tag $input{'only_with_tag'} not defined");
        !          2450:                }
1.8       fenner   2451:        }
1.1       jfieber  2452:
1.45.2.46  knu      2453:        undef @revisions;
                   2454:
                   2455:        foreach (@allrevisions) {
1.45.2.75! knu      2456:                ($br  = $_)  =~ s/\.\d+$//;
        !          2457:                ($brp = $br) =~ s/\.\d+$//;
        !          2458:                next
        !          2459:                    if ($onlyonbranch && $br ne $onlyonbranch
        !          2460:                    && $_ ne $onlybranchpoint);
        !          2461:                unshift (@revisions, $_);
1.45.2.46  knu      2462:        }
                   2463:
                   2464:        if ($logsort eq "date") {
1.45.2.75! knu      2465:
        !          2466:                # Sort the revisions in commit order an secondary sort on revision
        !          2467:                # (secondary sort needed for imported sources, or the first main
        !          2468:                # revision gets before the same revision on the 1.1.1 branch)
        !          2469:                @revdisplayorder =
        !          2470:                    sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) }
        !          2471:                    @revisions;
        !          2472:        } elsif ($logsort eq "rev") {
        !          2473:
        !          2474:                # Sort the revisions in revision order, highest first
        !          2475:                @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
        !          2476:        } else {
        !          2477:
        !          2478:                # No sorting. Present in the same order as rlog / cvs log
        !          2479:                @revdisplayorder = @revisions;
1.45.2.46  knu      2480:        }
                   2481:
                   2482: }
                   2483:
1.45.2.56  knu      2484: sub printDiffLinks($$) {
1.45.2.75! knu      2485:        my ($text, $url) = @_;
        !          2486:        my @extra;
1.45.2.56  knu      2487:
1.45.2.75! knu      2488:        local $_;
        !          2489:        for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
        !          2490:                my $f = $_ eq $defaultDiffType ? '' : $_;
1.45.2.56  knu      2491:
1.45.2.75! knu      2492:                push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
        !          2493:        }
1.45.2.56  knu      2494:
1.45.2.75! knu      2495:        print &link($text, $url), ' (', join (', ', @extra), ')';
1.45.2.56  knu      2496: }
                   2497:
1.45.2.46  knu      2498: sub printLog($;$) {
                   2499:        my ($link, $br, $brp);
1.45.2.75! knu      2500:        ($_, $link) = @_;
        !          2501:        ($br  = $_)  =~ s/\.\d+$//;
1.45.2.46  knu      2502:        ($brp = $br) =~ s/\.?\d+$//;
                   2503:        my ($isDead, $prev);
                   2504:
                   2505:        $link = 1 if (!defined($link));
                   2506:        $isDead = ($state{$_} eq "dead");
                   2507:
                   2508:        if ($link && !$isDead) {
1.45.2.75! knu      2509:                my ($filename);
        !          2510:                ($filename = $where) =~ s/^.*\///;
        !          2511:                my ($fileurl) = urlencode($filename);
        !          2512:                print "<a NAME=\"rev$_\"></a>";
        !          2513:
        !          2514:                if (defined($revsym{$_})) {
        !          2515:                        foreach my $sym (split (", ", $revsym{$_})) {
        !          2516:                                print "<a NAME=\"$sym\"></a>";
        !          2517:                        }
1.4       fenner   2518:                }
1.45.2.75! knu      2519:
        !          2520:                if (defined($revsym{$br}) && $revsym{$br}
        !          2521:                    && !defined($nameprinted{$br}))
        !          2522:                {
        !          2523:                        foreach my $sym (split (", ", $revsym{$br})) {
        !          2524:                                print "<a NAME=\"$sym\"></a>";
        !          2525:                        }
        !          2526:                        $nameprinted{$br} = 1;
1.45.2.46  knu      2527:                }
1.45.2.75! knu      2528:                print "\n Revision ";
        !          2529:                &download_link($fileurl, $_, $_,
        !          2530:                        $defaultViewable ? "text/x-cvsweb-markup" : undef);
        !          2531:
        !          2532:                if ($defaultViewable) {
        !          2533:                        print " / (";
        !          2534:                        &download_link($fileurl, $_, "download", $mimetype);
        !          2535:                        print ")";
        !          2536:                }
        !          2537:
        !          2538:                if (not $defaultTextPlain) {
        !          2539:                        print " / (";
        !          2540:                        &download_link($fileurl, $_, "as text", "text/plain");
        !          2541:                        print ")";
        !          2542:                }
        !          2543:
        !          2544:                if (!$defaultViewable) {
        !          2545:                        print " / (";
        !          2546:                        &download_link($fileurl, $_, "view",
        !          2547:                                "text/x-cvsweb-markup");
        !          2548:                        print ")";
        !          2549:                }
        !          2550:
        !          2551:                if ($allow_annotate) {
        !          2552:                        print " - ";
        !          2553:                        print &link(
        !          2554:                                'annotate',
        !          2555:                                sprintf(
        !          2556:                                        '%s/%s?annotate=%s%s', $scriptname,
        !          2557:                                        urlencode($where),     $_,
        !          2558:                                        $barequery
        !          2559:                                )
        !          2560:                        );
        !          2561:                }
        !          2562:
        !          2563:                # Plus a select link if enabled, and this version isn't selected
        !          2564:                if ($allow_version_select) {
        !          2565:                        if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
        !          2566:                                print " - ";
        !          2567:                                print &link(
        !          2568:                                        '[select for diffs]',
        !          2569:                                        sprintf(
        !          2570:                                                '%s?r1=%s%s', $scriptwhere,
        !          2571:                                                $_,           $barequery
        !          2572:                                        )
        !          2573:                                );
        !          2574:                        } else {
        !          2575:                                print " - <b>[selected]</b>";
        !          2576:                        }
1.45.2.46  knu      2577:                }
1.45.2.75! knu      2578:        } else {
        !          2579:                print "Revision <B>$_</B>";
1.45.2.46  knu      2580:        }
1.45.2.75! knu      2581:
1.45.2.46  knu      2582:        if (/^1\.1\.1\.\d+$/) {
1.45.2.75! knu      2583:                print " <i>(vendor branch)</i>";
1.45.2.46  knu      2584:        }
                   2585:        if (defined @mytz) {
1.45.2.75! knu      2586:                my ($est) = $mytz[(localtime($date{$_}))[8]];
        !          2587:                print ", <i>", scalar localtime($date{$_}), " $est</i> (";
1.45.2.46  knu      2588:        } else {
1.45.2.75! knu      2589:                print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
1.45.2.46  knu      2590:        }
1.45.2.75! knu      2591:        print readableTime(time() - $date{$_}, 1), " ago)";
1.45.2.46  knu      2592:        print " by ";
1.45.2.56  knu      2593:        print "<i>", $author{$_}, "</i>\n";
1.45.2.75! knu      2594:        print "<BR>Branch: <b>", $link ? link_tags($revsym{$br}) : $revsym{$br},
        !          2595:            "</b>\n"
1.45.2.46  knu      2596:            if ($revsym{$br});
1.45.2.75! knu      2597:        print "<BR>CVS Tags: <b>", $link ? link_tags($revsym{$_}) : $revsym{$_},
        !          2598:            "</b>"
1.45.2.46  knu      2599:            if ($revsym{$_});
1.45.2.75! knu      2600:        print "<BR>Branch point for: <b>",
        !          2601:            $link ? link_tags($branchpoint{$_}) : $branchpoint{$_}, "</b>\n"
1.45.2.46  knu      2602:            if ($branchpoint{$_});
1.45.2.75! knu      2603:
1.45.2.46  knu      2604:        # Find the previous revision
1.45.2.75! knu      2605:        my @prevrev = split (/\./, $_);
1.45.2.46  knu      2606:        do {
1.45.2.75! knu      2607:                if (--$prevrev[$#prevrev] <= 0) {
        !          2608:
        !          2609:                        # If it was X.Y.Z.1, just make it X.Y
        !          2610:                        pop (@prevrev);
        !          2611:                        pop (@prevrev);
        !          2612:                }
        !          2613:                $prev = join (".", @prevrev);
1.45.2.46  knu      2614:        } until (defined($date{$prev}) || $prev eq "");
1.45.2.75! knu      2615:
1.45.2.46  knu      2616:        if ($prev ne "") {
1.45.2.75! knu      2617:                if ($difflines{$_}) {
        !          2618:                        print
        !          2619:                            "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
        !          2620:                }
1.45.2.46  knu      2621:        }
1.45.2.75! knu      2622:
1.45.2.46  knu      2623:        if ($isDead) {
1.45.2.75! knu      2624:                print "<BR><B><I>FILE REMOVED</I></B>\n";
        !          2625:        } elsif ($link) {
        !          2626:                my %diffrev = ();
        !          2627:                $diffrev{$_} = 1;
        !          2628:                $diffrev{""} = 1;
        !          2629:                print "<BR>Diff";
1.45.2.56  knu      2630:
1.45.2.75! knu      2631:                #
        !          2632:                # Offer diff to previous revision
        !          2633:                if ($prev) {
        !          2634:                        $diffrev{$prev} = 1;
        !          2635:
        !          2636:                        my $url =
        !          2637:                            sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere,
        !          2638:                                $prev, $_, $barequery);
1.45.2.56  knu      2639:
1.45.2.75! knu      2640:                        print " to previous ";
        !          2641:                        printDiffLinks($prev, $url);
        !          2642:                }
1.45.2.56  knu      2643:
1.45.2.75! knu      2644:                #
        !          2645:                # Plus, if it's on a branch, and it's not a vendor branch,
        !          2646:                # offer a diff with the branch point.
        !          2647:                if ($revsym{$brp} && !/^1\.1\.1\.\d+$/
        !          2648:                    && !defined($diffrev{$brp}))
        !          2649:                {
        !          2650:                        my $url =
        !          2651:                            sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $brp,
        !          2652:                                $_, $barequery);
        !          2653:
        !          2654:                        print " to branchpoint ";
        !          2655:                        printDiffLinks($brp, $url);
1.1       jfieber  2656:                }
1.45.2.56  knu      2657:
1.45.2.75! knu      2658:                #
        !          2659:                # Plus, if it's on a branch, and it's not a vendor branch,
        !          2660:                # offer to diff with the next revision of the higher branch.
        !          2661:                # (e.g. change gets committed and then brought
        !          2662:                # over to -stable)
        !          2663:                if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
        !          2664:                        my ($i, $nextmain);
        !          2665:
        !          2666:                        for ($i = 0 ; $i < $#revorder && $revorder[$i] ne $_ ;
        !          2667:                            $i++)
        !          2668:                        {
        !          2669:                        }
        !          2670:                        my @tmp2 = split (/\./, $_);
        !          2671:                        for ($nextmain = "" ; $i > 0 ; $i--) {
        !          2672:                                my $next = $revorder[$i - 1];
        !          2673:                                my @tmp1 = split (/\./, $next);
        !          2674:
        !          2675:                                if (@tmp1 < @tmp2) {
        !          2676:                                        $nextmain = $next;
        !          2677:                                        last;
        !          2678:                                }
        !          2679:
        !          2680:                                # Only the highest version on a branch should have
        !          2681:                                # a diff for the "next main".
        !          2682:                                last
        !          2683:                                    if (@tmp1 - 1 <= @tmp2
        !          2684:                                    && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
        !          2685:                                    join (".", @tmp2[0 .. $#tmp1 - 1]));
        !          2686:                        }
        !          2687:
        !          2688:                        if (!defined($diffrev{$nextmain})) {
        !          2689:                                $diffrev{$nextmain} = 1;
        !          2690:
        !          2691:                                my $url =
        !          2692:                                    sprintf('%s.diff?r1=%s&r2=%s%s',
        !          2693:                                        $scriptwhere, $nextmain, $_,
        !          2694:                                        $barequery);
        !          2695:
        !          2696:                                print " next main ";
        !          2697:                                printDiffLinks($nextmain, $url);
        !          2698:                        }
        !          2699:                }
        !          2700:
        !          2701:                # Plus if user has selected only r1, then present a link
        !          2702:                # to make a diff to that revision
        !          2703:                if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
        !          2704:                        $diffrev{$input{"r1"}} = 1;
        !          2705:
        !          2706:                        my $url =
        !          2707:                            sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere,
        !          2708:                                $input{'r1'}, $_, $barequery);
        !          2709:
        !          2710:                        print " to selected ";
        !          2711:                        printDiffLinks($input{'r1'}, $url);
        !          2712:                }
1.1       jfieber  2713:        }
1.45.2.46  knu      2714:        print "<PRE>\n";
                   2715:        print &htmlify($log{$_}, 1);
                   2716:        print "</PRE>\n";
                   2717: }
                   2718:
1.45.2.47  knu      2719: sub doLog($) {
1.45.2.75! knu      2720:        my ($fullname) = @_;
1.45.2.46  knu      2721:        my ($diffrev, $upwhere, $filename, $backurl);
1.45.2.47  knu      2722:
1.45.2.46  knu      2723:        readLog($fullname);
                   2724:
1.45.2.75! knu      2725:        html_header("CVS log for $where");
        !          2726:        ($upwhere  = $where) =~ s|(Attic/)?[^/]+$||;
        !          2727:        ($filename = $where) =~ s|^.*/||;
        !          2728:        $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
        !          2729:        print &link($backicon, "$backurl#$filename"), " <b>Up to ",
        !          2730:            &clickablePath($upwhere, 1), "</b><p>\n";
1.45.2.56  knu      2731:        print &link('Request diff between arbitrary revisions', '#diff');
1.45.2.75! knu      2732:        print '<HR NOSHADE>';
1.45.2.56  knu      2733:
1.45.2.46  knu      2734:        if ($curbranch) {
1.45.2.75! knu      2735:                print "Default branch: ", ($revsym{$curbranch} || $curbranch);
        !          2736:        } else {
        !          2737:                print "No default branch";
1.45.2.46  knu      2738:        }
                   2739:        print "<BR>\n";
1.45.2.75! knu      2740:
1.45.2.46  knu      2741:        if ($input{only_with_tag}) {
1.45.2.75! knu      2742:                print "Current tag: $input{only_with_tag}<BR>\n";
1.45.2.46  knu      2743:        }
                   2744:
                   2745:        undef %nameprinted;
                   2746:
1.45.2.75! knu      2747:        for (my $i = 0 ; $i <= $#revdisplayorder ; $i++) {
        !          2748:                print "<HR size=1 NOSHADE>";
        !          2749:                printLog($revdisplayorder[$i]);
1.45.2.46  knu      2750:        }
                   2751:
1.45.2.75! knu      2752:        print "<HR NOSHADE>";
1.1       jfieber  2753:        print "<A NAME=diff>\n";
                   2754:        print "This form allows you to request diff's between any two\n";
                   2755:        print "revisions of a file.  You may select a symbolic revision\n";
                   2756:        print "name using the selection box or you may type in a numeric\n";
                   2757:        print "name using the type-in text box.\n";
                   2758:        print "</A><P>\n";
1.45.2.75! knu      2759:        print
        !          2760:            "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
        !          2761:
        !          2762:        foreach (@stickyvars) {
        !          2763:                printf('<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">', $_,
        !          2764:                    $input{$_})
        !          2765:                    if (defined($input{$_})
1.45.2.51  knu      2766:                    && ((!defined($DEFAULTVALUE{$_})
1.45.2.75! knu      2767:                    || $input{$_} ne $DEFAULTVALUE{$_}) && $input{$_} ne ""));
1.45.2.46  knu      2768:        }
1.45.2.51  knu      2769:        print "<TABLE><TR>\n";
                   2770:        print "<TD align=right>Diffs between \n";
1.1       jfieber  2771:        print "<SELECT NAME=\"r1\">\n";
                   2772:        print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
                   2773:        print $sel;
                   2774:        print "</SELECT>\n";
1.45.2.46  knu      2775:        $diffrev = $revdisplayorder[$#revdisplayorder];
                   2776:        $diffrev = $input{"r1"} if (defined($input{"r1"}));
1.45.2.75! knu      2777:        print
        !          2778:            "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
1.45.2.51  knu      2779:        print "<TD><BR></TD></TR>\n";
                   2780:        print "<TR><TD align=right>and \n";
1.1       jfieber  2781:        print "<SELECT NAME=\"r2\">\n";
                   2782:        print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
                   2783:        print $sel;
                   2784:        print "</SELECT>\n";
1.45.2.46  knu      2785:        $diffrev = $revdisplayorder[0];
                   2786:        $diffrev = $input{"r2"} if (defined($input{"r2"}));
1.45.2.75! knu      2787:        print
        !          2788:            "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
1.45.2.51  knu      2789:        print "<TD><INPUT TYPE=SUBMIT VALUE=\"  Get Diffs  \"></TD>\n";
1.1       jfieber  2790:        print "</FORM>\n";
1.45.2.51  knu      2791:        print "</TR></TABLE>\n";
1.7       fenner   2792:        print "<HR noshade>\n";
1.45.2.51  knu      2793:        print "<TABLE>";
                   2794:        print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
1.45.2.56  knu      2795:        print "<TR><TD align=right>Preferred Diff type:</TD>";
                   2796:        print "<TD>";
1.45.2.51  knu      2797:        printDiffSelect($use_java_script);
                   2798:        print "</TD><TD></TD></TR>\n";
1.45.2.75! knu      2799:
        !          2800:        if (@branchnames) {
        !          2801:                print "<TR><TD align=right>View only Branch:</TD>";
        !          2802:                print "<TD>";
        !          2803:                print "<A name=branch></A>\n";
        !          2804:                print "<SELECT NAME=\"only_with_tag\"";
        !          2805:                print " onchange=\"submit()\"" if ($use_java_script);
        !          2806:                print ">\n";
        !          2807:                print "<OPTION VALUE=\"\"";
        !          2808:                print " SELECTED"
        !          2809:                    if (defined($input{"only_with_tag"})
        !          2810:                    && $input{"only_with_tag"} eq "");
        !          2811:                print ">Show all branches\n";
        !          2812:
        !          2813:                foreach (reverse sort @branchnames) {
        !          2814:                        print "<OPTION";
        !          2815:                        print " SELECTED"
        !          2816:                            if (defined($input{"only_with_tag"})
        !          2817:                            && $input{"only_with_tag"} eq $_);
        !          2818:                        print ">${_}\n";
        !          2819:                }
        !          2820:                print "</SELECT></TD><TD></TD></TR>\n";
1.7       fenner   2821:        }
1.45.2.75! knu      2822:
1.45.2.46  knu      2823:        foreach (@stickyvars) {
1.45.2.75! knu      2824:                next if ($_ eq "f");
        !          2825:                next if ($_ eq "only_with_tag");
        !          2826:                next if ($_ eq "logsort");
        !          2827:                print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
        !          2828:                    if (defined($input{$_})
1.45.2.51  knu      2829:                    && (!defined($DEFAULTVALUE{$_})
1.45.2.75! knu      2830:                    || $input{$_} ne $DEFAULTVALUE{$_}) && $input{$_} ne "");
1.45.2.46  knu      2831:        }
1.45.2.51  knu      2832:        print "<TR><TD align=right>";
                   2833:        print "<A name=logsort></A>\n";
                   2834:        print "Sort log by:</TD>";
1.45.2.56  knu      2835:        print "<TD>";
                   2836:        printLogSortSelect($use_java_script);
                   2837:        print "</TD>";
1.45.2.51  knu      2838:        print "<TD><INPUT TYPE=SUBMIT VALUE=\"  Set  \"></TD>";
1.7       fenner   2839:        print "</FORM>\n";
1.45.2.51  knu      2840:        print "</TR></TABLE>";
1.45.2.75! knu      2841:        print &html_footer;
1.1       jfieber  2842:        print "</BODY></HTML>\n";
1.10      wosch    2843: }
                   2844:
1.45.2.47  knu      2845: sub flush_diff_rows($$$$) {
1.45.2.75! knu      2846:        my $j;
        !          2847:        my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
        !          2848:
        !          2849:        if (!defined($state)) {
        !          2850:                return;
        !          2851:        }
        !          2852:
        !          2853:        if ($state eq "PreChangeRemove") {    # we just got remove-lines before
        !          2854:                for ($j = 0 ; $j < $leftRow ; $j++) {
        !          2855:                        print
        !          2856:                            "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
        !          2857:                        print
        !          2858:                            "<td bgcolor=\"$diffcolorEmpty\">&nbsp;</td></tr>\n";
        !          2859:                }
        !          2860:        } elsif ($state eq "PreChange") {    # state eq "PreChange"
        !          2861:                    # we got removes with subsequent adds
        !          2862:
        !          2863:                for ($j = 0 ; $j < $leftRow || $j < $rightRow ; $j++)
        !          2864:                {    # dump out both cols
        !          2865:                        print "<tr>";
        !          2866:                        if ($j < $leftRow) {
        !          2867:                                print
        !          2868:                                    "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
        !          2869:                        } else {
        !          2870:                                print
        !          2871:                                    "<td bgcolor=\"$diffcolorDarkChange\">&nbsp;</td>";
        !          2872:                        }
        !          2873:
        !          2874:                        if ($j < $rightRow) {
        !          2875:                                print
        !          2876:                                    "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
        !          2877:                        } else {
        !          2878:                                print
        !          2879:                                    "<td bgcolor=\"$diffcolorDarkChange\">&nbsp;</td>";
        !          2880:                        }
        !          2881:                        print "</tr>\n";
        !          2882:                }
        !          2883:        }
1.45.2.46  knu      2884: }
                   2885:
                   2886: ##
                   2887: # Function to generate Human readable diff-files
                   2888: # human_readable_diff(String revision_to_return_to);
                   2889: ##
1.45.2.75! knu      2890: sub human_readable_diff($) {
        !          2891:        my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
        !          2892:        my ($fh, $rev) = @_;
        !          2893:        my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
        !          2894:        my (@rightCol, @leftCol);
        !          2895:
        !          2896:        ($where_nd       = $where)       =~ s/.diff$//;
        !          2897:        ($filename       = $where_nd)    =~ s/^.*\///;
        !          2898:        ($pathname       = $where_nd)    =~ s/(Attic\/)?[^\/]*$//;
        !          2899:        ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
        !          2900:
        !          2901:        navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
        !          2902:
        !          2903:        # Read header to pick up read revision and date, if possible
        !          2904:        while (<$fh>) {
        !          2905:                ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
        !          2906:                ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
        !          2907:                last if (/^\+\+\+ /);
        !          2908:        }
        !          2909:
        !          2910:        if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
        !          2911:                $rev1  = $r1r;
        !          2912:                $date1 = $r1d;
        !          2913:        }
        !          2914:        if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
        !          2915:                $rev2  = $r2r;
        !          2916:                $date2 = $r2d;
        !          2917:        }
        !          2918:
        !          2919:        print
        !          2920:            "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
        !          2921:            "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n",
        !          2922:            "<tr bgcolor=\"#ffffff\">\n", "<th width=\"50%\" valign=TOP>",
        !          2923:            "version $rev1";
        !          2924:        print ", $date1"         if (defined($date1));
        !          2925:        print "<br>Tag: $sym1\n" if ($sym1);
        !          2926:        print "</th>\n", "<th width=\"50%\" valign=TOP>", "version $rev2";
        !          2927:        print ", $date2"         if (defined($date2));
        !          2928:        print "<br>Tag: $sym2\n" if ($sym1);
        !          2929:        print "</th>\n";
        !          2930:
        !          2931:        my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\"><tt>";
        !          2932:        my $fe = "</tt></font>";
        !          2933:
        !          2934:        my $leftRow  = 0;
        !          2935:        my $rightRow = 0;
        !          2936:        my ($oldline, $newline, $funname, $diffcode, $rest);
        !          2937:
        !          2938:        # Process diff text
        !          2939:        # The diffrows are could make excellent use of
        !          2940:        # cascading style sheets because we've to set the
        !          2941:        # font and color for each row. anyone ...?
        !          2942:        ####
        !          2943:
        !          2944:        # prefetch several lines
        !          2945:        my @buf = head($fh);
        !          2946:
        !          2947:        my %d = scan_directives(@buf);
        !          2948:
        !          2949:        while (@buf || !eof($fh)) {
        !          2950:                $difftxt = @buf ? shift @buf : <$fh>;
        !          2951:
        !          2952:                if ($difftxt =~ /^@@/) {
        !          2953:                        ($oldline, $newline, $funname) =
        !          2954:                            $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
        !          2955:                        $funname = htmlquote($funname);
        !          2956:                        print
        !          2957:                            "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
        !          2958:                        print
        !          2959:                            "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
        !          2960:                        print
        !          2961:                            "&nbsp;<font size=-1>$funname</font></td></tr></table>";
        !          2962:                        print "</td><td width=\"50%\">";
        !          2963:                        print
        !          2964:                            "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
        !          2965:                        print
        !          2966:                            "&nbsp;<font size=-1>$funname</font></td></tr></table>";
        !          2967:                        print "</td>\n";
        !          2968:                        $state    = "dump";
        !          2969:                        $leftRow  = 0;
        !          2970:                        $rightRow = 0;
        !          2971:                } else {
        !          2972:                        ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
        !          2973:                        $_ = spacedHtmlText($rest, $d{'tabstop'});
        !          2974:
        !          2975:                        # Add fontface, size
        !          2976:                        $_ = "$fs&nbsp;$_$fe";
        !          2977:
        !          2978:                        #########
        !          2979:                        # little state machine to parse unified-diff output (Hen, zeller@think.de)
        !          2980:                        # in order to get some nice 'ediff'-mode output
        !          2981:                        # states:
        !          2982:                        #  "dump"             - just dump the value
        !          2983:                        #  "PreChangeRemove"  - we began with '-' .. so this could be the start of a 'change' area or just remove
        !          2984:                        #  "PreChange"        - okey, we got several '-' lines and moved to '+' lines -> this is a change block
        !          2985:                        ##########
        !          2986:
        !          2987:                        if ($diffcode eq '+') {
        !          2988:                                if ($state eq "dump")
        !          2989:                                { # 'change' never begins with '+': just dump out value
        !          2990:                                        print
        !          2991:                                            "<tr><td bgcolor=\"$diffcolorEmpty\">&nbsp;</td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
        !          2992:                                } else {    # we got minus before
        !          2993:                                        $state = "PreChange";
        !          2994:                                        $rightCol[$rightRow++] = $_;
        !          2995:                                }
        !          2996:                        } elsif ($diffcode eq '-') {
        !          2997:                                $state = "PreChangeRemove";
        !          2998:                                $leftCol[$leftRow++] = $_;
        !          2999:                        } else {    # empty diffcode
        !          3000:                                flush_diff_rows \@leftCol, \@rightCol, $leftRow,
        !          3001:                                    $rightRow;
        !          3002:                                print "<tr><td>$_</td><td>$_</td></tr>\n";
        !          3003:                                $state    = "dump";
        !          3004:                                $leftRow  = 0;
        !          3005:                                $rightRow = 0;
        !          3006:                        }
        !          3007:                }
        !          3008:        }
        !          3009:        flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
        !          3010:
        !          3011:        # state is empty if we didn't have any change
        !          3012:        if (!$state) {
        !          3013:                print "<tr><td colspan=2>&nbsp;</td></tr>";
        !          3014:                print "<tr bgcolor=\"$diffcolorEmpty\" >";
        !          3015:                print
        !          3016:                    "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
        !          3017:        }
        !          3018:        print "</table>";
        !          3019:        close($fh);
        !          3020:
        !          3021:        print "<br><hr noshade width=\"100%\">\n";
        !          3022:
        !          3023:        print "<table border=0>";
        !          3024:
        !          3025:        print "<tr><td>";
        !          3026:
        !          3027:        # print legend
        !          3028:        print "<table border=1><tr><td>";
        !          3029:        print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
        !          3030:        print
        !          3031:            "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\">&nbsp;</td></tr>";
        !          3032:        print
        !          3033:            "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
        !          3034:        print
        !          3035:            "<tr><td bgcolor=\"$diffcolorEmpty\">&nbsp;</td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
        !          3036:        print "</table></td></tr></table>\n";
1.45.2.46  knu      3037:
1.45.2.75! knu      3038:        print "<td>";
        !          3039:
        !          3040:        # Print format selector
        !          3041:        print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
        !          3042:        foreach my $var (keys %input) {
        !          3043:                next if ($var eq "f");
        !          3044:                next
        !          3045:                    if (defined($DEFAULTVALUE{$var})
        !          3046:                    && $DEFAULTVALUE{$var} eq $input{$var});
        !          3047:                print "<INPUT TYPE=HIDDEN NAME=\"", urlencode($var),
        !          3048:                    "\" VALUE=\"", urlencode($input{$var}), "\">\n";
        !          3049:        }
        !          3050:        printDiffSelect($use_java_script);
        !          3051:        print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
        !          3052:        print "</FORM>\n";
        !          3053:        print "</td>";
        !          3054:
        !          3055:        print "</tr></table>";
1.45.2.46  knu      3056: }
                   3057:
1.45.2.47  knu      3058: sub navigateHeader($$$$$) {
1.45.2.75! knu      3059:        my ($swhere, $path, $filename, $rev, $title) = @_;
        !          3060:        $swhere = "" if ($swhere eq $scriptwhere);
        !          3061:        $swhere = './' . urlencode($filename) if ($swhere eq "");
1.45.2.68  knu      3062:
1.45.2.75! knu      3063:        print <<EOF;
1.45.2.68  knu      3064: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
                   3065: <HTML>
                   3066: <HEAD>
                   3067: <META name="robots" content="nofollow">
                   3068: <!-- knu-cvsweb $cvsweb_revision -->
                   3069: <TITLE>$path$filename - $title - $rev</TITLE></HEAD>
                   3070: $body_tag_for_src
                   3071: <table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="$navigationHeaderColor">
                   3072: <tr valign=bottom><td>
                   3073: EOF
                   3074:
1.45.2.75! knu      3075:        print &link($backicon, "$swhere$query#rev$rev");
        !          3076:        print "<b>Return to ", &link($filename, "$swhere$query#rev$rev"),
        !          3077:            " CVS log";
        !          3078:        print "</b> $fileicon</td>";
        !          3079:
        !          3080:        print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1),
        !          3081:            "</b></td>";
        !          3082:        print "</tr></table>";
1.45.2.46  knu      3083: }
                   3084:
1.45.2.47  knu      3085: sub plural_write($$) {
1.45.2.75! knu      3086:        my ($num, $text) = @_;
        !          3087:        if ($num != 1) {
        !          3088:                $text .= "s";
        !          3089:        }
        !          3090:
        !          3091:        if ($num > 0) {
        !          3092:                return join (' ', $num, $text);
        !          3093:        } else {
        !          3094:                return "";
        !          3095:        }
1.45.2.46  knu      3096: }
                   3097:
                   3098: ##
                   3099: # print readable timestamp in terms of
                   3100: # '..time ago'
                   3101: # H. Zeller <zeller@think.de>
                   3102: ##
1.45.2.47  knu      3103: sub readableTime($$) {
1.45.2.75! knu      3104:        my ($i, $break, $retval);
        !          3105:        my ($secs, $long) = @_;
1.45.2.46  knu      3106:
1.45.2.75! knu      3107:        # this function works correct for time >= 2 seconds
        !          3108:        if ($secs < 2) {
        !          3109:                return "very little time";
        !          3110:        }
        !          3111:
        !          3112:        my %desc = (
        !          3113:                1,        'second', 60,     'minute', 3600,    'hour',
        !          3114:                86400,    'day',    604800, 'week',   2628000, 'month',
        !          3115:                31536000, 'year'
        !          3116:        );
        !          3117:        my @breaks = sort { $a <=> $b } keys %desc;
        !          3118:        $i = 0;
1.45.2.46  knu      3119:
1.45.2.75! knu      3120:        while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
        !          3121:                $i++;
        !          3122:        }
1.45.2.46  knu      3123:        $i--;
1.45.2.75! knu      3124:        $break  = $breaks[$i];
        !          3125:        $retval = plural_write(int($secs / $break), $desc{$break});
        !          3126:
        !          3127:        if ($long == 1 && $i > 0) {
        !          3128:                my $rest = $secs % $break;
        !          3129:                $i--;
        !          3130:                $break = $breaks[$i];
        !          3131:                my $resttime = plural_write(int($rest / $break), $desc{$break});
        !          3132:                if ($resttime) {
        !          3133:                        $retval .= ", $resttime";
        !          3134:                }
1.45.2.46  knu      3135:        }
                   3136:
1.45.2.75! knu      3137:        return $retval;
1.45.2.46  knu      3138: }
                   3139:
                   3140: ##
                   3141: # clickablePath(String pathname, boolean last_item_clickable)
                   3142: #
                   3143: # returns a html-ified path whereas each directory is a link for
                   3144: # faster navigation. last_item_clickable controls whether the
                   3145: # basename (last directory/file) is a link as well
                   3146: ##
                   3147: sub clickablePath($$) {
1.45.2.75! knu      3148:        my ($pathname, $clickLast) = @_;
        !          3149:        my $retval = '';
1.45.2.47  knu      3150:
1.45.2.75! knu      3151:        if ($pathname eq '/') {
        !          3152:
        !          3153:                # this should never happen - chooseCVSRoot() is
        !          3154:                # intended to do this
        !          3155:                $retval = "[$cvstree]";
        !          3156:        } else {
        !          3157:                $retval .= ' ' . &link("[$cvstree]",
        !          3158:                        sprintf('%s/%s#dirlist', $scriptname, $query));
        !          3159:                my $wherepath = '';
        !          3160:                my ($lastslash) = $pathname =~ m|/$|;
        !          3161:
        !          3162:                foreach (split (/\//, $pathname)) {
        !          3163:                        $retval .= " / ";
        !          3164:                        $wherepath .= "/$_";
        !          3165:                        my ($last) = "$wherepath/" eq "/$pathname"
        !          3166:                            || $wherepath eq "/$pathname";
        !          3167:
        !          3168:                        if ($clickLast || !$last) {
        !          3169:                                $retval .= &link($_,
        !          3170:                                        join ('', $scriptname,
        !          3171:                                        urlencode($wherepath),
        !          3172:                                        (!$last || $lastslash ? '/' : ''),
        !          3173:                                        $query,
        !          3174:                                        (!$last || $lastslash ? "#dirlist" : "")
        !          3175:                                ));
        !          3176:                        } else {    # do not make a link to the current dir
        !          3177:                                $retval .= $_;
        !          3178:                        }
        !          3179:                }
1.45.2.46  knu      3180:        }
1.45.2.75! knu      3181:        return $retval;
1.45.2.46  knu      3182: }
                   3183:
                   3184: sub chooseCVSRoot() {
1.45.2.75! knu      3185:        if (2 <= @CVSROOT) {
        !          3186:                my ($k);
        !          3187:                print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
        !          3188:                foreach $k (keys %input) {
        !          3189:                        print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
        !          3190:                            if ($input{$k}) && ($k ne "cvsroot");
        !          3191:                }
        !          3192:
        !          3193:                # Form-Elements look wierd in Netscape if the background
        !          3194:                # isn't gray and the form elements are not placed
        !          3195:                # within a table ...
        !          3196:                print "<table><tr>";
        !          3197:                print "<td>CVS Root:</td>";
        !          3198:                print "<td>\n<select name=\"cvsroot\"";
        !          3199:                print " onchange=\"submit()\"" if ($use_java_script);
        !          3200:                print ">\n";
        !          3201:
        !          3202:                foreach $k (@CVSROOT) {
        !          3203:                        print "<option value=\"$k\"";
        !          3204:                        print " selected" if ($k eq $cvstree);
        !          3205:                        print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k),
        !          3206:                            "</option>\n";
        !          3207:                }
        !          3208:                print "</select>\n</td>";
        !          3209:                print "<td>";
        !          3210:        } else {
        !          3211:
        !          3212:                # no choice -- but we need the form to select module/path, at least for Netscape
        !          3213:                print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
        !          3214:                print "CVS Root: <b>[$cvstree]</b>";
1.45.2.46  knu      3215:        }
1.45.2.75! knu      3216:
        !          3217:        print " Module path or alias:\n";
        !          3218:        print "<INPUT TYPE=TEXT NAME=\"path\" VALUE=\"\" SIZE=15>\n";
        !          3219:        print "<input type=submit value=\"Go\">";
        !          3220:
        !          3221:        if (2 <= @CVSROOT) {
        !          3222:                print "</td></tr></table>";
        !          3223:        }
        !          3224:        print "</form>";
1.45.2.46  knu      3225: }
                   3226:
                   3227: sub chooseMirror() {
1.45.2.75! knu      3228:        my ($mirror, $moremirrors);
        !          3229:        $moremirrors = 0;
        !          3230:
        !          3231:        # This code comes from the original BSD-cvsweb
        !          3232:        # and may not be useful for your site; If you don't
        !          3233:        # set %MIRRORS this won't show up, anyway
        !          3234:        #
        !          3235:        # Should perhaps exlude the current site somehow..
        !          3236:        if (keys %MIRRORS) {
        !          3237:                print "\nThis cvsweb is mirrored in:\n";
        !          3238:
        !          3239:                foreach $mirror (keys %MIRRORS) {
        !          3240:                        print ", " if ($moremirrors);
        !          3241:                        print &link(htmlquote($mirror), $MIRRORS{$mirror});
        !          3242:                        $moremirrors = 1;
        !          3243:                }
        !          3244:                print "<p>\n";
1.45.2.46  knu      3245:        }
                   3246: }
                   3247:
1.45.2.47  knu      3248: sub fileSortCmp() {
1.45.2.75! knu      3249:        my ($comp) = 0;
        !          3250:        my ($c, $d, $af, $bf);
1.45.2.46  knu      3251:
1.45.2.75! knu      3252:        ($af = $a) =~ s/,v$//;
        !          3253:        ($bf = $b) =~ s/,v$//;
        !          3254:        my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
        !          3255:            if (defined($fileinfo{$af}));
        !          3256:        my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
        !          3257:            if (defined($fileinfo{$bf}));
        !          3258:
        !          3259:        if (defined($filename1) && defined($filename2) && $af eq $filename1
        !          3260:            && $bf eq $filename2)
        !          3261:        {
        !          3262:
        !          3263:                # Two files
        !          3264:                $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
        !          3265:                $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
        !          3266:                $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
        !          3267:                $comp = ($author1 cmp $author2)
        !          3268:                    if ($byauthor && $author1 && $author2);
        !          3269:        }
        !          3270:
        !          3271:        if ($comp == 0) {
        !          3272:
        !          3273:                # Directories first, then sorted on name if no other sort critera
        !          3274:                # available.
        !          3275:                my $ad = ((-d "$fullname/$a") ? "D" : "F");
        !          3276:                my $bd = ((-d "$fullname/$b") ? "D" : "F");
        !          3277:                ($c = $a) =~ s|.*/||;
        !          3278:                ($d = $b) =~ s|.*/||;
        !          3279:                $comp = ("$ad$c" cmp "$bd$d");
        !          3280:        }
        !          3281:        return $comp;
1.45.2.46  knu      3282: }
                   3283:
                   3284: # make A url for downloading
1.45.2.47  knu      3285: sub download_url($$;$) {
1.45.2.75! knu      3286:        my ($url, $revision, $mimetype) = @_;
1.45.2.46  knu      3287:
1.45.2.75! knu      3288:        $revision =~ s/\b0\.//;
1.45.2.46  knu      3289:
1.45.2.75! knu      3290:        if (defined($checkoutMagic)
        !          3291:            && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
        !          3292:        {
        !          3293:                my $path = $where;
        !          3294:                $path =~ s|/[^/]*$|/|;
        !          3295:                $url = "$scriptname/$checkoutMagic/${path}$url";
        !          3296:        }
        !          3297:        $url .= "?rev=$revision";
        !          3298:        $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
1.45.2.69  knu      3299:
1.45.2.75! knu      3300:        $url;
1.45.2.46  knu      3301: }
                   3302:
1.45.2.47  knu      3303: # Presents a link to download the
1.45.2.46  knu      3304: # selected revision
1.45.2.47  knu      3305: sub download_link($$$;$) {
1.45.2.75! knu      3306:        my ($url, $revision, $textlink, $mimetype) = @_;
        !          3307:        my ($fullurl) = download_url($url, $revision, $mimetype);
1.45.2.56  knu      3308:
1.45.2.75! knu      3309:        $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
1.45.2.56  knu      3310:
1.45.2.75! knu      3311:        printf '<A HREF="%s"', hrefquote("$fullurl$barequery");
1.45.2.56  knu      3312:
1.45.2.75! knu      3313:        if ($open_extern_window
        !          3314:            && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
        !          3315:        {
        !          3316:                print ' target="cvs_checkout"';
        !          3317:
        !          3318:                # we should have
        !          3319:                #   'if (document.cvswin==null) document.cvswin=window.open(...'
        !          3320:                # in order to allow the user to resize the window; otherwise
        !          3321:                # the user may resize the window, but on next checkout - zap -
        !          3322:                # its original (configured s. cvsweb.conf) size is back again
        !          3323:                # .. annoying (if $extern_window_(width|height) is defined)
        !          3324:                # but this if (..) solution is far from perfect
        !          3325:                # what we need to do as well is
        !          3326:                # 1) save cvswin in an invisible frame that always exists
        !          3327:                #    (document.cvswin will be void on next load)
        !          3328:                # 2) on close of the cvs_checkout - window set the cvswin
        !          3329:                #    variable to 'null' again - so that it will be
        !          3330:                #    reopenend with the configured size
        !          3331:                # anyone a JavaScript programmer ?
        !          3332:                # .. so here without if (..):
        !          3333:                # currently, the best way is to comment out the size parameters
        !          3334:                # ($extern_window...) in cvsweb.conf.
        !          3335:                if ($use_java_script) {
        !          3336:                        my @attr = qw(resizeable scrollbars);
        !          3337:
        !          3338:                        push @attr, qw(status toolbar)
        !          3339:                            if (defined($mimetype) && $mimetype eq "text/html");
        !          3340:
        !          3341:                        push @attr, "width=$extern_window_width"
        !          3342:                            if (defined($extern_window_width));
        !          3343:
        !          3344:                        push @attr, "height=$extern_window_height"
        !          3345:                            if (defined($extern_window_height));
        !          3346:
        !          3347:                        printf
        !          3348:                            q` onClick="window.open('%s','cvs_checkout','%s');"`,
        !          3349:                            hrefquote($fullurl), join (',', @attr);
        !          3350:                }
1.45.2.46  knu      3351:        }
1.45.2.75! knu      3352:        print "><b>$textlink</b></A>";
1.45.2.46  knu      3353: }
                   3354:
                   3355: # Returns a Query string with the
                   3356: # specified parameter toggled
                   3357: sub toggleQuery($$) {
1.45.2.75! knu      3358:        my ($toggle, $value) = @_;
        !          3359:        my ($newquery, $var);
        !          3360:        my (%vars);
        !          3361:        %vars = %input;
        !          3362:
        !          3363:        if (defined($value)) {
        !          3364:                $vars{$toggle} = $value;
        !          3365:        } else {
        !          3366:                $vars{$toggle} = $vars{$toggle} ? 0 : 1;
        !          3367:        }
        !          3368:
        !          3369:        # Build a new query of non-default paramenters
        !          3370:        $newquery = "";
        !          3371:        foreach $var (@stickyvars) {
        !          3372:                my ($value) = defined($vars{$var}) ? $vars{$var} : "";
        !          3373:                my ($default) =
        !          3374:                    defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
        !          3375:
        !          3376:                if ($value ne $default) {
        !          3377:                        $newquery .= "&" if ($newquery ne "");
        !          3378:                        $newquery .= urlencode($var) . "=" . urlencode($value);
        !          3379:                }
        !          3380:        }
        !          3381:
        !          3382:        if ($newquery) {
        !          3383:                return '?' . $newquery;
        !          3384:        }
        !          3385:        return "";
1.45.2.46  knu      3386: }
                   3387:
1.45.2.47  knu      3388: sub urlencode($) {
1.45.2.75! knu      3389:        local ($_) = @_;
1.45.2.56  knu      3390:
1.45.2.75! knu      3391:        s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
1.45.2.56  knu      3392:
1.45.2.75! knu      3393:        $_;
1.45.2.56  knu      3394: }
                   3395:
                   3396: sub htmlquote($) {
1.45.2.75! knu      3397:        local ($_) = @_;
1.45.2.56  knu      3398:
1.45.2.75! knu      3399:        # Special Characters; RFC 1866
        !          3400:        s/&/&amp;/g;
        !          3401:        s/\"/&quot;/g;
        !          3402:        s/</&lt;/g;
        !          3403:        s/>/&gt;/g;
1.45.2.56  knu      3404:
1.45.2.75! knu      3405:        $_;
1.45.2.56  knu      3406: }
                   3407:
                   3408: sub htmlunquote($) {
1.45.2.75! knu      3409:        local ($_) = @_;
1.45.2.56  knu      3410:
1.45.2.75! knu      3411:        # Special Characters; RFC 1866
        !          3412:        s/&quot;/\"/g;
        !          3413:        s/&lt;/</g;
        !          3414:        s/&gt;/>/g;
        !          3415:        s/&amp;/&/g;
1.45.2.56  knu      3416:
1.45.2.75! knu      3417:        $_;
1.45.2.46  knu      3418: }
                   3419:
1.45.2.61  knu      3420: sub hrefquote($) {
1.45.2.75! knu      3421:        local ($_) = @_;
1.45.2.61  knu      3422:
1.45.2.75! knu      3423:        y/ /+/;
1.45.2.61  knu      3424:
1.45.2.75! knu      3425:        htmlquote($_)
1.45.2.61  knu      3426: }
                   3427:
1.45.2.47  knu      3428: sub http_header(;$) {
1.45.2.75! knu      3429:        my $content_type = shift || "text/html";
1.45.2.63  knu      3430:
1.45.2.75! knu      3431:        $content_type .= "; charset=$charset"
        !          3432:            if $content_type =~ m,^text/, && defined($charset) && $charset;
1.45.2.63  knu      3433:
1.45.2.75! knu      3434:        if (defined($moddate)) {
        !          3435:                if ($is_mod_perl) {
        !          3436:                        Apache->request->header_out(
        !          3437:                                "Last-Modified" => scalar gmtime($moddate)
        !          3438:                                . " GMT");
        !          3439:                } else {
        !          3440:                        print "Last-Modified: ", scalar gmtime($moddate),
        !          3441:                            " GMT\r\n";
        !          3442:                }
1.45.2.46  knu      3443:        }
1.45.2.75! knu      3444:
        !          3445:        if ($is_mod_perl) {
        !          3446:                Apache->request->content_type($content_type);
        !          3447:        } else {
        !          3448:                print "Content-type: $content_type\r\n";
1.45.2.46  knu      3449:        }
1.45.2.75! knu      3450:
        !          3451:        if ($allow_compress && $maycompress) {
        !          3452:                if ($has_zlib
        !          3453:                    || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c"))
        !          3454:                    )
        !          3455:                {
        !          3456:
        !          3457:                        if ($is_mod_perl) {
        !          3458:                                Apache->request->content_encoding("x-gzip");
        !          3459:                                Apache->request->header_out(
        !          3460:                                        Vary => "Accept-Encoding");
        !          3461:                                Apache->request->send_http_header;
        !          3462:                        } else {
        !          3463:                                print "Content-encoding: x-gzip\r\n";
        !          3464:                                print "Vary: Accept-Encoding\r\n"
        !          3465:                                    ;            #RFC 2068, 14.43
        !          3466:                                print "\r\n";    # Close headers
        !          3467:                        }
        !          3468:                        $| = 1;
        !          3469:                        $| = 0;    # Flush header output
        !          3470:
        !          3471:                        if ($has_zlib) {
        !          3472:                                tie *GZIP, __PACKAGE__, \*STDOUT;
        !          3473:                        }
        !          3474:                        select(GZIP);
        !          3475:                        $gzip_open = 1;
        !          3476:
        !          3477:                        #           print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
        !          3478:                } else {
        !          3479:                        if ($is_mod_perl) {
        !          3480:                                Apache->request->send_http_header;
        !          3481:                        } else {
        !          3482:                                print "\r\n";    # Close headers
        !          3483:                        }
        !          3484:                        print
        !          3485:                            "<font size=-1>Unable to find gzip binary in the <b>\$command_path</b> ($command_path) to compress output</font><br>";
        !          3486:                }
        !          3487:        } else {
        !          3488:
        !          3489:                if ($is_mod_perl) {
        !          3490:                        Apache->request->send_http_header;
        !          3491:                } else {
        !          3492:                        print "\r\n";    # Close headers
        !          3493:                }
1.45.2.46  knu      3494:        }
                   3495: }
                   3496:
                   3497: sub html_header($) {
1.45.2.75! knu      3498:        my ($title) = @_;
        !          3499:        http_header("text/html");
1.45.2.46  knu      3500:
1.45.2.75! knu      3501:        (my $header = &cgi_style::html_header) =~ s/^.*\n\n//; # remove HTTP response header
1.45.2.46  knu      3502:
1.45.2.75! knu      3503:        print <<EOH;
1.45.2.46  knu      3504: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
                   3505:  "http://www.w3.org/TR/REC-html40/loose.dtd">
                   3506: $header
1.45.2.68  knu      3507: <!-- knu-cvsweb $cvsweb_revision -->

CVSweb