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