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