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