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

Annotation of cvsweb/cvsweb.cgi, Revision 3.283

3.204     scop        1: #!/usr/bin/perl -T
1.1       jfieber     2: #
3.1       knu         3: # cvsweb - a CGI interface to CVS trees.
1.1       jfieber     4: #
3.12      knu         5: # Written in their spare time by
3.113     scop        6: #             Bill Fenner          <fenner@FreeBSD.org>   (original work)
                      7: # extended by Henner Zeller        <zeller@think.de>,
                      8: #             Henrik Nordstrom     <hno@hem.passagen.se>
                      9: #             Ken Coar             <coar@Apache.Org>
                     10: #             Dick Balaska         <dick@buckosoft.com>
                     11: #             Akinori MUSHA        <knu@FreeBSD.org>
                     12: #             Jens-Uwe Mager       <jum@helios.de>
                     13: #             Ville Skyttä         <scop@FreeBSD.org>
                     14: #             Vassilii Khachaturov <vassilii@tarunz.org>
3.1       knu        15: #
                     16: # Based on:
                     17: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
3.5       knu        18: #   http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1       jfieber    19: #
1.21      wosch      20: # Copyright (c) 1996-1998 Bill Fenner
3.1       knu        21: #           (c) 1998-1999 Henner Zeller
3.109     scop       22: #           (c) 1999      Henrik Nordstrom
                     23: #           (c) 2000-2002 Akinori MUSHA
3.216     scop       24: #           (c) 2002-2004 Ville Skyttä
1.21      wosch      25: # All rights reserved.
                     26: #
                     27: # Redistribution and use in source and binary forms, with or without
                     28: # modification, are permitted provided that the following conditions
                     29: # are met:
                     30: # 1. Redistributions of source code must retain the above copyright
                     31: #    notice, this list of conditions and the following disclaimer.
                     32: # 2. Redistributions in binary form must reproduce the above copyright
                     33: #    notice, this list of conditions and the following disclaimer in the
                     34: #    documentation and/or other materials provided with the distribution.
                     35: #
                     36: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
                     37: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     38: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     39: # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
                     40: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     41: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     42: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     43: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     44: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     45: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     46: # SUCH DAMAGE.
                     47: #
3.87      knu        48: # $FreeBSD$
3.82      knu        49: # $Id: cvsweb.cgi,v 1.112 2001/07/24 13:03:16 hzeller Exp $
3.85      knu        50: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 3.84 2001/10/07 20:50:10 knu Exp $
1.21      wosch      51: #
3.1       knu        52: ###
                     53:
3.204     scop       54: require 5.006;
3.55      knu        55:
3.1       knu        56: use strict;
1.21      wosch      57:
3.204     scop       58: use warnings;
                     59: use filetest qw(access);
                     60:
3.1       knu        61: use vars qw (
3.273     scop       62:   $VERSION $CheckoutMagic $MimeTypes $DEBUG
3.144     scop       63:   $config $allow_version_select
3.120     scop       64:   @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr
                     65:   %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
3.225     scop       66:   %DIFF_COMMANDS @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS
3.129     scop       67:   %alltags %fileinfo %tags @branchnames %nameprinted
3.120     scop       68:   %symrev %revsym @allrevisions %date %author @revdisplayorder
3.152     scop       69:   @revisions %state %difflines %log %branchpoint @revorder $keywordsubstitution
3.120     scop       70:   $prcgi @prcategories $re_prcategories $prkeyword $re_prkeyword $mancgi
3.222     scop       71:   $doCheckout $scriptname $scriptwhere
3.264     scop       72:   $where $Browser $nofilelinks $maycompress @stickyvars %funcline_regexp
3.120     scop       73:   $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
                     74:   %input $query $barequery $sortby $bydate $byrev $byauthor
                     75:   $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot
3.230     scop       76:   $charset $output_filter
                     77:   @command_path %CMD $allow_compress $backicon $diricon $fileicon $graphicon
3.264     scop       78:   $fullname $cvstreedefault $logo $defaulttitle $address $binfileicon
3.131     scop       79:   $long_intro $short_instruction $shortLogLen $show_author
3.129     scop       80:   $tablepadding $hr_breakable $showfunc $hr_ignwhite $hr_ignkeysubst
                     81:   $inputTextSize $mime_types $allow_annotate $allow_markup
3.120     scop       82:   $allow_log_extra $allow_dir_extra $allow_source_extra
3.218     scop       83:   $allow_cvsgraph $cvsgraph_config $use_java_script $edit_option_form
3.144     scop       84:   $show_subdir_lastmod $show_log_in_markup $preformat_in_markup
3.233     scop       85:   $tabstop $state $annTable $sel @ForbiddenFiles
                     86:   $use_descriptions %descriptions @mytz $dwhere
3.222     scop       87:   $use_moddate $gzip_open $file_list_len
3.120     scop       88:   $allow_tar @tar_options @gzip_options @zip_options @cvs_options
3.222     scop       89:   @annotate_options @rcsdiff_options
3.257     scop       90:   $HTML_DOCTYPE $HTML_META $cssurl $CSS $cvshistory_url
3.222     scop       91:   $allow_enscript @enscript_options %enscript_types
3.1       knu        92: );
                     93:
3.183     scop       94: use Cwd                   qw(abs_path cwd);
3.172     scop       95: use File::Basename        qw(dirname);
3.171     scop       96: use File::Path            qw(rmtree);
3.232     scop       97: use File::Spec::Functions qw(canonpath catdir catfile curdir devnull rootdir
                     98:                              tmpdir updir);
3.225     scop       99: use File::Temp            qw(tempdir tempfile);
3.229     scop      100: use IPC::Run              qw();
3.172     scop      101: use Time::Local           qw(timegm);
3.206     scop      102: use URI::Escape           qw(uri_escape uri_unescape);
3.122     scop      103:
3.222     scop      104: use constant VALID_PATH   => qr/^([[:^cntrl:]]+)$/o;
                    105: use constant VALID_TAG1   => qr/^([a-zA-Z][[:graph:]]*)$/o;
                    106: use constant VALID_TAG2   => qr/^([^\$,.:;@]+)$/o;
3.261     scop      107: use constant CVSWEBMARKUP => qr{^text/(x-cvsweb|vnd\.viewcvs)-markup$}io;
3.222     scop      108: use constant LOG_FILESEPR => qr/^={77}$/o;
                    109: use constant LOG_REVSEPR  => qr/^-{28}$/o;
                    110:
                    111: use constant HAS_ZLIB     => eval { require Compress::Zlib; };
                    112: use constant HAS_EDIFF    => eval { require String::Ediff;  };
3.194     scop      113:
3.122     scop      114: # -----------------------------------------------------------------------------
                    115:
                    116: # All global initialization that can be done in compile time should go to
                    117: # the BEGIN block.  Persistent environments, such as mod_perl, will benefit
                    118: # from this.
                    119:
                    120: BEGIN
                    121: {
3.280     scop      122:   $VERSION = '3.0.4';
3.122     scop      123:
                    124:   $HTML_DOCTYPE =
3.208     scop      125:     '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ' .
                    126:     '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
3.122     scop      127:
                    128:   $HTML_META = <<EOM;
3.208     scop      129: <meta name="robots" content="nofollow" />
                    130: <meta name="generator" content="FreeBSD-CVSweb $VERSION" />
                    131: <meta http-equiv="Content-Script-Type" content="text/javascript" />
                    132: <meta http-equiv="Content-Style-Type" content="text/css" />
3.122     scop      133: EOM
                    134:
3.156     scop      135:   # Use MIME::Types for MIME type lookups if it's available.
                    136:   eval {
                    137:     require MIME::Types;
3.223     scop      138:     $MimeTypes = MIME::Types->new(only_complete => 1);
3.156     scop      139:   };
                    140:   $MimeTypes = undef if $@;
                    141:
3.222     scop      142:   $CheckoutMagic = '~checkout~';
3.122     scop      143: }
                    144:
                    145: # -----------------------------------------------------------------------------
                    146:
3.12      knu       147: sub printDiffSelect($);
3.168     scop      148: sub printDiffSelectStickyVars();
3.225     scop      149: sub getDiffLinks($$$);
3.37      knu       150: sub printLogSortSelect($);
3.12      knu       151: sub findLastModifiedSubdirs(@);
3.36      knu       152: sub htmlify_sub(&$);
3.12      knu       153: sub htmlify($;$);
3.20      knu       154: sub spacedHtmlText($;$);
3.12      knu       155: sub link($$);
                    156: sub revcmp($$);
3.103     knu       157: sub fatal($$@);
3.269     scop      158: sub redirect($;$);
3.12      knu       159: sub safeglob($);
3.58      knu       160: sub search_path($);
3.219     scop      161: sub getEnscriptHL($);
3.156     scop      162: sub getMimeType($;$);
3.24      knu       163: sub head($;$);
                    164: sub scan_directives(@);
3.86      knu       165: sub openOutputFilter();
3.275     scop      166: sub doAnnotate($$);
                    167: sub doCheckout($$$);
3.240     scop      168: sub doEnscript($$$;$);
3.170     scop      169: sub doGraph();
                    170: sub doGraphView();
3.219     scop      171: sub cvswebMarkup($$$$$$;$);
3.12      knu       172: sub viewable($);
                    173: sub doDiff($$$$$$);
                    174: sub getDirLogs($$@);
                    175: sub readLog($;$);
3.219     scop      176: sub printLog($$$;$$);
3.12      knu       177: sub doLog($);
                    178: sub flush_diff_rows($$$$);
3.144     scop      179: sub human_readable_diff($$);
3.163     scop      180: sub navigateHeader($$$$$;$);
3.12      knu       181: sub plural_write($$);
                    182: sub readableTime($$);
                    183: sub clickablePath($$);
                    184: sub chooseCVSRoot();
                    185: sub chooseMirror();
                    186: sub fileSortCmp();
                    187: sub download_url($$;$);
                    188: sub download_link($$$;$);
3.219     scop      189: sub display_url($$;$);
                    190: sub display_link($$;$$);
3.170     scop      191: sub graph_link($;$);
3.258     scop      192: sub history_link($$;$);
3.140     scop      193: sub toggleQuery($;$);
3.35      knu       194: sub htmlquote($);
3.36      knu       195: sub htmlunquote($);
3.271     scop      196: sub uri_escape_path($);
3.163     scop      197: sub http_header(;$$);
                    198: sub html_header($;$);
3.12      knu       199: sub html_footer();
                    200: sub link_tags($);
3.233     scop      201: sub forbidden($);
3.191     scop      202: sub startproc(@);
3.215     scop      203: sub runproc(@);
3.225     scop      204: sub checkout_to_temp($$$);
3.12      knu       205:
3.1       knu       206: ##### Start of Configuration Area ########
3.122     scop      207:
3.142     scop      208: # Get rid of unsafe environment vars.  Don't do this in BEGIN...
                    209: delete(@ENV{qw(PATH IFS CDPATH ENV BASH_ENV)});
3.59      knu       210:
3.172     scop      211: my ($mydir) = (dirname($0) =~ /(.*)/);    # untaint
3.58      knu       212:
3.12      knu       213: # == EDIT this ==
3.28      knu       214: # Locations to search for user configuration, in order:
3.165     scop      215: for (catfile($mydir, 'cvsweb.conf'), '/usr/local/etc/cvsweb/cvsweb.conf') {
                    216:   if (-r $_) {
3.120     scop      217:     $config = $_;
                    218:     last;
                    219:   }
3.11      knu       220: }
3.122     scop      221: undef $mydir;
3.1       knu       222:
                    223: # == Configuration defaults ==
                    224: # Defaults for configuration variables that shouldn't need
                    225: # to be configured..
                    226: $allow_version_select = 1;
3.120     scop      227: $allow_log_extra      = 1;
3.1       knu       228:
                    229: ##### End of Configuration Area   ########
                    230:
                    231: ######## Configuration variables #########
                    232: # These are defined to allow checking with perl -cw
3.120     scop      233:
3.80      knu       234: @CVSrepositories = @CVSROOT = %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS =
3.225     scop      235:   %MTYPES = %tags = %alltags = %fileinfo = %DIFF_COMMANDS = ();
3.120     scop      236:
3.129     scop      237: $cvstreedefault = $logo = $defaulttitle =
3.120     scop      238:   $address = $long_intro = $short_instruction = $shortLogLen = $show_author =
3.131     scop      239:   $tablepadding = $hr_breakable = $showfunc = $hr_ignwhite =
3.129     scop      240:   $hr_ignkeysubst = $inputTextSize = $mime_types = $allow_annotate =
3.218     scop      241:   $allow_markup = $use_java_script = $edit_option_form =
3.144     scop      242:   $show_subdir_lastmod = $show_log_in_markup =
3.273     scop      243:   $tabstop = $use_moddate = $gzip_open = $DEBUG = undef;
3.32      knu       244:
3.37      knu       245: @DIFFTYPES = qw(h H u c s);
                    246: @DIFFTYPES{@DIFFTYPES} = (
3.120     scop      247:   {
                    248:     'descr'   => 'colored',
                    249:     'opts'    => ['-u'],
                    250:     'colored' => 1,
                    251:   },
                    252:   {
                    253:     'descr'   => 'long colored',
                    254:     'opts'    => ['--unified=15'],
                    255:     'colored' => 1,
                    256:   },
                    257:   {
                    258:     'descr'   => 'unified',
                    259:     'opts'    => ['-u'],
                    260:     'colored' => 0,
                    261:   },
                    262:   {
                    263:     'descr'   => 'context',
                    264:     'opts'    => ['-c'],
                    265:     'colored' => 0,
                    266:   },
                    267:   {
                    268:     'descr'   => 'side by side',
3.236     scop      269:     # width=168 should be enough to support 80 character line lengths
                    270:     'opts'    => ['--side-by-side', '--width=168'],
3.120     scop      271:     'colored' => 0,
                    272:   },
3.80      knu       273: );
3.37      knu       274:
                    275: @LOGSORTKEYS = qw(cvs date rev);
                    276: @LOGSORTKEYS{@LOGSORTKEYS} = (
3.254     scop      277:   { descr => 'Not sorted',  },
                    278:   { descr => 'Commit date', },
                    279:   { descr => 'Revision',    },
3.80      knu       280: );
3.37      knu       281:
3.1       knu       282: ##### End of configuration variables #####
                    283:
3.264     scop      284: my $pathinfo = '';
                    285: if (defined($ENV{PATH_INFO}) && $ENV{PATH_INFO} ne '') {
3.194     scop      286:   ($pathinfo) = ($ENV{PATH_INFO} =~ VALID_PATH)
                    287:     or fatal('500 Internal Error',
                    288:              'Illegal PATH_INFO in environment: <code>%s</code>',
                    289:              $ENV{PATH_INFO});
                    290: }
                    291: if ($ENV{SCRIPT_NAME}) {
                    292:   ($scriptname) = ($ENV{SCRIPT_NAME} =~ VALID_PATH)
                    293:     or fatal('500 Internal Error',
                    294:              'Illegal SCRIPT_NAME in environment: <code>%s</code>',
                    295:              $ENV{SCRIPT_NAME});
                    296: }
                    297:
                    298: $scriptname    = '' unless defined($scriptname);
                    299:
