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