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