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