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