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

Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.29

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

CVSweb