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