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

Annotation of cvsweb/cvsweb.cgi, Revision 4.3

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

CVSweb