3.120     scop      300: $where         =  $pathinfo;
3.268     scop      301: $doCheckout    =  $where =~ s|^/$CheckoutMagic/|/|o;
3.120     scop      302: $where         =~ s|^/||;
                    303: $scriptname    =~ s|^/*|/|;
3.63      knu       304:
3.64      knu       305: # Let's workaround thttpd's stupidity..
3.63      knu       306: if ($scriptname =~ m|/$|) {
3.120     scop      307:   $pathinfo .= '/';
                    308:   my $re = quotemeta $pathinfo;
                    309:   $scriptname =~ s/$re$//;
3.63      knu       310: }
                    311:
3.271     scop      312: # $scriptname : the URI escaped path to this script
                    313: # $where      : the path in the CVS repository (without leading /, or only /)
                    314: # $scriptwhere: the URI escaped $scriptname + '/' + $where
                    315: $scriptname   = uri_escape_path($scriptname);
                    316: $scriptwhere  = join('/', $scriptname, uri_escape_path($where));
3.268     scop      317: $where        = '/' if ($where eq '');
3.3       knu       318:
3.188     scop      319: # In text-based browsers, it's very annoying to have two links per file;
                    320: # skip linking the image for them.
                    321:
3.120     scop      322: $Browser     = $ENV{HTTP_USER_AGENT} || '';
3.187     scop      323: $is_links    = ($Browser =~ m`^E?Links `);
3.80      knu       324: $is_lynx     = ($Browser =~ m`^Lynx/`i);
                    325: $is_w3m      = ($Browser =~ m`^w3m/`i);
                    326: $is_msie     = ($Browser =~ m`MSIE`);
3.5       knu       327: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
3.3       knu       328:
3.34      knu       329: $is_textbased = ($is_links || $is_lynx || $is_w3m);
3.5       knu       330:
                    331: $nofilelinks = $is_textbased;
3.1       knu       332:
                    333: # newer browsers accept gzip content encoding
                    334: # and state this in a header
                    335: # (netscape did always but didn't state it)
                    336: # It has been reported that these
                    337: #  braindamaged MS-Internet Exploders claim that they
                    338: # accept gzip .. but don't in fact and
                    339: # display garbage then :-/
3.23      knu       340: # Turn off gzip if running under mod_perl and no zlib is available,
                    341: # piping does not work as expected inside the server.
3.120     scop      342: $maycompress = (
                    343:   ((defined($ENV{HTTP_ACCEPT_ENCODING})
                    344:     && $ENV{HTTP_ACCEPT_ENCODING} =~ /gzip/)
                    345:    || $is_mozilla3)
                    346:   && !$is_msie
3.222     scop      347:   && !(defined($ENV{MOD_PERL}) && !HAS_ZLIB)
3.120     scop      348: );
3.1       knu       349:
3.194     scop      350: # Variables that will be sticky in all constructed links/query strings.
                    351: @stickyvars =
3.282     scop      352:   qw(cvsroot hideattic ignorecase sortby logsort f only_with_tag ln
                    353:      hidecvsroot hidenonreadable);
1.1       jfieber   354:
3.227     scop      355: #
                    356: # Load configuration.
                    357: #
3.1       knu       358: if (-f $config) {
3.120     scop      359:   do "$config"
                    360:     or fatal("500 Internal Error",
3.208     scop      361:              'Error in loading configuration file: %s<br /><br />%s<br />',
3.120     scop      362:              $config, $@);
3.27      knu       363: } else {
3.120     scop      364:   fatal("500 Internal Error",
                    365:         'Configuration not found.  Set the variable <code>$config</code> in cvsweb.cgi to your <b>cvsweb.conf</b> configuration file first.');
3.1       knu       366: }
                    367:
3.183     scop      368: # Try to find a readable dir where we can cd into.  Some abs_path()
                    369: # implementations as well as various cvs operations require such a dir to
                    370: # work properly.
                    371: {
                    372:   local $^W = 0;
3.190     scop      373:   if (!-r cwd()) {
                    374:     for my $dir (tmpdir(), rootdir()) {
                    375:       last if (-r $dir && chdir($dir));
                    376:     }
3.183     scop      377:   }
                    378: }
                    379:
3.144     scop      380: $CSS = $cssurl ?
3.208     scop      381:   sprintf("<link rel=\"stylesheet\" type=\"text/css\" href=\"%s\" />\n",
3.144     scop      382:           htmlquote($cssurl)) : '';
                    383:
3.194     scop      384: # --- input parameters
                    385:
3.202     scop      386: my %query = ();
                    387: if (defined($ENV{QUERY_STRING})) {
                    388:   for my $p (split(/[;&]+/, $ENV{QUERY_STRING})) {
                    389:     next unless $p;
                    390:     $p =~ y/+/ /;
                    391:     my ($key, $val) = split(/=/, $p, 2);
                    392:     next unless defined($key);
                    393:     $val = 1 unless defined($val);
3.222     scop      394:     ($key = uri_unescape($key)) =~ /[[:graph:]]/ or next;
                    395:     ($val = uri_unescape($val)) =~ /[[:graph:]]/ or next;
3.202     scop      396:     $query{$key} = $val;
                    397:   }
                    398: }
                    399:
3.1       knu       400: undef %input;
1.10      wosch     401:
3.194     scop      402: my $t;
                    403: for my $p (qw(graph hideattic hidecvsroot hidenonreadable ignorecase ln copt
                    404:               makeimage options tarball)) {
3.202     scop      405:   $t = $query{$p};
                    406:   if (defined($t)) {
3.222     scop      407:     ($input{$p}) = ($t =~ /^([01]|on)$/)
3.194     scop      408:       or fatal('500 Internal Error',
                    409:                'Invalid boolean value: <code>%s=%s</code>', $p, $t);
                    410:   }
                    411: }
                    412: for my $p (qw(annotate r1 r2 rev tr1 tr2)) {
3.202     scop      413:   $t = $query{$p};
                    414:   if (defined($t)) {
3.207     scop      415:     if (($p eq 'r1' || $p eq 'r2') && $t eq 'text') {
                    416:       # Special case for the "Use text field" option in the log view diff form.
                    417:       $input{$p} = $t;
                    418:       next;
3.275     scop      419:     } elsif (($p eq 'rev' || $p eq 'annotate') && ($t eq '.' || $t eq 'HEAD')){
3.253     scop      420:       # Another special case, allow linking to latest revision using these.
                    421:       $input{$p} = '.';
                    422:       next;
3.207     scop      423:     }
3.194     scop      424:     my ($rev, $tag) = split(/:/, $t, 2);
3.251     scop      425:     ($input{$p}) = ($rev =~ /^(\d+(?:\.\d+)*)$/)
3.194     scop      426:       or fatal('500 Internal Error',
                    427:                'Invalid revision: <code>%s=%s</code>', $p, $t);
                    428:     if (defined($tag)) {
                    429:       ($tag) = ($tag =~ VALID_TAG1)
                    430:         or fatal('500 Internal Error',
3.254     scop      431:                  'Invalid tag/branch name in revision: <code>%s=%s</code>',
                    432:                  $p, $t);
3.194     scop      433:       ($tag) = ($tag =~ VALID_TAG2)
                    434:         or fatal('500 Internal Error',
3.254     scop      435:                  'Invalid tag/branch name in revision: <code>%s=%s</code>',
                    436:                  $p, $t);
3.207     scop      437:       $input{$p} .= ':' . $tag;
3.194     scop      438:     }
                    439:   }
                    440: }
3.202     scop      441: $t = defined($query{only_with_tag}) ?
                    442:   $query{only_with_tag} : $query{only_on_branch}; # Backwards compatibility.
                    443: if (defined($t)) {
3.211     scop      444:   ($input{only_with_tag}) = ($t =~ VALID_TAG1)
3.194     scop      445:     or fatal('500 Internal Error',
                    446:              'Invalid tag/branch name: <code>%s</code>', $t);
3.211     scop      447:   ($input{only_with_tag}) = ($t =~ VALID_TAG2)
3.194     scop      448:     or fatal('500 Internal Error',
                    449:              'Invalid tag/branch name: <code>%s</code>', $t);
                    450: }
3.202     scop      451: $t = $query{logsort};
                    452: if (defined($t)) {
3.222     scop      453:   ($input{logsort}) = ($t =~ /^(cvs|date|rev)$/)
3.194     scop      454:     or fatal('500 Internal Error',
                    455:              'Unsupported log sort key: <code>%s</code>', $t);
                    456: }
3.202     scop      457: $t = $query{f};
                    458: if (defined($t)) {
3.225     scop      459:   ($input{f}) = ($t =~ /^(([hH]|[ucs]c?)|ext\d*)$/)
3.194     scop      460:     or fatal('500 Internal Error',
                    461:              'Unsupported diff format: <code>%s</code>', $t);
                    462: }
3.202     scop      463: $t = $query{sortby};
                    464: if (defined($t)) {
3.222     scop      465:   ($input{sortby}) = ($t =~ /^(file|date|rev|author|log)$/)
3.194     scop      466:     or fatal('500 Internal Error',
                    467:              'Unsupported dir sort key: <code>%s</code>', $t);
                    468: }
3.202     scop      469: $t = $query{'content-type'};
                    470: if (defined($t)) {
3.261     scop      471:   ($input{'content-type'}) = ($t =~ m|^([-0-9A-Za-z]+/[-0-9A-Za-z\.]+)$|)
3.194     scop      472:     or fatal('500 Internal Error',
                    473:              'Unsupported content type: <code>%s</code>', $t);
                    474: }
3.202     scop      475: $t = $query{cvsroot};
                    476: if (defined($t)) {
3.222     scop      477:   ($input{cvsroot}) = ($t =~ /^([[:print:]]+)$/)
3.194     scop      478:     or fatal('500 Internal Error',
                    479:              'Invalid symbolic CVS root name: <code>%s</code>', $t);
                    480: }
3.202     scop      481: $t = $query{path};
                    482: if (defined($t)) {
3.194     scop      483:   ($input{path}) = ($t =~ VALID_PATH)
                    484:     or fatal('500 Internal Error',
                    485:              'Invalid path: <code>%s</code>', $t);
3.97      knu       486: }
3.194     scop      487: undef($t);
3.205     scop      488: undef(%query);
3.97      knu       489:
3.194     scop      490: # --- end input parameters
1.10      wosch     491:
3.158     scop      492: #
                    493: # CVS roots
                    494: #
                    495: my $rootfound = 0;
                    496: for (my $i = 0; $i < scalar(@CVSrepositories); $i += 2) {
                    497:   my $key = $CVSrepositories[$i];
3.232     scop      498:   my ($descr, $root) = @{$CVSrepositories[$i+1]};
                    499:   $root = canonpath($root);
                    500:   unless (-d $root) {
                    501:     warn("Root '$root' defined in \@CVSrepositories is not a directory, " .
3.158     scop      502:          'entry ignored');
                    503:     next;
                    504:   }
                    505:   $rootfound ||= 1;
                    506:   $cvstreedefault = $key unless defined($cvstreedefault);
                    507:   $CVSROOTdescr{$key} = $descr;
3.232     scop      508:   $CVSROOT{$key} = $root;
3.158     scop      509:   push(@CVSROOT, $key);
                    510: }
                    511: unless ($rootfound) {
                    512:   fatal('500 Internal Error',
                    513:         'No valid CVS roots found!  See <code>@CVSrepositories</code> in ' .
3.221     scop      514:         'the configuration file (<code>%s</code>).',
3.158     scop      515:         $config);
                    516: }
                    517: undef $rootfound;
                    518:
                    519: #
                    520: # Default CVS root
                    521: #
                    522: if (!defined($CVSROOT{$cvstreedefault})) {
                    523:   fatal("500 Internal Error",
                    524:         '<code>$cvstreedefault</code> points to a repository (%s) not ' .
                    525:         'defined in <code>@CVSrepositories</code> in your configuration ' .
                    526:         'file (<code>%s</code>).',
                    527:         $cvstreedefault,
                    528:         $config);
                    529: }
                    530:
3.254     scop      531: $DEFAULTVALUE{cvsroot} = $cvstreedefault;
1.10      wosch     532:
3.120     scop      533: while (my ($key, $defval) = each %DEFAULTVALUE) {
3.80      knu       534:
3.120     scop      535:   # Replace not given parameters with defaults.
3.194     scop      536:   next unless (defined($defval) && $defval =~ /\S/ && !defined($input{$key}));
3.120     scop      537:
                    538:   # Empty checkboxes in forms return nothing, so we define a helper variable
                    539:   # in these forms (copt) which indicates that we just set parameters with a
                    540:   # checkbox.
3.194     scop      541:   if ($input{copt}) {
3.120     scop      542:
3.194     scop      543:     # 'copt' is set -> the result of empty input checkbox
3.120     scop      544:     # -> set to zero (disable) if default is a boolean (0|1).
                    545:     $input{$key} = 0 if ($defval eq '0' || $defval eq '1');
                    546:
                    547:   } else {
                    548:
3.194     scop      549:     # 'copt' isn't set --> empty input is not the result
3.120     scop      550:     # of empty input checkbox --> set default.
                    551:     $input{$key} = $defval;
                    552:   }
1.10      wosch     553: }
3.12      knu       554:
3.1       knu       555: $barequery = "";
3.31      knu       556: my @barequery;
3.1       knu       557: foreach (@stickyvars) {
3.80      knu       558:
3.120     scop      559:   # construct a query string with the sticky non default parameters set
                    560:   if (defined($input{$_})
                    561:       && !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_}))
                    562:   {
3.206     scop      563:     push(@barequery, join('=', uri_escape($_), uri_escape($input{$_})));
3.120     scop      564:   }
3.1       knu       565: }
3.80      knu       566:
3.168     scop      567: if ($allow_enscript) {
                    568:   push(@DIFFTYPES, qw(uc cc sc));
                    569:   @DIFFTYPES{qw(uc cc sc)} = (
                    570:     {
                    571:      'descr'   => 'unified, colored',
                    572:      'opts'    => ['-u'],
                    573:      'colored' => 0,
                    574:     },
                    575:     {
                    576:      'descr'   => 'context, colored',
                    577:      'opts'    => ['-c'],
                    578:      'colored' => 0,
                    579:     },
                    580:     {
                    581:      'descr'   => 'side by side, colored',
3.238     scop      582:      # width=168 should be enough to support 80 character line lengths
                    583:      'opts'    => ['--side-by-side', '--width=168'],
3.168     scop      584:      'colored' => 0,
                    585:     },
                    586:   );
                    587: } else {
                    588:   # No Enscript -> respect difftype, but don't offer colorization.
                    589:   if ($input{f} && $input{f} =~ /^([ucs])c$/) {
                    590:     $input{f} = $1;
                    591:   }
                    592: }
                    593:
3.1       knu       594: # is there any query ?
3.31      knu       595: if (@barequery) {
3.203     scop      596:   $barequery = join (';', @barequery);
3.120     scop      597:   $query     = "?$barequery";
3.203     scop      598:   $barequery = ";$barequery";
3.80      knu       599: } else {
3.120     scop      600:   $query = "";
3.1       knu       601: }
3.31      knu       602: undef @barequery;
3.1       knu       603:
3.254     scop      604: if (defined($input{path})) {
3.120     scop      605:   redirect("$scriptname/$input{path}$query");
3.57      knu       606: }
                    607:
3.1       knu       608: # get actual parameters
3.144     scop      609: {
                    610:   my $sortby = $input{sortby} || 'file';
                    611:   $bydate    = 0;
                    612:   $byrev     = 0;
                    613:   $byauthor  = 0;
                    614:   $bylog     = 0;
                    615:   $byfile    = 0;
                    616:   if ($sortby eq 'date') {
                    617:     $bydate = 1;
                    618:   } elsif ($sortby eq 'rev') {
                    619:     $byrev = 1;
                    620:   } elsif ($sortby eq 'author') {
                    621:     $byauthor = 1;
                    622:   } elsif ($sortby eq 'log') {
                    623:     $bylog = 1;
                    624:   } else {
                    625:     $byfile = 1;
                    626:   }
3.1       knu       627: }
                    628:
3.254     scop      629: $defaultDiffType = $input{f};
3.1       knu       630:
3.254     scop      631: $logsort = $input{logsort};
3.1       knu       632:
                    633: # alternate CVS-Tree, configured in cvsweb.conf
3.254     scop      634: if ($input{cvsroot} && $CVSROOT{$input{cvsroot}}) {
                    635:   $cvstree = $input{cvsroot};
3.1       knu       636: } else {
3.120     scop      637:   $cvstree = $cvstreedefault;
1.10      wosch     638: }
                    639:
3.1       knu       640: $cvsroot = $CVSROOT{$cvstree};
1.10      wosch     641:
3.1       knu       642: # create icons out of description
3.120     scop      643: foreach my $k (keys %ICONS) {
                    644:   my ($itxt, $ipath, $iwidth, $iheight) = @{$ICONS{$k}};
                    645:   no strict 'refs';
                    646:   if ($ipath) {
                    647:     ${"${k}icon"} =
3.208     scop      648:       sprintf('<img src="%s" alt="%s" border="0" width="%d" height="%d" />',
3.271     scop      649:               htmlquote($ipath), htmlquote($itxt), $iwidth, $iheight);
3.120     scop      650:   } else {
                    651:     ${"${k}icon"} = $itxt;
                    652:   }
1.24      wosch     653: }
                    654:
3.27      knu       655: my $config_cvstree = "$config-$cvstree";
                    656:
3.1       knu       657: # Do some special configuration for cvstrees
3.27      knu       658: if (-f $config_cvstree) {
3.120     scop      659:   do "$config_cvstree"
                    660:     or fatal("500 Internal Error",
3.208     scop      661:              'Error in loading configuration file: %s<br /><br />%s<br />',
3.120     scop      662:              $config_cvstree, $@);
3.27      knu       663: }
3.31      knu       664: undef $config_cvstree;
3.1       knu       665:
3.120     scop      666: $re_prcategories  = '(?:' . join ('|', @prcategories) . ')' if @prcategories;
                    667: $re_prkeyword     = quotemeta($prkeyword) if defined($prkeyword);
                    668: $prcgi           .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.24      wosch     669:
3.233     scop      670: $fullname         = catfile($cvsroot, $where);
3.1       knu       671:
3.63      knu       672: my $rewrite = 0;
                    673: if ($pathinfo =~ m|//|) {
3.120     scop      674:   $pathinfo =~ y|/|/|s;
                    675:   $rewrite = 1;
3.63      knu       676: }
3.120     scop      677: if (-d $fullname) {
                    678:   if ($pathinfo !~ m|/$|) {
                    679:     $pathinfo .= '/';
                    680:     $rewrite   = 1;
                    681:   }
3.268     scop      682: } elsif ($pathinfo =~ m|/$|) {
                    683:   chop $pathinfo;
                    684:   $rewrite = 1;
3.63      knu       685: }
                    686: if ($rewrite) {
3.271     scop      687:   redirect($scriptname . uri_escape_path($pathinfo) . $query, 1);
3.1       knu       688: }
3.268     scop      689: undef $rewrite;
3.1       knu       690:
3.264     scop      691: undef $pathinfo;
3.63      knu       692:
3.1       knu       693: if (!-d $cvsroot) {
3.120     scop      694:   fatal("500 Internal Error",
                    695:         '$CVSROOT not found!<p>The server on which the CVS tree lives is probably down.  Please try again in a few minutes.');
3.1       knu       696: }
                    697:
                    698: #
3.233     scop      699: # Short-circuit forbidden things.  Note that $fullname should not change
                    700: # after this, because the rest of the code assumes this check has already
                    701: # been done.
3.1       knu       702: #
3.233     scop      703: fatal('403 Forbidden', 'Access to %s forbidden.', $where)
                    704:   if forbidden($fullname);
3.46      knu       705:
                    706: #
                    707: # Handle tarball downloads before any headers are output.
                    708: #
                    709: if ($input{tarball}) {
3.120     scop      710:   fatal('403 Forbidden', 'Downloading tarballs is prohibited.')
                    711:     unless $allow_tar;
3.191     scop      712:
3.120     scop      713:   my ($module)  =  ($where =~ m,^/?(.*),);    # untaint
                    714:   $module       =~ s,/([^/]*)$,,;
3.191     scop      715:   my ($ext)     =  ($1 =~ /(\.t(?:ar\.)?gz|\.zip)$/);
3.120     scop      716:   my ($basedir) =  ($module =~ m,([^/]+)$,);
                    717:
                    718:   if ($basedir eq '' || $module eq '') {
                    719:     fatal('500 Internal Error',
                    720:           'You cannot download the top level directory.');
                    721:   }
                    722:
3.191     scop      723:   my $istar = ($ext eq '.tar.gz' || $ext eq '.tgz');
                    724:   if ($istar) {
                    725:     fatal('500 Internal Error', 'tar command not found.') unless $CMD{tar};
                    726:     fatal('500 Internal Error', 'gzip command not found.') unless $CMD{gzip};
                    727:   }
                    728:   my $iszip = ($ext eq '.zip');
                    729:   if ($iszip && !$CMD{zip}) {
                    730:     fatal('500 Internal Error', 'zip command not found.');
                    731:   }
3.215     scop      732:   if (!$istar && !$iszip) {
                    733:     fatal('500 Internal Error', 'Unsupported archive type.');
                    734:   }
3.191     scop      735:
3.138     scop      736:   my $tmpexportdir;
                    737:   eval {
                    738:     local $SIG{__DIE__};
3.171     scop      739:     # Don't use the CLEANUP argument to tempdir() here, since we might be under
                    740:     # mod_perl (the process runs for a long time), unlink explicitly later.
                    741:     $tmpexportdir = tempdir('.cvsweb.XXXXXXXX', TMPDIR => 1);
3.138     scop      742:   };
                    743:   if ($@) {
                    744:     fatal('500 Internal Error', 'Unable to make temporary directory: %s', $@);
                    745:   }
3.191     scop      746:   if (!chdir($tmpexportdir)) {
                    747:     fatal('500 Internal Error',
                    748:           "Can't cd to temporary directory %s: %s", $tmpexportdir, $!);
                    749:   }
3.120     scop      750:
                    751:   my @fatal;
3.194     scop      752:   my $tag = $input{only_with_tag} || 'HEAD';
                    753:   $tag = 'HEAD' if ($tag eq 'MAIN');
3.120     scop      754:
3.215     scop      755:   my @cmd =
3.241     scop      756:     ($CMD{cvs}, @cvs_options, '-Qd', $cvsroot, 'export', '-r', $tag,
                    757:      '-d', $basedir, $module);
3.215     scop      758:   my $export_err;
                    759:   my ($errcode, $err) = runproc(\@cmd, '2>', \$export_err);
                    760:   if ($errcode) {
                    761:     @fatal =
                    762:       ('500 Internal Error',
                    763:        'Export failure (exit status %s), output: <pre>%s</pre>',
                    764:        $errcode, $err || $export_err);
3.191     scop      765:
3.215     scop      766:   } else {
3.191     scop      767:
3.120     scop      768:     $| = 1;    # Essential to get the buffering right.
3.191     scop      769:     local (*TAR_OUT);
3.120     scop      770:
3.191     scop      771:     my (@cmd, $ctype);
                    772:     if ($istar) {
                    773:       my @tar = ($CMD{tar}, @tar_options, '-cf', '-', $basedir);
                    774:       my @gzip = ($CMD{gzip}, @gzip_options, '-c');
                    775:       push(@cmd, \@tar, '|', \@gzip);
                    776:       $ctype = 'application/x-gzip';
                    777:     } elsif ($iszip) {
                    778:       my @zip = ($CMD{zip}, @zip_options, '-r', '-', $basedir);
                    779:       push(@cmd, \@zip, \'');
                    780:       $ctype = 'application/zip';
                    781:     }
3.229     scop      782:     push(@cmd, '>pipe', \*TAR_OUT);
3.191     scop      783:
                    784:     my ($h, $err) = startproc(@cmd);
                    785:     if ($h) {
                    786:       print "Content-Type: $ctype\r\n\r\n";
                    787:       local $/ = undef;
                    788:       print <TAR_OUT>;
3.229     scop      789:       $h->finish();
3.120     scop      790:     } else {
3.215     scop      791:       @fatal = ('500 Internal Error',
                    792:                 '%s failure (exit status %s), output: <pre>%s</pre>',
                    793:                 $istar ? 'Tar' : 'Zip', $? >> 8 || -1, $err);
3.120     scop      794:     }
                    795:   }
3.46      knu       796:
3.171     scop      797:   # Clean up.
                    798:   rmtree($tmpexportdir);
3.46      knu       799:
3.120     scop      800:   &fatal(@fatal) if @fatal;
3.46      knu       801:
3.120     scop      802:   exit;
3.46      knu       803: }
                    804:
3.1       knu       805: ##############################
                    806: # View a directory
                    807: ###############################
3.46      knu       808: if (-d $fullname) {
3.233     scop      809:
3.120     scop      810:   my $dh = do { local (*DH); };
                    811:   opendir($dh, $fullname) or fatal("404 Not Found", '%s: %s', $where, $!);
3.233     scop      812:   my @dir = grep(!forbidden(catfile($fullname, $_)), readdir($dh));
3.120     scop      813:   closedir($dh);
                    814:   my @subLevelFiles = findLastModifiedSubdirs(@dir)
                    815:     if ($show_subdir_lastmod);
3.150     scop      816:   my @unreadable = getDirLogs($cvsroot, $where, @subLevelFiles);
3.120     scop      817:
                    818:   if ($where eq '/') {
                    819:     html_header($defaulttitle);
                    820:     $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
                    821:     print $long_intro;
                    822:   } else {
                    823:     html_header($where);
3.212     scop      824:     my $html = (-f catfile($fullname, 'README.cvs.html,v') ||
                    825:                 -f catfile($fullname, 'Attic', 'README.cvs.html,v'));
                    826:     my $text = (!$html &&
                    827:                 (-f catfile($fullname, 'README.cvs,v') ||
                    828:                  -f catfile($fullname, 'Attic', 'README.cvs,v')));
                    829:     if ($html || $text) {
                    830:       my $rev = $input{only_with_tag} || 'HEAD';
                    831:       my $cr = abs_path($cvsroot) || $cvsroot;
                    832:       my $co = "$where/README.cvs.html" if $html;
                    833:       $co ||= "$where/README.cvs" if $text;
                    834:       # abs_path() taints when run as a CGI...
                    835:       if ($cr =~ VALID_PATH) {
                    836:         $cr = $1;
                    837:       } else {
                    838:         fatal('500 Internal Error', 'Illegal CVS root: <code>%s</code>', $cr);
                    839:       }
                    840:       my @cmd = ($CMD{cvs}, @cvs_options, '-d', $cr, 'co', '-p', "-r$rev",$co);
                    841:       local (*CVS_OUT, *CVS_ERR);
                    842:       my ($h, $err) = startproc(\@cmd, \"", '>pipe', \*CVS_OUT,
3.229     scop      843:                                 '2>pipe', \*CVS_ERR);
3.212     scop      844:       fatal('500 Internal Error', $err) unless $h;
                    845:       if ($html) {
                    846:         local $/ = undef;
                    847:         print <CVS_OUT>;
                    848:       } else {
                    849:         print "<p>\n";
                    850:         while (<CVS_OUT>) {
                    851:           chomp;
                    852:           print htmlquote($_), '<br />';
                    853:         }
                    854:         print "</p>";
                    855:       }
3.229     scop      856:       $h->finish();
3.212     scop      857:     }
3.120     scop      858:     print $short_instruction;
                    859:   }
                    860:
3.165     scop      861:   if ($use_descriptions &&
3.268     scop      862:       open(DESC, catfile($cvsroot, 'CVSROOT', 'descriptions'))) {
3.120     scop      863:     while (<DESC>) {
                    864:       chomp;
                    865:       my ($dir, $description) = /(\S+)\s+(.*)/;
                    866:       $descriptions{$dir} = $description;
                    867:     }
                    868:     close(DESC);
                    869:   }
                    870:
                    871:   print "<p><a name=\"dirlist\"></a></p>\n";
                    872:
                    873:   # give direct access to dirs
                    874:   if ($where eq '/') {
                    875:     chooseMirror();
                    876:     chooseCVSRoot();
3.268     scop      877:
3.120     scop      878:   } else {
3.257     scop      879:     print '<p>Current directory: <b>', clickablePath($where, 0), '</b>';
                    880:     if ($cvshistory_url) {
                    881:       (my $d = $where) =~ s|^/*(.*?)/*$|$1|;
3.258     scop      882:       print ' - ', history_link($d, '');
3.257     scop      883:     }
                    884:     print "</p>\n";
3.153     scop      885:     print "<p>Current tag: <b>", htmlquote($input{only_with_tag}), "</b></p>\n"
3.120     scop      886:       if $input{only_with_tag};
                    887:   }
                    888:
3.208     scop      889:   print "<hr />\n";
3.120     scop      890:
3.179     scop      891:   my $infocols = 1;
3.131     scop      892:
3.265     scop      893:   printf(<<EOF, 'Directory index of ' . htmlquote($where));
3.182     scop      894: <table class="dir" width="100%%" cellspacing="0" cellpadding="$tablepadding" summary="%s">
3.179     scop      895: <tr>
                    896: EOF
3.199     scop      897:   printf('<th colspan="2"%s>', ($byfile ? ' class="sorted"' : ''));
3.131     scop      898:
                    899:   if ($byfile) {
                    900:     print 'File';
                    901:   } else {
                    902:     print &link('File',
                    903:                 sprintf('./%s#dirlist', toggleQuery('sortby', 'file')));
                    904:   }
                    905:   print "</th>\n";
3.120     scop      906:
3.131     scop      907:   # Do not display the other column headers if we do not have any files
                    908:   # with revision information.
                    909:   if (scalar(%fileinfo)) {
3.120     scop      910:     $infocols++;
3.199     scop      911:     printf('<th%s>', ($byrev ? ' class="sorted"' : ''));
3.120     scop      912:
3.131     scop      913:     if ($byrev) {
                    914:       print 'Rev.';
3.120     scop      915:     } else {
3.131     scop      916:       print &link('Rev.',
                    917:                   sprintf('./%s#dirlist', toggleQuery('sortby', 'rev')));
3.120     scop      918:     }
                    919:     print "</th>\n";
3.131     scop      920:     $infocols++;
3.199     scop      921:     printf('<th%s>', ($bydate ? ' class="sorted"' : ''));
3.120     scop      922:
3.131     scop      923:     if ($bydate) {
                    924:       print 'Age';
                    925:     } else {
                    926:       print &link('Age',
                    927:                   sprintf('./%s#dirlist', toggleQuery('sortby', 'date')));
                    928:     }
                    929:     print "</th>\n";
3.120     scop      930:
3.131     scop      931:     if ($show_author) {
3.120     scop      932:       $infocols++;
3.199     scop      933:       printf('<th%s>', ($byauthor ? ' class="sorted"' : ''));
3.120     scop      934:
3.131     scop      935:       if ($byauthor) {
                    936:         print 'Author';
3.120     scop      937:       } else {
3.131     scop      938:         print
                    939:           &link('Author',
                    940:                 sprintf('./%s#dirlist', toggleQuery('sortby', 'author')));
3.120     scop      941:       }
                    942:       print "</th>\n";
3.131     scop      943:     }
                    944:     $infocols++;
3.199     scop      945:     printf('<th%s>', ($bylog ? ' class="sorted"' : ''));
3.120     scop      946:
3.131     scop      947:     if ($bylog) {
                    948:       print 'Last log entry';
                    949:     } else {
                    950:       print &link('Last log entry',
                    951:                   sprintf('./%s#dirlist', toggleQuery('sortby', 'log')));
3.120     scop      952:     }
3.131     scop      953:     print "</th>\n";
                    954:   } elsif ($use_descriptions) {
3.199     scop      955:     print "<th>Description</th>\n";
3.131     scop      956:     $infocols++;
3.120     scop      957:   }
3.131     scop      958:   print "</tr>\n";
                    959:
3.120     scop      960:   my $dirrow = 0;
                    961:
                    962:   my $i;
                    963:   lookingforattic:
                    964:   for ($i = 0; $i <= $#dir; $i++) {
                    965:     if ($dir[$i] eq "Attic") {
                    966:       last lookingforattic;
                    967:     }
                    968:   }
                    969:
3.254     scop      970:   if (!$input{hideattic}
3.120     scop      971:       && ($i <= $#dir)
                    972:       && opendir($dh, $fullname . '/Attic'))
                    973:   {
                    974:     splice(@dir, $i, 1, grep((s|^|Attic/|, !m|/\.|), readdir($dh)));
                    975:     closedir($dh);
                    976:   }
                    977:
                    978:   my $hideAtticToggleLink =
3.254     scop      979:     $input{hideattic}
3.120     scop      980:     ? ''
3.239     scop      981:     : &link('[hide]', sprintf('./%s#dirlist', &toggleQuery('hideattic')));
3.120     scop      982:
                    983:   # Sort without the Attic/ pathname.
                    984:   # place directories first
                    985:
                    986:   my $filesexists;
                    987:   my $filesfound;
                    988:
                    989:   foreach my $file (sort { &fileSortCmp } @dir) {
                    990:
3.196     scop      991:     next if ($file eq curdir());
3.120     scop      992:
                    993:     # ignore CVS lock and stale NFS files
                    994:     next if ($file =~ /^\#cvs\.|^,|^\.nfs/); # \# for XEmacs cperl-mode...
                    995:
                    996:     # Check whether to show the CVSROOT path
3.254     scop      997:     next if ($input{hidecvsroot} && $where eq '/' && $file eq 'CVSROOT');
3.120     scop      998:
3.150     scop      999:     # Is it a directory?
3.232     scop     1000:     my $isdir = -d catdir($fullname, $file);
3.150     scop     1001:
                   1002:     # Ignore non-readable files and directories?
3.254     scop     1003:     next if ($input{hidenonreadable} && (! -r _ || ($isdir && ! -x _)));
3.120     scop     1004:
3.268     scop     1005:     my $attic = '';
3.120     scop     1006:     if ($file =~ s|^Attic/||) {
3.239     scop     1007:       $attic = ' <span class="attic">(in the Attic) ' .
                   1008:         $hideAtticToggleLink . '</span>';
3.120     scop     1009:     }
                   1010:
3.196     scop     1011:     if ($file eq updir() || $isdir) {
                   1012:       next if ($file eq updir() && $where eq '/');
3.152     scop     1013:       my ($rev, $date, $log, $author, $filename, $keywordsubst) =
                   1014:         @{$fileinfo{$file}} if (defined($fileinfo{$file}));
3.239     scop     1015:       printf "<tr class=\"%s\">\n<td class=\"dir\" colspan=\"2\">",
3.132     scop     1016:         ($dirrow % 2) ? 'even' : 'odd';
3.120     scop     1017:
3.196     scop     1018:       if ($file eq updir()) {
3.268     scop     1019:         my $url = "../$query";
3.261     scop     1020:         print $nofilelinks ? $backicon : &link($backicon, $url);
3.120     scop     1021:         print '&nbsp;', &link("Parent Directory", $url);
3.261     scop     1022:
3.120     scop     1023:       } else {
3.271     scop     1024:         my $url = './' . uri_escape_path($file) . "/$query";
                   1025:         print '<a name="', htmlquote($file), '"></a>';
3.261     scop     1026:         print $nofilelinks ? $diricon : &link($diricon, $url);
3.136     scop     1027:         print '&nbsp;', &link(htmlquote("$file/"), $url), $attic;
3.120     scop     1028:         if ($file eq "Attic") {
3.239     scop     1029:           print ' <span class="attic">',
                   1030:             &link('[show]',
                   1031:                   sprintf('./%s#dirlist', &toggleQuery('hideattic'))),
                   1032:                     '</span>';
3.120     scop     1033:         }
                   1034:       }
                   1035:
                   1036:       # Show last change in dir
                   1037:       if ($filename) {
3.199     scop     1038:         print "</td>\n<td>&nbsp;</td>\n<td class=\"age\">";
                   1039:         print readableTime(time() - $date, 0) if $date;
                   1040:         print "</td>\n<td class=\"author\">", htmlquote($author)
                   1041:           if $show_author;
                   1042:         print "</td>\n<td class=\"log\">";
3.120     scop     1043:         $filename =~ s%^[^/]+/%%;
3.199     scop     1044:         print &link(htmlquote("$filename/$rev"),
                   1045:                     sprintf('%s/%s%s#rev%s',
3.206     scop     1046:                             uri_escape($file), uri_escape($filename),
3.208     scop     1047:                             $query, $rev)), '<br />';
3.120     scop     1048:         if ($log) {
3.199     scop     1049:           print htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
3.120     scop     1050:           print '...' if (length($log) > 80);
                   1051:         }
3.199     scop     1052:
3.120     scop     1053:       } else {
                   1054:         my $dwhere = ($where ne '/' ? $where : '') . $file;
                   1055:
                   1056:         if ($use_descriptions && defined $descriptions{$dwhere}) {
3.199     scop     1057:           print '<td colspan="', ($infocols - 1), '">';
3.120     scop     1058:           print $descriptions{$dwhere};
                   1059:
3.131     scop     1060:         } elsif ($infocols > 1) {
3.120     scop     1061:
                   1062:           # close the row with the appropriate number of
                   1063:           # columns, so that the vertical seperators are visible
                   1064:           my ($cols) = $infocols;
                   1065:           while ($cols > 1) {
                   1066:             print "</td>\n<td>&nbsp;";
                   1067:             $cols--;
                   1068:           }
                   1069:         }
                   1070:       }
                   1071:
3.131     scop     1072:       print "</td>\n</tr>\n";
3.120     scop     1073:       $dirrow++;
3.131     scop     1074:
3.120     scop     1075:     } elsif ($file =~ s/,v$//) {
                   1076:
3.271     scop     1077:       my $fileurl = ($attic ? 'Attic/' : '') . uri_escape_path($file);
3.268     scop     1078:       my $url     = './' . $fileurl . $query;
3.120     scop     1079:       $filesexists++;
                   1080:       next if (!defined($fileinfo{$file}));
3.152     scop     1081:       my ($rev, $date, $log, $author, $filename, $keywordsubst) =
                   1082:         @{$fileinfo{$file}};
3.156     scop     1083:       my $isbinary = $keywordsubst eq 'b' ? 1 : 0;
3.120     scop     1084:       $filesfound++;
3.156     scop     1085:
3.199     scop     1086:       printf "<tr class=\"%s\">\n", ($dirrow % 2) ? 'even' : 'odd';
3.239     scop     1087:       printf '<td class="file"%s>', $allow_cvsgraph ? '' : ' colspan="2"';
3.120     scop     1088:
3.156     scop     1089:       my $icon = $isbinary ? $binfileicon : $fileicon;
3.261     scop     1090:       print $nofilelinks ? $icon : &link($icon, $url);
3.120     scop     1091:       print '&nbsp;', &link(htmlquote($file), $url), $attic;
3.199     scop     1092:       print '</td><td class="graph">', graph_link($fileurl) if $allow_cvsgraph;
3.219     scop     1093:       print "</td>\n<td width=\"30\">", display_link($fileurl, $rev);
3.199     scop     1094:       print "</td>\n<td class=\"age\">";
                   1095:       print readableTime(time() - $date, 0) if $date;
                   1096:       print "</td>\n<td class=\"author\">", htmlquote($author) if $show_author;
                   1097:       print "</td>\n<td class=\"log\">";
3.120     scop     1098:
                   1099:       if ($log) {
3.199     scop     1100:         print htmlify(substr($log, 0, $shortLogLen), $allow_dir_extra);
3.120     scop     1101:         print '...' if (length $log > 80);
                   1102:       }
3.131     scop     1103:       print "</td>\n</tr>";
3.120     scop     1104:       $dirrow++;
                   1105:     }
                   1106:     print "\n";
                   1107:   }
                   1108:
3.131     scop     1109:   print "</table>\n";
3.120     scop     1110:
3.150     scop     1111:   if ((my $num = scalar(@unreadable)) && ! $input{hidenonreadable}) {
                   1112:     printf(<<EOF, $num, htmlquote(join(', ', @unreadable)));
                   1113: <p>
3.208     scop     1114:  <b>NOTE:</b> The following %d unreadable files were ignored:<br />
3.150     scop     1115:  <em>%s</em>
                   1116: </p>
                   1117: EOF
                   1118:   }
                   1119:
3.120     scop     1120:   if ($filesexists && !$filesfound) {
3.150     scop     1121:     my $currtag = defined($input{only_with_tag}) ?
                   1122:       sprintf(' (%s)', htmlquote($input{only_with_tag})) : '';
                   1123:     printf(<<EOF, $filesexists, $currtag);
                   1124: <p>
                   1125:  <b>NOTE:</b> There are %d files, but none matches the current tag%s.
                   1126: </p>
                   1127: EOF
3.120     scop     1128:   }
                   1129:
                   1130:   if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
                   1131:     %tags = %alltags;
                   1132:   }
                   1133:
                   1134:   if (scalar %tags
                   1135:       || $input{only_with_tag}
                   1136:       || $edit_option_form
3.254     scop     1137:       || defined($input{options}))
3.120     scop     1138:   {
3.208     scop     1139:     print "<hr />\n";
3.120     scop     1140:   }
                   1141:
                   1142:   if (scalar %tags || $input{only_with_tag}) {
3.208     scop     1143:     print "<form method=\"get\" action=\"./\">\n<p>\n";
3.120     scop     1144:     foreach my $var (@stickyvars) {
3.208     scop     1145:       printf("<input type=\"hidden\" name=\"$var\" value=\"%s\" />\n",
3.154     scop     1146:              htmlquote($input{$var}))
3.120     scop     1147:         if (defined($input{$var})
                   1148:             && (!defined($DEFAULTVALUE{$var})
                   1149:                 || $input{$var} ne $DEFAULTVALUE{$var})
                   1150:             && $var ne 'only_with_tag');
                   1151:     }
3.208     scop     1152:     printf(<<EOF, ($use_java_script ? ' onchange="this.form.submit()"' : ''));
3.239     scop     1153: <span class="nowrap">
3.208     scop     1154: <label for="only_with_tag" accesskey="T">Show only files with tag:
                   1155: <select id="only_with_tag" name="only_with_tag"%s>
                   1156: <option value="">All tags / default branch</option>
                   1157: EOF
3.120     scop     1158:     foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
3.136     scop     1159:       my $selected =
                   1160:         defined($input{only_with_tag}) && $input{only_with_tag} eq $tag;
                   1161:       printf("<option%s>%s</option>\n",
3.208     scop     1162:              $selected ? ' selected="selected"' : '',
3.136     scop     1163:              htmlquote($tag));
3.120     scop     1164:     }
3.208     scop     1165:     printf(<<EOF, htmlquote($where));
                   1166: </select>
3.239     scop     1167: </label></span> <span class="nowrap">
                   1168: <label for="path" accesskey="P">Module path or alias:
3.208     scop     1169: <input type="text" id="path" name="path" value="%s" size="15" /></label>
3.239     scop     1170: </span>
3.208     scop     1171: <input type="submit" value="Go" accesskey="G" />
                   1172: </p>
                   1173: </form>
                   1174: EOF
3.120     scop     1175:   }
                   1176:
3.188     scop     1177:   if ($allow_tar && $filesfound) {
3.120     scop     1178:     my ($basefile) = ($where =~ m,(?:.*/)?([^/]+),);
3.192     scop     1179:     my $havetar = $CMD{tar} && $CMD{gzip};
                   1180:     my $havezip = $CMD{zip};
                   1181:     if (defined($basefile) && $basefile ne '' && ($havetar || $havezip)) {
3.203     scop     1182:       my $q = ($query ? "$query;" : '?') . 'tarball=1';
3.208     scop     1183:       print "<hr />\n",
3.189     scop     1184:         '<div style="text-align: center">Download this directory in ';
3.192     scop     1185:       # Mangle the filename so browsers show a reasonable filename to download.
                   1186:       my @types = ();
3.271     scop     1187:       $basefile = uri_escape($basefile);
3.192     scop     1188:       push(@types, &link('tarball', "$basefile.tar.gz$q")) if $havetar;
                   1189:       push(@types, &link('zip archive', "$basefile.zip$q")) if $havezip;
                   1190:       print join(' or ', @types), "</div>\n";
3.120     scop     1191:     }
                   1192:   }
                   1193:
