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

Annotation of cvsweb/cvsweb.cgi, Revision 3.208

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

CVSweb