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