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