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