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