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