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