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