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