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