3.254     scop     1194:   if ($edit_option_form || defined($input{options})) {
3.120     scop     1195:
3.149     scop     1196:     print <<EOF;
3.270     scop     1197: <form method="get" action="./">
3.189     scop     1198: <fieldset>
                   1199: <legend>General options</legend>
3.208     scop     1200: <input type="hidden" name="copt" value="1" />
3.149     scop     1201: EOF
3.283   ! scop     1202:     for my $v qw(hidecvsroot hidenonreadable) {
        !          1203:       printf(qq{<input type="hidden" name="%s" value="%s" />\n},
        !          1204:              $v, $input{$v} || 0);
        !          1205:     }
3.120     scop     1206:     if ($cvstree ne $cvstreedefault) {
3.208     scop     1207:       print "<input type=\"hidden\" name=\"cvsroot\" value=\"$cvstree\" />\n";
3.120     scop     1208:     }
3.149     scop     1209:     print <<EOF;
3.265     scop     1210: <table summary="General options">
3.149     scop     1211: <tr>
3.189     scop     1212: <td class="opt-label">
                   1213: <label for="sortby" accesskey="F">Sort files by:</label>
                   1214: </td>
                   1215: <td class="opt-value">
3.149     scop     1216: <select id="sortby" name="sortby">
                   1217: <option value="">File</option>
                   1218: EOF
3.208     scop     1219:     print "<option", $bydate ? ' selected="selected"' : '',
3.120     scop     1220:       " value=\"date\">Age</option>\n";
3.208     scop     1221:     print "<option", $byauthor ? ' selected="selected"' : '',
3.120     scop     1222:       " value=\"author\">Author</option>\n"
3.140     scop     1223:         if $show_author;
3.208     scop     1224:     print "<option", $byrev ? ' selected="selected"' : '',
3.120     scop     1225:       " value=\"rev\">Revision</option>\n";
3.208     scop     1226:     print "<option", $bylog ? ' selected="selected"' : '',
3.120     scop     1227:       " value=\"log\">Log message</option>\n";
3.189     scop     1228:     print <<EOF;
                   1229: </select>,
                   1230: <label for="ignorecase" accesskey="I">case-insensitive:
                   1231: EOF
                   1232:     print '<input id="ignorecase" name="ignorecase" type="checkbox"',
3.208     scop     1233:       $input{ignorecase} ? ' checked="checked"' : '',
                   1234:         " value=\"1\" /></label>\n";
3.189     scop     1235:     print <<EOF;
                   1236: </td>
                   1237: <td class="opt-label">
                   1238: <label for="hideattic" accesskey="A">Hide files in Attic:</label>
                   1239: </td>
                   1240: <td class="opt-value">
                   1241: EOF
                   1242:     print '<input id="hideattic" name="hideattic" type="checkbox"',
3.208     scop     1243:       $input{hideattic} ? ' checked="checked"' : '', ' value="1" />';
3.189     scop     1244:     print <<EOF;
                   1245: </td>
                   1246: </tr>
                   1247: <tr>
                   1248: <td class="opt-label">
                   1249: <label for="logsort" accesskey="L">Sort log by:</label>
                   1250: </td>
                   1251: <td class="opt-value">
                   1252: EOF
3.120     scop     1253:     printLogSortSelect(0);
3.189     scop     1254:     print <<EOF;
                   1255: </td>
                   1256: <td class="opt-label">
                   1257: <label for="ln" accesskey="N">Show line numbers:</label>
                   1258: </td>
                   1259: <td class="opt-value">
                   1260: EOF
                   1261:     print '<input id="ln" name="ln" type="checkbox"',
3.208     scop     1262:       $input{ln} ? ' checked="checked"' : '', " value=\"1\" />\n";
3.189     scop     1263:     print <<EOF;
                   1264: </td>
                   1265: </tr>
                   1266: <tr>
                   1267: <td class="opt-label">
                   1268: <label for="f" accesskey="D">Diff format:</label>
                   1269: </td>
                   1270: <td>
                   1271: EOF
3.120     scop     1272:     printDiffSelect(0);
3.149     scop     1273:     print <<EOF;
3.189     scop     1274: </td>
                   1275: <td colspan="2" class="opt-label">
3.208     scop     1276: <input type="submit" value="Change Options" accesskey="C" />
3.189     scop     1277: </td>
3.149     scop     1278: </tr>
                   1279: </table>
3.189     scop     1280: </fieldset>
3.149     scop     1281: </form>
                   1282: EOF
3.120     scop     1283:   }
                   1284:   html_footer();
3.80      knu      1285: }
3.1       knu      1286:
                   1287: ###############################
                   1288: # View Files
                   1289: ###############################
3.80      knu      1290: elsif (-f $fullname . ',v') {
3.114     scop     1291:
3.254     scop     1292:   if (defined($input{rev}) || $doCheckout) {
3.275     scop     1293:     &doCheckout($fullname, $input{rev}, $input{only_with_tag});
3.120     scop     1294:     gzipclose();
                   1295:     exit;
                   1296:   }
                   1297:
3.254     scop     1298:   if (defined($input{annotate}) && $allow_annotate) {
3.275     scop     1299:     &doAnnotate($input{annotate}, $input{only_with_tag});
3.120     scop     1300:     gzipclose();
                   1301:     exit;
                   1302:   }
                   1303:
3.254     scop     1304:   if (defined($input{r1}) && defined($input{r2})) {
                   1305:     &doDiff($fullname,  $input{r1},  $input{tr1},
                   1306:             $input{r2}, $input{tr2}, $input{f});
3.120     scop     1307:     gzipclose();
                   1308:     exit;
                   1309:   }
3.132     scop     1310:
3.170     scop     1311:   if ($allow_cvsgraph && $input{graph}) {
                   1312:     if ($input{makeimage}) {
                   1313:       doGraph();
3.132     scop     1314:     } else {
3.170     scop     1315:       doGraphView();
3.132     scop     1316:     }
                   1317:     gzipclose();
                   1318:     exit;
                   1319:   }
                   1320:
3.120     scop     1321:   &doLog($fullname);
3.276     scop     1322: }
3.120     scop     1323:
3.276     scop     1324: ##############################
                   1325: # View Diff
                   1326: ##############################
                   1327: elsif ($fullname =~ s/\.diff$//
                   1328:        && -f $fullname . ',v' && $input{r1} && $input{r2})
3.120     scop     1329: {
                   1330:
                   1331:   # $where-diff-removal if 'cvs rdiff' is used
                   1332:   # .. but 'cvs rdiff'doesn't support some options
                   1333:   # rcsdiff does (-w and -p), so it is disabled
                   1334:   # $where =~ s/\.diff$//;
                   1335:
3.189     scop     1336:   # Allow diffs using the ".diff" extension so that browsers that default
                   1337:   # to the filename in the URL when saving don't save diffs as eg. foo.c.
3.254     scop     1338:   &doDiff($fullname,  $input{r1},  $input{tr1},
                   1339:           $input{r2}, $input{tr2}, $input{f});
3.120     scop     1340:   gzipclose();
                   1341:   exit;
                   1342:
3.276     scop     1343: }
                   1344:
                   1345: elsif (do { (my $tmp = $fullname) =~ s|/([^/]+)$|/Attic/$1|; -f "$tmp,v" }) {
3.120     scop     1346:   # The file has been removed and is in the Attic.
                   1347:   # Send a redirect pointing to the file in the Attic.
                   1348:   (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
                   1349:   if ($ENV{QUERY_STRING} ne "") {
3.268     scop     1350:     redirect("$newplace?$ENV{QUERY_STRING}");
3.120     scop     1351:   } else {
                   1352:     redirect($newplace);
                   1353:   }
                   1354:   exit;
3.268     scop     1355:
3.276     scop     1356: }
                   1357:
                   1358: elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
3.120     scop     1359:   http_header("text/plain");
                   1360:   print "You matched the following files:\n";
                   1361:   print join ("\n", @files);
3.80      knu      1362:
3.276     scop     1363:   # TODO:
3.120     scop     1364:   # Find the tags from each file
                   1365:   # Display a form offering diffs between said tags
3.276     scop     1366: }
3.80      knu      1367:
3.276     scop     1368: else {
3.120     scop     1369:   # Assume it's a module name with a potential path following it.
3.268     scop     1370:   my $module;
3.266     scop     1371:   my $xtra = (($module = $where) =~ s|(/.*)||) ? $1 : '';
3.80      knu      1372:
3.120     scop     1373:   # Is there an indexed version of modules?
3.268     scop     1374:   my $fh = do { local (*FH); };
                   1375:   if (open($fh, catfile($cvsroot, 'CVSROOT', 'modules'))) {
3.120     scop     1376:     while (<$fh>) {
                   1377:       if (/^(\S+)\s+(\S+)/o
                   1378:           && $module eq $1
3.268     scop     1379:           && $module ne $2
                   1380:           && -d "$cvsroot/$2")
3.120     scop     1381:       {
3.267     scop     1382:         close($fh);
3.120     scop     1383:         redirect("$scriptname/$2$xtra$query");
                   1384:       }
                   1385:     }
3.267     scop     1386:     close($fh);
3.120     scop     1387:   }
                   1388:   fatal("404 Not Found", '%s: no such file or directory', $where);
3.80      knu      1389: }
3.23      knu      1390:
3.25      knu      1391: gzipclose();
3.80      knu      1392:
3.1       knu      1393: ## End MAIN
                   1394:
3.175     scop     1395:
3.120     scop     1396: sub printDiffSelect($)
                   1397: {
                   1398:   my ($use_java_script) = @_;
                   1399:
                   1400:   print '<select id="f" name="f"';
                   1401:   print ' onchange="this.form.submit()"' if $use_java_script;
                   1402:   print ">\n";
                   1403:
3.175     scop     1404:   for my $difftype (@DIFFTYPES) {
3.120     scop     1405:     printf("<option value=\"%s\"%s>%s</option>\n",
3.208     scop     1406:            $difftype, $input{f} eq $difftype ? ' selected="selected"' : '',
3.175     scop     1407:            "\u$DIFFTYPES{$difftype}{descr}");
3.120     scop     1408:   }
                   1409:
                   1410:   print "</select>";
                   1411: }
                   1412:
3.175     scop     1413:
3.168     scop     1414: sub printDiffSelectStickyVars()
                   1415: {
                   1416:   while (my ($key, $val) = each %input) {
                   1417:     next if ($key eq 'f');
                   1418:     next if (defined($DEFAULTVALUE{$key}) && $DEFAULTVALUE{$key} eq $val);
3.206     scop     1419:     print "<input type=\"hidden\" name=\"", htmlquote($key), "\" value=\"",
3.208     scop     1420:       htmlquote($val), "\" />\n";
3.168     scop     1421:   }
                   1422: }
                   1423:
3.175     scop     1424:
3.120     scop     1425: sub printLogSortSelect($)
                   1426: {
                   1427:   my ($use_java_script) = @_;
                   1428:
                   1429:   print '<select id="logsort" name="logsort"';
                   1430:   print ' onchange="this.form.submit()"' if $use_java_script;
                   1431:   print ">\n";
                   1432:
3.175     scop     1433:   for my $sortkey (@LOGSORTKEYS) {
3.120     scop     1434:     printf("<option value=\"%s\"%s>%s</option>\n",
3.208     scop     1435:            $sortkey, $logsort eq $sortkey ? ' selected="selected"' : '',
3.175     scop     1436:            "\u$LOGSORTKEYS{$sortkey}{descr}");
3.120     scop     1437:   }
                   1438:
                   1439:   print "</select>";
                   1440: }
                   1441:
3.175     scop     1442:
3.197     scop     1443: #
                   1444: # Find the last modified, version controlled files in the given directories.
                   1445: # Compares solely based on modification timestamps.  Files in the returned list
                   1446: # are without the ,v suffix, and unreadable files have been filtered out.
                   1447: #
3.120     scop     1448: sub findLastModifiedSubdirs(@)
                   1449: {
                   1450:   my (@dirs) = @_;
                   1451:
3.175     scop     1452:   my @files;
                   1453:   foreach my $dirname (@dirs) {
3.196     scop     1454:     next if ($dirname eq curdir() || $dirname eq updir());
                   1455:     my $dir = catdir($fullname, $dirname);
3.120     scop     1456:     next if (!-d $dir);
                   1457:
                   1458:     my $dh = do { local (*DH); };
                   1459:     opendir($dh, $dir) or next;
3.233     scop     1460:     my (@filenames) = grep(!forbidden(catfile($dir, $_)), readdir($dh));
3.120     scop     1461:     closedir($dh);
                   1462:
3.175     scop     1463:     my $lastmod     = undef;
                   1464:     my $lastmodtime = undef;
3.120     scop     1465:     foreach my $filename (@filenames) {
3.197     scop     1466:       ($filename) =
                   1467:         (catfile($dirname, $filename) =~ VALID_PATH) or next; # untaint
3.196     scop     1468:       my ($file) = catfile($fullname, $filename);
3.197     scop     1469:       next if ($filename !~ /,v$/o || !-f $file || !-r _);
                   1470:       my $modtime = -M _;
3.120     scop     1471:       if (!defined($lastmod) || $modtime < $lastmodtime) {
3.233     scop     1472:         ($lastmod    = $filename) =~ s/,v$//;
3.120     scop     1473:         $lastmodtime = $modtime;
                   1474:       }
                   1475:     }
3.175     scop     1476:     push(@files, $lastmod) if (defined($lastmod));
3.120     scop     1477:   }
                   1478:   return @files;
                   1479: }
                   1480:
3.175     scop     1481:
3.120     scop     1482: sub htmlify_sub(&$)
                   1483: {
                   1484:   (my $proc, local $_) = @_;
3.261     scop     1485:   my @a = split(m|(<a [^>]+>[^<]*</a>)|i);
3.120     scop     1486:   my $linked;
                   1487:   my $result = '';
                   1488:
                   1489:   while (($_, $linked) = splice(@a, 0, 2)) {
                   1490:     &$proc();
                   1491:     $result .= $_      if defined($_);
                   1492:     $result .= $linked if defined($linked);
                   1493:   }
                   1494:
3.175     scop     1495:   return $result;
3.120     scop     1496: }
                   1497:
