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