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