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