Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.69
1.45.2.64 knu 1: #!/usr/bin/perl -wT
1.1 jfieber 2: #
1.45.2.46 knu 3: # cvsweb - a CGI interface to CVS trees.
1.1 jfieber 4: #
1.45.2.47 knu 5: # Written in their spare time by
1.45.2.46 knu 6: # Bill Fenner <fenner@FreeBSD.org> (original work)
7: # extended by Henner Zeller <zeller@think.de>,
1.45.2.47 knu 8: # Henrik Nordstrom <hno@hem.passagen.se>
1.45.2.46 knu 9: # Ken Coar <coar@Apache.Org>
10: # Dick Balaska <dick@buckosoft.com>
11: # Akinori MUSHA <knu@FreeBSD.org>
1.45.2.51 knu 12: # Jens-Uwe Mager <jum@helios.de>
1.45.2.46 knu 13: #
14: # Based on:
15: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
16: # http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1 jfieber 17: #
1.21 wosch 18: # Copyright (c) 1996-1998 Bill Fenner
1.45.2.46 knu 19: # (c) 1998-1999 Henner Zeller
20: # (c) 1999 Henrik Nordstrom
1.45.2.68 knu 21: # (c) 2000-2001 Akinori MUSHA
1.21 wosch 22: # All rights reserved.
23: #
24: # Redistribution and use in source and binary forms, with or without
25: # modification, are permitted provided that the following conditions
26: # are met:
27: # 1. Redistributions of source code must retain the above copyright
28: # notice, this list of conditions and the following disclaimer.
29: # 2. Redistributions in binary form must reproduce the above copyright
30: # notice, this list of conditions and the following disclaimer in the
31: # documentation and/or other materials provided with the distribution.
32: #
33: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
34: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
37: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43: # SUCH DAMAGE.
44: #
1.45.2.69! knu 45: # $zId: cvsweb.cgi,v 1.106 2001/03/10 01:16:27 hnordstrom Exp $
! 46: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 1.68 2001/03/22 19:46:59 knu Exp $
! 47: # $FreeBSD: www/en/cgi/cvsweb.cgi,v 1.68 2001/01/14 08:59:59 knu Exp $
1.21 wosch 48: #
1.45.2.46 knu 49: ###
1.21 wosch 50:
1.45.2.64 knu 51: require 5.000;
52:
1.45.2.46 knu 53: use strict;
1.21 wosch 54:
1.45.2.46 knu 55: use vars qw (
1.45.2.68 knu 56: $cvsweb_revision
1.45.2.67 knu 57: $mydir $uname $config $allow_version_select $verbose
1.45.2.65 knu 58: @CVSrepositories @CVSROOT %CVSROOT %CVSROOTdescr
59: %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
1.45.2.56 knu 60: @DIFFTYPES %DIFFTYPES @LOGSORTKEYS %LOGSORTKEYS
1.45.2.46 knu 61: %alltags @tabcolors %fileinfo %tags @branchnames %nameprinted
62: %symrev %revsym @allrevisions %date %author @revdisplayorder
1.45.2.49 knu 63: @revisions %state %difflines %log %branchpoint @revorder
1.45.2.63 knu 64: $prcgi @prcategories $re_prcategories $prkeyword $re_prkeyword $mancgi
1.45.2.46 knu 65: $checkoutMagic $doCheckout $scriptname $scriptwhere
66: $where $pathinfo $Browser $nofilelinks $maycompress @stickyvars
67: %funcline_regexp $is_mod_perl
1.45.2.56 knu 68: $is_links $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
1.45.2.46 knu 69: %input $query $barequery $sortby $bydate $byrev $byauthor
1.45.2.56 knu 70: $bylog $byfile $defaultDiffType $logsort $cvstree $cvsroot
1.45.2.58 knu 71: $mimetype $charset $defaultTextPlain $defaultViewable
1.45.2.67 knu 72: $command_path %CMD $allow_compress
73: $backicon $diricon $fileicon
1.45.2.58 knu 74: $fullname $newname $cvstreedefault
75: $body_tag $body_tag_for_src $logo $defaulttitle $address
1.45.2.52 knu 76: $long_intro $short_instruction $shortLogLen
1.45.2.46 knu 77: $show_author $dirtable $tablepadding $columnHeaderColorDefault
78: $columnHeaderColorSorted $hr_breakable $showfunc $hr_ignwhite
79: $hr_ignkeysubst $diffcolorHeading $diffcolorEmpty $diffcolorRemove
80: $diffcolorChange $diffcolorAdd $diffcolorDarkChange $difffontface
81: $difffontsize $inputTextSize $mime_types $allow_annotate
82: $allow_markup $use_java_script $open_extern_window
83: $extern_window_width $extern_window_height $edit_option_form
1.45.2.63 knu 84: $show_subdir_lastmod $show_log_in_markup $preformat_in_markup $v
1.45.2.46 knu 85: $navigationHeaderColor $tableBorderColor $markupLogColor
86: $tabstop $state $annTable $sel $curbranch @HideModules
87: $module $use_descriptions %descriptions @mytz $dwhere $moddate
1.45.2.67 knu 88: $use_moddate $has_zlib $gzip_open
89: $allow_tar @tar_options @gzip_options @cvs_options
1.45.2.55 knu 90: $LOG_FILESEPARATOR $LOG_REVSEPARATOR
1.45.2.46 knu 91: );
92:
1.45.2.47 knu 93: sub printDiffSelect($);
1.45.2.56 knu 94: sub printDiffLinks($$);
95: sub printLogSortSelect($);
1.45.2.47 knu 96: sub findLastModifiedSubdirs(@);
1.45.2.56 knu 97: sub htmlify_sub(&$);
1.45.2.47 knu 98: sub htmlify($;$);
1.45.2.51 knu 99: sub spacedHtmlText($;$);
1.45.2.47 knu 100: sub link($$);
101: sub revcmp($$);
102: sub fatal($$);
103: sub redirect($);
104: sub safeglob($);
1.45.2.67 knu 105: sub search_path($);
1.45.2.47 knu 106: sub getMimeTypeFromSuffix($);
1.45.2.51 knu 107: sub head($;$);
108: sub scan_directives(@);
1.45.2.47 knu 109: sub doAnnotate($$);
110: sub doCheckout($$);
111: sub cvswebMarkup($$$);
112: sub viewable($);
113: sub doDiff($$$$$$);
114: sub getDirLogs($$@);
115: sub readLog($;$);
116: sub printLog($;$);
117: sub doLog($);
118: sub flush_diff_rows($$$$);
119: sub human_readable_diff($);
120: sub navigateHeader($$$$$);
121: sub plural_write($$);
122: sub readableTime($$);
123: sub clickablePath($$);
124: sub chooseCVSRoot();
125: sub chooseMirror();
126: sub fileSortCmp();
127: sub download_url($$;$);
128: sub download_link($$$;$);
129: sub toggleQuery($$);
130: sub urlencode($);
1.45.2.56 knu 131: sub htmlquote($);
132: sub htmlunquote($);
1.45.2.62 knu 133: sub hrefquote($);
1.45.2.47 knu 134: sub http_header(;$);
135: sub html_header($);
136: sub html_footer();
137: sub link_tags($);
138: sub forbidden_module($);
139:
1.45.2.46 knu 140: ##### Start of Configuration Area ########
1.45.2.67 knu 141: delete $ENV{PATH};
142:
1.45.2.69! knu 143: $cvsweb_revision = '1.106' . '.' . (split(/ /,
! 144: q$Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 1.68 2001/03/22 19:46:59 knu Exp $
! 145: ))[2];
1.45.2.68 knu 146:
1.45.2.64 knu 147: use File::Basename;
1.45.2.46 knu 148:
1.45.2.66 knu 149: ($mydir) = (dirname($0) =~ /(.*)/); # untaint
150:
1.45.2.47 knu 151: # == EDIT this ==
1.45.2.53 knu 152: # Locations to search for user configuration, in order:
153: for (
1.45.2.66 knu 154: "$mydir/cvsweb.conf",
1.45.2.65 knu 155: '/usr/local/etc/cvsweb/cvsweb.conf'
1.45.2.53 knu 156: ) {
1.45.2.64 knu 157: if (defined($_) && -r $_) {
1.45.2.66 knu 158: $config = $_;
1.45.2.64 knu 159: last;
160: }
1.45.2.46 knu 161: }
1.1 jfieber 162:
1.45.2.46 knu 163: # == Configuration defaults ==
164: # Defaults for configuration variables that shouldn't need
165: # to be configured..
166: $allow_version_select = 1;
167:
168: ##### End of Configuration Area ########
169:
170: ######## Configuration variables #########
171: # These are defined to allow checking with perl -cw
1.45.2.65 knu 172: @CVSrepositories = @CVSROOT = %CVSROOT =
173: %MIRRORS = %DEFAULTVALUE = %ICONS = %MTYPES =
1.45.2.46 knu 174: %tags = %alltags = @tabcolors = ();
1.45.2.53 knu 175: $cvstreedefault = $body_tag = $body_tag_for_src =
1.45.2.52 knu 176: $logo = $defaulttitle = $address =
177: $long_intro = $short_instruction = $shortLogLen =
1.45.2.46 knu 178: $show_author = $dirtable = $tablepadding = $columnHeaderColorDefault =
179: $columnHeaderColorSorted = $hr_breakable = $showfunc = $hr_ignwhite =
180: $hr_ignkeysubst = $diffcolorHeading = $diffcolorEmpty = $diffcolorRemove =
181: $diffcolorChange = $diffcolorAdd = $diffcolorDarkChange = $difffontface =
182: $difffontsize = $inputTextSize = $mime_types = $allow_annotate =
183: $allow_markup = $use_java_script = $open_extern_window =
184: $extern_window_width = $extern_window_height = $edit_option_form =
1.45.2.56 knu 185: $show_subdir_lastmod = $show_log_in_markup = $v =
1.45.2.47 knu 186: $navigationHeaderColor = $tableBorderColor = $markupLogColor =
1.45.2.52 knu 187: $tabstop = $use_moddate = $moddate = $gzip_open = undef;
1.45.2.46 knu 188:
1.45.2.55 knu 189: $LOG_FILESEPARATOR = q/^={77}$/;
190: $LOG_REVSEPARATOR = q/^-{28}$/;
191:
1.45.2.56 knu 192: @DIFFTYPES = qw(h H u c s);
193: @DIFFTYPES{@DIFFTYPES} = (
194: {
195: 'descr' => 'colored',
196: 'opts' => [ '-u' ],
197: 'colored' => 1,
198: },
199: {
200: 'descr' => 'long colored',
201: 'opts' => [ '--unified=15' ],
202: 'colored' => 1,
203: },
204: {
205: 'descr' => 'unified',
206: 'opts' => [ '-u' ],
207: 'colored' => 0,
208: },
209: {
210: 'descr' => 'context',
211: 'opts' => [ '-c' ],
212: 'colored' => 0,
213: },
214: {
215: 'descr' => 'side by side',
216: 'opts' => [ '--side-by-side', '--width=164' ],
217: 'colored' => 0,
218: },
219: );
220:
221: @LOGSORTKEYS = qw(cvs date rev);
222: @LOGSORTKEYS{@LOGSORTKEYS} = (
223: {
224: 'descr' => 'Not sorted',
225: },
226: {
227: 'descr' => 'Commit date',
228: },
229: {
230: 'descr' => 'Revision',
231: },
232: );
233:
1.45.2.46 knu 234: ##### End of configuration variables #####
235:
236: $cgi_style::hsty_base = 'http://www.FreeBSD.org';
1.45.2.69! knu 237: $_ = q$FreeBSD: www/en/cgi/cvsweb.cgi,v 1.68 2001/01/14 08:59:59 knu Exp $;
1.45.2.60 knu 238: @_ = split;
239: $cgi_style::hsty_date = "@_[3,4]";
240:
241: # warningproof
242: 0 if $cgi_style::hsty_base ne $cgi_style::hsty_date;
243:
244: package cgi_style;
1.45.2.66 knu 245: require "$main::mydir/cgi-style.pl";
1.45.2.46 knu 246: package main;
1.2 jfieber 247:
1.45.2.56 knu 248: ##### End of configuration variables #####
249:
1.45.2.46 knu 250: use Time::Local;
251: use IPC::Open2;
1.1 jfieber 252:
1.45.2.51 knu 253: # Check if the zlib C library interface is installed, and if yes
254: # we can avoid using the extra gzip process.
255: eval {
256: require Compress::Zlib;
257: };
258: $has_zlib = !$@;
259:
1.1 jfieber 260: $verbose = $v;
1.45.2.46 knu 261: $checkoutMagic = "~checkout~";
262: $pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
263: $where = $pathinfo;
1.45.2.67 knu 264: $doCheckout = ($where =~ m|^/$checkoutMagic/|);
265: $where =~ s|^/$checkoutMagic/|/|;
266: $where =~ s|^/||;
1.45.2.46 knu 267: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
1.45.2.67 knu 268: $scriptname =~ s|^/*|/|;
269:
1.45.2.68 knu 270: # Let's workaround thttpd's stupidity..
1.45.2.67 knu 271: if ($scriptname =~ m|/$|) {
272: $pathinfo .= '/';
273: my $re = quotemeta $pathinfo;
274: $scriptname =~ s/$re$//;
1.45.2.46 knu 275: }
276:
1.45.2.67 knu 277: $scriptwhere = $scriptname;
278: $scriptwhere .= '/' . urlencode($where);
279: $where = '/' if ($where eq '');
280:
1.45.2.46 knu 281: $is_mod_perl = defined($ENV{MOD_PERL});
282:
283: # in lynx, it it very annoying to have two links
284: # per file, so disable the link at the icon
285: # in this case:
1.45.2.59 knu 286: $Browser = $ENV{HTTP_USER_AGENT} || '';
1.45.2.56 knu 287: $is_links = ($Browser =~ m`^Links `);
1.45.2.46 knu 288: $is_lynx = ($Browser =~ m`^Lynx/`i);
289: $is_w3m = ($Browser =~ m`^w3m/`i);
290: $is_msie = ($Browser =~ m`MSIE`);
291: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
292:
1.45.2.56 knu 293: $is_textbased = ($is_links || $is_lynx || $is_w3m);
1.45.2.46 knu 294:
295: $nofilelinks = $is_textbased;
296:
297: # newer browsers accept gzip content encoding
298: # and state this in a header
299: # (netscape did always but didn't state it)
300: # It has been reported that these
301: # braindamaged MS-Internet Exploders claim that they
302: # accept gzip .. but don't in fact and
303: # display garbage then :-/
1.45.2.51 knu 304: # Turn off gzip if running under mod_perl and no zlib is available,
305: # piping does not work as expected inside the server.
1.45.2.52 knu 306: $maycompress = (((defined($ENV{HTTP_ACCEPT_ENCODING})
307: && $ENV{HTTP_ACCEPT_ENCODING} =~ m`gzip`)
1.45.2.47 knu 308: || $is_mozilla3)
309: && !$is_msie
1.45.2.51 knu 310: && !($is_mod_perl && !$has_zlib));
1.45.2.46 knu 311:
312: # put here the variables we need in order
313: # to hold our state - they will be added (with
1.45.2.47 knu 314: # their current value) to any link/query string
1.45.2.46 knu 315: # you construct
316: @stickyvars = qw(cvsroot hideattic sortby logsort f only_with_tag);
1.1 jfieber 317:
1.45.2.46 knu 318: if (-f $config) {
1.45.2.62 knu 319: require $config
1.45.2.53 knu 320: || &fatal("500 Internal Error",
321: sprintf('Error in loading configuration file: %s<BR><BR>%s<BR>',
322: $config, &htmlify($@)));
323: } else {
1.45.2.46 knu 324: &fatal("500 Internal Error",
325: 'Configuration not found. Set the variable <code>$config</code> '
1.45.2.69! knu 326: . 'in cvsweb.cgi to your <b>cvsweb.conf</b> configuration file first.');
1.45.2.46 knu 327: }
328:
329: undef %input;
330: $query = $ENV{QUERY_STRING};
331:
1.45.2.47 knu 332: if (defined($query) && $query ne '') {
1.9 fenner 333: foreach (split(/&/, $query)) {
1.45.2.61 knu 334: y/+/ /;
1.7 fenner 335: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
336: if (/(\S+)=(.*)/) {
1.45.2.46 knu 337: $input{$1} = $2 if ($2 ne "");
338: }
339: else {
1.7 fenner 340: $input{$_}++;
341: }
342: }
343: }
1.10 wosch 344:
1.45.2.47 knu 345: # For backwards compability, set only_with_tag to only_on_branch if set.
1.45.2.46 knu 346: $input{only_with_tag} = $input{only_on_branch}
347: if (defined($input{only_on_branch}));
1.10 wosch 348:
1.45.2.46 knu 349: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
1.10 wosch 350:
1.45.2.46 knu 351: foreach (keys %DEFAULTVALUE)
352: {
353: # replace not given parameters with the default parameters
354: if (!defined($input{$_}) || $input{$_} eq "") {
355: # Empty Checkboxes in forms return -- nothing. So we define a helper
356: # variable in these forms (copt) which indicates that we just set
357: # parameters with a checkbox
358: if (!defined($input{"copt"})) {
359: # 'copt' isn't defined --> empty input is not the result
360: # of empty input checkbox --> set default
361: $input{$_} = $DEFAULTVALUE{$_} if (defined($DEFAULTVALUE{$_}));
362: }
363: else {
364: # 'copt' is defined -> the result of empty input checkbox
365: # -> set to zero (disable) if default is a boolean (0|1).
366: $input{$_} = 0
367: if (defined($DEFAULTVALUE{$_})
368: && ($DEFAULTVALUE{$_} eq "0" || $DEFAULTVALUE{$_} eq "1"));
369: }
1.10 wosch 370: }
371: }
1.45.2.47 knu 372:
1.45.2.46 knu 373: $barequery = "";
1.45.2.55 knu 374: my @barequery;
1.45.2.46 knu 375: foreach (@stickyvars) {
376: # construct a query string with the sticky non default parameters set
1.45.2.47 knu 377: if (defined($input{$_}) && $input{$_} ne '' &&
1.45.2.46 knu 378: !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_})) {
1.45.2.55 knu 379: push @barequery, join('=', urlencode($_), urlencode($input{$_}));
1.45.2.46 knu 380: }
381: }
382: # is there any query ?
1.45.2.55 knu 383: if (@barequery) {
1.45.2.56 knu 384: $barequery = join('&', @barequery);
1.45.2.46 knu 385: $query = "?$barequery";
1.45.2.56 knu 386: $barequery = "&$barequery";
1.45.2.46 knu 387: }
388: else {
389: $query = "";
390: }
1.45.2.55 knu 391: undef @barequery;
1.10 wosch 392:
1.45.2.65 knu 393: if (defined($input{path})) {
394: redirect("$scriptname/$input{path}$query");
395: }
396:
1.45.2.46 knu 397: # get actual parameters
398: $sortby = $input{"sortby"};
399: $bydate = 0;
400: $byrev = 0;
401: $byauthor = 0;
402: $bylog = 0;
403: $byfile = 0;
404: if ($sortby eq "date") {
405: $bydate = 1;
406: }
407: elsif ($sortby eq "rev") {
408: $byrev = 1;
409: }
410: elsif ($sortby eq "author") {
411: $byauthor = 1;
412: }
413: elsif ($sortby eq "log") {
414: $bylog = 1;
415: }
416: else {
417: $byfile = 1;
418: }
1.12 fenner 419:
1.45.2.56 knu 420: $defaultDiffType = $input{'f'};
1.45.2.46 knu 421:
422: $logsort = $input{'logsort'};
423:
1.45.2.65 knu 424: my @tmp = @CVSrepositories;
425: my @pair;
426:
427: while (@pair = splice(@tmp, 0, 2)) {
428: my($key, $val) = @pair;
429: my($descr, $cvsroot) = @$val;
430:
431: next if !-d $cvsroot;
432:
433: $CVSROOTdescr{$key} = $descr;
434: $CVSROOT{$key} = $cvsroot;
435: push @CVSROOT, $key;
436: }
437: undef @tmp;
438: undef @pair;
1.45.2.46 knu 439:
440: ## Default CVS-Tree
441: if (!defined($CVSROOT{$cvstreedefault})) {
442: &fatal("500 Internal Error",
443: "<code>\$cvstreedefault</code> points to a repository "
444: . "not defined in <code>%CVSROOT</code> "
445: . "(edit your configuration file $config)");
1.10 wosch 446: }
447:
1.45.2.46 knu 448: # alternate CVS-Tree, configured in cvsweb.conf
449: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
450: $cvstree = $input{'cvsroot'};
451: } else {
452: $cvstree = $cvstreedefault;
453: }
1.10 wosch 454:
1.45.2.46 knu 455: $cvsroot = $CVSROOT{$cvstree};
456:
457: # create icons out of description
1.45.2.55 knu 458: my $k;
459: foreach $k (keys %ICONS) {
1.45.2.46 knu 460: no strict 'refs';
461: my ($itxt,$ipath,$iwidth,$iheight) = @{$ICONS{$k}};
462: if ($ipath) {
1.45.2.56 knu 463: ${"${k}icon"} = sprintf('<IMG SRC="%s" ALT="%s" BORDER="0" WIDTH="%d" HEIGHT="%d">',
1.45.2.61 knu 464: hrefquote($ipath), htmlquote($itxt), $iwidth, $iheight)
1.16 wosch 465: }
1.45.2.46 knu 466: else {
467: ${"${k}icon"} = $itxt;
1.24 wosch 468: }
469: }
1.45.2.55 knu 470: undef $k;
1.24 wosch 471:
1.45.2.53 knu 472: my $config_cvstree = "$config-$cvstree";
473:
1.45.2.46 knu 474: # Do some special configuration for cvstrees
1.45.2.53 knu 475: if (-f $config_cvstree) {
1.45.2.62 knu 476: require $config_cvstree
1.45.2.53 knu 477: || &fatal("500 Internal Error",
478: sprintf('Error in loading configuration file: %s<BR><BR>%s<BR>',
479: $config_cvstree, &htmlify($@)));
480: }
1.45.2.55 knu 481: undef $config_cvstree;
1.24 wosch 482:
1.45.2.63 knu 483: $re_prcategories = '(?:' . join('|', @prcategories) . ')' if @prcategories;
484: $re_prkeyword = quotemeta($prkeyword) if defined($prkeyword);
1.45.2.49 knu 485: $prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.45.2.46 knu 486:
1.45.2.63 knu 487: $fullname = "$cvsroot/$where";
1.45.2.46 knu 488: $mimetype = &getMimeTypeFromSuffix ($fullname);
489: $defaultTextPlain = ($mimetype eq "text/plain");
490: $defaultViewable = $allow_markup && viewable($mimetype);
491:
1.45.2.67 knu 492: my $rewrite = 0;
493:
494: if ($pathinfo =~ m|//|) {
495: $pathinfo =~ y|/|/|s;
496: $rewrite = 1;
1.16 wosch 497: }
498:
1.45.2.67 knu 499: if (-d $fullname && $pathinfo !~ m|/$|) {
500: $pathinfo .= '/';
501: $rewrite = 1;
502: }
503:
504: if (!-d $fullname && $pathinfo =~ m|/$|) {
505: chop $pathinfo;
506: $rewrite = 1;
1.45.2.46 knu 507: }
508:
1.45.2.67 knu 509: if ($rewrite) {
510: redirect($scriptname . urlencode($pathinfo) . $query);
511: }
512:
513: undef $rewrite;
514:
1.45.2.46 knu 515: if (!-d $cvsroot) {
516: &fatal("500 Internal Error",'$CVSROOT not found!<P>The server on which the CVS tree lives is probably down. Please try again in a few minutes.');
517: }
518:
519: #
520: # See if the module is in our forbidden list.
521: #
522: $where =~ m:([^/]*):;
523: $module = $1;
524: if ($module && &forbidden_module($module)) {
525: &fatal("403 Forbidden", "Access to $where forbidden.");
526: }
1.45.2.61 knu 527:
528: #
529: # Handle tarball downloads before any headers are output.
530: #
531: if ($input{tarball}) {
532: &fatal("403 Forbidden", "Downloading tarballs is prohibited.")
533: unless $allow_tar;
1.45.2.64 knu 534: my($module) = ($where =~ m,^/?(.*),); # untaint
535: $module =~ s,/[^/]*$,,;
536: my($basedir) = ($module =~ m,([^/]+)$,);
1.45.2.61 knu 537:
1.45.2.64 knu 538: if ($basedir eq '' || $module eq '') {
1.45.2.61 knu 539: &fatal("500 Internal Error", "You cannot download the top level directory.");
540: }
541:
542: my $tmpdir = "/tmp/.cvsweb.$$." . int(time);
543:
544: mkdir($tmpdir, 0700)
545: or &fatal("500 Internal Error", "Unable to make temporary directory: $!");
546:
547: my $fatal = '';
548:
1.45.2.64 knu 549: while (1) {
1.45.2.63 knu 550: my $tag = (exists $input{only_with_tag} && length $input{only_with_tag})
551: ? $input{only_with_tag} : "HEAD";
1.45.2.61 knu 552:
1.45.2.67 knu 553: system $CMD{cvs}, @cvs_options, '-Qd', $cvsroot, 'export', '-r', $tag, '-d', "$tmpdir/$basedir", $module
1.45.2.64 knu 554: and $fatal = "500 Internal Error","cvs co failure: $!: $module"
1.45.2.61 knu 555: && last;
556:
557: $| = 1; # Essential to get the buffering right.
558:
559: print "Content-type: application/x-gzip\r\n\r\n";
560:
1.45.2.67 knu 561: system "$CMD{tar} @tar_options -cf - -C $tmpdir $basedir | $CMD{gzip} @gzip_options -c"
1.45.2.61 knu 562: and $fatal = "500 Internal Error","tar zc failure: $!: $basedir"
563: && last;
564:
1.45.2.64 knu 565: last;
566: }
1.45.2.61 knu 567:
1.45.2.67 knu 568: system $CMD{rm}, '-rf', $tmpdir if -d $tmpdir;
1.45.2.61 knu 569:
570: &fatal($fatal) if $fatal;
571:
572: exit;
573: }
574:
1.45.2.46 knu 575: ##############################
576: # View a directory
577: ###############################
1.45.2.61 knu 578: if (-d $fullname) {
1.45.2.46 knu 579: my $dh = do {local(*DH);};
580: opendir($dh, $fullname) || &fatal("404 Not Found","$where: $!");
581: my @dir = readdir($dh);
582: closedir($dh);
583: my @subLevelFiles = findLastModifiedSubdirs(@dir)
584: if ($show_subdir_lastmod);
585: getDirLogs($cvsroot,$where,@subLevelFiles);
586:
587: if ($where eq '/') {
588: html_header($defaulttitle);
589: $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
590: print $long_intro;
591: }
592: else {
593: html_header($where);
594: print $short_instruction;
595: }
596:
597: my $descriptions;
598: if (($use_descriptions) && open (DESC, "<$cvsroot/CVSROOT/descriptions")) {
599: while (<DESC>) {
600: chomp;
601: my ($dir,$description) = /(\S+)\s+(.*)/;
602: $descriptions{$dir} = $description;
603: }
1.1 jfieber 604: }
1.45.2.46 knu 605:
606: print "<P><a name=\"dirlist\"></a>\n";
607: # give direct access to dirs
608: if ($where eq '/') {
609: chooseMirror();
610: chooseCVSRoot();
611: }
612: else {
613: print "<p>Current directory: <b>", &clickablePath($where,0), "</b>\n";
614:
615: print "<P>Current tag: <B>", $input{only_with_tag}, "</b>\n" if
616: $input{only_with_tag};
617:
618: }
1.45.2.47 knu 619:
1.45.2.46 knu 620:
621: print "<HR NOSHADE>\n";
1.1 jfieber 622: # Using <MENU> in this manner violates the HTML2.0 spec but
623: # provides the results that I want in most browsers. Another
624: # case of layout spooging up HTML.
1.45.2.47 knu 625:
1.45.2.46 knu 626: my $infocols = 0;
627: if ($dirtable) {
628: if (defined($tableBorderColor)) {
629: # Can't this be done by defining the border for the inner table?
630: print "<table border=0 cellpadding=0 width=\"100%\"><tr><td bgcolor=\"$tableBorderColor\">";
631: }
632: print "<table width=\"100%\" border=0 cellspacing=1 cellpadding=$tablepadding>\n";
633: $infocols++;
1.45.2.56 knu 634: printf '<tr><th align=left bgcolor="%s">',
635: $byfile ? $columnHeaderColorSorted : $columnHeaderColorDefault;
636: if ($byfile) {
637: print 'File';
638: } else {
639: print &link('File', sprintf('./%s#dirlist',
640: &toggleQuery("sortby", "file")));
641: }
1.45.2.46 knu 642: print "</th>";
643: # do not display the other column-headers, if we do not have any files
644: # with revision information:
645: if (scalar(%fileinfo)) {
646: $infocols++;
1.45.2.56 knu 647: printf '<th align=left bgcolor="%s">',
648: $byrev ? $columnHeaderColorSorted : $columnHeaderColorDefault;
649: if ($byrev) {
650: print 'Rev.';
651: } else {
652: print &link('Rev.', sprintf('./%s#dirlist',
653: &toggleQuery("sortby", "rev")));
654: }
1.45.2.46 knu 655: print "</th>";
656: $infocols++;
1.45.2.56 knu 657: printf '<th align=left bgcolor="%s">',
658: $bydate ? $columnHeaderColorSorted : $columnHeaderColorDefault;
659: if ($bydate) {
660: print 'Age';
661: } else {
662: print &link('Age', sprintf('./%s#dirlist',
663: &toggleQuery("sortby", "date")));
664: }
1.45.2.46 knu 665: print "</th>";
666: if ($show_author) {
667: $infocols++;
1.45.2.56 knu 668: printf '<th align=left bgcolor="%s">',
669: $byauthor ? $columnHeaderColorSorted : $columnHeaderColorDefault;
670: if ($byauthor) {
671: print 'Author';
672: } else {
673: print &link('Author', sprintf('./%s#dirlist',
674: &toggleQuery("sortby", "author")));
675: }
1.45.2.46 knu 676: print "</th>";
677: }
678: $infocols++;
1.45.2.56 knu 679: printf '<th align=left bgcolor="%s">',
680: $bylog ? $columnHeaderColorSorted : $columnHeaderColorDefault;
681: if ($bylog) {
682: print 'Last log entry';
683: } else {
684: print &link('Last log entry', sprintf('./%s#dirlist',
685: &toggleQuery("sortby", "log")));
686: }
1.45.2.46 knu 687: print "</th>";
688: }
689: elsif ($use_descriptions) {
1.45.2.56 knu 690: printf '<th align=left bgcolor="%s">', $columnHeaderColorDefault;
1.45.2.46 knu 691: print "Description";
692: $infocols++;
693: }
694: print "</tr>\n";
695: }
696: else {
697: print "<menu>\n";
698: }
699: my $dirrow = 0;
1.45.2.47 knu 700:
1.45.2.46 knu 701: my $i;
1.9 fenner 702: lookingforattic:
703: for ($i = 0; $i <= $#dir; $i++) {
704: if ($dir[$i] eq "Attic") {
1.45.2.46 knu 705: last lookingforattic;
1.9 fenner 706: }
707: }
1.45.2.46 knu 708: if (!$input{'hideattic'} && ($i <= $#dir) &&
709: opendir($dh, $fullname . "/Attic")) {
710: splice(@dir, $i, 1,
711: grep((s|^|Attic/|,!m|/\.|), readdir($dh)));
712: closedir($dh);
1.9 fenner 713: }
1.45.2.46 knu 714:
1.45.2.56 knu 715: my $hideAtticToggleLink = $input{'hideattic'} ? '' :
716: &link('[Hide]', sprintf('./%s#dirlist',
717: &toggleQuery ("hideattic")));
1.45.2.46 knu 718:
1.9 fenner 719: # Sort without the Attic/ pathname.
1.45.2.46 knu 720: # place directories first
721:
722: my $attic;
723: my $url;
724: my $fileurl;
725: my $filesexists;
726: my $filesfound;
727:
728: foreach (sort { &fileSortCmp } @dir) {
1.1 jfieber 729: if ($_ eq '.') {
730: next;
731: }
1.19 wosch 732: # ignore CVS lock and stale NFS files
1.45.2.46 knu 733: next if (/^#cvs\.|^,|^\.nfs/);
734:
735: # Check whether to show the CVSROOT path
736: next if ($input{'hidecvsroot'} && ($_ eq 'CVSROOT'));
737:
738: # Check whether the module is in the restricted list
739: next if ($_ && &forbidden_module($_));
740:
741: # Ignore non-readable files
742: next if ($input{'hidenonreadable'} && !(-r "$fullname/$_"));
1.18 wosch 743:
1.9 fenner 744: if (s|^Attic/||) {
1.45.2.46 knu 745: $attic = " (in the Attic) " . $hideAtticToggleLink;
746: }
747: else {
1.9 fenner 748: $attic = "";
749: }
1.45.2.46 knu 750:
751: if ($_ eq '..' || -d "$fullname/$_") {
752: next if ($_ eq '..' && $where eq '/');
1.45.2.68 knu 753: my ($rev,$date,$log,$author,$filename);
754: ($rev,$date,$log,$author,$filename) = @{$fileinfo{$_}}
1.45.2.46 knu 755: if (defined($fileinfo{$_}));
1.45.2.56 knu 756: printf '<tr bgcolor="%s"><td>', $tabcolors[$dirrow % 2] if $dirtable;
1.45.2.46 knu 757: if ($_ eq '..') {
1.45.2.56 knu 758: $url = "../$query";
1.45.2.46 knu 759: if ($nofilelinks) {
760: print $backicon;
761: }
762: else {
1.45.2.56 knu 763: print &link($backicon, $url);
1.45.2.46 knu 764: }
1.45.2.56 knu 765: print " ", &link("Previous Directory", $url);
1.45.2.46 knu 766: }
767: else {
1.45.2.56 knu 768: $url = urlencode($_) . "/$query";
1.45.2.46 knu 769: print "<A NAME=\"$_\"></A>";
770: if ($nofilelinks) {
771: print $diricon;
772: }
773: else {
1.45.2.56 knu 774: print &link($diricon, $url);
1.45.2.46 knu 775: }
1.45.2.56 knu 776: print " ", &link("$_/", $url), $attic;
1.45.2.46 knu 777: if ($_ eq "Attic") {
1.45.2.56 knu 778: print " ";
779: print &link("[Don't hide]", sprintf('./%s#dirlist',
780: &toggleQuery ("hideattic")));
1.45.2.46 knu 781: }
1.45.2.47 knu 782: }
1.45.2.46 knu 783: # Show last change in dir
784: if ($filename) {
785: print "</td><td> </td><td> " if ($dirtable);
786: if ($date) {
1.45.2.56 knu 787: print " <i>", readableTime(time() - $date,0), "</i>";
1.45.2.46 knu 788: }
789: if ($show_author) {
790: print "</td><td> " if ($dirtable);
791: print $author;
792: }
793: print "</td><td> " if ($dirtable);
794: $filename =~ s%^[^/]+/%%;
795: print "$filename/$rev";
796: print "<BR>" if ($dirtable);
797: if ($log) {
1.45.2.56 knu 798: print " <font size=-1>",
799: &htmlify(substr($log,0,$shortLogLen));
1.45.2.46 knu 800: if (length $log > 80) {
801: print "...";
802: }
803: print "</font>";
804: }
805: }
806: else {
807: my ($dwhere) = ($where ne "/" ? $where : "") . $_;
808: if ($use_descriptions && defined $descriptions{$dwhere}) {
1.45.2.56 knu 809: print "<TD COLSPAN=", ($infocols-1), "> " if $dirtable;
1.45.2.46 knu 810: print $descriptions{$dwhere};
811: } elsif ($dirtable && $infocols > 1) {
812: # close the row with the appropriate number of
813: # columns, so that the vertical seperators are visible
814: my($cols) = $infocols;
815: while ($cols > 1) {
816: print "</td><td> ";
817: $cols--;
818: }
819: }
820: }
821: if ($dirtable) {
822: print "</td></tr>\n";
823: }
824: else {
825: print "<br>\n";
826: }
827: $dirrow++;
1.9 fenner 828: }
1.45.2.46 knu 829: elsif (s/,v$//) {
830: $fileurl = ($attic ? "Attic/" : "") . urlencode($_);
831: $url = $fileurl . $query;
832: my $rev = '';
833: my $date = '';
834: my $log = '';
835: my $author = '';
836: $filesexists++;
837: next if (!defined($fileinfo{$_}));
838: ($rev,$date,$log,$author) = @{$fileinfo{$_}};
839: $filesfound++;
1.45.2.56 knu 840: printf '<tr bgcolor="%s"><td>', $tabcolors[$dirrow % 2] if $dirtable;
1.45.2.46 knu 841: print "<A NAME=\"$_\"></A>";
842: if ($nofilelinks) {
843: print $fileicon;
844: }
845: else {
846: print &link($fileicon,$url);
847: }
848: print " ", &link($_, $url), $attic;
849: print "</td><td> " if ($dirtable);
850: download_link($fileurl,
1.45.2.56 knu 851: $rev, $rev,
852: $defaultViewable ? "text/x-cvsweb-markup" : undef);
1.45.2.46 knu 853: print "</td><td> " if ($dirtable);
854: if ($date) {
1.45.2.56 knu 855: print " <i>", readableTime(time() - $date,0), "</i>";
1.45.2.46 knu 856: }
857: if ($show_author) {
858: print "</td><td> " if ($dirtable);
859: print $author;
860: }
861: print "</td><td> " if ($dirtable);
862: if ($log) {
1.45.2.56 knu 863: print " <font size=-1>", &htmlify(substr($log,0,$shortLogLen));
1.45.2.46 knu 864: if (length $log > 80) {
865: print "...";
866: }
867: print "</font>";
868: }
869: print "</td>" if ($dirtable);
870: print (($dirtable) ? "</tr>" : "<br>");
871: $dirrow++;
872: }
873: print "\n";
874: }
875: if ($dirtable && defined($tableBorderColor)) {
876: print "</td></tr></table>";
877: }
1.45.2.56 knu 878: print( $dirtable == 1 ? "</table>\n" : "</menu>\n" );
1.45.2.47 knu 879:
1.45.2.46 knu 880: if ($filesexists && !$filesfound) {
881: print "<P><B>NOTE:</B> There are $filesexists files, but none matches the current tag ($input{only_with_tag})\n";
882: }
883: if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
884: %tags = %alltags
885: }
1.45.2.47 knu 886: if (scalar %tags
887: || $input{only_with_tag}
1.45.2.46 knu 888: || $edit_option_form
889: || defined($input{"options"})) {
890: print "<hr size=1 NOSHADE>";
891: }
892:
893: if (scalar %tags || $input{only_with_tag}) {
894: print "<FORM METHOD=\"GET\" ACTION=\"./\">\n";
895: foreach my $var (@stickyvars) {
896: print "<INPUT TYPE=HIDDEN NAME=\"$var\" VALUE=\"$input{$var}\">\n"
897: if (defined($input{$var})
1.45.2.51 knu 898: && (!defined($DEFAULTVALUE{$var})
899: || $input{$var} ne $DEFAULTVALUE{$var})
1.45.2.46 knu 900: && $input{$var} ne ""
901: && $var ne "only_with_tag");
902: }
903: print "Show only files with tag:\n";
904: print "<SELECT NAME=only_with_tag";
905: print " onchange=\"submit()\"" if ($use_java_script);
906: print ">";
907: print "<OPTION VALUE=\"\">All tags / default branch\n";
908: foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
1.45.2.47 knu 909: print "<OPTION",defined($input{only_with_tag}) &&
910: $input{only_with_tag} eq $tag ? " SELECTED" : "",
1.45.2.46 knu 911: ">$tag\n";
912: }
913: print "</SELECT>\n";
1.45.2.65 knu 914: print " Module path or alias:\n";
915: printf "<INPUT TYPE=TEXT NAME=\"path\" VALUE=\"%s\" SIZE=15>\n", htmlquote($where);
1.45.2.46 knu 916: print "<INPUT TYPE=SUBMIT VALUE=\"Go\">\n";
1.9 fenner 917: print "</FORM>\n";
918: }
1.45.2.61 knu 919:
920: if ($allow_tar) {
921: my($basefile) = ($where =~ m,(?:.*/)?([^/]+),);
922:
1.45.2.65 knu 923: if (defined($basefile) && $basefile ne '') {
1.45.2.61 knu 924: print "<HR NOSHADE>\n",
925: "<DIV align=center>",
926: &link("Download this directory in tarball",
927: # Mangle the filename so browsers show a reasonable
928: # filename to download.
929: "$basefile.tar.gz$query".
930: ($query ? "&" : "?")."tarball=1"),
931: "</DIV>";
932: }
933: }
934:
1.45.2.46 knu 935: my $formwhere = $scriptwhere;
936: $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
937:
938: if ($edit_option_form || defined($input{"options"})) {
939: print "<FORM METHOD=\"GET\" ACTION=\"${formwhere}\">\n";
940: print "<INPUT TYPE=HIDDEN NAME=\"copt\" VALUE=\"1\">\n";
941: if ($cvstree ne $cvstreedefault) {
942: print "<INPUT TYPE=HIDDEN NAME=\"cvsroot\" VALUE=\"$cvstree\">\n";
943: }
944: print "<center><table cellpadding=0 cellspacing=0>";
945: print "<tr bgcolor=\"$columnHeaderColorDefault\"><th colspan=2>Preferences</th></tr>";
946: print "<tr><td>Sort files by <SELECT name=\"sortby\">";
947: print "<OPTION VALUE=\"\">File";
948: print "<OPTION",$bydate ? " SELECTED" : ""," VALUE=date>Age";
949: print "<OPTION",$byauthor ? " SELECTED" : ""," VALUE=author>Author"
950: if ($show_author);
951: print "<OPTION",$byrev ? " SELECTED" : ""," VALUE=rev>Revision";
952: print "<OPTION",$bylog ? " SELECTED" : ""," VALUE=log>Log message";
953: print "</SELECT></td>";
1.45.2.56 knu 954: print "<td>Sort log by: ";
955: printLogSortSelect(0);
956: print "</td></tr>";
1.45.2.46 knu 957: print "<tr><td>Diff format: ";
1.45.2.47 knu 958: printDiffSelect(0);
1.45.2.46 knu 959: print "</td>";
960: print "<td>Show Attic files: ";
1.45.2.47 knu 961: print "<INPUT NAME=hideattic TYPE=CHECKBOX", $input{'hideattic'} ? " CHECKED" : "",
1.45.2.46 knu 962: "></td></tr>\n";
963: print "<tr><td align=center colspan=2><input type=submit value=\"Change Options\">";
964: print "</td></tr></table></center></FORM>\n";
1.12 fenner 965: }
1.2 jfieber 966: print &html_footer;
1.1 jfieber 967: print "</BODY></HTML>\n";
1.45.2.47 knu 968: }
1.45.2.46 knu 969:
970: ###############################
971: # View Files
972: ###############################
973: elsif (-f $fullname . ',v') {
974: if (defined($input{'rev'}) || $doCheckout) {
975: &doCheckout($fullname, $input{'rev'});
1.45.2.52 knu 976: gzipclose();
1.45.2.46 knu 977: exit;
978: }
979: if (defined($input{'annotate'}) && $allow_annotate) {
980: &doAnnotate($input{'annotate'});
1.45.2.52 knu 981: gzipclose();
1.45.2.46 knu 982: exit;
983: }
984: if (defined($input{'r1'}) && defined($input{'r2'})) {
985: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
986: $input{'r2'}, $input{'tr2'}, $input{'f'});
1.45.2.52 knu 987: gzipclose();
1.45.2.46 knu 988: exit;
989: }
990: print("going to dolog($fullname)\n") if ($verbose);
991: &doLog($fullname);
992: ##############################
993: # View Diff
994: ##############################
995: }
996: elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" &&
997: $input{'r1'} && $input{'r2'}) {
998:
999: # $where-diff-removal if 'cvs rdiff' is used
1000: # .. but 'cvs rdiff'doesn't support some options
1001: # rcsdiff does (-w and -p), so it is disabled
1002: # $where =~ s/\.diff$//;
1003:
1.12 fenner 1004: # Allow diffs using the ".diff" extension
1005: # so that browsers that default to the URL
1006: # for a save filename don't save diff's as
1007: # e.g. foo.c
1.45.2.46 knu 1008: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1.12 fenner 1009: $input{'r2'}, $input{'tr2'}, $input{'f'});
1.45.2.52 knu 1010: gzipclose();
1.12 fenner 1011: exit;
1.45.2.46 knu 1012: }
1013: elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| &&
1014: -f $newname . ",v") {
1.12 fenner 1015: # The file has been removed and is in the Attic.
1016: # Send a redirect pointing to the file in the Attic.
1.45.2.46 knu 1017: (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
1.45.2.65 knu 1018: redirect("$newplace$query");
1.12 fenner 1019: exit;
1.45.2.46 knu 1020: }
1021: elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
1022: http_header("text/plain");
1.12 fenner 1023: print "You matched the following files:\n";
1024: print join("\n", @files);
1025: # Find the tags from each file
1026: # Display a form offering diffs between said tags
1.45.2.46 knu 1027: }
1028: else {
1029: my $fh = do {local(*FH);};
1030: my ($xtra, $module);
1.12 fenner 1031: # Assume it's a module name with a potential path following it.
1.45.2.59 knu 1032: $xtra = (($module = $where) =~ s|/.*||) ? $& : '';
1.12 fenner 1033: # Is there an indexed version of modules?
1.45.2.67 knu 1034: if (open($fh, "< $cvsroot/CVSROOT/modules")) {
1.45.2.46 knu 1035: while (<$fh>) {
1036: if (/^(\S+)\s+(\S+)/o && $module eq $1
1.45.2.59 knu 1037: && -d "$cvsroot/$2" && $module ne $2) {
1.45.2.65 knu 1038: redirect("$scriptname/$2$xtra$query");
1.12 fenner 1039: }
1.45.2.46 knu 1040: }
1.12 fenner 1041: }
1042: &fatal("404 Not Found","$where: no such file or directory");
1.45.2.46 knu 1043: }
1.45.2.51 knu 1044:
1.45.2.52 knu 1045: gzipclose();
1.45.2.46 knu 1046: ## End MAIN
1047:
1.45.2.47 knu 1048: sub printDiffSelect($) {
1.45.2.46 knu 1049: my ($use_java_script) = @_;
1.45.2.56 knu 1050: my $f = $input{'f'};
1051:
1052: print '<SELECT NAME="f"';
1053: print ' onchange="submit()"' if $use_java_script;
1054: print '>';
1055:
1056: local $_;
1057: for (@DIFFTYPES) {
1058: printf('<OPTION VALUE="%s"%s>%s',
1059: $_,
1060: $f eq $_ ? ' SELECTED' : '',
1061: "\u$DIFFTYPES{$_}{'descr'}"
1062: );
1063: }
1064:
1065: print "</SELECT>";
1066: }
1067:
1068: sub printLogSortSelect($) {
1069: my ($use_java_script) = @_;
1070:
1071: print '<SELECT NAME="logsort"';
1072: print ' onchange="submit()"' if $use_java_script;
1073: print '>';
1074:
1075: local $_;
1076: for (@LOGSORTKEYS) {
1077: printf('<OPTION VALUE="%s"%s>%s',
1078: $_,
1079: $logsort eq $_ ? ' SELECTED' : '',
1080: "\u$LOGSORTKEYS{$_}{'descr'}"
1081: );
1082: }
1083:
1.45.2.46 knu 1084: print "</SELECT>";
1085: }
1086:
1.45.2.47 knu 1087: sub findLastModifiedSubdirs(@) {
1.45.2.46 knu 1088: my (@dirs) = @_;
1089: my ($dirname, @files);
1090:
1091: foreach $dirname (@dirs) {
1092: next if ($dirname eq ".");
1093: next if ($dirname eq "..");
1094: my ($dir) = "$fullname/$dirname";
1095: next if (!-d $dir);
1096:
1097: my ($lastmod) = undef;
1098: my ($lastmodtime) = undef;
1099: my $dh = do {local(*DH);};
1100:
1101: opendir($dh,$dir) || next;
1102: my (@filenames) = readdir($dh);
1103: closedir($dh);
1104:
1105: foreach my $filename (@filenames) {
1106: $filename = "$dirname/$filename";
1107: my ($file) = "$fullname/$filename";
1108: next if ($filename !~ /,v$/ || !-f $file);
1109: $filename =~ s/,v$//;
1110: my $modtime = -M $file;
1111: if (!defined($lastmod) || $modtime < $lastmodtime) {
1112: $lastmod = $filename;
1113: $lastmodtime = $modtime;
1114: }
1115: }
1116: push(@files, $lastmod) if (defined($lastmod));
1117: }
1118: return @files;
1.12 fenner 1119: }
1120:
1.45.2.56 knu 1121: sub htmlify_sub(&$) {
1122: (my $proc, local $_) = @_;
1123: local @_ = split(m`(<a [^>]+>[^<]*</a>)`i);
1.45.2.57 knu 1124: my $linked;
1125: my $result = '';
1.45.2.56 knu 1126:
1127: while (($_, $linked) = splice(@_, 0, 2)) {
1128: &$proc();
1.45.2.57 knu 1129: $result .= $_ if defined($_);
1130: $result .= $linked if defined($linked);
1.45.2.56 knu 1131: }
1.12 fenner 1132:
1.45.2.56 knu 1133: $result;
1134: }
1.12 fenner 1135:
1.45.2.56 knu 1136: sub htmlify($;$) {
1137: (local $_, my $extra) = @_;
1.45.2.46 knu 1138:
1.45.2.56 knu 1139: $_ = htmlquote($_);
1.45.2.49 knu 1140:
1.45.2.56 knu 1141: # get URL's as link
1142: s{
1143: (http|ftp|https)://\S+
1144: }{
1145: &link($&, htmlunquote($&))
1146: }egx;
1147:
1148: # get e-mails as link
1149: $_ = htmlify_sub {
1150: s<
1151: [\w+=\-.!]+@[\w\-]+(\.[\w\-]+)+
1152: ><
1153: &link($&, "mailto:$&")
1154: >egix;
1155: } $_;
1156:
1157: if ($extra) {
1158: # get PR #'s as link: "PR#nnnn" "PR: nnnn, ..." "PR nnnn, ..." "bin/nnnn"
1.45.2.63 knu 1159: if (defined($prcgi) && defined($re_prcategories) && defined($re_prkeyword)) {
1.45.2.56 knu 1160: my $prev;
1161:
1162: do {
1163: $prev = $_;
1164:
1165: $_ = htmlify_sub {
1166: s{
1.45.2.63 knu 1167: (\b$re_prkeyword[:\#]?\s*
1.45.2.56 knu 1168: (?:
1169: \#?
1170: \d+[,\s]\s*
1171: )*
1172: \#?)
1173: (\d+)\b
1174: }{
1.45.2.58 knu 1175: $1 . &link($2, sprintf($prcgi, $2))
1.45.2.56 knu 1176: }egix;
1177: } $_;
1178: } while ($_ ne $prev);
1179:
1180: $_ = htmlify_sub {
1181: s{
1.45.2.63 knu 1182: (\b$re_prcategories/(\d+)\b)
1.45.2.56 knu 1183: }{
1.45.2.58 knu 1184: &link($1, sprintf($prcgi, $2))
1.45.2.56 knu 1185: }egox;
1186: } $_;
1187: }
1188:
1189: # get manpage specs as link: "foo.1" "foo(1)"
1190: if (defined($mancgi)) {
1191: $_ = htmlify_sub {
1192: s{
1.45.2.63 knu 1193: (\b([a-zA-Z][\w.]+)
1.45.2.56 knu 1194: (?:
1195: \( ([0-9n]) \)\B
1196: |
1197: \.([0-9n])\b
1198: )
1199: )
1200: }{
1.45.2.63 knu 1201: &link($1, sprintf($mancgi, defined($3) ? $3 : $4, $2))
1.45.2.56 knu 1202: }egx;
1203: } $_;
1.12 fenner 1204: }
1.45.2.56 knu 1205: }
1.12 fenner 1206:
1.45.2.56 knu 1207: $_;
1.45.2.46 knu 1208: }
1209:
1.45.2.51 knu 1210: sub spacedHtmlText($;$) {
1.45.2.47 knu 1211: local $_ = $_[0];
1.45.2.51 knu 1212: my $ts = $_[1] || $tabstop;
1.45.2.46 knu 1213:
1.45.2.51 knu 1214: # Cut trailing spaces and tabs
1215: s/[ \t]+$//;
1.45.2.46 knu 1216:
1.45.2.51 knu 1217: if (defined($ts)) {
1218: # Expand tabs
1219: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e
1220: }
1.45.2.46 knu 1221:
1222: # replace <tab> and <space> (\001 is to protect us from htmlify)
1223: # gzip can make excellent use of this repeating pattern :-)
1224: if ($hr_breakable) {
1225: # make every other space 'breakable'
1.45.2.47 knu 1226: s/ / \001nbsp;/g; # 2 * <space>
1.45.2.46 knu 1227: # leave single space as it is
1.45.2.51 knu 1228: } else {
1.45.2.47 knu 1229: s/ /\001nbsp;/g;
1.45.2.46 knu 1230: }
1231:
1.45.2.47 knu 1232: $_ = htmlify($_);
1.45.2.46 knu 1233:
1234: # unescape
1.45.2.51 knu 1235: y/\001/&/;
1.45.2.46 knu 1236:
1.45.2.47 knu 1237: return $_;
1.12 fenner 1238: }
1239:
1.45.2.47 knu 1240: sub link($$) {
1.45.2.67 knu 1241: my($name, $url) = @_;
1.12 fenner 1242:
1.45.2.69! knu 1243: $url =~ s/:/sprintf("%%%02x", ord($&))/eg;
! 1244:
1.45.2.67 knu 1245: sprintf '<A HREF="%s">%s</A>', hrefquote($url), $name;
1.12 fenner 1246: }
1247:
1.45.2.47 knu 1248: sub revcmp($$) {
1.45.2.46 knu 1249: my($rev1, $rev2) = @_;
1.45.2.48 knu 1250:
1251: # make no comparison for a tag or a branch
1252: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
1253:
1.45.2.46 knu 1254: my(@r1) = split(/\./, $rev1);
1255: my(@r2) = split(/\./, $rev2);
1256: my($a,$b);
1.12 fenner 1257:
1258: while (($a = shift(@r1)) && ($b = shift(@r2))) {
1259: if ($a != $b) {
1260: return $a <=> $b;
1261: }
1262: }
1263: if (@r1) { return 1; }
1264: if (@r2) { return -1; }
1265: return 0;
1266: }
1267:
1.45.2.47 knu 1268: sub fatal($$) {
1.45.2.46 knu 1269: my($errcode, $errmsg) = @_;
1270: if ($is_mod_perl) {
1271: Apache->request->status((split(/ /, $errcode))[0]);
1272: }
1273: else {
1274: print "Status: $errcode\r\n";
1275: }
1276: html_header("Error");
1.12 fenner 1277: print "Error: $errmsg\n";
1278: print &html_footer;
1279: exit(1);
1280: }
1281:
1.45.2.47 knu 1282: sub redirect($) {
1.45.2.46 knu 1283: my($url) = @_;
1284: if ($is_mod_perl) {
1285: Apache->request->status(301);
1286: Apache->request->header_out(Location => $url);
1287: }
1288: else {
1289: print "Status: 301 Moved\r\n";
1290: print "Location: $url\r\n";
1291: }
1292: html_header("Moved");
1.45.2.56 knu 1293: print "This document is located ", &link('here', $url), "\n";
1.12 fenner 1294: print &html_footer;
1295: exit(1);
1296: }
1297:
1.45.2.47 knu 1298: sub safeglob($) {
1.45.2.46 knu 1299: my ($filename) = @_;
1300: my ($dirname);
1301: my (@results);
1302: my $dh = do {local(*DH);};
1.12 fenner 1303:
1304: ($dirname = $filename) =~ s|/[^/]+$||;
1305: $filename =~ s|.*/||;
1306:
1.45.2.46 knu 1307: if (opendir($dh, $dirname)) {
1308: my $glob = $filename;
1309: my $t;
1.12 fenner 1310: # transform filename from glob to regex. Deal with:
1311: # [, {, ?, * as glob chars
1312: # make sure to escape all other regex chars
1313: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1314: $glob =~ s/\*/.*/g;
1315: $glob =~ s/\?/./g;
1316: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
1.45.2.46 knu 1317: foreach (readdir($dh)) {
1.12 fenner 1318: if (/^${glob}$/) {
1.45.2.56 knu 1319: push(@results, "$dirname/" .$_);
1.12 fenner 1320: }
1321: }
1.45.2.69! knu 1322: closedir($dh);
1.12 fenner 1323: }
1324:
1325: @results;
1326: }
1327:
1.45.2.67 knu 1328: sub search_path($) {
1329: my($command) = @_;
1330: my $d;
1331:
1332: for $d (split(/:/, $command_path)) {
1333: return "$d/$command" if -x "$d/$command";
1334: }
1335:
1336: $command;
1337: }
1338:
1.45.2.47 knu 1339: sub getMimeTypeFromSuffix($) {
1.45.2.46 knu 1340: my ($fullname) = @_;
1341: my ($mimetype, $suffix);
1342: my $fh = do {local(*FH);};
1343:
1344: ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1345: $mimetype = $MTYPES{$suffix};
1346: $mimetype = $MTYPES{'*'} if (!$mimetype);
1.45.2.47 knu 1347:
1.45.2.46 knu 1348: if (!$mimetype && -f $mime_types) {
1349: # okey, this is something special - search the
1350: # mime.types database
1351: open ($fh, "<$mime_types");
1352: while (<$fh>) {
1353: if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
1354: $mimetype = $1;
1355: last;
1356: }
1357: }
1358: close ($fh);
1359: }
1.45.2.47 knu 1360:
1.45.2.46 knu 1361: # okey, didn't find anything useful ..
1362: if (!($mimetype =~ /\S\/\S/)) {
1363: $mimetype = "text/plain";
1364: }
1365: return $mimetype;
1366: }
1.12 fenner 1367:
1.45.2.46 knu 1368: ###############################
1.45.2.51 knu 1369: # read first lines like head(1)
1370: ###############################
1371: sub head($;$) {
1372: my $fh = $_[0];
1373: my $linecount = $_[1] || 10;
1374:
1375: my @buf;
1376:
1377: if ($linecount > 0) {
1378: my $i;
1379: for ($i = 0; !eof($fh) && $i < $linecount; $i++) {
1380: push @buf, scalar <$fh>;
1381: }
1382: } else {
1383: @buf = <$fh>;
1384: }
1385:
1386: @buf;
1387: }
1388:
1389: ###############################
1390: # scan vim and Emacs directives
1391: ###############################
1392: sub scan_directives(@) {
1393: my $ts = undef;
1394:
1395: for (@_) {
1396: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1397: }
1398:
1399: ('tabstop' => $ts);
1400: }
1401:
1402: ###############################
1.45.2.46 knu 1403: # show Annotation
1404: ###############################
1.45.2.47 knu 1405: sub doAnnotate($$) {
1.45.2.46 knu 1406: my ($rev) = @_;
1407: my ($pid);
1408: my ($pathname, $filename);
1409: my $reader = do {local(*FH);};
1410: my $writer = do {local(*FH);};
1411:
1.45.2.67 knu 1412: # make sure the revisions are wellformed, for security
1.45.2.46 knu 1413: # reasons ..
1.45.2.48 knu 1414: if ($rev =~ /[^\w.]/) {
1.45.2.46 knu 1415: &fatal("404 Not Found",
1416: "Malformed query \"$ENV{QUERY_STRING}\"");
1417: }
1418:
1419: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1420: ($filename = $where) =~ s/^.*\///;
1421:
1422: # this seems to be necessary
1423: $| = 1; $| = 0; # Flush
1424:
1425: # this annotate version is based on the
1426: # cvs annotate-demo Perl script by Cyclic Software
1427: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1428: # the public domain.
1429: # we could abandon the use of rlog, rcsdiff and co using
1430: # the cvsserver in a similiar way one day (..after rewrite)
1.45.2.69! knu 1431: $pid = open2($reader, $writer, $CMD{cvs}, @cvs_options, "server")
1.45.2.64 knu 1432: || fatal ("500 Internal Error", "Fatal Error - unable to open cvs for annotation");
1.45.2.47 knu 1433:
1.45.2.46 knu 1434: # OK, first send the request to the server. A simplified example is:
1435: # Root /home/kingdon/zwork/cvsroot
1436: # Argument foo/xx
1437: # Directory foo
1438: # /home/kingdon/zwork/cvsroot/foo
1439: # Directory .
1440: # /home/kingdon/zwork/cvsroot
1441: # annotate
1442: # although as you can see there are a few more details.
1.45.2.47 knu 1443:
1.45.2.46 knu 1444: print $writer "Root $cvsroot\n";
1445: print $writer "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1446: # Don't worry about sending valid-requests, the server just needs to
1447: # support "annotate" and if it doesn't, there isn't anything to be done.
1448: print $writer "UseUnchanged\n";
1449: print $writer "Argument -r\n";
1450: print $writer "Argument $rev\n";
1451: print $writer "Argument $where\n";
1452:
1453: # The protocol requires us to fully fake a working directory (at
1454: # least to the point of including the directories down to the one
1455: # containing the file in question).
1456: # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
1457: my @dirs = split('/', $where);
1458: my $path = "";
1459: foreach (@dirs) {
1460: if ($path eq "") {
1461: # In our example, $_ is "dir".
1462: $path = $_;
1.45.2.47 knu 1463: }
1.45.2.46 knu 1464: else {
1465: print $writer "Directory $path\n";
1466: print $writer "$cvsroot/$path\n";
1467: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1468: # And the next time, "file" and "dir/sdir/file" (which then gets
1469: # ignored, because we don't need to send Directory for the file).
1470: $path .= "/$_";
1.12 fenner 1471: }
1.45.2.46 knu 1472: }
1473: # And the last "Directory" before "annotate" is the top level.
1474: print $writer "Directory .\n";
1475: print $writer "$cvsroot\n";
1.45.2.47 knu 1476:
1.45.2.46 knu 1477: print $writer "annotate\n";
1478: # OK, we've sent our command to the server. Thing to do is to
1479: # close the writer side and get all the responses. If "cvs server"
1480: # were nicer about buffering, then we could just leave it open, I think.
1481: close ($writer) || die "cannot close: $!";
1.45.2.47 knu 1482:
1.45.2.54 knu 1483: http_header();
1484:
1485: navigateHeader($scriptwhere,$pathname,$filename,$rev, "annotate");
1486: print "<h3 align=center>Annotation of $pathname$filename, Revision $rev</h3>\n";
1487:
1.45.2.46 knu 1488: # Ready to get the responses from the server.
1489: # For example:
1490: # E Annotations for foo/xx
1491: # E ***************
1.45.2.47 knu 1492: # M 1.3 (kingdon 06-Sep-97): hello
1.45.2.46 knu 1493: # ok
1494: my ($lineNr) = 0;
1495: my ($oldLrev, $oldLusr) = ("", "");
1496: my ($revprint, $usrprint);
1497: if ($annTable) {
1498: print "<table border=0 cellspacing=0 cellpadding=0>\n";
1499: }
1500: else {
1501: print "<pre>";
1502: }
1.45.2.51 knu 1503:
1504: # prefetch several lines
1505: my @buf = head($reader);
1506:
1507: my %d = scan_directives(@buf);
1508:
1509: while (@buf || !eof($reader)) {
1510: $_ = @buf ? shift @buf : <$reader>;
1511:
1.45.2.46 knu 1512: my @words = split;
1513: # Adding one is for the (single) space which follows $words[0].
1514: my $rest = substr ($_, length ($words[0]) + 1);
1515: if ($words[0] eq "E") {
1516: next;
1517: }
1518: elsif ($words[0] eq "M") {
1519: $lineNr++;
1.45.2.54 knu 1520: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1521: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1522: my $line = substr($_, 36);
1523: my $isCurrentRev = ($rev eq $lrev);
1.45.2.46 knu 1524: # we should parse the date here ..
1525: if ($lrev eq $oldLrev) {
1.45.2.54 knu 1526: $revprint = sprintf('%-8s', '');
1.45.2.46 knu 1527: }
1528: else {
1.45.2.54 knu 1529: $revprint = sprintf('%-8s', $lrev);
1.45.2.56 knu 1530: $revprint =~ s`\S+`&link($&, "$scriptwhere$query#rev$&")`e; # `
1.45.2.54 knu 1531: $oldLusr = '';
1.45.2.46 knu 1532: }
1533: if ($lusr eq $oldLusr) {
1.45.2.54 knu 1534: $usrprint = '';
1.45.2.46 knu 1535: }
1536: else {
1537: $usrprint = $lusr;
1538: }
1539: $oldLrev = $lrev;
1540: $oldLusr = $lusr;
1.45.2.47 knu 1541:
1.45.2.54 knu 1542: # Set bold for text-based browsers only - graphical
1543: # browsers show bold fonts a bit wider than regular fonts,
1544: # so it looks irregular.
1545: print "<b>" if ($isCurrentRev && $is_textbased);
1546:
1.45.2.55 knu 1547: printf "%s%s %-8s %4d:",
1.45.2.54 knu 1548: $revprint,
1549: $isCurrentRev ? '!' : ' ',
1550: $usrprint,
1.45.2.55 knu 1551: $lineNr;
1.45.2.51 knu 1552: print spacedHtmlText($line, $d{'tabstop'});
1.45.2.54 knu 1553:
1554: print "</b>" if ($isCurrentRev && $is_textbased);
1.45.2.46 knu 1555: }
1556: elsif ($words[0] eq "ok") {
1557: # We could complain about any text received after this, like the
1558: # CVS command line client. But for simplicity, we don't.
1559: }
1560: elsif ($words[0] eq "error") {
1.45.2.56 knu 1561: fatal("500 Internal Error", "Error occured during annotate: <b>$_</b>");
1.45.2.46 knu 1562: }
1563: }
1564: if ($annTable) {
1565: print "</table>";
1566: }
1567: else {
1568: print "</pre>";
1569: }
1570: close ($reader) || warn "cannot close: $!";
1571: wait;
1572: }
1573:
1574: ###############################
1575: # make Checkout
1576: ###############################
1.45.2.47 knu 1577: sub doCheckout($$) {
1.45.2.46 knu 1578: my ($fullname, $rev) = @_;
1579: my ($mimetype,$revopt);
1580: my $fh = do {local(*FH);};
1581:
1.45.2.48 knu 1582: if ($rev eq 'HEAD' || $rev eq '.') {
1583: $rev = undef;
1584: }
1585:
1.45.2.46 knu 1586: # make sure the revisions a wellformed, for security
1587: # reasons ..
1.45.2.48 knu 1588: if (defined($rev) && $rev =~ /[^\w.]/) {
1.45.2.46 knu 1589: &fatal("404 Not Found",
1590: "Malformed query \"$ENV{QUERY_STRING}\"");
1591: }
1592:
1593: # get mimetype
1594: if (defined($input{"content-type"}) && ($input{"content-type"} =~ /\S\/\S/)) {
1595: $mimetype = $input{"content-type"}
1596: }
1597: else {
1598: $mimetype = &getMimeTypeFromSuffix($fullname);
1599: }
1600:
1601: if (defined($rev)) {
1602: $revopt = "-r$rev";
1603: if ($use_moddate) {
1604: readLog($fullname,$rev);
1605: $moddate=$date{$rev};
1606: }
1607: }
1608: else {
1609: $revopt = "-rHEAD";
1610: if ($use_moddate) {
1611: readLog($fullname);
1612: $moddate=$date{$symrev{HEAD}};
1613: }
1614: }
1.45.2.47 knu 1615:
1.45.2.46 knu 1616: ### just for the record:
1617: ### 'cvs co' seems to have a bug regarding single checkout of
1618: ### directories/files having spaces in it;
1619: ### this is an issue that should be resolved on cvs's side
1620: #
1621: # Safely for a child process to read from.
1622: if (! open($fh, "-|")) { # child
1.45.2.67 knu 1623: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1624: exec($CMD{cvs}, @cvs_options, '-d', $cvsroot, 'co', '-p', $revopt, $where);
1.45.2.47 knu 1625: }
1.45.2.58 knu 1626:
1627: if (eof($fh)) {
1628: &fatal("404 Not Found",
1629: "$where is not (any longer) pertinent");
1630: }
1.45.2.46 knu 1631: #===================================================================
1632: #Checking out squid/src/ftp.c
1633: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1634: #VERS: 1.1.1.28.6.2
1635: #***************
1636:
1637: # Parse CVS header
1638: my ($revision, $filename, $cvsheader);
1639: while(<$fh>) {
1640: last if (/^\*\*\*\*/);
1641: $revision = $1 if (/^VERS: (.*)$/);
1642: if (/^Checking out (.*)$/) {
1643: $filename = $1;
1644: $filename =~ s/^\.\/*//;
1645: }
1646: $cvsheader .= $_;
1647: }
1648: if ($filename ne $where) {
1649: &fatal("500 Internal Error",
1.45.2.58 knu 1650: "Unexpected output from cvs co: $cvsheader");
1.45.2.46 knu 1651: }
1652: $| = 1;
1653:
1654: if ($mimetype eq "text/x-cvsweb-markup") {
1655: &cvswebMarkup($fh,$fullname,$revision);
1656: }
1657: else {
1658: http_header($mimetype);
1659: print <$fh>;
1660: }
1661: close($fh);
1662: }
1663:
1.45.2.47 knu 1664: sub cvswebMarkup($$$) {
1.45.2.46 knu 1665: my ($filehandle,$fullname,$revision) = @_;
1666: my ($pathname, $filename);
1667:
1668: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1669: ($filename = $where) =~ s/^.*\///;
1670: my ($fileurl) = urlencode($filename);
1671:
1672: http_header();
1673:
1.45.2.47 knu 1674: navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
1.45.2.46 knu 1675: print "<HR noshade>";
1676: print "<table width=\"100%\"><tr><td bgcolor=\"$markupLogColor\">";
1677: print "File: ", &clickablePath($where, 1);
1.45.2.56 knu 1678: print " (";
1679: &download_link($fileurl, $revision, "download");
1680: print ")";
1.45.2.46 knu 1681: if (!$defaultTextPlain) {
1.45.2.56 knu 1682: print " (";
1683: &download_link($fileurl, $revision, "as text",
1.45.2.46 knu 1684: "text/plain");
1.45.2.56 knu 1685: print ")";
1.45.2.46 knu 1686: }
1687: print "<BR>\n";
1688: if ($show_log_in_markup) {
1689: readLog($fullname); #,$revision);
1690: printLog($revision,0);
1691: }
1692: else {
1693: print "Version: <B>$revision</B><BR>\n";
1694: print "Tag: <B>", $input{only_with_tag}, "</b><br>\n" if
1695: $input{only_with_tag};
1696: }
1697: print "</td></tr></table>";
1698: my $url = download_url($fileurl, $revision, $mimetype);
1699: print "<HR noshade>";
1700: if ($mimetype =~ /^image/) {
1.45.2.61 knu 1701: printf '<IMG SRC="%s"><BR>', hrefquote("$url$barequery");
1.45.2.46 knu 1702: }
1.45.2.51 knu 1703: elsif ($mimetype =~ m%^application/pdf%) {
1.45.2.61 knu 1704: printf '<EMBED SRC="%s" WIDTH="100%"><BR>', hrefquote("$url$barequery");
1.45.2.51 knu 1705: }
1.45.2.63 knu 1706: elsif ($preformat_in_markup) {
1.45.2.46 knu 1707: print "<PRE>";
1.45.2.51 knu 1708:
1709: # prefetch several lines
1710: my @buf = head($filehandle);
1711:
1712: my %d = scan_directives(@buf);
1713:
1714: while (@buf || !eof($filehandle)) {
1715: $_ = @buf ? shift @buf : <$filehandle>;
1716:
1717: print spacedHtmlText($_, $d{'tabstop'});
1.12 fenner 1718: }
1.45.2.46 knu 1719: print "</PRE>";
1720: }
1.45.2.63 knu 1721: else {
1722: print "<PLAINTEXT>\n", <$filehandle>;
1723: }
1.12 fenner 1724: }
1725:
1.45.2.46 knu 1726: sub viewable($) {
1727: my ($mimetype) = @_;
1728:
1.45.2.51 knu 1729: $mimetype =~ m%^((text|image)/|application/pdf)% ;
1.45.2.46 knu 1730: }
1731:
1732: ###############################
1733: # Show Colored Diff
1734: ###############################
1.45.2.47 knu 1735: sub doDiff($$$$$$) {
1.45.2.46 knu 1736: my($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1737: my $fh = do {local(*FH);};
1.45.2.56 knu 1738: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1.12 fenner 1739:
1740: if ($r1 =~ /([^:]+)(:(.+))?/) {
1741: $rev1 = $1;
1742: $sym1 = $3;
1743: }
1.45.2.46 knu 1744: if ($r1 eq 'text') {
1.12 fenner 1745: $rev1 = $tr1;
1.45.2.46 knu 1746: $sym1 = "";
1.12 fenner 1747: }
1748: if ($r2 =~ /([^:]+)(:(.+))?/) {
1749: $rev2 = $1;
1750: $sym2 = $3;
1751: }
1.45.2.46 knu 1752: if ($r2 eq 'text') {
1.12 fenner 1753: $rev2 = $tr2;
1.45.2.46 knu 1754: $sym2 = "";
1.12 fenner 1755: }
1.45.2.48 knu 1756:
1.45.2.46 knu 1757: # make sure the revisions a wellformed, for security
1758: # reasons ..
1.45.2.48 knu 1759: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1.12 fenner 1760: &fatal("404 Not Found",
1.45.2.46 knu 1761: "Malformed query \"$ENV{QUERY_STRING}\"");
1.12 fenner 1762: }
1763: #
1764: # rev1 and rev2 are now both numeric revisions.
1765: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1766: # XXX should we warn about the fact that we do this?
1767: if (&revcmp($rev1,$rev2) > 0) {
1.45.2.46 knu 1768: my ($tmp1, $tmp2) = ($rev1, $sym1);
1.12 fenner 1769: ($rev1, $sym1) = ($rev2, $sym2);
1770: ($rev2, $sym2) = ($tmp1, $tmp2);
1771: }
1.45.2.56 knu 1772: my $difftype = $DIFFTYPES{$f};
1773:
1774: if (!$difftype) {
1.45.2.46 knu 1775: fatal ("400 Bad arguments", "Diff format $f not understood");
1776: }
1777:
1.45.2.56 knu 1778: my @difftype = @{$difftype->{'opts'}};
1779: my $human_readable = $difftype->{'colored'};
1780:
1.45.2.46 knu 1781: # apply special options
1782: if ($showfunc) {
1.45.2.56 knu 1783: push @difftype, '-p' if $f ne 's';
1.45.2.46 knu 1784:
1785: my($re1, $re2);
1786:
1787: while (($re1, $re2) = each %funcline_regexp) {
1788: if ($fullname =~ /$re1/) {
1789: push @difftype, '-F', '$re2';
1790: last;
1791: }
1792: }
1793: }
1794: if ($human_readable) {
1795: if ($hr_ignwhite) {
1796: push @difftype, '-w';
1797: }
1798: if ($hr_ignkeysubst) {
1799: push @difftype, '-kk';
1800: }
1801: }
1802: if (! open($fh, "-|")) { # child
1.44 knu 1803: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1.45.2.67 knu 1804: exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname);
1.45.2.46 knu 1805: }
1806: if ($human_readable) {
1807: http_header();
1808: &human_readable_diff($fh, $rev2);
1.45.2.52 knu 1809: gzipclose();
1.45.2.46 knu 1810: exit;
1811: }
1812: else {
1813: http_header("text/plain");
1.44 knu 1814: }
1.12 fenner 1815: #
1816: #===================================================================
1817: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
1818: #retrieving revision 1.16
1819: #retrieving revision 1.17
1820: #diff -c -r1.16 -r1.17
1821: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1822: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
1823: #
1824: # Ideas:
1825: # - nuke the stderr output if it's what we expect it to be
1826: # - Add "no differences found" if the diff command supplied no output.
1827: #
1828: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1829: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
1830: # (bogus example, but...)
1831: #
1.45.2.46 knu 1832: if (grep { $_ eq '-u'} @difftype) {
1.12 fenner 1833: $f1 = '---';
1834: $f2 = '\+\+\+';
1.45.2.46 knu 1835: }
1836: else {
1.12 fenner 1837: $f1 = '\*\*\*';
1838: $f2 = '---';
1839: }
1.45.2.46 knu 1840: while (<$fh>) {
1.12 fenner 1841: if (m|^$f1 $cvsroot|o) {
1842: s|$cvsroot/||o;
1843: if ($sym1) {
1844: chop;
1.45.2.56 knu 1845: $_ .= " $sym1\n";
1.12 fenner 1846: }
1.45.2.46 knu 1847: }
1848: elsif (m|^$f2 $cvsroot|o) {
1.12 fenner 1849: s|$cvsroot/||o;
1850: if ($sym2) {
1851: chop;
1.45.2.56 knu 1852: $_ .= " $sym2\n";
1.12 fenner 1853: }
1854: }
1855: print $_;
1856: }
1.45.2.46 knu 1857: close($fh);
1.12 fenner 1858: }
1859:
1.45.2.46 knu 1860: ###############################
1861: # Show Logs ..
1862: ###############################
1.45.2.47 knu 1863: sub getDirLogs($$@) {
1.45.2.46 knu 1864: my ($cvsroot,$dirname,@otherFiles) = @_;
1865: my ($state,$otherFiles,$tag, $file, $date, $branchpoint, $branch, $log);
1866: my ($rev, $revision, $revwanted, $filename, $head, $author);
1867:
1868: $tag = $input{only_with_tag};
1869:
1870: my ($DirName) = "$cvsroot/$where";
1871: my (@files, @filetags);
1872: my $fh = do {local(*FH);};
1873:
1874: push(@files, &safeglob("$DirName/*,v"));
1875: push(@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
1876: foreach $file (@otherFiles) {
1877: push(@files, "$DirName/$file");
1878: }
1879:
1880: # just execute rlog if there are any files
1.45.2.47 knu 1881: if ($#files < 0) {
1.45.2.46 knu 1882: return;
1883: }
1884:
1.45.2.63 knu 1885: if (defined($tag)) {
1.45.2.46 knu 1886: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
1887: if (! open($fh, "-|")) {
1.45.2.67 knu 1888: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1889: exec($CMD{rlog}, @files);
1.45.2.46 knu 1890: }
1891: }
1892: else {
1.45.2.67 knu 1893: if (! open($fh, "-|")) {
1894: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1895: exec($CMD{rlog}, '-r', @files);
1.45.2.46 knu 1896: }
1897: }
1898: $state = "start";
1899: while (<$fh>) {
1900: if ($state eq "start") {
1901: #Next file. Initialize file variables
1.45.2.63 knu 1902: $rev = '';
1903: $revwanted = '';
1904: $branch = '';
1905: $branchpoint = '';
1906: $filename = '';
1907: $log = '';
1908: $revision = '';
1.45.2.46 knu 1909: %symrev = ();
1910: @filetags = ();
1911: #jump to head state
1912: $state = "head";
1913: }
1914: print "$state:$_" if ($verbose);
1915: again:
1916: if ($state eq "head") {
1917: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
1.45.2.58 knu 1918:
1919: if (/^Working file: (.+)$/) {
1920: $filename = $1;
1921: } elsif (/^head: (.+)$/) {
1922: $head = $1;
1923: } elsif (/^branch: (.+)$/) {
1924: $branch = $1
1925: } elsif (/^symbolic names:/) {
1926: $state = "tags";
1.45.2.63 knu 1927: ($branch = $head) =~ s/\.\d+$// if $branch eq '';
1.45.2.59 knu 1928: $branch =~ s/(\d+)$/0.$1/;
1.45.2.58 knu 1929: $symrev{MAIN} = $branch;
1930: $symrev{HEAD} = $branch;
1931: $alltags{MAIN} = 1;
1932: $alltags{HEAD} = 1;
1933: push (@filetags, "MAIN", "HEAD");
1934: } elsif (/$LOG_REVSEPARATOR/o) {
1935: $state = "log";
1.45.2.63 knu 1936: $rev = '';
1937: $date = '';
1938: $log = '';
1.45.2.58 knu 1939: # Try to reconstruct the relative filename if RCS spits out a full path
1940: $filename =~ s%^\Q$DirName\E/%%;
1941: }
1.45.2.46 knu 1942: next;
1943: }
1.45.2.58 knu 1944: if ($state eq "tags") {
1945: if (/^\s+(.+):\s+([\d\.]+)\s+$/) {
1946: push (@filetags, $1);
1947: $symrev{$1} = $2;
1948: $alltags{$1} = 1;
1.45.2.46 knu 1949: next;
1.45.2.58 knu 1950: } elsif (/^\S/) {
1951: if (defined($tag)) {
1952: if(defined($symrev{$tag}) || $tag eq "HEAD") {
1953: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
1.45.2.59 knu 1954: ($branch = $revwanted) =~ s/\b0\.//;
1.45.2.58 knu 1955: ($branchpoint = $branch) =~ s/\.?\d+$//;
1.45.2.63 knu 1956: $revwanted = '' if ($revwanted ne $branch);
1.45.2.58 knu 1957: } elsif ($tag ne "HEAD") {
1958: print "Tag not found, skip this file" if ($verbose);
1959: $state = "skip";
1960: next;
1961: }
1962: }
1963: foreach my $tagfound (@filetags) {
1964: $tags{$tagfound} = 1;
1965: }
1966: $state = "head";
1967: goto again;
1.45.2.46 knu 1968: }
1969: }
1970: if ($state eq "log") {
1.45.2.55 knu 1971: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
1.45.2.46 knu 1972: # End of a log entry.
1.45.2.63 knu 1973: my $revbranch = $rev;
1974: $revbranch =~ s/\.\d+$//;
1.45.2.56 knu 1975: print "$filename $rev Wanted: $revwanted ",
1976: "Revbranch: $revbranch Branch: $branch ",
1977: "Branchpoint: $branchpoint\n" if ($verbose);
1.45.2.63 knu 1978: if ($revwanted eq '' && $branch ne ''
1.45.2.46 knu 1979: && $branch eq $revbranch || !defined($tag)) {
1980: print "File revision $rev found for branch $branch\n"
1981: if ($verbose);
1982: $revwanted = $rev;
1983: }
1.45.2.63 knu 1984: if ($revwanted ne '' ? $rev eq $revwanted :
1985: $branchpoint ne '' ? $rev eq $branchpoint :
1.45.2.46 knu 1986: 0 && ($rev eq $head)) { # Don't think head is needed here..
1987: print "File info $rev found for $filename\n" if ($verbose);
1988: my @finfo = ($rev,$date,$log,$author,$filename);
1989: my ($name);
1990: ($name = $filename) =~ s%/.*%%;
1991: $fileinfo{$name} = [ @finfo ];
1992: $state = "done" if ($rev eq $revwanted);
1993: }
1.45.2.63 knu 1994: $rev = '';
1995: $date = '';
1996: $log = '';
1.45.2.46 knu 1997: }
1.45.2.63 knu 1998: elsif ($date eq '' && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
1.45.2.46 knu 1999: my $yr = $1;
2000: # damn 2-digit year routines :-)
2001: if ($yr > 100) {
2002: $yr -= 1900;
2003: }
2004: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
2005: ($author) = /author: ([^;]+)/;
2006: $state = "log";
2007: $log = '';
2008: next;
2009: }
1.45.2.63 knu 2010: elsif ($rev eq '' && /^revision (.*)$/) {
1.45.2.46 knu 2011: $rev = $1;
2012: next;
2013: }
2014: else {
1.45.2.56 knu 2015: $log .= $_;
1.45.2.46 knu 2016: }
2017: }
1.45.2.55 knu 2018: if (/$LOG_FILESEPARATOR/o) {
1.45.2.46 knu 2019: $state = "start";
2020: next;
2021: }
2022: }
2023: if ($. == 0) {
1.45.2.47 knu 2024: fatal("500 Internal Error",
1.45.2.67 knu 2025: "Failed to spawn GNU rlog on <em>'".join(", ", @files)."'</em><p>Did you set the <b>\$command_path</b> in your configuration file correctly ? (Currently '$command_path'");
1.45.2.46 knu 2026: }
2027: close($fh);
2028: }
2029:
1.45.2.47 knu 2030: sub readLog($;$) {
1.45.2.46 knu 2031: my($fullname,$revision) = @_;
2032: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2033: my $fh = do {local(*FH);};
2034:
2035: if (defined($revision)) {
2036: $revision = "-r$revision";
2037: }
2038: else {
2039: $revision = "";
2040: }
2041:
2042: undef %symrev;
2043: undef %revsym;
2044: undef @allrevisions;
2045: undef %date;
2046: undef %author;
2047: undef %state;
2048: undef %difflines;
2049: undef %log;
1.12 fenner 2050:
2051: print("Going to rlog '$fullname'\n") if ($verbose);
1.45.2.46 knu 2052: if (! open($fh, "-|")) { # child
1.45.2.67 knu 2053: if ($revision ne '') {
2054: exec($CMD{rlog}, $revision, $fullname);
2055: }
2056: else {
2057: exec($CMD{rlog}, $fullname);
2058: }
1.44 knu 2059: }
1.45.2.46 knu 2060: while (<$fh>) {
1.1 jfieber 2061: print if ($verbose);
2062: if ($symnames) {
2063: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2064: $symrev{$1} = $2;
1.45.2.46 knu 2065: }
2066: else {
1.1 jfieber 2067: $symnames = 0;
2068: }
1.45.2.46 knu 2069: }
2070: elsif (/^head:\s+([\d\.]+)/) {
2071: $head = $1;
2072: }
2073: elsif (/^branch:\s+([\d\.]+)/) {
2074: $curbranch = $1;
2075: }
2076: elsif (/^symbolic names/) {
1.1 jfieber 2077: $symnames = 1;
1.45.2.46 knu 2078: }
2079: elsif (/^-----/) {
1.1 jfieber 2080: last;
2081: }
2082: }
1.45.2.46 knu 2083: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7 fenner 2084:
1.1 jfieber 2085: # each log entry is of the form:
2086: # ----------------------------
2087: # revision 3.7.1.1
2088: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2089: # log info
2090: # ----------------------------
2091: logentry:
1.45.2.55 knu 2092: while (!/$LOG_FILESEPARATOR/o) {
1.45.2.46 knu 2093: $_ = <$fh>;
1.12 fenner 2094: last logentry if (!defined($_)); # EOF
1.1 jfieber 2095: print "R:", $_ if ($verbose);
2096: if (/^revision ([\d\.]+)/) {
2097: $rev = $1;
1.45.2.46 knu 2098: unshift(@allrevisions,$rev);
2099: }
1.45.2.55 knu 2100: elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
1.1 jfieber 2101: next logentry;
1.45.2.46 knu 2102: }
2103: else {
1.12 fenner 2104: # The rlog output is syntactically ambiguous. We must
2105: # have guessed wrong about where the end of the last log
2106: # message was.
2107: # Since this is likely to happen when people put rlog output
2108: # in their commit messages, don't even bother keeping
2109: # these lines since we don't know what revision they go with
2110: # any more.
2111: next logentry;
2112: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 2113: }
1.45.2.46 knu 2114: $_ = <$fh>;
1.1 jfieber 2115: print "D:", $_ if ($verbose);
1.45.2.46 knu 2116: if (m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|) {
2117: my $yr = $1;
2118: # damn 2-digit year routines :-)
2119: if ($yr > 100) {
2120: $yr -= 1900;
2121: }
2122: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 2123: $author{$rev} = $7;
1.9 fenner 2124: $state{$rev} = $8;
1.45.2.46 knu 2125: $difflines{$rev} = $10;
2126: }
2127: else {
1.1 jfieber 2128: &fatal("500 Internal Error", "Error parsing RCS output: $_");
2129: }
2130: line:
1.45.2.46 knu 2131: while (<$fh>) {
1.1 jfieber 2132: print "L:", $_ if ($verbose);
2133: next line if (/^branches:\s/);
1.45.2.55 knu 2134: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
1.1 jfieber 2135: $log{$rev} .= $_;
2136: }
2137: print "E:", $_ if ($verbose);
2138: }
1.45.2.46 knu 2139: close($fh);
1.1 jfieber 2140: print "Done reading RCS file\n" if ($verbose);
1.45.2.46 knu 2141:
2142: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
2143: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
2144:
1.1 jfieber 2145: #
2146: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 2147: # branch, unless there is a branch tag in the RCS file in which case it's the
2148: # highest revision on that branch. Find it by looking through @revorder; it
2149: # is the first commit listed on the appropriate branch.
1.45.2.46 knu 2150: # This is not neccesary the same revision as marked as head in the RCS file.
2151: my $headrev = $curbranch || "1";
1.45.2.59 knu 2152: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
1.45.2.46 knu 2153: foreach $rev (@revorder) {
2154: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2155: $symrev{"HEAD"} = $rev;
1.45.2.58 knu 2156: last;
1.1 jfieber 2157: }
2158: }
1.45.2.46 knu 2159: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2160: if (!defined($symrev{"HEAD"}));
1.1 jfieber 2161: print "Done finding HEAD\n" if ($verbose);
2162: #
2163: # Now that we know all of the revision numbers, we can associate
2164: # absolute revision numbers with all of the symbolic names, and
2165: # pass them to the form so that the same association doesn't have
2166: # to be built then.
2167: #
1.45.2.46 knu 2168: undef @branchnames;
2169: undef %branchpoint;
2170: undef $sel;
2171:
2172: foreach (reverse sort keys %symrev) {
1.1 jfieber 2173: $rev = $symrev{$_};
1.45.2.59 knu 2174: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
1.7 fenner 2175: push(@branchnames, $_);
1.1 jfieber 2176: #
2177: # A revision number of A.B.0.D really translates into
2178: # "the highest current revision on branch A.B.D".
2179: #
2180: # If there is no branch A.B.D, then it translates into
2181: # the head A.B .
2182: #
1.45.2.46 knu 2183: # This reasoning also applies to the main branch A.B,
2184: # with the branch number 0.A, with the exception that
2185: # it has no head to translate to if there is nothing on
2186: # the branch, but I guess this can never happen?
1.45.2.57 knu 2187: #
1.45.2.59 knu 2188: # (the code below gracefully forgets about the branch
2189: # if it should happen)
1.45.2.46 knu 2190: #
2191: $head = defined($2) ? $2 : "";
1.1 jfieber 2192: $branch = $3;
1.45.2.46 knu 2193: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2194: my $regex;
1.45.2.58 knu 2195: $regex = quotemeta $branchrev;
1.1 jfieber 2196: $rev = $head;
2197:
1.45.2.46 knu 2198: foreach my $r (@revorder) {
2199: if ($r =~ /^${regex}\b/) {
2200: $rev = $branchrev;
1.45.2.58 knu 2201: last;
1.1 jfieber 2202: }
2203: }
1.45.2.46 knu 2204: next if ($rev eq "");
2205: if ($rev ne $head && $head ne "") {
1.8 fenner 2206: $branchpoint{$head} .= ", " if ($branchpoint{$head});
2207: $branchpoint{$head} .= $_;
2208: }
1.1 jfieber 2209: }
1.45.2.46 knu 2210: $revsym{$rev} .= ", " if ($revsym{$rev});
2211: $revsym{$rev} .= $_;
1.1 jfieber 2212: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
2213: }
2214: print "Done associating revisions with branches\n" if ($verbose);
1.45.2.46 knu 2215:
2216: my ($onlyonbranch, $onlybranchpoint);
2217: if ($onlyonbranch = $input{'only_with_tag'}) {
2218: $onlyonbranch = $symrev{$onlyonbranch};
1.45.2.59 knu 2219: if ($onlyonbranch =~ s/\b0\.//) {
1.45.2.46 knu 2220: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2221: }
2222: else {
2223: $onlybranchpoint = $onlyonbranch;
2224: }
2225: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2226: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
2227: }
1.8 fenner 2228: }
1.1 jfieber 2229:
1.45.2.46 knu 2230: undef @revisions;
2231:
2232: foreach (@allrevisions) {
1.7 fenner 2233: ($br = $_) =~ s/\.\d+$//;
1.45.2.46 knu 2234: ($brp = $br) =~ s/\.\d+$//;
1.7 fenner 2235: next if ($onlyonbranch && $br ne $onlyonbranch &&
1.45.2.46 knu 2236: $_ ne $onlybranchpoint);
2237: unshift(@revisions,$_);
2238: }
2239:
2240: if ($logsort eq "date") {
2241: # Sort the revisions in commit order an secondary sort on revision
2242: # (secondary sort needed for imported sources, or the first main
2243: # revision gets before the same revision on the 1.1.1 branch)
2244: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
2245: }
2246: elsif ($logsort eq "rev") {
2247: # Sort the revisions in revision order, highest first
2248: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
2249: }
2250: else {
2251: # No sorting. Present in the same order as rlog / cvs log
2252: @revdisplayorder = @revisions;
2253: }
2254:
2255: }
2256:
1.45.2.56 knu 2257: sub printDiffLinks($$) {
2258: my($text, $url) = @_;
2259: my @extra;
2260:
2261: local $_;
2262: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2263: my $f = $_ eq $defaultDiffType ? '' : $_;
2264:
2265: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2266: }
2267:
2268: print &link($text, $url), ' (', join(', ', @extra), ')';
2269: }
2270:
1.45.2.46 knu 2271: sub printLog($;$) {
2272: my ($link, $br, $brp);
2273: ($_,$link) = @_;
2274: ($br = $_) =~ s/\.\d+$//;
2275: ($brp = $br) =~ s/\.?\d+$//;
2276: my ($isDead, $prev);
2277:
2278: $link = 1 if (!defined($link));
2279: $isDead = ($state{$_} eq "dead");
2280:
2281: if ($link && !$isDead) {
2282: my ($filename);
2283: ($filename = $where) =~ s/^.*\///;
2284: my ($fileurl) = urlencode($filename);
1.4 fenner 2285: print "<a NAME=\"rev$_\"></a>";
1.45.2.46 knu 2286: if (defined($revsym{$_})) {
2287: foreach my $sym (split(", ", $revsym{$_})) {
2288: print "<a NAME=\"$sym\"></a>";
2289: }
1.4 fenner 2290: }
1.45.2.46 knu 2291: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
2292: foreach my $sym (split(", ", $revsym{$br})) {
1.4 fenner 2293: print "<a NAME=\"$sym\"></a>";
2294: }
1.45.2.46 knu 2295: $nameprinted{$br} = 1;
1.4 fenner 2296: }
1.45.2.46 knu 2297: print "\n Revision ";
2298: &download_link($fileurl, $_, $_,
1.45.2.56 knu 2299: $defaultViewable ? "text/x-cvsweb-markup" : undef);
1.45.2.46 knu 2300: if ($defaultViewable) {
1.45.2.56 knu 2301: print " / (";
2302: &download_link($fileurl, $_, "download", $mimetype);
2303: print ")";
1.45.2.46 knu 2304: }
2305: if (not $defaultTextPlain) {
1.45.2.56 knu 2306: print " / (";
2307: &download_link($fileurl, $_, "as text", "text/plain");
2308: print ")";
1.45.2.46 knu 2309: }
2310: if (!$defaultViewable) {
1.45.2.56 knu 2311: print " / (";
2312: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2313: print ")";
1.45.2.46 knu 2314: }
2315: if ($allow_annotate) {
1.45.2.56 knu 2316: print " - ";
2317: print &link('annotate',
2318: sprintf('%s/%s?annotate=%s%s',
2319: $scriptname,
2320: urlencode($where),
2321: $_,
2322: $barequery));
1.45.2.46 knu 2323: }
2324: # Plus a select link if enabled, and this version isn't selected
2325: if ($allow_version_select) {
2326: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
1.45.2.56 knu 2327: print " - ";
2328: print &link('[select for diffs]',
2329: sprintf('%s?r1=%s%s',
2330: $scriptwhere,
2331: $_,
2332: $barequery));
1.45.2.46 knu 2333: }
2334: else {
2335: print " - <b>[selected]</b>";
2336: }
2337: }
2338: }
2339: else {
2340: print "Revision <B>$_</B>";
2341: }
2342: if (/^1\.1\.1\.\d+$/) {
2343: print " <i>(vendor branch)</i>";
2344: }
2345: if (defined @mytz) {
2346: my ($est) = $mytz[(localtime($date{$_}))[8]];
1.45.2.56 knu 2347: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
1.45.2.46 knu 2348: } else {
1.45.2.56 knu 2349: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
1.45.2.46 knu 2350: }
1.45.2.56 knu 2351: print readableTime(time() - $date{$_},1), " ago)";
1.45.2.46 knu 2352: print " by ";
1.45.2.56 knu 2353: print "<i>", $author{$_}, "</i>\n";
1.45.2.46 knu 2354: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
2355: if ($revsym{$br});
2356: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
2357: if ($revsym{$_});
2358: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
2359: if ($branchpoint{$_});
2360: # Find the previous revision
2361: my @prevrev = split(/\./, $_);
2362: do {
2363: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 2364: # If it was X.Y.Z.1, just make it X.Y
1.45.2.46 knu 2365: pop(@prevrev);
2366: pop(@prevrev);
2367: }
2368: $prev = join(".", @prevrev);
2369: } until (defined($date{$prev}) || $prev eq "");
2370: if ($prev ne "") {
2371: if ($difflines{$_}) {
2372: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
2373: }
2374: }
2375: if ($isDead) {
2376: print "<BR><B><I>FILE REMOVED</I></B>\n";
2377: }
2378: elsif ($link) {
2379: my %diffrev = ();
2380: $diffrev{$_} = 1;
2381: $diffrev{""} = 1;
2382: print "<BR>Diff";
2383: #
2384: # Offer diff to previous revision
2385: if ($prev) {
2386: $diffrev{$prev} = 1;
1.45.2.56 knu 2387:
2388: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2389: $scriptwhere,
2390: $prev,
2391: $_,
2392: $barequery);
2393:
2394: print " to previous ";
2395: printDiffLinks($prev, $url);
1.1 jfieber 2396: }
1.45.2.46 knu 2397: #
2398: # Plus, if it's on a branch, and it's not a vendor branch,
2399: # offer a diff with the branch point.
2400: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
1.45.2.56 knu 2401: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2402: $scriptwhere,
2403: $brp,
2404: $_,
2405: $barequery);
2406:
2407: print " to branchpoint ";
2408: printDiffLinks($brp, $url);
1.45.2.46 knu 2409: }
2410: #
2411: # Plus, if it's on a branch, and it's not a vendor branch,
2412: # offer to diff with the next revision of the higher branch.
2413: # (e.g. change gets committed and then brought
2414: # over to -stable)
2415: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2416: my ($i,$nextmain);
2417: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
1.45.2.63 knu 2418: my @tmp2 = split(/\./, $_);
1.45.2.46 knu 2419: for ($nextmain = ""; $i > 0; $i--) {
1.45.2.63 knu 2420: my $next = $revorder[$i-1];
2421: my @tmp1 = split(/\./, $next);
2422: if (@tmp1 < @tmp2) {
1.45.2.46 knu 2423: $nextmain = $next;
2424: last;
2425: }
2426: # Only the highest version on a branch should have
2427: # a diff for the "next main".
1.45.2.63 knu 2428: last if (@tmp1 - 1 <= @tmp2 &&
2429: join(".",@tmp1[0..$#tmp1-1]) eq join(".",@tmp2[0..$#tmp1-1]));
1.45.2.46 knu 2430: }
2431: if (!defined($diffrev{$nextmain})) {
2432: $diffrev{$nextmain} = 1;
1.45.2.56 knu 2433:
2434: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2435: $scriptwhere,
2436: $nextmain,
2437: $_,
2438: $barequery);
2439:
2440: print " next main ";
2441: printDiffLinks($nextmain, $url);
1.1 jfieber 2442: }
2443: }
1.45.2.46 knu 2444: # Plus if user has selected only r1, then present a link
2445: # to make a diff to that revision
2446: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2447: $diffrev{$input{"r1"}} = 1;
2448:
1.45.2.56 knu 2449: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2450: $scriptwhere,
2451: $input{'r1'},
2452: $_,
2453: $barequery);
2454:
2455: print " to selected ";
2456: printDiffLinks($input{'r1'}, $url);
1.9 fenner 2457: }
1.1 jfieber 2458: }
1.45.2.46 knu 2459: print "<PRE>\n";
2460: print &htmlify($log{$_}, 1);
2461: print "</PRE>\n";
2462: }
2463:
1.45.2.47 knu 2464: sub doLog($) {
1.45.2.46 knu 2465: my($fullname) = @_;
2466: my ($diffrev, $upwhere, $filename, $backurl);
1.45.2.47 knu 2467:
1.45.2.46 knu 2468: readLog($fullname);
2469:
2470: html_header("CVS log for $where");
2471: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2472: ($filename = $where) =~ s|^.*/||;
2473: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2474: print &link($backicon, "$backurl#$filename"),
1.45.2.56 knu 2475: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
2476: print &link('Request diff between arbitrary revisions', '#diff');
2477: print '<HR NOSHADE>';
2478:
1.45.2.46 knu 2479: if ($curbranch) {
2480: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
2481: }
2482: else {
2483: print "No default branch";
2484: }
2485: print "<BR>\n";
2486: if ($input{only_with_tag}) {
2487: print "Current tag: $input{only_with_tag}<BR>\n";
2488: }
2489:
2490: undef %nameprinted;
2491:
2492: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2493: print "<HR size=1 NOSHADE>";
2494: printLog($revdisplayorder[$i]);
2495: }
2496:
2497: print "<HR NOSHADE>";
1.1 jfieber 2498: print "<A NAME=diff>\n";
2499: print "This form allows you to request diff's between any two\n";
2500: print "revisions of a file. You may select a symbolic revision\n";
2501: print "name using the selection box or you may type in a numeric\n";
2502: print "name using the type-in text box.\n";
2503: print "</A><P>\n";
1.45.2.46 knu 2504: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2505: foreach (@stickyvars) {
1.45.2.56 knu 2506: printf('<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">', $_, $input{$_})
1.45.2.46 knu 2507: if (defined($input{$_})
1.45.2.51 knu 2508: && ((!defined($DEFAULTVALUE{$_})
2509: || $input{$_} ne $DEFAULTVALUE{$_})
2510: && $input{$_} ne ""));
1.45.2.46 knu 2511: }
1.45.2.51 knu 2512: print "<TABLE><TR>\n";
2513: print "<TD align=right>Diffs between \n";
1.1 jfieber 2514: print "<SELECT NAME=\"r1\">\n";
2515: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2516: print $sel;
2517: print "</SELECT>\n";
1.45.2.46 knu 2518: $diffrev = $revdisplayorder[$#revdisplayorder];
2519: $diffrev = $input{"r1"} if (defined($input{"r1"}));
1.45.2.51 knu 2520: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
2521: print "<TD><BR></TD></TR>\n";
2522: print "<TR><TD align=right>and \n";
1.1 jfieber 2523: print "<SELECT NAME=\"r2\">\n";
2524: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2525: print $sel;
2526: print "</SELECT>\n";
1.45.2.46 knu 2527: $diffrev = $revdisplayorder[0];
2528: $diffrev = $input{"r2"} if (defined($input{"r2"}));
1.45.2.51 knu 2529: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
2530: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Get Diffs \"></TD>\n";
1.1 jfieber 2531: print "</FORM>\n";
1.45.2.51 knu 2532: print "</TR></TABLE>\n";
1.7 fenner 2533: print "<HR noshade>\n";
1.45.2.51 knu 2534: print "<TABLE>";
2535: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
1.45.2.56 knu 2536: print "<TR><TD align=right>Preferred Diff type:</TD>";
2537: print "<TD>";
1.45.2.51 knu 2538: printDiffSelect($use_java_script);
2539: print "</TD><TD></TD></TR>\n";
1.45.2.46 knu 2540: if (@branchnames) {
1.45.2.51 knu 2541: print "<TR><TD align=right>View only Branch:</TD>";
2542: print "<TD>";
1.45.2.46 knu 2543: print "<A name=branch></A>\n";
2544: print "<SELECT NAME=\"only_with_tag\"";
2545: print " onchange=\"submit()\"" if ($use_java_script);
2546: print ">\n";
2547: print "<OPTION VALUE=\"\"";
2548: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2549: $input{"only_with_tag"} eq "");
2550: print ">Show all branches\n";
2551: foreach (reverse sort @branchnames) {
1.9 fenner 2552: print "<OPTION";
1.45.2.46 knu 2553: print " SELECTED" if (defined($input{"only_with_tag"})
2554: && $input{"only_with_tag"} eq $_);
1.9 fenner 2555: print ">${_}\n";
1.45.2.46 knu 2556: }
1.45.2.51 knu 2557: print "</SELECT></TD><TD></TD></TR>\n";
1.7 fenner 2558: }
1.45.2.46 knu 2559: foreach (@stickyvars) {
1.45.2.51 knu 2560: next if ($_ eq "f");
1.45.2.46 knu 2561: next if ($_ eq "only_with_tag");
2562: next if ($_ eq "logsort");
2563: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
1.45.2.51 knu 2564: if (defined($input{$_})
2565: && (!defined($DEFAULTVALUE{$_})
2566: || $input{$_} ne $DEFAULTVALUE{$_})
1.45.2.46 knu 2567: && $input{$_} ne "");
2568: }
1.45.2.51 knu 2569: print "<TR><TD align=right>";
2570: print "<A name=logsort></A>\n";
2571: print "Sort log by:</TD>";
1.45.2.56 knu 2572: print "<TD>";
2573: printLogSortSelect($use_java_script);
2574: print "</TD>";
1.45.2.51 knu 2575: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Set \"></TD>";
1.7 fenner 2576: print "</FORM>\n";
1.45.2.51 knu 2577: print "</TR></TABLE>";
1.2 jfieber 2578: print &html_footer;
1.1 jfieber 2579: print "</BODY></HTML>\n";
1.10 wosch 2580: }
2581:
1.45.2.47 knu 2582: sub flush_diff_rows($$$$) {
1.45.2.46 knu 2583: my $j;
2584: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2585: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2586: for ($j = 0 ; $j < $leftRow; $j++) {
2587: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2588: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2589: }
2590: }
2591: elsif ($state eq "PreChange") { # state eq "PreChange"
2592: # we got removes with subsequent adds
2593: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2594: print "<tr>";
2595: if ($j < $leftRow) {
2596: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2597: }
2598: else {
2599: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2600: }
2601: if ($j < $rightRow) {
2602: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2603: }
2604: else {
2605: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2606: }
2607: print "</tr>\n";
2608: }
2609: }
2610: }
2611:
2612: ##
2613: # Function to generate Human readable diff-files
2614: # human_readable_diff(String revision_to_return_to);
2615: ##
2616: sub human_readable_diff($){
1.45.2.51 knu 2617: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
1.45.2.46 knu 2618: my ($fh, $rev) = @_;
2619: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2620: my (@rightCol, @leftCol);
2621:
2622: ($where_nd = $where) =~ s/.diff$//;
2623: ($filename = $where_nd) =~ s/^.*\///;
2624: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2625: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2626:
1.45.2.47 knu 2627: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
1.45.2.46 knu 2628:
2629: # Read header to pick up read revision and date, if possible
2630: while (<$fh>) {
2631: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2632: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2633: last if (/^\+\+\+ /);
2634: }
2635: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2636: $rev1 = $r1r;
2637: $date1 = $r1d;
2638: }
2639: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2640: $rev2 = $r2r;
2641: $date2 = $r2d;
2642: }
1.45.2.47 knu 2643:
1.45.2.56 knu 2644: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
2645: "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n",
2646: "<tr bgcolor=\"#ffffff\">\n",
2647: "<th width=\"50%\" valign=TOP>",
2648: "version $rev1";
1.45.2.46 knu 2649: print ", $date1" if (defined($date1));
2650: print "<br>Tag: $sym1\n" if ($sym1);
1.45.2.56 knu 2651: print "</th>\n",
2652: "<th width=\"50%\" valign=TOP>",
2653: "version $rev2";
1.45.2.46 knu 2654: print ", $date2" if (defined($date2));
2655: print "<br>Tag: $sym2\n" if ($sym1);
2656: print "</th>\n";
2657:
1.45.2.69! knu 2658: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\"><tt>";
! 2659: my $fe = "</tt></font>";
1.45.2.46 knu 2660:
2661: my $leftRow = 0;
2662: my $rightRow = 0;
2663: my ($oldline, $newline, $funname, $diffcode, $rest);
2664:
2665: # Process diff text
2666: # The diffrows are could make excellent use of
2667: # cascading style sheets because we've to set the
2668: # font and color for each row. anyone ...?
2669: ####
1.45.2.51 knu 2670:
2671: # prefetch several lines
2672: my @buf = head($fh);
2673:
2674: my %d = scan_directives(@buf);
2675:
2676: while (@buf || !eof($fh)) {
2677: $difftxt = @buf ? shift @buf : <$fh>;
1.45.2.47 knu 2678:
1.45.2.46 knu 2679: if ($difftxt =~ /^@@/) {
2680: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2681: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2682: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2683: print " <font size=-1>$funname</font></td></tr></table>";
2684: print "</td><td width=\"50%\">";
2685: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2686: print " <font size=-1>$funname</font></td></tr></table>";
2687: print "</td>\n";
2688: $state = "dump";
2689: $leftRow = 0;
2690: $rightRow = 0;
2691: }
2692: else {
2693: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
1.45.2.51 knu 2694: $_ = spacedHtmlText($rest, $d{'tabstop'});
1.45.2.46 knu 2695:
2696: # Add fontface, size
2697: $_ = "$fs $_$fe";
1.45.2.47 knu 2698:
1.45.2.46 knu 2699: #########
2700: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2701: # in order to get some nice 'ediff'-mode output
2702: # states:
2703: # "dump" - just dump the value
2704: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2705: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2706: ##########
2707:
2708: if ($diffcode eq '+') {
2709: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2710: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2711: }
2712: else { # we got minus before
2713: $state = "PreChange";
2714: $rightCol[$rightRow++] = $_;
2715: }
1.45.2.47 knu 2716: }
1.45.2.46 knu 2717: elsif ($diffcode eq '-') {
2718: $state = "PreChangeRemove";
2719: $leftCol[$leftRow++] = $_;
2720: }
2721: else { # empty diffcode
2722: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2723: print "<tr><td>$_</td><td>$_</td></tr>\n";
2724: $state = "dump";
2725: $leftRow = 0;
2726: $rightRow = 0;
2727: }
2728: }
2729: }
2730: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2731:
2732: # state is empty if we didn't have any change
2733: if (!$state) {
2734: print "<tr><td colspan=2> </td></tr>";
2735: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2736: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2737: }
2738: print "</table>";
2739: close($fh);
2740:
2741: print "<br><hr noshade width=\"100%\">\n";
2742:
2743: print "<table border=0>";
2744:
2745: print "<tr><td>";
2746: # print legend
2747: print "<table border=1><tr><td>";
2748: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2749: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2750: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2751: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2752: print "</table></td></tr></table>\n";
2753:
2754: print "<td>";
2755: # Print format selector
2756: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2757: foreach my $var (keys %input) {
2758: next if ($var eq "f");
2759: next if (defined($DEFAULTVALUE{$var})
2760: && $DEFAULTVALUE{$var} eq $input{$var});
2761: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2762: urlencode($input{$var}),"\">\n";
2763: }
2764: printDiffSelect($use_java_script);
2765: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2766: print "</FORM>\n";
2767: print "</td>";
2768:
2769: print "</tr></table>";
2770: }
2771:
1.45.2.47 knu 2772: sub navigateHeader($$$$$) {
1.45.2.46 knu 2773: my ($swhere,$path,$filename,$rev,$title) = @_;
2774: $swhere = "" if ($swhere eq $scriptwhere);
2775: $swhere = urlencode($filename) if ($swhere eq "");
1.45.2.68 knu 2776:
2777: print <<EOF;
2778: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2779: <HTML>
2780: <HEAD>
2781: <META name="robots" content="nofollow">
2782: <!-- knu-cvsweb $cvsweb_revision -->
2783: <TITLE>$path$filename - $title - $rev</TITLE></HEAD>
2784: $body_tag_for_src
2785: <table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="$navigationHeaderColor">
2786: <tr valign=bottom><td>
2787: EOF
2788:
1.45.2.56 knu 2789: print &link($backicon, "$swhere$query#rev$rev");
1.45.2.46 knu 2790: print "</a> <b>Return to ", &link("$filename","$swhere$query#rev$rev")," CVS log";
2791: print "</b> $fileicon</td>";
1.45.2.47 knu 2792:
1.45.2.46 knu 2793: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2794: print "</tr></table>";
2795: }
2796:
1.45.2.47 knu 2797: sub plural_write($$) {
1.45.2.46 knu 2798: my ($num,$text) = @_;
2799: if ($num != 1) {
1.45.2.56 knu 2800: $text .= "s";
1.45.2.46 knu 2801: }
2802: if ($num > 0) {
1.45.2.56 knu 2803: return join(' ', $num, $text);
1.45.2.46 knu 2804: }
2805: else {
2806: return "";
2807: }
2808: }
2809:
2810: ##
2811: # print readable timestamp in terms of
2812: # '..time ago'
2813: # H. Zeller <zeller@think.de>
2814: ##
1.45.2.47 knu 2815: sub readableTime($$) {
1.45.2.46 knu 2816: my ($i, $break, $retval);
2817: my ($secs,$long) = @_;
2818:
2819: # this function works correct for time >= 2 seconds
2820: if ($secs < 2) {
2821: return "very little time";
2822: }
2823:
2824: my %desc = (1 , 'second',
2825: 60, 'minute',
2826: 3600, 'hour',
2827: 86400, 'day',
2828: 604800, 'week',
2829: 2628000, 'month',
2830: 31536000, 'year');
2831: my @breaks = sort {$a <=> $b} keys %desc;
2832: $i = 0;
1.45.2.47 knu 2833: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
1.45.2.46 knu 2834: $i++;
2835: }
2836: $i--;
2837: $break = $breaks[$i];
2838: $retval = plural_write(int ($secs / $break), $desc{$break});
2839:
2840: if ($long == 1 && $i > 0) {
2841: my $rest = $secs % $break;
2842: $i--;
2843: $break = $breaks[$i];
1.45.2.47 knu 2844: my $resttime = plural_write(int ($rest / $break),
1.45.2.46 knu 2845: $desc{$break});
2846: if ($resttime) {
1.45.2.56 knu 2847: $retval .= ", $resttime";
1.45.2.46 knu 2848: }
2849: }
2850:
2851: return $retval;
2852: }
2853:
2854: ##
2855: # clickablePath(String pathname, boolean last_item_clickable)
2856: #
2857: # returns a html-ified path whereas each directory is a link for
2858: # faster navigation. last_item_clickable controls whether the
2859: # basename (last directory/file) is a link as well
2860: ##
2861: sub clickablePath($$) {
1.45.2.47 knu 2862: my ($pathname,$clickLast) = @_;
1.45.2.46 knu 2863: my $retval = '';
1.45.2.47 knu 2864:
1.45.2.46 knu 2865: if ($pathname eq '/') {
2866: # this should never happen - chooseCVSRoot() is
2867: # intended to do this
2868: $retval = "[$cvstree]";
2869: }
2870: else {
1.45.2.56 knu 2871: $retval .= ' ' . &link("[$cvstree]", sprintf('%s/%s#dirlist',
2872: $scriptname,
2873: $query));
1.45.2.46 knu 2874: my $wherepath = '';
2875: my ($lastslash) = $pathname =~ m|/$|;
2876: foreach (split(/\//, $pathname)) {
1.45.2.56 knu 2877: $retval .= " / ";
2878: $wherepath .= "/$_";
1.45.2.46 knu 2879: my ($last) = "$wherepath/" eq "/$pathname"
2880: || $wherepath eq "/$pathname";
2881: if ($clickLast || !$last) {
1.45.2.56 knu 2882: $retval .= &link($_, join('',
2883: $scriptname,
2884: urlencode($wherepath),
2885: (!$last || $lastslash ? '/' : ''),
2886: $query,
2887: (!$last || $lastslash ? "#dirlist" : "")));
1.45.2.46 knu 2888: }
2889: else { # do not make a link to the current dir
1.45.2.56 knu 2890: $retval .= $_;
1.45.2.46 knu 2891: }
2892: }
2893: }
2894: return $retval;
2895: }
2896:
2897: sub chooseCVSRoot() {
1.45.2.65 knu 2898: if (2 <= @CVSROOT) {
1.45.2.46 knu 2899: my ($k);
2900: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2901: foreach $k (keys %input) {
1.45.2.47 knu 2902: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
1.45.2.46 knu 2903: if ($input{$k}) && ($k ne "cvsroot");
2904: }
2905: # Form-Elements look wierd in Netscape if the background
2906: # isn't gray and the form elements are not placed
2907: # within a table ...
2908: print "<table><tr>";
2909: print "<td>CVS Root:</td>";
2910: print "<td>\n<select name=\"cvsroot\"";
2911: print " onchange=\"submit()\"" if ($use_java_script);
2912: print ">\n";
1.45.2.65 knu 2913: foreach $k (@CVSROOT) {
1.45.2.46 knu 2914: print "<option value=\"$k\"";
2915: print " selected" if ($k eq $cvstree);
1.45.2.56 knu 2916: print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k), "</option>\n";
1.45.2.46 knu 2917: }
2918: print "</select>\n</td>";
1.45.2.65 knu 2919: print "<td>";
1.45.2.46 knu 2920: }
2921: else {
2922: # no choice ..
2923: print "CVS Root: <b>[$cvstree]</b>";
2924: }
1.45.2.65 knu 2925:
2926: print " Module path or alias:\n";
2927: print "<INPUT TYPE=TEXT NAME=\"path\" VALUE=\"\" SIZE=15>\n";
2928: print "<input type=submit value=\"Go\">";
2929:
2930: if (2 <= @CVSROOT) {
2931: print "</td></tr></table></form>";
2932: }
1.45.2.46 knu 2933: }
2934:
2935: sub chooseMirror() {
2936: my ($mirror,$moremirrors);
2937: $moremirrors = 0;
2938: # This code comes from the original BSD-cvsweb
2939: # and may not be useful for your site; If you don't
2940: # set %MIRRORS this won't show up, anyway
2941: #
1.45.2.47 knu 2942: # Should perhaps exlude the current site somehow..
1.45.2.46 knu 2943: if (keys %MIRRORS) {
2944: print "\nThis cvsweb is mirrored in:\n";
2945: foreach $mirror (keys %MIRRORS) {
2946: print ", " if ($moremirrors);
1.45.2.56 knu 2947: print &link(htmlquote($mirror),$MIRRORS{$mirror});
1.45.2.46 knu 2948: $moremirrors = 1;
2949: }
2950: print "<p>\n";
2951: }
2952: }
2953:
1.45.2.47 knu 2954: sub fileSortCmp() {
1.45.2.46 knu 2955: my ($comp) = 0;
2956: my ($c,$d,$af,$bf);
2957:
2958: ($af = $a) =~ s/,v$//;
2959: ($bf = $b) =~ s/,v$//;
2960: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2961: if (defined($fileinfo{$af}));
2962: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2963: if (defined($fileinfo{$bf}));
2964:
2965: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2966: # Two files
2967: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2968: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2969: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2970: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2971: }
2972: if ($comp == 0) {
2973: # Directories first, then sorted on name if no other sort critera
2974: # available.
2975: my $ad = ((-d "$fullname/$a")?"D":"F");
2976: my $bd = ((-d "$fullname/$b")?"D":"F");
2977: ($c=$a) =~ s|.*/||;
2978: ($d=$b) =~ s|.*/||;
2979: $comp = ("$ad$c" cmp "$bd$d");
2980: }
2981: return $comp;
2982: }
2983:
2984: # make A url for downloading
1.45.2.47 knu 2985: sub download_url($$;$) {
1.45.2.46 knu 2986: my ($url,$revision,$mimetype) = @_;
2987:
1.45.2.59 knu 2988: $revision =~ s/\b0\.//;
1.45.2.46 knu 2989:
1.45.2.56 knu 2990: if (defined($checkoutMagic)
1.45.2.46 knu 2991: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
1.45.2.56 knu 2992: my $path = $where;
2993: $path =~ s|/[^/]*$|/|;
1.45.2.46 knu 2994: $url = "$scriptname/$checkoutMagic/${path}$url";
2995: }
2996: $url .= "?rev=$revision";
1.45.2.56 knu 2997: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
1.45.2.69! knu 2998:
! 2999: $url =~ s/:/sprintf("%%%02x", ord($&))/eg;
1.45.2.46 knu 3000:
1.45.2.56 knu 3001: $url;
1.45.2.46 knu 3002: }
3003:
1.45.2.47 knu 3004: # Presents a link to download the
1.45.2.46 knu 3005: # selected revision
1.45.2.47 knu 3006: sub download_link($$$;$) {
1.45.2.56 knu 3007: my ($url, $revision, $textlink, $mimetype) = @_;
3008: my ($fullurl) = download_url($url, $revision, $mimetype);
3009:
1.45.2.61 knu 3010: printf '<A HREF="%s"', hrefquote("$fullurl$barequery");
1.45.2.56 knu 3011:
1.45.2.46 knu 3012: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
1.45.2.56 knu 3013: print ' target="cvs_checkout"';
1.45.2.46 knu 3014: # we should have
3015: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3016: # in order to allow the user to resize the window; otherwise
3017: # the user may resize the window, but on next checkout - zap -
3018: # its original (configured s. cvsweb.conf) size is back again
3019: # .. annoying (if $extern_window_(width|height) is defined)
3020: # but this if (..) solution is far from perfect
3021: # what we need to do as well is
3022: # 1) save cvswin in an invisible frame that always exists
3023: # (document.cvswin will be void on next load)
3024: # 2) on close of the cvs_checkout - window set the cvswin
3025: # variable to 'null' again - so that it will be
3026: # reopenend with the configured size
3027: # anyone a JavaScript programmer ?
3028: # .. so here without if (..):
3029: # currently, the best way is to comment out the size parameters
3030: # ($extern_window...) in cvsweb.conf.
3031: if ($use_java_script) {
1.45.2.56 knu 3032: my @attr = qw(resizeable scrollbars);
3033:
3034: push @attr, qw(status toolbar)
3035: if (defined($mimetype) && $mimetype eq "text/html");
3036:
3037: push @attr, "width=$extern_window_width"
3038: if (defined($extern_window_width));
3039:
3040: push @attr, "height=$extern_window_height"
3041: if (defined($extern_window_height));
3042:
3043: printf q` onClick="window.open('%s','cvs_checkout','%s');"`,
1.45.2.61 knu 3044: hrefquote($fullurl), join(',', @attr);
1.45.2.46 knu 3045: }
3046: }
3047: print "><b>$textlink</b></A>";
3048: }
3049:
3050: # Returns a Query string with the
3051: # specified parameter toggled
3052: sub toggleQuery($$) {
3053: my ($toggle,$value) = @_;
3054: my ($newquery,$var);
3055: my (%vars);
3056: %vars = %input;
3057: if (defined($value)) {
3058: $vars{$toggle} = $value;
3059: }
3060: else {
3061: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3062: }
3063: # Build a new query of non-default paramenters
3064: $newquery = "";
3065: foreach $var (@stickyvars) {
3066: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3067: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3068: if ($value ne $default) {
1.45.2.56 knu 3069: $newquery .= "&" if ($newquery ne "");
1.45.2.46 knu 3070: $newquery .= urlencode($var) . "=" . urlencode($value);
3071: }
3072: }
3073: if ($newquery) {
3074: return '?' . $newquery;
3075: }
3076: return "";
3077: }
3078:
1.45.2.47 knu 3079: sub urlencode($) {
1.45.2.56 knu 3080: local($_) = @_;
3081:
3082: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3083:
1.45.2.61 knu 3084: $_;
1.45.2.56 knu 3085: }
3086:
3087: sub htmlquote($) {
3088: local($_) = @_;
3089:
3090: # Special Characters; RFC 1866
3091: s/&/&/g;
3092: s/\"/"/g;
3093: s/</</g;
3094: s/>/>/g;
3095:
3096: $_;
3097: }
3098:
3099: sub htmlunquote($) {
3100: local($_) = @_;
3101:
3102: # Special Characters; RFC 1866
3103: s/"/\"/g;
3104: s/</</g;
3105: s/>/>/g;
3106: s/&/&/g;
3107:
3108: $_;
1.45.2.46 knu 3109: }
3110:
1.45.2.61 knu 3111: sub hrefquote($) {
3112: local($_) = @_;
3113:
3114: y/ /+/;
3115:
3116: htmlquote($_)
3117: }
3118:
1.45.2.47 knu 3119: sub http_header(;$) {
1.45.2.46 knu 3120: my $content_type = shift || "text/html";
1.45.2.63 knu 3121:
3122: $content_type .= "; charset=$charset"
3123: if $content_type =~ m,^text/, && defined($charset) && $charset;
3124:
1.45.2.46 knu 3125: if (defined($moddate)) {
3126: if ($is_mod_perl) {
1.45.2.51 knu 3127: Apache->request->header_out("Last-Modified" => scalar gmtime($moddate) . " GMT");
1.45.2.46 knu 3128: }
3129: else {
1.45.2.56 knu 3130: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
1.45.2.46 knu 3131: }
3132: }
3133: if ($is_mod_perl) {
3134: Apache->request->content_type($content_type);
3135: }
3136: else {
3137: print "Content-type: $content_type\r\n";
3138: }
3139: if ($allow_compress && $maycompress) {
1.45.2.67 knu 3140: if ($has_zlib || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c"))) {
1.45.2.46 knu 3141: if ($is_mod_perl) {
3142: Apache->request->content_encoding("x-gzip");
3143: Apache->request->header_out(Vary => "Accept-Encoding");
3144: Apache->request->send_http_header;
3145: }
3146: else {
3147: print "Content-encoding: x-gzip\r\n";
3148: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
3149: print "\r\n"; # Close headers
3150: }
3151: $| = 1; $| = 0; # Flush header output
1.45.2.51 knu 3152: if ($has_zlib) {
3153: tie *GZIP, __PACKAGE__, \*STDOUT;
3154: }
3155: select(GZIP);
3156: $gzip_open = 1;
1.45.2.58 knu 3157: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
1.45.2.46 knu 3158: }
3159: else {
3160: if ($is_mod_perl) {
3161: Apache->request->send_http_header;
3162: }
3163: else {
3164: print "\r\n"; # Close headers
3165: }
1.45.2.67 knu 3166: print "<font size=-1>Unable to find gzip binary in the <b>\$command_path</b> ($command_path) to compress output</font><br>";
1.45.2.46 knu 3167: }
3168: }
3169: else {
3170: if ($is_mod_perl) {
3171: Apache->request->send_http_header;
3172: }
3173: else {
3174: print "\r\n"; # Close headers
3175: }
3176: }
3177: }
3178:
3179: sub html_header($) {
3180: my ($title) = @_;
1.45.2.68 knu 3181: http_header("text/html");
1.45.2.46 knu 3182:
3183: (my $header = &cgi_style::html_header) =~ s/^.*\n\n//; # remove HTTP response header
3184:
3185: print <<EOH;
3186: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
3187: "http://www.w3.org/TR/REC-html40/loose.dtd">
3188: $header
1.45.2.68 knu 3189: <!-- knu-cvsweb $cvsweb_revision -->
1.45.2.46 knu 3190: EOH
3191: }
3192:
1.45.2.47 knu 3193: sub html_footer() {
1.45.2.46 knu 3194: return &cgi_style::html_footer;
3195: }
3196:
1.45.2.47 knu 3197: sub link_tags($) {
1.45.2.46 knu 3198: my ($tags) = @_;
3199: my ($ret) = "";
3200: my ($fileurl,$filename);
3201:
3202: ($filename = $where) =~ s/^.*\///;
3203: $fileurl = urlencode($filename);
3204:
3205: foreach my $sym (split(", ", $tags)) {
3206: $ret .= ",\n" if ($ret ne "");
1.45.2.56 knu 3207: $ret .= &link($sym, $fileurl . toggleQuery('only_with_tag',$sym));
1.45.2.46 knu 3208: }
1.45.2.56 knu 3209: return "$ret\n";
1.45.2.46 knu 3210: }
3211:
3212: #
3213: # See if a module is listed in the config file's @HideModule list.
3214: #
1.45.2.47 knu 3215: sub forbidden_module($) {
1.45.2.46 knu 3216: my($module) = @_;
1.45.2.47 knu 3217:
1.45.2.46 knu 3218: for (my $i=0; $i < @HideModules; $i++) {
3219: return 1 if $module eq $HideModules[$i];
3220: }
3221:
3222: return 0;
1.45.2.52 knu 3223: }
3224:
3225: # Close the GZIP handle remove the tie.
3226:
3227: sub gzipclose {
3228: if ($gzip_open) {
3229: select(STDOUT);
3230: close(GZIP);
3231: untie *GZIP;
3232: $gzip_open = 0;
3233: }
1.45.2.51 knu 3234: }
3235:
3236: # implement a gzipped file handle via the Compress:Zlib compression
3237: # library.
3238:
3239: sub MAGIC1() { 0x1f }
3240: sub MAGIC2() { 0x8b }
3241: sub OSCODE() { 3 }
3242:
3243: sub TIEHANDLE {
3244: my ($class, $out) = @_;
3245: my ($d) = Compress::Zlib::deflateInit(-Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3246: -WindowBits => -Compress::Zlib::MAX_WBITS()) or return undef;
3247: my ($o) = {
3248: handle => $out,
3249: dh => $d,
3250: crc => 0,
3251: len => 0,
3252: };
3253: my ($header) = pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0,0,0,0,0,0, OSCODE);
3254: print {$o->{handle}} $header;
3255: return bless($o, $class);
3256: }
3257:
3258: sub PRINT {
3259: my ($o) = shift;
3260: my ($buf) = join(defined $, ? $, : "",@_);
3261: my ($len) = length($buf);
3262: my ($compressed, $status) = $o->{dh}->deflate($buf);
3263: print {$o->{handle}} $compressed if defined($compressed);
3264: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3265: $o->{len} += $len;
3266: return $len;
3267: }
3268:
3269: sub PRINTF {
3270: my ($o) = shift;
3271: my ($fmt) = shift;
3272: my ($buf) = sprintf($fmt, @_);
3273: my ($len) = length($buf);
3274: my ($compressed, $status) = $o->{dh}->deflate($buf);
3275: print {$o->{handle}} $compressed if defined($compressed);
3276: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3277: $o->{len} += $len;
3278: return $len;
3279: }
3280:
3281: sub WRITE {
3282: my ($o, $buf, $len, $off) = @_;
3283: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3284: print {$o->{handle}} $compressed if defined($compressed);
3285: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3286: $o->{len} += $len;
3287: return $len;
3288: }
3289:
3290: sub CLOSE {
3291: my ($o) = @_;
3292: return if !defined( $o->{dh});
3293: my ($buf) = $o->{dh}->flush();
3294: $buf .= pack("V V", $o->{crc}, $o->{len});
3295: print {$o->{handle}} $buf;
3296: undef $o->{dh};
3297: }
3298:
3299: sub DESTROY {
3300: my ($o) = @_;
3301: CLOSE($o);
1.1 jfieber 3302: }
CVSweb