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