3.175     scop     1498:
3.120     scop     1499: sub htmlify($;$)
                   1500: {
                   1501:   (local $_, my $extra) = @_;
                   1502:
                   1503:   $_ = htmlquote($_);
                   1504:
                   1505:   # get URL's as link
                   1506:   s{
3.130     scop     1507:     ((https?|ftp)://.+?)([\s\']|&(quot|[lg]t);)
3.120     scop     1508:    }{
3.130     scop     1509:      &link($1, htmlunquote($1)) . $3
3.120     scop     1510:    }egx;
                   1511:
                   1512:   # get e-mails as link
                   1513:   $_ = htmlify_sub {
                   1514:     s<
3.266     scop     1515:       ([\w+=\-.!]+@[\w\-]+(?:\.[\w\-]+)+)
3.120     scop     1516:      ><
3.266     scop     1517:        &link($1, "mailto:$1")
3.120     scop     1518:      >egix;
                   1519:   } $_;
                   1520:
                   1521:   if ($extra) {
                   1522:
                   1523:     # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
                   1524:     if (defined($prcgi) && defined($re_prkeyword)) {
                   1525:       my $prev;
                   1526:
                   1527:       do {
                   1528:         $prev = $_;
                   1529:
                   1530:         $_ = htmlify_sub {
                   1531:           s{
                   1532:             (\b$re_prkeyword[:\#]?\s*
                   1533:              (?:
                   1534:               \#?
                   1535:               \d+[,\s]\s*
                   1536:              )*
                   1537:              \#?)
                   1538:             (\d+)\b
                   1539:            }{
                   1540:              $1 . &link($2, sprintf($prcgi, $2))
                   1541:            }egix;
                   1542:         } $_;
                   1543:       } while ($_ ne $prev);
                   1544:
                   1545:       if (defined($re_prcategories)) {
                   1546:         $_ = htmlify_sub {
                   1547:           s{
                   1548:             (\b$re_prcategories/(\d+)\b)
                   1549:            }{
                   1550:              &link($1, sprintf($prcgi, $2))
                   1551:            }egox;
                   1552:         } $_;
                   1553:       }
                   1554:     }
                   1555:
                   1556:     # get manpage specs as link: "foo.1" "foo(1)"
                   1557:     if (defined($mancgi)) {
                   1558:       $_ = htmlify_sub {
                   1559:         s{
3.143     knu      1560:           (
                   1561:            \b ( \w[\w+\-.]* (?: ::\w[\w+\-.]*)* )
3.120     scop     1562:            (?:
3.143     knu      1563:             \( ([0-9n]) \) \B
3.120     scop     1564:             |
3.143     knu      1565:             \. ([0-9n]) \b
3.120     scop     1566:            )
                   1567:           )
                   1568:          }{
3.149     scop     1569:             my($text, $name, $section) = ($1, $2, defined($3) ? $3 : $4);
                   1570:             ($name =~ /[A-Za-z]/ && $name !~ /\.(:|$)/)
3.271     scop     1571:              ? &link($text, sprintf($mancgi, $section, uri_escape($name)))
3.149     scop     1572:               : $text;
3.120     scop     1573:          }egx;
                   1574:       } $_;
                   1575:     }
                   1576:   }
                   1577:
3.175     scop     1578:   return $_;
3.120     scop     1579: }
                   1580:
3.175     scop     1581:
3.120     scop     1582: sub spacedHtmlText($;$)
                   1583: {
3.175     scop     1584:   (local $_, my $ts) = @_;
3.224     scop     1585:   return '' unless defined($_);
3.175     scop     1586:   $ts ||= $tabstop;
3.120     scop     1587:
                   1588:   if (defined($ts)) {
                   1589:     # Expand tabs
3.279     scop     1590:     1 while s/(.*)(\t+)/$1 . ' ' x (length($2) * $ts - length($1) % $ts)/e;
3.120     scop     1591:   }
                   1592:
                   1593:   if ($hr_breakable) {
3.277     scop     1594:     s/^ /\001nbsp;/;      # protect leading and...
                   1595:     s/ $/\001nbsp;/;      # ...trailing whitespace (mostly for String::Ediff),
                   1596:     s/  / \001nbsp;/g;    # ...and leave every other space 'breakable'
3.120     scop     1597:   } else {
                   1598:     s/ /\001nbsp;/g;
                   1599:   }
                   1600:
                   1601:   $_ = htmlify($_, $allow_source_extra);
                   1602:
                   1603:   # unescape
                   1604:   y/\001/&/;
                   1605:
                   1606:   return $_;
                   1607: }
                   1608:
3.175     scop     1609:
3.120     scop     1610: # Note that this doesn't htmlquote the first argument...
                   1611: sub link($$)
                   1612: {
                   1613:   my ($name, $url) = @_;
3.271     scop     1614:   return sprintf('<a href="%s">%s</a>', htmlquote($url), $name);
3.120     scop     1615: }
                   1616:
3.175     scop     1617:
3.120     scop     1618: sub revcmp($$)
                   1619: {
                   1620:   my ($rev1, $rev2) = @_;
                   1621:
                   1622:   # make no comparison for a tag or a branch
                   1623:   return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
                   1624:
3.261     scop     1625:   my (@r1) = split(/\./, $rev1);
                   1626:   my (@r2) = split(/\./, $rev2);
3.120     scop     1627:   my ($a, $b);
                   1628:
3.261     scop     1629:   while (($a = shift(@r1)) && ($b = shift(@r2))) {
                   1630:     return $a <=> $b unless ($a == $b);
3.120     scop     1631:   }
                   1632:   if (@r1) { return  1; }
                   1633:   if (@r2) { return -1; }
                   1634:   return 0;
                   1635: }
                   1636:
3.175     scop     1637:
3.120     scop     1638: sub fatal($$@)
                   1639: {
                   1640:   my ($errcode, $format, @args) = @_;
3.185     scop     1641:   print "Status: $errcode\r\n";
3.131     scop     1642:   html_header('Error');
3.215     scop     1643:   print '<div id="error">Error: ',
                   1644:     sprintf($format, map(htmlquote($_), @args)), "</div>\n";
3.120     scop     1645:   html_footer();
                   1646:   exit(1);
                   1647: }
                   1648:
3.175     scop     1649:
3.269     scop     1650: #
                   1651: # Sends a redirect to the given URL.
                   1652: #
                   1653: sub redirect($;$)
3.120     scop     1654: {
3.269     scop     1655:   my ($url, $permanent) = @_;
                   1656:   my ($status, $text);
                   1657:   if ($permanent) {
                   1658:     $status = '301';
                   1659:     $text   = 'Moved Permanently';
                   1660:   } else {
                   1661:     $status = '302';
                   1662:     $text   = 'Found';
                   1663:   }
                   1664:   print "Status: $status $text\r\n", "Location: $url\r\n";
                   1665:   html_header($text);
                   1666:   print "<p>This document has moved ", &link('here', $url), ".</p>\n";
3.120     scop     1667:   html_footer();
                   1668:   exit(1);
                   1669: }
                   1670:
3.175     scop     1671:
3.120     scop     1672: sub safeglob($)
                   1673: {
                   1674:   my ($filename) = @_;
                   1675:
3.175     scop     1676:   (my $dirname = $filename) =~ s|/[^/]+$||;
3.120     scop     1677:   $filename =~ s|.*/||;
                   1678:
3.175     scop     1679:   my @results;
                   1680:   my $dh = do { local (*DH); };
3.120     scop     1681:   if (opendir($dh, $dirname)) {
                   1682:     my $glob = $filename;
                   1683:     my $t;
                   1684:
3.149     scop     1685:     #   transform filename from glob to regex.  Deal with:
                   1686:     #   [, {, ?, * as glob chars
                   1687:     #   make sure to escape all other regex chars
3.120     scop     1688:     $glob =~ s/([\.\(\)\|\+])/\\$1/g;
                   1689:     $glob =~ s/\*/.*/g;
                   1690:     $glob =~ s/\?/./g;
                   1691:     $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
3.222     scop     1692:     $glob = qr/^$glob$/;
                   1693:
3.120     scop     1694:     foreach (readdir($dh)) {
3.222     scop     1695:       if ($_ =~ $glob && $_ =~ VALID_PATH) {
3.194     scop     1696:         push(@results, catfile($dirname, $1)); # untaint
3.120     scop     1697:       }
                   1698:     }
                   1699:     closedir($dh);
                   1700:   }
                   1701:
3.175     scop     1702:   return @results;
3.120     scop     1703: }
                   1704:
3.160     scop     1705:
3.227     scop     1706: #
3.230     scop     1707: # Searches @command_path for the given executable file.
3.227     scop     1708: #
3.120     scop     1709: sub search_path($)
                   1710: {
                   1711:   my ($command) = @_;
3.230     scop     1712:   for my $d (@command_path) {
3.227     scop     1713:     my $cmd = catfile($d, $command);
                   1714:     return $cmd if (-x $cmd && !-d _);
3.120     scop     1715:   }
                   1716:   return '';
                   1717: }
                   1718:
3.156     scop     1719:
3.219     scop     1720: #
                   1721: # Gets the enscript(1) highlight mode corresponding to the given filename,
                   1722: # or undef if unsupported.
                   1723: #
                   1724: sub getEnscriptHL($)
                   1725: {
                   1726:   return undef unless $allow_enscript;
                   1727:   my ($filename) = @_;
                   1728:   while (my ($hl, $regex) = each %enscript_types) {
                   1729:     return $hl if ($filename =~ $regex);
                   1730:   }
                   1731:   return undef;
                   1732: }
                   1733:
                   1734:
                   1735: #
                   1736: # Gets the MIME type for the given file name.
                   1737: #
3.156     scop     1738: sub getMimeType($;$)
3.120     scop     1739: {
3.156     scop     1740:   my ($fullname, $binary) = @_;
                   1741:   $binary = ($keywordsubstitution && $keywordsubstitution =~ /b/)
                   1742:     unless defined($binary);
                   1743:
                   1744:   (my $suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
                   1745:
                   1746:   my $mimetype = $MTYPES{$suffix};
                   1747:   $mimetype  ||= $MimeTypes->mimeTypeOf($fullname) if defined($MimeTypes);
                   1748:
                   1749:   if (!$mimetype && $suffix ne '*' && -f $mime_types && -r _) {
                   1750:     my $fh = do { local (*FH); };
                   1751:     if (open($fh, $mime_types)) {
                   1752:       my $re = sprintf('^\s*(\S+\/\S+)\s.+\b%s\b', quotemeta($suffix));
3.222     scop     1753:       $re = qr/$re/;
3.156     scop     1754:       while (my $line = <$fh>) {
                   1755:         if ($line =~ $re) {
                   1756:           $mimetype = $1;
                   1757:           $MTYPES{$suffix} = $mimetype;
                   1758:           last;
                   1759:         }
3.120     scop     1760:       }
3.156     scop     1761:       close($fh);
                   1762:     } else {
                   1763:       warn("Can't open MIME types file $mime_types for reading: $!");
3.120     scop     1764:     }
                   1765:   }
                   1766:
3.156     scop     1767:   $mimetype ||= $MTYPES{'*'};
                   1768:   $mimetype ||= $binary ? 'application/octet-stream' : 'text/plain';
3.120     scop     1769:   return $mimetype;
3.1       knu      1770: }
                   1771:
3.156     scop     1772:
3.1       knu      1773: ###############################
3.24      knu      1774: # read first lines like head(1)
                   1775: ###############################
3.120     scop     1776: sub head($;$)
                   1777: {
3.175     scop     1778:   my ($fh, $linecount) = @_;
                   1779:   $linecount ||= 10;
3.24      knu      1780:
3.120     scop     1781:   my @buf;
                   1782:   if ($linecount > 0) {
3.184     scop     1783:     for (my $i = 0; !eof($fh) && $i < $linecount; $i++) {
3.120     scop     1784:       push @buf, scalar <$fh>;
                   1785:     }
                   1786:   } else {
                   1787:     @buf = <$fh>;
                   1788:   }
3.175     scop     1789:   return @buf;
                   1790: }
3.120     scop     1791:
3.24      knu      1792:
                   1793: ###############################
                   1794: # scan vim and Emacs directives
                   1795: ###############################
3.120     scop     1796: sub scan_directives(@)
                   1797: {
                   1798:   my $ts = undef;
3.24      knu      1799:
3.120     scop     1800:   for (@_) {
                   1801:     $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
                   1802:   }
3.24      knu      1803:
3.120     scop     1804:   ('tabstop' => $ts);
3.24      knu      1805: }
                   1806:
3.175     scop     1807:
3.120     scop     1808: sub openOutputFilter()
                   1809: {
3.175     scop     1810:   return unless $output_filter;
3.86      knu      1811:
3.120     scop     1812:   open(STDOUT, "|-") and return;
3.86      knu      1813:
3.120     scop     1814:   # child of child
3.273     scop     1815:   open(STDERR, '>', devnull()) unless $DEBUG;
3.120     scop     1816:   exec($output_filter) or exit -1;
3.86      knu      1817: }
                   1818:
3.175     scop     1819:
3.24      knu      1820: ###############################
3.1       knu      1821: # show Annotation
                   1822: ###############################
3.275     scop     1823: sub doAnnotate($$)
3.120     scop     1824: {
3.275     scop     1825:   my ($rev, $tag) = @_;
                   1826:   $rev = $tag || 'HEAD' if ($rev eq '.');
3.262     scop     1827:   (my $pathname = $where) =~ s|((?<=/)Attic/)?[^/]*$||;
3.261     scop     1828:   (my $filename = $where) =~ s|^.*/||;
3.126     scop     1829:
3.174     scop     1830:   # This annotate version is based on the cvs annotate-demo Perl script by
                   1831:   # Cyclic Software.  It was written by Cyclic Software,
                   1832:   # http://www.cyclic.com/, and is in the public domain.
                   1833:   # We could abandon the use of rlog, rcsdiff and co using
                   1834:   # the cvs server in a similiar way one day (..after rewrite).
                   1835:
                   1836:   local (*CVS_IN, *CVS_OUT);
3.215     scop     1837:   my $annotate_err;
3.174     scop     1838:   my ($h, $err) =
                   1839:     startproc([ $CMD{cvs}, @annotate_options, 'server' ],
3.215     scop     1840:               '<pipe', \*CVS_IN, '>pipe', \*CVS_OUT,
3.229     scop     1841:               '2>', \$annotate_err);
3.215     scop     1842:   fatal('500 Internal Error',
                   1843:         'Annotate failure (exit status %s), output: <pre>%s</pre>',
                   1844:         $? >> 8 || -1, $err)
                   1845:     unless $h;
3.120     scop     1846:
                   1847:   # OK, first send the request to the server.  A simplified example is:
                   1848:   #     Root /home/kingdon/zwork/cvsroot
                   1849:   #     Argument foo/xx
                   1850:   #     Directory foo
                   1851:   #     /home/kingdon/zwork/cvsroot/foo
                   1852:   #     Directory .
                   1853:   #     /home/kingdon/zwork/cvsroot
                   1854:   #     annotate
                   1855:   # although as you can see there are a few more details.
                   1856:
3.174     scop     1857:   print CVS_IN "Root $cvsroot\n";
                   1858:   print CVS_IN
3.120     scop     1859:     "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
                   1860:
                   1861:   # Don't worry about sending valid-requests, the server just needs to
                   1862:   # support "annotate" and if it doesn't, there isn't anything to be done.
3.174     scop     1863:   print CVS_IN "UseUnchanged\n";
                   1864:   print CVS_IN "Argument -r\n";
                   1865:   print CVS_IN "Argument $rev\n";
                   1866:   print CVS_IN "Argument $where\n";
3.120     scop     1867:
                   1868:   # The protocol requires us to fully fake a working directory (at
                   1869:   # least to the point of including the directories down to the one
                   1870:   # containing the file in question).
3.123     scop     1871:   # So if $where is "dir/sdir/file", then dirs will be ("dir","sdir","file")
                   1872:   my $path = '';
                   1873:   foreach my $dir (split('/', $where)) {
3.120     scop     1874:
                   1875:     if ($path eq "") {
3.123     scop     1876:       # In our example, $dir is "dir".
                   1877:       $path = $dir;
3.120     scop     1878:     } else {
3.174     scop     1879:       print CVS_IN "Directory $path\n";
                   1880:       print CVS_IN "$cvsroot/$path\n";
3.120     scop     1881:
                   1882:       # In our example, $_ is "sdir" and $path becomes "dir/sdir"
                   1883:       # And the next time, "file" and "dir/sdir/file" (which then gets
                   1884:       # ignored, because we don't need to send Directory for the file).
3.123     scop     1885:       $path .= "/$dir";
3.120     scop     1886:     }
                   1887:   }
3.123     scop     1888:   undef $path;
3.120     scop     1889:
                   1890:   # And the last "Directory" before "annotate" is the top level.
3.174     scop     1891:   print CVS_IN "Directory .\n";
                   1892:   print CVS_IN "$cvsroot\n";
3.120     scop     1893:
3.174     scop     1894:   print CVS_IN "annotate\n";
3.120     scop     1895:
                   1896:   # OK, we've sent our command to the server.  Thing to do is to
3.215     scop     1897:   # close the writer side and get all the responses.
                   1898:   if (!close(CVS_IN)) {
3.229     scop     1899:     $h->finish();
3.215     scop     1900:     fatal('500 Internal Error',
                   1901:           'Annotate failure (exit status %s): <code>%s</code>, output: ' .
                   1902:           '<pre>%s</pre>', $? >> 8, $!, $annotate_err);
                   1903:   }
3.120     scop     1904:
3.133     scop     1905:   navigateHeader($scriptwhere, $pathname, $filename, $rev, 'annotate');
3.120     scop     1906:
3.275     scop     1907:   my $revtype = ($rev =~ /\./) ? 'revision' : 'tag'; # TODO: tag -> branch/tag?
3.136     scop     1908:   print '<h3 style="text-align: center">Annotation of ',
3.275     scop     1909:     htmlquote("$pathname$filename"), ", $revtype $rev</h3>\n";
3.120     scop     1910:
                   1911:   # Ready to get the responses from the server.
                   1912:   # For example:
                   1913:   #     E Annotations for foo/xx
                   1914:   #     E ***************
                   1915:   #     M 1.3          (kingdon  06-Sep-97): hello
                   1916:   #     ok
                   1917:   my ($lineNr) = 0;
                   1918:   my ($oldLrev, $oldLusr) = ("", "");
                   1919:   my ($revprint, $usrprint);
                   1920:
                   1921:   if ($annTable) {
3.179     scop     1922:     print <<EOF;
                   1923: <table style="border: none" cellspacing="0" cellpadding="0" summary="Annotation">
                   1924: EOF
3.120     scop     1925:   } else {
                   1926:     print "<pre>";
                   1927:   }
                   1928:
                   1929:   # prefetch several lines
3.174     scop     1930:   my @buf = head(*CVS_OUT);
3.120     scop     1931:
                   1932:   my %d = scan_directives(@buf);
                   1933:
3.174     scop     1934:   while (@buf || !eof(*CVS_OUT)) {
3.197     scop     1935:
3.174     scop     1936:     $_ = @buf ? shift @buf : <CVS_OUT>;
3.120     scop     1937:     my @words = split;
                   1938:
                   1939:     # Adding one is for the (single) space which follows $words[0].
                   1940:     my $rest = substr($_, length($words[0]) + 1);
                   1941:     if ($words[0] eq "E") {
                   1942:       next;
                   1943:     } elsif ($words[0] eq "M") {
                   1944:       $lineNr++;
                   1945:       (my $lrev = substr($_, 2,  13)) =~ y/ //d;
                   1946:       (my $lusr = substr($_, 16, 9))  =~ y/ //d;
                   1947:       my $line = substr($_, 36);
3.275     scop     1948:       # TODO: this does not work for branch/tag revisions.
3.120     scop     1949:       my $isCurrentRev = ($rev eq $lrev);
                   1950:
                   1951:       # we should parse the date here ..
                   1952:       if ($lrev eq $oldLrev) {
                   1953:         $revprint = sprintf('%-8s', '');
                   1954:       } else {
                   1955:         $revprint = sprintf('%-8s', $lrev);
3.266     scop     1956:         $revprint =~ s|(\S+)|&link($1, uri_escape($filename)."$query#rev$1")|e;
3.120     scop     1957:         $oldLusr = '';
                   1958:       }
                   1959:
3.268     scop     1960:       $usrprint = ($lusr eq $oldLusr) ? '' : $lusr;
3.120     scop     1961:       $oldLrev = $lrev;
                   1962:       $oldLusr = $lusr;
                   1963:
3.250     scop     1964:       print $is_textbased ? '<b>' : '<span class="current-rev">'
                   1965:         if $isCurrentRev;
3.120     scop     1966:
3.136     scop     1967:       $usrprint = sprintf('%-8s', $usrprint);
                   1968:       printf '%s%s %s %4d:', $revprint, $isCurrentRev ? '!' : ' ',
                   1969:         htmlquote($usrprint), $lineNr;
3.254     scop     1970:       print spacedHtmlText($line, $d{tabstop});
3.120     scop     1971:
3.250     scop     1972:       print $is_textbased ? '</b>' : '</span>' if $isCurrentRev;
                   1973:
3.120     scop     1974:     } elsif ($words[0] eq "ok") {
                   1975:       # We could complain about any text received after this, like the
                   1976:       # CVS command line client.  But for simplicity, we don't.
3.275     scop     1977:
3.120     scop     1978:     } elsif ($words[0] eq "error") {
                   1979:       fatal("500 Internal Error",
                   1980:             'Error occured during annotate: <b>%s</b>', $_);
                   1981:     }
                   1982:   }
3.229     scop     1983:   $h->finish();
3.120     scop     1984:
                   1985:   if ($annTable) {
                   1986:     print "</table>";
                   1987:   } else {
                   1988:     print "</pre>";
                   1989:   }
3.124     scop     1990:   html_footer();
3.1       knu      1991: }
                   1992:
                   1993: ###############################
                   1994: # make Checkout
                   1995: ###############################
3.275     scop     1996: sub doCheckout($$$)
3.120     scop     1997: {
3.275     scop     1998:   my ($fullname, $rev, $tag) = @_;
                   1999:   $rev = $tag || undef if (!$rev || $rev eq '.');
3.120     scop     2000:
3.219     scop     2001:   # Start resolving whether we will do a markup view or not.
                   2002:   my $do_markup = undef;
3.226     scop     2003:   my $want_type = $input{'content-type'};
                   2004:
3.219     scop     2005:   # No markup if markup disallowed.
                   2006:   $do_markup = 0 unless $allow_markup;
3.226     scop     2007:
3.219     scop     2008:   # No markup if checkout magic cookie in URL.
                   2009:   $do_markup = 0 if (!defined($do_markup) && $doCheckout);
3.226     scop     2010:
3.219     scop     2011:   # Do markup if explicitly asked using cvsweb-markup content type.  If the
                   2012:   # asked content type is anything else, no markup.
3.226     scop     2013:   if (!defined($do_markup) && $want_type) {
                   2014:     if ($want_type =~ CVSWEBMARKUP) {
                   2015:       $want_type = undef;
                   2016:       $do_markup = 1;
                   2017:     } else {
                   2018:       $do_markup = 0;
                   2019:     }
3.219     scop     2020:   }
                   2021:
                   2022:   # Ok, if $do_markup is still undefined, we know that a download has not been
                   2023:   # explicitly asked.  For the last check further down below we'll need to
                   2024:   # know if the file is binary, and possibly run a log on it.
                   2025:   my $needlog = $do_markup || $use_moddate;
3.120     scop     2026:
3.163     scop     2027:   my $moddate = undef;
3.175     scop     2028:   my $revopt;
3.120     scop     2029:   if (defined($rev)) {
                   2030:     $revopt = "-r$rev";
3.219     scop     2031:     if ($needlog) {
3.120     scop     2032:       readLog($fullname, $rev);
3.275     scop     2033:       $moddate   = $date{$rev};
                   2034:       # TODO: even this does not work for branch tags, but only normal tags :(
                   2035:       $moddate ||= $date{$symrev{$rev}} if defined($symrev{$rev});
3.120     scop     2036:     }
                   2037:   } else {
                   2038:     $revopt = "-rHEAD";
3.219     scop     2039:     if ($needlog) {
3.120     scop     2040:       readLog($fullname);
                   2041:       $moddate = $date{$symrev{HEAD}};
                   2042:     }
                   2043:   }
                   2044:
3.194     scop     2045:   my $cr = abs_path($cvsroot) || $cvsroot;
                   2046:   # abs_path() taints when run as a CGI...
                   2047:   if ($cr =~ VALID_PATH) {
                   2048:     $cr = $1;
                   2049:   } else {
                   2050:     fatal('500 Internal Error', 'Illegal CVS root: <code>%s</code>', $cr);
                   2051:   }
3.183     scop     2052:   # Use abs_path() to work around a bug of cvs -p; expand symlinks if we can.
3.194     scop     2053:   my @cmd = ($CMD{cvs}, @cvs_options, '-d', $cr, 'co', '-p', $revopt, $where);
3.183     scop     2054:
3.174     scop     2055:   local (*CVS_OUT, *CVS_ERR);
                   2056:   my ($h, $err) =
3.229     scop     2057:     startproc(\@cmd, \"", '>pipe', \*CVS_OUT, '2>pipe', \*CVS_ERR);
3.215     scop     2058:   fatal('500 Internal Error',
                   2059:         'Checkout failure (exit status %s), output: <pre>%s</pre>',
                   2060:         $? >> 8 || -1, $err)
                   2061:     unless $h;
3.120     scop     2062:
3.174     scop     2063:   if (eof(CVS_ERR)) {
3.229     scop     2064:     $h->finish();
3.120     scop     2065:     fatal("404 Not Found", '%s is not (any longer) pertinent', $where);
                   2066:   }
                   2067:
                   2068:   #===================================================================
                   2069:   #Checking out squid/src/ftp.c
                   2070:   #RCS:  /usr/src/CVS/squid/src/ftp.c,v
                   2071:   #VERS: 1.1.1.28.6.2
                   2072:   #***************
                   2073:
                   2074:   # Parse CVS header
                   2075:   my ($revision, $filename, $cvsheader);
                   2076:   $filename = "";
3.174     scop     2077:   while (<CVS_ERR>) {
3.120     scop     2078:     last if (/^\*\*\*\*/);
                   2079:     $revision = $1 if (/^VERS: (.*)$/);
                   2080:
                   2081:     if (/^Checking out (.*)$/) {
3.214     scop     2082:       ($filename = $1) =~ s|^\./+||;
3.120     scop     2083:     }
                   2084:     $cvsheader .= $_;
                   2085:   }
3.219     scop     2086:   close(CVS_ERR);
3.120     scop     2087:
                   2088:   if ($filename ne $where) {
3.229     scop     2089:     $h->finish();
3.120     scop     2090:     fatal("500 Internal Error",
3.214     scop     2091:           'Unexpected output from cvs co: <pre>%s</pre> ' .
                   2092:           '(expected "<code>%s</code>" but got "<code>%s</code>")',
                   2093:           $cvsheader, $where, $filename);
3.120     scop     2094:   }
                   2095:
3.219     scop     2096:   # Last checks whether we'll do markup or not.
                   2097:   my $isbin = $keywordsubstitution && $keywordsubstitution =~ /b/;
                   2098:   my $mimetype = getMimeType($fullname, $isbin);
                   2099:
                   2100:   # If we still are not sure whether to do markup or not:
                   2101:   # if the MIME type is "viewable" or this is not a binary file, do.
                   2102:   $do_markup = !$isbin || viewable($mimetype) unless defined($do_markup);
                   2103:
                   2104:   if ($do_markup) {
                   2105:
                   2106:     # If this is something we'll be linking to in the markup view, we are
                   2107:     # done with this particular output from "cvs co" and must discard it.
                   2108:     my $linked = $mimetype =~ m{^image/|application/pdf$}i;
                   2109:     if ($linked) {
                   2110:       close(CVS_OUT);
3.229     scop     2111:       $h->finish();
3.219     scop     2112:     }
                   2113:
3.163     scop     2114:     # Here we know the last modified date, but don't know if tags have been
3.219     scop     2115:     # added afterwards (those are shown in the markup view): no last-modified.
                   2116:     cvswebMarkup(\*CVS_OUT, $fullname, $revision, $isbin, $mimetype, $needlog);
                   2117:
3.229     scop     2118:     $h->finish() unless $linked;
3.219     scop     2119:
3.120     scop     2120:   } else {
3.226     scop     2121:     http_header($want_type || $mimetype, $moddate);
3.174     scop     2122:     local $/ = undef;
                   2123:     print <CVS_OUT>;
3.229     scop     2124:     $h->finish();
3.120     scop     2125:   }
1.12      fenner   2126: }
                   2127:
3.174     scop     2128:
3.219     scop     2129: sub cvswebMarkup($$$$$$;$)
3.120     scop     2130: {
3.219     scop     2131:   my ($filehandle, $fullname, $rev, $isbin, $mimetype, $logged, $mod) = @_;
3.1       knu      2132:
3.262     scop     2133:   (my $pathname = $where) =~ s|((?<=/)Attic/)?[^/]*$||;
3.261     scop     2134:   (my $filename = $where) =~ s|^.*/||;
3.120     scop     2135:
3.219     scop     2136:   navigateHeader($scriptwhere, $pathname, $filename, $rev, 'view', $mod);
3.120     scop     2137:
3.144     scop     2138:   print <<EOF;
3.208     scop     2139: <hr />
3.182     scop     2140: <div class="log-markup">
                   2141: File:&nbsp;
3.144     scop     2142: EOF
3.219     scop     2143:   print &clickablePath($where, 1), "<br />\n";
3.120     scop     2144:
                   2145:   if ($show_log_in_markup) {
3.219     scop     2146:     readLog($fullname) unless $logged; #,$rev);
                   2147:     printLog($rev, $mimetype, $isbin);
3.120     scop     2148:   } else {
3.244     scop     2149:     print "Revision: <b>$rev</b><br />\n";
                   2150:     print 'Tag: ', htmlquote($input{only_with_tag}), "<br />\n"
3.120     scop     2151:       if $input{only_with_tag};
                   2152:   }
3.208     scop     2153:   print "</div>\n<hr />";
3.271     scop     2154:   my $url = download_url(uri_escape($filename), $rev, $mimetype);
3.120     scop     2155:
3.219     scop     2156:   if ($mimetype =~ m|^image/|i) {
3.208     scop     2157:     printf '<img src="%s" alt="%s" /><br />',
3.271     scop     2158:       $url . $barequery, htmlquote($filename);
3.219     scop     2159:   } elsif (lc($mimetype) eq 'application/pdf') {
3.208     scop     2160:     printf '<embed src="%s" width="100%%" height="100%%" /><br />',
3.271     scop     2161:       $url . $barequery;
3.120     scop     2162:   } else {
                   2163:
3.208     scop     2164:     print "<pre>\n";
3.167     scop     2165:     my $linenumbers = $input{ln} || 0;
3.149     scop     2166:
3.219     scop     2167:     if (my $enscript_hl = getEnscriptHL($filename)) {
3.167     scop     2168:       doEnscript($filehandle, $enscript_hl, $linenumbers);
3.148     scop     2169:
                   2170:     } else {
3.200     scop     2171:       my $ln  = 0;
                   2172:       my @buf = ();
                   2173:       my $ts  = undef;
                   2174:
                   2175:       if ($preformat_in_markup) {
                   2176:         # prefetch several lines
                   2177:         @buf = head($filehandle);
                   2178:         my %d = scan_directives(@buf);
                   2179:         $ts = $d{tabstop};
                   2180:       }
                   2181:
                   2182:       while (@buf || !eof($filehandle)) {
                   2183:         $_ = @buf ? shift @buf : <$filehandle>;
3.167     scop     2184:         if ($linenumbers) {
                   2185:           $ln++;
                   2186:           printf '<a id="l%d" class="src">%5d: </a>', ($ln) x 2;
3.149     scop     2187:         }
3.200     scop     2188:         print $preformat_in_markup ? spacedHtmlText($_, $ts) : htmlquote($_);
3.148     scop     2189:       }
3.120     scop     2190:     }
3.149     scop     2191:
                   2192:     print "</pre>\n";
3.120     scop     2193:   }
3.131     scop     2194:   html_footer();
3.120     scop     2195: }
                   2196:
3.156     scop     2197:
3.120     scop     2198: sub viewable($)
                   2199: {
3.219     scop     2200:   return shift =~ m{^((text|image)/|application/pdf)}i;
3.156     scop     2201: }
3.120     scop     2202:
3.1       knu      2203:
                   2204: ###############################
                   2205: # Show Colored Diff
                   2206: ###############################
3.120     scop     2207: sub doDiff($$$$$$)
                   2208: {
                   2209:   my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
                   2210:
3.233     scop     2211:   if (forbidden($fullname)) {
                   2212:     fatal('403 Forbidden', 'Access to %s forbidden.', $where);
3.120     scop     2213:   }
                   2214:
3.175     scop     2215:   my ($rev1, $sym1);
3.120     scop     2216:   if ($r1 =~ /([^:]+)(:(.+))?/) {
                   2217:     $rev1 = $1;
                   2218:     $sym1 = $3;
                   2219:   }
                   2220:   if ($r1 eq 'text') {
                   2221:     $rev1 = $tr1;
                   2222:     $sym1 = "";
                   2223:   }
                   2224:
3.175     scop     2225:   my ($rev2, $sym2);
3.120     scop     2226:   if ($r2 =~ /([^:]+)(:(.+))?/) {
                   2227:     $rev2 = $1;
                   2228:     $sym2 = $3;
                   2229:   }
                   2230:   if ($r2 eq 'text') {
                   2231:     $rev2 = $tr2;
                   2232:     $sym2 = "";
                   2233:   }
                   2234:
                   2235:   #
                   2236:   # rev1 and rev2 are now both numeric revisions.
                   2237:   # Thus we do a DWIM here and swap them if rev1 is after rev2.
                   2238:   # XXX should we warn about the fact that we do this?
                   2239:   if (&revcmp($rev1, $rev2) > 0) {
                   2240:     my ($tmp1, $tmp2) = ($rev1, $sym1);
                   2241:     ($rev1, $sym1) = ($rev2, $sym2);
                   2242:     ($rev2, $sym2) = ($tmp1, $tmp2);
                   2243:   }
3.225     scop     2244:
                   2245:   my $mimetype = getMimeType($fullname);
                   2246:
                   2247:   #
                   2248:   #  Check for per-MIME type diff commands.
                   2249:   #
                   2250:   my $diffcmd = undef;
                   2251:   if (my $diffcmds = $DIFF_COMMANDS{lc($mimetype)}) {
                   2252:     if ($f =~ /^ext(\d*)$/) {
                   2253:       my $n = $1 || 0;
                   2254:       $diffcmd = $diffcmds->[$n];
                   2255:     }
                   2256:   }
                   2257:   if ($diffcmd && $diffcmd->{cmd} && $diffcmd->{name}) {
                   2258:
                   2259:     if ($diffcmd->{args} && ref($diffcmd->{args}) ne 'ARRAY') {
                   2260:       fatal('500 Internal Error',
                   2261:             'Configuration error: arguments to external diff tools must ' .
                   2262:             'be given as array refs.  See "<code>%s</code>" in ' .
                   2263:             '<code>%%DIFF_COMMANDS</code>.',
                   2264:             $diffcmd->{name});
                   2265:     }
                   2266:
                   2267:     (my $cvsname = $where) =~ s/\.diff$//;
                   2268:
                   2269:     # Create two temporary files with the two revisions
                   2270:     my $temp_fn1 = checkout_to_temp($cvsroot, $cvsname, $rev1);
                   2271:     my $temp_fn2 = checkout_to_temp($cvsroot, $cvsname, $rev2);
                   2272:
                   2273:     # Execute chosen diff binary.
                   2274:     local (*DIFF_OUT);
                   2275:     my @cmd = ($diffcmd->{cmd});
                   2276:     push(@cmd, @{$diffcmd->{args}}) if $diffcmd->{args};
                   2277:     push(@cmd, $temp_fn1, $temp_fn2);
                   2278:     my ($h, $err) = startproc(\@cmd, \"", '>pipe', \*DIFF_OUT);
                   2279:     if (!$h) {
                   2280:       unlink($temp_fn1);
                   2281:       unlink($temp_fn2);
                   2282:       fatal('500 Internal Error',
                   2283:             'Diff failure (exit status %s), output: <pre>%s</pre>',
                   2284:             $? >> 8 || -1, $err);
                   2285:     }
                   2286:
                   2287:     http_header($diffcmd->{type} || 'text/plain');
                   2288:     local $/ = undef;
                   2289:     print <DIFF_OUT>;
3.229     scop     2290:     $h->finish();
3.225     scop     2291:     unlink($temp_fn1);
                   2292:     unlink($temp_fn2);
                   2293:
                   2294:     exit;
                   2295:   }
                   2296:
                   2297:   #
                   2298:   # Normal CVS diff.
                   2299:   #
                   2300:
                   2301:   $f = $DEFAULTVALUE{f} || 'u' if ($f =~ /^ext\d*$/);
3.120     scop     2302:   my $difftype = $DIFFTYPES{$f};
                   2303:   if (!$difftype) {
                   2304:     fatal("400 Bad arguments", 'Diff format %s not understood', $f);
                   2305:   }
                   2306:
3.254     scop     2307:   my @difftype       = @{$difftype->{opts}};
                   2308:   my $human_readable = $difftype->{colored};
3.120     scop     2309:
3.247     scop     2310:   # Apply special diff options.  -p and -F are not available with side by side
                   2311:   # diffs and may cause problems with older (< 2.8) versions of diffutils if
                   2312:   # used with --side-by-side.
                   2313:   if ($showfunc && $f !~ /^s/) {
                   2314:     push(@difftype, '-p');
                   2315:     while (my ($re1, $re2) = each %funcline_regexp) {
3.222     scop     2316:       if ($fullname =~ $re1) {
3.247     scop     2317:         push(@difftype, '-F', $re2);
3.120     scop     2318:         last;
                   2319:       }
                   2320:     }
                   2321:   }
                   2322:
                   2323:   if ($human_readable) {
3.247     scop     2324:     push(@difftype, '-w')  if $hr_ignwhite;
                   2325:     push(@difftype, '-kk') if $hr_ignkeysubst;
3.120     scop     2326:   }
                   2327:
3.175     scop     2328:   my $fh = do { local (*FH); };
3.120     scop     2329:   if (!open($fh, "-|")) {    # child
                   2330:     open(STDERR, ">&STDOUT");    # Redirect stderr to stdout
                   2331:     openOutputFilter();
3.166     scop     2332:     exec($CMD{rcsdiff}, @rcsdiff_options, @difftype, "-r$rev1", "-r$rev2",
                   2333:          $fullname) or exit -1;
3.120     scop     2334:   }
3.166     scop     2335:
3.120     scop     2336:   if ($human_readable) {
3.168     scop     2337:     #
                   2338:     # Human readable diff.
                   2339:     #
                   2340:     human_readable_diff($fh, $rev2);
                   2341:     html_footer();
                   2342:     gzipclose();
                   2343:     exit;
                   2344:
                   2345:   } elsif ($f =~ /^([ucs])c$/) {
                   2346:     #
                   2347:     # Enscript colored diff.
                   2348:     #
                   2349:     my $hl = 'diff';
                   2350:     $hl .= $1 if ($1 eq 'u' || $1 eq 's');
                   2351:     (my $where_nd = $where)       =~ s/\.diff$//;
3.262     scop     2352:     (my $pathname = $where_nd)    =~ s|((?<=/)Attic/)?[^/]*$||;
3.168     scop     2353:     (my $filename = $where_nd)    =~ s|^.*/||;
                   2354:     (my $swhere   = $scriptwhere) =~ s|\.diff$||;
                   2355:     navigateHeader($swhere, $pathname, $filename, $rev2, 'diff');
                   2356:     printf(<<EOF, $where_nd, $rev1, $rev2);
                   2357: <h3 style="text-align: center">Diff for /%s between versions %s and %s</h3>
                   2358: <pre>
                   2359: EOF
3.240     scop     2360:     doEnscript(\$fh, $hl, 0, 'cvsweb_diff');
3.168     scop     2361:     print <<EOF;
                   2362: </pre>
3.208     scop     2363: <hr style="width: 100%" />
3.168     scop     2364: <form method="get" action="$scriptwhere">
                   2365: EOF
                   2366:     printDiffSelectStickyVars();
                   2367:     print 'Diff format: ';
                   2368:     printDiffSelect($use_java_script);
3.208     scop     2369:     print "<input type=\"submit\" value=\"Show\" />\n</form>\n";
3.120     scop     2370:     html_footer();
                   2371:     gzipclose();
                   2372:     exit;
3.168     scop     2373:
3.120     scop     2374:   } else {
3.168     scop     2375:     #
                   2376:     # Plain diff.
                   2377:     #
3.120     scop     2378:     http_header("text/plain");
                   2379:   }
                   2380:
                   2381:   #
                   2382:   #===================================================================
                   2383:   #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
                   2384:   #retrieving revision 1.16
                   2385:   #retrieving revision 1.17
                   2386:   #diff -c -r1.16 -r1.17
                   2387:   #*** /home/ncvs/src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
                   2388:   #--- /home/ncvs/src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17
                   2389:   #
                   2390:   # Ideas:
                   2391:   # - nuke the stderr output if it's what we expect it to be
                   2392:   # - Add "no differences found" if the diff command supplied no output.
                   2393:   #
                   2394:   #*** src/sys/netinet/tcp_output.c     1995/11/03 22:08:08     1.16
                   2395:   #--- src/sys/netinet/tcp_output.c     1995/12/05 17:46:35     1.17 RELENG_2_1_0
                   2396:   # (bogus example, but...)
                   2397:   #
3.175     scop     2398:   my ($f1, $f2);
3.120     scop     2399:   if (grep { $_ eq '-u' } @difftype) {
                   2400:     $f1 = '---';
                   2401:     $f2 = '\+\+\+';
                   2402:   } else {
                   2403:     $f1 = '\*\*\*';
                   2404:     $f2 = '---';
                   2405:   }
                   2406:
                   2407:   while (<$fh>) {
                   2408:     if (m|^$f1 $cvsroot|o) {
                   2409:       s|$cvsroot/||o;
                   2410:       if ($sym1) {
                   2411:         chop;
                   2412:         $_ .= " $sym1\n";
                   2413:       }
                   2414:     } elsif (m|^$f2 $cvsroot|o) {
                   2415:       s|$cvsroot/||o;
                   2416:
                   2417:       if ($sym2) {
                   2418:         chop;
                   2419:         $_ .= " $sym2\n";
                   2420:       }
                   2421:     }
                   2422:     print $_;
                   2423:   }
                   2424:   close($fh);
1.12      fenner   2425: }
                   2426:
3.175     scop     2427:
3.1       knu      2428: ###############################
                   2429: # Show Logs ..
                   2430: ###############################
3.120     scop     2431: sub getDirLogs($$@)
                   2432: {
                   2433:   my ($cvsroot, $dirname, @otherFiles) = @_;
3.139     scop     2434:   my $tag = $input{only_with_tag};
3.196     scop     2435:   my $DirName = catdir($cvsroot, $where);
3.120     scop     2436:
3.139     scop     2437:   my @files = &safeglob("$DirName/*,v");
3.254     scop     2438:   push (@files, &safeglob("$DirName/Attic/*,v")) unless $input{hideattic};
3.120     scop     2439:   foreach my $file (@otherFiles) {
3.196     scop     2440:     push(@files, catfile($DirName, $file));
3.120     scop     2441:   }
                   2442:
3.150     scop     2443:   # Weed out unreadable files.
                   2444:   my $i = 0;
                   2445:   my @unreadable = ();
                   2446:   while ($i < scalar(@files)) {
3.197     scop     2447:     # Note: last modified files from subdirs returned by
                   2448:     # findLastModifiedSubdirs() come without the ,v suffix so they're not
                   2449:     # found here, but have already been checked for readability.  *cough*
                   2450:     if (-r $files[$i] || !-e _) {
3.150     scop     2451:       $i++;
                   2452:     } else {
                   2453:       push(@unreadable, splice(@files, $i, 1));
                   2454:     }
                   2455:   }
                   2456:
3.139     scop     2457:   # If there are no files, we're done.
3.150     scop     2458:   return @unreadable unless @files;
3.120     scop     2459:
3.139     scop     2460:   my @cmd = ($CMD{rlog});
                   2461:   # Can't use -r<tag> as '-' is allowed in tagnames,
                   2462:   # but misinterpreted by rlog.
                   2463:   push(@cmd, '-r') unless defined($tag);
3.120     scop     2464:
3.139     scop     2465:   my $fh = do { local (*FH); };
3.273     scop     2466:   if (!open($fh, '-|')) {                       # Child
                   2467:     open(STDERR, '>', devnull()) unless $DEBUG; # Ignore rlog's complaints.
3.139     scop     2468:     openOutputFilter();
                   2469:     if ($file_list_len && $file_list_len > 1) {
                   2470:       while (scalar(@files) > $file_list_len) {  # Process files in chunks.
                   2471:         system(@cmd, splice(@files, 0, $file_list_len)) == 0 or exit -1;
                   2472:       }
3.120     scop     2473:     }
3.139     scop     2474:     exec(@cmd, @files) or exit -1;
                   2475:   }
                   2476:   undef @cmd;
3.120     scop     2477:
3.139     scop     2478:   my $state = 'start';
                   2479:   my ($date, $branchpoint, $branch, $log, @filetags);
3.152     scop     2480:   my ($rev, $revision, $revwanted, $filename, $head, $author, $keywordsubst);
3.120     scop     2481:
                   2482:   while (<$fh>) {
                   2483:     if ($state eq "start") {
                   2484:
                   2485:       #Next file. Initialize file variables
                   2486:       $rev         = '';
                   2487:       $revwanted   = '';
                   2488:       $branch      = '';
                   2489:       $branchpoint = '';
                   2490:       $filename    = '';
                   2491:       $log         = '';
                   2492:       $revision    = '';
                   2493:       %symrev      = ();
                   2494:       @filetags    = ();
3.152     scop     2495:       $keywordsubst= '';
3.120     scop     2496:
                   2497:       #jump to head state
                   2498:       $state = "head";
                   2499:     }
3.144     scop     2500:
3.120     scop     2501:     again:
                   2502:
                   2503:     if ($state eq "head") {
                   2504:
                   2505:       #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
                   2506:
                   2507:       if (/^Working file: (.+)$/) {
                   2508:         $filename = $1;
                   2509:       } elsif (/^head: (.+)$/) {
                   2510:         $head = $1;
                   2511:       } elsif (/^branch: (.+)$/) {
                   2512:         $branch = $1;
3.152     scop     2513:       } elsif (/^keyword substitution: (.+)$/) {
                   2514:         $keywordsubst = $1;
3.120     scop     2515:       } elsif (/^symbolic names:/) {
                   2516:         $state = "tags";
                   2517:         ($branch = $head) =~ s/\.\d+$//
                   2518:           if $branch eq '';
                   2519:         $branch =~ s/(\d+)$/0.$1/;
                   2520:         $symrev{MAIN}  = $branch;
                   2521:         $symrev{HEAD}  = $branch;
                   2522:         $alltags{MAIN} = 1;
                   2523:         $alltags{HEAD} = 1;
                   2524:         push (@filetags, "MAIN", "HEAD");
3.222     scop     2525:       } elsif ($_ =~ LOG_REVSEPR) {
3.120     scop     2526:         $state = "log";
                   2527:         $rev   = '';
                   2528:         $date  = '';
                   2529:         $log   = '';
                   2530:
                   2531:         # Try to reconstruct the relative filename if RCS spits out a full path
                   2532:         $filename =~ s%^\Q$DirName\E/%%;
                   2533:       }
                   2534:       next;
                   2535:     }
                   2536:
                   2537:     if ($state eq "tags") {
                   2538:       if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
                   2539:         push (@filetags, $1);
                   2540:         $symrev{$1}  = $2;
                   2541:         $alltags{$1} = 1;
                   2542:         next;
                   2543:       } elsif (/^\S/) {
                   2544:
                   2545:         if (defined($tag)) {
                   2546:           if (defined($symrev{$tag}) || $tag eq "HEAD") {
                   2547:             $revwanted    = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
                   2548:             ($branch      = $revwanted) =~ s/\b0\.//;
                   2549:             ($branchpoint = $branch)    =~ s/\.?\d+$//;
                   2550:             $revwanted    = '' if ($revwanted ne $branch);
                   2551:           } elsif ($tag ne "HEAD") {
                   2552:             $state = "skip";
                   2553:             next;
                   2554:           }
                   2555:         }
                   2556:
                   2557:         foreach my $tagfound (@filetags) {
                   2558:           $tags{$tagfound} = 1;
                   2559:         }
                   2560:         $state = "head";
                   2561:         goto again;
                   2562:       }
                   2563:     }
                   2564:
                   2565:     if ($state eq "log") {
3.222     scop     2566:       if ($_ =~ LOG_REVSEPR || $_ =~ LOG_FILESEPR) {
3.120     scop     2567:
                   2568:         # End of a log entry.
                   2569:         my $revbranch = $rev;
                   2570:         $revbranch =~ s/\.\d+$//;
                   2571:
                   2572:         if ($revwanted eq '' && $branch ne '' && $branch eq $revbranch
                   2573:             || !defined($tag))
                   2574:         {
                   2575:           $revwanted = $rev;
                   2576:         }
                   2577:
                   2578:         if ($revwanted ne ''
                   2579:             ? $rev eq $revwanted
                   2580:             : $branchpoint ne ''
                   2581:               ? $rev eq $branchpoint
                   2582:               : 0
                   2583:             && ($rev eq $head))
                   2584:         {    # Don't think head is needed here..
3.152     scop     2585:           my @finfo = ($rev, $date, $log, $author, $filename, $keywordsubst);
                   2586:           (my $name = $filename) =~ s%/.*%%;
3.120     scop     2587:           $fileinfo{$name} = [@finfo];
                   2588:           $state = "done" if ($rev eq $revwanted);
                   2589:         }
                   2590:         $rev  = '';
                   2591:         $date = '';
                   2592:         $log  = '';
                   2593:       } elsif ($date eq ''
                   2594:                && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|)
                   2595:       {
3.172     scop     2596:         my $yr    = $1;
                   2597:         $yr      -= 1900 if ($yr > 100); # Damn 2-digit year routines :-)
                   2598:         $date     = timegm($6, $5, $4, $3, $2 - 1, $yr);
3.120     scop     2599:         ($author) = /author: ([^;]+)/;
3.172     scop     2600:         $state    = 'log';
                   2601:         $log      = '';
3.120     scop     2602:         next;
                   2603:       } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
                   2604:         $rev = $1;    # .*$ eats up the locker(lockers?) info, if any
                   2605:         next;
                   2606:       } else {
                   2607:         $log .= $_;
                   2608:       }
                   2609:     }
                   2610:
3.222     scop     2611:     if ($_ =~ LOG_FILESEPR) {
3.120     scop     2612:       $state = "start";
                   2613:       next;
                   2614:     }
                   2615:   }
                   2616:
3.139     scop     2617:   my $linesread = $. || 0;
                   2618:   close($fh);
                   2619:
                   2620:   if ($linesread == 0) {
3.137     scop     2621:     fatal('500 Internal Error',
3.230     scop     2622:           'Failed to spawn GNU rlog on <em>"%s"</em>.<br /><br />Did you set the <b><code>@command_path</code></b> in your configuration file correctly? (Currently: "<code>%s</code>")',
                   2623:           htmlquote(join(', ', @files)), join(':', @command_path));
3.120     scop     2624:   }
3.150     scop     2625:
                   2626:   return @unreadable;
3.120     scop     2627: }
                   2628:
3.175     scop     2629:
3.120     scop     2630: sub readLog($;$)
                   2631: {
                   2632:   my ($fullname, $revision) = @_;
                   2633:   my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
                   2634:
                   2635:   undef %symrev;
                   2636:   undef %revsym;
                   2637:   undef @allrevisions;
                   2638:   undef %date;
                   2639:   undef %author;
                   2640:   undef %state;
                   2641:   undef %difflines;
                   2642:   undef %log;
3.152     scop     2643:   $keywordsubstitution = '';
3.120     scop     2644:
3.175     scop     2645:   my $fh = do { local (*FH); };
3.120     scop     2646:   if (!open($fh, "-|")) {    # child
3.275     scop     2647:     openOutputFilter();
                   2648:     $revision = defined($revision) ? "-r$revision" : '';
                   2649:     if ($revision =~ /\./) {
                   2650:       # Normal revision, not a branch/tag name.
3.120     scop     2651:       exec($CMD{rlog}, $revision, $fullname) or exit -1;
                   2652:     } else {
                   2653:       exec($CMD{rlog}, $fullname) or exit -1;
                   2654:     }
                   2655:   }
                   2656:
3.217     scop     2657:   my $curbranch = undef;
3.120     scop     2658:   while (<$fh>) {
                   2659:     if ($symnames) {
                   2660:       if (/^\s+([^:]+):\s+([\d\.]+)/) {
                   2661:         $symrev{$1} = $2;
3.152     scop     2662:         next;
3.120     scop     2663:       } else {
                   2664:         $symnames = 0;
                   2665:       }
3.152     scop     2666:     }
                   2667:     if (/^head:\s+([\d\.]+)/) {
3.120     scop     2668:       $head = $1;
                   2669:     } elsif (/^branch:\s+([\d\.]+)/) {
                   2670:       $curbranch = $1;
                   2671:     } elsif (/^symbolic names/) {
                   2672:       $symnames = 1;
3.152     scop     2673:     } elsif (/^keyword substitution: (.+)$/) {
                   2674:       $keywordsubstitution = $1;
3.120     scop     2675:     } elsif (/^-----/) {
                   2676:       last;
                   2677:     }
                   2678:   }
                   2679:   ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
                   2680:
                   2681:   # each log entry is of the form:
                   2682:   # ----------------------------
                   2683:   # revision 3.7.1.1
                   2684:   # date: 1995/11/29 22:15:52;  author: fenner;  state: Exp;  lines: +5 -3
                   2685:   # log info
                   2686:   # ----------------------------
                   2687:
                   2688:   # For a locked revision, the first line after the separator
                   2689:   # becomes smth like
3.149     scop     2690:   # revision 9.19       locked by: vassilii;
3.120     scop     2691:
                   2692:   logentry:
                   2693:
3.222     scop     2694:   while ($_ !~ LOG_FILESEPR) {
3.120     scop     2695:     $_ = <$fh>;
                   2696:     last logentry if (!defined($_));    # EOF
                   2697:     if (/^revision (\d+(?:\.\d+)+)/) {
                   2698:       $rev = $1;
3.261     scop     2699:       unshift(@allrevisions, $rev);
3.222     scop     2700:     } elsif ($_ =~ LOG_FILESEPR || $_ =~ LOG_REVSEPR) {
3.120     scop     2701:       next logentry;
                   2702:     } else {
                   2703:
                   2704:       # The rlog output is syntactically ambiguous.  We must
                   2705:       # have guessed wrong about where the end of the last log
                   2706:       # message was.
                   2707:       # Since this is likely to happen when people put rlog output
                   2708:       # in their commit messages, don't even bother keeping
                   2709:       # these lines since we don't know what revision they go with
                   2710:       # any more.
                   2711:       next logentry;
                   2712:     }
                   2713:     $_ = <$fh>;
                   2714:     if (
                   2715:       m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
                   2716:       )
                   2717:     {
3.172     scop     2718:       my $yr           = $1;
                   2719:       $yr             -= 1900 if ($yr > 100); # Damn 2-digit year routines :-)
                   2720:       $date{$rev}      = timegm($6, $5, $4, $3, $2 - 1, $yr);
3.120     scop     2721:       $author{$rev}    = $7;
                   2722:       $state{$rev}     = $8;
                   2723:       $difflines{$rev} = $10;
                   2724:     } else {
                   2725:       fatal("500 Internal Error", 'Error parsing RCS output: %s', $_);
                   2726:     }
                   2727:
                   2728:   line:
                   2729:     while (<$fh>) {
                   2730:       next line if (/^branches:\s/);
3.222     scop     2731:       last line if ($_ =~ LOG_FILESEPR || $_ =~ LOG_REVSEPR);
3.120     scop     2732:       $log{$rev} .= $_;
                   2733:     }
                   2734:   }
                   2735:   close($fh);
                   2736:
                   2737:   @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
                   2738:
                   2739:   #
                   2740:   # HEAD is an artificial tag which is simply the highest tag number on the main
                   2741:   # branch, unless there is a branch tag in the RCS file in which case it's the
                   2742:   # highest revision on that branch.  Find it by looking through @revorder; it
                   2743:   # is the first commit listed on the appropriate branch.
                   2744:   # This is not neccesary the same revision as marked as head in the RCS file.
                   2745:   my $headrev = $curbranch || "1";
3.254     scop     2746:   ($symrev{MAIN} = $headrev) =~ s/(\d+)$/0.$1/;
3.120     scop     2747:
                   2748:   foreach $rev (@revorder) {
                   2749:     if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
3.254     scop     2750:       $symrev{HEAD} = $rev;
3.120     scop     2751:       last;
                   2752:     }
                   2753:   }
3.254     scop     2754:   ($symrev{HEAD} = $headrev) =~ s/\.\d+$// unless defined($symrev{HEAD});
3.120     scop     2755:
                   2756:   #
                   2757:   # Now that we know all of the revision numbers, we can associate
                   2758:   # absolute revision numbers with all of the symbolic names, and
                   2759:   # pass them to the form so that the same association doesn't have
                   2760:   # to be built then.
                   2761:   #
                   2762:   undef @branchnames;
                   2763:   undef %branchpoint;
                   2764:   undef $sel;
                   2765:
                   2766:   foreach (reverse sort keys %symrev) {
                   2767:     $rev = $symrev{$_};
                   2768:     if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
                   2769:       push (@branchnames, $_);
                   2770:
                   2771:       #
                   2772:       # A revision number of A.B.0.D really translates into
                   2773:       # "the highest current revision on branch A.B.D".
                   2774:       #
                   2775:       # If there is no branch A.B.D, then it translates into
                   2776:       # the head A.B .
                   2777:       #
                   2778:       # This reasoning also applies to the main branch A.B,
                   2779:       # with the branch number 0.A, with the exception that
                   2780:       # it has no head to translate to if there is nothing on
                   2781:       # the branch, but I guess this can never happen?
                   2782:       #
                   2783:       # (the code below gracefully forgets about the branch
                   2784:       # if it should happen)
                   2785:       #
                   2786:       $head = defined($2) ? $2 : "";
                   2787:       $branch = $3;
                   2788:       $branchrev = $head . ($head ne "" ? "." : "") . $branch;
3.222     scop     2789:       $rev = $head;
                   2790:
                   2791:       my $regex = '^' . quotemeta($branchrev) . '\b';
                   2792:       $regex = qr/$regex/;
3.120     scop     2793:
                   2794:       foreach my $r (@revorder) {
3.222     scop     2795:         if ($r =~ $regex) {
3.120     scop     2796:           $rev = $branchrev;
                   2797:           last;
                   2798:         }
                   2799:       }
                   2800:       next if ($rev eq "");
                   2801:
                   2802:       if ($rev ne $head && $head ne "") {
3.131     scop     2803:         $branchpoint{$head} .= ', ' if ($branchpoint{$head});
3.120     scop     2804:         $branchpoint{$head} .= $_;
                   2805:       }
                   2806:     }
                   2807:     $revsym{$rev} .= ", " if ($revsym{$rev});
                   2808:     $revsym{$rev} .= $_;
3.136     scop     2809:     $sel .= sprintf("<option value=\"%s:%s\">%s</option>\n",
                   2810:                     htmlquote($rev), (htmlquote($_)) x 2);
3.120     scop     2811:   }
                   2812:
                   2813:   my ($onlyonbranch, $onlybranchpoint);
3.254     scop     2814:   if ($onlyonbranch = $input{only_with_tag}) {
3.120     scop     2815:     $onlyonbranch = $symrev{$onlyonbranch};
3.275     scop     2816:     if ($onlyonbranch && $onlyonbranch =~ s/\b0\.//) {
3.120     scop     2817:       ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
                   2818:     } else {
                   2819:       $onlybranchpoint = $onlyonbranch;
                   2820:     }
                   2821:
                   2822:     if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
3.275     scop     2823:       fatal("404 Tag not found", 'Tag "<code>%s</code>" is not defined.',
3.254     scop     2824:             $input{only_with_tag});
3.120     scop     2825:     }
                   2826:   }
                   2827:
                   2828:   undef @revisions;
                   2829:
                   2830:   foreach (@allrevisions) {
                   2831:     ($br  = $_)  =~ s/\.\d+$//;
                   2832:     ($brp = $br) =~ s/\.\d+$//;
                   2833:     next if ($onlyonbranch
                   2834:              && $br ne $onlyonbranch
                   2835:              && $_  ne $onlybranchpoint);
3.261     scop     2836:     unshift(@revisions, $_);
3.120     scop     2837:   }
                   2838:
                   2839:   if ($logsort eq "date") {
                   2840:
                   2841:     # Sort the revisions in commit order an secondary sort on revision
                   2842:     # (secondary sort needed for imported sources, or the first main
                   2843:     # revision gets before the same revision on the 1.1.1 branch)
                   2844:     @revdisplayorder =
                   2845:       sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) } @revisions;
                   2846:   } elsif ($logsort eq "rev") {
                   2847:
                   2848:     # Sort the revisions in revision order, highest first
                   2849:     @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
                   2850:   } else {
                   2851:
                   2852:     # No sorting. Present in the same order as rlog / cvs log
                   2853:     @revdisplayorder = @revisions;
                   2854:   }
                   2855:
