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