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