3.217     scop     2856:   return $curbranch;
3.120     scop     2857: }
                   2858:
3.175     scop     2859:
3.225     scop     2860: sub getDiffLinks($$$)
3.120     scop     2861: {
3.225     scop     2862:   my ($url, $mimetype, $isbin) = @_;
                   2863:
                   2864:   my @links = ();
                   2865:   if (!$isbin) { # Offer ordinary diff only for non-binary files.
                   2866:     push(@links, &link('preferred', $url));
                   2867:     for my $difftype ($DIFFTYPES{$defaultDiffType}{colored} ? qw(u) : qw(h)) {
                   2868:       my $f = $difftype eq $defaultDiffType ? '' : $difftype;
                   2869:       push(@links,
                   2870:            &link(htmlquote(lc($DIFFTYPES{$difftype}{descr})), "$url;f=$f"));
                   2871:     }
                   2872:   }
                   2873:   if (my $extdiffs = $DIFF_COMMANDS{lc($mimetype)}) {
                   2874:     for my $i (0 .. scalar(@$extdiffs)-1) {
                   2875:       my $extdiff = $extdiffs->[$i];
                   2876:       push(@links, &link(htmlquote($extdiff->{name}), "$url;f=ext$i"))
                   2877:         if ($extdiff->{cmd} && $extdiff->{name});
                   2878:     }
3.120     scop     2879:   }
3.225     scop     2880:   return @links;
3.120     scop     2881: }
                   2882:
