Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.54
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.54! knu 46: # $kId: cvsweb.cgi,v 1.30 2000/09/30 20:10:01 knu Exp $
! 47: # $FreeBSD: www/en/cgi/cvsweb.cgi,v 1.53 2000/09/30 18:57:41 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: # this seems to be necessary
1152: $| = 1; $| = 0; # Flush
1153:
1154: # this annotate version is based on the
1155: # cvs annotate-demo Perl script by Cyclic Software
1156: # It was written by Cyclic Software, http://www.cyclic.com/, and is in
1157: # the public domain.
1158: # we could abandon the use of rlog, rcsdiff and co using
1159: # the cvsserver in a similiar way one day (..after rewrite)
1.45.2.53 knu 1160: $pid = open2($reader, $writer, "cvs -Rl server") || fatal ("500 Internal Error",
1.45.2.46 knu 1161: "Fatal Error - unable to open cvs for annotation");
1.45.2.47 knu 1162:
1.45.2.46 knu 1163: # OK, first send the request to the server. A simplified example is:
1164: # Root /home/kingdon/zwork/cvsroot
1165: # Argument foo/xx
1166: # Directory foo
1167: # /home/kingdon/zwork/cvsroot/foo
1168: # Directory .
1169: # /home/kingdon/zwork/cvsroot
1170: # annotate
1171: # although as you can see there are a few more details.
1.45.2.47 knu 1172:
1.45.2.46 knu 1173: print $writer "Root $cvsroot\n";
1174: print $writer "Valid-responses ok error Valid-requests Checked-in Updated Merged Removed M E\n";
1175: # Don't worry about sending valid-requests, the server just needs to
1176: # support "annotate" and if it doesn't, there isn't anything to be done.
1177: print $writer "UseUnchanged\n";
1178: print $writer "Argument -r\n";
1179: print $writer "Argument $rev\n";
1180: print $writer "Argument $where\n";
1181:
1182: # The protocol requires us to fully fake a working directory (at
1183: # least to the point of including the directories down to the one
1184: # containing the file in question).
1185: # So if $where is "dir/sdir/file", then @dirs will be ("dir","sdir","file")
1186: my @dirs = split('/', $where);
1187: my $path = "";
1188: foreach (@dirs) {
1189: if ($path eq "") {
1190: # In our example, $_ is "dir".
1191: $path = $_;
1.45.2.47 knu 1192: }
1.45.2.46 knu 1193: else {
1194: print $writer "Directory $path\n";
1195: print $writer "$cvsroot/$path\n";
1196: # In our example, $_ is "sdir" and $path becomes "dir/sdir"
1197: # And the next time, "file" and "dir/sdir/file" (which then gets
1198: # ignored, because we don't need to send Directory for the file).
1199: $path .= "/$_";
1.12 fenner 1200: }
1.45.2.46 knu 1201: }
1202: # And the last "Directory" before "annotate" is the top level.
1203: print $writer "Directory .\n";
1204: print $writer "$cvsroot\n";
1.45.2.47 knu 1205:
1.45.2.46 knu 1206: print $writer "annotate\n";
1207: # OK, we've sent our command to the server. Thing to do is to
1208: # close the writer side and get all the responses. If "cvs server"
1209: # were nicer about buffering, then we could just leave it open, I think.
1210: close ($writer) || die "cannot close: $!";
1.45.2.47 knu 1211:
1.45.2.54! knu 1212: http_header();
! 1213:
! 1214: navigateHeader($scriptwhere,$pathname,$filename,$rev, "annotate");
! 1215: print "<h3 align=center>Annotation of $pathname$filename, Revision $rev</h3>\n";
! 1216:
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++;
1.45.2.54! knu 1249: (my $lrev = substr($_, 2, 13)) =~ y/ //d;
! 1250: (my $lusr = substr($_, 16, 9)) =~ y/ //d;
! 1251: my $line = substr($_, 36);
! 1252: my $isCurrentRev = ($rev eq $lrev);
1.45.2.46 knu 1253: # we should parse the date here ..
1254: if ($lrev eq $oldLrev) {
1.45.2.54! knu 1255: $revprint = sprintf('%-8s', '');
1.45.2.46 knu 1256: }
1257: else {
1.45.2.54! knu 1258: $revprint = sprintf('%-8s', $lrev);
! 1259: $revprint =~ s`\S+`<a href="${scriptwhere}${barequery}#rev$1">$&</A>`; # `
! 1260: $oldLusr = '';
1.45.2.46 knu 1261: }
1262: if ($lusr eq $oldLusr) {
1.45.2.54! knu 1263: $usrprint = '';
1.45.2.46 knu 1264: }
1265: else {
1266: $usrprint = $lusr;
1267: }
1268: $oldLrev = $lrev;
1269: $oldLusr = $lusr;
1.45.2.47 knu 1270:
1.45.2.54! knu 1271: # Set bold for text-based browsers only - graphical
! 1272: # browsers show bold fonts a bit wider than regular fonts,
! 1273: # so it looks irregular.
! 1274: print "<b>" if ($isCurrentRev && $is_textbased);
! 1275:
! 1276: printf ("%s%s %-8s %4d:",
! 1277: $revprint,
! 1278: $isCurrentRev ? '!' : ' ',
! 1279: $usrprint,
! 1280: $lineNr);
1.45.2.51 knu 1281: print spacedHtmlText($line, $d{'tabstop'});
1.45.2.54! knu 1282:
! 1283: print "</b>" if ($isCurrentRev && $is_textbased);
1.45.2.46 knu 1284: }
1285: elsif ($words[0] eq "ok") {
1286: # We could complain about any text received after this, like the
1287: # CVS command line client. But for simplicity, we don't.
1288: }
1289: elsif ($words[0] eq "error") {
1290: fatal ("500 Internal Error", "Error occured during annotate: <b>$_</b>");
1291: }
1292: }
1293: if ($annTable) {
1294: print "</table>";
1295: }
1296: else {
1297: print "</pre>";
1298: }
1299: close ($reader) || warn "cannot close: $!";
1300: wait;
1301: }
1302:
1303: ###############################
1304: # make Checkout
1305: ###############################
1.45.2.47 knu 1306: sub doCheckout($$) {
1.45.2.46 knu 1307: my ($fullname, $rev) = @_;
1308: my ($mimetype,$revopt);
1309: my $fh = do {local(*FH);};
1310:
1.45.2.48 knu 1311: if ($rev eq 'HEAD' || $rev eq '.') {
1312: $rev = undef;
1313: }
1314:
1.45.2.46 knu 1315: # make sure the revisions a wellformed, for security
1316: # reasons ..
1.45.2.48 knu 1317: if (defined($rev) && $rev =~ /[^\w.]/) {
1.45.2.46 knu 1318: &fatal("404 Not Found",
1319: "Malformed query \"$ENV{QUERY_STRING}\"");
1320: }
1321:
1322: # get mimetype
1323: if (defined($input{"content-type"}) && ($input{"content-type"} =~ /\S\/\S/)) {
1324: $mimetype = $input{"content-type"}
1325: }
1326: else {
1327: $mimetype = &getMimeTypeFromSuffix($fullname);
1328: }
1329:
1330: if (defined($rev)) {
1331: $revopt = "-r$rev";
1332: if ($use_moddate) {
1333: readLog($fullname,$rev);
1334: $moddate=$date{$rev};
1335: }
1336: }
1337: else {
1338: $revopt = "-rHEAD";
1339: if ($use_moddate) {
1340: readLog($fullname);
1341: $moddate=$date{$symrev{HEAD}};
1342: }
1343: }
1.45.2.47 knu 1344:
1.45.2.46 knu 1345: ### just for the record:
1346: ### 'cvs co' seems to have a bug regarding single checkout of
1347: ### directories/files having spaces in it;
1348: ### this is an issue that should be resolved on cvs's side
1349: #
1350: # Safely for a child process to read from.
1351: if (! open($fh, "-|")) { # child
1352: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1.45.2.48 knu 1353: exec("cvs", "-Rld", $cvsroot, "co", "-p", $revopt, $where);
1.45.2.47 knu 1354: }
1.45.2.46 knu 1355: #===================================================================
1356: #Checking out squid/src/ftp.c
1357: #RCS: /usr/src/CVS/squid/src/ftp.c,v
1358: #VERS: 1.1.1.28.6.2
1359: #***************
1360:
1361: # Parse CVS header
1362: my ($revision, $filename, $cvsheader);
1363: while(<$fh>) {
1364: last if (/^\*\*\*\*/);
1365: $revision = $1 if (/^VERS: (.*)$/);
1366: if (/^Checking out (.*)$/) {
1367: $filename = $1;
1368: $filename =~ s/^\.\/*//;
1369: }
1370: $cvsheader .= $_;
1371: }
1372: if ($filename ne $where) {
1373: &fatal("500 Internal Error",
1374: "Unexpected output from cvs co: $cvsheader"
1375: . "<p><b>Check whether the directory $cvsroot/CVSROOT exists "
1376: . "and the script has write-access to the CVSROOT/history "
1377: . "file if it exists."
1378: . "<br>The script needs to place lock files in the "
1379: . "directory the file is in as well.</b>");
1380: }
1381: $| = 1;
1382:
1383: if ($mimetype eq "text/x-cvsweb-markup") {
1384: &cvswebMarkup($fh,$fullname,$revision);
1385: }
1386: else {
1387: http_header($mimetype);
1388: print <$fh>;
1389: }
1390: close($fh);
1391: }
1392:
1.45.2.47 knu 1393: sub cvswebMarkup($$$) {
1.45.2.46 knu 1394: my ($filehandle,$fullname,$revision) = @_;
1395: my ($pathname, $filename);
1396:
1397: ($pathname = $where) =~ s/(Attic\/)?[^\/]*$//;
1398: ($filename = $where) =~ s/^.*\///;
1399: my ($fileurl) = urlencode($filename);
1400:
1401: http_header();
1402:
1.45.2.47 knu 1403: navigateHeader($scriptwhere, $pathname, $filename, $revision, "view");
1.45.2.46 knu 1404: print "<HR noshade>";
1405: print "<table width=\"100%\"><tr><td bgcolor=\"$markupLogColor\">";
1406: print "File: ", &clickablePath($where, 1);
1407: print " ";
1408: &download_link(urlencode($fileurl), $revision, "(download)");
1409: if (!$defaultTextPlain) {
1410: print " ";
1.45.2.47 knu 1411: &download_link(urlencode($fileurl), $revision, "(as text)",
1.45.2.46 knu 1412: "text/plain");
1413: }
1414: print "<BR>\n";
1415: if ($show_log_in_markup) {
1416: readLog($fullname); #,$revision);
1417: printLog($revision,0);
1418: }
1419: else {
1420: print "Version: <B>$revision</B><BR>\n";
1421: print "Tag: <B>", $input{only_with_tag}, "</b><br>\n" if
1422: $input{only_with_tag};
1423: }
1424: print "</td></tr></table>";
1425: my $url = download_url($fileurl, $revision, $mimetype);
1426: print "<HR noshade>";
1427: if ($mimetype =~ /^image/) {
1428: print "<IMG SRC=\"$url$barequery\"><BR>";
1429: }
1.45.2.51 knu 1430: elsif ($mimetype =~ m%^application/pdf%) {
1431: print "<EMBED SRC=\"$url$barequery\" WIDTH=\"100%\"><BR>";
1432: }
1.45.2.46 knu 1433: else {
1434: print "<PRE>";
1.45.2.51 knu 1435:
1436: # prefetch several lines
1437: my @buf = head($filehandle);
1438:
1439: my %d = scan_directives(@buf);
1440:
1441: while (@buf || !eof($filehandle)) {
1442: $_ = @buf ? shift @buf : <$filehandle>;
1443:
1444: print spacedHtmlText($_, $d{'tabstop'});
1.12 fenner 1445: }
1.45.2.46 knu 1446: print "</PRE>";
1447: }
1.12 fenner 1448: }
1449:
1.45.2.46 knu 1450: sub viewable($) {
1451: my ($mimetype) = @_;
1452:
1.45.2.51 knu 1453: $mimetype =~ m%^((text|image)/|application/pdf)% ;
1.45.2.46 knu 1454: }
1455:
1456: ###############################
1457: # Show Colored Diff
1458: ###############################
1.45.2.47 knu 1459: sub doDiff($$$$$$) {
1.45.2.46 knu 1460: my($fullname, $r1, $tr1, $r2, $tr2, $f) = @_;
1461: my $fh = do {local(*FH);};
1462: my ($rev1, $rev2, $sym1, $sym2, @difftype, $diffname, $f1, $f2);
1.12 fenner 1463:
1464: if ($r1 =~ /([^:]+)(:(.+))?/) {
1465: $rev1 = $1;
1466: $sym1 = $3;
1467: }
1.45.2.46 knu 1468: if ($r1 eq 'text') {
1.12 fenner 1469: $rev1 = $tr1;
1.45.2.46 knu 1470: $sym1 = "";
1.12 fenner 1471: }
1472: if ($r2 =~ /([^:]+)(:(.+))?/) {
1473: $rev2 = $1;
1474: $sym2 = $3;
1475: }
1.45.2.46 knu 1476: if ($r2 eq 'text') {
1.12 fenner 1477: $rev2 = $tr2;
1.45.2.46 knu 1478: $sym2 = "";
1.12 fenner 1479: }
1.45.2.48 knu 1480:
1.45.2.46 knu 1481: # make sure the revisions a wellformed, for security
1482: # reasons ..
1.45.2.48 knu 1483: if ($rev1 =~ /[^\w.]/ || $rev2 =~ /[^\w.]/) {
1.12 fenner 1484: &fatal("404 Not Found",
1.45.2.46 knu 1485: "Malformed query \"$ENV{QUERY_STRING}\"");
1.12 fenner 1486: }
1487: #
1488: # rev1 and rev2 are now both numeric revisions.
1489: # Thus we do a DWIM here and swap them if rev1 is after rev2.
1490: # XXX should we warn about the fact that we do this?
1491: if (&revcmp($rev1,$rev2) > 0) {
1.45.2.46 knu 1492: my ($tmp1, $tmp2) = ($rev1, $sym1);
1.12 fenner 1493: ($rev1, $sym1) = ($rev2, $sym2);
1494: ($rev2, $sym2) = ($tmp1, $tmp2);
1495: }
1.45.2.46 knu 1496: my $human_readable = 0;
1.12 fenner 1497: if ($f eq 'c') {
1.45.2.46 knu 1498: @difftype = qw{-c};
1.12 fenner 1499: $diffname = "Context diff";
1.45.2.46 knu 1500: }
1501: elsif ($f eq 's') {
1502: @difftype = qw{--side-by-side --width=164};
1.12 fenner 1503: $diffname = "Side by Side";
1.45.2.46 knu 1504: }
1505: elsif ($f eq 'H') {
1506: $human_readable = 1;
1507: @difftype = qw{--unified=15};
1508: $diffname = "Long Human readable";
1509: }
1510: elsif ($f eq 'h') {
1511: @difftype =qw{-u};
1512: $human_readable = 1;
1513: $diffname = "Human readable";
1514: }
1515: elsif ($f eq 'u') {
1516: @difftype = qw{-u};
1.12 fenner 1517: $diffname = "Unidiff";
1518: }
1.45.2.46 knu 1519: else {
1520: fatal ("400 Bad arguments", "Diff format $f not understood");
1521: }
1522:
1523: # apply special options
1524: if ($showfunc) {
1.45.2.48 knu 1525: push @difftype, '-p' if $f =~ /^[cHhu]$/;
1.45.2.46 knu 1526:
1527: my($re1, $re2);
1528:
1529: while (($re1, $re2) = each %funcline_regexp) {
1530: if ($fullname =~ /$re1/) {
1531: push @difftype, '-F', '$re2';
1532: last;
1533: }
1534: }
1535: }
1536: if ($human_readable) {
1537: if ($hr_ignwhite) {
1538: push @difftype, '-w';
1539: }
1540: if ($hr_ignkeysubst) {
1541: push @difftype, '-kk';
1542: }
1543: }
1544: if (! open($fh, "-|")) { # child
1.44 knu 1545: open(STDERR, ">&STDOUT"); # Redirect stderr to stdout
1.45.2.46 knu 1546: exec("rcsdiff",@difftype,"-r$rev1","-r$rev2",$fullname);
1547: }
1548: if ($human_readable) {
1549: http_header();
1550: &human_readable_diff($fh, $rev2);
1.45.2.52 knu 1551: gzipclose();
1.45.2.46 knu 1552: exit;
1553: }
1554: else {
1555: http_header("text/plain");
1.44 knu 1556: }
1.12 fenner 1557: #
1558: #===================================================================
1559: #RCS file: /home/ncvs/src/sys/netinet/tcp_output.c,v
1560: #retrieving revision 1.16
1561: #retrieving revision 1.17
1562: #diff -c -r1.16 -r1.17
1563: #*** /home/ncvs/src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1564: #--- /home/ncvs/src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17
1565: #
1566: # Ideas:
1567: # - nuke the stderr output if it's what we expect it to be
1568: # - Add "no differences found" if the diff command supplied no output.
1569: #
1570: #*** src/sys/netinet/tcp_output.c 1995/11/03 22:08:08 1.16
1571: #--- src/sys/netinet/tcp_output.c 1995/12/05 17:46:35 1.17 RELENG_2_1_0
1572: # (bogus example, but...)
1573: #
1.45.2.46 knu 1574: if (grep { $_ eq '-u'} @difftype) {
1.12 fenner 1575: $f1 = '---';
1576: $f2 = '\+\+\+';
1.45.2.46 knu 1577: }
1578: else {
1.12 fenner 1579: $f1 = '\*\*\*';
1580: $f2 = '---';
1581: }
1.45.2.46 knu 1582: while (<$fh>) {
1.12 fenner 1583: if (m|^$f1 $cvsroot|o) {
1584: s|$cvsroot/||o;
1585: if ($sym1) {
1586: chop;
1587: $_ .= " " . $sym1 . "\n";
1588: }
1.45.2.46 knu 1589: }
1590: elsif (m|^$f2 $cvsroot|o) {
1.12 fenner 1591: s|$cvsroot/||o;
1592: if ($sym2) {
1593: chop;
1594: $_ .= " " . $sym2 . "\n";
1595: }
1596: }
1597: print $_;
1598: }
1.45.2.46 knu 1599: close($fh);
1.12 fenner 1600: }
1601:
1.45.2.46 knu 1602: ###############################
1603: # Show Logs ..
1604: ###############################
1.45.2.47 knu 1605: sub getDirLogs($$@) {
1.45.2.46 knu 1606: my ($cvsroot,$dirname,@otherFiles) = @_;
1607: my ($state,$otherFiles,$tag, $file, $date, $branchpoint, $branch, $log);
1608: my ($rev, $revision, $revwanted, $filename, $head, $author);
1609:
1610: $tag = $input{only_with_tag};
1611:
1612: my ($DirName) = "$cvsroot/$where";
1613: my (@files, @filetags);
1614: my $fh = do {local(*FH);};
1615:
1616: push(@files, &safeglob("$DirName/*,v"));
1617: push(@files, &safeglob("$DirName/Attic/*,v")) if (!$input{'hideattic'});
1618: foreach $file (@otherFiles) {
1619: push(@files, "$DirName/$file");
1620: }
1621:
1622: # just execute rlog if there are any files
1.45.2.47 knu 1623: if ($#files < 0) {
1.45.2.46 knu 1624: return;
1625: }
1626:
1627: if ($tag) {
1628: #can't use -r<tag> as - is allowed in tagnames, but misinterpreated by rlog..
1629: if (! open($fh, "-|")) {
1630: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1631: exec('rlog', @files);
1632: }
1633: }
1634: else {
1635: my $kidpid = open($fh, "-|");
1636: if (! $kidpid) {
1637: open(STDERR, '>/dev/null'); # rlog may complain; ignore.
1638: exec('rlog', '-r', @files);
1639: }
1640: }
1641: $state = "start";
1642: while (<$fh>) {
1643: if ($state eq "start") {
1644: #Next file. Initialize file variables
1645: $rev = undef;
1646: $revwanted = undef;
1647: $branch = undef;
1648: $branchpoint = undef;
1649: $filename = undef;
1650: $log = undef;
1651: $revision = undef;
1652: $branch = undef;
1653: %symrev = ();
1654: @filetags = ();
1655: #jump to head state
1656: $state = "head";
1657: }
1658: print "$state:$_" if ($verbose);
1659: again:
1660: if ($state eq "head") {
1661: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
1662: $filename = $1 if (/^Working file: (.+)$/);
1663: $head = $1 if (/^head: (.+)$/);
1664: $branch = $1 if (/^branch: (.+)$/);
1665: }
1666: if ($state eq "head" && /^symbolic names/) {
1667: $state = "tags";
1.45.2.47 knu 1668: ($branch = $head) =~ s/\.\d+$// if (!defined($branch));
1.45.2.46 knu 1669: $branch =~ s/(\.?)(\d+)$/${1}0.$2/;
1670: $symrev{MAIN} = $branch;
1671: $symrev{HEAD} = $branch;
1672: $alltags{MAIN} = 1;
1673: $alltags{HEAD} = 1;
1674: push (@filetags, "MAIN", "HEAD");
1675: next;
1676: }
1677: if ($state eq "tags" &&
1678: /^\s+(.+):\s+([\d\.]+)\s+$/) {
1679: push (@filetags, $1);
1680: $symrev{$1} = $2;
1681: $alltags{$1} = 1;
1682: next;
1683: }
1684: if ($state eq "tags" && /^\S/) {
1685: if (defined($tag) && (defined($symrev{$tag}) || $tag eq "HEAD")) {
1686: $revwanted = $tag eq "HEAD" ? $symrev{"MAIN"} : $symrev{$tag};
1687: ($branch = $revwanted) =~ s/\b0\.//;
1688: ($branchpoint = $branch) =~ s/\.?\d+$//;
1689: $revwanted = undef if ($revwanted ne $branch);
1690: }
1691: elsif (defined($tag) && $tag ne "HEAD") {
1692: print "Tag not found, skip this file" if ($verbose);
1693: $state = "skip";
1694: next;
1695: }
1696: foreach my $tagfound (@filetags) {
1697: $tags{$tagfound} = 1;
1698: }
1699: $state = "head";
1700: goto again;
1701: }
1702: if ($state eq "head" && /^----------------------------$/) {
1703: $state = "log";
1704: $rev = undef;
1705: $date = undef;
1706: $log = "";
1707: # Try to reconstruct the relative filename if RCS spits out a full path
1708: $filename =~ s%^\Q$DirName\E/%%;
1709: next;
1710: }
1711: if ($state eq "log") {
1712: if (/^----------------------------$/
1713: || /^=============================/) {
1714: # End of a log entry.
1715: my $revbranch;
1716: ($revbranch = $rev) =~ s/\.\d+$//;
1717: print "$filename $rev Wanted: $revwanted "
1718: . "Revbranch: $revbranch Branch: $branch "
1719: . "Branchpoint: $branchpoint\n" if ($verbose);
1720: if (!defined($revwanted) && defined($branch)
1721: && $branch eq $revbranch || !defined($tag)) {
1722: print "File revision $rev found for branch $branch\n"
1723: if ($verbose);
1724: $revwanted = $rev;
1725: }
1726: if (defined($revwanted) ? $rev eq $revwanted :
1727: defined($branchpoint) ? $rev eq $branchpoint :
1728: 0 && ($rev eq $head)) { # Don't think head is needed here..
1729: print "File info $rev found for $filename\n" if ($verbose);
1730: my @finfo = ($rev,$date,$log,$author,$filename);
1731: my ($name);
1732: ($name = $filename) =~ s%/.*%%;
1733: $fileinfo{$name} = [ @finfo ];
1734: $state = "done" if ($rev eq $revwanted);
1735: }
1736: $rev = undef;
1737: $date = undef;
1738: $log = "";
1739: }
1740: elsif (!defined($date) && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
1741: my $yr = $1;
1742: # damn 2-digit year routines :-)
1743: if ($yr > 100) {
1744: $yr -= 1900;
1745: }
1746: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1747: ($author) = /author: ([^;]+)/;
1748: $state = "log";
1749: $log = '';
1750: next;
1751: }
1752: elsif (!defined($rev) && m/^revision (.*)$/) {
1753: $rev = $1;
1754: next;
1755: }
1756: else {
1757: $log = $log . $_;
1758: }
1759: }
1760: if (/^===============/) {
1761: $state = "start";
1762: next;
1763: }
1764: }
1765: if ($. == 0) {
1.45.2.47 knu 1766: fatal("500 Internal Error",
1.45.2.46 knu 1767: "Failed to spawn GNU rlog on <em>'".join(", ", @files)."'</em><p>did you set the <b>\$ENV{PATH}</b> in your configuration file correctly ?");
1768: }
1769: close($fh);
1770: }
1771:
1.45.2.47 knu 1772: sub readLog($;$) {
1.45.2.46 knu 1773: my($fullname,$revision) = @_;
1774: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
1775: my $fh = do {local(*FH);};
1776:
1777: if (defined($revision)) {
1778: $revision = "-r$revision";
1779: }
1780: else {
1781: $revision = "";
1782: }
1783:
1784: undef %symrev;
1785: undef %revsym;
1786: undef @allrevisions;
1787: undef %date;
1788: undef %author;
1789: undef %state;
1790: undef %difflines;
1791: undef %log;
1.12 fenner 1792:
1793: print("Going to rlog '$fullname'\n") if ($verbose);
1.45.2.46 knu 1794: if (! open($fh, "-|")) { # child
1795: if ($revision ne '') {
1796: exec("rlog",$revision,$fullname);
1797: }
1798: else {
1799: exec("rlog",$fullname);
1800: }
1.44 knu 1801: }
1.45.2.46 knu 1802: while (<$fh>) {
1.1 jfieber 1803: print if ($verbose);
1804: if ($symnames) {
1805: if (/^\s+([^:]+):\s+([\d\.]+)/) {
1806: $symrev{$1} = $2;
1.45.2.46 knu 1807: }
1808: else {
1.1 jfieber 1809: $symnames = 0;
1810: }
1.45.2.46 knu 1811: }
1812: elsif (/^head:\s+([\d\.]+)/) {
1813: $head = $1;
1814: }
1815: elsif (/^branch:\s+([\d\.]+)/) {
1816: $curbranch = $1;
1817: }
1818: elsif (/^symbolic names/) {
1.1 jfieber 1819: $symnames = 1;
1.45.2.46 knu 1820: }
1821: elsif (/^-----/) {
1.1 jfieber 1822: last;
1823: }
1824: }
1.45.2.46 knu 1825: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7 fenner 1826:
1.1 jfieber 1827: # each log entry is of the form:
1828: # ----------------------------
1829: # revision 3.7.1.1
1830: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
1831: # log info
1832: # ----------------------------
1833: logentry:
1834: while (!/^=========/) {
1.45.2.46 knu 1835: $_ = <$fh>;
1.12 fenner 1836: last logentry if (!defined($_)); # EOF
1.1 jfieber 1837: print "R:", $_ if ($verbose);
1838: if (/^revision ([\d\.]+)/) {
1839: $rev = $1;
1.45.2.46 knu 1840: unshift(@allrevisions,$rev);
1841: }
1842: elsif (/^========/ || /^----------------------------$/) {
1.1 jfieber 1843: next logentry;
1.45.2.46 knu 1844: }
1845: else {
1.12 fenner 1846: # The rlog output is syntactically ambiguous. We must
1847: # have guessed wrong about where the end of the last log
1848: # message was.
1849: # Since this is likely to happen when people put rlog output
1850: # in their commit messages, don't even bother keeping
1851: # these lines since we don't know what revision they go with
1852: # any more.
1853: next logentry;
1854: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 1855: }
1.45.2.46 knu 1856: $_ = <$fh>;
1.1 jfieber 1857: print "D:", $_ if ($verbose);
1.45.2.46 knu 1858: 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+-]+))?|) {
1859: my $yr = $1;
1860: # damn 2-digit year routines :-)
1861: if ($yr > 100) {
1862: $yr -= 1900;
1863: }
1864: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 1865: $author{$rev} = $7;
1.9 fenner 1866: $state{$rev} = $8;
1.45.2.46 knu 1867: $difflines{$rev} = $10;
1868: }
1869: else {
1.1 jfieber 1870: &fatal("500 Internal Error", "Error parsing RCS output: $_");
1871: }
1872: line:
1.45.2.46 knu 1873: while (<$fh>) {
1.1 jfieber 1874: print "L:", $_ if ($verbose);
1875: next line if (/^branches:\s/);
1876: last line if (/^----------------------------$/ || /^=========/);
1877: $log{$rev} .= $_;
1878: }
1879: print "E:", $_ if ($verbose);
1880: }
1.45.2.46 knu 1881: close($fh);
1.1 jfieber 1882: print "Done reading RCS file\n" if ($verbose);
1.45.2.46 knu 1883:
1884: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
1885: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
1886:
1.1 jfieber 1887: #
1888: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 1889: # branch, unless there is a branch tag in the RCS file in which case it's the
1890: # highest revision on that branch. Find it by looking through @revorder; it
1891: # is the first commit listed on the appropriate branch.
1.45.2.46 knu 1892: # This is not neccesary the same revision as marked as head in the RCS file.
1893: my $headrev = $curbranch || "1";
1894: ($symrev{"MAIN"} = $headrev) =~ s/(\.?)(\d+)$/${1}0.$2/;
1.1 jfieber 1895: revision:
1.45.2.46 knu 1896: foreach $rev (@revorder) {
1897: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
1898: $symrev{"HEAD"} = $rev;
1.1 jfieber 1899: last revision;
1900: }
1901: }
1.45.2.46 knu 1902: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
1903: if (!defined($symrev{"HEAD"}));
1.1 jfieber 1904: print "Done finding HEAD\n" if ($verbose);
1905: #
1906: # Now that we know all of the revision numbers, we can associate
1907: # absolute revision numbers with all of the symbolic names, and
1908: # pass them to the form so that the same association doesn't have
1909: # to be built then.
1910: #
1.45.2.46 knu 1911: undef @branchnames;
1912: undef %branchpoint;
1913: undef $sel;
1914:
1915: foreach (reverse sort keys %symrev) {
1.1 jfieber 1916: $rev = $symrev{$_};
1.45.2.46 knu 1917: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
1.7 fenner 1918: push(@branchnames, $_);
1.1 jfieber 1919: #
1920: # A revision number of A.B.0.D really translates into
1921: # "the highest current revision on branch A.B.D".
1922: #
1923: # If there is no branch A.B.D, then it translates into
1924: # the head A.B .
1925: #
1.45.2.46 knu 1926: # This reasoning also applies to the main branch A.B,
1927: # with the branch number 0.A, with the exception that
1928: # it has no head to translate to if there is nothing on
1929: # the branch, but I guess this can never happen?
1930: # (the code below gracefully forgets about the branch
1931: # if it should happen)
1932: #
1933: $head = defined($2) ? $2 : "";
1.1 jfieber 1934: $branch = $3;
1.45.2.46 knu 1935: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
1936: my $regex;
1937: ($regex = $branchrev) =~ s/\./\\./g;
1.1 jfieber 1938: $rev = $head;
1939:
1940: revision:
1.45.2.46 knu 1941: foreach my $r (@revorder) {
1942: if ($r =~ /^${regex}\b/) {
1943: $rev = $branchrev;
1.1 jfieber 1944: last revision;
1945: }
1946: }
1.45.2.46 knu 1947: next if ($rev eq "");
1948: if ($rev ne $head && $head ne "") {
1.8 fenner 1949: $branchpoint{$head} .= ", " if ($branchpoint{$head});
1950: $branchpoint{$head} .= $_;
1951: }
1.1 jfieber 1952: }
1.45.2.46 knu 1953: $revsym{$rev} .= ", " if ($revsym{$rev});
1954: $revsym{$rev} .= $_;
1.1 jfieber 1955: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
1956: }
1957: print "Done associating revisions with branches\n" if ($verbose);
1.45.2.46 knu 1958:
1959: my ($onlyonbranch, $onlybranchpoint);
1960: if ($onlyonbranch = $input{'only_with_tag'}) {
1961: $onlyonbranch = $symrev{$onlyonbranch};
1962: if ($onlyonbranch =~ s/\b0\.//) {
1963: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
1964: }
1965: else {
1966: $onlybranchpoint = $onlyonbranch;
1967: }
1968: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
1969: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
1970: }
1.8 fenner 1971: }
1.1 jfieber 1972:
1.45.2.46 knu 1973: undef @revisions;
1974:
1975: foreach (@allrevisions) {
1.7 fenner 1976: ($br = $_) =~ s/\.\d+$//;
1.45.2.46 knu 1977: ($brp = $br) =~ s/\.\d+$//;
1.7 fenner 1978: next if ($onlyonbranch && $br ne $onlyonbranch &&
1.45.2.46 knu 1979: $_ ne $onlybranchpoint);
1980: unshift(@revisions,$_);
1981: }
1982:
1983: if ($logsort eq "date") {
1984: # Sort the revisions in commit order an secondary sort on revision
1985: # (secondary sort needed for imported sources, or the first main
1986: # revision gets before the same revision on the 1.1.1 branch)
1987: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
1988: }
1989: elsif ($logsort eq "rev") {
1990: # Sort the revisions in revision order, highest first
1991: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
1992: }
1993: else {
1994: # No sorting. Present in the same order as rlog / cvs log
1995: @revdisplayorder = @revisions;
1996: }
1997:
1998: }
1999:
2000: sub printLog($;$) {
2001: my ($link, $br, $brp);
2002: ($_,$link) = @_;
2003: ($br = $_) =~ s/\.\d+$//;
2004: ($brp = $br) =~ s/\.?\d+$//;
2005: my ($isDead, $prev);
2006:
2007: $link = 1 if (!defined($link));
2008: $isDead = ($state{$_} eq "dead");
2009:
2010: if ($link && !$isDead) {
2011: my ($filename);
2012: ($filename = $where) =~ s/^.*\///;
2013: my ($fileurl) = urlencode($filename);
1.4 fenner 2014: print "<a NAME=\"rev$_\"></a>";
1.45.2.46 knu 2015: if (defined($revsym{$_})) {
2016: foreach my $sym (split(", ", $revsym{$_})) {
2017: print "<a NAME=\"$sym\"></a>";
2018: }
1.4 fenner 2019: }
1.45.2.46 knu 2020: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
2021: foreach my $sym (split(", ", $revsym{$br})) {
1.4 fenner 2022: print "<a NAME=\"$sym\"></a>";
2023: }
1.45.2.46 knu 2024: $nameprinted{$br} = 1;
1.4 fenner 2025: }
1.45.2.46 knu 2026: print "\n Revision ";
2027: &download_link($fileurl, $_, $_,
2028: $defaultViewable ? "text/x-cvsweb-markup" : undef);
2029: if ($defaultViewable) {
2030: print " / ";
2031: &download_link($fileurl, $_, "(download)", $mimetype);
2032: }
2033: if (not $defaultTextPlain) {
2034: print " / ";
1.45.2.47 knu 2035: &download_link($fileurl, $_, "(as text)",
1.45.2.46 knu 2036: "text/plain");
2037: }
2038: if (!$defaultViewable) {
2039: print " / ";
2040: &download_link($fileurl, $_, "(view)", "text/x-cvsweb-markup");
2041: }
2042: if ($allow_annotate) {
2043: print " - <a href=\"" . $scriptname . "/" . urlencode($where) . "?annotate=$_$barequery\">";
2044: print "annotate</a>";
2045: }
2046: # Plus a select link if enabled, and this version isn't selected
2047: if ($allow_version_select) {
2048: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
2049: print " - <A HREF=\"${scriptwhere}?r1=$_$barequery" .
2050: "\">[select for diffs]</A>\n";
2051: }
2052: else {
2053: print " - <b>[selected]</b>";
2054: }
2055: }
2056: }
2057: else {
2058: print "Revision <B>$_</B>";
2059: }
2060: if (/^1\.1\.1\.\d+$/) {
2061: print " <i>(vendor branch)</i>";
2062: }
2063: if (defined @mytz) {
2064: my ($est) = $mytz[(localtime($date{$_}))[8]];
2065: print ", <i>" . scalar localtime($date{$_}) . " $est</i> (";
2066: } else {
2067: print ", <i>" . scalar gmtime($date{$_}) . " UTC</i> (";
2068: }
2069: print readableTime(time() - $date{$_},1) . " ago)";
2070: print " by ";
2071: print "<i>" . $author{$_} . "</i>\n";
2072: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
2073: if ($revsym{$br});
2074: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
2075: if ($revsym{$_});
2076: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
2077: if ($branchpoint{$_});
2078: # Find the previous revision
2079: my @prevrev = split(/\./, $_);
2080: do {
2081: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 2082: # If it was X.Y.Z.1, just make it X.Y
1.45.2.46 knu 2083: pop(@prevrev);
2084: pop(@prevrev);
2085: }
2086: $prev = join(".", @prevrev);
2087: } until (defined($date{$prev}) || $prev eq "");
2088: if ($prev ne "") {
2089: if ($difflines{$_}) {
2090: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
2091: }
2092: }
2093: if ($isDead) {
2094: print "<BR><B><I>FILE REMOVED</I></B>\n";
2095: }
2096: elsif ($link) {
2097: my %diffrev = ();
2098: $diffrev{$_} = 1;
2099: $diffrev{""} = 1;
2100: print "<BR>Diff";
2101: #
2102: # Offer diff to previous revision
2103: if ($prev) {
2104: $diffrev{$prev} = 1;
2105: print " to previous <A HREF=\"${scriptwhere}.diff?r1=$prev";
2106: print "&r2=$_" . $barequery . "\">$prev</A>\n";
2107: if (!$hr_default) { # offer a human readable version if not default
2108: print "(<A HREF=\"${scriptwhere}.diff?r1=$prev";
2109: print "&r2=$_" . $barequery . "&f=h\">colored</A>)\n";
1.1 jfieber 2110: }
2111: }
1.45.2.46 knu 2112: #
2113: # Plus, if it's on a branch, and it's not a vendor branch,
2114: # offer a diff with the branch point.
2115: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
2116: print " to branchpoint <A HREF=\"${scriptwhere}.diff?r1=$brp";
2117: print "&r2=$_" . $barequery . "\">$brp</A>\n";
2118: if (!$hr_default) { # offer a human readable version if not default
2119: print "(<A HREF=\"${scriptwhere}.diff?r1=$brp";
2120: print "&r2=$_" . $barequery . "&f=h\">colored</A>)\n";
2121: }
2122: }
2123: #
2124: # Plus, if it's on a branch, and it's not a vendor branch,
2125: # offer to diff with the next revision of the higher branch.
2126: # (e.g. change gets committed and then brought
2127: # over to -stable)
2128: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2129: my ($i,$nextmain);
2130: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
2131: my (@tmp2) = split(/\./, $_);
2132: for ($nextmain = ""; $i > 0; $i--) {
2133: my ($next) = $revorder[$i-1];
2134: my (@tmp1) = split(/\./, $next);
1.1 jfieber 2135: if ($#tmp1 < $#tmp2) {
1.45.2.46 knu 2136: $nextmain = $next;
2137: last;
2138: }
2139: # Only the highest version on a branch should have
2140: # a diff for the "next main".
2141: last if (join(".",@tmp1[0..$#tmp1-1])
2142: eq join(".",@tmp2[0..$#tmp1-1]));
2143: }
2144: if (!defined($diffrev{$nextmain})) {
2145: $diffrev{$nextmain} = 1;
2146: print " next main <A HREF=\"${scriptwhere}.diff?r1=$nextmain";
2147: print "&r2=$_" . $barequery .
2148: "\">$nextmain</A>\n";
2149: if (!$hr_default) { # offer a human readable version if not default
2150: print "(<A HREF=\"${scriptwhere}.diff?r1=$nextmain";
2151: print "&r2=$_" . $barequery .
2152: "&f=h\">colored</A>)\n";
1.1 jfieber 2153: }
2154: }
2155: }
1.45.2.46 knu 2156: # Plus if user has selected only r1, then present a link
2157: # to make a diff to that revision
2158: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2159: $diffrev{$input{"r1"}} = 1;
2160: print " to selected <A HREF=\"${scriptwhere}.diff?"
2161: . "r1=$input{'r1'}&r2=$_" . $barequery
2162: . "\">$input{'r1'}</A>\n";
2163: if (!$hr_default) { # offer a human readable version if not default
2164: print "(<A HREF=\"${scriptwhere}.diff?r1=$input{'r1'}";
2165: print "&r2=$_" . $barequery .
2166: "&f=h\">colored</A>)\n";
2167:
2168: }
1.9 fenner 2169: }
1.1 jfieber 2170: }
1.45.2.46 knu 2171: print "<PRE>\n";
2172: print &htmlify($log{$_}, 1);
2173: print "</PRE>\n";
2174: }
2175:
1.45.2.47 knu 2176: sub doLog($) {
1.45.2.46 knu 2177: my($fullname) = @_;
2178: my ($diffrev, $upwhere, $filename, $backurl);
1.45.2.47 knu 2179:
1.45.2.46 knu 2180: readLog($fullname);
2181:
2182: html_header("CVS log for $where");
2183: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2184: ($filename = $where) =~ s|^.*/||;
2185: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2186: print &link($backicon, "$backurl#$filename"),
2187: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
2188: print <<EOF;
2189: <A HREF="#diff">Request diff between arbitrary revisions</A>
2190: <HR NOSHADE>
2191: EOF
2192: if ($curbranch) {
2193: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
2194: }
2195: else {
2196: print "No default branch";
2197: }
2198: print "<BR>\n";
2199: if ($input{only_with_tag}) {
2200: print "Current tag: $input{only_with_tag}<BR>\n";
2201: }
2202:
2203: undef %nameprinted;
2204:
2205: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2206: print "<HR size=1 NOSHADE>";
2207: printLog($revdisplayorder[$i]);
2208: }
2209:
2210: print "<HR NOSHADE>";
1.1 jfieber 2211: print "<A NAME=diff>\n";
2212: print "This form allows you to request diff's between any two\n";
2213: print "revisions of a file. You may select a symbolic revision\n";
2214: print "name using the selection box or you may type in a numeric\n";
2215: print "name using the type-in text box.\n";
2216: print "</A><P>\n";
1.45.2.46 knu 2217: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2218: foreach (@stickyvars) {
2219: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
2220: if (defined($input{$_})
1.45.2.51 knu 2221: && ((!defined($DEFAULTVALUE{$_})
2222: || $input{$_} ne $DEFAULTVALUE{$_})
2223: && $input{$_} ne ""));
1.45.2.46 knu 2224: }
1.45.2.51 knu 2225: print "<TABLE><TR>\n";
2226: print "<TD align=right>Diffs between \n";
1.1 jfieber 2227: print "<SELECT NAME=\"r1\">\n";
2228: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2229: print $sel;
2230: print "</SELECT>\n";
1.45.2.46 knu 2231: $diffrev = $revdisplayorder[$#revdisplayorder];
2232: $diffrev = $input{"r1"} if (defined($input{"r1"}));
1.45.2.51 knu 2233: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
2234: print "<TD><BR></TD></TR>\n";
2235: print "<TR><TD align=right>and \n";
1.1 jfieber 2236: print "<SELECT NAME=\"r2\">\n";
2237: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2238: print $sel;
2239: print "</SELECT>\n";
1.45.2.46 knu 2240: $diffrev = $revdisplayorder[0];
2241: $diffrev = $input{"r2"} if (defined($input{"r2"}));
1.45.2.51 knu 2242: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
2243: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Get Diffs \"></TD>\n";
1.1 jfieber 2244: print "</FORM>\n";
1.45.2.51 knu 2245: print "</TR></TABLE>\n";
1.7 fenner 2246: print "<HR noshade>\n";
1.45.2.51 knu 2247: print "<TABLE>";
2248: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
2249: print "<TR><TD align=right>Preferred Diff type:</TD>";
2250: print "<TD>";
2251: printDiffSelect($use_java_script);
2252: print "</TD><TD></TD></TR>\n";
1.45.2.46 knu 2253: if (@branchnames) {
1.45.2.51 knu 2254: print "<TR><TD align=right>View only Branch:</TD>";
2255: print "<TD>";
1.45.2.46 knu 2256: print "<A name=branch></A>\n";
2257: print "<SELECT NAME=\"only_with_tag\"";
2258: print " onchange=\"submit()\"" if ($use_java_script);
2259: print ">\n";
2260: print "<OPTION VALUE=\"\"";
2261: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2262: $input{"only_with_tag"} eq "");
2263: print ">Show all branches\n";
2264: foreach (reverse sort @branchnames) {
1.9 fenner 2265: print "<OPTION";
1.45.2.46 knu 2266: print " SELECTED" if (defined($input{"only_with_tag"})
2267: && $input{"only_with_tag"} eq $_);
1.9 fenner 2268: print ">${_}\n";
1.45.2.46 knu 2269: }
1.45.2.51 knu 2270: print "</SELECT></TD><TD></TD></TR>\n";
1.7 fenner 2271: }
1.45.2.46 knu 2272: foreach (@stickyvars) {
1.45.2.51 knu 2273: next if ($_ eq "f");
1.45.2.46 knu 2274: next if ($_ eq "only_with_tag");
2275: next if ($_ eq "logsort");
2276: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
1.45.2.51 knu 2277: if (defined($input{$_})
2278: && (!defined($DEFAULTVALUE{$_})
2279: || $input{$_} ne $DEFAULTVALUE{$_})
1.45.2.46 knu 2280: && $input{$_} ne "");
2281: }
1.45.2.51 knu 2282: print "<TR><TD align=right>";
2283: print "<A name=logsort></A>\n";
2284: print "Sort log by:</TD>";
2285: print "<TD><SELECT NAME=\"logsort\"";
1.45.2.46 knu 2286: print " onchange=\"submit()\"" if ($use_java_script);
2287: print ">\n";
2288: print "<OPTION VALUE=cvs",$logsort eq "cvs" ? " SELECTED" : "", ">Not sorted";
2289: print "<OPTION VALUE=date",$logsort eq "date" ? " SELECTED" : "", ">Commit date";
2290: print "<OPTION VALUE=rev",$logsort eq "rev" ? " SELECTED" : "", ">Revision";
1.45.2.51 knu 2291: print "</SELECT></TD>";
2292: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Set \"></TD>";
1.7 fenner 2293: print "</FORM>\n";
1.45.2.51 knu 2294: print "</TR></TABLE>";
1.2 jfieber 2295: print &html_footer;
1.1 jfieber 2296: print "</BODY></HTML>\n";
1.10 wosch 2297: }
2298:
1.45.2.47 knu 2299: sub flush_diff_rows($$$$) {
1.45.2.46 knu 2300: my $j;
2301: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2302: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2303: for ($j = 0 ; $j < $leftRow; $j++) {
2304: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2305: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2306: }
2307: }
2308: elsif ($state eq "PreChange") { # state eq "PreChange"
2309: # we got removes with subsequent adds
2310: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2311: print "<tr>";
2312: if ($j < $leftRow) {
2313: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2314: }
2315: else {
2316: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2317: }
2318: if ($j < $rightRow) {
2319: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2320: }
2321: else {
2322: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2323: }
2324: print "</tr>\n";
2325: }
2326: }
2327: }
2328:
2329: ##
2330: # Function to generate Human readable diff-files
2331: # human_readable_diff(String revision_to_return_to);
2332: ##
2333: sub human_readable_diff($){
1.45.2.51 knu 2334: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
1.45.2.46 knu 2335: my ($fh, $rev) = @_;
2336: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2337: my (@rightCol, @leftCol);
2338:
2339: ($where_nd = $where) =~ s/.diff$//;
2340: ($filename = $where_nd) =~ s/^.*\///;
2341: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2342: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2343:
1.45.2.47 knu 2344: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
1.45.2.46 knu 2345:
2346: # Read header to pick up read revision and date, if possible
2347: while (<$fh>) {
2348: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2349: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2350: last if (/^\+\+\+ /);
2351: }
2352: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2353: $rev1 = $r1r;
2354: $date1 = $r1d;
2355: }
2356: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2357: $rev2 = $r2r;
2358: $date2 = $r2d;
2359: }
1.45.2.47 knu 2360:
1.45.2.46 knu 2361: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n";
2362:
2363: print "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n";
2364: print "<tr bgcolor=\"#ffffff\">\n";
2365: print "<th width=\"50%\" valign=TOP>";
2366: print "version $rev1";
2367: print ", $date1" if (defined($date1));
2368: print "<br>Tag: $sym1\n" if ($sym1);
2369: print "</th>\n";
2370: print "<th width=\"50%\" valign=TOP>";
2371: print "version $rev2";
2372: print ", $date2" if (defined($date2));
2373: print "<br>Tag: $sym2\n" if ($sym1);
2374: print "</th>\n";
2375:
2376: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\">";
2377: my $fe = "</font>";
2378:
2379: my $leftRow = 0;
2380: my $rightRow = 0;
2381: my ($oldline, $newline, $funname, $diffcode, $rest);
2382:
2383: # Process diff text
2384: # The diffrows are could make excellent use of
2385: # cascading style sheets because we've to set the
2386: # font and color for each row. anyone ...?
2387: ####
1.45.2.51 knu 2388:
2389: # prefetch several lines
2390: my @buf = head($fh);
2391:
2392: my %d = scan_directives(@buf);
2393:
2394: while (@buf || !eof($fh)) {
2395: $difftxt = @buf ? shift @buf : <$fh>;
1.45.2.47 knu 2396:
1.45.2.46 knu 2397: if ($difftxt =~ /^@@/) {
2398: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2399: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2400: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2401: print " <font size=-1>$funname</font></td></tr></table>";
2402: print "</td><td width=\"50%\">";
2403: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2404: print " <font size=-1>$funname</font></td></tr></table>";
2405: print "</td>\n";
2406: $state = "dump";
2407: $leftRow = 0;
2408: $rightRow = 0;
2409: }
2410: else {
2411: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
1.45.2.51 knu 2412: $_ = spacedHtmlText($rest, $d{'tabstop'});
1.45.2.46 knu 2413:
2414: # Add fontface, size
2415: $_ = "$fs $_$fe";
1.45.2.47 knu 2416:
1.45.2.46 knu 2417: #########
2418: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2419: # in order to get some nice 'ediff'-mode output
2420: # states:
2421: # "dump" - just dump the value
2422: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2423: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2424: ##########
2425:
2426: if ($diffcode eq '+') {
2427: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2428: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2429: }
2430: else { # we got minus before
2431: $state = "PreChange";
2432: $rightCol[$rightRow++] = $_;
2433: }
1.45.2.47 knu 2434: }
1.45.2.46 knu 2435: elsif ($diffcode eq '-') {
2436: $state = "PreChangeRemove";
2437: $leftCol[$leftRow++] = $_;
2438: }
2439: else { # empty diffcode
2440: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2441: print "<tr><td>$_</td><td>$_</td></tr>\n";
2442: $state = "dump";
2443: $leftRow = 0;
2444: $rightRow = 0;
2445: }
2446: }
2447: }
2448: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2449:
2450: # state is empty if we didn't have any change
2451: if (!$state) {
2452: print "<tr><td colspan=2> </td></tr>";
2453: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2454: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2455: }
2456: print "</table>";
2457: close($fh);
2458:
2459: print "<br><hr noshade width=\"100%\">\n";
2460:
2461: print "<table border=0>";
2462:
2463: print "<tr><td>";
2464: # print legend
2465: print "<table border=1><tr><td>";
2466: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2467: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2468: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2469: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2470: print "</table></td></tr></table>\n";
2471:
2472: print "<td>";
2473: # Print format selector
2474: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2475: foreach my $var (keys %input) {
2476: next if ($var eq "f");
2477: next if (defined($DEFAULTVALUE{$var})
2478: && $DEFAULTVALUE{$var} eq $input{$var});
2479: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2480: urlencode($input{$var}),"\">\n";
2481: }
2482: printDiffSelect($use_java_script);
2483: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2484: print "</FORM>\n";
2485: print "</td>";
2486:
2487: print "</tr></table>";
2488: }
2489:
1.45.2.47 knu 2490: sub navigateHeader($$$$$) {
1.45.2.46 knu 2491: my ($swhere,$path,$filename,$rev,$title) = @_;
2492: $swhere = "" if ($swhere eq $scriptwhere);
2493: $swhere = urlencode($filename) if ($swhere eq "");
2494: print "<\!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">";
2495: print "<HTML>\n<HEAD>\n";
1.45.2.54! knu 2496: print '<!-- CVSweb $zRevision: 1.103 $ $kRevision: 1.30 $ -->';
1.45.2.46 knu 2497: print "\n<TITLE>$path$filename - $title - $rev</TITLE></HEAD>\n";
1.45.2.52 knu 2498: print "$body_tag_for_src\n";
1.45.2.46 knu 2499: print "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$navigationHeaderColor\">";
2500: print "<tr valign=bottom><td>";
2501: print "<a href=\"$swhere$query#rev$rev\">$backicon";
2502: print "</a> <b>Return to ", &link("$filename","$swhere$query#rev$rev")," CVS log";
2503: print "</b> $fileicon</td>";
1.45.2.47 knu 2504:
1.45.2.46 knu 2505: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2506: print "</tr></table>";
2507: }
2508:
1.45.2.47 knu 2509: sub plural_write($$) {
1.45.2.46 knu 2510: my ($num,$text) = @_;
2511: if ($num != 1) {
2512: $text = $text . "s";
2513: }
2514: if ($num > 0) {
2515: return $num . " " . $text;
2516: }
2517: else {
2518: return "";
2519: }
2520: }
2521:
2522: ##
2523: # print readable timestamp in terms of
2524: # '..time ago'
2525: # H. Zeller <zeller@think.de>
2526: ##
1.45.2.47 knu 2527: sub readableTime($$) {
1.45.2.46 knu 2528: my ($i, $break, $retval);
2529: my ($secs,$long) = @_;
2530:
2531: # this function works correct for time >= 2 seconds
2532: if ($secs < 2) {
2533: return "very little time";
2534: }
2535:
2536: my %desc = (1 , 'second',
2537: 60, 'minute',
2538: 3600, 'hour',
2539: 86400, 'day',
2540: 604800, 'week',
2541: 2628000, 'month',
2542: 31536000, 'year');
2543: my @breaks = sort {$a <=> $b} keys %desc;
2544: $i = 0;
1.45.2.47 knu 2545: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
1.45.2.46 knu 2546: $i++;
2547: }
2548: $i--;
2549: $break = $breaks[$i];
2550: $retval = plural_write(int ($secs / $break), $desc{$break});
2551:
2552: if ($long == 1 && $i > 0) {
2553: my $rest = $secs % $break;
2554: $i--;
2555: $break = $breaks[$i];
1.45.2.47 knu 2556: my $resttime = plural_write(int ($rest / $break),
1.45.2.46 knu 2557: $desc{$break});
2558: if ($resttime) {
2559: $retval = $retval . ", " . $resttime;
2560: }
2561: }
2562:
2563: return $retval;
2564: }
2565:
2566: ##
2567: # clickablePath(String pathname, boolean last_item_clickable)
2568: #
2569: # returns a html-ified path whereas each directory is a link for
2570: # faster navigation. last_item_clickable controls whether the
2571: # basename (last directory/file) is a link as well
2572: ##
2573: sub clickablePath($$) {
1.45.2.47 knu 2574: my ($pathname,$clickLast) = @_;
1.45.2.46 knu 2575: my $retval = '';
1.45.2.47 knu 2576:
1.45.2.46 knu 2577: if ($pathname eq '/') {
2578: # this should never happen - chooseCVSRoot() is
2579: # intended to do this
2580: $retval = "[$cvstree]";
2581: }
2582: else {
2583: $retval = $retval . " <a href=\"${scriptname}/${query}#dirlist\">[$cvstree]</a>";
2584: my $wherepath = '';
2585: my ($lastslash) = $pathname =~ m|/$|;
2586: foreach (split(/\//, $pathname)) {
2587: $retval = $retval . " / ";
2588: $wherepath = $wherepath . '/' . $_;
2589: my ($last) = "$wherepath/" eq "/$pathname"
2590: || $wherepath eq "/$pathname";
2591: if ($clickLast || !$last) {
2592: $retval = $retval . "<a href=\"${scriptname}"
2593: . urlencode($wherepath)
2594: . (!$last || $lastslash ? '/' : '')
2595: . ${query}
2596: . (!$last || $lastslash ? "#dirlist" : "")
2597: . "\">$_</a>";
2598: }
2599: else { # do not make a link to the current dir
2600: $retval = $retval . $_;
2601: }
2602: }
2603: }
2604: return $retval;
2605: }
2606:
2607: sub chooseCVSRoot() {
2608: my @foo;
2609: foreach (sort keys %CVSROOT) {
2610: if (-d $CVSROOT{$_}) {
2611: push(@foo, $_);
2612: }
2613: }
2614: if (@foo > 1) {
2615: my ($k);
2616: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2617: foreach $k (keys %input) {
1.45.2.47 knu 2618: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
1.45.2.46 knu 2619: if ($input{$k}) && ($k ne "cvsroot");
2620: }
2621: # Form-Elements look wierd in Netscape if the background
2622: # isn't gray and the form elements are not placed
2623: # within a table ...
2624: print "<table><tr>";
2625: print "<td>CVS Root:</td>";
2626: print "<td>\n<select name=\"cvsroot\"";
2627: print " onchange=\"submit()\"" if ($use_java_script);
2628: print ">\n";
2629: foreach $k (@foo) {
2630: print "<option value=\"$k\"";
2631: print " selected" if ($k eq $cvstree);
2632: print ">" . ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} :
2633: $k). "</option>\n";
2634: }
2635: print "</select>\n</td>";
2636: print "<td><input type=submit value=\"Go\"></td>";
2637: print "</tr></table></form>";
2638: }
2639: else {
2640: # no choice ..
2641: print "CVS Root: <b>[$cvstree]</b>";
2642: }
2643: }
2644:
2645: sub chooseMirror() {
2646: my ($mirror,$moremirrors);
2647: $moremirrors = 0;
2648: # This code comes from the original BSD-cvsweb
2649: # and may not be useful for your site; If you don't
2650: # set %MIRRORS this won't show up, anyway
2651: #
1.45.2.47 knu 2652: # Should perhaps exlude the current site somehow..
1.45.2.46 knu 2653: if (keys %MIRRORS) {
2654: print "\nThis cvsweb is mirrored in:\n";
2655: foreach $mirror (keys %MIRRORS) {
2656: print ", " if ($moremirrors);
2657: print qq(<a href="$MIRRORS{$mirror}">$mirror</A>\n);
2658: $moremirrors = 1;
2659: }
2660: print "<p>\n";
2661: }
2662: }
2663:
1.45.2.47 knu 2664: sub fileSortCmp() {
1.45.2.46 knu 2665: my ($comp) = 0;
2666: my ($c,$d,$af,$bf);
2667:
2668: ($af = $a) =~ s/,v$//;
2669: ($bf = $b) =~ s/,v$//;
2670: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2671: if (defined($fileinfo{$af}));
2672: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2673: if (defined($fileinfo{$bf}));
2674:
2675: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2676: # Two files
2677: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2678: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2679: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2680: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2681: }
2682: if ($comp == 0) {
2683: # Directories first, then sorted on name if no other sort critera
2684: # available.
2685: my $ad = ((-d "$fullname/$a")?"D":"F");
2686: my $bd = ((-d "$fullname/$b")?"D":"F");
2687: ($c=$a) =~ s|.*/||;
2688: ($d=$b) =~ s|.*/||;
2689: $comp = ("$ad$c" cmp "$bd$d");
2690: }
2691: return $comp;
2692: }
2693:
2694: # make A url for downloading
1.45.2.47 knu 2695: sub download_url($$;$) {
1.45.2.46 knu 2696: my ($url,$revision,$mimetype) = @_;
2697:
2698: $revision =~ s/\b0\.//;
2699:
2700: if (defined($checkout_magic)
2701: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
2702: my ($path);
2703: ($path = $where) =~ s|/[^/]*$|/|;
2704: $url = "$scriptname/$checkoutMagic/${path}$url";
2705: }
2706: $url .= "?rev=$revision";
2707: $url .= "&content-type=$mimetype" if (defined($mimetype));
2708:
2709: return $url;
2710: }
2711:
1.45.2.47 knu 2712: # Presents a link to download the
1.45.2.46 knu 2713: # selected revision
1.45.2.47 knu 2714: sub download_link($$$;$) {
1.45.2.46 knu 2715: my ($url,$revision,$textlink,$mimetype) = @_;
2716: my ($fullurl) = download_url($url,$revision,$mimetype);
2717: my ($paren) = $textlink =~ /^\(/;
2718: $textlink =~ s/^\(// if ($paren);
2719: $textlink =~ s/\)$// if ($paren);
2720: print "(" if ($paren);
2721: print "<A HREF=\"$fullurl";
2722: print $barequery;
2723: print "\"";
2724: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
2725: print " target=\"cvs_checkout\"";
2726: # we should have
2727: # 'if (document.cvswin==null) document.cvswin=window.open(...'
2728: # in order to allow the user to resize the window; otherwise
2729: # the user may resize the window, but on next checkout - zap -
2730: # its original (configured s. cvsweb.conf) size is back again
2731: # .. annoying (if $extern_window_(width|height) is defined)
2732: # but this if (..) solution is far from perfect
2733: # what we need to do as well is
2734: # 1) save cvswin in an invisible frame that always exists
2735: # (document.cvswin will be void on next load)
2736: # 2) on close of the cvs_checkout - window set the cvswin
2737: # variable to 'null' again - so that it will be
2738: # reopenend with the configured size
2739: # anyone a JavaScript programmer ?
2740: # .. so here without if (..):
2741: # currently, the best way is to comment out the size parameters
2742: # ($extern_window...) in cvsweb.conf.
2743: if ($use_java_script) {
2744: print " onClick=\"window.open('$fullurl','cvs_checkout',";
2745: print "'resizeable,scrollbars";
2746: print ",status,toolbar" if (defined($mimetype)
2747: && $mimetype eq "text/html");
2748: print ",width=$extern_window_width" if (defined($extern_window_width));
2749: print ",height=$extern_window_height" if (defined($extern_window_height));
2750: print"');\"";
2751: }
2752: }
2753: print "><b>$textlink</b></A>";
2754: print ")" if ($paren);
2755: }
2756:
2757: # Returns a Query string with the
2758: # specified parameter toggled
2759: sub toggleQuery($$) {
2760: my ($toggle,$value) = @_;
2761: my ($newquery,$var);
2762: my (%vars);
2763: %vars = %input;
2764: if (defined($value)) {
2765: $vars{$toggle} = $value;
2766: }
2767: else {
2768: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
2769: }
2770: # Build a new query of non-default paramenters
2771: $newquery = "";
2772: foreach $var (@stickyvars) {
2773: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
2774: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
2775: if ($value ne $default) {
2776: $newquery .= "&" if ($newquery ne "");
2777: $newquery .= urlencode($var) . "=" . urlencode($value);
2778: }
2779: }
2780: if ($newquery) {
2781: return '?' . $newquery;
2782: }
2783: return "";
2784: }
2785:
1.45.2.47 knu 2786: sub urlencode($) {
1.45.2.46 knu 2787: my ($in) = @_;
2788: my ($out);
2789: ($out = $in) =~ s/([\000-+{-\377])/sprintf("%%%02x", ord($1))/ge;
2790: return $out;
2791: }
2792:
1.45.2.47 knu 2793: sub http_header(;$) {
1.45.2.46 knu 2794: my $content_type = shift || "text/html";
2795: if (defined($moddate)) {
2796: if ($is_mod_perl) {
1.45.2.51 knu 2797: Apache->request->header_out("Last-Modified" => scalar gmtime($moddate) . " GMT");
1.45.2.46 knu 2798: }
2799: else {
2800: print "Last-Modified: " . scalar gmtime($moddate) . " GMT\r\n";
2801: }
2802: }
2803: if ($is_mod_perl) {
2804: Apache->request->content_type($content_type);
2805: }
2806: else {
2807: print "Content-type: $content_type\r\n";
2808: }
2809: if ($allow_compress && $maycompress) {
1.45.2.51 knu 2810: if ($has_zlib || (defined($GZIPBIN) && open(GZIP, "|$GZIPBIN -1 -c"))) {
1.45.2.46 knu 2811: if ($is_mod_perl) {
2812: Apache->request->content_encoding("x-gzip");
2813: Apache->request->header_out(Vary => "Accept-Encoding");
2814: Apache->request->send_http_header;
2815: }
2816: else {
2817: print "Content-encoding: x-gzip\r\n";
2818: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
2819: print "\r\n"; # Close headers
2820: }
2821: $| = 1; $| = 0; # Flush header output
1.45.2.51 knu 2822: if ($has_zlib) {
2823: tie *GZIP, __PACKAGE__, \*STDOUT;
2824: }
2825: select(GZIP);
2826: $gzip_open = 1;
1.45.2.46 knu 2827: # print "<!-- gzipped -->" if ($content_type eq "text/html");
2828: }
2829: else {
2830: if ($is_mod_perl) {
2831: Apache->request->send_http_header;
2832: }
2833: else {
2834: print "\r\n"; # Close headers
2835: }
2836: print "<font size=-1>Unable to find gzip binary in the \$PATH to compress output</font><br>";
2837: }
2838: }
2839: else {
2840: if ($is_mod_perl) {
2841: Apache->request->send_http_header;
2842: }
2843: else {
2844: print "\r\n"; # Close headers
2845: }
2846: }
2847: }
2848:
2849: sub html_header($) {
2850: my ($title) = @_;
1.45.2.54! knu 2851: my $version = '$zRevision: 1.103 $ $kRevision: 1.30 $'; #'
1.45.2.46 knu 2852: http_header();
2853:
2854: (my $header = &cgi_style::html_header) =~ s/^.*\n\n//; # remove HTTP response header
2855:
2856: print <<EOH;
2857: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
2858: "http://www.w3.org/TR/REC-html40/loose.dtd">
2859: $header
2860: <!-- CVSweb $version -->
2861: EOH
2862: }
2863:
1.45.2.47 knu 2864: sub html_footer() {
1.45.2.46 knu 2865: return &cgi_style::html_footer;
2866: }
2867:
1.45.2.47 knu 2868: sub link_tags($) {
1.45.2.46 knu 2869: my ($tags) = @_;
2870: my ($ret) = "";
2871: my ($fileurl,$filename);
2872:
2873: ($filename = $where) =~ s/^.*\///;
2874: $fileurl = urlencode($filename);
2875:
2876: foreach my $sym (split(", ", $tags)) {
2877: $ret .= ",\n" if ($ret ne "");
2878: $ret .= "<A HREF=\"$fileurl"
2879: . toggleQuery('only_with_tag',$sym) . "\">$sym</A>";
2880: }
2881: return $ret."\n";
2882: }
2883:
2884: #
2885: # See if a module is listed in the config file's @HideModule list.
2886: #
1.45.2.47 knu 2887: sub forbidden_module($) {
1.45.2.46 knu 2888: my($module) = @_;
1.45.2.47 knu 2889:
1.45.2.46 knu 2890: for (my $i=0; $i < @HideModules; $i++) {
2891: return 1 if $module eq $HideModules[$i];
2892: }
2893:
2894: return 0;
1.45.2.52 knu 2895: }
2896:
2897: # Close the GZIP handle remove the tie.
2898:
2899: sub gzipclose {
2900: if ($gzip_open) {
2901: select(STDOUT);
2902: close(GZIP);
2903: untie *GZIP;
2904: $gzip_open = 0;
2905: }
1.45.2.51 knu 2906: }
2907:
2908: # implement a gzipped file handle via the Compress:Zlib compression
2909: # library.
2910:
2911: sub MAGIC1() { 0x1f }
2912: sub MAGIC2() { 0x8b }
2913: sub OSCODE() { 3 }
2914:
2915: sub TIEHANDLE {
2916: my ($class, $out) = @_;
2917: my ($d) = Compress::Zlib::deflateInit(-Level => Compress::Zlib::Z_BEST_COMPRESSION(),
2918: -WindowBits => -Compress::Zlib::MAX_WBITS()) or return undef;
2919: my ($o) = {
2920: handle => $out,
2921: dh => $d,
2922: crc => 0,
2923: len => 0,
2924: };
2925: my ($header) = pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0,0,0,0,0,0, OSCODE);
2926: print {$o->{handle}} $header;
2927: return bless($o, $class);
2928: }
2929:
2930: sub PRINT {
2931: my ($o) = shift;
2932: my ($buf) = join(defined $, ? $, : "",@_);
2933: my ($len) = length($buf);
2934: my ($compressed, $status) = $o->{dh}->deflate($buf);
2935: print {$o->{handle}} $compressed if defined($compressed);
2936: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
2937: $o->{len} += $len;
2938: return $len;
2939: }
2940:
2941: sub PRINTF {
2942: my ($o) = shift;
2943: my ($fmt) = shift;
2944: my ($buf) = sprintf($fmt, @_);
2945: my ($len) = length($buf);
2946: my ($compressed, $status) = $o->{dh}->deflate($buf);
2947: print {$o->{handle}} $compressed if defined($compressed);
2948: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
2949: $o->{len} += $len;
2950: return $len;
2951: }
2952:
2953: sub WRITE {
2954: my ($o, $buf, $len, $off) = @_;
2955: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
2956: print {$o->{handle}} $compressed if defined($compressed);
2957: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
2958: $o->{len} += $len;
2959: return $len;
2960: }
2961:
2962: sub CLOSE {
2963: my ($o) = @_;
2964: return if !defined( $o->{dh});
2965: my ($buf) = $o->{dh}->flush();
2966: $buf .= pack("V V", $o->{crc}, $o->{len});
2967: print {$o->{handle}} $buf;
2968: undef $o->{dh};
2969: }
2970:
2971: sub DESTROY {
2972: my ($o) = @_;
2973: CLOSE($o);
1.1 jfieber 2974: }
CVSweb