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