3.175     scop     2883:
3.219     scop     2884: sub printLog($$$;$$)
3.120     scop     2885: {
3.219     scop     2886:   # inlogview: 1 if in log view, otherwise in markup view.
                   2887:   ($_, my $mimetype, my $isbin, my $inlogview, my $isSelected) = @_;
3.175     scop     2888:   (my $br  = $_)  =~ s/\.\d+$//;
                   2889:   (my $brp = $br) =~ s/\.?\d+$//;
3.120     scop     2890:
3.219     scop     2891:   print "<a name=\"rev$_\"></a>";
                   2892:   if (defined($revsym{$_})) {
3.261     scop     2893:     foreach my $sym (split(", ", $revsym{$_})) {
3.271     scop     2894:       print '<a name="', htmlquote($sym), '"></a>';
3.120     scop     2895:     }
3.219     scop     2896:   }
                   2897:   if ($revsym{$br} && !defined($nameprinted{$br})) {
3.261     scop     2898:     foreach my $sym (split(", ", $revsym{$br})) {
3.271     scop     2899:       print '<a name="', htmlquote($sym), '"></a>';
3.120     scop     2900:     }
3.219     scop     2901:     $nameprinted{$br} = 1;
                   2902:   }
3.120     scop     2903:
3.271     scop     2904:   print "\n Revision <b>$_</b>";
3.219     scop     2905:   if (/^1\.1\.1\.\d+$/) {
                   2906:     print " <i>(vendor branch)</i>";
                   2907:   }
3.261     scop     2908:
3.271     scop     2909:   (my $filename = $where) =~ s|^.*/||;
                   2910:   my $fileurl   = uri_escape($filename);
                   2911:   undef $filename;
                   2912:
3.261     scop     2913:   my $isDead = ($state{$_} eq 'dead');
3.219     scop     2914:   if (!$isDead) {
3.261     scop     2915:
3.220     scop     2916:     print ': ', download_link($fileurl, $_, 'download', $mimetype);
3.219     scop     2917:
                   2918:     my @vlinks = ();
                   2919:     push(@vlinks, display_link($fileurl, $_, 'text', 'text/plain'))
                   2920:       unless $isbin;
                   2921:     push(@vlinks, display_link($fileurl, $_, 'markup', 'text/x-cvsweb-markup'))
                   2922:       if ($allow_markup && $inlogview && (!$isbin || viewable($mimetype)));
3.268     scop     2923:     if (!$isbin && $allow_annotate) {
3.219     scop     2924:       push(@vlinks,
                   2925:            &link('annotated',
3.271     scop     2926:                  sprintf('%s?annotate=%s%s', $fileurl, $_, $barequery)));
3.219     scop     2927:     }
                   2928:     print ' - view: ', join(', ', @vlinks) if @vlinks;
                   2929:     undef @vlinks;
                   2930:
3.243     scop     2931:     if (!$isbin && $allow_version_select) {
                   2932:       print ' - ';
                   2933:       if ($isSelected) {
                   2934:         print '<b>[selected&nbsp;for&nbsp;diffs]</b>';
                   2935:       } else {
                   2936:         print &link('select&nbsp;for&nbsp;diffs',
                   2937:                     sprintf('%s?r1=%s%s#rev%s',
3.271     scop     2938:                             $fileurl, $_, $barequery, $_));
3.120     scop     2939:       }
                   2940:     }
3.243     scop     2941:     print ' - ', graph_link('', 'revision graph')
                   2942:       if (!$inlogview && $allow_cvsgraph);
3.120     scop     2943:   }
3.219     scop     2944:   print "<br />\n";
3.120     scop     2945:
3.219     scop     2946:   print '<i>';
3.120     scop     2947:   if (defined @mytz) {
                   2948:     my ($est) = $mytz[(localtime($date{$_}))[8]];
3.219     scop     2949:     print scalar localtime($date{$_}), " $est</i> (";
3.120     scop     2950:   } else {
3.219     scop     2951:     print scalar gmtime($date{$_}), " UTC</i> (";
3.120     scop     2952:   }
3.136     scop     2953:   print readableTime(time() - $date{$_}, 1), ' ago)';
3.208     scop     2954:   print ' by <i>', htmlquote($author{$_}), "</i><br />\n";
3.136     scop     2955:
3.243     scop     2956:   printf("Branches: %s<br />\n", link_tags($revsym{$br})) if $revsym{$br};
                   2957:   printf("CVS tags: %s<br />\n", link_tags($revsym{$_}))  if $revsym{$_};
                   2958:   printf("Branch point for: %s<br />\n", link_tags($branchpoint{$_}))
                   2959:     if $branchpoint{$_};
3.120     scop     2960:
                   2961:   # Find the previous revision
3.175     scop     2962:   my $prev;
3.261     scop     2963:   my @prevrev = split(/\./, $_);
3.120     scop     2964:   do {
                   2965:     if (--$prevrev[$#prevrev] <= 0) {
                   2966:
                   2967:       # If it was X.Y.Z.1, just make it X.Y
                   2968:       pop (@prevrev);
                   2969:       pop (@prevrev);
                   2970:     }
                   2971:     $prev = join (".", @prevrev);
                   2972:   } until (defined($date{$prev}) || $prev eq "");
                   2973:
                   2974:   if ($isDead) {
3.219     scop     2975:     print "<b><i>FILE REMOVED</i></b><br />\n";
3.243     scop     2976:   } else {
3.120     scop     2977:     my %diffrev = ();
                   2978:     $diffrev{$_} = 1;
                   2979:     $diffrev{""} = 1;
                   2980:     my $diff = 'Diff';
3.219     scop     2981:     my $printed = 0;
3.120     scop     2982:
                   2983:     #
                   2984:     # Offer diff to previous revision
                   2985:     if ($prev) {
                   2986:       $diffrev{$prev} = 1;
                   2987:       my $url =
3.271     scop     2988:         sprintf('%s.diff?r1=%s;r2=%s%s', $fileurl, $prev, $_, $barequery);
3.225     scop     2989:       if (my @dlinks = getDiffLinks($url, $mimetype, $isbin)) {
                   2990:         print $diff, ' to previous ', $prev, ': ', join(', ', @dlinks);
                   2991:         $diff = ''; $printed = 1;
                   2992:       }
3.120     scop     2993:     }
                   2994:
                   2995:     #
                   2996:     # Plus, if it's on a branch, and it's not a vendor branch,
                   2997:     # offer a diff with the branch point.
                   2998:     if ($revsym{$brp}
                   2999:       && !/^1\.1\.1\.\d+$/
                   3000:       && !defined($diffrev{$brp}))
                   3001:     {
                   3002:       my $url =
3.271     scop     3003:         sprintf('%s.diff?r1=%s;r2=%s%s', $fileurl, $brp, $_, $barequery);
3.225     scop     3004:       if (my @dlinks = getDiffLinks($url, $mimetype, $isbin)) {
                   3005:         print $diff, ' to branchpoint ', $brp, ': ', join(', ', @dlinks);
                   3006:         $diff = ''; $printed = 1;
                   3007:       }
3.120     scop     3008:     }
                   3009:
                   3010:     #
                   3011:     # Plus, if it's on a branch, and it's not a vendor branch,
                   3012:     # offer to diff with the next revision of the higher branch.
                   3013:     # (e.g. change gets committed and then brought
                   3014:     # over to -stable)
                   3015:     if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
                   3016:       my ($i, $nextmain);
                   3017:
                   3018:       for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++) {
                   3019:       }
3.261     scop     3020:       my @tmp2 = split(/\./, $_);
3.120     scop     3021:       for ($nextmain = ""; $i > 0; $i--) {
                   3022:         my $next = $revorder[$i - 1];
3.261     scop     3023:         my @tmp1 = split(/\./, $next);
3.120     scop     3024:
                   3025:         if (@tmp1 < @tmp2) {
                   3026:           $nextmain = $next;
                   3027:           last;
                   3028:         }
                   3029:
                   3030:         # Only the highest version on a branch should have
                   3031:         # a diff for the "next main".
                   3032:         last
                   3033:           if (@tmp1 - 1 <= @tmp2
                   3034:           && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
                   3035:           join (".", @tmp2[0 .. $#tmp1 - 1]));
                   3036:       }
                   3037:
                   3038:       if (!defined($diffrev{$nextmain})) {
                   3039:         $diffrev{$nextmain} = 1;
3.203     scop     3040:         my $url = sprintf('%s.diff?r1=%s;r2=%s%s',
3.271     scop     3041:           $fileurl, $nextmain, $_, $barequery);
3.225     scop     3042:         if (my @dlinks = getDiffLinks($url, $mimetype, $isbin)) {
                   3043:           print $diff, ' next main ', $nextmain, ': ', join(', ', @dlinks);
                   3044:           $diff = ''; $printed = 1;
                   3045:         }
3.120     scop     3046:       }
                   3047:     }
                   3048:
                   3049:     # Plus if user has selected only r1, then present a link
                   3050:     # to make a diff to that revision
3.254     scop     3051:     if (defined($input{r1}) && !defined($diffrev{$input{r1}})) {
                   3052:       $diffrev{$input{r1}} = 1;
3.203     scop     3053:       my $url = sprintf('%s.diff?r1=%s;r2=%s%s',
3.271     scop     3054:         $fileurl, $input{r1}, $_, $barequery);
3.225     scop     3055:       if (my @dlinks = getDiffLinks($url, $mimetype, $isbin)) {
                   3056:         print $diff, ' to selected ', $input{r1}, ': ', join(', ', @dlinks);
                   3057:         $diff = ''; $printed = 1;
                   3058:       }
3.120     scop     3059:     }
                   3060:
3.219     scop     3061:     print "<br />\n" if $printed;
                   3062:   }
                   3063:
                   3064:   if ($prev ne "" && $difflines{$_}) {
                   3065:     printf "Changes since revision %s: %s lines<br />\n",
                   3066:       htmlquote($prev), htmlquote($difflines{$_});
3.120     scop     3067:   }
3.189     scop     3068:
3.219     scop     3069:   print "<pre class=\"log\">\n";
3.120     scop     3070:   print &htmlify($log{$_}, $allow_log_extra);
                   3071:   print "</pre>\n";
                   3072: }
                   3073:
3.175     scop     3074:
3.132     scop     3075: #
                   3076: # Generates the HTML view for CvsGraph.
                   3077: #
3.170     scop     3078: sub doGraphView()
3.132     scop     3079: {
                   3080:   (my $pathname = $where) =~ s|[^/]*$||;
                   3081:   (my $filename = $where) =~ s|^.*/||;
                   3082:
3.170     scop     3083:   navigateHeader($scriptwhere, $pathname, $filename, undef, 'graph');
3.132     scop     3084:
3.146     scop     3085:   my $title = 'Revision graph of ' . htmlquote($pathname . $filename);
3.132     scop     3086:   my $mapname = 'CvsGraphMap';
                   3087:
3.170     scop     3088:   printf(<<EOF, $title, $mapname, $cvstree, $title);
3.146     scop     3089: <h3 style="text-align: center">%s</h3>
3.219     scop     3090: <div style="text-align: center"><img border="0" usemap="#%s" src="?cvsroot=%s;graph=1;makeimage=1" alt="%s" />
3.146     scop     3091: EOF
3.132     scop     3092:
3.255     scop     3093:   # Remove any pre-existing tag/branch names from branch links.
3.271     scop     3094:   (my $notag_query = $barequery) =~ s/;+only_with_tag=.*?(?=;|$)//g;
3.255     scop     3095:
3.135     scop     3096:   my @graph_cmd =
                   3097:     ($CMD{cvsgraph},
                   3098:      '-r', $cvsroot,
3.249     scop     3099:      '-m', $pathname,
3.135     scop     3100:      '-i',
                   3101:      '-M', $mapname,
3.208     scop     3102:      '-x', 'x',
3.271     scop     3103:      "-Omap_branch_href=\"href=\\\"./?only_with_tag=%(%t%)$notag_query\\\"\"",
                   3104:      "-Omap_rev_href=\"href=\\\"?rev=%(%R%)$barequery\\\"\"",
3.146     scop     3105:      "-Omap_diff_href=\"href=\\\"%(%F%).diff" .
3.271     scop     3106:      "?r1=%(%P%);r2=%(%R%)$barequery\\\"\"",
3.135     scop     3107:      );
3.132     scop     3108:   push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
3.249     scop     3109:   push(@graph_cmd, $filename . ',v');
3.132     scop     3110:
3.174     scop     3111:   local *CVSGRAPH_OUT;
                   3112:   my ($h, $err) =
3.229     scop     3113:     startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT);
3.174     scop     3114:   fatal('500 Internal Error', $err) unless $h;
3.242     scop     3115:
                   3116:   # Browser compatibility kludge: many browsers do not support client side
                   3117:   # image maps where the <map> element contains only the id attribute.  Let's
                   3118:   # add the corresponding name attribute to it on the fly.
                   3119:   while (<CVSGRAPH_OUT>) {
                   3120:     s/(<map\s+id="([^"]+)")\s*>/$1 name="$2">/;
                   3121:     print;
3.132     scop     3122:   }
3.242     scop     3123:
3.229     scop     3124:   $h->finish();
3.219     scop     3125:   print "</div>\n";
3.132     scop     3126:
                   3127:   html_footer();
                   3128: }
                   3129:
3.175     scop     3130:
3.132     scop     3131: #
                   3132: # Generates a graph using CvsGraph.
                   3133: #
3.170     scop     3134: sub doGraph()
3.132     scop     3135: {
                   3136:   (my $pathname = $where) =~ s|[^/]*$||;
                   3137:   (my $filename = $where) =~ s|^.*/||;
                   3138:
                   3139:   http_header('image/png');
                   3140:
3.249     scop     3141:   my @graph_cmd = ($CMD{cvsgraph}, '-r', $cvsroot, '-m', $pathname);
3.132     scop     3142:   push(@graph_cmd, '-c', $cvsgraph_config) if $cvsgraph_config;
3.249     scop     3143:   push(@graph_cmd, $filename . ',v');
3.132     scop     3144:
3.174     scop     3145:   local *CVSGRAPH_OUT;
                   3146:   my ($h, $err) =
3.229     scop     3147:     startproc(\@graph_cmd, \"", '>pipe', \*CVSGRAPH_OUT);
3.174     scop     3148:   fatal('500 Internal Error', $err) unless $h;
3.132     scop     3149:   {
                   3150:     local $/ = undef;
                   3151:     binmode(\*STDOUT);
3.174     scop     3152:     print <CVSGRAPH_OUT>;
3.132     scop     3153:   }
3.229     scop     3154:   $h->finish();
3.132     scop     3155: }
                   3156:
                   3157:
3.120     scop     3158: sub doLog($)
                   3159: {
                   3160:   my ($fullname) = @_;
                   3161:
3.217     scop     3162:   my $curbranch = readLog($fullname);
3.120     scop     3163:
                   3164:   html_header("CVS log for $where");
3.144     scop     3165:
3.271     scop     3166:   my $upwhere = $where;
3.144     scop     3167:   (my $filename = $where) =~ s|^.*/||;
3.271     scop     3168:   my $backurl = "./$query#" . uri_escape($filename);
                   3169:   if ($where =~ m|^(.*?)((?<=/)Attic/)?[^/]+$|) {
                   3170:     $upwhere = $1;
                   3171:     $backurl = ".$backurl" if $2; # skip over Attic
                   3172:   }
3.144     scop     3173:
3.219     scop     3174:   my $isbin = $keywordsubstitution =~ /b/;
                   3175:   my $mimetype = getMimeType($filename, $isbin);
                   3176:
3.120     scop     3177:   print "<p>\n ";
3.271     scop     3178:   print &link($backicon, $backurl), " <b>Up to ",
3.120     scop     3179:     &clickablePath($upwhere, 1), "</b>\n</p>\n";
                   3180:   print "<p>\n ";
                   3181:   print &link('Request diff between arbitrary revisions', '#diff');
3.268     scop     3182:   print ' - ', &graph_link('', 'Display revisions graphically')
                   3183:     if $allow_cvsgraph;
3.258     scop     3184:   if ($cvshistory_url) {
                   3185:     (my $d = $upwhere) =~ s|/+$||;
                   3186:     print ' - ', history_link($d, $filename);
                   3187:   }
3.208     scop     3188:   print "\n</p>\n<hr />\n";
3.120     scop     3189:
                   3190:   print "<p>\n";
3.152     scop     3191:
3.219     scop     3192:   my $explain = $isbin ? ' (i.e.: CVS considers this a binary file)' : '';
3.208     scop     3193:   print "Keyword substitution: $keywordsubstitution$explain<br />\n";
3.217     scop     3194:   if ($curbranch) {
                   3195:     print "Default branch: ", ($revsym{$curbranch} || $curbranch);
                   3196:   } else {
                   3197:     print "No default branch";
                   3198:   }
3.208     scop     3199:   print "<br />\n";
3.120     scop     3200:
3.208     scop     3201:   print 'Current tag: ', htmlquote($input{only_with_tag}), "<br />\n"
3.153     scop     3202:     if $input{only_with_tag};
3.120     scop     3203:   print "</p>\n";
                   3204:
                   3205:   undef %nameprinted;
                   3206:
3.182     scop     3207:   for my $r (@revdisplayorder) {
3.208     scop     3208:     print "<hr />\n";
3.182     scop     3209:     my $sel = (defined($input{r1}) && $input{r1} eq $r);
                   3210:     print "<div class=\"diff-selected\">\n" if $sel;
3.219     scop     3211:     printLog($r, $mimetype, $isbin, 1, $sel);
3.182     scop     3212:     print "</div>\n" if $sel;
3.120     scop     3213:   }
                   3214:
3.144     scop     3215:   printf(<<EOF, $scriptwhere);
3.208     scop     3216: <hr />
                   3217: <form method="get" action="%s.diff" id="diff_select">
3.189     scop     3218: <fieldset>
                   3219: <legend>Diff request</legend>
3.144     scop     3220: <p>
                   3221:  <a name="diff">
3.189     scop     3222:   This form allows you to request diffs between any two revisions of a file.
3.144     scop     3223:   You may select a symbolic revision name using the selection box or you may
                   3224:   type in a numeric name using the type-in text box.
                   3225:  </a>
                   3226: </p>
                   3227: EOF
3.120     scop     3228:
                   3229:   foreach (@stickyvars) {
3.208     scop     3230:     printf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n",
3.154     scop     3231:            $_, htmlquote($input{$_}))
3.194     scop     3232:       if (defined($input{$_}) &&
                   3233:           (!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_}));
3.120     scop     3234:   }
3.144     scop     3235:
                   3236:   print <<EOF;
3.189     scop     3237: <table summary="Diff between arbitrary revisions">
3.144     scop     3238: <tr>
3.189     scop     3239: <td class="opt-label">
                   3240: <label for="r1" accesskey="1">Diffs between</label>
                   3241: </td>
                   3242: <td class="opt-value">
3.144     scop     3243: <select id="r1" name="r1">
3.208     scop     3244: <option value="text" selected="selected">Use Text Field</option>
3.144     scop     3245: EOF
                   3246:   print $sel, "</select>\n";
                   3247:
                   3248:   my $diffrev = defined($input{r1}) ?
                   3249:     $input{r1} : $revdisplayorder[$#revdisplayorder];
                   3250:
                   3251:   printf(<<EOF, $inputTextSize, $diffrev);
3.208     scop     3252: <input type="text" size="%s" name="tr1" value="%s" onchange="this.form.r1.selectedIndex=0" />
3.144     scop     3253: </td>
3.189     scop     3254: <td></td>
                   3255: </tr>
                   3256: <tr>
                   3257: <td class="opt-label">
                   3258: <label for="r2" accesskey="2">and</label>
                   3259: </td>
                   3260: <td class="opt-value">
3.144     scop     3261: <select id="r2" name="r2">
3.208     scop     3262: <option value="text" selected="selected">Use Text Field</option>
3.144     scop     3263: EOF
                   3264:   print $sel, "</select>\n";
                   3265:
                   3266:   $diffrev = defined($input{r2}) ? $input{r2} : $revdisplayorder[0];
                   3267:
                   3268:   printf(<<EOF, $inputTextSize, $diffrev, $scriptwhere);
3.208     scop     3269: <input type="text" size="%s" name="tr2" value="%s" onchange="this.form.r2.selectedIndex=0" />
3.144     scop     3270: </td>
3.208     scop     3271: <td><input type="submit" value="Get Diffs" accesskey="G" /></td>
3.144     scop     3272: </tr>
                   3273: </table>
3.189     scop     3274: </fieldset>
3.144     scop     3275: </form>
                   3276: <form method="get" action="%s">
3.189     scop     3277: <fieldset>
                   3278: <legend>Log view options</legend>
                   3279: <table summary="Log view options">
3.144     scop     3280: <tr>
3.189     scop     3281: <td class="opt-label">
                   3282: <label for="f" accesskey="D">Preferred diff type:</label>
                   3283: </td>
                   3284: <td class="opt-value">
3.144     scop     3285: EOF
3.120     scop     3286:   printDiffSelect($use_java_script);
3.144     scop     3287:   print <<EOF;
3.189     scop     3288: </td>
                   3289: <td></td>
3.144     scop     3290: </tr>
                   3291: EOF
3.120     scop     3292:
                   3293:   if (@branchnames) {
3.144     scop     3294:
                   3295:     printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
                   3296: <tr>
3.189     scop     3297: <td class="opt-label">
3.188     scop     3298: <label for="only_with_tag" accesskey="B">View only branch:</label>
3.189     scop     3299: </td>
                   3300: <td class="opt-value">
                   3301: <a name="branch">
3.144     scop     3302: <select id="only_with_tag" name="only_with_tag"%s>
                   3303: EOF
3.120     scop     3304:
3.193     scop     3305:     my @tmp = ();
                   3306:     my $selfound = 0;
3.120     scop     3307:     foreach (reverse sort @branchnames) {
3.136     scop     3308:       my $selected =
3.254     scop     3309:         (defined($input{only_with_tag}) && $input{only_with_tag} eq $_);
3.193     scop     3310:       $selfound ||= $selected;
                   3311:       push(@tmp, sprintf('<option%s>%s</option>',
3.208     scop     3312:                          $selected ? ' selected="selected"' : '',
3.193     scop     3313:                          htmlquote($_)));
3.120     scop     3314:     }
3.193     scop     3315:     printf("<option value=\"\"%s>Show all branches</option>\n",
3.208     scop     3316:            $selfound ? '' : ' selected="selected"');
3.193     scop     3317:     print join("\n", @tmp);
                   3318:
3.144     scop     3319:     print <<EOF
                   3320: </select>
3.189     scop     3321: </a>
3.144     scop     3322: </td>
                   3323: <td></td>
                   3324: </tr>
                   3325: EOF
3.120     scop     3326:   }
                   3327:
3.144     scop     3328:   print <<EOF;
3.189     scop     3329: <tr>
                   3330: <td class="opt-label">
                   3331: <label for="logsort" accesskey="L">Sort log by:</label>
                   3332: </td>
                   3333: <td>
3.144     scop     3334: EOF
3.120     scop     3335:   printLogSortSelect($use_java_script);
3.144     scop     3336:   print <<EOF;
3.189     scop     3337: </td>
3.208     scop     3338: <td><input type="submit" value="Set" accesskey="S" /></td>
3.189     scop     3339: </tr>
3.144     scop     3340: </table>
                   3341: EOF
3.154     scop     3342:   foreach (@stickyvars) {
                   3343:     next if ($_ eq "f");
                   3344:     next if ($_ eq "only_with_tag");
                   3345:     next if ($_ eq "logsort");
3.208     scop     3346:     printf("<input type=\"hidden\" name=\"$_\" value=\"%s\" />\n",
3.154     scop     3347:            htmlquote($input{$_}))
                   3348:       if (defined($input{$_})
3.194     scop     3349:           && (!defined($DEFAULTVALUE{$_}) || $input{$_} ne $DEFAULTVALUE{$_}));
3.154     scop     3350:   }
3.189     scop     3351:   print "</fieldset>\n</form>\n";
3.120     scop     3352:   html_footer();
                   3353: }
                   3354:
