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

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.66

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

CVSweb