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