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