Annotation of cvsweb/cvsweb.cgi, Revision 3.27
3.10 knu 1: #!/usr/bin/perl5 -ws
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.1 knu 6: # Bill Fenner <fenner@FreeBSD.org> (original work)
7: # extended by Henner Zeller <zeller@think.de>,
3.12 knu 8: # Henrik Nordstrom <hno@hem.passagen.se>
3.1 knu 9: # Ken Coar <coar@Apache.Org>
10: # Dick Balaska <dick@buckosoft.com>
11: # Akinori MUSHA <knu@FreeBSD.org>
3.23 knu 12: # Jens-Uwe Mager <jum@helios.de>
3.1 knu 13: #
14: # Based on:
15: # * Bill Fenners cvsweb.cgi revision 1.28 available from:
3.5 knu 16: # http://www.FreeBSD.org/cgi/cvsweb.cgi/www/en/cgi/cvsweb.cgi
1.1 jfieber 17: #
1.21 wosch 18: # Copyright (c) 1996-1998 Bill Fenner
3.1 knu 19: # (c) 1998-1999 Henner Zeller
20: # (c) 1999 Henrik Nordstrom
21: # (c) 2000 Akinori MUSHA
1.21 wosch 22: # All rights reserved.
23: #
24: # Redistribution and use in source and binary forms, with or without
25: # modification, are permitted provided that the following conditions
26: # are met:
27: # 1. Redistributions of source code must retain the above copyright
28: # notice, this list of conditions and the following disclaimer.
29: # 2. Redistributions in binary form must reproduce the above copyright
30: # notice, this list of conditions and the following disclaimer in the
31: # documentation and/or other materials provided with the distribution.
32: #
33: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
34: # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35: # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36: # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
37: # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38: # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39: # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41: # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42: # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
43: # SUCH DAMAGE.
44: #
3.25 knu 45: # $zId: cvsweb.cgi,v 1.103 2000/09/20 17:02:29 jumager Exp $
3.27 ! knu 46: # $Id: cvsweb.cgi,v 3.26 2000/09/22 11:13:17 knu Exp $
1.21 wosch 47: #
3.1 knu 48: ###
49:
50: use strict;
1.21 wosch 51:
3.1 knu 52: use vars qw (
53: $config $allow_version_select $verbose
54: %CVSROOT %CVSROOTdescr %MIRRORS %DEFAULTVALUE %ICONS %MTYPES
55: %alltags @tabcolors %fileinfo %tags @branchnames %nameprinted
56: %symrev %revsym @allrevisions %date %author @revdisplayorder
3.17 knu 57: @revisions %state %difflines %log %branchpoint @revorder
58: $prcgi @prcategories $prcategories $mancgi
3.1 knu 59: $checkoutMagic $doCheckout $scriptname $scriptwhere
3.3 knu 60: $where $pathinfo $Browser $nofilelinks $maycompress @stickyvars
61: %funcline_regexp $is_mod_perl
3.5 knu 62: $is_lynx $is_w3m $is_msie $is_mozilla3 $is_textbased
3.1 knu 63: %input $query $barequery $sortby $bydate $byrev $byauthor
64: $bylog $byfile $hr_default $logsort $cvstree $cvsroot
65: $mimetype $defaultTextPlain $defaultViewable $allow_compress
66: $GZIPBIN $backicon $diricon $fileicon $fullname $newname
3.26 knu 67: $cvstreedefault $body_tag $body_tag_for_src
68: $logo $defaulttitle $address
69: $long_intro $short_instruction $shortLogLen
3.1 knu 70: $show_author $dirtable $tablepadding $columnHeaderColorDefault
3.3 knu 71: $columnHeaderColorSorted $hr_breakable $showfunc $hr_ignwhite
3.1 knu 72: $hr_ignkeysubst $diffcolorHeading $diffcolorEmpty $diffcolorRemove
73: $diffcolorChange $diffcolorAdd $diffcolorDarkChange $difffontface
74: $difffontsize $inputTextSize $mime_types $allow_annotate
75: $allow_markup $use_java_script $open_extern_window
76: $extern_window_width $extern_window_height $edit_option_form
77: $checkout_magic $show_subdir_lastmod $show_log_in_markup $v
78: $navigationHeaderColor $tableBorderColor $markupLogColor
79: $tabstop $state $annTable $sel $curbranch @HideModules
80: $module $use_descriptions %descriptions @mytz $dwhere $moddate
3.23 knu 81: $use_moddate $has_zlib $gzip_open
3.1 knu 82: );
83:
3.12 knu 84: sub printDiffSelect($);
85: sub findLastModifiedSubdirs(@);
86: sub htmlify($;$);
3.20 knu 87: sub spacedHtmlText($;$);
3.12 knu 88: sub link($$);
89: sub revcmp($$);
90: sub fatal($$);
91: sub redirect($);
92: sub safeglob($);
93: sub getMimeTypeFromSuffix($);
3.24 knu 94: sub head($;$);
95: sub scan_directives(@);
3.12 knu 96: sub doAnnotate($$);
97: sub doCheckout($$);
98: sub cvswebMarkup($$$);
99: sub viewable($);
100: sub doDiff($$$$$$);
101: sub getDirLogs($$@);
102: sub readLog($;$);
103: sub printLog($;$);
104: sub doLog($);
105: sub flush_diff_rows($$$$);
106: sub human_readable_diff($);
107: sub navigateHeader($$$$$);
108: sub plural_write($$);
109: sub readableTime($$);
110: sub clickablePath($$);
111: sub chooseCVSRoot();
112: sub chooseMirror();
113: sub fileSortCmp();
114: sub download_url($$;$);
115: sub download_link($$$;$);
116: sub toggleQuery($$);
117: sub urlencode($);
118: sub http_header(;$);
119: sub html_header($);
120: sub html_footer();
121: sub link_tags($);
122: sub forbidden_module($);
123:
3.1 knu 124: ##### Start of Configuration Area ########
3.11 knu 125: use Cwd;
126:
3.12 knu 127: # == EDIT this ==
3.1 knu 128: # User configuration is stored in
3.11 knu 129: $config = undef;
130:
3.13 knu 131: for ($ENV{CVSWEB_CONFIG},
132: # '/home/knu/etc/cvsweb.conf',
133: '/usr/local/etc/cvsweb.conf',
134: getcwd . '/cvsweb.conf') {
3.12 knu 135: $config = $_ if defined($_) && -r $_;
3.11 knu 136: }
3.1 knu 137:
138: # == Configuration defaults ==
139: # Defaults for configuration variables that shouldn't need
140: # to be configured..
141: $allow_version_select = 1;
142:
143: ##### End of Configuration Area ########
144:
145: ######## Configuration variables #########
146: # These are defined to allow checking with perl -cw
147: %CVSROOT = %MIRRORS = %DEFAULTVALUE = %ICONS = %MTYPES =
148: %tags = %alltags = @tabcolors = ();
3.26 knu 149: $cvstreedefault = $body_tag = $body_tag_for_src =
150: $logo = $defaulttitle = $address =
151: $long_intro = $short_instruction = $shortLogLen =
3.1 knu 152: $show_author = $dirtable = $tablepadding = $columnHeaderColorDefault =
3.3 knu 153: $columnHeaderColorSorted = $hr_breakable = $showfunc = $hr_ignwhite =
3.1 knu 154: $hr_ignkeysubst = $diffcolorHeading = $diffcolorEmpty = $diffcolorRemove =
155: $diffcolorChange = $diffcolorAdd = $diffcolorDarkChange = $difffontface =
156: $difffontsize = $inputTextSize = $mime_types = $allow_annotate =
157: $allow_markup = $use_java_script = $open_extern_window =
158: $extern_window_width = $extern_window_height = $edit_option_form =
159: $checkout_magic = $show_subdir_lastmod = $show_log_in_markup = $v =
3.12 knu 160: $navigationHeaderColor = $tableBorderColor = $markupLogColor =
3.25 knu 161: $tabstop = $use_moddate = $moddate = $gzip_open = undef;
1.21 wosch 162:
3.1 knu 163: ##### End of configuration variables #####
164:
165: use Time::Local;
166: use IPC::Open2;
1.1 jfieber 167:
3.23 knu 168: # Check if the zlib C library interface is installed, and if yes
169: # we can avoid using the extra gzip process.
170: eval {
171: require Compress::Zlib;
172: };
173: $has_zlib = !$@;
174:
1.1 jfieber 175: $verbose = $v;
3.1 knu 176: $checkoutMagic = "~checkout~";
3.3 knu 177: $pathinfo = defined($ENV{PATH_INFO}) ? $ENV{PATH_INFO} : '';
178: $where = $pathinfo;
3.1 knu 179: $doCheckout = ($where =~ /^\/$checkoutMagic/);
180: $where =~ s|^/($checkoutMagic)?||;
181: $where =~ s|/+$||;
3.3 knu 182: $scriptname = defined($ENV{SCRIPT_NAME}) ? $ENV{SCRIPT_NAME} : '';
183: $scriptname =~ s|^/?|/|;
3.1 knu 184: $scriptname =~ s|/+$||;
3.3 knu 185: $scriptwhere = $scriptname;
3.1 knu 186: if ($where) {
3.3 knu 187: $scriptwhere .= '/' . urlencode($where);
3.1 knu 188: }
3.3 knu 189:
190: $is_mod_perl = defined($ENV{MOD_PERL});
3.1 knu 191:
192: # in lynx, it it very annoying to have two links
193: # per file, so disable the link at the icon
194: # in this case:
3.12 knu 195: $Browser = $ENV{HTTP_USER_AGENT};
3.5 knu 196: $is_lynx = ($Browser =~ m`^Lynx/`i);
197: $is_w3m = ($Browser =~ m`^w3m/`i);
3.3 knu 198: $is_msie = ($Browser =~ m`MSIE`);
3.5 knu 199: $is_mozilla3 = ($Browser =~ m`^Mozilla/[3-9]`);
3.3 knu 200:
3.5 knu 201: $is_textbased = ($is_lynx || $is_w3m);
202:
203: $nofilelinks = $is_textbased;
3.1 knu 204:
205: # newer browsers accept gzip content encoding
206: # and state this in a header
207: # (netscape did always but didn't state it)
208: # It has been reported that these
209: # braindamaged MS-Internet Exploders claim that they
210: # accept gzip .. but don't in fact and
211: # display garbage then :-/
3.23 knu 212: # Turn off gzip if running under mod_perl and no zlib is available,
213: # piping does not work as expected inside the server.
3.25 knu 214: $maycompress = (((defined($ENV{HTTP_ACCEPT_ENCODING})
215: && $ENV{HTTP_ACCEPT_ENCODING} =~ m`gzip`)
3.12 knu 216: || $is_mozilla3)
217: && !$is_msie
3.23 knu 218: && !($is_mod_perl && !$has_zlib));
3.1 knu 219:
220: # put here the variables we need in order
221: # to hold our state - they will be added (with
3.12 knu 222: # their current value) to any link/query string
3.1 knu 223: # you construct
3.6 knu 224: @stickyvars = qw(cvsroot hideattic sortby logsort f only_with_tag);
1.1 jfieber 225:
3.1 knu 226: if (-f $config) {
3.27 ! knu 227: do $config
! 228: || &fatal("500 Internal Error",
! 229: sprintf('Error in loading configuration file: %s<BR><BR>%s<BR>',
! 230: $config, &htmlify($@)));
! 231: } else {
3.1 knu 232: &fatal("500 Internal Error",
233: 'Configuration not found. Set the variable <code>$config</code> '
234: . 'in cvsweb.cgi, or the environment variable '
235: . '<code>CVSWEB_CONFIG</code>, to your <b>cvsweb.conf</b> '
236: . 'configuration file first.');
237: }
238:
239: undef %input;
3.3 knu 240: $query = $ENV{QUERY_STRING};
241:
3.12 knu 242: if (defined($query) && $query ne '') {
1.9 fenner 243: foreach (split(/&/, $query)) {
1.7 fenner 244: s/%(..)/sprintf("%c", hex($1))/ge; # unquote %-quoted
245: if (/(\S+)=(.*)/) {
3.1 knu 246: $input{$1} = $2 if ($2 ne "");
247: }
248: else {
1.7 fenner 249: $input{$_}++;
250: }
251: }
252: }
1.10 wosch 253:
3.12 knu 254: # For backwards compability, set only_with_tag to only_on_branch if set.
3.1 knu 255: $input{only_with_tag} = $input{only_on_branch}
256: if (defined($input{only_on_branch}));
1.10 wosch 257:
3.1 knu 258: $DEFAULTVALUE{'cvsroot'} = $cvstreedefault;
1.10 wosch 259:
3.1 knu 260: foreach (keys %DEFAULTVALUE)
261: {
262: # replace not given parameters with the default parameters
263: if (!defined($input{$_}) || $input{$_} eq "") {
264: # Empty Checkboxes in forms return -- nothing. So we define a helper
265: # variable in these forms (copt) which indicates that we just set
266: # parameters with a checkbox
267: if (!defined($input{"copt"})) {
268: # 'copt' isn't defined --> empty input is not the result
269: # of empty input checkbox --> set default
270: $input{$_} = $DEFAULTVALUE{$_} if (defined($DEFAULTVALUE{$_}));
271: }
272: else {
273: # 'copt' is defined -> the result of empty input checkbox
274: # -> set to zero (disable) if default is a boolean (0|1).
275: $input{$_} = 0
276: if (defined($DEFAULTVALUE{$_})
277: && ($DEFAULTVALUE{$_} eq "0" || $DEFAULTVALUE{$_} eq "1"));
278: }
1.10 wosch 279: }
280: }
3.12 knu 281:
3.1 knu 282: $barequery = "";
283: foreach (@stickyvars) {
284: # construct a query string with the sticky non default parameters set
3.12 knu 285: if (defined($input{$_}) && $input{$_} ne '' &&
3.4 knu 286: !(defined($DEFAULTVALUE{$_}) && $input{$_} eq $DEFAULTVALUE{$_})) {
287: if ($barequery) {
3.1 knu 288: $barequery = $barequery . "&";
289: }
290: my $thisval = urlencode($_) . "=" . urlencode($input{$_});
291: $barequery .= $thisval;
292: }
293: }
294: # is there any query ?
295: if ($barequery) {
296: $query = "?$barequery";
297: $barequery = "&" . $barequery;
298: }
299: else {
300: $query = "";
301: }
302:
303: # get actual parameters
304: $sortby = $input{"sortby"};
305: $bydate = 0;
306: $byrev = 0;
307: $byauthor = 0;
308: $bylog = 0;
309: $byfile = 0;
310: if ($sortby eq "date") {
311: $bydate = 1;
312: }
313: elsif ($sortby eq "rev") {
314: $byrev = 1;
315: }
316: elsif ($sortby eq "author") {
317: $byauthor = 1;
318: }
319: elsif ($sortby eq "log") {
320: $bylog = 1;
321: }
322: else {
323: $byfile = 1;
324: }
325:
326: $hr_default = $input{'f'} eq 'h';
327:
3.3 knu 328: $logsort = $input{'logsort'};
1.10 wosch 329:
1.12 fenner 330:
3.1 knu 331: ## Default CVS-Tree
332: if (!defined($CVSROOT{$cvstreedefault})) {
333: &fatal("500 Internal Error",
334: "<code>\$cvstreedefault</code> points to a repository "
335: . "not defined in <code>%CVSROOT</code> "
336: . "(edit your configuration file $config)");
337: }
338:
339: # alternate CVS-Tree, configured in cvsweb.conf
340: if ($input{'cvsroot'} && $CVSROOT{$input{'cvsroot'}}) {
341: $cvstree = $input{'cvsroot'};
342: } else {
343: $cvstree = $cvstreedefault;
1.10 wosch 344: }
345:
3.1 knu 346: $cvsroot = $CVSROOT{$cvstree};
1.10 wosch 347:
3.1 knu 348: # create icons out of description
349: foreach my $k (keys %ICONS) {
350: no strict 'refs';
351: my ($itxt,$ipath,$iwidth,$iheight) = @{$ICONS{$k}};
352: if ($ipath) {
3.3 knu 353: ${"${k}icon"} = "<IMG SRC=\"$ipath\" ALT=\"$itxt\" BORDER=\"0\" WIDTH=\"$iwidth\" HEIGHT=\"$iheight\">";
1.16 wosch 354: }
3.1 knu 355: else {
3.3 knu 356: ${"${k}icon"} = $itxt;
1.24 wosch 357: }
358: }
359:
3.27 ! knu 360: my $config_cvstree = "$config-$cvstree";
! 361:
3.1 knu 362: # Do some special configuration for cvstrees
3.27 ! knu 363: if (-f $config_cvstree) {
! 364: do $config_cvstree
! 365: || &fatal("500 Internal Error",
! 366: sprintf('Error in loading configuration file: %s<BR><BR>%s<BR>',
! 367: $config_cvstree, &htmlify($@)));
! 368: }
3.1 knu 369:
370: $prcategories = '(?:' . join('|', @prcategories) . ')';
3.17 knu 371: $prcgi .= '%s' if defined($prcgi) && $prcgi !~ /%s/;
1.24 wosch 372:
3.1 knu 373: $fullname = $cvsroot . '/' . $where;
374: $mimetype = &getMimeTypeFromSuffix ($fullname);
375: $defaultTextPlain = ($mimetype eq "text/plain");
376: $defaultViewable = $allow_markup && viewable($mimetype);
377:
378: # search for GZIP if compression allowed
379: # We've to find out if the GZIP-binary exists .. otherwise
380: # ge get an Internal Server Error if we try to pipe the
3.12 knu 381: # output through the nonexistent gzip ..
3.1 knu 382: # any more elegant ways to prevent this are welcome!
3.23 knu 383: if ($allow_compress && $maycompress && !$has_zlib) {
3.1 knu 384: foreach (split(/:/, $ENV{PATH})) {
385: if (-x "$_/gzip") {
386: $GZIPBIN = "$_/gzip";
387: last;
1.16 wosch 388: }
389: }
390: }
391:
3.1 knu 392: if (-d $fullname) {
393: #
394: # ensure, that directories always end with (exactly) one '/'
395: # to allow relative URL's. If they're not, make a redirect.
396: ##
397: if (!($pathinfo =~ m|/$|) || ($pathinfo =~ m |/{2,}$|)) {
398: redirect ($scriptwhere . '/' . $query);
399: }
400: else {
401: $where .= '/';
402: $scriptwhere .= '/';
403: }
404: }
405:
406: if (!-d $cvsroot) {
407: &fatal("500 Internal Error",'$CVSROOT not found!<P>The server on which the CVS tree lives is probably down. Please try again in a few minutes.');
408: }
409:
410: #
411: # See if the module is in our forbidden list.
412: #
413: $where =~ m:([^/]*):;
414: $module = $1;
415: if ($module && &forbidden_module($module)) {
416: &fatal("403 Forbidden", "Access to $where forbidden.");
417: }
418: ##############################
419: # View a directory
420: ###############################
421: elsif (-d $fullname) {
422: my $dh = do {local(*DH);};
423: opendir($dh, $fullname) || &fatal("404 Not Found","$where: $!");
424: my @dir = readdir($dh);
425: closedir($dh);
426: my @subLevelFiles = findLastModifiedSubdirs(@dir)
427: if ($show_subdir_lastmod);
428: getDirLogs($cvsroot,$where,@subLevelFiles);
429:
430: if ($where eq '/') {
3.3 knu 431: html_header($defaulttitle);
3.2 knu 432: $long_intro =~ s/!!CVSROOTdescr!!/$CVSROOTdescr{$cvstree}/g;
3.1 knu 433: print $long_intro;
434: }
435: else {
3.3 knu 436: html_header($where);
3.1 knu 437: print $short_instruction;
438: }
439:
440: my $descriptions;
441: if (($use_descriptions) && open (DESC, "<$cvsroot/CVSROOT/descriptions")) {
442: while (<DESC>) {
443: chomp;
444: my ($dir,$description) = /(\S+)\s+(.*)/;
445: $descriptions{$dir} = $description;
446: }
447: }
448:
449: print "<P><a name=\"dirlist\"></a>\n";
450: # give direct access to dirs
451: if ($where eq '/') {
452: chooseMirror();
453: chooseCVSRoot();
454: }
455: else {
456: print "<p>Current directory: <b>", &clickablePath($where,0), "</b>\n";
457:
458: print "<P>Current tag: <B>", $input{only_with_tag}, "</b>\n" if
459: $input{only_with_tag};
1.16 wosch 460:
1.1 jfieber 461: }
3.12 knu 462:
3.1 knu 463:
464: print "<HR NOSHADE>\n";
1.1 jfieber 465: # Using <MENU> in this manner violates the HTML2.0 spec but
466: # provides the results that I want in most browsers. Another
467: # case of layout spooging up HTML.
3.12 knu 468:
3.1 knu 469: my $infocols = 0;
470: if ($dirtable) {
471: if (defined($tableBorderColor)) {
472: # Can't this be done by defining the border for the inner table?
473: print "<table border=0 cellpadding=0 width=\"100%\"><tr><td bgcolor=\"$tableBorderColor\">";
474: }
475: print "<table width=\"100%\" border=0 cellspacing=1 cellpadding=$tablepadding>\n";
476: $infocols++;
3.12 knu 477: print "<tr><th align=left bgcolor=\"" . (($byfile) ?
478: $columnHeaderColorSorted :
3.1 knu 479: $columnHeaderColorDefault) . "\">";
480: print "<a href=\"./" . &toggleQuery("sortby","file") .
481: "#dirlist\">" if (!$byfile);
482: print "File";
483: print "</a>" if (!$byfile);
484: print "</th>";
485: # do not display the other column-headers, if we do not have any files
486: # with revision information:
487: if (scalar(%fileinfo)) {
488: $infocols++;
3.12 knu 489: print "<th align=left bgcolor=\"" . (($byrev) ?
490: $columnHeaderColorSorted :
3.1 knu 491: $columnHeaderColorDefault) . "\">";
492: print "<a href=\"./" . &toggleQuery ("sortby","rev") .
493: "#dirlist\">" if (!$byrev);
494: print "Rev.";
495: print "</a>" if (!$byrev);
496: print "</th>";
497: $infocols++;
3.12 knu 498: print "<th align=left bgcolor=\"" . (($bydate) ?
499: $columnHeaderColorSorted :
3.1 knu 500: $columnHeaderColorDefault) . "\">";
501: print "<a href=\"./" . &toggleQuery ("sortby","date") .
502: "#dirlist\">" if (!$bydate);
503: print "Age";
504: print "</a>" if (!$bydate);
505: print "</th>";
506: if ($show_author) {
507: $infocols++;
3.12 knu 508: print "<th align=left bgcolor=\"" . (($byauthor) ?
509: $columnHeaderColorSorted :
3.1 knu 510: $columnHeaderColorDefault) . "\">";
511: print "<a href=\"./" . &toggleQuery ("sortby","author") .
512: "#dirlist\">" if (!$byauthor);
513: print "Author";
514: print "</a>" if (!$byauthor);
515: print "</th>";
516: }
517: $infocols++;
3.12 knu 518: print "<th align=left bgcolor=\"" . (($bylog) ?
519: $columnHeaderColorSorted :
3.1 knu 520: $columnHeaderColorDefault) . "\">";
521: print "<a href=\"./", toggleQuery("sortby","log"), "#dirlist\">" if (!$bylog);
522: print "Last log entry";
523: print "</a>" if (!$bylog);
524: print "</th>";
525: }
526: elsif ($use_descriptions) {
527: print "<th align=left bgcolor=\"". $columnHeaderColorDefault . "\">";
528: print "Description";
529: $infocols++;
530: }
531: print "</tr>\n";
532: }
533: else {
534: print "<menu>\n";
535: }
536: my $dirrow = 0;
3.12 knu 537:
3.1 knu 538: my $i;
1.9 fenner 539: lookingforattic:
540: for ($i = 0; $i <= $#dir; $i++) {
541: if ($dir[$i] eq "Attic") {
3.1 knu 542: last lookingforattic;
1.9 fenner 543: }
544: }
3.1 knu 545: if (!$input{'hideattic'} && ($i <= $#dir) &&
546: opendir($dh, $fullname . "/Attic")) {
547: splice(@dir, $i, 1,
548: grep((s|^|Attic/|,!m|/\.|), readdir($dh)));
549: closedir($dh);
1.9 fenner 550: }
3.1 knu 551:
3.12 knu 552: my $hideAtticToggleLink = "<a href=\"./" .
3.1 knu 553: &toggleQuery ("hideattic") .
554: "#dirlist\">[Hide]</a>" if (!$input{'hideattic'});
555:
1.9 fenner 556: # Sort without the Attic/ pathname.
3.1 knu 557: # place directories first
558:
559: my $attic;
560: my $url;
561: my $fileurl;
562: my $filesexists;
563: my $filesfound;
564:
565: foreach (sort { &fileSortCmp } @dir) {
1.1 jfieber 566: if ($_ eq '.') {
567: next;
568: }
1.19 wosch 569: # ignore CVS lock and stale NFS files
3.1 knu 570: next if (/^#cvs\.|^,|^\.nfs/);
571:
572: # Check whether to show the CVSROOT path
573: next if ($input{'hidecvsroot'} && ($_ eq 'CVSROOT'));
574:
575: # Check whether the module is in the restricted list
576: next if ($_ && &forbidden_module($_));
577:
578: # Ignore non-readable files
579: next if ($input{'hidenonreadable'} && !(-r "$fullname/$_"));
1.18 wosch 580:
1.9 fenner 581: if (s|^Attic/||) {
3.1 knu 582: $attic = " (in the Attic) " . $hideAtticToggleLink;
583: }
584: else {
1.9 fenner 585: $attic = "";
586: }
3.1 knu 587:
588: if ($_ eq '..' || -d "$fullname/$_") {
589: next if ($_ eq '..' && $where eq '/');
590: my ($rev,$date,$log,$author,$filename) = @{$fileinfo{$_}}
591: if (defined($fileinfo{$_}));
592: print "<tr bgcolor=\"" . @tabcolors[$dirrow%2] . "\"><td>" if ($dirtable);
593: if ($_ eq '..') {
594: $url = "../" . $query;
595: if ($nofilelinks) {
596: print $backicon;
597: }
598: else {
599: print &link($backicon,$url);
600: }
601: print " ", &link("Previous Directory",$url);
602: }
603: else {
604: $url = urlencode($_) . '/' . $query;
605: print "<A NAME=\"$_\"></A>";
606: if ($nofilelinks) {
607: print $diricon;
608: }
609: else {
610: print &link($diricon,$url);
611: }
612: print " ", &link($_ . "/", $url), $attic;
613: if ($_ eq "Attic") {
3.12 knu 614: print " <a href=\"./" .
3.1 knu 615: &toggleQuery ("hideattic") .
616: "#dirlist\">[Don't hide]</a>";
617: }
3.12 knu 618: }
3.1 knu 619: # Show last change in dir
620: if ($filename) {
621: print "</td><td> </td><td> " if ($dirtable);
622: if ($date) {
623: print " <i>" . readableTime(time() - $date,0) . "</i>";
624: }
625: if ($show_author) {
626: print "</td><td> " if ($dirtable);
627: print $author;
628: }
629: print "</td><td> " if ($dirtable);
630: $filename =~ s%^[^/]+/%%;
631: print "$filename/$rev";
632: print "<BR>" if ($dirtable);
633: if ($log) {
634: print " <font size=-1>"
635: . &htmlify(substr($log,0,$shortLogLen));
636: if (length $log > 80) {
637: print "...";
638: }
639: print "</font>";
640: }
641: }
642: else {
643: my ($dwhere) = ($where ne "/" ? $where : "") . $_;
644: if ($use_descriptions && defined $descriptions{$dwhere}) {
645: print "<TD COLSPAN=" . ($infocols-1) . "> " if $dirtable;
646: print $descriptions{$dwhere};
647: } elsif ($dirtable && $infocols > 1) {
648: # close the row with the appropriate number of
649: # columns, so that the vertical seperators are visible
650: my($cols) = $infocols;
651: while ($cols > 1) {
652: print "</td><td> ";
653: $cols--;
654: }
655: }
656: }
657: if ($dirtable) {
658: print "</td></tr>\n";
659: }
660: else {
661: print "<br>\n";
662: }
663: $dirrow++;
1.9 fenner 664: }
3.1 knu 665: elsif (s/,v$//) {
666: $fileurl = ($attic ? "Attic/" : "") . urlencode($_);
667: $url = $fileurl . $query;
668: my $rev = '';
669: my $date = '';
670: my $log = '';
671: my $author = '';
672: $filesexists++;
673: next if (!defined($fileinfo{$_}));
674: ($rev,$date,$log,$author) = @{$fileinfo{$_}};
675: $filesfound++;
676: print "<tr bgcolor=\"" . @tabcolors[$dirrow%2] . "\"><td>" if ($dirtable);
677: print "<A NAME=\"$_\"></A>";
678: if ($nofilelinks) {
679: print $fileicon;
680: }
681: else {
682: print &link($fileicon,$url);
683: }
684: print " ", &link($_, $url), $attic;
685: print "</td><td> " if ($dirtable);
686: download_link($fileurl,
3.12 knu 687: $rev, $rev,
3.1 knu 688: $defaultViewable ? "text/x-cvsweb-markup" : undef);
689: print "</td><td> " if ($dirtable);
690: if ($date) {
691: print " <i>" . readableTime(time() - $date,0) . "</i>";
692: }
693: if ($show_author) {
694: print "</td><td> " if ($dirtable);
695: print $author;
696: }
697: print "</td><td> " if ($dirtable);
698: if ($log) {
699: print " <font size=-1>" . &htmlify(substr($log,0,$shortLogLen));
700: if (length $log > 80) {
701: print "...";
702: }
703: print "</font>";
704: }
705: print "</td>" if ($dirtable);
706: print (($dirtable) ? "</tr>" : "<br>");
707: $dirrow++;
708: }
709: print "\n";
710: }
711: if ($dirtable && defined($tableBorderColor)) {
712: print "</td></tr></table>";
713: }
714: print "". ($dirtable == 1) ? "</table>" : "</menu>" . "\n";
3.12 knu 715:
3.1 knu 716: if ($filesexists && !$filesfound) {
717: print "<P><B>NOTE:</B> There are $filesexists files, but none matches the current tag ($input{only_with_tag})\n";
718: }
719: if ($input{only_with_tag} && (!%tags || !$tags{$input{only_with_tag}})) {
720: %tags = %alltags
721: }
3.12 knu 722: if (scalar %tags
723: || $input{only_with_tag}
3.1 knu 724: || $edit_option_form
725: || defined($input{"options"})) {
726: print "<hr size=1 NOSHADE>";
727: }
728:
729: if (scalar %tags || $input{only_with_tag}) {
730: print "<FORM METHOD=\"GET\" ACTION=\"./\">\n";
731: foreach my $var (@stickyvars) {
732: print "<INPUT TYPE=HIDDEN NAME=\"$var\" VALUE=\"$input{$var}\">\n"
733: if (defined($input{$var})
3.23 knu 734: && (!defined($DEFAULTVALUE{$var})
735: || $input{$var} ne $DEFAULTVALUE{$var})
3.1 knu 736: && $input{$var} ne ""
737: && $var ne "only_with_tag");
738: }
739: print "Show only files with tag:\n";
740: print "<SELECT NAME=only_with_tag";
741: print " onchange=\"submit()\"" if ($use_java_script);
742: print ">";
743: print "<OPTION VALUE=\"\">All tags / default branch\n";
744: foreach my $tag (reverse sort { lc $a cmp lc $b } keys %tags) {
3.12 knu 745: print "<OPTION",defined($input{only_with_tag}) &&
3.13 knu 746: $input{only_with_tag} eq $tag ? " SELECTED" : "",
3.1 knu 747: ">$tag\n";
748: }
749: print "</SELECT>\n";
750: print "<INPUT TYPE=SUBMIT VALUE=\"Go\">\n";
1.9 fenner 751: print "</FORM>\n";
752: }
3.1 knu 753: my $formwhere = $scriptwhere;
754: $formwhere =~ s|Attic/?$|| if ($input{'hideattic'});
755:
756: if ($edit_option_form || defined($input{"options"})) {
757: print "<FORM METHOD=\"GET\" ACTION=\"${formwhere}\">\n";
758: print "<INPUT TYPE=HIDDEN NAME=\"copt\" VALUE=\"1\">\n";
759: if ($cvstree ne $cvstreedefault) {
760: print "<INPUT TYPE=HIDDEN NAME=\"cvsroot\" VALUE=\"$cvstree\">\n";
761: }
762: print "<center><table cellpadding=0 cellspacing=0>";
763: print "<tr bgcolor=\"$columnHeaderColorDefault\"><th colspan=2>Preferences</th></tr>";
764: print "<tr><td>Sort files by <SELECT name=\"sortby\">";
765: print "<OPTION VALUE=\"\">File";
766: print "<OPTION",$bydate ? " SELECTED" : ""," VALUE=date>Age";
767: print "<OPTION",$byauthor ? " SELECTED" : ""," VALUE=author>Author"
768: if ($show_author);
769: print "<OPTION",$byrev ? " SELECTED" : ""," VALUE=rev>Revision";
770: print "<OPTION",$bylog ? " SELECTED" : ""," VALUE=log>Log message";
771: print "</SELECT></td>";
772: print "<td>revisions by: \n";
773: print "<SELECT NAME=logsort>\n";
774: print "<OPTION VALUE=cvs",$logsort eq "cvs" ? " SELECTED" : "", ">Not sorted";
775: print "<OPTION VALUE=date",$logsort eq "date" ? " SELECTED" : "", ">Commit date";
776: print "<OPTION VALUE=rev",$logsort eq "rev" ? " SELECTED" : "", ">Revision";
777: print "</SELECT></td></tr>";
778: print "<tr><td>Diff format: ";
3.12 knu 779: printDiffSelect(0);
3.1 knu 780: print "</td>";
781: print "<td>Show Attic files: ";
3.13 knu 782: print "<INPUT NAME=hideattic TYPE=CHECKBOX", $input{'hideattic'} ? " CHECKED" : "",
3.1 knu 783: "></td></tr>\n";
784: print "<tr><td align=center colspan=2><input type=submit value=\"Change Options\">";
785: print "</td></tr></table></center></FORM>\n";
1.12 fenner 786: }
1.2 jfieber 787: print &html_footer;
1.1 jfieber 788: print "</BODY></HTML>\n";
3.12 knu 789: }
3.1 knu 790:
791: ###############################
792: # View Files
793: ###############################
794: elsif (-f $fullname . ',v') {
795: if (defined($input{'rev'}) || $doCheckout) {
796: &doCheckout($fullname, $input{'rev'});
3.25 knu 797: gzipclose();
3.1 knu 798: exit;
799: }
800: if (defined($input{'annotate'}) && $allow_annotate) {
801: &doAnnotate($input{'annotate'});
3.25 knu 802: gzipclose();
3.1 knu 803: exit;
804: }
805: if (defined($input{'r1'}) && defined($input{'r2'})) {
806: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
807: $input{'r2'}, $input{'tr2'}, $input{'f'});
3.25 knu 808: gzipclose();
3.1 knu 809: exit;
810: }
811: print("going to dolog($fullname)\n") if ($verbose);
812: &doLog($fullname);
813: ##############################
814: # View Diff
815: ##############################
816: }
817: elsif ($fullname =~ s/\.diff$// && -f $fullname . ",v" &&
818: $input{'r1'} && $input{'r2'}) {
819:
820: # $where-diff-removal if 'cvs rdiff' is used
821: # .. but 'cvs rdiff'doesn't support some options
822: # rcsdiff does (-w and -p), so it is disabled
823: # $where =~ s/\.diff$//;
824:
1.12 fenner 825: # Allow diffs using the ".diff" extension
826: # so that browsers that default to the URL
827: # for a save filename don't save diff's as
828: # e.g. foo.c
3.1 knu 829: &doDiff($fullname, $input{'r1'}, $input{'tr1'},
1.12 fenner 830: $input{'r2'}, $input{'tr2'}, $input{'f'});
3.25 knu 831: gzipclose();
1.12 fenner 832: exit;
3.1 knu 833: }
834: elsif (($newname = $fullname) =~ s|/([^/]+)$|/Attic/$1| &&
835: -f $newname . ",v") {
1.12 fenner 836: # The file has been removed and is in the Attic.
837: # Send a redirect pointing to the file in the Attic.
3.1 knu 838: (my $newplace = $scriptwhere) =~ s|/([^/]+)$|/Attic/$1|;
1.12 fenner 839: &redirect($newplace);
840: exit;
3.1 knu 841: }
842: elsif (0 && (my @files = &safeglob($fullname . ",v"))) {
843: http_header("text/plain");
1.12 fenner 844: print "You matched the following files:\n";
845: print join("\n", @files);
846: # Find the tags from each file
847: # Display a form offering diffs between said tags
3.1 knu 848: }
849: else {
850: my $fh = do {local(*FH);};
851: my ($xtra, $module);
1.12 fenner 852: # Assume it's a module name with a potential path following it.
1.13 fenner 853: $xtra = $& if (($module = $where) =~ s|/.*||);
1.12 fenner 854: # Is there an indexed version of modules?
3.1 knu 855: if (open($fh, "$cvsroot/CVSROOT/modules")) {
856: while (<$fh>) {
857: if (/^(\S+)\s+(\S+)/o && $module eq $1
858: && -d "${cvsroot}/$2" && $module ne $2) {
859: &redirect($scriptname . '/' . $2 . $xtra);
1.12 fenner 860: }
3.1 knu 861: }
1.12 fenner 862: }
863: &fatal("404 Not Found","$where: no such file or directory");
3.1 knu 864: }
3.23 knu 865:
3.25 knu 866: gzipclose();
3.1 knu 867: ## End MAIN
868:
3.12 knu 869: sub printDiffSelect($) {
3.1 knu 870: my ($use_java_script) = @_;
871: my ($f) = $input{'f'};
872: print "<SELECT NAME=\"f\"";
873: print " onchange=\"submit()\"" if ($use_java_script);
874: print ">\n";
875: print "<OPTION VALUE=h",$f eq "h" ? " SELECTED" : "", ">Colored Diff";
876: print "<OPTION VALUE=H",$f eq "H" ? " SELECTED" : "", ">Long Colored Diff";
877: print "<OPTION VALUE=u",$f eq "u" ? " SELECTED" : "", ">Unidiff";
878: print "<OPTION VALUE=c",$f eq "c" ? " SELECTED" : "", ">Context Diff";
879: print "<OPTION VALUE=s",$f eq "s" ? " SELECTED" : "", ">Side by Side";
880: print "</SELECT>";
881: }
882:
3.12 knu 883: sub findLastModifiedSubdirs(@) {
3.1 knu 884: my (@dirs) = @_;
885: my ($dirname, @files);
886:
887: foreach $dirname (@dirs) {
888: next if ($dirname eq ".");
889: next if ($dirname eq "..");
890: my ($dir) = "$fullname/$dirname";
891: next if (!-d $dir);
892:
893: my ($lastmod) = undef;
894: my ($lastmodtime) = undef;
895: my $dh = do {local(*DH);};
896:
897: opendir($dh,$dir) || next;
898: my (@filenames) = readdir($dh);
899: closedir($dh);
900:
901: foreach my $filename (@filenames) {
902: $filename = "$dirname/$filename";
903: my ($file) = "$fullname/$filename";
904: next if ($filename !~ /,v$/ || !-f $file);
905: $filename =~ s/,v$//;
906: my $modtime = -M $file;
907: if (!defined($lastmod) || $modtime < $lastmodtime) {
908: $lastmod = $filename;
909: $lastmodtime = $modtime;
910: }
911: }
912: push(@files, $lastmod) if (defined($lastmod));
913: }
914: return @files;
1.12 fenner 915: }
916:
3.12 knu 917: sub htmlify($;$) {
3.17 knu 918: my($string, $extra) = @_;
1.12 fenner 919:
3.1 knu 920: # Special Characters; RFC 1866
1.12 fenner 921: $string =~ s/&/&/g;
3.12 knu 922: $string =~ s/\"/"/g;
1.12 fenner 923: $string =~ s/</</g;
924: $string =~ s/>/>/g;
925:
3.1 knu 926: # get URL's as link ..
3.19 knu 927: $string =~ s`(http|ftp|https)(://[-a-zA-Z0-9%.~:_/]+)([?&]([-a-zA-Z0-9%.~:_]+)=([-a-zA-Z0-9%.~:_])+)*`<A HREF="$1$2$3">$1$2$3</A>`g; # `
3.1 knu 928: # get e-mails as link
3.19 knu 929: $string =~ s`([-a-zA-Z0-9_.]+@([-a-zA-Z0-9]+\.)+[A-Za-z]{2,4})`<A HREF="mailto:$1">$1</A>`g; # `
3.1 knu 930:
3.17 knu 931: if ($extra) {
932: # get PR #'s as link ..
933: if (defined($prcgi)) {
3.19 knu 934: 1 while $string =~ s`\b(pr[:#]?\s*(?:#?\d+[,\s]\s*)*#?)(\d+)\b`$1 . &link($2, sprintf($prcgi, $2))`ie; # `
935: $string =~ s`\b${prcategories}/(\d+)\b`&link($&, sprintf($prcgi, $1))`igeo; # `
3.17 knu 936: }
937:
938: # get manpage specs as link ..
939: if (defined($mancgi)) {
3.19 knu 940: $string =~ s`\b([a-zA-Z]\w+)\(([0-9n])\)\B`&link($&, sprintf($mancgi, $2, $1))`ge; # `
3.17 knu 941: }
3.1 knu 942: }
943:
944: return $string;
945: }
946:
3.20 knu 947: sub spacedHtmlText($;$) {
3.12 knu 948: local $_ = $_[0];
3.20 knu 949: my $ts = $_[1] || $tabstop;
3.1 knu 950:
3.20 knu 951: # Cut trailing spaces and tabs
952: s/[ \t]+$//;
3.1 knu 953:
3.22 knu 954: if (defined($ts)) {
3.20 knu 955: # Expand tabs
956: 1 while s/\t+/' ' x (length($&) * $ts - length($`) % $ts)/e
957: }
3.1 knu 958:
959: # replace <tab> and <space> (\001 is to protect us from htmlify)
960: # gzip can make excellent use of this repeating pattern :-)
961: if ($hr_breakable) {
962: # make every other space 'breakable'
3.12 knu 963: s/ / \001nbsp;/g; # 2 * <space>
3.1 knu 964: # leave single space as it is
3.20 knu 965: } else {
3.12 knu 966: s/ /\001nbsp;/g;
1.12 fenner 967: }
968:
3.12 knu 969: $_ = htmlify($_);
3.1 knu 970:
971: # unescape
3.20 knu 972: y/\001/&/;
3.1 knu 973:
3.12 knu 974: return $_;
1.12 fenner 975: }
976:
3.12 knu 977: sub link($$) {
3.1 knu 978: my($name, $where) = @_;
1.12 fenner 979:
3.1 knu 980: return "<A HREF=\"$where\">$name</A>\n";
1.12 fenner 981: }
982:
3.12 knu 983: sub revcmp($$) {
3.1 knu 984: my($rev1, $rev2) = @_;
3.15 knu 985:
986: # make no comparison for a tag or a branch
987: return 0 if $rev1 =~ /[^\d.]/ || $rev2 =~ /[^\d.]/;
988:
3.1 knu 989: my(@r1) = split(/\./, $rev1);
990: my(@r2) = split(/\./, $rev2);
991: my($a,$b);
1.12 fenner 992:
993: while (($a = shift(@r1)) && ($b = shift(@r2))) {
994: if ($a != $b) {
995: return $a <=> $b;
996: }
997: }
998: if (@r1) { return 1; }
999: if (@r2) { return -1; }
1000: return 0;
1001: }
1002:
3.12 knu 1003: sub fatal($$) {
3.1 knu 1004: my($errcode, $errmsg) = @_;
3.3 knu 1005: if ($is_mod_perl) {
3.1 knu 1006: Apache->request->status((split(/ /, $errcode))[0]);
1007: }
1008: else {
3.4 knu 1009: print "Status: $errcode\r\n";
3.1 knu 1010: }
1011: html_header("Error");
1.12 fenner 1012: print "Error: $errmsg\n";
1013: print &html_footer;
1014: exit(1);
1015: }
1016:
3.12 knu 1017: sub redirect($) {
3.1 knu 1018: my($url) = @_;
3.3 knu 1019: if ($is_mod_perl) {
3.1 knu 1020: Apache->request->status(301);
1021: Apache->request->header_out(Location => $url);
1022: }
1023: else {
3.4 knu 1024: print "Status: 301 Moved\r\n";
1025: print "Location: $url\r\n";
3.1 knu 1026: }
1027: html_header("Moved");
1.12 fenner 1028: print "This document is located <A HREF=$url>here</A>.\n";
1029: print &html_footer;
1030: exit(1);
1031: }
1032:
3.12 knu 1033: sub safeglob($) {
3.1 knu 1034: my ($filename) = @_;
1035: my ($dirname);
1036: my (@results);
1037: my $dh = do {local(*DH);};
1.12 fenner 1038:
1039: ($dirname = $filename) =~ s|/[^/]+$||;
1040: $filename =~ s|.*/||;
1041:
3.1 knu 1042: if (opendir($dh, $dirname)) {
1043: my $glob = $filename;
1044: my $t;
1.12 fenner 1045: # transform filename from glob to regex. Deal with:
1046: # [, {, ?, * as glob chars
1047: # make sure to escape all other regex chars
1048: $glob =~ s/([\.\(\)\|\+])/\\$1/g;
1049: $glob =~ s/\*/.*/g;
1050: $glob =~ s/\?/./g;
1051: $glob =~ s/{([^}]+)}/($t = $1) =~ s-,-|-g; "($t)"/eg;
3.1 knu 1052: foreach (readdir($dh)) {
1.12 fenner 1053: if (/^${glob}$/) {
1054: push(@results, $dirname . "/" .$_);
1055: }
1056: }
1057: }
1058:
1059: @results;
1060: }
1061:
3.12 knu 1062: sub getMimeTypeFromSuffix($) {
3.1 knu 1063: my ($fullname) = @_;
1064: my ($mimetype, $suffix);
1065: my $fh = do {local(*FH);};
1066:
1067: ($suffix = $fullname) =~ s/^.*\.([^.]*)$/$1/;
1068: $mimetype = $MTYPES{$suffix};
1069: $mimetype = $MTYPES{'*'} if (!$mimetype);
3.12 knu 1070:
3.1 knu 1071: if (!$mimetype && -f $mime_types) {
1072: # okey, this is something special - search the
1073: # mime.types database
1074: open ($fh, "<$mime_types");
1075: while (<$fh>) {
1076: if ($_ =~ /^\s*(\S+\/\S+).*\b$suffix\b/) {
1077: $mimetype = $1;
1078: last;
1079: }
1080: }
1081: close ($fh);
1082: }
3.12 knu 1083:
3.1 knu 1084: # okey, didn't find anything useful ..
1085: if (!($mimetype =~ /\S\/\S/)) {
1086: $mimetype = "text/plain";
1087: }
1088: return $mimetype;
1089: }
1090:
1091: ###############################
3.24 knu 1092: # read first lines like head(1)
1093: ###############################
1094: sub head($;$) {
1095: my $fh = $_[0];
1096: my $linecount = $_[1] || 10;
1097:
1098: my @buf;
1099:
1100: if ($linecount > 0) {
1101: my $i;
1102: for ($i = 0; !eof($fh) && $i < $linecount; $i++) {
1103: push @buf, scalar <$fh>;
1104: }
1105: } else {
1106: @buf = <$fh>;
1107: }
1108:
1109: @buf;
1110: }
1111:
1112: ###############################
1113: # scan vim and Emacs directives
1114: ###############################
1115: sub scan_directives(@) {
1116: my $ts = undef;
1117:
1118: for (@_) {
1119: $ts = $1 if /\b(?:ts|tabstop|tab-width)[:=]\s*([1-9]\d*)\b/;
1120: }
1121:
1122: ('tabstop' => $ts);
1123: }
1124:
1125: ###############################
3.1 knu 1126: # show Annotation
1127: ###############################
3.12 knu 1128: sub doAnnotate($$) {
3.1 knu 1129: my ($rev) = @_;
1130: my ($pid);
1131: my ($pathname, $filename);
1132: my $reader = do {local(*FH);};
1133: my $writer = do {local(*FH);};
1134:
1135: # make sure the revisions a wellformed, for security
1136: # reasons ..
3.15 knu 1137: if ($rev =~ /[^\w.]/) {
3.1 knu 1138: &fatal("404 Not Found",
3.3 knu 1139: "Malformed query \"$ENV{QUERY_STRING}\"");
3.1 knu 1140: }
1.12 fenner 1141:
3.1 knu 1142: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1143: ($filename = $where) =~ s/^.*\///;
1144:
1145: http_header();
1146:
3.12 knu 1147: navigateHeader($scriptwhere,$pathname,$filename,$rev, "annotate");
3.1 knu 1148: print "<h3 align=center>Annotation of $pathname$filename, Revision $rev</h3>\n";
1149:
1150: # this seems to be necessary
1151: $| = 1; $| = 0; # Flush
1152:
1153: # this annotate version is based on the
1154: # cvs annotate-demo Perl script by Cyclic Software
1155: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1156: # the public domain.
1157: # we could abandon the use of rlog, rcsdiff and co using
1158: # the cvsserver in a similiar way one day (..after rewrite)
3.12 knu 1159: $pid = open2($reader, $writer, "cvs server") || fatal ("500 Internal Error",
3.1 knu 1160: "Fatal Error - unable to open cvs for annotation");
3.12 knu 1161:
3.1 knu 1162: # OK, first send the request to the server. A simplified example is:
1163: # Root /home/kingdon/zwork/cvsroot
1164: # Argument foo/xx
1165: # Directory foo
1166: # /home/kingdon/zwork/cvsroot/foo
1167: # Directory .
1168: # /home/kingdon/zwork/cvsroot
1169: # annotate
1170: # although as you can see there are a few more details.
3.12 knu 1171:
3.1 knu 1172: print $writer "Root $cvsroot\n";
1173: print $writer "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1174: # Don't worry about sending valid-requests, the server just needs to
1175: # support "annotate" and if it doesn't, there isn't anything to be done.
1176: print $writer "UseUnchanged\n";
1177: print $writer "Argument -r\n";
1178: print $writer "Argument $rev\n";
1179: print $writer "Argument $where\n";
1180:
1181: # The protocol requires us to fully fake a working directory (at
1182: # least to the point of including the directories down to the one
1183: # containing the file in question).
1184: # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
3.3 knu 1185: my @dirs = split('/', $where);
3.1 knu 1186: my $path = "";
1187: foreach (@dirs) {
1188: if ($path eq "") {
1189: # In our example, $_ is "dir".
1190: $path = $_;
3.12 knu 1191: }
3.1 knu 1192: else {
3.3 knu 1193: print $writer "Directory $path\n";
1194: print $writer "$cvsroot/$path\n";
3.1 knu 1195: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1196: # And the next time, "file" and "dir/sdir/file" (which then gets
1197: # ignored, because we don't need to send Directory for the file).
3.3 knu 1198: $path .= "/$_";
3.1 knu 1199: }
1200: }
1201: # And the last "Directory" before "annotate" is the top level.
1202: print $writer "Directory .\n";
1203: print $writer "$cvsroot\n";
3.12 knu 1204:
3.1 knu 1205: print $writer "annotate\n";
1206: # OK, we've sent our command to the server. Thing to do is to
1207: # close the writer side and get all the responses. If "cvs server"
1208: # were nicer about buffering, then we could just leave it open, I think.
1209: close ($writer) || die "cannot close: $!";
3.12 knu 1210:
3.1 knu 1211: # Ready to get the responses from the server.
1212: # For example:
1213: # E Annotations for foo/xx
1214: # E ***************
3.12 knu 1215: # M 1.3 (kingdon 06-Sep-97): hello
3.1 knu 1216: # ok
1217: my ($lineNr) = 0;
1218: my ($oldLrev, $oldLusr) = ("", "");
1219: my ($revprint, $usrprint);
1220: if ($annTable) {
1221: print "<table border=0 cellspacing=0 cellpadding=0>\n";
1222: }
1223: else {
1224: print "<pre>";
1225: }
3.24 knu 1226:
1227: # prefetch several lines
1228: my @buf = head($reader);
1229:
1230: my %d = scan_directives(@buf);
1231:
1232: while (@buf || !eof($reader)) {
1233: $_ = @buf ? shift @buf : <$reader>;
1234:
3.1 knu 1235: my @words = split;
1236: # Adding one is for the (single) space which follows $words[0].
1237: my $rest = substr ($_, length ($words[0]) + 1);
1238: if ($words[0] eq "E") {
1239: next;
1240: }
1241: elsif ($words[0] eq "M") {
1242: $lineNr++;
1243: my $lrev = substr ($_, 2, 13);
1244: my $lusr = substr ($_, 16, 9);
1245: my $line = substr ($_, 36);
1246: # we should parse the date here ..
1247: if ($lrev eq $oldLrev) {
1248: $revprint = " ";
1249: }
1250: else {
1251: $revprint = $lrev; $oldLusr = "";
3.19 knu 1252: $revprint =~ s`^(\S+)`<a href="${scriptwhere}${barequery}#rev$1">$1</A>`; # `
3.1 knu 1253: }
1254: if ($lusr eq $oldLusr) {
1255: $usrprint = " ";
1256: }
1257: else {
1258: $usrprint = $lusr;
1259: }
1260: $oldLrev = $lrev;
1261: $oldLusr = $lusr;
1262: # is there a less timeconsuming way to strip spaces ?
1263: ($lrev = $lrev) =~ s/\s+//g;
3.3 knu 1264: my $isCurrentRev = ($rev eq $lrev);
3.12 knu 1265:
3.1 knu 1266: print "<b>" if ($isCurrentRev);
1267: printf ("%8s%s%8s %4d:", $revprint, ($isCurrentRev ? "|" : " "), $usrprint, $lineNr);
3.24 knu 1268: print spacedHtmlText($line, $d{'tabstop'});
3.1 knu 1269: print "</b>" if ($isCurrentRev);
1270: }
1271: elsif ($words[0] eq "ok") {
1272: # We could complain about any text received after this, like the
1273: # CVS command line client. But for simplicity, we don't.
1274: }
1275: elsif ($words[0] eq "error") {
1276: fatal ("500 Internal Error", "Error occured during annotate: <b>$_</b>");
1277: }
1278: }
1279: if ($annTable) {
1280: print "</table>";
1281: }
1282: else {
1283: print "</pre>";
1284: }
1285: close ($reader) || warn "cannot close: $!";
1286: wait;
1287: }
1288:
1289: ###############################
1290: # make Checkout
1291: ###############################
3.12 knu 1292: sub doCheckout($$) {
3.1 knu 1293: my ($fullname, $rev) = @_;
1294: my ($mimetype,$revopt);
1295: my $fh = do {local(*FH);};
1296:
3.15 knu 1297: if ($rev eq 'HEAD' || $rev eq '.') {
1298: $rev = undef;
1299: }
1300:
3.1 knu 1301: # make sure the revisions a wellformed, for security
1302: # reasons ..
3.15 knu 1303: if (defined($rev) && $rev =~ /[^\w.]/) {
3.1 knu 1304: &fatal("404 Not Found",
3.3 knu 1305: "Malformed query \"$ENV{QUERY_STRING}\"");
3.1 knu 1306: }
1307:
1308: # get mimetype
1309: if (defined($input{"content-type"}) && ($input{"content-type"} =~ /\S\/\S/)) {
1310: $mimetype = $input{"content-type"}
1311: }
1312: else {
1313: $mimetype = &getMimeTypeFromSuffix($fullname);
1314: }
1315:
1316: if (defined($rev)) {
1317: $revopt = "-r$rev";
1318: if ($use_moddate) {
1319: readLog($fullname,$rev);
1320: $moddate=$date{$rev};
1321: }
1322: }
1323: else {
1324: $revopt = "-rHEAD";
1325: if ($use_moddate) {
1326: readLog($fullname);
1327: $moddate=$date{$symrev{HEAD}};
1328: }
1329: }
3.12 knu 1330:
3.1 knu 1331: ### just for the record:
1332: ### 'cvs co' seems to have a bug regarding single checkout of
1333: ### directories/files having spaces in it;
1334: ### this is an issue that should be resolved on cvs's side
1335: #
1336: # Safely for a child process to read from.
1337: if (! open($fh, "-|")) { # child
1338: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
3.15 knu 1339: exec("cvs", "-Rld", $cvsroot, "co", "-p", $revopt, $where);
3.12 knu 1340: }
3.1 knu 1341: #===================================================================
1342: #Checking out squid/src/ftp.c
1343: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1344: #VERS: 1.1.1.28.6.2
1345: #***************
1346:
1347: # Parse CVS header
1348: my ($revision, $filename, $cvsheader);
1349: while(<$fh>) {
1350: last if (/^\*\*\*\*/);
1351: $revision = $1 if (/^VERS: (.*)$/);
1352: if (/^Checking out (.*)$/) {
1353: $filename = $1;
1354: $filename =~ s/^\.\/*//;
1.12 fenner 1355: }
3.1 knu 1356: $cvsheader .= $_;
1357: }
1358: if ($filename ne $where) {
1359: &fatal("500 Internal Error",
1360: "Unexpected output from cvs co: $cvsheader"
1361: . "<p><b>Check whether the directory $cvsroot/CVSROOT exists "
1362: . "and the script has write-access to the CVSROOT/history "
1363: . "file if it exists."
1364: . "<br>The script needs to place lock files in the "
1365: . "directory the file is in as well.</b>");
1366: }
1367: $| = 1;
1368:
1369: if ($mimetype eq "text/x-cvsweb-markup") {
1370: &cvswebMarkup($fh,$fullname,$revision);
1371: }
1372: else {
1373: http_header($mimetype);
1374: print <$fh>;
1375: }
1376: close($fh);
1377: }
1378:
3.12 knu 1379: sub cvswebMarkup($$$) {
3.1 knu 1380: my ($filehandle,$fullname,$revision) = @_;
1381: my ($pathname, $filename);
1382:
1383: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1384: ($filename = $where) =~ s/^.*\///;
1385: my ($fileurl) = urlencode($filename);
1386:
1387: http_header();
1388:
3.12 knu 1389: navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
3.1 knu 1390: print "<HR noshade>";
1391: print "<table width=\"100%\"><tr><td bgcolor=\"$markupLogColor\">";
1392: print "File: ", &clickablePath($where, 1);
1393: print " ";
1394: &download_link(urlencode($fileurl), $revision, "(download)");
1395: if (!$defaultTextPlain) {
1396: print " ";
3.12 knu 1397: &download_link(urlencode($fileurl), $revision, "(as text)",
3.1 knu 1398: "text/plain");
1399: }
1400: print "<BR>\n";
1401: if ($show_log_in_markup) {
1402: readLog($fullname); #,$revision);
1403: printLog($revision,0);
1404: }
1405: else {
1406: print "Version: <B>$revision</B><BR>\n";
1407: print "Tag: <B>", $input{only_with_tag}, "</b><br>\n" if
1408: $input{only_with_tag};
1409: }
1410: print "</td></tr></table>";
1411: my $url = download_url($fileurl, $revision, $mimetype);
1412: print "<HR noshade>";
1413: if ($mimetype =~ /^image/) {
1414: print "<IMG SRC=\"$url$barequery\"><BR>";
1415: }
3.23 knu 1416: elsif ($mimetype =~ m%^application/pdf%) {
1417: print "<EMBED SRC=\"$url$barequery\" WIDTH=\"100%\"><BR>";
1418: }
3.1 knu 1419: else {
1420: print "<PRE>";
3.24 knu 1421:
1422: # prefetch several lines
1423: my @buf = head($filehandle);
1424:
1425: my %d = scan_directives(@buf);
1426:
1427: while (@buf || !eof($filehandle)) {
1428: $_ = @buf ? shift @buf : <$filehandle>;
1429:
1430: print spacedHtmlText($_, $d{'tabstop'});
1.12 fenner 1431: }
3.1 knu 1432: print "</PRE>";
1433: }
1.12 fenner 1434: }
1435:
3.1 knu 1436: sub viewable($) {
1437: my ($mimetype) = @_;
1438:
3.23 knu 1439: $mimetype =~ m%^((text|image)/|application/pdf)% ;
3.1 knu 1440: }
1441:
1442: ###############################
1443: # Show Colored Diff
1444: ###############################
3.12 knu 1445: sub doDiff($$$$$$) {
3.1 knu 1446: my($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1447: my $fh = do {local(*FH);};
1448: my ($rev1, $rev2, $sym1, $sym2, @difftype, $diffname, $f1, $f2);
1.12 fenner 1449:
1450: if ($r1 =~ /([^:]+)(:(.+))?/) {
1451: $rev1 = $1;
1452: $sym1 = $3;
1453: }
3.1 knu 1454: if ($r1 eq 'text') {
1.12 fenner 1455: $rev1 = $tr1;
3.1 knu 1456: $sym1 = "";
1.12 fenner 1457: }
1458: if ($r2 =~ /([^:]+)(:(.+))?/) {
1459: $rev2 = $1;
1460: $sym2 = $3;
1461: }
3.1 knu 1462: if ($r2 eq 'text') {
1.12 fenner 1463: $rev2 = $tr2;
3.1 knu 1464: $sym2 = "";
1.12 fenner 1465: }
3.15 knu 1466:
3.1 knu 1467: # make sure the revisions a wellformed, for security
1468: # reasons ..
3.15 knu 1469: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1.12 fenner 1470: &fatal("404 Not Found",
3.3 knu 1471: "Malformed query \"$ENV{QUERY_STRING}\"");
1.12 fenner 1472: }
1473: #
1474: # rev1 and rev2 are now both numeric revisions.
1475: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1476: # XXX should we warn about the fact that we do this?
1477: if (&revcmp($rev1,$rev2) > 0) {
3.1 knu 1478: my ($tmp1, $tmp2) = ($rev1, $sym1);
1.12 fenner 1479: ($rev1, $sym1) = ($rev2, $sym2);
1480: ($rev2, $sym2) = ($tmp1, $tmp2);
1481: }
3.1 knu 1482: my $human_readable = 0;
1.12 fenner 1483: if ($f eq 'c') {
3.1 knu 1484: @difftype = qw{-c};
1.12 fenner 1485: $diffname = "Context diff";
3.1 knu 1486: }
1487: elsif ($f eq 's') {
1488: @difftype = qw{--side-by-side --width=164};
1.12 fenner 1489: $diffname = "Side by Side";
3.1 knu 1490: }
1491: elsif ($f eq 'H') {
1492: $human_readable = 1;
1493: @difftype = qw{--unified=15};
1494: $diffname = "Long Human readable";
1495: }
1496: elsif ($f eq 'h') {
1497: @difftype =qw{-u};
1498: $human_readable = 1;
1499: $diffname = "Human readable";
1500: }
1501: elsif ($f eq 'u') {
1502: @difftype = qw{-u};
1.12 fenner 1503: $diffname = "Unidiff";
1504: }
3.1 knu 1505: else {
1506: fatal ("400 Bad arguments", "Diff format $f not understood");
1507: }
1508:
1509: # apply special options
3.3 knu 1510: if ($showfunc) {
3.15 knu 1511: push @difftype, '-p' if $f =~ /^[cHhu]$/;
3.1 knu 1512:
3.3 knu 1513: my($re1, $re2);
3.1 knu 1514:
3.3 knu 1515: while (($re1, $re2) = each %funcline_regexp) {
1516: if ($fullname =~ /$re1/) {
1517: push @difftype, '-F', '$re2';
1518: last;
3.1 knu 1519: }
1520: }
3.3 knu 1521: }
1522: if ($human_readable) {
3.1 knu 1523: if ($hr_ignwhite) {
1524: push @difftype, '-w';
1525: }
1526: if ($hr_ignkeysubst) {
1527: push @difftype, '-kk';
1528: }
1529: }
1530: if (! open($fh, "-|")) { # child
3.3 knu 1531: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1532: exec("rcsdiff",@difftype,"-r$rev1","-r$rev2",$fullname);
3.1 knu 1533: }
1534: if ($human_readable) {
1535: http_header();
1536: &human_readable_diff($fh, $rev2);
3.25 knu 1537: gzipclose();
3.1 knu 1538: exit;
1539: }
1540: else {
1541: http_header("text/plain");
1.44 knu 1542: }
1.12 fenner 1543: #
1544: #===================================================================
1545: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
1546: #retrieving revision 1.16
1547: #retrieving revision 1.17
1548: #diff -c -r1.16 -r1.17
1549: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1550: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
1551: #
1552: # Ideas:
1553: # - nuke the stderr output if it's what we expect it to be
1554: # - Add "no differences found" if the diff command supplied no output.
1555: #
1556: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1557: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
1558: # (bogus example, but...)
1559: #
3.1 knu 1560: if (grep { $_ eq '-u'} @difftype) {
1.12 fenner 1561: $f1 = '---';
1562: $f2 = '\+\+\+';
3.1 knu 1563: }
1564: else {
1.12 fenner 1565: $f1 = '\*\*\*';
1566: $f2 = '---';
1567: }
3.1 knu 1568: while (<$fh>) {
1.12 fenner 1569: if (m|^$f1 $cvsroot|o) {
1570: s|$cvsroot/||o;
1571: if ($sym1) {
1572: chop;
1573: $_ .= " " . $sym1 . "\n";
1574: }
3.1 knu 1575: }
1576: elsif (m|^$f2 $cvsroot|o) {
1.12 fenner 1577: s|$cvsroot/||o;
1578: if ($sym2) {
1579: chop;
1580: $_ .= " " . $sym2 . "\n";
1581: }
1582: }
1583: print $_;
1584: }
3.1 knu 1585: close($fh);
1.12 fenner 1586: }
1587:
3.1 knu 1588: ###############################
1589: # Show Logs ..
1590: ###############################
3.12 knu 1591: sub getDirLogs($$@) {
3.1 knu 1592: my ($cvsroot,$dirname,@otherFiles) = @_;
1593: my ($state,$otherFiles,$tag, $file, $date, $branchpoint, $branch, $log);
1594: my ($rev, $revision, $revwanted, $filename, $head, $author);
1595:
1596: $tag = $input{only_with_tag};
1597:
1598: my ($DirName) = "$cvsroot/$where";
1599: my (@files, @filetags);
1600: my $fh = do {local(*FH);};
1601:
1602: push(@files, &safeglob("$DirName/*,v"));
1603: push(@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
1604: foreach $file (@otherFiles) {
1605: push(@files, "$DirName/$file");
1606: }
1607:
1608: # just execute rlog if there are any files
3.12 knu 1609: if ($#files < 0) {
3.1 knu 1610: return;
1611: }
1612:
1613: if ($tag) {
1614: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
1615: if (! open($fh, "-|")) {
3.7 knu 1616: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1617: exec('rlog', @files);
3.1 knu 1618: }
1619: }
1620: else {
1621: my $kidpid = open($fh, "-|");
1622: if (! $kidpid) {
3.4 knu 1623: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
3.7 knu 1624: exec('rlog', '-r', @files);
3.1 knu 1625: }
1626: }
1627: $state = "start";
1628: while (<$fh>) {
1629: if ($state eq "start") {
1630: #Next file. Initialize file variables
1631: $rev = undef;
1632: $revwanted = undef;
1633: $branch = undef;
1634: $branchpoint = undef;
1635: $filename = undef;
1636: $log = undef;
1637: $revision = undef;
1638: $branch = undef;
1639: %symrev = ();
1640: @filetags = ();
1641: #jump to head state
1642: $state = "head";
1643: }
1644: print "$state:$_" if ($verbose);
1645: again:
1646: if ($state eq "head") {
1647: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
1648: $filename = $1 if (/^Working file: (.+)$/);
1649: $head = $1 if (/^head: (.+)$/);
1650: $branch = $1 if (/^branch: (.+)$/);
1651: }
1652: if ($state eq "head" && /^symbolic names/) {
1653: $state = "tags";
3.12 knu 1654: ($branch = $head) =~ s/\.\d+$// if (!defined($branch));
3.1 knu 1655: $branch =~ s/(\.?)(\d+)$/${1}0.$2/;
1656: $symrev{MAIN} = $branch;
1657: $symrev{HEAD} = $branch;
1658: $alltags{MAIN} = 1;
1659: $alltags{HEAD} = 1;
1660: push (@filetags, "MAIN", "HEAD");
1661: next;
1662: }
1663: if ($state eq "tags" &&
1664: /^\s+(.+):\s+([\d\.]+)\s+$/) {
1665: push (@filetags, $1);
1666: $symrev{$1} = $2;
1667: $alltags{$1} = 1;
1668: next;
1669: }
1670: if ($state eq "tags" && /^\S/) {
1671: if (defined($tag) && (defined($symrev{$tag}) || $tag eq "HEAD")) {
1672: $revwanted = $tag eq "HEAD" ? $symrev{"MAIN"} : $symrev{$tag};
1673: ($branch = $revwanted) =~ s/\b0\.//;
1674: ($branchpoint = $branch) =~ s/\.?\d+$//;
1675: $revwanted = undef if ($revwanted ne $branch);
1676: }
1677: elsif (defined($tag) && $tag ne "HEAD") {
1678: print "Tag not found, skip this file" if ($verbose);
1679: $state = "skip";
1680: next;
1681: }
1682: foreach my $tagfound (@filetags) {
1683: $tags{$tagfound} = 1;
1684: }
1685: $state = "head";
1686: goto again;
1687: }
1688: if ($state eq "head" && /^----------------------------$/) {
1689: $state = "log";
1690: $rev = undef;
1691: $date = undef;
1692: $log = "";
1693: # Try to reconstruct the relative filename if RCS spits out a full path
1694: $filename =~ s%^\Q$DirName\E/%%;
1695: next;
1696: }
1697: if ($state eq "log") {
1698: if (/^----------------------------$/
1699: || /^=============================/) {
1700: # End of a log entry.
1701: my $revbranch;
1702: ($revbranch = $rev) =~ s/\.\d+$//;
1703: print "$filename $rev Wanted: $revwanted "
1704: . "Revbranch: $revbranch Branch: $branch "
1705: . "Branchpoint: $branchpoint\n" if ($verbose);
1706: if (!defined($revwanted) && defined($branch)
1707: && $branch eq $revbranch || !defined($tag)) {
1708: print "File revision $rev found for branch $branch\n"
1709: if ($verbose);
1710: $revwanted = $rev;
1711: }
1712: if (defined($revwanted) ? $rev eq $revwanted :
1713: defined($branchpoint) ? $rev eq $branchpoint :
1714: 0 && ($rev eq $head)) { # Don't think head is needed here..
1715: print "File info $rev found for $filename\n" if ($verbose);
1716: my @finfo = ($rev,$date,$log,$author,$filename);
1717: my ($name);
1718: ($name = $filename) =~ s%/.*%%;
1719: $fileinfo{$name} = [ @finfo ];
1720: $state = "done" if ($rev eq $revwanted);
1721: }
1722: $rev = undef;
1723: $date = undef;
1724: $log = "";
1725: }
1726: elsif (!defined($date) && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
1727: my $yr = $1;
1728: # damn 2-digit year routines :-)
1729: if ($yr > 100) {
1730: $yr -= 1900;
1731: }
1732: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1733: ($author) = /author: ([^;]+)/;
1734: $state = "log";
1735: $log = '';
1736: next;
1737: }
1738: elsif (!defined($rev) && m/^revision (.*)$/) {
1739: $rev = $1;
1740: next;
1741: }
1742: else {
1743: $log = $log . $_;
1744: }
1745: }
1746: if (/^===============/) {
1747: $state = "start";
1748: next;
1749: }
1750: }
1751: if ($. == 0) {
3.12 knu 1752: fatal("500 Internal Error",
3.1 knu 1753: "Failed to spawn GNU rlog on <em>'".join(", ", @files)."'</em><p>did you set the <b>\$ENV{PATH}</b> in your configuration file correctly ?");
1754: }
1755: close($fh);
1756: }
1757:
3.12 knu 1758: sub readLog($;$) {
3.1 knu 1759: my($fullname,$revision) = @_;
1760: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
1761: my $fh = do {local(*FH);};
1762:
1763: if (defined($revision)) {
1764: $revision = "-r$revision";
1765: }
1766: else {
1767: $revision = "";
1768: }
1769:
1770: undef %symrev;
1771: undef %revsym;
1772: undef @allrevisions;
1773: undef %date;
1774: undef %author;
1775: undef %state;
1776: undef %difflines;
1777: undef %log;
1.12 fenner 1778:
1779: print("Going to rlog '$fullname'\n") if ($verbose);
3.1 knu 1780: if (! open($fh, "-|")) { # child
1781: if ($revision ne '') {
1782: exec("rlog",$revision,$fullname);
1783: }
1784: else {
1785: exec("rlog",$fullname);
1786: }
1.44 knu 1787: }
3.1 knu 1788: while (<$fh>) {
1.1 jfieber 1789: print if ($verbose);
1790: if ($symnames) {
1791: if (/^\s+([^:]+):\s+([\d\.]+)/) {
1792: $symrev{$1} = $2;
3.1 knu 1793: }
1794: else {
1.1 jfieber 1795: $symnames = 0;
1796: }
3.1 knu 1797: }
1798: elsif (/^head:\s+([\d\.]+)/) {
1799: $head = $1;
1800: }
1801: elsif (/^branch:\s+([\d\.]+)/) {
1802: $curbranch = $1;
1803: }
1804: elsif (/^symbolic names/) {
1.1 jfieber 1805: $symnames = 1;
3.1 knu 1806: }
1807: elsif (/^-----/) {
1.1 jfieber 1808: last;
1809: }
1810: }
3.1 knu 1811: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7 fenner 1812:
1.1 jfieber 1813: # each log entry is of the form:
1814: # ----------------------------
1815: # revision 3.7.1.1
1816: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
1817: # log info
1818: # ----------------------------
1819: logentry:
1820: while (!/^=========/) {
3.1 knu 1821: $_ = <$fh>;
1.12 fenner 1822: last logentry if (!defined($_)); # EOF
1.1 jfieber 1823: print "R:", $_ if ($verbose);
1824: if (/^revision ([\d\.]+)/) {
1825: $rev = $1;
3.1 knu 1826: unshift(@allrevisions,$rev);
1827: }
1828: elsif (/^========/ || /^----------------------------$/) {
1.1 jfieber 1829: next logentry;
3.1 knu 1830: }
1831: else {
1.12 fenner 1832: # The rlog output is syntactically ambiguous. We must
1833: # have guessed wrong about where the end of the last log
1834: # message was.
1835: # Since this is likely to happen when people put rlog output
1836: # in their commit messages, don't even bother keeping
1837: # these lines since we don't know what revision they go with
1838: # any more.
1839: next logentry;
1840: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 1841: }
3.1 knu 1842: $_ = <$fh>;
1.1 jfieber 1843: print "D:", $_ if ($verbose);
3.1 knu 1844: if (m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);\s+author:\s+(\S+);\s+state:\s+(\S+);\s+(lines:\s+([0-9\s+-]+))?|) {
1845: my $yr = $1;
1846: # damn 2-digit year routines :-)
1847: if ($yr > 100) {
1848: $yr -= 1900;
1849: }
1850: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 1851: $author{$rev} = $7;
1.9 fenner 1852: $state{$rev} = $8;
3.1 knu 1853: $difflines{$rev} = $10;
1854: }
1855: else {
1.1 jfieber 1856: &fatal("500 Internal Error", "Error parsing RCS output: $_");
1857: }
1858: line:
3.1 knu 1859: while (<$fh>) {
1.1 jfieber 1860: print "L:", $_ if ($verbose);
1861: next line if (/^branches:\s/);
1862: last line if (/^----------------------------$/ || /^=========/);
1863: $log{$rev} .= $_;
1864: }
1865: print "E:", $_ if ($verbose);
1866: }
3.1 knu 1867: close($fh);
1.1 jfieber 1868: print "Done reading RCS file\n" if ($verbose);
3.1 knu 1869:
1870: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
1871: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
1872:
1.1 jfieber 1873: #
1874: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 1875: # branch, unless there is a branch tag in the RCS file in which case it's the
1876: # highest revision on that branch. Find it by looking through @revorder; it
1877: # is the first commit listed on the appropriate branch.
3.1 knu 1878: # This is not neccesary the same revision as marked as head in the RCS file.
1879: my $headrev = $curbranch || "1";
1880: ($symrev{"MAIN"} = $headrev) =~ s/(\.?)(\d+)$/${1}0.$2/;
1.1 jfieber 1881: revision:
3.1 knu 1882: foreach $rev (@revorder) {
1883: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
1884: $symrev{"HEAD"} = $rev;
1.1 jfieber 1885: last revision;
1886: }
1887: }
3.1 knu 1888: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
1889: if (!defined($symrev{"HEAD"}));
1.1 jfieber 1890: print "Done finding HEAD\n" if ($verbose);
1891: #
1892: # Now that we know all of the revision numbers, we can associate
1893: # absolute revision numbers with all of the symbolic names, and
1894: # pass them to the form so that the same association doesn't have
1895: # to be built then.
1896: #
3.1 knu 1897: undef @branchnames;
1898: undef %branchpoint;
1899: undef $sel;
1900:
1901: foreach (reverse sort keys %symrev) {
1.1 jfieber 1902: $rev = $symrev{$_};
3.1 knu 1903: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
1.7 fenner 1904: push(@branchnames, $_);
1.1 jfieber 1905: #
1906: # A revision number of A.B.0.D really translates into
1907: # "the highest current revision on branch A.B.D".
1908: #
1909: # If there is no branch A.B.D, then it translates into
1910: # the head A.B .
1911: #
3.1 knu 1912: # This reasoning also applies to the main branch A.B,
1913: # with the branch number 0.A, with the exception that
1914: # it has no head to translate to if there is nothing on
1915: # the branch, but I guess this can never happen?
1916: # (the code below gracefully forgets about the branch
1917: # if it should happen)
1918: #
1919: $head = defined($2) ? $2 : "";
1.1 jfieber 1920: $branch = $3;
3.1 knu 1921: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
1922: my $regex;
1923: ($regex = $branchrev) =~ s/\./\\./g;
1.1 jfieber 1924: $rev = $head;
1925:
1926: revision:
3.1 knu 1927: foreach my $r (@revorder) {
1928: if ($r =~ /^${regex}\b/) {
1929: $rev = $branchrev;
1.1 jfieber 1930: last revision;
1931: }
1932: }
3.1 knu 1933: next if ($rev eq "");
1934: if ($rev ne $head && $head ne "") {
1.8 fenner 1935: $branchpoint{$head} .= ", " if ($branchpoint{$head});
1936: $branchpoint{$head} .= $_;
1937: }
1.1 jfieber 1938: }
3.1 knu 1939: $revsym{$rev} .= ", " if ($revsym{$rev});
1940: $revsym{$rev} .= $_;
1.1 jfieber 1941: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
1942: }
1943: print "Done associating revisions with branches\n" if ($verbose);
3.1 knu 1944:
1945: my ($onlyonbranch, $onlybranchpoint);
1946: if ($onlyonbranch = $input{'only_with_tag'}) {
1947: $onlyonbranch = $symrev{$onlyonbranch};
1948: if ($onlyonbranch =~ s/\b0\.//) {
1949: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
1950: }
1951: else {
1952: $onlybranchpoint = $onlyonbranch;
1953: }
1954: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
1955: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
1956: }
1.8 fenner 1957: }
1.1 jfieber 1958:
3.1 knu 1959: undef @revisions;
1960:
1961: foreach (@allrevisions) {
1.7 fenner 1962: ($br = $_) =~ s/\.\d+$//;
3.1 knu 1963: ($brp = $br) =~ s/\.\d+$//;
1.7 fenner 1964: next if ($onlyonbranch && $br ne $onlyonbranch &&
3.1 knu 1965: $_ ne $onlybranchpoint);
1966: unshift(@revisions,$_);
1967: }
1968:
1969: if ($logsort eq "date") {
1970: # Sort the revisions in commit order an secondary sort on revision
1971: # (secondary sort needed for imported sources, or the first main
1972: # revision gets before the same revision on the 1.1.1 branch)
1973: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
1974: }
1975: elsif ($logsort eq "rev") {
1976: # Sort the revisions in revision order, highest first
1977: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
1978: }
1979: else {
1980: # No sorting. Present in the same order as rlog / cvs log
1981: @revdisplayorder = @revisions;
1982: }
1983:
1984: }
1985:
1986: sub printLog($;$) {
1987: my ($link, $br, $brp);
1988: ($_,$link) = @_;
1989: ($br = $_) =~ s/\.\d+$//;
1990: ($brp = $br) =~ s/\.?\d+$//;
1991: my ($isDead, $prev);
1992:
1993: $link = 1 if (!defined($link));
1994: $isDead = ($state{$_} eq "dead");
1995:
1996: if ($link && !$isDead) {
1997: my ($filename);
1998: ($filename = $where) =~ s/^.*\///;
1999: my ($fileurl) = urlencode($filename);
1.4 fenner 2000: print "<a NAME=\"rev$_\"></a>";
3.1 knu 2001: if (defined($revsym{$_})) {
2002: foreach my $sym (split(", ", $revsym{$_})) {
2003: print "<a NAME=\"$sym\"></a>";
2004: }
1.4 fenner 2005: }
3.1 knu 2006: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
2007: foreach my $sym (split(", ", $revsym{$br})) {
1.4 fenner 2008: print "<a NAME=\"$sym\"></a>";
2009: }
3.1 knu 2010: $nameprinted{$br} = 1;
1.4 fenner 2011: }
3.1 knu 2012: print "\n Revision ";
2013: &download_link($fileurl, $_, $_,
2014: $defaultViewable ? "text/x-cvsweb-markup" : undef);
2015: if ($defaultViewable) {
2016: print " / ";
2017: &download_link($fileurl, $_, "(download)", $mimetype);
2018: }
2019: if (not $defaultTextPlain) {
2020: print " / ";
3.12 knu 2021: &download_link($fileurl, $_, "(as text)",
3.1 knu 2022: "text/plain");
2023: }
2024: if (!$defaultViewable) {
2025: print " / ";
2026: &download_link($fileurl, $_, "(view)", "text/x-cvsweb-markup");
2027: }
2028: if ($allow_annotate) {
2029: print " - <a href=\"" . $scriptname . "/" . urlencode($where) . "?annotate=$_$barequery\">";
2030: print "annotate</a>";
2031: }
2032: # Plus a select link if enabled, and this version isn't selected
2033: if ($allow_version_select) {
2034: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
2035: print " - <A HREF=\"${scriptwhere}?r1=$_$barequery" .
2036: "\">[select for diffs]</A>\n";
2037: }
2038: else {
2039: print " - <b>[selected]</b>";
2040: }
2041: }
2042: }
2043: else {
2044: print "Revision <B>$_</B>";
2045: }
2046: if (/^1\.1\.1\.\d+$/) {
2047: print " <i>(vendor branch)</i>";
2048: }
2049: if (defined @mytz) {
2050: my ($est) = $mytz[(localtime($date{$_}))[8]];
2051: print ", <i>" . scalar localtime($date{$_}) . " $est</i> (";
2052: } else {
2053: print ", <i>" . scalar gmtime($date{$_}) . " UTC</i> (";
2054: }
2055: print readableTime(time() - $date{$_},1) . " ago)";
2056: print " by ";
2057: print "<i>" . $author{$_} . "</i>\n";
2058: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
2059: if ($revsym{$br});
2060: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
2061: if ($revsym{$_});
2062: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
2063: if ($branchpoint{$_});
2064: # Find the previous revision
2065: my @prevrev = split(/\./, $_);
2066: do {
2067: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 2068: # If it was X.Y.Z.1, just make it X.Y
3.1 knu 2069: pop(@prevrev);
2070: pop(@prevrev);
2071: }
2072: $prev = join(".", @prevrev);
2073: } until (defined($date{$prev}) || $prev eq "");
2074: if ($prev ne "") {
2075: if ($difflines{$_}) {
2076: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
2077: }
2078: }
2079: if ($isDead) {
2080: print "<BR><B><I>FILE REMOVED</I></B>\n";
2081: }
2082: elsif ($link) {
2083: my %diffrev = ();
2084: $diffrev{$_} = 1;
2085: $diffrev{""} = 1;
2086: print "<BR>Diff";
2087: #
2088: # Offer diff to previous revision
2089: if ($prev) {
2090: $diffrev{$prev} = 1;
2091: print " to previous <A HREF=\"${scriptwhere}.diff?r1=$prev";
2092: print "&r2=$_" . $barequery . "\">$prev</A>\n";
2093: if (!$hr_default) { # offer a human readable version if not default
2094: print "(<A HREF=\"${scriptwhere}.diff?r1=$prev";
2095: print "&r2=$_" . $barequery . "&f=h\">colored</A>)\n";
2096: }
2097: }
2098: #
2099: # Plus, if it's on a branch, and it's not a vendor branch,
2100: # offer a diff with the branch point.
2101: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
2102: print " to branchpoint <A HREF=\"${scriptwhere}.diff?r1=$brp";
2103: print "&r2=$_" . $barequery . "\">$brp</A>\n";
2104: if (!$hr_default) { # offer a human readable version if not default
2105: print "(<A HREF=\"${scriptwhere}.diff?r1=$brp";
2106: print "&r2=$_" . $barequery . "&f=h\">colored</A>)\n";
1.1 jfieber 2107: }
2108: }
3.1 knu 2109: #
2110: # Plus, if it's on a branch, and it's not a vendor branch,
2111: # offer to diff with the next revision of the higher branch.
2112: # (e.g. change gets committed and then brought
2113: # over to -stable)
2114: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2115: my ($i,$nextmain);
2116: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
2117: my (@tmp2) = split(/\./, $_);
2118: for ($nextmain = ""; $i > 0; $i--) {
2119: my ($next) = $revorder[$i-1];
2120: my (@tmp1) = split(/\./, $next);
1.1 jfieber 2121: if ($#tmp1 < $#tmp2) {
3.1 knu 2122: $nextmain = $next;
2123: last;
2124: }
2125: # Only the highest version on a branch should have
2126: # a diff for the "next main".
2127: last if (join(".",@tmp1[0..$#tmp1-1])
2128: eq join(".",@tmp2[0..$#tmp1-1]));
2129: }
2130: if (!defined($diffrev{$nextmain})) {
2131: $diffrev{$nextmain} = 1;
2132: print " next main <A HREF=\"${scriptwhere}.diff?r1=$nextmain";
2133: print "&r2=$_" . $barequery .
2134: "\">$nextmain</A>\n";
2135: if (!$hr_default) { # offer a human readable version if not default
2136: print "(<A HREF=\"${scriptwhere}.diff?r1=$nextmain";
2137: print "&r2=$_" . $barequery .
2138: "&f=h\">colored</A>)\n";
1.1 jfieber 2139: }
2140: }
2141: }
3.1 knu 2142: # Plus if user has selected only r1, then present a link
2143: # to make a diff to that revision
2144: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2145: $diffrev{$input{"r1"}} = 1;
2146: print " to selected <A HREF=\"${scriptwhere}.diff?"
2147: . "r1=$input{'r1'}&r2=$_" . $barequery
2148: . "\">$input{'r1'}</A>\n";
2149: if (!$hr_default) { # offer a human readable version if not default
2150: print "(<A HREF=\"${scriptwhere}.diff?r1=$input{'r1'}";
2151: print "&r2=$_" . $barequery .
2152: "&f=h\">colored</A>)\n";
2153:
2154: }
1.9 fenner 2155: }
1.1 jfieber 2156: }
3.1 knu 2157: print "<PRE>\n";
2158: print &htmlify($log{$_}, 1);
2159: print "</PRE>\n";
2160: }
2161:
3.12 knu 2162: sub doLog($) {
3.1 knu 2163: my($fullname) = @_;
2164: my ($diffrev, $upwhere, $filename, $backurl);
3.12 knu 2165:
3.1 knu 2166: readLog($fullname);
2167:
2168: html_header("CVS log for $where");
2169: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2170: ($filename = $where) =~ s|^.*/||;
2171: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2172: print &link($backicon, "$backurl#$filename"),
2173: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
3.3 knu 2174: print <<EOF;
2175: <A HREF="#diff">Request diff between arbitrary revisions</A>
2176: <HR NOSHADE>
2177: EOF
3.1 knu 2178: if ($curbranch) {
3.3 knu 2179: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
3.1 knu 2180: }
2181: else {
2182: print "No default branch";
2183: }
2184: print "<BR>\n";
2185: if ($input{only_with_tag}) {
2186: print "Current tag: $input{only_with_tag}<BR>\n";
2187: }
2188:
2189: undef %nameprinted;
2190:
2191: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2192: print "<HR size=1 NOSHADE>";
2193: printLog($revdisplayorder[$i]);
2194: }
2195:
2196: print "<HR NOSHADE>";
1.1 jfieber 2197: print "<A NAME=diff>\n";
2198: print "This form allows you to request diff's between any two\n";
2199: print "revisions of a file. You may select a symbolic revision\n";
2200: print "name using the selection box or you may type in a numeric\n";
2201: print "name using the type-in text box.\n";
2202: print "</A><P>\n";
3.1 knu 2203: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2204: foreach (@stickyvars) {
2205: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
2206: if (defined($input{$_})
3.23 knu 2207: && ((!defined($DEFAULTVALUE{$_})
2208: || $input{$_} ne $DEFAULTVALUE{$_})
2209: && $input{$_} ne ""));
3.1 knu 2210: }
3.21 knu 2211: print "<TABLE><TR>\n";
2212: print "<TD align=right>Diffs between \n";
1.1 jfieber 2213: print "<SELECT NAME=\"r1\">\n";
2214: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2215: print $sel;
2216: print "</SELECT>\n";
3.1 knu 2217: $diffrev = $revdisplayorder[$#revdisplayorder];
2218: $diffrev = $input{"r1"} if (defined($input{"r1"}));
3.21 knu 2219: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
2220: print "<TD><BR></TD></TR>\n";
2221: print "<TR><TD align=right>and \n";
1.1 jfieber 2222: print "<SELECT NAME=\"r2\">\n";
2223: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2224: print $sel;
2225: print "</SELECT>\n";
3.1 knu 2226: $diffrev = $revdisplayorder[0];
2227: $diffrev = $input{"r2"} if (defined($input{"r2"}));
3.21 knu 2228: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
2229: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Get Diffs \"></TD>\n";
1.1 jfieber 2230: print "</FORM>\n";
3.21 knu 2231: print "</TR></TABLE>\n";
1.7 fenner 2232: print "<HR noshade>\n";
3.21 knu 2233: print "<TABLE>";
2234: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
2235: print "<TR><TD align=right>Preferred Diff type:</TD>";
2236: print "<TD>";
2237: printDiffSelect($use_java_script);
2238: print "</TD><TD></TD></TR>\n";
3.1 knu 2239: if (@branchnames) {
3.21 knu 2240: print "<TR><TD align=right>View only Branch:</TD>";
2241: print "<TD>";
3.1 knu 2242: print "<A name=branch></A>\n";
2243: print "<SELECT NAME=\"only_with_tag\"";
2244: print " onchange=\"submit()\"" if ($use_java_script);
2245: print ">\n";
2246: print "<OPTION VALUE=\"\"";
2247: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2248: $input{"only_with_tag"} eq "");
2249: print ">Show all branches\n";
2250: foreach (reverse sort @branchnames) {
1.9 fenner 2251: print "<OPTION";
3.1 knu 2252: print " SELECTED" if (defined($input{"only_with_tag"})
2253: && $input{"only_with_tag"} eq $_);
1.9 fenner 2254: print ">${_}\n";
3.1 knu 2255: }
3.21 knu 2256: print "</SELECT></TD><TD></TD></TR>\n";
1.7 fenner 2257: }
3.1 knu 2258: foreach (@stickyvars) {
3.21 knu 2259: next if ($_ eq "f");
3.1 knu 2260: next if ($_ eq "only_with_tag");
2261: next if ($_ eq "logsort");
2262: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
3.23 knu 2263: if (defined($input{$_})
2264: && (!defined($DEFAULTVALUE{$_})
2265: || $input{$_} ne $DEFAULTVALUE{$_})
3.1 knu 2266: && $input{$_} ne "");
2267: }
3.21 knu 2268: print "<TR><TD align=right>";
2269: print "<A name=logsort></A>\n";
2270: print "Sort log by:</TD>";
2271: print "<TD><SELECT NAME=\"logsort\"";
3.1 knu 2272: print " onchange=\"submit()\"" if ($use_java_script);
2273: print ">\n";
2274: print "<OPTION VALUE=cvs",$logsort eq "cvs" ? " SELECTED" : "", ">Not sorted";
2275: print "<OPTION VALUE=date",$logsort eq "date" ? " SELECTED" : "", ">Commit date";
2276: print "<OPTION VALUE=rev",$logsort eq "rev" ? " SELECTED" : "", ">Revision";
3.21 knu 2277: print "</SELECT></TD>";
2278: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Set \"></TD>";
1.7 fenner 2279: print "</FORM>\n";
3.21 knu 2280: print "</TR></TABLE>";
1.2 jfieber 2281: print &html_footer;
1.1 jfieber 2282: print "</BODY></HTML>\n";
1.10 wosch 2283: }
2284:
3.12 knu 2285: sub flush_diff_rows($$$$) {
3.1 knu 2286: my $j;
2287: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2288: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2289: for ($j = 0 ; $j < $leftRow; $j++) {
2290: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2291: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2292: }
2293: }
2294: elsif ($state eq "PreChange") { # state eq "PreChange"
2295: # we got removes with subsequent adds
2296: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2297: print "<tr>";
2298: if ($j < $leftRow) {
2299: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2300: }
2301: else {
2302: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2303: }
2304: if ($j < $rightRow) {
2305: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2306: }
2307: else {
2308: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2309: }
2310: print "</tr>\n";
2311: }
2312: }
2313: }
2314:
2315: ##
2316: # Function to generate Human readable diff-files
2317: # human_readable_diff(String revision_to_return_to);
2318: ##
2319: sub human_readable_diff($){
3.24 knu 2320: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
3.1 knu 2321: my ($fh, $rev) = @_;
2322: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2323: my (@rightCol, @leftCol);
2324:
2325: ($where_nd = $where) =~ s/.diff$//;
2326: ($filename = $where_nd) =~ s/^.*\///;
2327: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2328: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2329:
3.12 knu 2330: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
3.1 knu 2331:
2332: # Read header to pick up read revision and date, if possible
2333: while (<$fh>) {
2334: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2335: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2336: last if (/^\+\+\+ /);
2337: }
2338: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2339: $rev1 = $r1r;
2340: $date1 = $r1d;
2341: }
2342: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2343: $rev2 = $r2r;
2344: $date2 = $r2d;
2345: }
3.12 knu 2346:
3.1 knu 2347: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n";
2348:
2349: print "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n";
2350: print "<tr bgcolor=\"#ffffff\">\n";
2351: print "<th width=\"50%\" valign=TOP>";
2352: print "version $rev1";
2353: print ", $date1" if (defined($date1));
2354: print "<br>Tag: $sym1\n" if ($sym1);
2355: print "</th>\n";
2356: print "<th width=\"50%\" valign=TOP>";
2357: print "version $rev2";
2358: print ", $date2" if (defined($date2));
2359: print "<br>Tag: $sym2\n" if ($sym1);
2360: print "</th>\n";
2361:
2362: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\">";
2363: my $fe = "</font>";
2364:
2365: my $leftRow = 0;
2366: my $rightRow = 0;
2367: my ($oldline, $newline, $funname, $diffcode, $rest);
2368:
2369: # Process diff text
2370: # The diffrows are could make excellent use of
2371: # cascading style sheets because we've to set the
2372: # font and color for each row. anyone ...?
2373: ####
3.24 knu 2374:
2375: # prefetch several lines
2376: my @buf = head($fh);
2377:
2378: my %d = scan_directives(@buf);
2379:
2380: while (@buf || !eof($fh)) {
2381: $difftxt = @buf ? shift @buf : <$fh>;
3.12 knu 2382:
3.1 knu 2383: if ($difftxt =~ /^@@/) {
2384: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2385: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2386: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2387: print " <font size=-1>$funname</font></td></tr></table>";
2388: print "</td><td width=\"50%\">";
2389: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2390: print " <font size=-1>$funname</font></td></tr></table>";
2391: print "</td>\n";
2392: $state = "dump";
2393: $leftRow = 0;
2394: $rightRow = 0;
2395: }
2396: else {
2397: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
3.24 knu 2398: $_ = spacedHtmlText($rest, $d{'tabstop'});
3.1 knu 2399:
2400: # Add fontface, size
2401: $_ = "$fs $_$fe";
3.12 knu 2402:
3.1 knu 2403: #########
2404: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2405: # in order to get some nice 'ediff'-mode output
2406: # states:
2407: # "dump" - just dump the value
2408: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2409: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2410: ##########
2411:
2412: if ($diffcode eq '+') {
2413: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2414: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2415: }
2416: else { # we got minus before
2417: $state = "PreChange";
2418: $rightCol[$rightRow++] = $_;
2419: }
3.12 knu 2420: }
3.1 knu 2421: elsif ($diffcode eq '-') {
2422: $state = "PreChangeRemove";
2423: $leftCol[$leftRow++] = $_;
2424: }
2425: else { # empty diffcode
2426: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2427: print "<tr><td>$_</td><td>$_</td></tr>\n";
2428: $state = "dump";
2429: $leftRow = 0;
2430: $rightRow = 0;
2431: }
2432: }
2433: }
2434: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2435:
2436: # state is empty if we didn't have any change
2437: if (!$state) {
2438: print "<tr><td colspan=2> </td></tr>";
2439: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2440: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2441: }
2442: print "</table>";
2443: close($fh);
2444:
2445: print "<br><hr noshade width=\"100%\">\n";
2446:
2447: print "<table border=0>";
2448:
2449: print "<tr><td>";
2450: # print legend
2451: print "<table border=1><tr><td>";
2452: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2453: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2454: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2455: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2456: print "</table></td></tr></table>\n";
2457:
2458: print "<td>";
2459: # Print format selector
2460: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2461: foreach my $var (keys %input) {
2462: next if ($var eq "f");
2463: next if (defined($DEFAULTVALUE{$var})
2464: && $DEFAULTVALUE{$var} eq $input{$var});
2465: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2466: urlencode($input{$var}),"\">\n";
2467: }
2468: printDiffSelect($use_java_script);
2469: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2470: print "</FORM>\n";
2471: print "</td>";
2472:
2473: print "</tr></table>";
2474: }
2475:
3.12 knu 2476: sub navigateHeader($$$$$) {
3.1 knu 2477: my ($swhere,$path,$filename,$rev,$title) = @_;
2478: $swhere = "" if ($swhere eq $scriptwhere);
2479: $swhere = urlencode($filename) if ($swhere eq "");
2480: print "<\!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
2481: print "<HTML>\n<HEAD>\n";
3.27 ! knu 2482: print '<!-- CVSweb $zRevision: 1.103 $ $Revision: 3.26 $ -->';
3.1 knu 2483: print "\n<TITLE>$path$filename - $title - $rev</TITLE></HEAD>\n";
3.26 knu 2484: print "$body_tag_for_src\n";
3.1 knu 2485: print "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$navigationHeaderColor\">";
2486: print "<tr valign=bottom><td>";
2487: print "<a href=\"$swhere$query#rev$rev\">$backicon";
2488: print "</a> <b>Return to ", &link("$filename","$swhere$query#rev$rev")," CVS log";
2489: print "</b> $fileicon</td>";
3.12 knu 2490:
3.1 knu 2491: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2492: print "</tr></table>";
2493: }
2494:
3.12 knu 2495: sub plural_write($$) {
3.1 knu 2496: my ($num,$text) = @_;
2497: if ($num != 1) {
2498: $text = $text . "s";
2499: }
2500: if ($num > 0) {
2501: return $num . " " . $text;
2502: }
2503: else {
2504: return "";
2505: }
2506: }
2507:
2508: ##
2509: # print readable timestamp in terms of
2510: # '..time ago'
2511: # H. Zeller <zeller@think.de>
2512: ##
3.12 knu 2513: sub readableTime($$) {
3.1 knu 2514: my ($i, $break, $retval);
2515: my ($secs,$long) = @_;
2516:
2517: # this function works correct for time >= 2 seconds
2518: if ($secs < 2) {
2519: return "very little time";
2520: }
2521:
2522: my %desc = (1 , 'second',
2523: 60, 'minute',
2524: 3600, 'hour',
2525: 86400, 'day',
2526: 604800, 'week',
2527: 2628000, 'month',
2528: 31536000, 'year');
2529: my @breaks = sort {$a <=> $b} keys %desc;
2530: $i = 0;
3.12 knu 2531: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3.1 knu 2532: $i++;
2533: }
2534: $i--;
2535: $break = $breaks[$i];
3.3 knu 2536: $retval = plural_write(int ($secs / $break), $desc{$break});
3.1 knu 2537:
2538: if ($long == 1 && $i > 0) {
2539: my $rest = $secs % $break;
2540: $i--;
2541: $break = $breaks[$i];
3.12 knu 2542: my $resttime = plural_write(int ($rest / $break),
3.3 knu 2543: $desc{$break});
3.1 knu 2544: if ($resttime) {
2545: $retval = $retval . ", " . $resttime;
2546: }
2547: }
2548:
2549: return $retval;
2550: }
2551:
2552: ##
2553: # clickablePath(String pathname, boolean last_item_clickable)
2554: #
2555: # returns a html-ified path whereas each directory is a link for
2556: # faster navigation. last_item_clickable controls whether the
2557: # basename (last directory/file) is a link as well
2558: ##
2559: sub clickablePath($$) {
3.12 knu 2560: my ($pathname,$clickLast) = @_;
3.1 knu 2561: my $retval = '';
3.12 knu 2562:
3.1 knu 2563: if ($pathname eq '/') {
2564: # this should never happen - chooseCVSRoot() is
2565: # intended to do this
2566: $retval = "[$cvstree]";
2567: }
2568: else {
2569: $retval = $retval . " <a href=\"${scriptname}/${query}#dirlist\">[$cvstree]</a>";
2570: my $wherepath = '';
2571: my ($lastslash) = $pathname =~ m|/$|;
2572: foreach (split(/\//, $pathname)) {
2573: $retval = $retval . " / ";
2574: $wherepath = $wherepath . '/' . $_;
2575: my ($last) = "$wherepath/" eq "/$pathname"
3.3 knu 2576: || $wherepath eq "/$pathname";
3.1 knu 2577: if ($clickLast || !$last) {
2578: $retval = $retval . "<a href=\"${scriptname}"
2579: . urlencode($wherepath)
2580: . (!$last || $lastslash ? '/' : '')
2581: . ${query}
2582: . (!$last || $lastslash ? "#dirlist" : "")
2583: . "\">$_</a>";
2584: }
2585: else { # do not make a link to the current dir
2586: $retval = $retval . $_;
2587: }
2588: }
2589: }
2590: return $retval;
2591: }
2592:
2593: sub chooseCVSRoot() {
2594: my @foo;
2595: foreach (sort keys %CVSROOT) {
2596: if (-d $CVSROOT{$_}) {
2597: push(@foo, $_);
2598: }
2599: }
2600: if (@foo > 1) {
2601: my ($k);
2602: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2603: foreach $k (keys %input) {
3.12 knu 2604: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
3.1 knu 2605: if ($input{$k}) && ($k ne "cvsroot");
2606: }
2607: # Form-Elements look wierd in Netscape if the background
2608: # isn't gray and the form elements are not placed
2609: # within a table ...
2610: print "<table><tr>";
2611: print "<td>CVS Root:</td>";
2612: print "<td>\n<select name=\"cvsroot\"";
2613: print " onchange=\"submit()\"" if ($use_java_script);
2614: print ">\n";
2615: foreach $k (@foo) {
2616: print "<option value=\"$k\"";
3.3 knu 2617: print " selected" if ($k eq $cvstree);
2618: print ">" . ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} :
3.1 knu 2619: $k). "</option>\n";
2620: }
2621: print "</select>\n</td>";
2622: print "<td><input type=submit value=\"Go\"></td>";
2623: print "</tr></table></form>";
2624: }
2625: else {
2626: # no choice ..
2627: print "CVS Root: <b>[$cvstree]</b>";
2628: }
2629: }
2630:
2631: sub chooseMirror() {
2632: my ($mirror,$moremirrors);
2633: $moremirrors = 0;
2634: # This code comes from the original BSD-cvsweb
2635: # and may not be useful for your site; If you don't
2636: # set %MIRRORS this won't show up, anyway
2637: #
3.12 knu 2638: # Should perhaps exlude the current site somehow..
3.1 knu 2639: if (keys %MIRRORS) {
2640: print "\nThis cvsweb is mirrored in:\n";
2641: foreach $mirror (keys %MIRRORS) {
2642: print ", " if ($moremirrors);
2643: print qq(<a href="$MIRRORS{$mirror}">$mirror</A>\n);
2644: $moremirrors = 1;
2645: }
2646: print "<p>\n";
2647: }
2648: }
2649:
3.12 knu 2650: sub fileSortCmp() {
3.1 knu 2651: my ($comp) = 0;
2652: my ($c,$d,$af,$bf);
2653:
2654: ($af = $a) =~ s/,v$//;
2655: ($bf = $b) =~ s/,v$//;
2656: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2657: if (defined($fileinfo{$af}));
2658: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2659: if (defined($fileinfo{$bf}));
2660:
2661: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2662: # Two files
2663: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2664: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2665: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2666: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2667: }
2668: if ($comp == 0) {
2669: # Directories first, then sorted on name if no other sort critera
2670: # available.
2671: my $ad = ((-d "$fullname/$a")?"D":"F");
2672: my $bd = ((-d "$fullname/$b")?"D":"F");
2673: ($c=$a) =~ s|.*/||;
2674: ($d=$b) =~ s|.*/||;
2675: $comp = ("$ad$c" cmp "$bd$d");
2676: }
2677: return $comp;
2678: }
2679:
2680: # make A url for downloading
3.12 knu 2681: sub download_url($$;$) {
3.1 knu 2682: my ($url,$revision,$mimetype) = @_;
2683:
2684: $revision =~ s/\b0\.//;
2685:
2686: if (defined($checkout_magic)
2687: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
2688: my ($path);
2689: ($path = $where) =~ s|/[^/]*$|/|;
2690: $url = "$scriptname/$checkoutMagic/${path}$url";
2691: }
2692: $url .= "?rev=$revision";
2693: $url .= "&content-type=$mimetype" if (defined($mimetype));
2694:
2695: return $url;
2696: }
2697:
3.12 knu 2698: # Presents a link to download the
3.1 knu 2699: # selected revision
3.12 knu 2700: sub download_link($$$;$) {
3.1 knu 2701: my ($url,$revision,$textlink,$mimetype) = @_;
2702: my ($fullurl) = download_url($url,$revision,$mimetype);
2703: my ($paren) = $textlink =~ /^\(/;
2704: $textlink =~ s/^\(// if ($paren);
2705: $textlink =~ s/\)$// if ($paren);
2706: print "(" if ($paren);
2707: print "<A HREF=\"$fullurl";
2708: print $barequery;
2709: print "\"";
2710: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
2711: print " target=\"cvs_checkout\"";
2712: # we should have
2713: # 'if (document.cvswin==null) document.cvswin=window.open(...'
2714: # in order to allow the user to resize the window; otherwise
2715: # the user may resize the window, but on next checkout - zap -
2716: # its original (configured s. cvsweb.conf) size is back again
2717: # .. annoying (if $extern_window_(width|height) is defined)
2718: # but this if (..) solution is far from perfect
2719: # what we need to do as well is
2720: # 1) save cvswin in an invisible frame that always exists
2721: # (document.cvswin will be void on next load)
2722: # 2) on close of the cvs_checkout - window set the cvswin
2723: # variable to 'null' again - so that it will be
2724: # reopenend with the configured size
2725: # anyone a JavaScript programmer ?
2726: # .. so here without if (..):
2727: # currently, the best way is to comment out the size parameters
2728: # ($extern_window...) in cvsweb.conf.
2729: if ($use_java_script) {
2730: print " onClick=\"window.open('$fullurl','cvs_checkout',";
2731: print "'resizeable,scrollbars";
2732: print ",status,toolbar" if (defined($mimetype)
2733: && $mimetype eq "text/html");
2734: print ",width=$extern_window_width" if (defined($extern_window_width));
2735: print ",height=$extern_window_height" if (defined($extern_window_height));
2736: print"');\"";
2737: }
2738: }
2739: print "><b>$textlink</b></A>";
2740: print ")" if ($paren);
2741: }
2742:
2743: # Returns a Query string with the
2744: # specified parameter toggled
2745: sub toggleQuery($$) {
2746: my ($toggle,$value) = @_;
2747: my ($newquery,$var);
2748: my (%vars);
2749: %vars = %input;
2750: if (defined($value)) {
2751: $vars{$toggle} = $value;
2752: }
2753: else {
2754: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
2755: }
2756: # Build a new query of non-default paramenters
2757: $newquery = "";
2758: foreach $var (@stickyvars) {
2759: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
2760: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
2761: if ($value ne $default) {
2762: $newquery .= "&" if ($newquery ne "");
2763: $newquery .= urlencode($var) . "=" . urlencode($value);
2764: }
2765: }
2766: if ($newquery) {
2767: return '?' . $newquery;
2768: }
2769: return "";
2770: }
2771:
3.12 knu 2772: sub urlencode($) {
3.1 knu 2773: my ($in) = @_;
2774: my ($out);
2775: ($out = $in) =~ s/([\000-+{-\377])/sprintf("%%%02x", ord($1))/ge;
2776: return $out;
2777: }
2778:
3.12 knu 2779: sub http_header(;$) {
3.1 knu 2780: my $content_type = shift || "text/html";
2781: if (defined($moddate)) {
2782: if ($is_mod_perl) {
3.23 knu 2783: Apache->request->header_out("Last-Modified" => scalar gmtime($moddate) . " GMT");
3.1 knu 2784: }
2785: else {
3.4 knu 2786: print "Last-Modified: " . scalar gmtime($moddate) . " GMT\r\n";
3.1 knu 2787: }
2788: }
2789: if ($is_mod_perl) {
2790: Apache->request->content_type($content_type);
2791: }
2792: else {
3.4 knu 2793: print "Content-type: $content_type\r\n";
3.1 knu 2794: }
2795: if ($allow_compress && $maycompress) {
3.23 knu 2796: if ($has_zlib || (defined($GZIPBIN) && open(GZIP, "|$GZIPBIN -1 -c"))) {
3.1 knu 2797: if ($is_mod_perl) {
2798: Apache->request->content_encoding("x-gzip");
2799: Apache->request->header_out(Vary => "Accept-Encoding");
2800: Apache->request->send_http_header;
2801: }
2802: else {
3.4 knu 2803: print "Content-encoding: x-gzip\r\n";
2804: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
2805: print "\r\n"; # Close headers
3.1 knu 2806: }
2807: $| = 1; $| = 0; # Flush header output
3.23 knu 2808: if ($has_zlib) {
2809: tie *GZIP, __PACKAGE__, \*STDOUT;
2810: }
2811: select(GZIP);
2812: $gzip_open = 1;
3.1 knu 2813: # print "<!-- gzipped -->" if ($content_type eq "text/html");
2814: }
2815: else {
2816: if ($is_mod_perl) {
2817: Apache->request->send_http_header;
2818: }
2819: else {
3.4 knu 2820: print "\r\n"; # Close headers
3.1 knu 2821: }
2822: print "<font size=-1>Unable to find gzip binary in the \$PATH to compress output</font><br>";
2823: }
2824: }
2825: else {
2826: if ($is_mod_perl) {
2827: Apache->request->send_http_header;
2828: }
2829: else {
3.4 knu 2830: print "\r\n"; # Close headers
3.1 knu 2831: }
2832: }
2833: }
2834:
2835: sub html_header($) {
2836: my ($title) = @_;
3.27 ! knu 2837: my $version = '$zRevision: 1.103 $ $Revision: 3.26 $'; #'
3.1 knu 2838: http_header();
2839: print <<EOH;
2840: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
2841: "http://www.w3.org/TR/REC-html40/loose.dtd">
2842: <html>
2843: <title>$title</title>
3.3 knu 2844: <!-- CVSweb $version -->
3.1 knu 2845: </head>
2846: $body_tag
2847: $logo <h1 align="center">$title</h1>
2848: EOH
2849: }
2850:
3.12 knu 2851: sub html_footer() {
3.1 knu 2852: return "<hr noshade><address>$address</address>\n";
2853: }
2854:
3.12 knu 2855: sub link_tags($) {
3.1 knu 2856: my ($tags) = @_;
2857: my ($ret) = "";
2858: my ($fileurl,$filename);
2859:
2860: ($filename = $where) =~ s/^.*\///;
2861: $fileurl = urlencode($filename);
2862:
2863: foreach my $sym (split(", ", $tags)) {
2864: $ret .= ",\n" if ($ret ne "");
2865: $ret .= "<A HREF=\"$fileurl"
2866: . toggleQuery('only_with_tag',$sym) . "\">$sym</A>";
2867: }
2868: return $ret."\n";
2869: }
2870:
2871: #
2872: # See if a module is listed in the config file's @HideModule list.
2873: #
3.12 knu 2874: sub forbidden_module($) {
3.1 knu 2875: my($module) = @_;
3.12 knu 2876:
3.1 knu 2877: for (my $i=0; $i < @HideModules; $i++) {
2878: return 1 if $module eq $HideModules[$i];
2879: }
2880:
2881: return 0;
3.25 knu 2882: }
2883:
2884: # Close the GZIP handle remove the tie.
2885:
2886: sub gzipclose {
2887: if ($gzip_open) {
2888: select(STDOUT);
2889: close(GZIP);
2890: untie *GZIP;
2891: $gzip_open = 0;
2892: }
3.23 knu 2893: }
2894:
2895: # implement a gzipped file handle via the Compress:Zlib compression
2896: # library.
2897:
2898: sub MAGIC1() { 0x1f }
2899: sub MAGIC2() { 0x8b }
2900: sub OSCODE() { 3 }
2901:
2902: sub TIEHANDLE {
2903: my ($class, $out) = @_;
2904: my ($d) = Compress::Zlib::deflateInit(-Level => Compress::Zlib::Z_BEST_COMPRESSION(),
2905: -WindowBits => -Compress::Zlib::MAX_WBITS()) or return undef;
2906: my ($o) = {
2907: handle => $out,
2908: dh => $d,
2909: crc => 0,
2910: len => 0,
2911: };
2912: my ($header) = pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0,0,0,0,0,0, OSCODE);
2913: print {$o->{handle}} $header;
2914: return bless($o, $class);
2915: }
2916:
2917: sub PRINT {
2918: my ($o) = shift;
2919: my ($buf) = join(defined $, ? $, : "",@_);
2920: my ($len) = length($buf);
2921: my ($compressed, $status) = $o->{dh}->deflate($buf);
2922: print {$o->{handle}} $compressed if defined($compressed);
2923: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
2924: $o->{len} += $len;
2925: return $len;
2926: }
2927:
2928: sub PRINTF {
2929: my ($o) = shift;
2930: my ($fmt) = shift;
2931: my ($buf) = sprintf($fmt, @_);
2932: my ($len) = length($buf);
2933: my ($compressed, $status) = $o->{dh}->deflate($buf);
2934: print {$o->{handle}} $compressed if defined($compressed);
2935: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
2936: $o->{len} += $len;
2937: return $len;
2938: }
2939:
2940: sub WRITE {
2941: my ($o, $buf, $len, $off) = @_;
2942: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
2943: print {$o->{handle}} $compressed if defined($compressed);
2944: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
2945: $o->{len} += $len;
2946: return $len;
2947: }
2948:
2949: sub CLOSE {
2950: my ($o) = @_;
2951: return if !defined( $o->{dh});
2952: my ($buf) = $o->{dh}->flush();
2953: $buf .= pack("V V", $o->{crc}, $o->{len});
2954: print {$o->{handle}} $buf;
2955: undef $o->{dh};
2956: }
2957:
2958: sub DESTROY {
2959: my ($o) = @_;
2960: CLOSE($o);
1.1 jfieber 2961: }
CVSweb