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