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