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