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