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

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.91

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

CVSweb