3.175     scop     3355:
3.120     scop     3356: sub flush_diff_rows($$$$)
                   3357: {
                   3358:   my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
                   3359:
3.175     scop     3360:   return unless defined($state);
3.120     scop     3361:
                   3362:   if ($state eq "PreChangeRemove") {    # we just got remove-lines before
3.133     scop     3363:     for (my $j = 0; $j < $leftRow; $j++) {
3.256     scop     3364:       printf(<<EOF, spacedHtmlText(@$leftColRef[$j]));
3.144     scop     3365: <tr>
3.260     scop     3366:  <td class="diff diff-removed">&nbsp;%s</td>
                   3367:  <td class="diff diff-empty">&nbsp;</td>
3.144     scop     3368: </tr>
                   3369: EOF
3.120     scop     3370:     }
                   3371:   } elsif ($state eq "PreChange") {     # state eq "PreChange"
                   3372:                                         # we got removes with subsequent adds
3.222     scop     3373:     if (HAS_EDIFF) {
3.176     scop     3374:       # construct the suffix tree
                   3375:       my $left_diff = join("\n", @$leftColRef[0..$leftRow-1]);
                   3376:       my $right_diff = join("\n", @$rightColRef[0..$rightRow-1]);
                   3377:       my $diff_str = String::Ediff::ediff($left_diff, $right_diff);
                   3378:
                   3379:       my @diff_str = split(/ /, $diff_str);
                   3380:       my $INFINITY = 10000000;
                   3381:       push(@diff_str, ($INFINITY) x 8);
                   3382:       my ($idx, $b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
                   3383:         (0, @diff_str[0..7]);
                   3384:       my ($l_cul, $r_cul) = (0, 0);
                   3385:       my ($ldx, $rdx) = (0, 0);
                   3386:       my (@left_html, @right_html);
                   3387:       for (my $j = 0; $j < $leftRow; $j++) {
                   3388:         my $line_len = length(@$leftColRef[$j]);
                   3389:         my $line = @$leftColRef[$j];
                   3390:         $l_cul += length($line) + 1; # includes "\n"
                   3391:         my $l_culx = $l_cul - 1; # not includes "\n"
                   3392:         if ($j < $lb1) {
                   3393:           $line = spacedHtmlText($line);
3.260     scop     3394:           push(@left_html, "<td class=\"diff diff-changed\">$line</td>");
3.176     scop     3395:         } elsif ($lb1 == $j) {
                   3396:           my $html_line;
                   3397:           while ($lb1 == $j) {
                   3398:             my $begin_char = $l_culx - $b1;
                   3399:
                   3400:             $line =~ /^(.*)(.{$begin_char})$/;
                   3401:             $html_line .= spacedHtmlText($1) .
3.260     scop     3402:               '</span><span class="diff diff-unchanged">';
3.176     scop     3403:             $line = $2;
                   3404:             last if ($j != $le1);
                   3405:
                   3406:             my $end_char = $l_culx - $e1;
                   3407:             $line =~ /^(.*)(.{$end_char})$/;
                   3408:             $html_line .= spacedHtmlText($1) .
3.260     scop     3409:               '</span><span class="diff diff-changed">';
3.176     scop     3410:             $line = $2;
                   3411:
                   3412:             $idx++;
                   3413:             my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
                   3414:               ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
                   3415:             ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
                   3416:               @diff_str[$idx*8..($idx+1)*8-1];
                   3417:             $lb1 = $INFINITY if ($lb1 < 0);
                   3418:             $lb2 = $INFINITY if ($lb2 < 0);
                   3419:             $le1 = $INFINITY if ($le1 < 0);
                   3420:             $le2 = $INFINITY if ($le2 < 0);
                   3421:             if ($te1 > $b1) {
                   3422:               ($b1, $lb1) = ($te1, $tle1);
                   3423:             }
                   3424:             if ($te2 > $b2) {
                   3425:               ($b2, $lb2) = ($te2, $tle2);
                   3426:             }
                   3427:           }
                   3428:           push(@left_html,
3.260     scop     3429:                sprintf('<td><span class="diff diff-changed">%s%s</span></td>',
                   3430:                        $html_line, spacedHtmlText($line)));
3.176     scop     3431:         } elsif ($le1 == $j) {
                   3432:           my $html_line;
                   3433:           while ($le1 == $j) {
                   3434:             my $end_char = $l_culx - $e1;
                   3435:             $line =~ /^(.*)(.{$end_char})$/;
                   3436:             $html_line .= spacedHtmlText($1) .
3.260     scop     3437:               '</span><span class="diff diff-changed">';
3.176     scop     3438:             $line = $2;
                   3439:
                   3440:             $idx++;
                   3441:             my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
                   3442:               ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
                   3443:             ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
                   3444:               @diff_str[$idx*8..($idx+1)*8-1];
                   3445:             $lb1 = $INFINITY if ($lb1 < 0);
                   3446:             $lb2 = $INFINITY if ($lb2 < 0);
                   3447:             $le1 = $INFINITY if ($le1 < 0);
                   3448:             $le2 = $INFINITY if ($le2 < 0);
                   3449:             if ($te1 > $b1) {
                   3450:               ($b1, $lb1) = ($te1, $tle1);
                   3451:             }
                   3452:             if ($te2 > $b2) {
                   3453:               ($b2, $lb2) = ($te2, $tle2);
                   3454:             }
                   3455:
                   3456:             last if ($lb1 != $j);
                   3457:
                   3458:             my $begin_char = $l_culx - $b1;
                   3459:
                   3460:             $line =~ /^(.*)(.{$begin_char})$/;
                   3461:             $html_line .= spacedHtmlText($1) .
3.260     scop     3462:               '</span><span class="diff diff-unchanged">';
3.176     scop     3463:             $line = $2;
                   3464:           }
                   3465:           push(@left_html,
3.260     scop     3466:               sprintf('<td><span class="diff diff-unchanged">%s%s</span></td>',
                   3467:                       $html_line, spacedHtmlText($line)));
3.176     scop     3468:         } else {
                   3469:           $line = spacedHtmlText($line);
3.260     scop     3470:           push(@left_html, "<td class=\"diff diff-unchanged\">$line</td>");
3.176     scop     3471:         }
                   3472:       }
                   3473:       ($idx, $b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
                   3474:         (0, @diff_str[0..7]);
                   3475:       $lb1 = $INFINITY if ($lb1 < 0);
                   3476:       $lb2 = $INFINITY if ($lb2 < 0);
                   3477:       $le1 = $INFINITY if ($le1 < 0);
                   3478:       $le2 = $INFINITY if ($le2 < 0);
                   3479:       for (my $j = 0; $j < $rightRow; $j++) {
                   3480:         my $line_len = length(@$rightColRef[$j]);
                   3481:         my $line = @$rightColRef[$j];
                   3482:         $r_cul += length($line) + 1; # includes "\n"
                   3483:         my $r_culx = $r_cul - 1; # not includes "\n"
                   3484:         if ($j < $lb2) {
                   3485:           $line = spacedHtmlText($line);
3.260     scop     3486:           push(@right_html, "<td class=\"diff diff-changed\">$line</td>");
3.176     scop     3487:         } elsif ($lb2 == $j) {
                   3488:           my $html_line;
                   3489:           while ($lb2 == $j) {
                   3490:             my $begin_char = $r_culx - $b2;
                   3491:
                   3492:             $line =~ /^(.*)(.{$begin_char})$/;
                   3493:             $html_line .= spacedHtmlText($1) .
3.260     scop     3494:               '</span><span class="diff diff-unchanged">';
3.176     scop     3495:             $line = $2;
                   3496:
                   3497:             last if ($j != $le2);
                   3498:
                   3499:             my $end_char = $r_culx - $e2;
                   3500:             $line =~ /^(.*)(.{$end_char})$/;
                   3501:             $html_line .= spacedHtmlText($1) .
3.260     scop     3502:               '</span><span class="diff diff-changed">';
3.176     scop     3503:             $line = $2;
                   3504:
                   3505:             $idx++;
                   3506:             my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
                   3507:               ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
                   3508:             ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
                   3509:               @diff_str[$idx*8..($idx+1)*8-1];
                   3510:             $lb1 = $INFINITY if ($lb1 < 0);
                   3511:             $lb2 = $INFINITY if ($lb2 < 0);
                   3512:             $le1 = $INFINITY if ($le1 < 0);
                   3513:             $le2 = $INFINITY if ($le2 < 0);
                   3514:             if ($te1 > $b1) {
                   3515:               ($b1, $lb1) = ($te1, $tle1);
                   3516:             }
                   3517:             if ($te2 > $b2) {
                   3518:               ($b2, $lb2) = ($te2, $tle2);
                   3519:             }
                   3520:           }
                   3521:           push(@right_html,
3.260     scop     3522:                sprintf('<td><span class="diff diff-changed">%s%s</span></td>',
                   3523:                        $html_line, spacedHtmlText($line)));
3.176     scop     3524:         } elsif ($le2 == $j) {
                   3525:           my $html_line;
                   3526:           while ($le2 == $j) {
                   3527:             my $end_char = $r_culx - $e2;
                   3528:             $line =~ /^(.*)(.{$end_char})$/;
                   3529:             $html_line .= spacedHtmlText($1) .
3.260     scop     3530:               '</span><span class="diff diff-changed">';
3.176     scop     3531:             $line = $2;
                   3532:
                   3533:             $idx++;
                   3534:             my ($tb1, $te1, $tlb1, $tle1, $tb2, $te2, $tlb2, $tle2) =
                   3535:               ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2);
                   3536:             ($b1, $e1, $lb1, $le1, $b2, $e2, $lb2, $le2) =
                   3537:               @diff_str[$idx*8..($idx+1)*8-1];
                   3538:             $lb1 = $INFINITY if ($lb1 < 0);
                   3539:             $lb2 = $INFINITY if ($lb2 < 0);
                   3540:             $le1 = $INFINITY if ($le1 < 0);
                   3541:             $le2 = $INFINITY if ($le2 < 0);
                   3542:             if ($te1 > $b1) {
                   3543:               ($b1, $lb1) = ($te1, $tle1);
                   3544:             }
                   3545:             if ($te2 > $b2) {
                   3546:               ($b2, $lb2) = ($te2, $tle2);
                   3547:             }
                   3548:
                   3549:             last if ($lb2 != $j);
                   3550:
                   3551:             my $begin_char = $r_culx - $b2;
                   3552:             $line =~ /^(.*)(.{$begin_char})$/;
                   3553:             $html_line .= spacedHtmlText($1) .
3.260     scop     3554:               '</span><span class="diff diff-unchanged">';
3.176     scop     3555:             $line = $2;
                   3556:           }
                   3557:           push(@right_html,
3.260     scop     3558:                sprintf('<td nowrap="nowrap"><span class="diff diff-unchanged"'.
                   3559:                        '>%s%s</span></td>',
                   3560:                        $html_line, spacedHtmlText($line)));
3.176     scop     3561:         } else {
                   3562:           $line = spacedHtmlText ($line);
3.260     scop     3563:           push @right_html, "<td class=\"diff diff-unchanged\">$line</td>";
3.176     scop     3564:         }
                   3565:       }
                   3566:       for (my $j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
                   3567:         print  '<tr>';
                   3568:         if ($j < $leftRow) {
                   3569:           print $left_html[$j];
                   3570:         } else {
3.260     scop     3571:           print '<td class="diff diff-changed-missing">&nbsp;</td>';
3.176     scop     3572:         }
                   3573:         if ($j < $rightRow) {
                   3574:           print $right_html[$j];
                   3575:         } else {
3.260     scop     3576:           print '<td class="diff diff-changed-missing">&nbsp;</td>';
3.176     scop     3577:         }
                   3578:         print "</tr>\n";
3.120     scop     3579:       }
3.176     scop     3580:     } else {
                   3581:       for (my $j = 0; $j < $leftRow || $j < $rightRow; $j++) { # dump both cols
                   3582:         print "<tr>\n";
                   3583:         if ($j < $leftRow) {
3.260     scop     3584:           print '<td class="diff diff-changed">&nbsp;' .
3.176     scop     3585:             spacedHtmlText(@$leftColRef[$j]) . '</td>';
                   3586:         } else {
3.260     scop     3587:           print '<td class="diff diff-changed-missing">&nbsp;</td>';
3.176     scop     3588:         }
                   3589:         print "\n";
3.120     scop     3590:
3.176     scop     3591:         if ($j < $rightRow) {
3.260     scop     3592:           print '<td class="diff diff-changed">&nbsp;' .
3.176     scop     3593:             spacedHtmlText(@$rightColRef[$j]) . '</td>';
                   3594:         } else {
3.260     scop     3595:           print '<td class="diff diff-changed-missing">&nbsp;</td>';
3.176     scop     3596:         }
                   3597:         print "\n</tr>\n";
3.120     scop     3598:       }
                   3599:     }
                   3600:   }
3.1       knu      3601: }
                   3602:
3.175     scop     3603:
3.263     scop     3604: #
                   3605: # Generates "human readable", HTMLified diffs.
                   3606: #
3.144     scop     3607: sub human_readable_diff($$)
3.120     scop     3608: {
                   3609:   my ($fh, $rev) = @_;
3.144     scop     3610:
3.169     scop     3611:   (my $where_nd       = $where)       =~ s|\.diff$||;
                   3612:   (my $filename       = $where_nd)    =~ s|^.*/||;
3.262     scop     3613:   (my $pathname       = $where_nd)    =~ s|((?<=/)Attic/)?[^/]*$||;
3.169     scop     3614:   (my $scriptwhere_nd = $scriptwhere) =~ s|\.diff$||;
3.120     scop     3615:
3.133     scop     3616:   navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, 'diff');
3.120     scop     3617:
3.178     scop     3618:   # Read header to pick up read revision and date, if possible.
                   3619:
                   3620:   my ($r1d, $r1r, $r2d, $r2r);
3.120     scop     3621:   while (<$fh>) {
                   3622:     ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
                   3623:     ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
                   3624:     last if (/^\+\+\+ /);
                   3625:   }
                   3626:
3.178     scop     3627:   my ($rev1, $date1);
3.120     scop     3628:   if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
                   3629:     $rev1  = $r1r;
                   3630:     $date1 = $r1d;
                   3631:   }
3.178     scop     3632:   my ($rev2, $date2);
3.120     scop     3633:   if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
                   3634:     $rev2  = $r2r;
                   3635:     $date2 = $r2d;
                   3636:   }
3.178     scop     3637:   $rev1  = 'unknown-left'  unless defined($rev1);
                   3638:   $rev2  = 'unknown-right' unless defined($rev2);
                   3639:   $date1 = defined($date1) ? ', ' . htmlquote($date1) : '';
                   3640:   $date2 = defined($date2) ? ', ' . htmlquote($date2) : '';
3.120     scop     3641:
3.281     scop     3642:   my $link = uri_escape($filename) . ($query ? "$query;" : '?');
3.210     scop     3643:
3.144     scop     3644:   # Using <table style=\"border: none\" here breaks NS 4.x badly...
3.210     scop     3645:   print <<EOF;
                   3646: <h3 style="text-align: center">Diff for /$where_nd between versions $rev1 and $rev2</h3>
                   3647: <table border="0" cellspacing="0" cellpadding="0" width="100%" summary="Diff output">
3.144     scop     3648: <tr style="background-color: #ffffff">
3.210     scop     3649: <th style="text-align: center; vertical-align: top" width="50%">
3.281     scop     3650: <a href="${link}rev=$rev1">version $rev1</a>$date1
3.178     scop     3651: </th>
3.210     scop     3652: <th style="text-align: center; vertical-align: top" width="50%">
3.281     scop     3653: <a href="${link}rev=$rev2">version $rev2</a>$date2
3.144     scop     3654: </th>
3.178     scop     3655: </tr>
3.144     scop     3656: EOF
3.120     scop     3657:
                   3658:   # Process diff text
                   3659:   # prefetch several lines
                   3660:   my @buf = head($fh);
3.144     scop     3661:   my %d = scan_directives(@buf);
3.120     scop     3662:
3.144     scop     3663:   my $leftRow  = 0;
                   3664:   my $rightRow = 0;
                   3665:   my ($difftxt, @rightCol, @leftCol, $oldline, $newline, $funname);
3.120     scop     3666:
3.281     scop     3667:   $link .= 'content-type=text%2Fx-cvsweb-markup;';
                   3668:   $link .= 'ln=1;' unless ($link =~ /\?.*\bln=1\b/);
3.210     scop     3669:
3.120     scop     3670:   while (@buf || !eof($fh)) {
                   3671:     $difftxt = @buf ? shift @buf : <$fh>;
                   3672:
                   3673:     if ($difftxt =~ /^@@/) {
                   3674:       ($oldline, $newline, $funname) =
                   3675:         $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
                   3676:       $funname = htmlquote($funname);
                   3677:       $funname =~ s/\s/&nbsp;/go;
3.182     scop     3678:       $funname &&= "&nbsp;<span style=\"font-size: smaller\">$funname</span>";
3.210     scop     3679:       my $ol = $oldline || 1;
                   3680:       my $nl = $newline || 1;
3.144     scop     3681:
3.210     scop     3682:       print <<EOF;
3.182     scop     3683: <tr>
3.210     scop     3684: <td width="50%" class="diff-heading">
3.281     scop     3685:  <b><a href="${link}rev=$rev1#l$ol">Line&nbsp;$oldline</a></b>$funname
3.182     scop     3686: </td>
3.210     scop     3687: <td width="50%" class="diff-heading">
3.281     scop     3688:  <b><a href="${link}rev=$rev2#l$nl">Line&nbsp;$newline</a></b>$funname
3.144     scop     3689: </td>
3.208     scop     3690: </tr>
3.144     scop     3691: EOF
                   3692:
3.120     scop     3693:       $state    = "dump";
                   3694:       $leftRow  = 0;
                   3695:       $rightRow = 0;
                   3696:     } else {
3.224     scop     3697:       my ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
                   3698:       $diffcode = '' unless defined($diffcode);
3.176     scop     3699:       $_ = $rest;
3.120     scop     3700:
                   3701:       #########
                   3702:       # little state machine to parse unified-diff output (Hen, zeller@think.de)
                   3703:       # in order to get some nice 'ediff'-mode output
                   3704:       # states:
                   3705:       #  "dump"             - just dump the value
                   3706:       #  "PreChangeRemove"  - we began with '-' .. so this could be the start of a 'change' area or just remove
                   3707:       #  "PreChange"        - okey, we got several '-' lines and moved to '+' lines -> this is a change block
                   3708:       ##########
                   3709:
                   3710:       if ($diffcode eq '+') {
                   3711:         if ($state eq "dump")
                   3712:         {    # 'change' never begins with '+': just dump out value
3.254     scop     3713:           $_ = spacedHtmlText($rest, $d{tabstop});
3.144     scop     3714:           printf(<<EOF, $_);
                   3715: <tr>
3.260     scop     3716:  <td class="diff diff-empty">&nbsp;</td>
                   3717:  <td class="diff diff-added">&nbsp;%s</td>
3.144     scop     3718: </tr>
                   3719: EOF
3.120     scop     3720:         } else {    # we got minus before
                   3721:           $state = "PreChange";
                   3722:           $rightCol[$rightRow++] = $_;
                   3723:         }
                   3724:       } elsif ($diffcode eq '-') {
                   3725:         $state = "PreChangeRemove";
                   3726:         $leftCol[$leftRow++] = $_;
                   3727:       } else {    # empty diffcode
                   3728:         flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3.254     scop     3729:         $_ = spacedHtmlText($rest, $d{tabstop});
3.147     scop     3730:         printf(<<EOF, $_, $_);
3.144     scop     3731: <tr>
3.260     scop     3732:  <td class="diff diff-same">&nbsp;%s</td>
                   3733:  <td class="diff diff-same">&nbsp;%s</td>
3.144     scop     3734: </tr>
                   3735: EOF
3.120     scop     3736:         $state    = "dump";
                   3737:         $leftRow  = 0;
                   3738:         $rightRow = 0;
                   3739:       }
                   3740:     }
                   3741:   }
                   3742:   close($fh);
                   3743:
                   3744:   flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
                   3745:
                   3746:   # state is empty if we didn't have any change
                   3747:   if (!$state) {
3.144     scop     3748:     print <<EOF;
                   3749: <tr>
                   3750:  <td colspan="2">&nbsp;</td>
                   3751: </tr>
3.260     scop     3752: <tr class="diff diff-empty">
3.144     scop     3753:  <td colspan="2" align="center"><b>- No viewable change -</b></td>
                   3754: </tr>
                   3755: EOF
3.120     scop     3756:   }
                   3757:
3.182     scop     3758:   printf(<<EOF, $scriptwhere);
3.144     scop     3759: </table>
3.208     scop     3760: <hr style="width: 100%%" />
3.144     scop     3761: <form method="get" action="%s">
3.182     scop     3762: <div style="float: left">
3.208     scop     3763: <label for="f">Diff format:<br />
3.144     scop     3764: EOF
3.168     scop     3765:   printDiffSelectStickyVars();
3.120     scop     3766:   printDiffSelect($use_java_script);
3.182     scop     3767:   printf(<<EOF, $rev1, $rev2);
3.179     scop     3768: </label>
3.208     scop     3769: <input type="submit" value="Show" />
3.182     scop     3770: </div>
                   3771: <table style="float: right; border: thin outset" cellspacing="0" cellpadding="1" title="Legend" summary="Legend">
                   3772:  <tr>
3.260     scop     3773:   <td align="center" class="diff diff-removed">Removed from v.%s</td>
                   3774:   <td class="diff diff-empty">&nbsp;</td>
                   3775:  </tr><tr class="diff diff-changed">
3.182     scop     3776:   <td align="center" colspan="2">changed lines</td>
                   3777:  </tr><tr>
3.260     scop     3778:   <td class="diff diff-empty">&nbsp;</td>
                   3779:   <td align="center" class="diff diff-added">Added in v.%s</td>
3.182     scop     3780:  </tr>
3.144     scop     3781: </table>
                   3782: </form>
3.208     scop     3783: <br clear="all" />
3.144     scop     3784: EOF
3.120     scop     3785: }
3.167     scop     3786:
                   3787:
3.245     scop     3788: sub doEnscript($$$;$)
3.167     scop     3789: {
3.240     scop     3790:   my ($filehandle, $highlight, $linenumbers, $lang) = @_;
                   3791:   $lang ||= 'cvsweb';
3.167     scop     3792:
3.174     scop     3793:   my @cmd = ($CMD{enscript},
                   3794:              @enscript_options,
3.240     scop     3795:              '-q', "--language=$lang", '-o', '-', "--highlight=$highlight");
3.174     scop     3796:
                   3797:   local *ENSCRIPT_OUT;
                   3798:   my ($h, $err) =
3.229     scop     3799:     startproc(\@cmd, $filehandle, '>pipe', \*ENSCRIPT_OUT);
3.174     scop     3800:   fatal('500 Internal Error', $err) unless $h;
                   3801:
                   3802:   # We could short-circuit and have enscript output directly to STDOUT above,
                   3803:   # but that doesn't work with mod_perl (at least some 1.99 versions).
                   3804:   if ($linenumbers) {
                   3805:     my $ln = 0;
                   3806:     while (<ENSCRIPT_OUT>) {
                   3807:       printf '<a id="l%d" class="src">%5d: </a>', (++$ln) x 2;
                   3808:       print $_;
3.167     scop     3809:     }
3.174     scop     3810:   } else {
                   3811:     local $/ = undef;
                   3812:     print <ENSCRIPT_OUT>;
3.167     scop     3813:   }
3.229     scop     3814:   $h->finish();
3.167     scop     3815: }
                   3816:
3.120     scop     3817:
3.271     scop     3818: #
                   3819: # The passed in $path and $filename should not be URI escaped, and $swhere
                   3820: # *should* be.
                   3821: #
3.163     scop     3822: sub navigateHeader($$$$$;$)
3.120     scop     3823: {
3.163     scop     3824:   my ($swhere, $path, $filename, $rev, $title, $moddate) = @_;
3.120     scop     3825:   $swhere = "" if ($swhere eq $scriptwhere);
3.271     scop     3826:   $swhere = './' . uri_escape($filename) if ($swhere eq "");
3.120     scop     3827:
3.136     scop     3828:   my $qfile = htmlquote($filename);
                   3829:   my $qpath = htmlquote($path);
3.274     scop     3830:   my $trev  = $rev ? " - " . htmlquote($rev) : '';
3.100     knu      3831:
3.163     scop     3832:   http_header('', $moddate);
3.133     scop     3833:
3.120     scop     3834:   print <<EOF;
3.100     knu      3835: $HTML_DOCTYPE
3.89      knu      3836: <html>
                   3837: <head>
3.170     scop     3838: <title>$qpath$qfile - $title$trev</title>
3.144     scop     3839: $HTML_META$CSS</head>
3.129     scop     3840: <body class="src">
3.265     scop     3841: <table class="navigate-header" width="100%" summary="Navigation">
3.184     scop     3842:  <tr>
                   3843:   <td>
3.64      knu      3844: EOF
                   3845:
3.274     scop     3846:   my $frag = '';
                   3847:   if ($rev) {
                   3848:     $frag  = '#';
                   3849:     $frag .= 'rev' if ($rev =~ /\./);  # Normal revision: prefix with "rev".
                   3850:     $frag .= $rev;                     # Append revision/branch/tag.
                   3851:   }
                   3852:   my $backurl = "$swhere$query$frag";
                   3853:
                   3854:   print &link($backicon, $backurl);
                   3855:   printf '<b>Return to %s CVS log', &link($qfile, $backurl);
3.120     scop     3856:   print "</b> $fileicon</td>";
                   3857:
3.144     scop     3858:   printf(<<EOF, $diricon, &clickablePath($path, 1));
3.182     scop     3859:   <td style="text-align: right">%s <b>Up to %s</b></td>
3.144     scop     3860:  </tr>
                   3861: </table>
                   3862: EOF
3.120     scop     3863: }
                   3864:
3.175     scop     3865:
3.120     scop     3866: sub plural_write($$)
                   3867: {
                   3868:   my ($num, $text) = @_;
                   3869:   if ($num != 1) {
                   3870:     $text .= "s";
                   3871:   }
                   3872:
                   3873:   if ($num > 0) {
                   3874:     return join (' ', $num, $text);
                   3875:   } else {
                   3876:     return "";
                   3877:   }
3.1       knu      3878: }
                   3879:
3.175     scop     3880:
3.1       knu      3881: ##
                   3882: # print readable timestamp in terms of
                   3883: # '..time ago'
                   3884: # H. Zeller <zeller@think.de>
                   3885: ##
3.120     scop     3886: sub readableTime($$)
                   3887: {
                   3888:   my ($secs, $long) = @_;
                   3889:
3.175     scop     3890:   # This function works correctly for time >= 2 seconds.
                   3891:   return 'very little time' if ($secs < 2);
3.120     scop     3892:
                   3893:   my %desc = (
3.133     scop     3894:               1        => 'second',
                   3895:               60       => 'minute',
                   3896:               3600     => 'hour',
                   3897:               86400    => 'day',
                   3898:               604800   => 'week',
                   3899:               2628000  => 'month',
                   3900:               31536000 => 'year'
                   3901:              );
                   3902:
3.120     scop     3903:   my @breaks = sort { $a <=> $b } keys %desc;
3.133     scop     3904:   my $i = 0;
3.120     scop     3905:
                   3906:   while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
                   3907:     $i++;
                   3908:   }
                   3909:   $i--;
3.133     scop     3910:   my $break  = $breaks[$i];
                   3911:   my $retval = plural_write(int($secs / $break), $desc{$break});
