Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.70
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 $
1.45.2.70! knu 46: # $Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 1.70 2001/03/27 17:20:46 knu Exp $
! 47: # $FreeBSD: www/en/cgi/cvsweb.cgi,v 1.69 2001/03/22 19:55:43 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(/ /,
1.45.2.70! knu 144: q$Idaemons: /home/cvs/cvsweb/cvsweb.cgi,v 1.70 2001/03/27 17:20:46 knu Exp $
1.45.2.69 knu 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.70! knu 237: $_ = q$FreeBSD: www/en/cgi/cvsweb.cgi,v 1.69 2001/03/22 19:55:43 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.70! 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($_);
1.45.2.70! knu 831: $url = './' . $fileurl . $query;
1.45.2.46 knu 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.
1.45.2.70! knu 929: "./$basefile.tar.gz$query".
1.45.2.61 knu 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.70! knu 1243: $url =~ s/:/sprintf("%%%02x", ord($&))/eg if $url =~ /^[^a-z]/; # relative
1.45.2.69 knu 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 {
1.45.2.70! knu 1722: print "<PRE>";
! 1723: while (<$filehandle>) {
! 1724: print htmlquote($_);
! 1725: }
! 1726: print "</PRE>";
1.45.2.63 knu 1727: }
1.12 fenner 1728: }
1729:
1.45.2.46 knu 1730: sub viewable($) {
1731: my ($mimetype) = @_;
1732:
1.45.2.51 knu 1733: $mimetype =~ m%^((text|image)/|application/pdf)% ;
1.45.2.46 knu 1734: }
1735:
1736: ###############################
1737: # Show Colored Diff
1738: ###############################
1.45.2.47 knu 1739: sub doDiff($$$$$$) {
1.45.2.46 knu 1740: my($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1741: my $fh = do {local(*FH);};
1.45.2.56 knu 1742: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1.12 fenner 1743:
1744: if ($r1 =~ /([^:]+)(:(.+))?/) {
1745: $rev1 = $1;
1746: $sym1 = $3;
1747: }
1.45.2.46 knu 1748: if ($r1 eq 'text') {
1.12 fenner 1749: $rev1 = $tr1;
1.45.2.46 knu 1750: $sym1 = "";
1.12 fenner 1751: }
1752: if ($r2 =~ /([^:]+)(:(.+))?/) {
1753: $rev2 = $1;
1754: $sym2 = $3;
1755: }
1.45.2.46 knu 1756: if ($r2 eq 'text') {
1.12 fenner 1757: $rev2 = $tr2;
1.45.2.46 knu 1758: $sym2 = "";
1.12 fenner 1759: }
1.45.2.48 knu 1760:
1.45.2.46 knu 1761: # make sure the revisions a wellformed, for security
1762: # reasons ..
1.45.2.48 knu 1763: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1.12 fenner 1764: &fatal("404 Not Found",
1.45.2.46 knu 1765: "Malformed query \"$ENV{QUERY_STRING}\"");
1.12 fenner 1766: }
1767: #
1768: # rev1 and rev2 are now both numeric revisions.
1769: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1770: # XXX should we warn about the fact that we do this?
1771: if (&revcmp($rev1,$rev2) > 0) {
1.45.2.46 knu 1772: my ($tmp1, $tmp2) = ($rev1, $sym1);
1.12 fenner 1773: ($rev1, $sym1) = ($rev2, $sym2);
1774: ($rev2, $sym2) = ($tmp1, $tmp2);
1775: }
1.45.2.56 knu 1776: my $difftype = $DIFFTYPES{$f};
1777:
1778: if (!$difftype) {
1.45.2.46 knu 1779: fatal ("400 Bad arguments", "Diff format $f not understood");
1780: }
1781:
1.45.2.56 knu 1782: my @difftype = @{$difftype->{'opts'}};
1783: my $human_readable = $difftype->{'colored'};
1784:
1.45.2.46 knu 1785: # apply special options
1786: if ($showfunc) {
1.45.2.56 knu 1787: push @difftype, '-p' if $f ne 's';
1.45.2.46 knu 1788:
1789: my($re1, $re2);
1790:
1791: while (($re1, $re2) = each %funcline_regexp) {
1792: if ($fullname =~ /$re1/) {
1793: push @difftype, '-F', '$re2';
1794: last;
1795: }
1796: }
1797: }
1798: if ($human_readable) {
1799: if ($hr_ignwhite) {
1800: push @difftype, '-w';
1801: }
1802: if ($hr_ignkeysubst) {
1803: push @difftype, '-kk';
1804: }
1805: }
1806: if (! open($fh, "-|")) { # child
1.44 knu 1807: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1.45.2.67 knu 1808: exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname);
1.45.2.46 knu 1809: }
1810: if ($human_readable) {
1811: http_header();
1812: &human_readable_diff($fh, $rev2);
1.45.2.52 knu 1813: gzipclose();
1.45.2.46 knu 1814: exit;
1815: }
1816: else {
1817: http_header("text/plain");
1.44 knu 1818: }
1.12 fenner 1819: #
1820: #===================================================================
1821: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
1822: #retrieving revision 1.16
1823: #retrieving revision 1.17
1824: #diff -c -r1.16 -r1.17
1825: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1826: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
1827: #
1828: # Ideas:
1829: # - nuke the stderr output if it's what we expect it to be
1830: # - Add "no differences found" if the diff command supplied no output.
1831: #
1832: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1833: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
1834: # (bogus example, but...)
1835: #
1.45.2.46 knu 1836: if (grep { $_ eq '-u'} @difftype) {
1.12 fenner 1837: $f1 = '---';
1838: $f2 = '\+\+\+';
1.45.2.46 knu 1839: }
1840: else {
1.12 fenner 1841: $f1 = '\*\*\*';
1842: $f2 = '---';
1843: }
1.45.2.46 knu 1844: while (<$fh>) {
1.12 fenner 1845: if (m|^$f1 $cvsroot|o) {
1846: s|$cvsroot/||o;
1847: if ($sym1) {
1848: chop;
1.45.2.56 knu 1849: $_ .= " $sym1\n";
1.12 fenner 1850: }
1.45.2.46 knu 1851: }
1852: elsif (m|^$f2 $cvsroot|o) {
1.12 fenner 1853: s|$cvsroot/||o;
1854: if ($sym2) {
1855: chop;
1.45.2.56 knu 1856: $_ .= " $sym2\n";
1.12 fenner 1857: }
1858: }
1859: print $_;
1860: }
1.45.2.46 knu 1861: close($fh);
1.12 fenner 1862: }
1863:
1.45.2.46 knu 1864: ###############################
1865: # Show Logs ..
1866: ###############################
1.45.2.47 knu 1867: sub getDirLogs($$@) {
1.45.2.46 knu 1868: my ($cvsroot,$dirname,@otherFiles) = @_;
1869: my ($state,$otherFiles,$tag, $file, $date, $branchpoint, $branch, $log);
1870: my ($rev, $revision, $revwanted, $filename, $head, $author);
1871:
1872: $tag = $input{only_with_tag};
1873:
1874: my ($DirName) = "$cvsroot/$where";
1875: my (@files, @filetags);
1876: my $fh = do {local(*FH);};
1877:
1878: push(@files, &safeglob("$DirName/*,v"));
1879: push(@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
1880: foreach $file (@otherFiles) {
1881: push(@files, "$DirName/$file");
1882: }
1883:
1884: # just execute rlog if there are any files
1.45.2.47 knu 1885: if ($#files < 0) {
1.45.2.46 knu 1886: return;
1887: }
1888:
1.45.2.63 knu 1889: if (defined($tag)) {
1.45.2.46 knu 1890: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
1891: if (! open($fh, "-|")) {
1.45.2.67 knu 1892: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1893: exec($CMD{rlog}, @files);
1.45.2.46 knu 1894: }
1895: }
1896: else {
1.45.2.67 knu 1897: if (! open($fh, "-|")) {
1898: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1899: exec($CMD{rlog}, '-r', @files);
1.45.2.46 knu 1900: }
1901: }
1902: $state = "start";
1903: while (<$fh>) {
1904: if ($state eq "start") {
1905: #Next file. Initialize file variables
1.45.2.63 knu 1906: $rev = '';
1907: $revwanted = '';
1908: $branch = '';
1909: $branchpoint = '';
1910: $filename = '';
1911: $log = '';
1912: $revision = '';
1.45.2.46 knu 1913: %symrev = ();
1914: @filetags = ();
1915: #jump to head state
1916: $state = "head";
1917: }
1918: print "$state:$_" if ($verbose);
1919: again:
1920: if ($state eq "head") {
1921: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
1.45.2.58 knu 1922:
1923: if (/^Working file: (.+)$/) {
1924: $filename = $1;
1925: } elsif (/^head: (.+)$/) {
1926: $head = $1;
1927: } elsif (/^branch: (.+)$/) {
1928: $branch = $1
1929: } elsif (/^symbolic names:/) {
1930: $state = "tags";
1.45.2.63 knu 1931: ($branch = $head) =~ s/\.\d+$// if $branch eq '';
1.45.2.59 knu 1932: $branch =~ s/(\d+)$/0.$1/;
1.45.2.58 knu 1933: $symrev{MAIN} = $branch;
1934: $symrev{HEAD} = $branch;
1935: $alltags{MAIN} = 1;
1936: $alltags{HEAD} = 1;
1937: push (@filetags, "MAIN", "HEAD");
1938: } elsif (/$LOG_REVSEPARATOR/o) {
1939: $state = "log";
1.45.2.63 knu 1940: $rev = '';
1941: $date = '';
1942: $log = '';
1.45.2.58 knu 1943: # Try to reconstruct the relative filename if RCS spits out a full path
1944: $filename =~ s%^\Q$DirName\E/%%;
1945: }
1.45.2.46 knu 1946: next;
1947: }
1.45.2.58 knu 1948: if ($state eq "tags") {
1949: if (/^\s+(.+):\s+([\d\.]+)\s+$/) {
1950: push (@filetags, $1);
1951: $symrev{$1} = $2;
1952: $alltags{$1} = 1;
1.45.2.46 knu 1953: next;
1.45.2.58 knu 1954: } elsif (/^\S/) {
1955: if (defined($tag)) {
1956: if(defined($symrev{$tag}) || $tag eq "HEAD") {
1957: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
1.45.2.59 knu 1958: ($branch = $revwanted) =~ s/\b0\.//;
1.45.2.58 knu 1959: ($branchpoint = $branch) =~ s/\.?\d+$//;
1.45.2.63 knu 1960: $revwanted = '' if ($revwanted ne $branch);
1.45.2.58 knu 1961: } elsif ($tag ne "HEAD") {
1962: print "Tag not found, skip this file" if ($verbose);
1963: $state = "skip";
1964: next;
1965: }
1966: }
1967: foreach my $tagfound (@filetags) {
1968: $tags{$tagfound} = 1;
1969: }
1970: $state = "head";
1971: goto again;
1.45.2.46 knu 1972: }
1973: }
1974: if ($state eq "log") {
1.45.2.55 knu 1975: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
1.45.2.46 knu 1976: # End of a log entry.
1.45.2.63 knu 1977: my $revbranch = $rev;
1978: $revbranch =~ s/\.\d+$//;
1.45.2.56 knu 1979: print "$filename $rev Wanted: $revwanted ",
1980: "Revbranch: $revbranch Branch: $branch ",
1981: "Branchpoint: $branchpoint\n" if ($verbose);
1.45.2.63 knu 1982: if ($revwanted eq '' && $branch ne ''
1.45.2.46 knu 1983: && $branch eq $revbranch || !defined($tag)) {
1984: print "File revision $rev found for branch $branch\n"
1985: if ($verbose);
1986: $revwanted = $rev;
1987: }
1.45.2.63 knu 1988: if ($revwanted ne '' ? $rev eq $revwanted :
1989: $branchpoint ne '' ? $rev eq $branchpoint :
1.45.2.46 knu 1990: 0 && ($rev eq $head)) { # Don't think head is needed here..
1991: print "File info $rev found for $filename\n" if ($verbose);
1992: my @finfo = ($rev,$date,$log,$author,$filename);
1993: my ($name);
1994: ($name = $filename) =~ s%/.*%%;
1995: $fileinfo{$name} = [ @finfo ];
1996: $state = "done" if ($rev eq $revwanted);
1997: }
1.45.2.63 knu 1998: $rev = '';
1999: $date = '';
2000: $log = '';
1.45.2.46 knu 2001: }
1.45.2.63 knu 2002: elsif ($date eq '' && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
1.45.2.46 knu 2003: my $yr = $1;
2004: # damn 2-digit year routines :-)
2005: if ($yr > 100) {
2006: $yr -= 1900;
2007: }
2008: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
2009: ($author) = /author: ([^;]+)/;
2010: $state = "log";
2011: $log = '';
2012: next;
2013: }
1.45.2.63 knu 2014: elsif ($rev eq '' && /^revision (.*)$/) {
1.45.2.46 knu 2015: $rev = $1;
2016: next;
2017: }
2018: else {
1.45.2.56 knu 2019: $log .= $_;
1.45.2.46 knu 2020: }
2021: }
1.45.2.55 knu 2022: if (/$LOG_FILESEPARATOR/o) {
1.45.2.46 knu 2023: $state = "start";
2024: next;
2025: }
2026: }
2027: if ($. == 0) {
1.45.2.47 knu 2028: fatal("500 Internal Error",
1.45.2.67 knu 2029: "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 2030: }
2031: close($fh);
2032: }
2033:
1.45.2.47 knu 2034: sub readLog($;$) {
1.45.2.46 knu 2035: my($fullname,$revision) = @_;
2036: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
2037: my $fh = do {local(*FH);};
2038:
2039: if (defined($revision)) {
2040: $revision = "-r$revision";
2041: }
2042: else {
2043: $revision = "";
2044: }
2045:
2046: undef %symrev;
2047: undef %revsym;
2048: undef @allrevisions;
2049: undef %date;
2050: undef %author;
2051: undef %state;
2052: undef %difflines;
2053: undef %log;
1.12 fenner 2054:
2055: print("Going to rlog '$fullname'\n") if ($verbose);
1.45.2.46 knu 2056: if (! open($fh, "-|")) { # child
1.45.2.67 knu 2057: if ($revision ne '') {
2058: exec($CMD{rlog}, $revision, $fullname);
2059: }
2060: else {
2061: exec($CMD{rlog}, $fullname);
2062: }
1.44 knu 2063: }
1.45.2.46 knu 2064: while (<$fh>) {
1.1 jfieber 2065: print if ($verbose);
2066: if ($symnames) {
2067: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2068: $symrev{$1} = $2;
1.45.2.46 knu 2069: }
2070: else {
1.1 jfieber 2071: $symnames = 0;
2072: }
1.45.2.46 knu 2073: }
2074: elsif (/^head:\s+([\d\.]+)/) {
2075: $head = $1;
2076: }
2077: elsif (/^branch:\s+([\d\.]+)/) {
2078: $curbranch = $1;
2079: }
2080: elsif (/^symbolic names/) {
1.1 jfieber 2081: $symnames = 1;
1.45.2.46 knu 2082: }
2083: elsif (/^-----/) {
1.1 jfieber 2084: last;
2085: }
2086: }
1.45.2.46 knu 2087: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7 fenner 2088:
1.1 jfieber 2089: # each log entry is of the form:
2090: # ----------------------------
2091: # revision 3.7.1.1
2092: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2093: # log info
2094: # ----------------------------
2095: logentry:
1.45.2.55 knu 2096: while (!/$LOG_FILESEPARATOR/o) {
1.45.2.46 knu 2097: $_ = <$fh>;
1.12 fenner 2098: last logentry if (!defined($_)); # EOF
1.1 jfieber 2099: print "R:", $_ if ($verbose);
2100: if (/^revision ([\d\.]+)/) {
2101: $rev = $1;
1.45.2.46 knu 2102: unshift(@allrevisions,$rev);
2103: }
1.45.2.55 knu 2104: elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
1.1 jfieber 2105: next logentry;
1.45.2.46 knu 2106: }
2107: else {
1.12 fenner 2108: # The rlog output is syntactically ambiguous. We must
2109: # have guessed wrong about where the end of the last log
2110: # message was.
2111: # Since this is likely to happen when people put rlog output
2112: # in their commit messages, don't even bother keeping
2113: # these lines since we don't know what revision they go with
2114: # any more.
2115: next logentry;
2116: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 2117: }
1.45.2.46 knu 2118: $_ = <$fh>;
1.1 jfieber 2119: print "D:", $_ if ($verbose);
1.45.2.46 knu 2120: 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+-]+))?|) {
2121: my $yr = $1;
2122: # damn 2-digit year routines :-)
2123: if ($yr > 100) {
2124: $yr -= 1900;
2125: }
2126: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 2127: $author{$rev} = $7;
1.9 fenner 2128: $state{$rev} = $8;
1.45.2.46 knu 2129: $difflines{$rev} = $10;
2130: }
2131: else {
1.1 jfieber 2132: &fatal("500 Internal Error", "Error parsing RCS output: $_");
2133: }
2134: line:
1.45.2.46 knu 2135: while (<$fh>) {
1.1 jfieber 2136: print "L:", $_ if ($verbose);
2137: next line if (/^branches:\s/);
1.45.2.55 knu 2138: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
1.1 jfieber 2139: $log{$rev} .= $_;
2140: }
2141: print "E:", $_ if ($verbose);
2142: }
1.45.2.46 knu 2143: close($fh);
1.1 jfieber 2144: print "Done reading RCS file\n" if ($verbose);
1.45.2.46 knu 2145:
2146: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
2147: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
2148:
1.1 jfieber 2149: #
2150: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 2151: # branch, unless there is a branch tag in the RCS file in which case it's the
2152: # highest revision on that branch. Find it by looking through @revorder; it
2153: # is the first commit listed on the appropriate branch.
1.45.2.46 knu 2154: # This is not neccesary the same revision as marked as head in the RCS file.
2155: my $headrev = $curbranch || "1";
1.45.2.59 knu 2156: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
1.45.2.46 knu 2157: foreach $rev (@revorder) {
2158: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2159: $symrev{"HEAD"} = $rev;
1.45.2.58 knu 2160: last;
1.1 jfieber 2161: }
2162: }
1.45.2.46 knu 2163: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2164: if (!defined($symrev{"HEAD"}));
1.1 jfieber 2165: print "Done finding HEAD\n" if ($verbose);
2166: #
2167: # Now that we know all of the revision numbers, we can associate
2168: # absolute revision numbers with all of the symbolic names, and
2169: # pass them to the form so that the same association doesn't have
2170: # to be built then.
2171: #
1.45.2.46 knu 2172: undef @branchnames;
2173: undef %branchpoint;
2174: undef $sel;
2175:
2176: foreach (reverse sort keys %symrev) {
1.1 jfieber 2177: $rev = $symrev{$_};
1.45.2.59 knu 2178: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
1.7 fenner 2179: push(@branchnames, $_);
1.1 jfieber 2180: #
2181: # A revision number of A.B.0.D really translates into
2182: # "the highest current revision on branch A.B.D".
2183: #
2184: # If there is no branch A.B.D, then it translates into
2185: # the head A.B .
2186: #
1.45.2.46 knu 2187: # This reasoning also applies to the main branch A.B,
2188: # with the branch number 0.A, with the exception that
2189: # it has no head to translate to if there is nothing on
2190: # the branch, but I guess this can never happen?
1.45.2.57 knu 2191: #
1.45.2.59 knu 2192: # (the code below gracefully forgets about the branch
2193: # if it should happen)
1.45.2.46 knu 2194: #
2195: $head = defined($2) ? $2 : "";
1.1 jfieber 2196: $branch = $3;
1.45.2.46 knu 2197: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2198: my $regex;
1.45.2.58 knu 2199: $regex = quotemeta $branchrev;
1.1 jfieber 2200: $rev = $head;
2201:
1.45.2.46 knu 2202: foreach my $r (@revorder) {
2203: if ($r =~ /^${regex}\b/) {
2204: $rev = $branchrev;
1.45.2.58 knu 2205: last;
1.1 jfieber 2206: }
2207: }
1.45.2.46 knu 2208: next if ($rev eq "");
2209: if ($rev ne $head && $head ne "") {
1.8 fenner 2210: $branchpoint{$head} .= ", " if ($branchpoint{$head});
2211: $branchpoint{$head} .= $_;
2212: }
1.1 jfieber 2213: }
1.45.2.46 knu 2214: $revsym{$rev} .= ", " if ($revsym{$rev});
2215: $revsym{$rev} .= $_;
1.1 jfieber 2216: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
2217: }
2218: print "Done associating revisions with branches\n" if ($verbose);
1.45.2.46 knu 2219:
2220: my ($onlyonbranch, $onlybranchpoint);
2221: if ($onlyonbranch = $input{'only_with_tag'}) {
2222: $onlyonbranch = $symrev{$onlyonbranch};
1.45.2.59 knu 2223: if ($onlyonbranch =~ s/\b0\.//) {
1.45.2.46 knu 2224: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2225: }
2226: else {
2227: $onlybranchpoint = $onlyonbranch;
2228: }
2229: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2230: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
2231: }
1.8 fenner 2232: }
1.1 jfieber 2233:
1.45.2.46 knu 2234: undef @revisions;
2235:
2236: foreach (@allrevisions) {
1.7 fenner 2237: ($br = $_) =~ s/\.\d+$//;
1.45.2.46 knu 2238: ($brp = $br) =~ s/\.\d+$//;
1.7 fenner 2239: next if ($onlyonbranch && $br ne $onlyonbranch &&
1.45.2.46 knu 2240: $_ ne $onlybranchpoint);
2241: unshift(@revisions,$_);
2242: }
2243:
2244: if ($logsort eq "date") {
2245: # Sort the revisions in commit order an secondary sort on revision
2246: # (secondary sort needed for imported sources, or the first main
2247: # revision gets before the same revision on the 1.1.1 branch)
2248: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
2249: }
2250: elsif ($logsort eq "rev") {
2251: # Sort the revisions in revision order, highest first
2252: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
2253: }
2254: else {
2255: # No sorting. Present in the same order as rlog / cvs log
2256: @revdisplayorder = @revisions;
2257: }
2258:
2259: }
2260:
1.45.2.56 knu 2261: sub printDiffLinks($$) {
2262: my($text, $url) = @_;
2263: my @extra;
2264:
2265: local $_;
2266: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2267: my $f = $_ eq $defaultDiffType ? '' : $_;
2268:
2269: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2270: }
2271:
2272: print &link($text, $url), ' (', join(', ', @extra), ')';
2273: }
2274:
1.45.2.46 knu 2275: sub printLog($;$) {
2276: my ($link, $br, $brp);
2277: ($_,$link) = @_;
2278: ($br = $_) =~ s/\.\d+$//;
2279: ($brp = $br) =~ s/\.?\d+$//;
2280: my ($isDead, $prev);
2281:
2282: $link = 1 if (!defined($link));
2283: $isDead = ($state{$_} eq "dead");
2284:
2285: if ($link && !$isDead) {
2286: my ($filename);
2287: ($filename = $where) =~ s/^.*\///;
2288: my ($fileurl) = urlencode($filename);
1.4 fenner 2289: print "<a NAME=\"rev$_\"></a>";
1.45.2.46 knu 2290: if (defined($revsym{$_})) {
2291: foreach my $sym (split(", ", $revsym{$_})) {
2292: print "<a NAME=\"$sym\"></a>";
2293: }
1.4 fenner 2294: }
1.45.2.46 knu 2295: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
2296: foreach my $sym (split(", ", $revsym{$br})) {
1.4 fenner 2297: print "<a NAME=\"$sym\"></a>";
2298: }
1.45.2.46 knu 2299: $nameprinted{$br} = 1;
1.4 fenner 2300: }
1.45.2.46 knu 2301: print "\n Revision ";
2302: &download_link($fileurl, $_, $_,
1.45.2.56 knu 2303: $defaultViewable ? "text/x-cvsweb-markup" : undef);
1.45.2.46 knu 2304: if ($defaultViewable) {
1.45.2.56 knu 2305: print " / (";
2306: &download_link($fileurl, $_, "download", $mimetype);
2307: print ")";
1.45.2.46 knu 2308: }
2309: if (not $defaultTextPlain) {
1.45.2.56 knu 2310: print " / (";
2311: &download_link($fileurl, $_, "as text", "text/plain");
2312: print ")";
1.45.2.46 knu 2313: }
2314: if (!$defaultViewable) {
1.45.2.56 knu 2315: print " / (";
2316: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2317: print ")";
1.45.2.46 knu 2318: }
2319: if ($allow_annotate) {
1.45.2.56 knu 2320: print " - ";
2321: print &link('annotate',
2322: sprintf('%s/%s?annotate=%s%s',
2323: $scriptname,
2324: urlencode($where),
2325: $_,
2326: $barequery));
1.45.2.46 knu 2327: }
2328: # Plus a select link if enabled, and this version isn't selected
2329: if ($allow_version_select) {
2330: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
1.45.2.56 knu 2331: print " - ";
2332: print &link('[select for diffs]',
2333: sprintf('%s?r1=%s%s',
2334: $scriptwhere,
2335: $_,
2336: $barequery));
1.45.2.46 knu 2337: }
2338: else {
2339: print " - <b>[selected]</b>";
2340: }
2341: }
2342: }
2343: else {
2344: print "Revision <B>$_</B>";
2345: }
2346: if (/^1\.1\.1\.\d+$/) {
2347: print " <i>(vendor branch)</i>";
2348: }
2349: if (defined @mytz) {
2350: my ($est) = $mytz[(localtime($date{$_}))[8]];
1.45.2.56 knu 2351: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
1.45.2.46 knu 2352: } else {
1.45.2.56 knu 2353: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
1.45.2.46 knu 2354: }
1.45.2.56 knu 2355: print readableTime(time() - $date{$_},1), " ago)";
1.45.2.46 knu 2356: print " by ";
1.45.2.56 knu 2357: print "<i>", $author{$_}, "</i>\n";
1.45.2.46 knu 2358: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
2359: if ($revsym{$br});
2360: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
2361: if ($revsym{$_});
2362: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
2363: if ($branchpoint{$_});
2364: # Find the previous revision
2365: my @prevrev = split(/\./, $_);
2366: do {
2367: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 2368: # If it was X.Y.Z.1, just make it X.Y
1.45.2.46 knu 2369: pop(@prevrev);
2370: pop(@prevrev);
2371: }
2372: $prev = join(".", @prevrev);
2373: } until (defined($date{$prev}) || $prev eq "");
2374: if ($prev ne "") {
2375: if ($difflines{$_}) {
2376: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
2377: }
2378: }
2379: if ($isDead) {
2380: print "<BR><B><I>FILE REMOVED</I></B>\n";
2381: }
2382: elsif ($link) {
2383: my %diffrev = ();
2384: $diffrev{$_} = 1;
2385: $diffrev{""} = 1;
2386: print "<BR>Diff";
2387: #
2388: # Offer diff to previous revision
2389: if ($prev) {
2390: $diffrev{$prev} = 1;
1.45.2.56 knu 2391:
2392: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2393: $scriptwhere,
2394: $prev,
2395: $_,
2396: $barequery);
2397:
2398: print " to previous ";
2399: printDiffLinks($prev, $url);
1.1 jfieber 2400: }
1.45.2.46 knu 2401: #
2402: # Plus, if it's on a branch, and it's not a vendor branch,
2403: # offer a diff with the branch point.
2404: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
1.45.2.56 knu 2405: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2406: $scriptwhere,
2407: $brp,
2408: $_,
2409: $barequery);
2410:
2411: print " to branchpoint ";
2412: printDiffLinks($brp, $url);
1.45.2.46 knu 2413: }
2414: #
2415: # Plus, if it's on a branch, and it's not a vendor branch,
2416: # offer to diff with the next revision of the higher branch.
2417: # (e.g. change gets committed and then brought
2418: # over to -stable)
2419: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2420: my ($i,$nextmain);
2421: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
1.45.2.63 knu 2422: my @tmp2 = split(/\./, $_);
1.45.2.46 knu 2423: for ($nextmain = ""; $i > 0; $i--) {
1.45.2.63 knu 2424: my $next = $revorder[$i-1];
2425: my @tmp1 = split(/\./, $next);
2426: if (@tmp1 < @tmp2) {
1.45.2.46 knu 2427: $nextmain = $next;
2428: last;
2429: }
2430: # Only the highest version on a branch should have
2431: # a diff for the "next main".
1.45.2.63 knu 2432: last if (@tmp1 - 1 <= @tmp2 &&
2433: join(".",@tmp1[0..$#tmp1-1]) eq join(".",@tmp2[0..$#tmp1-1]));
1.45.2.46 knu 2434: }
2435: if (!defined($diffrev{$nextmain})) {
2436: $diffrev{$nextmain} = 1;
1.45.2.56 knu 2437:
2438: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2439: $scriptwhere,
2440: $nextmain,
2441: $_,
2442: $barequery);
2443:
2444: print " next main ";
2445: printDiffLinks($nextmain, $url);
1.1 jfieber 2446: }
2447: }
1.45.2.46 knu 2448: # Plus if user has selected only r1, then present a link
2449: # to make a diff to that revision
2450: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2451: $diffrev{$input{"r1"}} = 1;
2452:
1.45.2.56 knu 2453: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2454: $scriptwhere,
2455: $input{'r1'},
2456: $_,
2457: $barequery);
2458:
2459: print " to selected ";
2460: printDiffLinks($input{'r1'}, $url);
1.9 fenner 2461: }
1.1 jfieber 2462: }
1.45.2.46 knu 2463: print "<PRE>\n";
2464: print &htmlify($log{$_}, 1);
2465: print "</PRE>\n";
2466: }
2467:
1.45.2.47 knu 2468: sub doLog($) {
1.45.2.46 knu 2469: my($fullname) = @_;
2470: my ($diffrev, $upwhere, $filename, $backurl);
1.45.2.47 knu 2471:
1.45.2.46 knu 2472: readLog($fullname);
2473:
2474: html_header("CVS log for $where");
2475: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2476: ($filename = $where) =~ s|^.*/||;
2477: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2478: print &link($backicon, "$backurl#$filename"),
1.45.2.56 knu 2479: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
2480: print &link('Request diff between arbitrary revisions', '#diff');
2481: print '<HR NOSHADE>';
2482:
1.45.2.46 knu 2483: if ($curbranch) {
2484: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
2485: }
2486: else {
2487: print "No default branch";
2488: }
2489: print "<BR>\n";
2490: if ($input{only_with_tag}) {
2491: print "Current tag: $input{only_with_tag}<BR>\n";
2492: }
2493:
2494: undef %nameprinted;
2495:
2496: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2497: print "<HR size=1 NOSHADE>";
2498: printLog($revdisplayorder[$i]);
2499: }
2500:
2501: print "<HR NOSHADE>";
1.1 jfieber 2502: print "<A NAME=diff>\n";
2503: print "This form allows you to request diff's between any two\n";
2504: print "revisions of a file. You may select a symbolic revision\n";
2505: print "name using the selection box or you may type in a numeric\n";
2506: print "name using the type-in text box.\n";
2507: print "</A><P>\n";
1.45.2.46 knu 2508: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2509: foreach (@stickyvars) {
1.45.2.56 knu 2510: printf('<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">', $_, $input{$_})
1.45.2.46 knu 2511: if (defined($input{$_})
1.45.2.51 knu 2512: && ((!defined($DEFAULTVALUE{$_})
2513: || $input{$_} ne $DEFAULTVALUE{$_})
2514: && $input{$_} ne ""));
1.45.2.46 knu 2515: }
1.45.2.51 knu 2516: print "<TABLE><TR>\n";
2517: print "<TD align=right>Diffs between \n";
1.1 jfieber 2518: print "<SELECT NAME=\"r1\">\n";
2519: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2520: print $sel;
2521: print "</SELECT>\n";
1.45.2.46 knu 2522: $diffrev = $revdisplayorder[$#revdisplayorder];
2523: $diffrev = $input{"r1"} if (defined($input{"r1"}));
1.45.2.51 knu 2524: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
2525: print "<TD><BR></TD></TR>\n";
2526: print "<TR><TD align=right>and \n";
1.1 jfieber 2527: print "<SELECT NAME=\"r2\">\n";
2528: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2529: print $sel;
2530: print "</SELECT>\n";
1.45.2.46 knu 2531: $diffrev = $revdisplayorder[0];
2532: $diffrev = $input{"r2"} if (defined($input{"r2"}));
1.45.2.51 knu 2533: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
2534: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Get Diffs \"></TD>\n";
1.1 jfieber 2535: print "</FORM>\n";
1.45.2.51 knu 2536: print "</TR></TABLE>\n";
1.7 fenner 2537: print "<HR noshade>\n";
1.45.2.51 knu 2538: print "<TABLE>";
2539: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
1.45.2.56 knu 2540: print "<TR><TD align=right>Preferred Diff type:</TD>";
2541: print "<TD>";
1.45.2.51 knu 2542: printDiffSelect($use_java_script);
2543: print "</TD><TD></TD></TR>\n";
1.45.2.46 knu 2544: if (@branchnames) {
1.45.2.51 knu 2545: print "<TR><TD align=right>View only Branch:</TD>";
2546: print "<TD>";
1.45.2.46 knu 2547: print "<A name=branch></A>\n";
2548: print "<SELECT NAME=\"only_with_tag\"";
2549: print " onchange=\"submit()\"" if ($use_java_script);
2550: print ">\n";
2551: print "<OPTION VALUE=\"\"";
2552: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2553: $input{"only_with_tag"} eq "");
2554: print ">Show all branches\n";
2555: foreach (reverse sort @branchnames) {
1.9 fenner 2556: print "<OPTION";
1.45.2.46 knu 2557: print " SELECTED" if (defined($input{"only_with_tag"})
2558: && $input{"only_with_tag"} eq $_);
1.9 fenner 2559: print ">${_}\n";
1.45.2.46 knu 2560: }
1.45.2.51 knu 2561: print "</SELECT></TD><TD></TD></TR>\n";
1.7 fenner 2562: }
1.45.2.46 knu 2563: foreach (@stickyvars) {
1.45.2.51 knu 2564: next if ($_ eq "f");
1.45.2.46 knu 2565: next if ($_ eq "only_with_tag");
2566: next if ($_ eq "logsort");
2567: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
1.45.2.51 knu 2568: if (defined($input{$_})
2569: && (!defined($DEFAULTVALUE{$_})
2570: || $input{$_} ne $DEFAULTVALUE{$_})
1.45.2.46 knu 2571: && $input{$_} ne "");
2572: }
1.45.2.51 knu 2573: print "<TR><TD align=right>";
2574: print "<A name=logsort></A>\n";
2575: print "Sort log by:</TD>";
1.45.2.56 knu 2576: print "<TD>";
2577: printLogSortSelect($use_java_script);
2578: print "</TD>";
1.45.2.51 knu 2579: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Set \"></TD>";
1.7 fenner 2580: print "</FORM>\n";
1.45.2.51 knu 2581: print "</TR></TABLE>";
1.2 jfieber 2582: print &html_footer;
1.1 jfieber 2583: print "</BODY></HTML>\n";
1.10 wosch 2584: }
2585:
1.45.2.47 knu 2586: sub flush_diff_rows($$$$) {
1.45.2.46 knu 2587: my $j;
2588: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2589: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2590: for ($j = 0 ; $j < $leftRow; $j++) {
2591: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2592: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2593: }
2594: }
2595: elsif ($state eq "PreChange") { # state eq "PreChange"
2596: # we got removes with subsequent adds
2597: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2598: print "<tr>";
2599: if ($j < $leftRow) {
2600: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2601: }
2602: else {
2603: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2604: }
2605: if ($j < $rightRow) {
2606: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2607: }
2608: else {
2609: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2610: }
2611: print "</tr>\n";
2612: }
2613: }
2614: }
2615:
2616: ##
2617: # Function to generate Human readable diff-files
2618: # human_readable_diff(String revision_to_return_to);
2619: ##
2620: sub human_readable_diff($){
1.45.2.51 knu 2621: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
1.45.2.46 knu 2622: my ($fh, $rev) = @_;
2623: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2624: my (@rightCol, @leftCol);
2625:
2626: ($where_nd = $where) =~ s/.diff$//;
2627: ($filename = $where_nd) =~ s/^.*\///;
2628: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2629: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2630:
1.45.2.47 knu 2631: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
1.45.2.46 knu 2632:
2633: # Read header to pick up read revision and date, if possible
2634: while (<$fh>) {
2635: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2636: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2637: last if (/^\+\+\+ /);
2638: }
2639: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2640: $rev1 = $r1r;
2641: $date1 = $r1d;
2642: }
2643: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2644: $rev2 = $r2r;
2645: $date2 = $r2d;
2646: }
1.45.2.47 knu 2647:
1.45.2.56 knu 2648: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
2649: "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n",
2650: "<tr bgcolor=\"#ffffff\">\n",
2651: "<th width=\"50%\" valign=TOP>",
2652: "version $rev1";
1.45.2.46 knu 2653: print ", $date1" if (defined($date1));
2654: print "<br>Tag: $sym1\n" if ($sym1);
1.45.2.56 knu 2655: print "</th>\n",
2656: "<th width=\"50%\" valign=TOP>",
2657: "version $rev2";
1.45.2.46 knu 2658: print ", $date2" if (defined($date2));
2659: print "<br>Tag: $sym2\n" if ($sym1);
2660: print "</th>\n";
2661:
1.45.2.69 knu 2662: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\"><tt>";
2663: my $fe = "</tt></font>";
1.45.2.46 knu 2664:
2665: my $leftRow = 0;
2666: my $rightRow = 0;
2667: my ($oldline, $newline, $funname, $diffcode, $rest);
2668:
2669: # Process diff text
2670: # The diffrows are could make excellent use of
2671: # cascading style sheets because we've to set the
2672: # font and color for each row. anyone ...?
2673: ####
1.45.2.51 knu 2674:
2675: # prefetch several lines
2676: my @buf = head($fh);
2677:
2678: my %d = scan_directives(@buf);
2679:
2680: while (@buf || !eof($fh)) {
2681: $difftxt = @buf ? shift @buf : <$fh>;
1.45.2.47 knu 2682:
1.45.2.46 knu 2683: if ($difftxt =~ /^@@/) {
2684: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2685: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2686: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2687: print " <font size=-1>$funname</font></td></tr></table>";
2688: print "</td><td width=\"50%\">";
2689: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2690: print " <font size=-1>$funname</font></td></tr></table>";
2691: print "</td>\n";
2692: $state = "dump";
2693: $leftRow = 0;
2694: $rightRow = 0;
2695: }
2696: else {
2697: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
1.45.2.51 knu 2698: $_ = spacedHtmlText($rest, $d{'tabstop'});
1.45.2.46 knu 2699:
2700: # Add fontface, size
2701: $_ = "$fs $_$fe";
1.45.2.47 knu 2702:
1.45.2.46 knu 2703: #########
2704: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2705: # in order to get some nice 'ediff'-mode output
2706: # states:
2707: # "dump" - just dump the value
2708: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2709: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2710: ##########
2711:
2712: if ($diffcode eq '+') {
2713: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2714: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2715: }
2716: else { # we got minus before
2717: $state = "PreChange";
2718: $rightCol[$rightRow++] = $_;
2719: }
1.45.2.47 knu 2720: }
1.45.2.46 knu 2721: elsif ($diffcode eq '-') {
2722: $state = "PreChangeRemove";
2723: $leftCol[$leftRow++] = $_;
2724: }
2725: else { # empty diffcode
2726: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2727: print "<tr><td>$_</td><td>$_</td></tr>\n";
2728: $state = "dump";
2729: $leftRow = 0;
2730: $rightRow = 0;
2731: }
2732: }
2733: }
2734: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2735:
2736: # state is empty if we didn't have any change
2737: if (!$state) {
2738: print "<tr><td colspan=2> </td></tr>";
2739: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2740: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2741: }
2742: print "</table>";
2743: close($fh);
2744:
2745: print "<br><hr noshade width=\"100%\">\n";
2746:
2747: print "<table border=0>";
2748:
2749: print "<tr><td>";
2750: # print legend
2751: print "<table border=1><tr><td>";
2752: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2753: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2754: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2755: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2756: print "</table></td></tr></table>\n";
2757:
2758: print "<td>";
2759: # Print format selector
2760: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2761: foreach my $var (keys %input) {
2762: next if ($var eq "f");
2763: next if (defined($DEFAULTVALUE{$var})
2764: && $DEFAULTVALUE{$var} eq $input{$var});
2765: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2766: urlencode($input{$var}),"\">\n";
2767: }
2768: printDiffSelect($use_java_script);
2769: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2770: print "</FORM>\n";
2771: print "</td>";
2772:
2773: print "</tr></table>";
2774: }
2775:
1.45.2.47 knu 2776: sub navigateHeader($$$$$) {
1.45.2.46 knu 2777: my ($swhere,$path,$filename,$rev,$title) = @_;
2778: $swhere = "" if ($swhere eq $scriptwhere);
1.45.2.70! knu 2779: $swhere = './', urlencode($filename) if ($swhere eq "");
1.45.2.68 knu 2780:
2781: print <<EOF;
2782: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2783: <HTML>
2784: <HEAD>
2785: <META name="robots" content="nofollow">
2786: <!-- knu-cvsweb $cvsweb_revision -->
2787: <TITLE>$path$filename - $title - $rev</TITLE></HEAD>
2788: $body_tag_for_src
2789: <table width="100%" border=0 cellspacing=0 cellpadding=1 bgcolor="$navigationHeaderColor">
2790: <tr valign=bottom><td>
2791: EOF
2792:
1.45.2.56 knu 2793: print &link($backicon, "$swhere$query#rev$rev");
1.45.2.70! knu 2794: print "<b>Return to ", &link($filename,"$swhere$query#rev$rev")," CVS log";
1.45.2.46 knu 2795: print "</b> $fileicon</td>";
1.45.2.47 knu 2796:
1.45.2.46 knu 2797: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2798: print "</tr></table>";
2799: }
2800:
1.45.2.47 knu 2801: sub plural_write($$) {
1.45.2.46 knu 2802: my ($num,$text) = @_;
2803: if ($num != 1) {
1.45.2.56 knu 2804: $text .= "s";
1.45.2.46 knu 2805: }
2806: if ($num > 0) {
1.45.2.56 knu 2807: return join(' ', $num, $text);
1.45.2.46 knu 2808: }
2809: else {
2810: return "";
2811: }
2812: }
2813:
2814: ##
2815: # print readable timestamp in terms of
2816: # '..time ago'
2817: # H. Zeller <zeller@think.de>
2818: ##
1.45.2.47 knu 2819: sub readableTime($$) {
1.45.2.46 knu 2820: my ($i, $break, $retval);
2821: my ($secs,$long) = @_;
2822:
2823: # this function works correct for time >= 2 seconds
2824: if ($secs < 2) {
2825: return "very little time";
2826: }
2827:
2828: my %desc = (1 , 'second',
2829: 60, 'minute',
2830: 3600, 'hour',
2831: 86400, 'day',
2832: 604800, 'week',
2833: 2628000, 'month',
2834: 31536000, 'year');
2835: my @breaks = sort {$a <=> $b} keys %desc;
2836: $i = 0;
1.45.2.47 knu 2837: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
1.45.2.46 knu 2838: $i++;
2839: }
2840: $i--;
2841: $break = $breaks[$i];
2842: $retval = plural_write(int ($secs / $break), $desc{$break});
2843:
2844: if ($long == 1 && $i > 0) {
2845: my $rest = $secs % $break;
2846: $i--;
2847: $break = $breaks[$i];
1.45.2.47 knu 2848: my $resttime = plural_write(int ($rest / $break),
1.45.2.46 knu 2849: $desc{$break});
2850: if ($resttime) {
1.45.2.56 knu 2851: $retval .= ", $resttime";
1.45.2.46 knu 2852: }
2853: }
2854:
2855: return $retval;
2856: }
2857:
2858: ##
2859: # clickablePath(String pathname, boolean last_item_clickable)
2860: #
2861: # returns a html-ified path whereas each directory is a link for
2862: # faster navigation. last_item_clickable controls whether the
2863: # basename (last directory/file) is a link as well
2864: ##
2865: sub clickablePath($$) {
1.45.2.47 knu 2866: my ($pathname,$clickLast) = @_;
1.45.2.46 knu 2867: my $retval = '';
1.45.2.47 knu 2868:
1.45.2.46 knu 2869: if ($pathname eq '/') {
2870: # this should never happen - chooseCVSRoot() is
2871: # intended to do this
2872: $retval = "[$cvstree]";
2873: }
2874: else {
1.45.2.56 knu 2875: $retval .= ' ' . &link("[$cvstree]", sprintf('%s/%s#dirlist',
2876: $scriptname,
2877: $query));
1.45.2.46 knu 2878: my $wherepath = '';
2879: my ($lastslash) = $pathname =~ m|/$|;
2880: foreach (split(/\//, $pathname)) {
1.45.2.56 knu 2881: $retval .= " / ";
2882: $wherepath .= "/$_";
1.45.2.46 knu 2883: my ($last) = "$wherepath/" eq "/$pathname"
2884: || $wherepath eq "/$pathname";
2885: if ($clickLast || !$last) {
1.45.2.56 knu 2886: $retval .= &link($_, join('',
2887: $scriptname,
2888: urlencode($wherepath),
2889: (!$last || $lastslash ? '/' : ''),
2890: $query,
2891: (!$last || $lastslash ? "#dirlist" : "")));
1.45.2.46 knu 2892: }
2893: else { # do not make a link to the current dir
1.45.2.56 knu 2894: $retval .= $_;
1.45.2.46 knu 2895: }
2896: }
2897: }
2898: return $retval;
2899: }
2900:
2901: sub chooseCVSRoot() {
1.45.2.65 knu 2902: if (2 <= @CVSROOT) {
1.45.2.46 knu 2903: my ($k);
2904: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2905: foreach $k (keys %input) {
1.45.2.47 knu 2906: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
1.45.2.46 knu 2907: if ($input{$k}) && ($k ne "cvsroot");
2908: }
2909: # Form-Elements look wierd in Netscape if the background
2910: # isn't gray and the form elements are not placed
2911: # within a table ...
2912: print "<table><tr>";
2913: print "<td>CVS Root:</td>";
2914: print "<td>\n<select name=\"cvsroot\"";
2915: print " onchange=\"submit()\"" if ($use_java_script);
2916: print ">\n";
1.45.2.65 knu 2917: foreach $k (@CVSROOT) {
1.45.2.46 knu 2918: print "<option value=\"$k\"";
2919: print " selected" if ($k eq $cvstree);
1.45.2.56 knu 2920: print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k), "</option>\n";
1.45.2.46 knu 2921: }
2922: print "</select>\n</td>";
1.45.2.65 knu 2923: print "<td>";
1.45.2.46 knu 2924: }
2925: else {
2926: # no choice ..
2927: print "CVS Root: <b>[$cvstree]</b>";
2928: }
1.45.2.65 knu 2929:
2930: print " Module path or alias:\n";
2931: print "<INPUT TYPE=TEXT NAME=\"path\" VALUE=\"\" SIZE=15>\n";
2932: print "<input type=submit value=\"Go\">";
2933:
2934: if (2 <= @CVSROOT) {
2935: print "</td></tr></table></form>";
2936: }
1.45.2.46 knu 2937: }
2938:
2939: sub chooseMirror() {
2940: my ($mirror,$moremirrors);
2941: $moremirrors = 0;
2942: # This code comes from the original BSD-cvsweb
2943: # and may not be useful for your site; If you don't
2944: # set %MIRRORS this won't show up, anyway
2945: #
1.45.2.47 knu 2946: # Should perhaps exlude the current site somehow..
1.45.2.46 knu 2947: if (keys %MIRRORS) {
2948: print "\nThis cvsweb is mirrored in:\n";
2949: foreach $mirror (keys %MIRRORS) {
2950: print ", " if ($moremirrors);
1.45.2.56 knu 2951: print &link(htmlquote($mirror),$MIRRORS{$mirror});
1.45.2.46 knu 2952: $moremirrors = 1;
2953: }
2954: print "<p>\n";
2955: }
2956: }
2957:
1.45.2.47 knu 2958: sub fileSortCmp() {
1.45.2.46 knu 2959: my ($comp) = 0;
2960: my ($c,$d,$af,$bf);
2961:
2962: ($af = $a) =~ s/,v$//;
2963: ($bf = $b) =~ s/,v$//;
2964: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2965: if (defined($fileinfo{$af}));
2966: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2967: if (defined($fileinfo{$bf}));
2968:
2969: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2970: # Two files
2971: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2972: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2973: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2974: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2975: }
2976: if ($comp == 0) {
2977: # Directories first, then sorted on name if no other sort critera
2978: # available.
2979: my $ad = ((-d "$fullname/$a")?"D":"F");
2980: my $bd = ((-d "$fullname/$b")?"D":"F");
2981: ($c=$a) =~ s|.*/||;
2982: ($d=$b) =~ s|.*/||;
2983: $comp = ("$ad$c" cmp "$bd$d");
2984: }
2985: return $comp;
2986: }
2987:
2988: # make A url for downloading
1.45.2.47 knu 2989: sub download_url($$;$) {
1.45.2.46 knu 2990: my ($url,$revision,$mimetype) = @_;
2991:
1.45.2.59 knu 2992: $revision =~ s/\b0\.//;
1.45.2.46 knu 2993:
1.45.2.56 knu 2994: if (defined($checkoutMagic)
1.45.2.46 knu 2995: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
1.45.2.56 knu 2996: my $path = $where;
2997: $path =~ s|/[^/]*$|/|;
1.45.2.46 knu 2998: $url = "$scriptname/$checkoutMagic/${path}$url";
2999: }
3000: $url .= "?rev=$revision";
1.45.2.56 knu 3001: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
1.45.2.69 knu 3002:
1.45.2.56 knu 3003: $url;
1.45.2.46 knu 3004: }
3005:
1.45.2.47 knu 3006: # Presents a link to download the
1.45.2.46 knu 3007: # selected revision
1.45.2.47 knu 3008: sub download_link($$$;$) {
1.45.2.56 knu 3009: my ($url, $revision, $textlink, $mimetype) = @_;
3010: my ($fullurl) = download_url($url, $revision, $mimetype);
3011:
1.45.2.70! knu 3012: $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
! 3013:
1.45.2.61 knu 3014: printf '<A HREF="%s"', hrefquote("$fullurl$barequery");
1.45.2.56 knu 3015:
1.45.2.46 knu 3016: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
1.45.2.56 knu 3017: print ' target="cvs_checkout"';
1.45.2.46 knu 3018: # we should have
3019: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3020: # in order to allow the user to resize the window; otherwise
3021: # the user may resize the window, but on next checkout - zap -
3022: # its original (configured s. cvsweb.conf) size is back again
3023: # .. annoying (if $extern_window_(width|height) is defined)
3024: # but this if (..) solution is far from perfect
3025: # what we need to do as well is
3026: # 1) save cvswin in an invisible frame that always exists
3027: # (document.cvswin will be void on next load)
3028: # 2) on close of the cvs_checkout - window set the cvswin
3029: # variable to 'null' again - so that it will be
3030: # reopenend with the configured size
3031: # anyone a JavaScript programmer ?
3032: # .. so here without if (..):
3033: # currently, the best way is to comment out the size parameters
3034: # ($extern_window...) in cvsweb.conf.
3035: if ($use_java_script) {
1.45.2.56 knu 3036: my @attr = qw(resizeable scrollbars);
3037:
3038: push @attr, qw(status toolbar)
3039: if (defined($mimetype) && $mimetype eq "text/html");
3040:
3041: push @attr, "width=$extern_window_width"
3042: if (defined($extern_window_width));
3043:
3044: push @attr, "height=$extern_window_height"
3045: if (defined($extern_window_height));
3046:
3047: printf q` onClick="window.open('%s','cvs_checkout','%s');"`,
1.45.2.61 knu 3048: hrefquote($fullurl), join(',', @attr);
1.45.2.46 knu 3049: }
3050: }
3051: print "><b>$textlink</b></A>";
3052: }
3053:
3054: # Returns a Query string with the
3055: # specified parameter toggled
3056: sub toggleQuery($$) {
3057: my ($toggle,$value) = @_;
3058: my ($newquery,$var);
3059: my (%vars);
3060: %vars = %input;
3061: if (defined($value)) {
3062: $vars{$toggle} = $value;
3063: }
3064: else {
3065: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3066: }
3067: # Build a new query of non-default paramenters
3068: $newquery = "";
3069: foreach $var (@stickyvars) {
3070: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3071: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3072: if ($value ne $default) {
1.45.2.56 knu 3073: $newquery .= "&" if ($newquery ne "");
1.45.2.46 knu 3074: $newquery .= urlencode($var) . "=" . urlencode($value);
3075: }
3076: }
3077: if ($newquery) {
3078: return '?' . $newquery;
3079: }
3080: return "";
3081: }
3082:
1.45.2.47 knu 3083: sub urlencode($) {
1.45.2.56 knu 3084: local($_) = @_;
3085:
3086: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3087:
1.45.2.61 knu 3088: $_;
1.45.2.56 knu 3089: }
3090:
3091: sub htmlquote($) {
3092: local($_) = @_;
3093:
3094: # Special Characters; RFC 1866
3095: s/&/&/g;
3096: s/\"/"/g;
3097: s/</</g;
3098: s/>/>/g;
3099:
3100: $_;
3101: }
3102:
3103: sub htmlunquote($) {
3104: local($_) = @_;
3105:
3106: # Special Characters; RFC 1866
3107: s/"/\"/g;
3108: s/</</g;
3109: s/>/>/g;
3110: s/&/&/g;
3111:
3112: $_;
1.45.2.46 knu 3113: }
3114:
1.45.2.61 knu 3115: sub hrefquote($) {
3116: local($_) = @_;
3117:
3118: y/ /+/;
3119:
3120: htmlquote($_)
3121: }
3122:
1.45.2.47 knu 3123: sub http_header(;$) {
1.45.2.46 knu 3124: my $content_type = shift || "text/html";
1.45.2.63 knu 3125:
3126: $content_type .= "; charset=$charset"
3127: if $content_type =~ m,^text/, && defined($charset) && $charset;
3128:
1.45.2.46 knu 3129: if (defined($moddate)) {
3130: if ($is_mod_perl) {
1.45.2.51 knu 3131: Apache->request->header_out("Last-Modified" => scalar gmtime($moddate) . " GMT");
1.45.2.46 knu 3132: }
3133: else {
1.45.2.56 knu 3134: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
1.45.2.46 knu 3135: }
3136: }
3137: if ($is_mod_perl) {
3138: Apache->request->content_type($content_type);
3139: }
3140: else {
3141: print "Content-type: $content_type\r\n";
3142: }
3143: if ($allow_compress && $maycompress) {
1.45.2.67 knu 3144: if ($has_zlib || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c"))) {
1.45.2.46 knu 3145: if ($is_mod_perl) {
3146: Apache->request->content_encoding("x-gzip");
3147: Apache->request->header_out(Vary => "Accept-Encoding");
3148: Apache->request->send_http_header;
3149: }
3150: else {
3151: print "Content-encoding: x-gzip\r\n";
3152: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
3153: print "\r\n"; # Close headers
3154: }
3155: $| = 1; $| = 0; # Flush header output
1.45.2.51 knu 3156: if ($has_zlib) {
3157: tie *GZIP, __PACKAGE__, \*STDOUT;
3158: }
3159: select(GZIP);
3160: $gzip_open = 1;
1.45.2.58 knu 3161: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
1.45.2.46 knu 3162: }
3163: else {
3164: if ($is_mod_perl) {
3165: Apache->request->send_http_header;
3166: }
3167: else {
3168: print "\r\n"; # Close headers
3169: }
1.45.2.67 knu 3170: 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 3171: }
3172: }
3173: else {
3174: if ($is_mod_perl) {
3175: Apache->request->send_http_header;
3176: }
3177: else {
3178: print "\r\n"; # Close headers
3179: }
3180: }
3181: }
3182:
3183: sub html_header($) {
3184: my ($title) = @_;
1.45.2.68 knu 3185: http_header("text/html");
1.45.2.46 knu 3186:
3187: (my $header = &cgi_style::html_header) =~ s/^.*\n\n//; # remove HTTP response header
3188:
3189: print <<EOH;
3190: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
3191: "http://www.w3.org/TR/REC-html40/loose.dtd">
3192: $header
1.45.2.68 knu 3193: <!-- knu-cvsweb $cvsweb_revision -->
1.45.2.46 knu 3194: EOH
3195: }
3196:
1.45.2.47 knu 3197: sub html_footer() {
1.45.2.46 knu 3198: return &cgi_style::html_footer;
3199: }
3200:
1.45.2.47 knu 3201: sub link_tags($) {
1.45.2.46 knu 3202: my ($tags) = @_;
3203: my ($ret) = "";
3204: my ($fileurl,$filename);
3205:
3206: ($filename = $where) =~ s/^.*\///;
1.45.2.70! knu 3207: $fileurl = './' . urlencode($filename);
1.45.2.46 knu 3208:
3209: foreach my $sym (split(", ", $tags)) {
3210: $ret .= ",\n" if ($ret ne "");
1.45.2.56 knu 3211: $ret .= &link($sym, $fileurl . toggleQuery('only_with_tag',$sym));
1.45.2.46 knu 3212: }
1.45.2.56 knu 3213: return "$ret\n";
1.45.2.46 knu 3214: }
3215:
3216: #
3217: # See if a module is listed in the config file's @HideModule list.
3218: #
1.45.2.47 knu 3219: sub forbidden_module($) {
1.45.2.46 knu 3220: my($module) = @_;
1.45.2.47 knu 3221:
1.45.2.46 knu 3222: for (my $i=0; $i < @HideModules; $i++) {
3223: return 1 if $module eq $HideModules[$i];
3224: }
3225:
3226: return 0;
1.45.2.52 knu 3227: }
3228:
3229: # Close the GZIP handle remove the tie.
3230:
3231: sub gzipclose {
3232: if ($gzip_open) {
3233: select(STDOUT);
3234: close(GZIP);
3235: untie *GZIP;
3236: $gzip_open = 0;
3237: }
1.45.2.51 knu 3238: }
3239:
3240: # implement a gzipped file handle via the Compress:Zlib compression
3241: # library.
3242:
3243: sub MAGIC1() { 0x1f }
3244: sub MAGIC2() { 0x8b }
3245: sub OSCODE() { 3 }
3246:
3247: sub TIEHANDLE {
3248: my ($class, $out) = @_;
3249: my ($d) = Compress::Zlib::deflateInit(-Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3250: -WindowBits => -Compress::Zlib::MAX_WBITS()) or return undef;
3251: my ($o) = {
3252: handle => $out,
3253: dh => $d,
3254: crc => 0,
3255: len => 0,
3256: };
3257: my ($header) = pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0,0,0,0,0,0, OSCODE);
3258: print {$o->{handle}} $header;
3259: return bless($o, $class);
3260: }
3261:
3262: sub PRINT {
3263: my ($o) = shift;
3264: my ($buf) = join(defined $, ? $, : "",@_);
3265: my ($len) = length($buf);
3266: my ($compressed, $status) = $o->{dh}->deflate($buf);
3267: print {$o->{handle}} $compressed if defined($compressed);
3268: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3269: $o->{len} += $len;
3270: return $len;
3271: }
3272:
3273: sub PRINTF {
3274: my ($o) = shift;
3275: my ($fmt) = shift;
3276: my ($buf) = sprintf($fmt, @_);
3277: my ($len) = length($buf);
3278: my ($compressed, $status) = $o->{dh}->deflate($buf);
3279: print {$o->{handle}} $compressed if defined($compressed);
3280: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3281: $o->{len} += $len;
3282: return $len;
3283: }
3284:
3285: sub WRITE {
3286: my ($o, $buf, $len, $off) = @_;
3287: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3288: print {$o->{handle}} $compressed if defined($compressed);
3289: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3290: $o->{len} += $len;
3291: return $len;
3292: }
3293:
3294: sub CLOSE {
3295: my ($o) = @_;
3296: return if !defined( $o->{dh});
3297: my ($buf) = $o->{dh}->flush();
3298: $buf .= pack("V V", $o->{crc}, $o->{len});
3299: print {$o->{handle}} $buf;
3300: undef $o->{dh};
3301: }
3302:
3303: sub DESTROY {
3304: my ($o) = @_;
3305: CLOSE($o);
1.1 jfieber 3306: }
CVSweb