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