3.120     scop     3912:
                   3913:   if ($long == 1 && $i > 0) {
                   3914:     my $rest = $secs % $break;
                   3915:     $i--;
                   3916:     $break = $breaks[$i];
                   3917:     my $resttime = plural_write(int($rest / $break), $desc{$break});
                   3918:     if ($resttime) {
                   3919:       $retval .= ", $resttime";
                   3920:     }
                   3921:   }
3.1       knu      3922:
3.120     scop     3923:   return $retval;
3.1       knu      3924: }
                   3925:
3.175     scop     3926:
3.1       knu      3927: #
3.263     scop     3928: # Returns a htmlified path where each directory is a link for faster
                   3929: # navigation.  $clickLast controls whether the basename
3.271     scop     3930: # (last directory/file) is a link as well.  The passed in $pathname should
                   3931: # *not* be URI escaped.
3.263     scop     3932: #
3.120     scop     3933: sub clickablePath($$)
                   3934: {
                   3935:   my ($pathname, $clickLast) = @_;
                   3936:
3.154     scop     3937:   my $root = '[' . htmlquote($CVSROOTdescr{$cvstree} || $cvstree) . ']';
                   3938:
3.144     scop     3939:   # This should never happen (see chooseCVSRoot()), but let's be sure...
3.154     scop     3940:   return $root if ($pathname eq '/');
3.120     scop     3941:
3.144     scop     3942:   my $retval =
3.154     scop     3943:     ' ' . &link($root, sprintf('%s/%s#dirlist', $scriptname, $query));
3.144     scop     3944:   my $wherepath = '';
                   3945:   my ($lastslash) = $pathname =~ m|/$|;
                   3946:
3.261     scop     3947:   foreach (split(m|/|, $pathname)) {
3.144     scop     3948:     $retval .= ' / ';
                   3949:     $wherepath .= "/$_";
                   3950:     my $last = "$wherepath/" eq "/$pathname" || $wherepath eq "/$pathname";
                   3951:
                   3952:     if ($clickLast || !$last) {
                   3953:       $retval .= &link(htmlquote($_),
                   3954:                        join ('',
3.271     scop     3955:                              $scriptname, uri_escape_path($wherepath),
3.144     scop     3956:                              (!$last || $lastslash ? '/' : ''), $query,
                   3957:                              (!$last || $lastslash ? "#dirlist" : "")));
                   3958:     } else {    # do not make a link to the current dir
                   3959:       $retval .= htmlquote($_);
3.120     scop     3960:     }
                   3961:   }
                   3962:   return $retval;
                   3963: }
                   3964:
3.144     scop     3965:
3.120     scop     3966: sub chooseCVSRoot()
                   3967: {
3.268     scop     3968:   print "<form method=\"get\" action=\"$scriptwhere\">\n<p>\n";
3.120     scop     3969:   if (2 <= @CVSROOT) {
3.133     scop     3970:     foreach my $k (keys %input) {
3.208     scop     3971:       printf("<input type=\"hidden\" name=\"%s\" value=\"%s\" />\n",
3.154     scop     3972:              htmlquote($k), htmlquote($input{$k}))
                   3973:         if ($input{$k} && $k ne 'cvsroot');
3.120     scop     3974:     }
                   3975:
3.144     scop     3976:     printf(<<EOF, $use_java_script ? ' onchange="this.form.submit()"' : '');
3.208     scop     3977: <label for="cvsroot" accesskey="C">CVS Root:
3.144     scop     3978: <select id="cvsroot" name="cvsroot"%s>
                   3979: EOF
3.120     scop     3980:
3.133     scop     3981:     foreach my $k (@CVSROOT) {
3.136     scop     3982:       printf("<option value=\"%s\"%s>%s</option>\n",
                   3983:              htmlquote($k),
3.208     scop     3984:              ($k eq $cvstree) ? ' selected="selected"' : '',
3.136     scop     3985:              htmlquote($CVSROOTdescr{$k} || $k));
3.120     scop     3986:     }
3.208     scop     3987:     print '</select></label>';
3.120     scop     3988:   } else {
                   3989:
                   3990:     # no choice -- but we need the form to select module/path,
                   3991:     # at least for Netscape
3.208     scop     3992:     printf "CVS Root: <b>[%s]</b>",
3.154     scop     3993:       htmlquote($CVSROOTdescr{$cvstree} || $cvstree);
3.120     scop     3994:   }
                   3995:
3.144     scop     3996:   print <<EOF;
                   3997: <label for="mpath" accesskey="M">
                   3998: Module path or alias:
3.208     scop     3999: <input type="text" id="mpath" name="path" value="" size="15" />
3.144     scop     4000: </label>
3.208     scop     4001: <input type="submit" value="Go" accesskey="O" />
                   4002: </p>
                   4003: </form>
3.144     scop     4004: EOF
3.120     scop     4005: }
                   4006:
3.175     scop     4007:
3.120     scop     4008: sub chooseMirror()
                   4009: {
                   4010:   # This code comes from the original BSD-cvsweb
                   4011:   # and may not be useful for your site; If you don't
                   4012:   # set %MIRRORS this won't show up, anyway.
                   4013:   scalar(%MIRRORS) or return;
                   4014:
                   4015:   # Should perhaps exclude the current site somehow...
                   4016:   print "\n<p>\nThis CVSweb is mirrored in\n";
                   4017:
                   4018:   my @tmp = map(&link(htmlquote($_), $MIRRORS{$_}), sort keys %MIRRORS);
                   4019:   my $tmp = pop (@tmp);
                   4020:
                   4021:   if (scalar(@tmp)) {
                   4022:     print join (', ', @tmp), ' and ';
                   4023:   }
                   4024:
                   4025:   print "$tmp.\n</p>\n";
                   4026: }
                   4027:
3.175     scop     4028:
3.120     scop     4029: sub fileSortCmp()
                   4030: {
3.175     scop     4031:   (my $af = $a) =~ s/,v$//;
                   4032:   (my $bf = $b) =~ s/,v$//;
3.120     scop     4033:   my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
                   4034:     if (defined($fileinfo{$af}));
                   4035:   my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
                   4036:     if (defined($fileinfo{$bf}));
                   4037:
3.175     scop     4038:   my $comp = 0;
3.140     scop     4039:   if (defined($filename1) && defined($filename2) &&
                   4040:       $af eq $filename1   && $bf eq $filename2)
3.120     scop     4041:   {
                   4042:
                   4043:     # Two files
3.140     scop     4044:     $comp = -revcmp($rev1, $rev2)             if ($byrev  && $rev1  && $rev2);
                   4045:     $comp = ($date2   <=> $date1)             if ($bydate && $date1 && $date2);
                   4046:     if ($input{ignorecase}) {
                   4047:       $comp = (uc($log1)    cmp uc($log2))    if ($bylog && $log1 && $log2);
                   4048:       $comp = (uc($author1) cmp uc($author2)) if ($byauthor &&
                   4049:                                                   $author1 && $author2);
                   4050:     } else {
                   4051:       $comp = ($log1    cmp $log2)            if ($bylog && $log1 && $log2);
                   4052:       $comp = ($author1 cmp $author2)         if ($byauthor &&
                   4053:                                                   $author1 && $author2);
                   4054:     }
3.120     scop     4055:   }
                   4056:
                   4057:   if ($comp == 0) {
                   4058:
                   4059:     # Directories first, then files under version control,
                   4060:     # then other, "rogue" files.
                   4061:     # Sort by filename if no other criteria available.
                   4062:
                   4063:     my $ad = (
                   4064:       (-d "$fullname/$a")
                   4065:       ? 'D'
                   4066:       : (defined($fileinfo{$af}) ? 'F' : 'R')
                   4067:     );
                   4068:     my $bd = (
                   4069:       (-d "$fullname/$b")
                   4070:       ? 'D'
                   4071:       : (defined($fileinfo{$bf}) ? 'F' : 'R')
                   4072:     );
3.175     scop     4073:     (my $c = $a) =~ s|.*/||;
                   4074:     (my $d = $b) =~ s|.*/||;
3.144     scop     4075:
                   4076:     my ($l, $r) = ("$ad$c", "$bd$d");
                   4077:     $comp = $input{ignorecase} ? (uc($l) cmp uc($r)) : ($l cmp $r);
                   4078:
                   4079:     # Parent dir is always first, then Attic.
                   4080:     if ($comp != 0) {
                   4081:       if ($l eq 'D..') {
3.149     scop     4082:         $comp = -1;
3.144     scop     4083:       } elsif ($r eq 'D..') {
3.149     scop     4084:         $comp = 1;
3.144     scop     4085:       } elsif ($l eq 'DAttic') {
3.149     scop     4086:         $comp = -1;
3.144     scop     4087:       } elsif ($r eq 'DAttic') {
3.149     scop     4088:         $comp = 1;
3.144     scop     4089:       }
                   4090:     }
3.120     scop     4091:   }
                   4092:   return $comp;
3.1       knu      4093: }
                   4094:
3.220     scop     4095: #
                   4096: # Returns a URL to download the selected revision.
3.271     scop     4097: # Expects the passed in URL to be URI escaped, relative, and without a query
                   4098: # string.
3.220     scop     4099: #
3.120     scop     4100: sub download_url($$;$)
                   4101: {
                   4102:   my ($url, $revision, $mimetype) = @_;
3.252     scop     4103:   my @dots = $revision =~ /\./g;
                   4104:   $revision =~ s/\b0\.(?=\d+$)// if (scalar(@dots) & 1);
3.1       knu      4105:
3.222     scop     4106:   if (!defined($mimetype) || $mimetype !~ CVSWEBMARKUP) {
3.120     scop     4107:     my $path = $where;
                   4108:     $path =~ s|[^/]+$||;
3.261     scop     4109:     $url = "$scriptname/$CheckoutMagic/$path$url";
3.120     scop     4110:   }
3.219     scop     4111:   $url .= '?rev=' . uri_escape($revision);
                   4112:   $url .= ';content-type=' . uri_escape($mimetype) if $mimetype;
3.67      knu      4113:
3.175     scop     4114:   return $url;
3.1       knu      4115: }
                   4116:
3.175     scop     4117: #
3.220     scop     4118: # Returns a link to download the selected revision.
3.271     scop     4119: # Expects the passed in URL to be URI escaped, relative,
                   4120: # and without a query string.
3.175     scop     4121: #
3.120     scop     4122: sub download_link($$$;$)
                   4123: {
                   4124:   my ($url, $revision, $textlink, $mimetype) = @_;
3.220     scop     4125:   return sprintf('<a href="%s" class="download-link">%s</a>',
3.271     scop     4126:                  download_url($url, $revision, $mimetype) . $barequery,
                   4127:                  htmlquote($textlink));
3.218     scop     4128: }
3.120     scop     4129:
3.219     scop     4130: #
                   4131: # Returns a URL to display the selected revision.
3.263     scop     4132: # Expects the passed in URL to be URI escaped, and without a query string.
3.219     scop     4133: #
                   4134: sub display_url($$;$)
                   4135: {
                   4136:   my ($url, $revision, $mimetype) = @_;
                   4137:   $url .= '?rev=' . uri_escape($revision);
                   4138:   $url .= ';content-type=' . uri_escape($mimetype) if $mimetype;
                   4139:   return $url;
                   4140: }
                   4141:
                   4142: #
                   4143: # Returns a link to display the selected revision.
3.263     scop     4144: # Expects the passed in URL to be URI escaped, and without a query string.
3.219     scop     4145: #
                   4146: sub display_link($$;$$)
                   4147: {
                   4148:   my ($url, $revision, $textlink, $mtype) = @_;
                   4149:   $textlink = $revision unless defined($textlink);
                   4150:   return sprintf('<a href="%s" class="display-link">%s</a>',
3.271     scop     4151:                  display_url($url, $revision, $mtype) . $barequery,
3.219     scop     4152:                  htmlquote($textlink));
                   4153: }
3.132     scop     4154:
3.271     scop     4155: #
                   4156: # Expects the passed in URL to be URI escaped, and without a query string.
                   4157: # The passed in link text should be already HTML escaped as appropriate.
                   4158: #
3.170     scop     4159: sub graph_link($;$)
3.132     scop     4160: {
3.170     scop     4161:   my ($url, $text) = @_;
3.132     scop     4162:   $text ||= $graphicon;
3.271     scop     4163:   return sprintf('<a href="%s?graph=1%s">%s</a>', $url, $barequery, $text);
3.258     scop     4164: }
                   4165:
                   4166: #
                   4167: # Returns a link to CVSHistory for the given directory and filename.
                   4168: #
                   4169: sub history_link($$;$)
                   4170: {
                   4171:   my ($dir, $file, $text) = @_;
                   4172:   $dir  ||= '';
                   4173:   $file ||= '';
                   4174:   $text ||= 'History';
                   4175:   return &link($text,
                   4176:                sprintf('%s?cvsroot=%s;dsearch=%s;fsearch=%s;limit=1',
                   4177:                        $cvshistory_url, uri_escape($input{cvsroot} || ''),
                   4178:                        uri_escape($dir), uri_escape($file)));
3.1       knu      4179: }
                   4180:
                   4181: # Returns a Query string with the
                   4182: # specified parameter toggled
3.140     scop     4183: sub toggleQuery($;$)
3.120     scop     4184: {
                   4185:   my ($toggle, $value) = @_;
3.133     scop     4186:
                   4187:   my %vars = %input;
3.120     scop     4188:
                   4189:   if (defined($value)) {
                   4190:     $vars{$toggle} = $value;
                   4191:   } else {
                   4192:     $vars{$toggle} = $vars{$toggle} ? 0 : 1;
                   4193:   }
                   4194:
                   4195:   # Build a new query of non-default paramenters
3.133     scop     4196:   my $newquery = "";
                   4197:   foreach my $var (@stickyvars) {
3.120     scop     4198:     my ($value)   = defined($vars{$var})         ? $vars{$var}         : "";
                   4199:     my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
                   4200:
                   4201:     if ($value ne $default) {
3.203     scop     4202:       $newquery .= ';' if ($newquery ne "");
3.206     scop     4203:       $newquery .= uri_escape($var) . '=' . uri_escape($value);
3.120     scop     4204:     }
                   4205:   }
                   4206:
                   4207:   if ($newquery) {
                   4208:     return '?' . $newquery;
                   4209:   }
                   4210:   return "";
                   4211: }
                   4212:
                   4213: sub htmlquote($)
                   4214: {
                   4215:   local ($_) = @_;
                   4216:   # Special Characters; RFC 1866
                   4217:   s/&/&amp;/g;
                   4218:   s/\"/&quot;/g;
                   4219:   s/</&lt;/g;
                   4220:   s/>/&gt;/g;
3.175     scop     4221:   return $_;
3.120     scop     4222: }
                   4223:
                   4224: sub htmlunquote($)
                   4225: {
                   4226:   local ($_) = @_;
                   4227:   # Special Characters; RFC 1866
                   4228:   s/&quot;/\"/g;
                   4229:   s/&lt;/</g;
                   4230:   s/&gt;/>/g;
                   4231:   s/&amp;/&/g;
3.175     scop     4232:   return $_;
3.120     scop     4233: }
                   4234:
3.271     scop     4235: sub uri_escape_path($)
3.120     scop     4236: {
3.271     scop     4237:   return join('/', map(uri_escape($_), split(m|/+|, shift, -1)));
3.120     scop     4238: }
                   4239:
3.163     scop     4240: sub http_header(;$$)
3.120     scop     4241: {
3.163     scop     4242:   my ($content_type, $moddate) = @_;
                   4243:   $content_type ||= 'text/html';
3.120     scop     4244:
                   4245:   $content_type .= "; charset=$charset"
3.163     scop     4246:     if ($charset && $content_type =~ m,^text/,);
3.120     scop     4247:
3.185     scop     4248:   # Note that in the following, we explicitly join() and concatenate the
                   4249:   # headers instead of printing them as an array.  This is because some
                   4250:   # systems, eg. early versions of mod_perl 2 don't quite get it if the
                   4251:   # last \r\n\r\n isn't included in the last "payload" header print().
                   4252:
                   4253:   my @headers = ();
                   4254:   # TODO: ctime(3) from scalar gmtime() isn't HTTP compliant, see HTTP::Date.
                   4255:   push(@headers, 'Last-Modified: ' . scalar gmtime($moddate) . ' GMT')
                   4256:     if $moddate;
                   4257:   push(@headers, 'Content-Type: ' . $content_type);
3.120     scop     4258:
                   4259:   if ($allow_compress && $maycompress) {
3.222     scop     4260:     if (HAS_ZLIB
3.120     scop     4261:         || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c")))
                   4262:     {
                   4263:
3.185     scop     4264:       push(@headers, 'Content-Encoding: x-gzip');
                   4265:       push(@headers, 'Vary: Accept-Encoding');     # RFC 2616, 14.44
                   4266:       print join("\r\n", @headers) . "\r\n\r\n";
                   4267:
3.120     scop     4268:       $| = 1;
3.185     scop     4269:       $| = 0;                                      # Flush header output.
3.120     scop     4270:
3.222     scop     4271:       tie(*GZIP, __PACKAGE__, \*STDOUT) if HAS_ZLIB;
3.120     scop     4272:       select(GZIP);
                   4273:       $gzip_open = 1;
                   4274:
                   4275:     } else {
3.185     scop     4276:
                   4277:       print join("\r\n", @headers) . "\r\n\r\n";
3.230     scop     4278:       printf
                   4279:         '<span style="font-size: smaller">Unable to find gzip binary in the <b>$command_path</b> (<code>%s</code>) to compress output</span><br />',
                   4280:           htmlquote(join(':', @command_path));
3.120     scop     4281:     }
3.185     scop     4282:
3.120     scop     4283:   } else {
3.185     scop     4284:     print join("\r\n", @headers) . "\r\n\r\n";
3.120     scop     4285:   }
                   4286: }
                   4287:
3.131     scop     4288:
3.163     scop     4289: sub html_header($;$)
3.120     scop     4290: {
3.163     scop     4291:   my ($title, $moddate) = @_;
                   4292:   $title = htmlquote($title);
3.162     scop     4293:   my $l = $logo || '';
3.163     scop     4294:   http_header('text/html', $moddate);
3.120     scop     4295:   print <<EOH;
3.100     knu      4296: $HTML_DOCTYPE
3.1       knu      4297: <html>
3.40      knu      4298: <head>
3.134     scop     4299: <title>$title</title>
3.144     scop     4300: $HTML_META$CSS</head>
3.129     scop     4301: <body>
3.182     scop     4302: $l <h1>$title</h1>
3.1       knu      4303: EOH
                   4304: }
                   4305:
3.120     scop     4306: sub html_footer()
                   4307: {
3.208     scop     4308:   print "<hr />\n<address>$address</address>\n" if $address;
3.127     scop     4309:   print "</body>\n</html>\n";
3.1       knu      4310: }
                   4311:
3.120     scop     4312: sub link_tags($)
                   4313: {
                   4314:   my ($tags) = @_;
                   4315:
3.261     scop     4316:   (my $filename = $where) =~ s|^.*/||;
3.271     scop     4317:   my $fileurl = './' . uri_escape($filename);
3.120     scop     4318:
3.261     scop     4319:   my $ret = "";
                   4320:   foreach my $sym (split(", ", $tags)) {
3.120     scop     4321:     $ret .= ",\n" if ($ret ne "");
3.136     scop     4322:     $ret .= &link(htmlquote($sym),
                   4323:                   $fileurl . toggleQuery('only_with_tag', $sym));
3.120     scop     4324:   }
3.219     scop     4325:   return $ret;
3.1       knu      4326: }
                   4327:
3.175     scop     4328:
3.1       knu      4329: #
3.233     scop     4330: # See if a file/dir is listed in the config file's @ForbiddenFiles list.
                   4331: # Takes a full file system path or one relative to $cvsroot, and strips the
                   4332: # trailing ",v" if present, then compares.  Returns 1 if forbidden, else 0.
3.221     scop     4333: #
3.233     scop     4334: sub forbidden($)
3.120     scop     4335: {
3.233     scop     4336:   (my $path = canonpath(shift)) =~ s/,v$//;
                   4337:   $path =~ s|^$cvsroot/+||;
3.175     scop     4338:   for my $forbidden_re (@ForbiddenFiles) {
                   4339:     return 1 if ($path =~ $forbidden_re);
3.120     scop     4340:   }
                   4341:   return 0;
3.174     scop     4342: }
                   4343:
                   4344:
                   4345: #
                   4346: # Starts a process using IPC::Run.  All arguments are passed to
                   4347: # IPC::Run::start() as-is.  Returns an array ($harness, $error) where
                   4348: # $harness is from IPC::Run if start() succeeds, undef otherwise.  In case
3.184     scop     4349: # of an error, $error contains the error message.
3.174     scop     4350: #
3.191     scop     4351: sub startproc(@)
3.174     scop     4352: {
3.215     scop     4353:   my $h = my $err = undef;
3.174     scop     4354:   eval {
                   4355:     local $SIG{__DIE__};
3.215     scop     4356:     $h = IPC::Run::start(@_) or die("return code: $?");
3.174     scop     4357:   };
3.215     scop     4358:   if ($@) {
3.229     scop     4359:     $h->finish() if $h;
3.215     scop     4360:     $h = undef;
                   4361:     $err = "'@{$_[0]}' failed: $@";
                   4362:   }
3.174     scop     4363:   return ($h, $err);
3.215     scop     4364: }
                   4365:
                   4366: #
                   4367: # Runs a process using IPC::Run.  All arguments are passed to
                   4368: # IPC::Run::run() as-is.  Returns an array ($exitcode, $errormsg).
                   4369: #
                   4370: sub runproc(@)
                   4371: {
                   4372:   eval {
                   4373:     local $SIG{__DIE__};
                   4374:     IPC::Run::run(@_);
                   4375:   };
                   4376:   my $exitcode = $? >> 8;
                   4377:   my $errormsg  = undef;
                   4378:   if ($@) {
                   4379:     $exitcode ||= -1;
                   4380:     $errormsg = "'@{$_[0]}' failed: $@";
                   4381:   }
                   4382:   return ($exitcode, $errormsg);
3.129     scop     4383: }
                   4384:
3.225     scop     4385: #
                   4386: # Check out a file to a temporary file.
                   4387: #
                   4388: sub checkout_to_temp($$$)
                   4389: {
                   4390:   my ($cvsroot, $cvsname, $rev) = @_;
3.25      knu      4391:
3.225     scop     4392:   # Pipe given cvs file into a temporary place.
                   4393:   my ($temp_fh, $temp_fn) = tempfile('.cvsweb.XXXXXXXX', DIR => tmpdir());
                   4394:
                   4395:   my @cmd = ($CMD{cvs}, @cvs_options, '-Qd', $cvsroot,
                   4396:              'co', '-p', "-r$rev", $cvsname);
                   4397:
                   4398:   local (*DIFF_OUT);
                   4399:   my ($h, $err) = startproc(\@cmd, \"", '>pipe', \*DIFF_OUT);
                   4400:   if ($h) {
                   4401:     local $/ = undef;
                   4402:     print $temp_fh <DIFF_OUT>;
3.229     scop     4403:     $h->finish();
3.225     scop     4404:     close($temp_fh);
                   4405:   } else {
                   4406:     close($temp_fh);
                   4407:     unlink($temp_fn);
                   4408:     fatal('500 Internal Error',
                   4409:           'Checkout failure (exit status %s), output: <pre>%s</pre>',
                   4410:           $? >> 8 || -1, $err);
                   4411:   }
                   4412:
                   4413:   return $temp_fn;
                   4414: }
                   4415:
                   4416: #
3.173     scop     4417: # Close the GZIP handle, and remove the tie.
3.225     scop     4418: #
3.120     scop     4419: sub gzipclose
                   4420: {
                   4421:   if ($gzip_open) {
                   4422:     select(STDOUT);
                   4423:     close(GZIP);
                   4424:     untie *GZIP;
                   4425:     $gzip_open = 0;
                   4426:   }
3.23      knu      4427: }
                   4428:
                   4429: # implement a gzipped file handle via the Compress:Zlib compression
                   4430: # library.
                   4431:
                   4432: sub MAGIC1() { 0x1f }
                   4433: sub MAGIC2() { 0x8b }
3.80      knu      4434: sub OSCODE() { 3 }
3.23      knu      4435:
3.120     scop     4436: sub TIEHANDLE
                   4437: {
                   4438:   my ($class, $out) = @_;
                   4439:   my ($d) = Compress::Zlib::deflateInit(
                   4440:     -Level      => Compress::Zlib::Z_BEST_COMPRESSION(),
                   4441:     -WindowBits => -Compress::Zlib::MAX_WBITS()
                   4442:     )
                   4443:     or return undef;
                   4444:   my ($o) = { handle => $out,
                   4445:               dh     => $d,
                   4446:               crc    => 0,
                   4447:               len    => 0,
                   4448:             };
                   4449:   my ($header) = pack("c10",
                   4450:                       MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(),
                   4451:                       0, 0, 0, 0, 0, 0, OSCODE);
                   4452:   print {$o->{handle}} $header;
                   4453:   return bless($o, $class);
                   4454: }
                   4455:
                   4456: sub PRINT
                   4457: {
                   4458:   my ($o)   = shift;
3.164     scop     4459:   my ($buf) = join (defined($,) ? $, : "", @_);
3.120     scop     4460:   my ($len) = length($buf);
                   4461:   my ($compressed, $status) = $o->{dh}->deflate($buf);
                   4462:   print {$o->{handle}} $compressed if defined($compressed);
                   4463:   $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
                   4464:   $o->{len} += $len;
                   4465:   return $len;
                   4466: }
                   4467:
                   4468: sub PRINTF
                   4469: {
                   4470:   my ($o)   = shift;
                   4471:   my ($fmt) = shift;
                   4472:   my ($buf) = sprintf($fmt, @_);
                   4473:   my ($len) = length($buf);
                   4474:   my ($compressed, $status) = $o->{dh}->deflate($buf);
                   4475:   print {$o->{handle}} $compressed if defined($compressed);
                   4476:   $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
                   4477:   $o->{len} += $len;
                   4478:   return $len;
                   4479: }
                   4480:
                   4481: sub WRITE
                   4482: {
                   4483:   my ($o, $buf, $len, $off) = @_;
                   4484:   my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
                   4485:   print {$o->{handle}} $compressed if defined($compressed);
                   4486:   $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
                   4487:   $o->{len} += $len;
                   4488:   return $len;
                   4489: }
                   4490:
                   4491: sub CLOSE
                   4492: {
                   4493:   my ($o) = @_;
                   4494:   return if !defined($o->{dh});
                   4495:   my ($buf) = $o->{dh}->flush();
                   4496:   $buf .= pack("V V", $o->{crc}, $o->{len});
                   4497:   print {$o->{handle}} $buf;
                   4498:   undef $o->{dh};
                   4499: }
                   4500:
                   4501: sub DESTROY
                   4502: {
                   4503:   my ($o) = @_;
                   4504:   CLOSE($o);
1.1       jfieber  4505: }
3.149     scop     4506:
                   4507: # Local variables:
                   4508: # indent-tabs-mode: nil
                   4509: # cperl-indent-level: 2
                   4510: # End:

CVSweb