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