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

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.61

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

CVSweb