Annotation of cvsweb/cvsweb.cgi, Revision 3.119.2.2
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:
1610: # this annotate version is based on the
1611: # cvs annotate-demo Perl script by Cyclic Software
1612: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1613: # the public domain.
1614: # we could abandon the use of rlog, rcsdiff and co using
1615: # the cvsserver in a similiar way one day (..after rewrite)
1616: $pid = open2($reader, $writer, $CMD{cvs}, @cvs_options, "server")
3.95 knu 1617: or fatal("500 Internal Error",
3.103 knu 1618: 'Fatal Error - unable to open cvs for annotation');
3.80 knu 1619:
1620: # OK, first send the request to the server. A simplified example is:
1621: # Root /home/kingdon/zwork/cvsroot
1622: # Argument foo/xx
1623: # Directory foo
1624: # /home/kingdon/zwork/cvsroot/foo
1625: # Directory .
1626: # /home/kingdon/zwork/cvsroot
1627: # annotate
1628: # although as you can see there are a few more details.
1629:
1630: print $writer "Root $cvsroot\n";
1631: print $writer
1632: "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1633:
1634: # Don't worry about sending valid-requests, the server just needs to
1635: # support "annotate" and if it doesn't, there isn't anything to be done.
1636: print $writer "UseUnchanged\n";
1637: print $writer "Argument -r\n";
1638: print $writer "Argument $rev\n";
1639: print $writer "Argument $where\n";
1640:
1641: # The protocol requires us to fully fake a working directory (at
1642: # least to the point of including the directories down to the one
1643: # containing the file in question).
1644: # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
1645: my @dirs = split ('/', $where);
1646: my $path = "";
1647: foreach (@dirs) {
1648:
1649: if ($path eq "") {
1650:
1651: # In our example, $_ is "dir".
1652: $path = $_;
1653: } else {
1654: print $writer "Directory $path\n";
1655: print $writer "$cvsroot/$path\n";
1656:
1657: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1658: # And the next time, "file" and "dir/sdir/file" (which then gets
1659: # ignored, because we don't need to send Directory for the file).
1660: $path .= "/$_";
1661: }
1662: }
1663:
1664: # And the last "Directory" before "annotate" is the top level.
1665: print $writer "Directory .\n";
1666: print $writer "$cvsroot\n";
1667:
1668: print $writer "annotate\n";
1669:
1670: # OK, we've sent our command to the server. Thing to do is to
1671: # close the writer side and get all the responses. If "cvs server"
1672: # were nicer about buffering, then we could just leave it open, I think.
3.95 knu 1673: close($writer) or die "cannot close: $!";
3.80 knu 1674:
1675: http_header();
1676:
1677: navigateHeader($scriptwhere, $pathname, $filename, $rev, "annotate");
1678: print
3.100 knu 1679: "<h3 style=\"text-align: center\">Annotation of $pathname$filename, Revision $rev</h3>\n";
3.80 knu 1680:
1681: # Ready to get the responses from the server.
1682: # For example:
1683: # E Annotations for foo/xx
1684: # E ***************
1685: # M 1.3 (kingdon 06-Sep-97): hello
1686: # ok
1687: my ($lineNr) = 0;
1688: my ($oldLrev, $oldLusr) = ("", "");
1689: my ($revprint, $usrprint);
1690:
1691: if ($annTable) {
3.100 knu 1692: print "<table style=\"border: none\" cellspacing=\"0\" cellpadding=\"0\">\n";
3.80 knu 1693: } else {
1694: print "<pre>";
1695: }
1696:
1697: # prefetch several lines
1698: my @buf = head($reader);
1699:
1700: my %d = scan_directives(@buf);
1701:
1702: while (@buf || !eof($reader)) {
1703: $_ = @buf ? shift @buf : <$reader>;
1704:
1705: my @words = split;
1706:
1707: # Adding one is for the (single) space which follows $words[0].
1708: my $rest = substr($_, length($words[0]) + 1);
1709: if ($words[0] eq "E") {
1710: next;
1711: } elsif ($words[0] eq "M") {
1712: $lineNr++;
1713: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
1714: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
1715: my $line = substr($_, 36);
1716: my $isCurrentRev = ($rev eq $lrev);
1717:
1718: # we should parse the date here ..
1719: if ($lrev eq $oldLrev) {
1720: $revprint = sprintf('%-8s', '');
1721: } else {
1722: $revprint = sprintf('%-8s', $lrev);
1723: $revprint =~
1724: s`\S+`&link($&, "$scriptwhere$query#rev$&")`e
1725: ; # `
1726: $oldLusr = '';
1727: }
1728:
1729: if ($lusr eq $oldLusr) {
1730: $usrprint = '';
1731: } else {
1732: $usrprint = $lusr;
1733: }
1734: $oldLrev = $lrev;
1735: $oldLusr = $lusr;
1736:
1737: # Set bold for text-based browsers only - graphical
1738: # browsers show bold fonts a bit wider than regular fonts,
1739: # so it looks irregular.
1740: print "<b>" if ($isCurrentRev && $is_textbased);
1741:
1742: printf "%s%s %-8s %4d:", $revprint,
1743: $isCurrentRev ? '!' : ' ', $usrprint, $lineNr;
1744: print spacedHtmlText($line, $d{'tabstop'});
1745:
1746: print "</b>" if ($isCurrentRev && $is_textbased);
1747: } elsif ($words[0] eq "ok") {
3.12 knu 1748:
3.80 knu 1749: # We could complain about any text received after this, like the
1750: # CVS command line client. But for simplicity, we don't.
1751: } elsif ($words[0] eq "error") {
1752: fatal("500 Internal Error",
3.103 knu 1753: 'Error occured during annotate: <b>%s</b>',
1754: $_);
3.80 knu 1755: }
3.1 knu 1756: }
3.80 knu 1757:
1758: if ($annTable) {
1759: print "</table>";
1760: } else {
1761: print "</pre>";
3.1 knu 1762: }
3.119.2.2! scop 1763: html_footer();
! 1764:
3.95 knu 1765: close($reader) or warn "cannot close: $!";
3.80 knu 1766: wait;
3.1 knu 1767: }
1768:
1769: ###############################
1770: # make Checkout
1771: ###############################
3.12 knu 1772: sub doCheckout($$) {
3.80 knu 1773: my ($fullname, $rev) = @_;
1774: my ($mimetype, $revopt);
1775: my $fh = do { local (*FH); };
1776:
1777: if ($rev eq 'HEAD' || $rev eq '.') {
1778: $rev = undef;
1779: }
1780:
1781: # make sure the revisions a wellformed, for security
1782: # reasons ..
1783: if (defined($rev) && $rev =~ /[^\w.]/) {
3.103 knu 1784: fatal("404 Not Found",
1785: 'Malformed query "%s"',
1786: $ENV{QUERY_STRING});
3.81 knu 1787: }
1788:
3.80 knu 1789: # get mimetype
1790: if (defined($input{"content-type"})
1791: && ($input{"content-type"} =~ /\S\/\S/))
1792: {
1793: $mimetype = $input{"content-type"}
1794: } else {
1795: $mimetype = &getMimeTypeFromSuffix($fullname);
1796: }
1797:
1798: if (defined($rev)) {
1799: $revopt = "-r$rev";
1800: if ($use_moddate) {
1801: readLog($fullname, $rev);
1802: $moddate = $date{$rev};
1803: }
1804: } else {
1805: $revopt = "-rHEAD";
1806:
1807: if ($use_moddate) {
1808: readLog($fullname);
1809: $moddate = $date{$symrev{HEAD}};
1810: }
1811: }
1812:
1813: ### just for the record:
1814: ### 'cvs co' seems to have a bug regarding single checkout of
1815: ### directories/files having spaces in it;
1816: ### this is an issue that should be resolved on cvs's side
1817: #
1818: # Safely for a child process to read from.
1819: if (!open($fh, "-|")) { # child
1820: # chdir to $tmpdir before to avoid non-readable cgi-bin directories
1821: chdir($tmpdir);
1822: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
3.91 knu 1823:
1824: # work around a bug of cvs -p; expand symlinks
1825: use Cwd 'abs_path';
1826: exec($CMD{cvs}, @cvs_options,
1827: '-d', abs_path($cvsroot),
1828: 'co', '-p',
3.95 knu 1829: $revopt, $where) or exit -1;
3.80 knu 1830: }
1831:
1832: if (eof($fh)) {
3.103 knu 1833: fatal("404 Not Found",
1834: '%s is not (any longer) pertinent',
1835: $where);
3.80 knu 1836: }
1837:
1838: #===================================================================
1839: #Checking out squid/src/ftp.c
1840: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1841: #VERS: 1.1.1.28.6.2
1842: #***************
1843:
1844: # Parse CVS header
1845: my ($revision, $filename, $cvsheader);
1846: $filename = "";
1847: while (<$fh>) {
1848: last if (/^\*\*\*\*/);
1849: $revision = $1 if (/^VERS: (.*)$/);
1850:
1851: if (/^Checking out (.*)$/) {
1852: $filename = $1;
1853: $filename =~ s/^\.\/*//;
1854: }
1855: $cvsheader .= $_;
1856: }
1857:
1858: if ($filename ne $where) {
3.103 knu 1859: fatal("500 Internal Error",
1860: 'Unexpected output from cvs co: %s',
1861: $cvsheader);
3.80 knu 1862: }
1863: $| = 1;
1864:
1865: if ($mimetype eq "text/x-cvsweb-markup") {
1866: &cvswebMarkup($fh, $fullname, $revision);
1867: } else {
1868: http_header($mimetype);
1869: print <$fh>;
1870: }
1871: close($fh);
3.1 knu 1872: }
1873:
3.12 knu 1874: sub cvswebMarkup($$$) {
3.80 knu 1875: my ($filehandle, $fullname, $revision) = @_;
1876: my ($pathname, $filename);
3.1 knu 1877:
3.80 knu 1878: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1879: ($filename = $where) =~ s/^.*\///;
1880: my ($fileurl) = urlencode($filename);
1881:
1882: http_header();
1883:
1884: navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
3.89 knu 1885: print "<hr noshade>";
3.100 knu 1886: print "<table width=\"100%\">\n<tr>\n<td style=\"background-color: $markupLogColor\">";
3.80 knu 1887: print "File: ", &clickablePath($where, 1);
3.35 knu 1888: print " (";
3.80 knu 1889: &download_link($fileurl, $revision, "download");
3.35 knu 1890: print ")";
3.24 knu 1891:
3.80 knu 1892: if (!$defaultTextPlain) {
1893: print " (";
1894: &download_link($fileurl, $revision, "as text", "text/plain");
1895: print ")";
1896: }
3.89 knu 1897: print "<br>\n";
3.80 knu 1898:
1899: if ($show_log_in_markup) {
1900: readLog($fullname); #,$revision);
1901: printLog($revision, 0);
1902: } else {
3.89 knu 1903: print "Version: <b>$revision</b><br>\n";
1904: print "Tag: <b>", $input{only_with_tag}, "</b><br>\n"
3.80 knu 1905: if $input{only_with_tag};
1906: }
3.100 knu 1907: print "</td>\n</tr>\n</table>";
3.80 knu 1908: my $url = download_url($fileurl, $revision, $mimetype);
3.89 knu 1909: print "<hr noshade>";
3.80 knu 1910:
1911: if ($mimetype =~ /^image/) {
3.89 knu 1912: printf '<img src="%s" alt=""><br>', hrefquote("$url$barequery");
3.80 knu 1913: } elsif ($mimetype =~ m%^application/pdf%) {
3.89 knu 1914: printf '<embed src="%s" width="100%"><br>',
3.80 knu 1915: hrefquote("$url$barequery");
1916: } elsif ($preformat_in_markup) {
3.89 knu 1917: print "<pre>";
3.80 knu 1918:
1919: # prefetch several lines
1920: my @buf = head($filehandle);
1921:
1922: my %d = scan_directives(@buf);
3.24 knu 1923:
3.80 knu 1924: while (@buf || !eof($filehandle)) {
1925: $_ = @buf ? shift @buf : <$filehandle>;
3.24 knu 1926:
3.80 knu 1927: print spacedHtmlText($_, $d{'tabstop'});
1928: }
3.89 knu 1929: print "</pre>";
3.80 knu 1930: } else {
3.89 knu 1931: print "<pre>";
3.24 knu 1932:
3.80 knu 1933: while (<$filehandle>) {
1934: print htmlquote($_);
1935: }
3.89 knu 1936: print "</pre>";
3.69 knu 1937: }
1.12 fenner 1938: }
1939:
3.1 knu 1940: sub viewable($) {
3.80 knu 1941: my ($mimetype) = @_;
3.1 knu 1942:
3.80 knu 1943: $mimetype =~ m%^((text|image)/|application/pdf)%;
3.1 knu 1944: }
1945:
1946: ###############################
1947: # Show Colored Diff
1948: ###############################
3.12 knu 1949: sub doDiff($$$$$$) {
3.80 knu 1950: my ($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1951: my $fh = do { local (*FH); };
3.37 knu 1952: my ($rev1, $rev2, $sym1, $sym2, $f1, $f2);
1.12 fenner 1953:
3.81 knu 1954: if (&forbidden_file($fullname)) {
3.103 knu 1955: fatal("403 Forbidden",
1956: 'Access forbidden. This file is mentioned in @ForbiddenFiles');
3.81 knu 1957: return;
1958: }
1959:
1.12 fenner 1960: if ($r1 =~ /([^:]+)(:(.+))?/) {
3.80 knu 1961: $rev1 = $1;
1962: $sym1 = $3;
1.12 fenner 1963: }
3.1 knu 1964: if ($r1 eq 'text') {
3.80 knu 1965: $rev1 = $tr1;
1966: $sym1 = "";
1.12 fenner 1967: }
3.80 knu 1968:
1.12 fenner 1969: if ($r2 =~ /([^:]+)(:(.+))?/) {
3.80 knu 1970: $rev2 = $1;
1971: $sym2 = $3;
1.12 fenner 1972: }
3.1 knu 1973: if ($r2 eq 'text') {
3.80 knu 1974: $rev2 = $tr2;
1975: $sym2 = "";
1.12 fenner 1976: }
3.15 knu 1977:
3.1 knu 1978: # make sure the revisions a wellformed, for security
1979: # reasons ..
3.15 knu 1980: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
3.103 knu 1981: fatal("404 Not Found",
1982: 'Malformed query "%s"',
1983: $ENV{QUERY_STRING});
1.12 fenner 1984: }
3.80 knu 1985:
1986: #
1987: # rev1 and rev2 are now both numeric revisions.
1988: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1989: # XXX should we warn about the fact that we do this?
1990: if (&revcmp($rev1, $rev2) > 0) {
1991: my ($tmp1, $tmp2) = ($rev1, $sym1);
1992: ($rev1, $sym1) = ($rev2, $sym2);
1993: ($rev2, $sym2) = ($tmp1, $tmp2);
1.12 fenner 1994: }
3.37 knu 1995: my $difftype = $DIFFTYPES{$f};
1996:
1997: if (!$difftype) {
3.103 knu 1998: fatal("400 Bad arguments",
1999: 'Diff format %s not understood',
2000: $f);
3.1 knu 2001: }
2002:
3.37 knu 2003: my @difftype = @{$difftype->{'opts'}};
2004: my $human_readable = $difftype->{'colored'};
2005:
3.1 knu 2006: # apply special options
3.3 knu 2007: if ($showfunc) {
3.80 knu 2008: push @difftype, '-p' if $f ne 's';
3.1 knu 2009:
3.80 knu 2010: my ($re1, $re2);
3.1 knu 2011:
3.80 knu 2012: while (($re1, $re2) = each %funcline_regexp) {
2013: if ($fullname =~ /$re1/) {
2014: push @difftype, '-F', $re2;
2015: last;
2016: }
3.1 knu 2017: }
3.3 knu 2018: }
3.80 knu 2019:
3.3 knu 2020: if ($human_readable) {
3.80 knu 2021: if ($hr_ignwhite) {
2022: push @difftype, '-w';
2023: }
2024: if ($hr_ignkeysubst) {
2025: push @difftype, '-kk';
2026: }
3.1 knu 2027: }
3.80 knu 2028:
2029: if (!open($fh, "-|")) { # child
2030: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
3.86 knu 2031: openOutputFilter();
3.95 knu 2032: exec($CMD{rcsdiff}, @difftype, "-r$rev1", "-r$rev2", $fullname) or exit -1;
3.1 knu 2033: }
2034: if ($human_readable) {
3.80 knu 2035: http_header();
2036: &human_readable_diff($fh, $rev2);
3.100 knu 2037: html_footer();
3.80 knu 2038: gzipclose();
2039: exit;
2040: } else {
2041: http_header("text/plain");
3.1 knu 2042: }
3.80 knu 2043:
2044: #
2045: #===================================================================
2046: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
2047: #retrieving revision 1.16
2048: #retrieving revision 1.17
2049: #diff -c -r1.16 -r1.17
2050: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2051: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
2052: #
2053: # Ideas:
2054: # - nuke the stderr output if it's what we expect it to be
2055: # - Add "no differences found" if the diff command supplied no output.
2056: #
2057: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
2058: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
2059: # (bogus example, but...)
2060: #
2061: if (grep { $_ eq '-u' } @difftype) {
2062: $f1 = '---';
2063: $f2 = '\+\+\+';
2064: } else {
2065: $f1 = '\*\*\*';
2066: $f2 = '---';
1.12 fenner 2067: }
3.80 knu 2068:
3.1 knu 2069: while (<$fh>) {
3.80 knu 2070: if (m|^$f1 $cvsroot|o) {
2071: s|$cvsroot/||o;
2072: if ($sym1) {
2073: chop;
2074: $_ .= " $sym1\n";
2075: }
2076: } elsif (m|^$f2 $cvsroot|o) {
2077: s|$cvsroot/||o;
2078:
2079: if ($sym2) {
2080: chop;
2081: $_ .= " $sym2\n";
2082: }
1.12 fenner 2083: }
3.80 knu 2084: print $_;
1.12 fenner 2085: }
3.1 knu 2086: close($fh);
1.12 fenner 2087: }
2088:
3.1 knu 2089: ###############################
2090: # Show Logs ..
2091: ###############################
3.12 knu 2092: sub getDirLogs($$@) {
3.80 knu 2093: my ($cvsroot, $dirname, @otherFiles) = @_;
2094: my ($state, $otherFiles, $tag, $file, $date, $branchpoint, $branch,
2095: $log);
2096: my ($rev, $revision, $revwanted, $filename, $head, $author);
2097:
2098: $tag = $input{only_with_tag};
2099:
2100: my ($DirName) = "$cvsroot/$where";
2101: my (@files, @filetags);
2102: my $fh = do { local (*FH); };
2103:
2104: push (@files, &safeglob("$DirName/*,v"));
2105: push (@files, &safeglob("$DirName/Attic/*,v"))
2106: if (!$input{'hideattic'});
3.119.2.1 scop 2107: foreach my $file (@otherFiles) {
3.80 knu 2108: push (@files, "$DirName/$file");
2109: }
2110:
2111: # just execute rlog if there are any files
2112: if ($#files < 0) {
2113: return;
2114: }
2115:
2116: if (defined($tag)) {
2117:
2118: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
3.86 knu 2119: if (!open($fh, "-|")) { # child
3.80 knu 2120: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
3.86 knu 2121: openOutputFilter();
3.95 knu 2122: exec($CMD{rlog}, @files) or exit -1;
3.80 knu 2123: }
2124: } else {
2125:
3.86 knu 2126: if (!open($fh, "-|")) { # child
3.80 knu 2127: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
3.86 knu 2128: openOutputFilter();
3.95 knu 2129: exec($CMD{rlog}, '-r', @files) or exit -1;
3.80 knu 2130: }
3.1 knu 2131: }
3.80 knu 2132: $state = "start";
2133:
2134: while (<$fh>) {
2135: if ($state eq "start") {
2136:
2137: #Next file. Initialize file variables
2138: $rev = '';
2139: $revwanted = '';
2140: $branch = '';
2141: $branchpoint = '';
2142: $filename = '';
2143: $log = '';
2144: $revision = '';
2145: %symrev = ();
2146: @filetags = ();
2147:
2148: #jump to head state
2149: $state = "head";
2150: }
2151: print "$state:$_" if ($verbose);
2152: again:
2153:
2154: if ($state eq "head") {
2155:
2156: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
2157:
2158: if (/^Working file: (.+)$/) {
2159: $filename = $1;
2160: } elsif (/^head: (.+)$/) {
2161: $head = $1;
2162: } elsif (/^branch: (.+)$/) {
2163: $branch = $1
2164: } elsif (/^symbolic names:/) {
2165: $state = "tags";
2166: ($branch = $head) =~ s/\.\d+$//
2167: if $branch eq '';
2168: $branch =~ s/(\d+)$/0.$1/;
2169: $symrev{MAIN} = $branch;
2170: $symrev{HEAD} = $branch;
2171: $alltags{MAIN} = 1;
2172: $alltags{HEAD} = 1;
2173: push (@filetags, "MAIN", "HEAD");
2174: } elsif (/$LOG_REVSEPARATOR/o) {
2175: $state = "log";
2176: $rev = '';
2177: $date = '';
2178: $log = '';
2179:
2180: # Try to reconstruct the relative filename if RCS spits out a full path
2181: $filename =~ s%^\Q$DirName\E/%%;
2182: }
3.41 knu 2183: next;
2184: }
3.80 knu 2185:
2186: if ($state eq "tags") {
3.94 knu 2187: if (/^\s+([^:]+):\s+([\d\.]+)\s*$/) {
3.80 knu 2188: push (@filetags, $1);
2189: $symrev{$1} = $2;
2190: $alltags{$1} = 1;
2191: next;
2192: } elsif (/^\S/) {
2193:
2194: if (defined($tag)) {
2195: if (defined($symrev{$tag})
2196: || $tag eq "HEAD")
2197: {
2198: $revwanted =
2199: $symrev{$tag eq "HEAD" ?
2200: "MAIN" : $tag};
2201: ($branch = $revwanted) =~
2202: s/\b0\.//;
2203: ($branchpoint = $branch) =~
2204: s/\.?\d+$//;
2205: $revwanted = ''
2206: if ($revwanted ne $branch);
2207: } elsif ($tag ne "HEAD") {
2208: print
2209: "Tag not found, skip this file"
2210: if ($verbose);
2211: $state = "skip";
2212: next;
2213: }
2214: }
2215:
2216: foreach my $tagfound (@filetags) {
2217: $tags{$tagfound} = 1;
2218: }
2219: $state = "head";
2220: goto again;
2221: }
2222: }
2223:
2224: if ($state eq "log") {
2225: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
2226:
2227: # End of a log entry.
2228: my $revbranch = $rev;
2229: $revbranch =~ s/\.\d+$//;
2230: print "$filename $rev Wanted: $revwanted ",
2231: "Revbranch: $revbranch Branch: $branch ",
2232: "Branchpoint: $branchpoint\n"
2233: if ($verbose);
2234:
2235: if ($revwanted eq '' && $branch ne ''
2236: && $branch eq $revbranch || !defined($tag))
2237: {
2238: print
2239: "File revision $rev found for branch $branch\n"
2240: if ($verbose);
2241: $revwanted = $rev;
2242: }
2243:
2244: if ($revwanted ne '' ? $rev eq $revwanted :
2245: $branchpoint ne '' ? $rev eq $branchpoint :
2246: 0 && ($rev eq $head))
2247: { # Don't think head is needed here..
2248: print
2249: "File info $rev found for $filename\n"
2250: if ($verbose);
2251: my @finfo =
2252: ($rev, $date, $log, $author,
2253: $filename);
2254: my ($name);
2255: ($name = $filename) =~ s%/.*%%;
2256: $fileinfo{$name} = [@finfo];
2257: $state = "done" if ($rev eq $revwanted);
2258: }
2259: $rev = '';
2260: $date = '';
2261: $log = '';
2262: } elsif ($date eq ''
2263: && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|
2264: )
2265: {
2266: my $yr = $1;
2267:
2268: # damn 2-digit year routines :-)
2269: if ($yr > 100) {
2270: $yr -= 1900;
2271: }
2272: $date =
2273: &Time::Local::timegm($6, $5, $4, $3, $2 - 1,
2274: $yr);
2275: ($author) = /author: ([^;]+)/;
2276: $state = "log";
2277: $log = '';
2278: next;
3.98 knu 2279: } elsif ($rev eq '' && /^revision (\d+(?:\.\d+)+).*$/) {
2280: $rev = $1; # .*$ eats up the locker(lockers?) info, if any
3.80 knu 2281: next;
2282: } else {
2283: $log .= $_;
2284: }
2285: }
2286:
2287: if (/$LOG_FILESEPARATOR/o) {
2288: $state = "start";
2289: next;
3.41 knu 2290: }
3.1 knu 2291: }
3.80 knu 2292:
2293: if ($. == 0) {
3.103 knu 2294: fatal("500 Internal Error",
2295: '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"',
2296: join (", ", @files), $command_path);
3.1 knu 2297: }
3.80 knu 2298: close($fh);
3.1 knu 2299: }
2300:
3.12 knu 2301: sub readLog($;$) {
3.80 knu 2302: my ($fullname, $revision) = @_;
3.1 knu 2303: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
3.80 knu 2304: my $fh = do { local (*FH); };
3.1 knu 2305:
2306: if (defined($revision)) {
3.80 knu 2307: $revision = "-r$revision";
2308: } else {
2309: $revision = "";
3.1 knu 2310: }
2311:
2312: undef %symrev;
2313: undef %revsym;
2314: undef @allrevisions;
2315: undef %date;
2316: undef %author;
2317: undef %state;
2318: undef %difflines;
2319: undef %log;
1.12 fenner 2320:
2321: print("Going to rlog '$fullname'\n") if ($verbose);
3.80 knu 2322: if (!open($fh, "-|")) { # child
2323: if ($revision ne '') {
3.86 knu 2324: openOutputFilter();
3.95 knu 2325: exec($CMD{rlog}, $revision, $fullname) or exit -1;
3.80 knu 2326: } else {
3.86 knu 2327: openOutputFilter();
3.95 knu 2328: exec($CMD{rlog}, $fullname) or exit -1;
3.80 knu 2329: }
1.44 knu 2330: }
3.80 knu 2331:
3.1 knu 2332: while (<$fh>) {
3.80 knu 2333: print if ($verbose);
2334: if ($symnames) {
2335: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2336: $symrev{$1} = $2;
2337: } else {
2338: $symnames = 0;
2339: }
2340: } elsif (/^head:\s+([\d\.]+)/) {
2341: $head = $1;
2342: } elsif (/^branch:\s+([\d\.]+)/) {
2343: $curbranch = $1;
2344: } elsif (/^symbolic names/) {
2345: $symnames = 1;
2346: } elsif (/^-----/) {
2347: last;
1.1 jfieber 2348: }
2349: }
3.1 knu 2350: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7 fenner 2351:
3.80 knu 2352: # each log entry is of the form:
2353: # ----------------------------
2354: # revision 3.7.1.1
2355: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2356: # log info
2357: # ----------------------------
3.98 knu 2358:
2359: # For a locked revision, the first line after the separator
2360: # becomes smth like
2361: # revision 9.19 locked by: vassilii;
2362:
1.1 jfieber 2363: logentry:
3.80 knu 2364:
3.32 knu 2365: while (!/$LOG_FILESEPARATOR/o) {
3.80 knu 2366: $_ = <$fh>;
2367: last logentry if (!defined($_)); # EOF
2368: print "R:", $_ if ($verbose);
3.98 knu 2369: if (/^revision (\d+(?:\.\d+)+)/) {
3.80 knu 2370: $rev = $1;
2371: unshift (@allrevisions, $rev);
2372: } elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
2373: next logentry;
2374: } else {
2375:
2376: # The rlog output is syntactically ambiguous. We must
2377: # have guessed wrong about where the end of the last log
2378: # message was.
2379: # Since this is likely to happen when people put rlog output
2380: # in their commit messages, don't even bother keeping
2381: # these lines since we don't know what revision they go with
2382: # any more.
2383: next logentry;
2384: }
2385: $_ = <$fh>;
2386: print "D:", $_ if ($verbose);
2387: if (
2388: m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|
2389: )
2390: {
2391: my $yr = $1;
2392:
2393: # damn 2-digit year routines :-)
2394: if ($yr > 100) {
2395: $yr -= 1900;
2396: }
2397: $date{$rev} =
2398: &Time::Local::timegm($6, $5, $4, $3, $2 - 1, $yr);
2399: $author{$rev} = $7;
2400: $state{$rev} = $8;
2401: $difflines{$rev} = $10;
2402: } else {
3.103 knu 2403: fatal("500 Internal Error",
2404: 'Error parsing RCS output: %s',
2405: $_);
3.80 knu 2406: }
2407: line:
2408:
2409: while (<$fh>) {
2410: print "L:", $_ if ($verbose);
2411: next line if (/^branches:\s/);
2412: last line
2413: if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
2414: $log{$rev} .= $_;
2415: }
2416: print "E:", $_ if ($verbose);
1.1 jfieber 2417: }
3.1 knu 2418: close($fh);
1.1 jfieber 2419: print "Done reading RCS file\n" if ($verbose);
3.1 knu 2420:
3.80 knu 2421: @revorder = reverse sort { revcmp($a, $b) } @allrevisions;
2422: print "Done sorting revisions", join (" ", @revorder), "\n"
2423: if ($verbose);
2424:
2425: #
2426: # HEAD is an artificial tag which is simply the highest tag number on the main
2427: # branch, unless there is a branch tag in the RCS file in which case it's the
2428: # highest revision on that branch. Find it by looking through @revorder; it
2429: # is the first commit listed on the appropriate branch.
2430: # This is not neccesary the same revision as marked as head in the RCS file.
3.1 knu 2431: my $headrev = $curbranch || "1";
3.45 knu 2432: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
3.80 knu 2433:
3.1 knu 2434: foreach $rev (@revorder) {
3.80 knu 2435: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2436: $symrev{"HEAD"} = $rev;
2437: last;
2438: }
1.1 jfieber 2439: }
3.1 knu 2440: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
3.80 knu 2441: if (!defined($symrev{"HEAD"}));
1.1 jfieber 2442: print "Done finding HEAD\n" if ($verbose);
3.80 knu 2443:
2444: #
2445: # Now that we know all of the revision numbers, we can associate
2446: # absolute revision numbers with all of the symbolic names, and
2447: # pass them to the form so that the same association doesn't have
2448: # to be built then.
2449: #
3.1 knu 2450: undef @branchnames;
2451: undef %branchpoint;
2452: undef $sel;
2453:
2454: foreach (reverse sort keys %symrev) {
3.80 knu 2455: $rev = $symrev{$_};
2456: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
2457: push (@branchnames, $_);
2458:
2459: #
2460: # A revision number of A.B.0.D really translates into
2461: # "the highest current revision on branch A.B.D".
2462: #
2463: # If there is no branch A.B.D, then it translates into
2464: # the head A.B .
2465: #
2466: # This reasoning also applies to the main branch A.B,
2467: # with the branch number 0.A, with the exception that
2468: # it has no head to translate to if there is nothing on
2469: # the branch, but I guess this can never happen?
2470: #
2471: # (the code below gracefully forgets about the branch
2472: # if it should happen)
2473: #
2474: $head = defined($2) ? $2 : "";
2475: $branch = $3;
2476: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2477: my $regex;
2478: $regex = quotemeta $branchrev;
2479: $rev = $head;
2480:
2481: foreach my $r (@revorder) {
2482: if ($r =~ /^${regex}\b/) {
2483: $rev = $branchrev;
2484: last;
2485: }
2486: }
2487: next if ($rev eq "");
2488:
2489: if ($rev ne $head && $head ne "") {
2490: $branchpoint{$head} .= ", "
2491: if ($branchpoint{$head});
2492: $branchpoint{$head} .= $_;
2493: }
1.8 fenner 2494: }
3.80 knu 2495: $revsym{$rev} .= ", " if ($revsym{$rev});
2496: $revsym{$rev} .= $_;
3.89 knu 2497: $sel .= "<option value=\"${rev}:${_}\">$_</option>\n";
1.1 jfieber 2498: }
2499: print "Done associating revisions with branches\n" if ($verbose);
3.1 knu 2500:
2501: my ($onlyonbranch, $onlybranchpoint);
2502: if ($onlyonbranch = $input{'only_with_tag'}) {
3.80 knu 2503: $onlyonbranch = $symrev{$onlyonbranch};
2504: if ($onlyonbranch =~ s/\b0\.//) {
2505: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2506: } else {
2507: $onlybranchpoint = $onlyonbranch;
2508: }
2509:
2510: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2511: fatal("404 Tag not found",
3.103 knu 2512: 'Tag %s not defined',
2513: $input{'only_with_tag'});
3.80 knu 2514: }
1.8 fenner 2515: }
1.1 jfieber 2516:
3.1 knu 2517: undef @revisions;
2518:
2519: foreach (@allrevisions) {
3.80 knu 2520: ($br = $_) =~ s/\.\d+$//;
2521: ($brp = $br) =~ s/\.\d+$//;
2522: next
2523: if ($onlyonbranch && $br ne $onlyonbranch
2524: && $_ ne $onlybranchpoint);
2525: unshift (@revisions, $_);
3.1 knu 2526: }
2527:
2528: if ($logsort eq "date") {
3.80 knu 2529:
2530: # Sort the revisions in commit order an secondary sort on revision
2531: # (secondary sort needed for imported sources, or the first main
2532: # revision gets before the same revision on the 1.1.1 branch)
2533: @revdisplayorder =
2534: sort { $date{$b} <=> $date{$a} || -revcmp($a, $b) }
2535: @revisions;
2536: } elsif ($logsort eq "rev") {
2537:
2538: # Sort the revisions in revision order, highest first
2539: @revdisplayorder = reverse sort { revcmp($a, $b) } @revisions;
2540: } else {
2541:
2542: # No sorting. Present in the same order as rlog / cvs log
2543: @revdisplayorder = @revisions;
3.1 knu 2544: }
2545:
2546: }
2547:
3.37 knu 2548: sub printDiffLinks($$) {
3.80 knu 2549: my ($text, $url) = @_;
2550: my @extra;
3.37 knu 2551:
3.80 knu 2552: local $_;
2553: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2554: my $f = $_ eq $defaultDiffType ? '' : $_;
3.37 knu 2555:
3.80 knu 2556: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2557: }
3.37 knu 2558:
3.80 knu 2559: print &link($text, $url), ' (', join (', ', @extra), ')';
3.37 knu 2560: }
2561:
3.1 knu 2562: sub printLog($;$) {
2563: my ($link, $br, $brp);
3.80 knu 2564: ($_, $link) = @_;
2565: ($br = $_) =~ s/\.\d+$//;
3.1 knu 2566: ($brp = $br) =~ s/\.?\d+$//;
2567: my ($isDead, $prev);
2568:
2569: $link = 1 if (!defined($link));
2570: $isDead = ($state{$_} eq "dead");
2571:
3.100 knu 2572: print "<p>\n";
3.1 knu 2573: if ($link && !$isDead) {
3.80 knu 2574: my ($filename);
2575: ($filename = $where) =~ s/^.*\///;
2576: my ($fileurl) = urlencode($filename);
3.89 knu 2577: print "<a name=\"rev$_\"></a>";
3.80 knu 2578:
2579: if (defined($revsym{$_})) {
2580: foreach my $sym (split (", ", $revsym{$_})) {
3.89 knu 2581: print "<a name=\"$sym\"></a>";
3.80 knu 2582: }
3.1 knu 2583: }
3.80 knu 2584:
2585: if (defined($revsym{$br}) && $revsym{$br}
2586: && !defined($nameprinted{$br}))
2587: {
2588: foreach my $sym (split (", ", $revsym{$br})) {
3.89 knu 2589: print "<a name=\"$sym\"></a>";
3.80 knu 2590: }
2591: $nameprinted{$br} = 1;
1.4 fenner 2592: }
3.80 knu 2593: print "\n Revision ";
2594: &download_link($fileurl, $_, $_,
2595: $defaultViewable ? "text/x-cvsweb-markup" : undef);
2596:
2597: if ($defaultViewable) {
2598: print " / (";
2599: &download_link($fileurl, $_, "download", $mimetype);
2600: print ")";
2601: }
2602:
2603: if (not $defaultTextPlain) {
2604: print " / (";
2605: &download_link($fileurl, $_, "as text", "text/plain");
2606: print ")";
2607: }
2608:
2609: if (!$defaultViewable) {
2610: print " / (";
2611: &download_link($fileurl, $_, "view",
2612: "text/x-cvsweb-markup");
2613: print ")";
2614: }
2615:
2616: if ($allow_annotate) {
2617: print " - ";
2618: print &link(
2619: 'annotate',
2620: sprintf(
2621: '%s/%s?annotate=%s%s', $scriptname,
2622: urlencode($where), $_,
2623: $barequery
2624: )
2625: );
2626: }
2627:
2628: # Plus a select link if enabled, and this version isn't selected
2629: if ($allow_version_select) {
2630: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
2631: print " - ";
2632: print &link(
2633: '[select for diffs]',
2634: sprintf(
2635: '%s?r1=%s%s', $scriptwhere,
2636: $_, $barequery
2637: )
2638: );
2639: } else {
2640: print " - <b>[selected]</b>";
2641: }
3.1 knu 2642: }
3.80 knu 2643: } else {
3.89 knu 2644: print "Revision <b>$_</b>";
3.1 knu 2645: }
3.80 knu 2646:
3.1 knu 2647: if (/^1\.1\.1\.\d+$/) {
3.80 knu 2648: print " <i>(vendor branch)</i>";
3.1 knu 2649: }
2650: if (defined @mytz) {
3.80 knu 2651: my ($est) = $mytz[(localtime($date{$_}))[8]];
2652: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
3.1 knu 2653: } else {
3.80 knu 2654: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
3.1 knu 2655: }
3.80 knu 2656: print readableTime(time() - $date{$_}, 1), " ago)";
3.1 knu 2657: print " by ";
3.36 knu 2658: print "<i>", $author{$_}, "</i>\n";
3.89 knu 2659: print "<br>Branch: <b>", $link ? link_tags($revsym{$br}) : $revsym{$br},
3.80 knu 2660: "</b>\n"
3.1 knu 2661: if ($revsym{$br});
3.89 knu 2662: print "<br>CVS Tags: <b>", $link ? link_tags($revsym{$_}) : $revsym{$_},
3.80 knu 2663: "</b>"
3.1 knu 2664: if ($revsym{$_});
3.89 knu 2665: print "<br>Branch point for: <b>",
3.80 knu 2666: $link ? link_tags($branchpoint{$_}) : $branchpoint{$_}, "</b>\n"
3.1 knu 2667: if ($branchpoint{$_});
3.80 knu 2668:
3.1 knu 2669: # Find the previous revision
3.80 knu 2670: my @prevrev = split (/\./, $_);
3.1 knu 2671: do {
3.80 knu 2672: if (--$prevrev[$#prevrev] <= 0) {
2673:
2674: # If it was X.Y.Z.1, just make it X.Y
2675: pop (@prevrev);
2676: pop (@prevrev);
2677: }
2678: $prev = join (".", @prevrev);
3.1 knu 2679: } until (defined($date{$prev}) || $prev eq "");
3.80 knu 2680:
3.1 knu 2681: if ($prev ne "") {
3.80 knu 2682: if ($difflines{$_}) {
2683: print
3.89 knu 2684: "<br>Changes since <b>$prev: $difflines{$_} lines</b>";
3.80 knu 2685: }
3.1 knu 2686: }
3.80 knu 2687:
3.1 knu 2688: if ($isDead) {
3.89 knu 2689: print "<br><b><i>FILE REMOVED</i></b>\n";
3.80 knu 2690: } elsif ($link) {
2691: my %diffrev = ();
2692: $diffrev{$_} = 1;
2693: $diffrev{""} = 1;
3.96 knu 2694: print '<br>';
2695: my $diff = 'Diff';
3.80 knu 2696:
2697: #
2698: # Offer diff to previous revision
2699: if ($prev) {
2700: $diffrev{$prev} = 1;
2701:
2702: my $url =
2703: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere,
2704: $prev, $_, $barequery);
2705:
3.96 knu 2706: print $diff, " to previous ";
2707: $diff = '';
3.80 knu 2708: printDiffLinks($prev, $url);
2709: }
2710:
2711: #
2712: # Plus, if it's on a branch, and it's not a vendor branch,
2713: # offer a diff with the branch point.
2714: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/
2715: && !defined($diffrev{$brp}))
2716: {
2717: my $url =
2718: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere, $brp,
2719: $_, $barequery);
2720:
3.96 knu 2721: print $diff, " to branchpoint ";
2722: $diff = '';
3.80 knu 2723: printDiffLinks($brp, $url);
2724: }
2725:
2726: #
2727: # Plus, if it's on a branch, and it's not a vendor branch,
2728: # offer to diff with the next revision of the higher branch.
2729: # (e.g. change gets committed and then brought
2730: # over to -stable)
2731: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2732: my ($i, $nextmain);
2733:
2734: for ($i = 0 ; $i < $#revorder && $revorder[$i] ne $_ ;
2735: $i++)
2736: {
2737: }
2738: my @tmp2 = split (/\./, $_);
2739: for ($nextmain = "" ; $i > 0 ; $i--) {
2740: my $next = $revorder[$i - 1];
2741: my @tmp1 = split (/\./, $next);
2742:
2743: if (@tmp1 < @tmp2) {
2744: $nextmain = $next;
2745: last;
2746: }
2747:
2748: # Only the highest version on a branch should have
2749: # a diff for the "next main".
2750: last
2751: if (@tmp1 - 1 <= @tmp2
2752: && join (".", @tmp1[0 .. $#tmp1 - 1]) eq
2753: join (".", @tmp2[0 .. $#tmp1 - 1]));
2754: }
3.35 knu 2755:
3.80 knu 2756: if (!defined($diffrev{$nextmain})) {
2757: $diffrev{$nextmain} = 1;
3.35 knu 2758:
3.80 knu 2759: my $url =
2760: sprintf('%s.diff?r1=%s&r2=%s%s',
2761: $scriptwhere, $nextmain, $_,
2762: $barequery);
3.35 knu 2763:
3.96 knu 2764: print $diff, " next main ";
2765: $diff = '';
3.80 knu 2766: printDiffLinks($nextmain, $url);
2767: }
1.1 jfieber 2768: }
3.35 knu 2769:
3.80 knu 2770: # Plus if user has selected only r1, then present a link
2771: # to make a diff to that revision
2772: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2773: $diffrev{$input{"r1"}} = 1;
2774:
2775: my $url =
2776: sprintf('%s.diff?r1=%s&r2=%s%s', $scriptwhere,
2777: $input{'r1'}, $_, $barequery);
2778:
3.96 knu 2779: print $diff, " to selected ";
2780: $diff = '';
3.80 knu 2781: printDiffLinks($input{'r1'}, $url);
2782: }
3.96 knu 2783:
1.1 jfieber 2784: }
3.100 knu 2785: print "\n</p>\n<pre>\n";
3.101 knu 2786: print &htmlify($log{$_}, $allow_log_extra);
3.89 knu 2787: print "</pre>\n";
3.1 knu 2788: }
2789:
3.12 knu 2790: sub doLog($) {
3.80 knu 2791: my ($fullname) = @_;
3.1 knu 2792: my ($diffrev, $upwhere, $filename, $backurl);
3.12 knu 2793:
3.1 knu 2794: readLog($fullname);
2795:
3.80 knu 2796: html_header("CVS log for $where");
2797: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2798: ($filename = $where) =~ s|^.*/||;
2799: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
3.100 knu 2800: print "<p>\n ";
3.80 knu 2801: print &link($backicon, "$backurl#$filename"), " <b>Up to ",
3.100 knu 2802: &clickablePath($upwhere, 1), "</b>\n</p>\n";
2803: print "<p>\n ";
3.35 knu 2804: print &link('Request diff between arbitrary revisions', '#diff');
3.100 knu 2805: print "\n</p>\n<hr noshade>\n";
3.35 knu 2806:
3.100 knu 2807: print "<p>\n";
3.1 knu 2808: if ($curbranch) {
3.80 knu 2809: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
2810: } else {
2811: print "No default branch";
3.1 knu 2812: }
3.89 knu 2813: print "<br>\n";
3.80 knu 2814:
3.1 knu 2815: if ($input{only_with_tag}) {
3.89 knu 2816: print "Current tag: $input{only_with_tag}<br>\n";
3.1 knu 2817: }
3.100 knu 2818: print "</p>\n";
3.1 knu 2819:
2820: undef %nameprinted;
2821:
3.80 knu 2822: for (my $i = 0 ; $i <= $#revdisplayorder ; $i++) {
3.100 knu 2823: print "<hr size=\"1\" noshade>\n";
3.80 knu 2824: printLog($revdisplayorder[$i]);
3.1 knu 2825: }
2826:
3.100 knu 2827: print "<hr noshade>\n<p>\n";
3.89 knu 2828: print "<a name=\"diff\">\n";
1.1 jfieber 2829: print "This form allows you to request diff's between any two\n";
2830: print "revisions of a file. You may select a symbolic revision\n";
2831: print "name using the selection box or you may type in a numeric\n";
2832: print "name using the type-in text box.\n";
3.100 knu 2833: print "</a>\n</p>\n";
3.80 knu 2834: print
3.89 knu 2835: "<form method=\"get\" action=\"${scriptwhere}.diff\" name=\"diff_select\">\n";
3.80 knu 2836:
2837: foreach (@stickyvars) {
3.89 knu 2838: printf('<input type="hidden" name="%s" value="%s">', $_,
3.80 knu 2839: $input{$_})
2840: if (defined($input{$_})
3.23 knu 2841: && ((!defined($DEFAULTVALUE{$_})
3.80 knu 2842: || $input{$_} ne $DEFAULTVALUE{$_}) && $input{$_} ne ""));
3.1 knu 2843: }
3.100 knu 2844: print "<table style=\"border: none\">\n<tr>\n";
3.110 scop 2845: print "<td align=\"right\">";
2846: print "<label for=\"r1\" accesskey=\"1\">Diffs between </label>\n";
3.111 scop 2847: print "<select id=\"r1\" name=\"r1\">\n";
3.89 knu 2848: print "<option value=\"text\" selected>Use Text Field</option>\n";
1.1 jfieber 2849: print $sel;
3.89 knu 2850: print "</select>\n";
3.1 knu 2851: $diffrev = $revdisplayorder[$#revdisplayorder];
2852: $diffrev = $input{"r1"} if (defined($input{"r1"}));
3.80 knu 2853: print
3.110 scop 2854: "<input type=\"text\" size=\"$inputTextSize\" name=\"tr1\" value=\"$diffrev\" onchange=\"this.form.r1.selectedIndex=0\"></td>\n";
3.100 knu 2855: print "<td><br></td>\n</tr>\n";
3.110 scop 2856: print "<tr>\n<td align=\"right\">";
2857: print "<label for=\"r2\" accesskey=\"2\">and </label>\n";
3.111 scop 2858: print "<select id=\"r2\" name=\"r2\">\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[0];
2863: $diffrev = $input{"r2"} if (defined($input{"r2"}));
3.80 knu 2864: print
3.110 scop 2865: "<input type=\"text\" size=\"$inputTextSize\" name=\"tr2\" value=\"$diffrev\" onchange=\"this.form.r2.selectedIndex=0\"></td>\n";
2866: print "<td><input type=\"submit\" value=\" Get Diffs \" accesskey=\"G\"></td>\n";
3.100 knu 2867: print "</tr>\n</table>\n";
3.89 knu 2868: print "</form>\n";
2869: print "<hr noshade>\n";
2870: print "<form method=\"get\" action=\"$scriptwhere\">\n";
3.100 knu 2871: print "<table style=\"border: none\">\n";
3.110 scop 2872: print "<tr>\n<td align=\"right\">";
2873: print "<label for=\"f\" accesskey=\"D\">Preferred Diff type:";
2874: print "</label></td>\n";
3.89 knu 2875: print "<td>";
3.21 knu 2876: printDiffSelect($use_java_script);
3.100 knu 2877: print "</td>\n<td></td>\n</tr>\n";
3.80 knu 2878:
2879: if (@branchnames) {
3.110 scop 2880: print "<tr>\n<td align=\"right\">";
2881: print "<label for=\"only_with_tag\" accesskey=\"B\">";
2882: print "View only Branch:</label></td>\n";
3.89 knu 2883: print "<td>";
2884: print "<a name=\"branch\"></a>\n";
3.111 scop 2885: print "<select id=\"only_with_tag\" name=\"only_with_tag\"";
3.89 knu 2886: print " onchange=\"this.form.submit()\"" if $use_java_script;
3.80 knu 2887: print ">\n";
3.89 knu 2888: print "<option value=\"\"";
2889: print " selected"
3.80 knu 2890: if (defined($input{"only_with_tag"})
2891: && $input{"only_with_tag"} eq "");
3.89 knu 2892: print ">Show all branches</option>\n";
3.80 knu 2893:
2894: foreach (reverse sort @branchnames) {
3.89 knu 2895: print "<option";
2896: print " selected"
3.80 knu 2897: if (defined($input{"only_with_tag"})
2898: && $input{"only_with_tag"} eq $_);
3.89 knu 2899: print ">${_}</option>\n";
3.80 knu 2900: }
3.100 knu 2901: print "</select></td>\n<td></td>\n</tr>\n";
1.7 fenner 2902: }
3.80 knu 2903:
3.1 knu 2904: foreach (@stickyvars) {
3.80 knu 2905: next if ($_ eq "f");
2906: next if ($_ eq "only_with_tag");
2907: next if ($_ eq "logsort");
3.89 knu 2908: print "<input type=\"hidden\" name=\"$_\" value=\"$input{$_}\">\n"
3.80 knu 2909: if (defined($input{$_})
3.23 knu 2910: && (!defined($DEFAULTVALUE{$_})
3.80 knu 2911: || $input{$_} ne $DEFAULTVALUE{$_}) && $input{$_} ne "");
3.1 knu 2912: }
3.100 knu 2913: print "<tr>\n<td align=\"right\">";
3.89 knu 2914: print "<a name=\"logsort\"></a>\n";
3.110 scop 2915: print "<label for=\"logsort\" accesskey=\"L\">Sort log by:";
2916: print "</label></td>\n<td>";
3.37 knu 2917: printLogSortSelect($use_java_script);
3.100 knu 2918: print "</td>\n";
3.110 scop 2919: print "<td><input type=\"submit\" value=\" Set \" accesskey=\"S\"></td>\n";
3.100 knu 2920: print "</tr>\n</table>\n";
3.89 knu 2921: print "</form>\n";
3.100 knu 2922: html_footer();
1.10 wosch 2923: }
2924:
3.12 knu 2925: sub flush_diff_rows($$$$) {
3.80 knu 2926: my $j;
2927: my ($leftColRef, $rightColRef, $leftRow, $rightRow) = @_;
3.82 knu 2928:
2929: if (!defined($state)) {
2930: return;
2931: }
2932:
3.80 knu 2933: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2934: for ($j = 0 ; $j < $leftRow ; $j++) {
2935: print
3.100 knu 2936: "<tr>\n<td class=\"diff-removed\"> @$leftColRef[$j]</td>\n";
3.80 knu 2937: print
3.100 knu 2938: "<td class=\"diff-empty\"> </td>\n</tr>\n";
3.80 knu 2939: }
2940: } elsif ($state eq "PreChange") { # state eq "PreChange"
2941: # we got removes with subsequent adds
2942:
2943: for ($j = 0 ; $j < $leftRow || $j < $rightRow ; $j++)
2944: { # dump out both cols
3.100 knu 2945: print "<tr>\n";
3.80 knu 2946: if ($j < $leftRow) {
2947: print
3.100 knu 2948: "<td class=\"diff-changed\"> @$leftColRef[$j]</td>";
3.80 knu 2949: } else {
2950: print
3.100 knu 2951: "<td class=\"diff-changed-missing\"> </td>";
3.80 knu 2952: }
3.100 knu 2953: print "\n";
3.80 knu 2954:
2955: if ($j < $rightRow) {
2956: print
3.100 knu 2957: "<td class=\"diff-changed\"> @$rightColRef[$j]</td>";
3.80 knu 2958: } else {
2959: print
3.100 knu 2960: "<td class=\"diff-changed-missing\"> </td>";
3.80 knu 2961: }
3.100 knu 2962: print "\n</tr>\n";
3.80 knu 2963: }
2964: }
3.1 knu 2965: }
2966:
2967: ##
2968: # Function to generate Human readable diff-files
2969: # human_readable_diff(String revision_to_return_to);
2970: ##
3.80 knu 2971: sub human_readable_diff($) {
2972: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
2973: my ($fh, $rev) = @_;
2974: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2975: my (@rightCol, @leftCol);
2976:
2977: ($where_nd = $where) =~ s/.diff$//;
2978: ($filename = $where_nd) =~ s/^.*\///;
2979: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2980: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2981:
2982: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
2983:
2984: # Read header to pick up read revision and date, if possible
2985: while (<$fh>) {
2986: ($r1d, $r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2987: ($r2d, $r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2988: last if (/^\+\+\+ /);
2989: }
2990:
2991: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2992: $rev1 = $r1r;
2993: $date1 = $r1d;
2994: }
2995: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2996: $rev2 = $r2r;
2997: $date2 = $r2d;
2998: }
2999:
3000: print
3.100 knu 3001: "<h3 style=\"text-align: center\">Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
3002: # Using style=\"border: none\" here breaks NS 4.x badly...
3.89 knu 3003: "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n",
3.100 knu 3004: "<tr style=\"background-color: #ffffff\">\n", "<th width=\"50%\" valign=\"top\">",
3.80 knu 3005: "version $rev1";
3006: print ", $date1" if (defined($date1));
3007: print "<br>Tag: $sym1\n" if ($sym1);
3.89 knu 3008: print "</th>\n", "<th width=\"50%\" valign=\"top\">", "version $rev2";
3.80 knu 3009: print ", $date2" if (defined($date2));
3010: print "<br>Tag: $sym2\n" if ($sym1);
3011: print "</th>\n";
3012:
3013: my $leftRow = 0;
3014: my $rightRow = 0;
3015: my ($oldline, $newline, $funname, $diffcode, $rest);
3016:
3017: # Process diff text
3018:
3019: # prefetch several lines
3020: my @buf = head($fh);
3021:
3022: my %d = scan_directives(@buf);
3023:
3024: while (@buf || !eof($fh)) {
3025: $difftxt = @buf ? shift @buf : <$fh>;
3026:
3027: if ($difftxt =~ /^@@/) {
3028: ($oldline, $newline, $funname) =
3029: $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
3030: $funname = htmlquote($funname);
3.100 knu 3031: $funname =~ s/\s/ /go;
3.80 knu 3032: print
3.100 knu 3033: "<tr class=\"diff-heading\">\n<td width=\"50%\">";
3.80 knu 3034: print
3.100 knu 3035: "<table width=\"100%\" border=\"1\" cellpadding=\"5\">\n<tr>\n<td><b>Line $oldline</b>";
3.80 knu 3036: print
3.100 knu 3037: " <span style=\"font-size: smaller\">$funname</span></td>\n</tr>\n</table>";
3038: print "</td>\n<td width=\"50%\">";
3.80 knu 3039: print
3.100 knu 3040: "<table width=\"100%\" border=\"1\" cellpadding=\"5\">\n<tr>\n<td><b>Line $newline</b>";
3.80 knu 3041: print
3.100 knu 3042: " <span style=\"font-size: smaller\">$funname</span></td>\n</tr>\n</table>\n";
3.80 knu 3043: print "</td>\n";
3044: $state = "dump";
3045: $leftRow = 0;
3046: $rightRow = 0;
3047: } else {
3048: ($diffcode, $rest) = $difftxt =~ /^([-+ ])(.*)/;
3049: $_ = spacedHtmlText($rest, $d{'tabstop'});
3050:
3051: #########
3052: # little state machine to parse unified-diff output (Hen, zeller@think.de)
3053: # in order to get some nice 'ediff'-mode output
3054: # states:
3055: # "dump" - just dump the value
3056: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
3057: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
3058: ##########
3059:
3060: if ($diffcode eq '+') {
3061: if ($state eq "dump")
3062: { # 'change' never begins with '+': just dump out value
3063: print
3.100 knu 3064: "<tr>\n<td class=\"diff-empty\"> </td>\n<td class=\"diff-added\"> $_</td>\n</tr>\n";
3.80 knu 3065: } else { # we got minus before
3066: $state = "PreChange";
3067: $rightCol[$rightRow++] = $_;
3068: }
3069: } elsif ($diffcode eq '-') {
3070: $state = "PreChangeRemove";
3071: $leftCol[$leftRow++] = $_;
3072: } else { # empty diffcode
3073: flush_diff_rows \@leftCol, \@rightCol, $leftRow,
3074: $rightRow;
3.100 knu 3075: print "<tr>\n<td class=\"diff-same\"> $_</td>\n<td class=\"diff-same\"> $_</td>\n</tr>\n";
3.80 knu 3076: $state = "dump";
3077: $leftRow = 0;
3078: $rightRow = 0;
3079: }
3080: }
3081: }
3.89 knu 3082: close($fh);
3083:
3.80 knu 3084: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
3085:
3086: # state is empty if we didn't have any change
3087: if (!$state) {
3.100 knu 3088: print "<tr>\n<td colspan=\"2\"> </td>\n</tr>\n";
3089: print "<tr class=\"diff-empty\">\n";
3.80 knu 3090: print
3.100 knu 3091: "<td colspan=\"2\" align=\"center\"><b>- No viewable change -</b></td>\n</tr>\n";
3.80 knu 3092: }
3.100 knu 3093: print "</table>\n";
3.80 knu 3094:
3.100 knu 3095: print "<hr style=\"width: 100%\" noshade>\n";
3096: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3097: print "<table style=\"border: none\">\n<tr>\n<td>\n";
3.80 knu 3098:
3099: # print legend
3.100 knu 3100: print "<table border=\"1\">\n<tr>\n<td>";
3101: print "Legend:<br><table style=\"border: none\" cellspacing=\"0\" cellpadding=\"1\">\n";
3.80 knu 3102: print
3.100 knu 3103: "<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 3104: print
3.100 knu 3105: "<tr class=\"diff-changed\">\n<td align=\"center\" colspan=\"2\">changed lines</td>\n</tr>\n";
3.80 knu 3106: print
3.100 knu 3107: "<tr>\n<td class=\"diff-empty\"> </td>\n<td align=\"center\" class=\"diff-added\">Added in v.$rev2</td>\n</tr>\n";
3108: print "</table>\n</td>\n</tr>\n</table>\n</td>\n<td>";
3.80 knu 3109:
3110: # Print format selector
3111: foreach my $var (keys %input) {
3112: next if ($var eq "f");
3113: next
3114: if (defined($DEFAULTVALUE{$var})
3115: && $DEFAULTVALUE{$var} eq $input{$var});
3.89 knu 3116: print "<input type=\"hidden\" name=\"", urlencode($var),
3117: "\" value=\"", urlencode($input{$var}), "\">\n";
3.80 knu 3118: }
3119: printDiffSelect($use_java_script);
3.89 knu 3120: print "<input type=\"submit\" value=\"Show\">\n";
3.100 knu 3121: print "</td>\n";
3122:
3123: print "</tr>\n</table>\n";
3.89 knu 3124: print "</form>\n";
3.1 knu 3125: }
3126:
3.12 knu 3127: sub navigateHeader($$$$$) {
3.80 knu 3128: my ($swhere, $path, $filename, $rev, $title) = @_;
3129: $swhere = "" if ($swhere eq $scriptwhere);
3130: $swhere = './' . urlencode($filename) if ($swhere eq "");
3.64 knu 3131:
3.100 knu 3132: # TODO: this should be moved into external CSS file.
3133: my $css = '';
3134: if ($title eq 'diff') {
3135: $css = "
3136: <style type=\"text/css\">
3137: .diff-heading {
3138: background-color: $diffcolorHeading;
3139: }
3140: .diff-same {
3141: font-family: $difffontface;
3142: font-size: smaller;
3143: }
3144: .diff-empty {
3145: background-color: $diffcolorEmpty;
3146: }
3147: .diff-added {
3148: background-color: $diffcolorAdd;
3149: font-family: $difffontface;
3150: font-size: smaller;
3151: }
3152: .diff-removed {
3153: background-color: $diffcolorRemove;
3154: font-family: $difffontface;
3155: font-size: smaller;
3156: }
3157: .diff-changed {
3158: background-color: $diffcolorChange;
3159: font-family: $difffontface;
3160: font-size: smaller;
3161: }
3162: .diff-changed-missing {
3163: background-color: $diffcolorDarkChange;
3164: }
3165: </style>";
3166: }
3167:
3.80 knu 3168: print <<EOF;
3.100 knu 3169: $HTML_DOCTYPE
3.89 knu 3170: <html>
3171: <head>
3.100 knu 3172: <title>$path$filename - $title - $rev</title>$css
3.106 scop 3173: $HTML_META</head>
3.64 knu 3174: $body_tag_for_src
3.100 knu 3175: <table width="100%" style="border: none; background-color: $navigationHeaderColor" cellspacing="0" cellpadding="1">
3.89 knu 3176: <tr valign="bottom"><td>
3.64 knu 3177: EOF
3178:
3.80 knu 3179: print &link($backicon, "$swhere$query#rev$rev");
3180: print "<b>Return to ", &link($filename, "$swhere$query#rev$rev"),
3181: " CVS log";
3182: print "</b> $fileicon</td>";
3183:
3.89 knu 3184: print "<td align=\"right\">$diricon <b>Up to ",
3185: &clickablePath($path, 1),
3.80 knu 3186: "</b></td>";
3187: print "</tr></table>";
3.1 knu 3188: }
3189:
3.12 knu 3190: sub plural_write($$) {
3.80 knu 3191: my ($num, $text) = @_;
3192: if ($num != 1) {
3193: $text .= "s";
3194: }
3195:
3196: if ($num > 0) {
3197: return join (' ', $num, $text);
3198: } else {
3199: return "";
3200: }
3.1 knu 3201: }
3202:
3203: ##
3204: # print readable timestamp in terms of
3205: # '..time ago'
3206: # H. Zeller <zeller@think.de>
3207: ##
3.12 knu 3208: sub readableTime($$) {
3.80 knu 3209: my ($i, $break, $retval);
3210: my ($secs, $long) = @_;
3.1 knu 3211:
3.80 knu 3212: # this function works correct for time >= 2 seconds
3213: if ($secs < 2) {
3214: return "very little time";
3215: }
3216:
3217: my %desc = (
3218: 1, 'second', 60, 'minute', 3600, 'hour',
3219: 86400, 'day', 604800, 'week', 2628000, 'month',
3220: 31536000, 'year'
3221: );
3222: my @breaks = sort { $a <=> $b } keys %desc;
3223: $i = 0;
3.1 knu 3224:
3.80 knu 3225: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3226: $i++;
3227: }
3.1 knu 3228: $i--;
3.80 knu 3229: $break = $breaks[$i];
3230: $retval = plural_write(int($secs / $break), $desc{$break});
3231:
3232: if ($long == 1 && $i > 0) {
3233: my $rest = $secs % $break;
3234: $i--;
3235: $break = $breaks[$i];
3236: my $resttime = plural_write(int($rest / $break), $desc{$break});
3237: if ($resttime) {
3238: $retval .= ", $resttime";
3239: }
3.1 knu 3240: }
3241:
3.80 knu 3242: return $retval;
3.1 knu 3243: }
3244:
3245: ##
3246: # clickablePath(String pathname, boolean last_item_clickable)
3247: #
3248: # returns a html-ified path whereas each directory is a link for
3249: # faster navigation. last_item_clickable controls whether the
3250: # basename (last directory/file) is a link as well
3251: ##
3252: sub clickablePath($$) {
3.80 knu 3253: my ($pathname, $clickLast) = @_;
3254: my $retval = '';
3.12 knu 3255:
3.80 knu 3256: if ($pathname eq '/') {
3257:
3258: # this should never happen - chooseCVSRoot() is
3259: # intended to do this
3260: $retval = "[$cvstree]";
3261: } else {
3262: $retval .= ' ' . &link("[$cvstree]",
3263: sprintf('%s/%s#dirlist', $scriptname, $query));
3264: my $wherepath = '';
3265: my ($lastslash) = $pathname =~ m|/$|;
3266:
3267: foreach (split (/\//, $pathname)) {
3268: $retval .= " / ";
3269: $wherepath .= "/$_";
3270: my ($last) = "$wherepath/" eq "/$pathname"
3271: || $wherepath eq "/$pathname";
3272:
3273: if ($clickLast || !$last) {
3274: $retval .= &link($_,
3275: join ('', $scriptname,
3276: urlencode($wherepath),
3277: (!$last || $lastslash ? '/' : ''),
3278: $query,
3279: (!$last || $lastslash ? "#dirlist" : "")
3280: ));
3281: } else { # do not make a link to the current dir
3282: $retval .= $_;
3283: }
3284: }
3.1 knu 3285: }
3.80 knu 3286: return $retval;
3.1 knu 3287: }
3288:
3289: sub chooseCVSRoot() {
3.100 knu 3290:
3291: print "<form method=\"get\" action=\"${scriptwhere}\">\n";
3.80 knu 3292: if (2 <= @CVSROOT) {
3293: my ($k);
3294: foreach $k (keys %input) {
3.89 knu 3295: print "<input type=\"hidden\" name=\"$k\" value=\"$input{$k}\">\n"
3.80 knu 3296: if ($input{$k}) && ($k ne "cvsroot");
3297: }
3298:
3299: # Form-Elements look wierd in Netscape if the background
3300: # isn't gray and the form elements are not placed
3301: # within a table ...
3.100 knu 3302: print "<table style=\"border: none\">\n<tr>\n";
3.110 scop 3303: print "<td><label for=\"cvsroot\" accesskey=\"C\">CVS Root:</label></td>\n";
3.111 scop 3304: print "<td>\n<select id=\"cvsroot\" name=\"cvsroot\"";
3.89 knu 3305: print " onchange=\"this.form.submit()\"" if $use_java_script;
3.80 knu 3306: print ">\n";
3307:
3308: foreach $k (@CVSROOT) {
3309: print "<option value=\"$k\"";
3310: print " selected" if ($k eq $cvstree);
3.89 knu 3311: print ">",($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k),
3.80 knu 3312: "</option>\n";
3313: }
3.100 knu 3314: print "</select>\n</td>\n<td>";
3.80 knu 3315: } else {
3316:
3.100 knu 3317: # no choice -- but we need the form to select module/path,
3318: # at least for Netscape
3319: print "<p>\n";
3.80 knu 3320: print "CVS Root: <b>[$cvstree]</b>";
3.1 knu 3321: }
3.57 knu 3322:
3.117 scop 3323: print " <label for=\"mpath\" accesskey=\"M\">Module path or alias:";
3.110 scop 3324: print "</label>\n";
3.117 scop 3325: print "<input type=\"text\" id=\"mpath\" name=\"path\" value=\"\" size=\"15\">\n";
3326: print "<input type=\"submit\" value=\"Go\" accesskey=\"O\">";
3.80 knu 3327:
3328: if (2 <= @CVSROOT) {
3.100 knu 3329: print "</td>\n</tr>\n</table>";
3330: } else {
3331: print "</p>";
3.80 knu 3332: }
3.100 knu 3333: print "\n</form>";
3.1 knu 3334: }
3335:
3336: sub chooseMirror() {
3.80 knu 3337:
3338: # This code comes from the original BSD-cvsweb
3339: # and may not be useful for your site; If you don't
3.117 scop 3340: # set %MIRRORS this won't show up, anyway.
3341: scalar(%MIRRORS) or return;
3342:
3343: # Should perhaps exclude the current site somehow...
3344: print "\n<p>\nThis CVSweb is mirrored in\n";
3345:
3346: my @tmp = map(&link(htmlquote($_), $MIRRORS{$_}),
3347: sort keys %MIRRORS);
3348: my $tmp = pop(@tmp);
3349:
3350: if (scalar(@tmp)) {
3351: print join(', ', @tmp), ' and ';
3.1 knu 3352: }
3.117 scop 3353:
3354: print "$tmp.\n</p>\n";
3.1 knu 3355: }
3356:
3.12 knu 3357: sub fileSortCmp() {
3.80 knu 3358: my ($comp) = 0;
3359: my ($c, $d, $af, $bf);
3.1 knu 3360:
3.80 knu 3361: ($af = $a) =~ s/,v$//;
3362: ($bf = $b) =~ s/,v$//;
3363: my ($rev1, $date1, $log1, $author1, $filename1) = @{$fileinfo{$af}}
3364: if (defined($fileinfo{$af}));
3365: my ($rev2, $date2, $log2, $author2, $filename2) = @{$fileinfo{$bf}}
3366: if (defined($fileinfo{$bf}));
3367:
3368: if (defined($filename1) && defined($filename2) && $af eq $filename1
3369: && $bf eq $filename2)
3370: {
3371:
3372: # Two files
3373: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
3374: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
3375: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
3376: $comp = ($author1 cmp $author2)
3377: if ($byauthor && $author1 && $author2);
3378: }
3379:
3380: if ($comp == 0) {
3381:
3.113 scop 3382: # Directories first, then files under version control,
3383: # then other, "rogue" files.
3384: # Sort by filename if no other criteria available.
3385:
3386: my $ad = ((-d "$fullname/$a") ? 'D'
3387: : (defined($fileinfo{$af}) ? 'F' : 'R'));
3388: my $bd = ((-d "$fullname/$b") ? 'D'
3389: : (defined($fileinfo{$bf}) ? 'F' : 'R'));
3.80 knu 3390: ($c = $a) =~ s|.*/||;
3391: ($d = $b) =~ s|.*/||;
3392: $comp = ("$ad$c" cmp "$bd$d");
3393: }
3394: return $comp;
3.1 knu 3395: }
3396:
3397: # make A url for downloading
3.12 knu 3398: sub download_url($$;$) {
3.80 knu 3399: my ($url, $revision, $mimetype) = @_;
3.1 knu 3400:
3.80 knu 3401: $revision =~ s/\b0\.//;
3.1 knu 3402:
3.80 knu 3403: if (defined($checkoutMagic)
3404: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
3405: {
3406: my $path = $where;
3.84 knu 3407: $path =~ s|[^/]+$||;
3.80 knu 3408: $url = "$scriptname/$checkoutMagic/${path}$url";
3409: }
3410: $url .= "?rev=$revision";
3411: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.67 knu 3412:
3.80 knu 3413: $url;
3.1 knu 3414: }
3415:
3.12 knu 3416: # Presents a link to download the
3.1 knu 3417: # selected revision
3.12 knu 3418: sub download_link($$$;$) {
3.80 knu 3419: my ($url, $revision, $textlink, $mimetype) = @_;
3420: my ($fullurl) = download_url($url, $revision, $mimetype);
3.35 knu 3421:
3.80 knu 3422: $fullurl =~ s/:/sprintf("%%%02x", ord($&))/eg;
3.70 knu 3423:
3.89 knu 3424: printf '<a href="%s"', hrefquote("$fullurl$barequery");
3.35 knu 3425:
3.80 knu 3426: if ($open_extern_window
3427: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup"))
3428: {
3429: print ' target="cvs_checkout"';
3430:
3431: # we should have
3432: # 'if (document.cvswin==null) document.cvswin=window.open(...'
3433: # in order to allow the user to resize the window; otherwise
3434: # the user may resize the window, but on next checkout - zap -
3435: # its original (configured s. cvsweb.conf) size is back again
3436: # .. annoying (if $extern_window_(width|height) is defined)
3437: # but this if (..) solution is far from perfect
3438: # what we need to do as well is
3439: # 1) save cvswin in an invisible frame that always exists
3440: # (document.cvswin will be void on next load)
3441: # 2) on close of the cvs_checkout - window set the cvswin
3442: # variable to 'null' again - so that it will be
3443: # reopenend with the configured size
3444: # anyone a JavaScript programmer ?
3445: # .. so here without if (..):
3446: # currently, the best way is to comment out the size parameters
3447: # ($extern_window...) in cvsweb.conf.
3448: if ($use_java_script) {
3.117 scop 3449: my @attr = qw(resizable scrollbars);
3.80 knu 3450:
3451: push @attr, qw(status toolbar)
3452: if (defined($mimetype) && $mimetype eq "text/html");
3453:
3454: push @attr, "width=$extern_window_width"
3455: if (defined($extern_window_width));
3456:
3457: push @attr, "height=$extern_window_height"
3458: if (defined($extern_window_height));
3459:
3.89 knu 3460: # We need the "return false" here to prevent browsers
3461: # from following the href after the onclick handler.
3462: # This would effectively load the same document in
3463: # the same window *twice*.
3.80 knu 3464: printf
3.89 knu 3465: q` onclick="window.open('%s','cvs_checkout','%s');return false"`,
3.116 knu 3466: hrefquote("$fullurl$barequery"), join (',', @attr);
3.80 knu 3467: }
3.1 knu 3468: }
3.89 knu 3469: print "><b>$textlink</b></a>";
3.1 knu 3470: }
3471:
3472: # Returns a Query string with the
3473: # specified parameter toggled
3474: sub toggleQuery($$) {
3.80 knu 3475: my ($toggle, $value) = @_;
3476: my ($newquery, $var);
3477: my (%vars);
3478: %vars = %input;
3479:
3480: if (defined($value)) {
3481: $vars{$toggle} = $value;
3482: } else {
3483: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
3484: }
3485:
3486: # Build a new query of non-default paramenters
3487: $newquery = "";
3488: foreach $var (@stickyvars) {
3489: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3490: my ($default) =
3491: defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3492:
3493: if ($value ne $default) {
3494: $newquery .= "&" if ($newquery ne "");
3495: $newquery .= urlencode($var) . "=" . urlencode($value);
3496: }
3497: }
3498:
3499: if ($newquery) {
3500: return '?' . $newquery;
3501: }
3502: return "";
3.1 knu 3503: }
3504:
3.12 knu 3505: sub urlencode($) {
3.80 knu 3506: local ($_) = @_;
3.35 knu 3507:
3.80 knu 3508: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3.35 knu 3509:
3.80 knu 3510: $_;
3.35 knu 3511: }
3512:
3513: sub htmlquote($) {
3.80 knu 3514: local ($_) = @_;
3.35 knu 3515:
3.80 knu 3516: # Special Characters; RFC 1866
3517: s/&/&/g;
3518: s/\"/"/g;
3519: s/</</g;
3520: s/>/>/g;
3.35 knu 3521:
3.80 knu 3522: $_;
3.1 knu 3523: }
3524:
3.36 knu 3525: sub htmlunquote($) {
3.80 knu 3526: local ($_) = @_;
3.36 knu 3527:
3.80 knu 3528: # Special Characters; RFC 1866
3529: s/"/\"/g;
3530: s/</</g;
3531: s/>/>/g;
3532: s/&/&/g;
3.36 knu 3533:
3.80 knu 3534: $_;
3.36 knu 3535: }
3536:
3.46 knu 3537: sub hrefquote($) {
3.80 knu 3538: local ($_) = @_;
3.46 knu 3539:
3.80 knu 3540: y/ /+/;
3.46 knu 3541:
3.80 knu 3542: htmlquote($_)
3.46 knu 3543: }
3544:
3.12 knu 3545: sub http_header(;$) {
3.80 knu 3546: my $content_type = shift || "text/html";
3.50 knu 3547:
3.80 knu 3548: $content_type .= "; charset=$charset"
3549: if $content_type =~ m,^text/, && defined($charset) && $charset;
3550:
3551: if (defined($moddate)) {
3552: if ($is_mod_perl) {
3553: Apache->request->header_out(
3554: "Last-Modified" => scalar gmtime($moddate)
3555: . " GMT");
3556: } else {
3557: print "Last-Modified: ", scalar gmtime($moddate),
3558: " GMT\r\n";
3559: }
3560: }
3.50 knu 3561:
3.1 knu 3562: if ($is_mod_perl) {
3.80 knu 3563: Apache->request->content_type($content_type);
3564: } else {
3.89 knu 3565: print "Content-Type: $content_type\r\n";
3.1 knu 3566: }
3.80 knu 3567:
3568: if ($allow_compress && $maycompress) {
3569: if ($has_zlib
3570: || (defined($CMD{gzip}) && open(GZIP, "| $CMD{gzip} -1 -c"))
3571: )
3572: {
3573:
3574: if ($is_mod_perl) {
3575: Apache->request->content_encoding("x-gzip");
3576: Apache->request->header_out(
3577: Vary => "Accept-Encoding");
3578: Apache->request->send_http_header;
3579: } else {
3.89 knu 3580: print "Content-Encoding: x-gzip\r\n";
3.80 knu 3581: print "Vary: Accept-Encoding\r\n"
3582: ; #RFC 2068, 14.43
3583: print "\r\n"; # Close headers
3584: }
3585: $| = 1;
3586: $| = 0; # Flush header output
3587:
3588: if ($has_zlib) {
3589: tie *GZIP, __PACKAGE__, \*STDOUT;
3590: }
3591: select(GZIP);
3592: $gzip_open = 1;
3593:
3594: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
3595: } else {
3596: if ($is_mod_perl) {
3597: Apache->request->send_http_header;
3598: } else {
3599: print "\r\n"; # Close headers
3600: }
3601: print
3.100 knu 3602: "<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 3603: }
3604: } else {
3605:
3606: if ($is_mod_perl) {
3607: Apache->request->send_http_header;
3608: } else {
3609: print "\r\n"; # Close headers
3610: }
3.1 knu 3611: }
3612: }
3613:
3614: sub html_header($) {
3.80 knu 3615: my ($title) = @_;
3616: http_header("text/html");
3617: print <<EOH;
3.100 knu 3618: $HTML_DOCTYPE
3.1 knu 3619: <html>
3.40 knu 3620: <head>
3.1 knu 3621: <title>$title</title>
3.106 scop 3622: $HTML_META</head>
3.1 knu 3623: $body_tag
3624: $logo <h1 align="center">$title</h1>
3625: EOH
3626: }
3627:
3.12 knu 3628: sub html_footer() {
3.100 knu 3629: print "<hr noshade>\n<address>$address</address>\n</body>\n</html>\n";
3.1 knu 3630: }
3631:
3.12 knu 3632: sub link_tags($) {
3.80 knu 3633: my ($tags) = @_;
3634: my ($ret) = "";
3635: my ($fileurl, $filename);
3636:
3637: ($filename = $where) =~ s/^.*\///;
3638: $fileurl = './' . urlencode($filename);
3639:
3640: foreach my $sym (split (", ", $tags)) {
3641: $ret .= ",\n" if ($ret ne "");
3642: $ret .=
3643: &link($sym, $fileurl . toggleQuery('only_with_tag', $sym));
3644: }
3645: return "$ret\n";
3.1 knu 3646: }
3647:
3648: #
3.81 knu 3649: # See if a module is listed in the config file's @HideModules list.
3.1 knu 3650: #
3.12 knu 3651: sub forbidden_module($) {
3.80 knu 3652: my ($module) = @_;
3.81 knu 3653: local $_;
3.12 knu 3654:
3.81 knu 3655: for (@HideModules) {
3656: return 1 if $module =~ $_;
3.80 knu 3657: }
3.81 knu 3658: return 0;
3659: }
3.1 knu 3660:
3.81 knu 3661: sub forbidden_file($) {
3662: my ($path) = @_;
3663: $path = substr($path, length($cvsroot) + 1);
3664: local $_;
3665: for (@ForbiddenFiles) {
3666: return 1 if $path =~ $_;
3667: }
3.80 knu 3668: return 0;
3.25 knu 3669: }
3670:
3671: # Close the GZIP handle remove the tie.
3672:
3673: sub gzipclose {
3674: if ($gzip_open) {
3.80 knu 3675: select(STDOUT);
3676: close(GZIP);
3677: untie *GZIP;
3678: $gzip_open = 0;
3.25 knu 3679: }
3.23 knu 3680: }
3681:
3682: # implement a gzipped file handle via the Compress:Zlib compression
3683: # library.
3684:
3685: sub MAGIC1() { 0x1f }
3686: sub MAGIC2() { 0x8b }
3.80 knu 3687: sub OSCODE() { 3 }
3.23 knu 3688:
3689: sub TIEHANDLE {
3690: my ($class, $out) = @_;
3.80 knu 3691: my ($d) = Compress::Zlib::deflateInit(
3692: -Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3693: -WindowBits => -Compress::Zlib::MAX_WBITS()
3694: ) or return undef;
3.23 knu 3695: my ($o) = {
3696: handle => $out,
3.80 knu 3697: dh => $d,
3698: crc => 0,
3699: len => 0,
3.23 knu 3700: };
3.80 knu 3701: my ($header) =
3702: pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0, 0, 0,
3703: 0, 0, 0, OSCODE);
3.23 knu 3704: print {$o->{handle}} $header;
3705: return bless($o, $class);
3706: }
3707:
3708: sub PRINT {
3.80 knu 3709: my ($o) = shift;
3710: my ($buf) = join (defined $, ? $, : "", @_);
3.23 knu 3711: my ($len) = length($buf);
3712: my ($compressed, $status) = $o->{dh}->deflate($buf);
3713: print {$o->{handle}} $compressed if defined($compressed);
3714: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3715: $o->{len} += $len;
3716: return $len;
3717: }
3718:
3719: sub PRINTF {
3.80 knu 3720: my ($o) = shift;
3.23 knu 3721: my ($fmt) = shift;
3722: my ($buf) = sprintf($fmt, @_);
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 WRITE {
3732: my ($o, $buf, $len, $off) = @_;
3733: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3734: print {$o->{handle}} $compressed if defined($compressed);
3735: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3736: $o->{len} += $len;
3737: return $len;
3738: }
3739:
3740: sub CLOSE {
3741: my ($o) = @_;
3.80 knu 3742: return if !defined($o->{dh});
3.23 knu 3743: my ($buf) = $o->{dh}->flush();
3744: $buf .= pack("V V", $o->{crc}, $o->{len});
3745: print {$o->{handle}} $buf;
3746: undef $o->{dh};
3747: }
3748:
3749: sub DESTROY {
3750: my ($o) = @_;
3751: CLOSE($o);
1.1 jfieber 3752: }
CVSweb