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