Annotation of cvsweb/cvsweb.cgi, Revision 3.53
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.53 ! knu 46: # $Id: cvsweb.cgi,v 3.52 2000/12/29 23:56:39 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{
3.53 ! knu 1150: (\b([a-zA-Z][\w.]+)
3.36 knu 1151: (?:
1152: \( ([0-9n]) \)\B
1153: |
1154: \.([0-9n])\b
1155: )
1156: )
1157: }{
3.53 ! knu 1158: &link($1, sprintf($mancgi, defined($3) ? $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:
3.53 ! knu 1828: if (defined($tag)) {
3.1 knu 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
3.53 ! knu 1846: $rev = '';
! 1847: $revwanted = '';
! 1848: $branch = '';
! 1849: $branchpoint = '';
! 1850: $filename = '';
! 1851: $log = '';
! 1852: $revision = '';
3.1 knu 1853: %symrev = ();
1854: @filetags = ();
1855: #jump to head state
1856: $state = "head";
1857: }
1858: print "$state:$_" if ($verbose);
1859: again:
1860: if ($state eq "head") {
1861: #$rcsfile = $1 if (/^RCS file: (.+)$/); #not used (yet)
3.41 knu 1862:
1863: if (/^Working file: (.+)$/) {
1864: $filename = $1;
1865: } elsif (/^head: (.+)$/) {
1866: $head = $1;
1867: } elsif (/^branch: (.+)$/) {
1868: $branch = $1
1869: } elsif (/^symbolic names:/) {
1870: $state = "tags";
3.53 ! knu 1871: ($branch = $head) =~ s/\.\d+$// if $branch eq '';
3.45 knu 1872: $branch =~ s/(\d+)$/0.$1/;
3.41 knu 1873: $symrev{MAIN} = $branch;
1874: $symrev{HEAD} = $branch;
1875: $alltags{MAIN} = 1;
1876: $alltags{HEAD} = 1;
1877: push (@filetags, "MAIN", "HEAD");
1878: } elsif (/$LOG_REVSEPARATOR/o) {
1879: $state = "log";
3.53 ! knu 1880: $rev = '';
! 1881: $date = '';
! 1882: $log = '';
3.41 knu 1883: # Try to reconstruct the relative filename if RCS spits out a full path
1884: $filename =~ s%^\Q$DirName\E/%%;
1885: }
3.1 knu 1886: next;
1887: }
3.41 knu 1888: if ($state eq "tags") {
1889: if (/^\s+(.+):\s+([\d\.]+)\s+$/) {
1890: push (@filetags, $1);
1891: $symrev{$1} = $2;
1892: $alltags{$1} = 1;
3.1 knu 1893: next;
3.41 knu 1894: } elsif (/^\S/) {
1895: if (defined($tag)) {
1896: if(defined($symrev{$tag}) || $tag eq "HEAD") {
1897: $revwanted = $symrev{$tag eq "HEAD" ? "MAIN" : $tag};
3.45 knu 1898: ($branch = $revwanted) =~ s/\b0\.//;
3.41 knu 1899: ($branchpoint = $branch) =~ s/\.?\d+$//;
3.53 ! knu 1900: $revwanted = '' if ($revwanted ne $branch);
3.41 knu 1901: } elsif ($tag ne "HEAD") {
1902: print "Tag not found, skip this file" if ($verbose);
1903: $state = "skip";
1904: next;
1905: }
1906: }
1907: foreach my $tagfound (@filetags) {
1908: $tags{$tagfound} = 1;
1909: }
1910: $state = "head";
1911: goto again;
3.1 knu 1912: }
1913: }
1914: if ($state eq "log") {
3.32 knu 1915: if (/$LOG_REVSEPARATOR/o || /$LOG_FILESEPARATOR/o) {
3.1 knu 1916: # End of a log entry.
3.53 ! knu 1917: my $revbranch = $rev;
! 1918: $revbranch =~ s/\.\d+$//;
3.36 knu 1919: print "$filename $rev Wanted: $revwanted ",
1920: "Revbranch: $revbranch Branch: $branch ",
1921: "Branchpoint: $branchpoint\n" if ($verbose);
3.53 ! knu 1922: if ($revwanted eq '' && $branch ne ''
3.1 knu 1923: && $branch eq $revbranch || !defined($tag)) {
1924: print "File revision $rev found for branch $branch\n"
1925: if ($verbose);
1926: $revwanted = $rev;
1927: }
3.53 ! knu 1928: if ($revwanted ne '' ? $rev eq $revwanted :
! 1929: $branchpoint ne '' ? $rev eq $branchpoint :
3.1 knu 1930: 0 && ($rev eq $head)) { # Don't think head is needed here..
1931: print "File info $rev found for $filename\n" if ($verbose);
1932: my @finfo = ($rev,$date,$log,$author,$filename);
1933: my ($name);
1934: ($name = $filename) =~ s%/.*%%;
1935: $fileinfo{$name} = [ @finfo ];
1936: $state = "done" if ($rev eq $revwanted);
1937: }
3.53 ! knu 1938: $rev = '';
! 1939: $date = '';
! 1940: $log = '';
3.1 knu 1941: }
3.53 ! knu 1942: elsif ($date eq '' && m|^date:\s+(\d+)/(\d+)/(\d+)\s+(\d+):(\d+):(\d+);|) {
3.1 knu 1943: my $yr = $1;
1944: # damn 2-digit year routines :-)
1945: if ($yr > 100) {
1946: $yr -= 1900;
1947: }
1948: $date = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1949: ($author) = /author: ([^;]+)/;
1950: $state = "log";
1951: $log = '';
1952: next;
1953: }
3.53 ! knu 1954: elsif ($rev eq '' && /^revision (.*)$/) {
3.1 knu 1955: $rev = $1;
1956: next;
1957: }
1958: else {
3.36 knu 1959: $log .= $_;
3.1 knu 1960: }
1961: }
3.32 knu 1962: if (/$LOG_FILESEPARATOR/o) {
3.1 knu 1963: $state = "start";
1964: next;
1965: }
1966: }
1967: if ($. == 0) {
3.12 knu 1968: fatal("500 Internal Error",
3.1 knu 1969: "Failed to spawn GNU rlog on <em>'".join(", ", @files)."'</em><p>did you set the <b>\$ENV{PATH}</b> in your configuration file correctly ?");
1970: }
1971: close($fh);
1972: }
1973:
3.12 knu 1974: sub readLog($;$) {
3.1 knu 1975: my($fullname,$revision) = @_;
1976: my ($symnames, $head, $rev, $br, $brp, $branch, $branchrev);
1977: my $fh = do {local(*FH);};
1978:
1979: if (defined($revision)) {
1980: $revision = "-r$revision";
1981: }
1982: else {
1983: $revision = "";
1984: }
1985:
1986: undef %symrev;
1987: undef %revsym;
1988: undef @allrevisions;
1989: undef %date;
1990: undef %author;
1991: undef %state;
1992: undef %difflines;
1993: undef %log;
1.12 fenner 1994:
1995: print("Going to rlog '$fullname'\n") if ($verbose);
3.1 knu 1996: if (! open($fh, "-|")) { # child
1997: if ($revision ne '') {
1998: exec("rlog",$revision,$fullname);
1999: }
2000: else {
2001: exec("rlog",$fullname);
2002: }
1.44 knu 2003: }
3.1 knu 2004: while (<$fh>) {
1.1 jfieber 2005: print if ($verbose);
2006: if ($symnames) {
2007: if (/^\s+([^:]+):\s+([\d\.]+)/) {
2008: $symrev{$1} = $2;
3.1 knu 2009: }
2010: else {
1.1 jfieber 2011: $symnames = 0;
2012: }
3.1 knu 2013: }
2014: elsif (/^head:\s+([\d\.]+)/) {
2015: $head = $1;
2016: }
2017: elsif (/^branch:\s+([\d\.]+)/) {
2018: $curbranch = $1;
2019: }
2020: elsif (/^symbolic names/) {
1.1 jfieber 2021: $symnames = 1;
3.1 knu 2022: }
2023: elsif (/^-----/) {
1.1 jfieber 2024: last;
2025: }
2026: }
3.1 knu 2027: ($curbranch = $head) =~ s/\.\d+$// if (!defined($curbranch));
1.7 fenner 2028:
1.1 jfieber 2029: # each log entry is of the form:
2030: # ----------------------------
2031: # revision 3.7.1.1
2032: # date: 1995/11/29 22:15:52; author: fenner; state: Exp; lines: +5 -3
2033: # log info
2034: # ----------------------------
2035: logentry:
3.32 knu 2036: while (!/$LOG_FILESEPARATOR/o) {
3.1 knu 2037: $_ = <$fh>;
1.12 fenner 2038: last logentry if (!defined($_)); # EOF
1.1 jfieber 2039: print "R:", $_ if ($verbose);
2040: if (/^revision ([\d\.]+)/) {
2041: $rev = $1;
3.1 knu 2042: unshift(@allrevisions,$rev);
2043: }
3.32 knu 2044: elsif (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o) {
1.1 jfieber 2045: next logentry;
3.1 knu 2046: }
2047: else {
1.12 fenner 2048: # The rlog output is syntactically ambiguous. We must
2049: # have guessed wrong about where the end of the last log
2050: # message was.
2051: # Since this is likely to happen when people put rlog output
2052: # in their commit messages, don't even bother keeping
2053: # these lines since we don't know what revision they go with
2054: # any more.
2055: next logentry;
2056: # &fatal("500 Internal Error","Error parsing RCS output: $_");
1.1 jfieber 2057: }
3.1 knu 2058: $_ = <$fh>;
1.1 jfieber 2059: print "D:", $_ if ($verbose);
3.1 knu 2060: 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+-]+))?|) {
2061: my $yr = $1;
2062: # damn 2-digit year routines :-)
2063: if ($yr > 100) {
2064: $yr -= 1900;
2065: }
2066: $date{$rev} = &Time::Local::timegm($6,$5,$4,$3,$2 - 1,$yr);
1.1 jfieber 2067: $author{$rev} = $7;
1.9 fenner 2068: $state{$rev} = $8;
3.1 knu 2069: $difflines{$rev} = $10;
2070: }
2071: else {
1.1 jfieber 2072: &fatal("500 Internal Error", "Error parsing RCS output: $_");
2073: }
2074: line:
3.1 knu 2075: while (<$fh>) {
1.1 jfieber 2076: print "L:", $_ if ($verbose);
2077: next line if (/^branches:\s/);
3.32 knu 2078: last line if (/$LOG_FILESEPARATOR/o || /$LOG_REVSEPARATOR/o);
1.1 jfieber 2079: $log{$rev} .= $_;
2080: }
2081: print "E:", $_ if ($verbose);
2082: }
3.1 knu 2083: close($fh);
1.1 jfieber 2084: print "Done reading RCS file\n" if ($verbose);
3.1 knu 2085:
2086: @revorder = reverse sort {revcmp($a,$b)} @allrevisions;
2087: print "Done sorting revisions",join(" ",@revorder),"\n" if ($verbose);
2088:
1.1 jfieber 2089: #
2090: # HEAD is an artificial tag which is simply the highest tag number on the main
1.8 fenner 2091: # branch, unless there is a branch tag in the RCS file in which case it's the
2092: # highest revision on that branch. Find it by looking through @revorder; it
2093: # is the first commit listed on the appropriate branch.
3.1 knu 2094: # This is not neccesary the same revision as marked as head in the RCS file.
2095: my $headrev = $curbranch || "1";
3.45 knu 2096: ($symrev{"MAIN"} = $headrev) =~ s/(\d+)$/0.$1/;
3.1 knu 2097: foreach $rev (@revorder) {
2098: if ($rev =~ /^(\S*)\.\d+$/ && $headrev eq $1) {
2099: $symrev{"HEAD"} = $rev;
3.41 knu 2100: last;
1.1 jfieber 2101: }
2102: }
3.1 knu 2103: ($symrev{"HEAD"} = $headrev) =~ s/\.\d+$//
2104: if (!defined($symrev{"HEAD"}));
1.1 jfieber 2105: print "Done finding HEAD\n" if ($verbose);
2106: #
2107: # Now that we know all of the revision numbers, we can associate
2108: # absolute revision numbers with all of the symbolic names, and
2109: # pass them to the form so that the same association doesn't have
2110: # to be built then.
2111: #
3.1 knu 2112: undef @branchnames;
2113: undef %branchpoint;
2114: undef $sel;
2115:
2116: foreach (reverse sort keys %symrev) {
1.1 jfieber 2117: $rev = $symrev{$_};
3.45 knu 2118: if ($rev =~ /^((.*)\.)?\b0\.(\d+)$/) {
1.7 fenner 2119: push(@branchnames, $_);
1.1 jfieber 2120: #
2121: # A revision number of A.B.0.D really translates into
2122: # "the highest current revision on branch A.B.D".
2123: #
2124: # If there is no branch A.B.D, then it translates into
2125: # the head A.B .
2126: #
3.1 knu 2127: # This reasoning also applies to the main branch A.B,
2128: # with the branch number 0.A, with the exception that
2129: # it has no head to translate to if there is nothing on
2130: # the branch, but I guess this can never happen?
3.38 knu 2131: #
3.45 knu 2132: # (the code below gracefully forgets about the branch
2133: # if it should happen)
3.1 knu 2134: #
2135: $head = defined($2) ? $2 : "";
1.1 jfieber 2136: $branch = $3;
3.1 knu 2137: $branchrev = $head . ($head ne "" ? "." : "") . $branch;
2138: my $regex;
3.41 knu 2139: $regex = quotemeta $branchrev;
1.1 jfieber 2140: $rev = $head;
2141:
3.1 knu 2142: foreach my $r (@revorder) {
2143: if ($r =~ /^${regex}\b/) {
2144: $rev = $branchrev;
3.41 knu 2145: last;
1.1 jfieber 2146: }
2147: }
3.1 knu 2148: next if ($rev eq "");
2149: if ($rev ne $head && $head ne "") {
1.8 fenner 2150: $branchpoint{$head} .= ", " if ($branchpoint{$head});
2151: $branchpoint{$head} .= $_;
2152: }
1.1 jfieber 2153: }
3.1 knu 2154: $revsym{$rev} .= ", " if ($revsym{$rev});
2155: $revsym{$rev} .= $_;
1.1 jfieber 2156: $sel .= "<OPTION VALUE=\"${rev}:${_}\">$_\n";
2157: }
2158: print "Done associating revisions with branches\n" if ($verbose);
3.1 knu 2159:
2160: my ($onlyonbranch, $onlybranchpoint);
2161: if ($onlyonbranch = $input{'only_with_tag'}) {
2162: $onlyonbranch = $symrev{$onlyonbranch};
3.45 knu 2163: if ($onlyonbranch =~ s/\b0\.//) {
3.1 knu 2164: ($onlybranchpoint = $onlyonbranch) =~ s/\.\d+$//;
2165: }
2166: else {
2167: $onlybranchpoint = $onlyonbranch;
2168: }
2169: if (!defined($onlyonbranch) || $onlybranchpoint eq "") {
2170: fatal("404 Tag not found","Tag $input{'only_with_tag'} not defined");
2171: }
1.8 fenner 2172: }
1.1 jfieber 2173:
3.1 knu 2174: undef @revisions;
2175:
2176: foreach (@allrevisions) {
1.7 fenner 2177: ($br = $_) =~ s/\.\d+$//;
3.1 knu 2178: ($brp = $br) =~ s/\.\d+$//;
1.7 fenner 2179: next if ($onlyonbranch && $br ne $onlyonbranch &&
3.1 knu 2180: $_ ne $onlybranchpoint);
2181: unshift(@revisions,$_);
2182: }
2183:
2184: if ($logsort eq "date") {
2185: # Sort the revisions in commit order an secondary sort on revision
2186: # (secondary sort needed for imported sources, or the first main
2187: # revision gets before the same revision on the 1.1.1 branch)
2188: @revdisplayorder = sort {$date{$b} <=> $date{$a} || -revcmp($a, $b)} @revisions;
2189: }
2190: elsif ($logsort eq "rev") {
2191: # Sort the revisions in revision order, highest first
2192: @revdisplayorder = reverse sort {revcmp($a,$b)} @revisions;
2193: }
2194: else {
2195: # No sorting. Present in the same order as rlog / cvs log
2196: @revdisplayorder = @revisions;
2197: }
2198:
2199: }
2200:
3.37 knu 2201: sub printDiffLinks($$) {
2202: my($text, $url) = @_;
2203: my @extra;
2204:
2205: local $_;
2206: for ($DIFFTYPES{$defaultDiffType}{'colored'} ? qw(u) : qw(h)) {
2207: my $f = $_ eq $defaultDiffType ? '' : $_;
2208:
2209: push @extra, &link(lc $DIFFTYPES{$_}{'descr'}, "$url&f=$f");
2210: }
2211:
2212: print &link($text, $url), ' (', join(', ', @extra), ')';
2213: }
2214:
3.1 knu 2215: sub printLog($;$) {
2216: my ($link, $br, $brp);
2217: ($_,$link) = @_;
2218: ($br = $_) =~ s/\.\d+$//;
2219: ($brp = $br) =~ s/\.?\d+$//;
2220: my ($isDead, $prev);
2221:
2222: $link = 1 if (!defined($link));
2223: $isDead = ($state{$_} eq "dead");
2224:
2225: if ($link && !$isDead) {
2226: my ($filename);
2227: ($filename = $where) =~ s/^.*\///;
2228: my ($fileurl) = urlencode($filename);
1.4 fenner 2229: print "<a NAME=\"rev$_\"></a>";
3.1 knu 2230: if (defined($revsym{$_})) {
2231: foreach my $sym (split(", ", $revsym{$_})) {
2232: print "<a NAME=\"$sym\"></a>";
2233: }
1.4 fenner 2234: }
3.1 knu 2235: if (defined($revsym{$br}) && $revsym{$br} && !defined($nameprinted{$br})) {
2236: foreach my $sym (split(", ", $revsym{$br})) {
1.4 fenner 2237: print "<a NAME=\"$sym\"></a>";
2238: }
3.1 knu 2239: $nameprinted{$br} = 1;
1.4 fenner 2240: }
3.1 knu 2241: print "\n Revision ";
2242: &download_link($fileurl, $_, $_,
3.35 knu 2243: $defaultViewable ? "text/x-cvsweb-markup" : undef);
3.1 knu 2244: if ($defaultViewable) {
3.35 knu 2245: print " / (";
2246: &download_link($fileurl, $_, "download", $mimetype);
2247: print ")";
3.1 knu 2248: }
2249: if (not $defaultTextPlain) {
3.35 knu 2250: print " / (";
2251: &download_link($fileurl, $_, "as text", "text/plain");
2252: print ")";
3.1 knu 2253: }
2254: if (!$defaultViewable) {
3.35 knu 2255: print " / (";
2256: &download_link($fileurl, $_, "view", "text/x-cvsweb-markup");
2257: print ")";
3.1 knu 2258: }
2259: if ($allow_annotate) {
3.35 knu 2260: print " - ";
2261: print &link('annotate',
2262: sprintf('%s/%s?annotate=%s%s',
2263: $scriptname,
2264: urlencode($where),
2265: $_,
2266: $barequery));
3.1 knu 2267: }
2268: # Plus a select link if enabled, and this version isn't selected
2269: if ($allow_version_select) {
2270: if ((!defined($input{"r1"}) || $input{"r1"} ne $_)) {
3.35 knu 2271: print " - ";
2272: print &link('[select for diffs]',
2273: sprintf('%s?r1=%s%s',
2274: $scriptwhere,
2275: $_,
2276: $barequery));
3.1 knu 2277: }
2278: else {
2279: print " - <b>[selected]</b>";
2280: }
2281: }
2282: }
2283: else {
2284: print "Revision <B>$_</B>";
2285: }
2286: if (/^1\.1\.1\.\d+$/) {
2287: print " <i>(vendor branch)</i>";
2288: }
2289: if (defined @mytz) {
2290: my ($est) = $mytz[(localtime($date{$_}))[8]];
3.36 knu 2291: print ", <i>", scalar localtime($date{$_}), " $est</i> (";
3.1 knu 2292: } else {
3.36 knu 2293: print ", <i>", scalar gmtime($date{$_}), " UTC</i> (";
3.1 knu 2294: }
3.36 knu 2295: print readableTime(time() - $date{$_},1), " ago)";
3.1 knu 2296: print " by ";
3.36 knu 2297: print "<i>", $author{$_}, "</i>\n";
3.1 knu 2298: print "<BR>Branch: <b>",$link?link_tags($revsym{$br}):$revsym{$br},"</b>\n"
2299: if ($revsym{$br});
2300: print "<BR>CVS Tags: <b>",$link?link_tags($revsym{$_}):$revsym{$_},"</b>"
2301: if ($revsym{$_});
2302: print "<BR>Branch point for: <b>",$link?link_tags($branchpoint{$_}):$branchpoint{$_},"</b>\n"
2303: if ($branchpoint{$_});
2304: # Find the previous revision
2305: my @prevrev = split(/\./, $_);
2306: do {
2307: if (--$prevrev[$#prevrev] <= 0) {
1.1 jfieber 2308: # If it was X.Y.Z.1, just make it X.Y
3.1 knu 2309: pop(@prevrev);
2310: pop(@prevrev);
2311: }
2312: $prev = join(".", @prevrev);
2313: } until (defined($date{$prev}) || $prev eq "");
2314: if ($prev ne "") {
2315: if ($difflines{$_}) {
2316: print "<BR>Changes since <b>$prev: $difflines{$_} lines</b>";
2317: }
2318: }
2319: if ($isDead) {
2320: print "<BR><B><I>FILE REMOVED</I></B>\n";
2321: }
2322: elsif ($link) {
2323: my %diffrev = ();
2324: $diffrev{$_} = 1;
2325: $diffrev{""} = 1;
2326: print "<BR>Diff";
2327: #
2328: # Offer diff to previous revision
2329: if ($prev) {
2330: $diffrev{$prev} = 1;
3.35 knu 2331:
2332: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2333: $scriptwhere,
2334: $prev,
2335: $_,
2336: $barequery);
2337:
2338: print " to previous ";
3.37 knu 2339: printDiffLinks($prev, $url);
3.1 knu 2340: }
2341: #
2342: # Plus, if it's on a branch, and it's not a vendor branch,
2343: # offer a diff with the branch point.
2344: if ($revsym{$brp} && !/^1\.1\.1\.\d+$/ && !defined($diffrev{$brp})) {
3.35 knu 2345: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2346: $scriptwhere,
2347: $brp,
2348: $_,
2349: $barequery);
2350:
2351: print " to branchpoint ";
3.37 knu 2352: printDiffLinks($brp, $url);
1.1 jfieber 2353: }
3.1 knu 2354: #
2355: # Plus, if it's on a branch, and it's not a vendor branch,
2356: # offer to diff with the next revision of the higher branch.
2357: # (e.g. change gets committed and then brought
2358: # over to -stable)
2359: if (/^\d+\.\d+\.\d+/ && !/^1\.1\.1\.\d+$/) {
2360: my ($i,$nextmain);
2361: for ($i = 0; $i < $#revorder && $revorder[$i] ne $_; $i++){}
3.53 ! knu 2362: my @tmp2 = split(/\./, $_);
3.1 knu 2363: for ($nextmain = ""; $i > 0; $i--) {
3.53 ! knu 2364: my $next = $revorder[$i-1];
! 2365: my @tmp1 = split(/\./, $next);
! 2366: if (@tmp1 < @tmp2) {
3.1 knu 2367: $nextmain = $next;
2368: last;
2369: }
2370: # Only the highest version on a branch should have
2371: # a diff for the "next main".
3.53 ! knu 2372: last if (@tmp1 - 1 <= @tmp2 &&
! 2373: join(".",@tmp1[0..$#tmp1-1]) eq join(".",@tmp2[0..$#tmp1-1]));
3.1 knu 2374: }
2375: if (!defined($diffrev{$nextmain})) {
2376: $diffrev{$nextmain} = 1;
3.35 knu 2377:
2378: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2379: $scriptwhere,
2380: $nextmain,
2381: $_,
2382: $barequery);
2383:
2384: print " next main ";
3.37 knu 2385: printDiffLinks($nextmain, $url);
1.1 jfieber 2386: }
2387: }
3.1 knu 2388: # Plus if user has selected only r1, then present a link
2389: # to make a diff to that revision
2390: if (defined($input{"r1"}) && !defined($diffrev{$input{"r1"}})) {
2391: $diffrev{$input{"r1"}} = 1;
3.35 knu 2392:
2393: my $url = sprintf('%s.diff?r1=%s&r2=%s%s',
2394: $scriptwhere,
2395: $input{'r1'},
2396: $_,
2397: $barequery);
2398:
2399: print " to selected ";
3.37 knu 2400: printDiffLinks($input{'r1'}, $url);
1.9 fenner 2401: }
1.1 jfieber 2402: }
3.1 knu 2403: print "<PRE>\n";
2404: print &htmlify($log{$_}, 1);
2405: print "</PRE>\n";
2406: }
2407:
3.12 knu 2408: sub doLog($) {
3.1 knu 2409: my($fullname) = @_;
2410: my ($diffrev, $upwhere, $filename, $backurl);
3.12 knu 2411:
3.1 knu 2412: readLog($fullname);
2413:
2414: html_header("CVS log for $where");
2415: ($upwhere = $where) =~ s|(Attic/)?[^/]+$||;
2416: ($filename = $where) =~ s|^.*/||;
2417: $backurl = $scriptname . "/" . urlencode($upwhere) . $query;
2418: print &link($backicon, "$backurl#$filename"),
3.35 knu 2419: " <b>Up to ", &clickablePath($upwhere, 1), "</b><p>\n";
2420: print &link('Request diff between arbitrary revisions', '#diff');
2421: print '<HR NOSHADE>';
2422:
3.1 knu 2423: if ($curbranch) {
3.3 knu 2424: print "Default branch: ", ($revsym{$curbranch} || $curbranch);
3.1 knu 2425: }
2426: else {
2427: print "No default branch";
2428: }
2429: print "<BR>\n";
2430: if ($input{only_with_tag}) {
2431: print "Current tag: $input{only_with_tag}<BR>\n";
2432: }
2433:
2434: undef %nameprinted;
2435:
2436: for (my $i = 0; $i <= $#revdisplayorder; $i++) {
2437: print "<HR size=1 NOSHADE>";
2438: printLog($revdisplayorder[$i]);
2439: }
2440:
2441: print "<HR NOSHADE>";
1.1 jfieber 2442: print "<A NAME=diff>\n";
2443: print "This form allows you to request diff's between any two\n";
2444: print "revisions of a file. You may select a symbolic revision\n";
2445: print "name using the selection box or you may type in a numeric\n";
2446: print "name using the type-in text box.\n";
2447: print "</A><P>\n";
3.1 knu 2448: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}.diff\" NAME=\"diff_select\">\n";
2449: foreach (@stickyvars) {
3.35 knu 2450: printf('<INPUT TYPE=HIDDEN NAME="%s" VALUE="%s">', $_, $input{$_})
3.1 knu 2451: if (defined($input{$_})
3.23 knu 2452: && ((!defined($DEFAULTVALUE{$_})
2453: || $input{$_} ne $DEFAULTVALUE{$_})
2454: && $input{$_} ne ""));
3.1 knu 2455: }
3.21 knu 2456: print "<TABLE><TR>\n";
2457: print "<TD align=right>Diffs between \n";
1.1 jfieber 2458: print "<SELECT NAME=\"r1\">\n";
2459: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2460: print $sel;
2461: print "</SELECT>\n";
3.1 knu 2462: $diffrev = $revdisplayorder[$#revdisplayorder];
2463: $diffrev = $input{"r1"} if (defined($input{"r1"}));
3.21 knu 2464: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr1\" VALUE=\"$diffrev\" onChange='document.diff_select.r1.selectedIndex=0'></TD>";
2465: print "<TD><BR></TD></TR>\n";
2466: print "<TR><TD align=right>and \n";
1.1 jfieber 2467: print "<SELECT NAME=\"r2\">\n";
2468: print "<OPTION VALUE=\"text\" SELECTED>Use Text Field\n";
2469: print $sel;
2470: print "</SELECT>\n";
3.1 knu 2471: $diffrev = $revdisplayorder[0];
2472: $diffrev = $input{"r2"} if (defined($input{"r2"}));
3.21 knu 2473: print "<INPUT TYPE=\"TEXT\" SIZE=\"$inputTextSize\" NAME=\"tr2\" VALUE=\"$diffrev\" onChange='document.diff_select.r2.selectedIndex=0'></TD>";
2474: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Get Diffs \"></TD>\n";
1.1 jfieber 2475: print "</FORM>\n";
3.21 knu 2476: print "</TR></TABLE>\n";
1.7 fenner 2477: print "<HR noshade>\n";
3.21 knu 2478: print "<TABLE>";
2479: print "<FORM METHOD=\"GET\" ACTION=\"$scriptwhere\">\n";
3.37 knu 2480: print "<TR><TD align=right>Preferred Diff type:</TD>";
2481: print "<TD>";
3.21 knu 2482: printDiffSelect($use_java_script);
2483: print "</TD><TD></TD></TR>\n";
3.1 knu 2484: if (@branchnames) {
3.21 knu 2485: print "<TR><TD align=right>View only Branch:</TD>";
2486: print "<TD>";
3.1 knu 2487: print "<A name=branch></A>\n";
2488: print "<SELECT NAME=\"only_with_tag\"";
2489: print " onchange=\"submit()\"" if ($use_java_script);
2490: print ">\n";
2491: print "<OPTION VALUE=\"\"";
2492: print " SELECTED" if (defined($input{"only_with_tag"}) &&
2493: $input{"only_with_tag"} eq "");
2494: print ">Show all branches\n";
2495: foreach (reverse sort @branchnames) {
1.9 fenner 2496: print "<OPTION";
3.1 knu 2497: print " SELECTED" if (defined($input{"only_with_tag"})
2498: && $input{"only_with_tag"} eq $_);
1.9 fenner 2499: print ">${_}\n";
3.1 knu 2500: }
3.21 knu 2501: print "</SELECT></TD><TD></TD></TR>\n";
1.7 fenner 2502: }
3.1 knu 2503: foreach (@stickyvars) {
3.21 knu 2504: next if ($_ eq "f");
3.1 knu 2505: next if ($_ eq "only_with_tag");
2506: next if ($_ eq "logsort");
2507: print "<INPUT TYPE=HIDDEN NAME=\"$_\" VALUE=\"$input{$_}\">\n"
3.23 knu 2508: if (defined($input{$_})
2509: && (!defined($DEFAULTVALUE{$_})
2510: || $input{$_} ne $DEFAULTVALUE{$_})
3.1 knu 2511: && $input{$_} ne "");
2512: }
3.21 knu 2513: print "<TR><TD align=right>";
2514: print "<A name=logsort></A>\n";
2515: print "Sort log by:</TD>";
3.37 knu 2516: print "<TD>";
2517: printLogSortSelect($use_java_script);
2518: print "</TD>";
3.21 knu 2519: print "<TD><INPUT TYPE=SUBMIT VALUE=\" Set \"></TD>";
1.7 fenner 2520: print "</FORM>\n";
3.21 knu 2521: print "</TR></TABLE>";
1.2 jfieber 2522: print &html_footer;
1.1 jfieber 2523: print "</BODY></HTML>\n";
1.10 wosch 2524: }
2525:
3.12 knu 2526: sub flush_diff_rows($$$$) {
3.1 knu 2527: my $j;
2528: my ($leftColRef,$rightColRef,$leftRow,$rightRow) = @_;
2529: if ($state eq "PreChangeRemove") { # we just got remove-lines before
2530: for ($j = 0 ; $j < $leftRow; $j++) {
2531: print "<tr><td bgcolor=\"$diffcolorRemove\">@$leftColRef[$j]</td>";
2532: print "<td bgcolor=\"$diffcolorEmpty\"> </td></tr>\n";
2533: }
2534: }
2535: elsif ($state eq "PreChange") { # state eq "PreChange"
2536: # we got removes with subsequent adds
2537: for ($j = 0; $j < $leftRow || $j < $rightRow ; $j++) { # dump out both cols
2538: print "<tr>";
2539: if ($j < $leftRow) {
2540: print "<td bgcolor=\"$diffcolorChange\">@$leftColRef[$j]</td>";
2541: }
2542: else {
2543: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2544: }
2545: if ($j < $rightRow) {
2546: print "<td bgcolor=\"$diffcolorChange\">@$rightColRef[$j]</td>";
2547: }
2548: else {
2549: print "<td bgcolor=\"$diffcolorDarkChange\"> </td>";
2550: }
2551: print "</tr>\n";
2552: }
2553: }
2554: }
2555:
2556: ##
2557: # Function to generate Human readable diff-files
2558: # human_readable_diff(String revision_to_return_to);
2559: ##
2560: sub human_readable_diff($){
3.24 knu 2561: my ($difftxt, $where_nd, $filename, $pathname, $scriptwhere_nd);
3.1 knu 2562: my ($fh, $rev) = @_;
2563: my ($date1, $date2, $r1d, $r2d, $r1r, $r2r, $rev1, $rev2, $sym1, $sym2);
2564: my (@rightCol, @leftCol);
2565:
2566: ($where_nd = $where) =~ s/.diff$//;
2567: ($filename = $where_nd) =~ s/^.*\///;
2568: ($pathname = $where_nd) =~ s/(Attic\/)?[^\/]*$//;
2569: ($scriptwhere_nd = $scriptwhere) =~ s/.diff$//;
2570:
3.12 knu 2571: navigateHeader($scriptwhere_nd, $pathname, $filename, $rev, "diff");
3.1 knu 2572:
2573: # Read header to pick up read revision and date, if possible
2574: while (<$fh>) {
2575: ($r1d,$r1r) = /\t(.*)\t(.*)$/ if (/^--- /);
2576: ($r2d,$r2r) = /\t(.*)\t(.*)$/ if (/^\+\+\+ /);
2577: last if (/^\+\+\+ /);
2578: }
2579: if (defined($r1r) && $r1r =~ /^(\d+\.)+\d+$/) {
2580: $rev1 = $r1r;
2581: $date1 = $r1d;
2582: }
2583: if (defined($r2r) && $r2r =~ /^(\d+\.)+\d+$/) {
2584: $rev2 = $r2r;
2585: $date2 = $r2d;
2586: }
3.12 knu 2587:
3.36 knu 2588: print "<h3 align=center>Diff for /$where_nd between version $rev1 and $rev2</h3>\n",
2589: "<table border=0 cellspacing=0 cellpadding=0 width=\"100%\">\n",
2590: "<tr bgcolor=\"#ffffff\">\n",
2591: "<th width=\"50%\" valign=TOP>",
2592: "version $rev1";
3.1 knu 2593: print ", $date1" if (defined($date1));
2594: print "<br>Tag: $sym1\n" if ($sym1);
3.36 knu 2595: print "</th>\n",
2596: "<th width=\"50%\" valign=TOP>",
2597: "version $rev2";
3.1 knu 2598: print ", $date2" if (defined($date2));
2599: print "<br>Tag: $sym2\n" if ($sym1);
2600: print "</th>\n";
2601:
2602: my $fs = "<font face=\"$difffontface\" size=\"$difffontsize\">";
2603: my $fe = "</font>";
2604:
2605: my $leftRow = 0;
2606: my $rightRow = 0;
2607: my ($oldline, $newline, $funname, $diffcode, $rest);
2608:
2609: # Process diff text
2610: # The diffrows are could make excellent use of
2611: # cascading style sheets because we've to set the
2612: # font and color for each row. anyone ...?
2613: ####
3.24 knu 2614:
2615: # prefetch several lines
2616: my @buf = head($fh);
2617:
2618: my %d = scan_directives(@buf);
2619:
2620: while (@buf || !eof($fh)) {
2621: $difftxt = @buf ? shift @buf : <$fh>;
3.12 knu 2622:
3.1 knu 2623: if ($difftxt =~ /^@@/) {
2624: ($oldline,$newline,$funname) = $difftxt =~ /@@ \-([0-9]+).*\+([0-9]+).*@@(.*)/;
2625: print "<tr bgcolor=\"$diffcolorHeading\"><td width=\"50%\">";
2626: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $oldline</b>";
2627: print " <font size=-1>$funname</font></td></tr></table>";
2628: print "</td><td width=\"50%\">";
2629: print "<table width=\"100%\" border=1 cellpadding=5><tr><td><b>Line $newline</b>";
2630: print " <font size=-1>$funname</font></td></tr></table>";
2631: print "</td>\n";
2632: $state = "dump";
2633: $leftRow = 0;
2634: $rightRow = 0;
2635: }
2636: else {
2637: ($diffcode,$rest) = $difftxt =~ /^([-+ ])(.*)/;
3.24 knu 2638: $_ = spacedHtmlText($rest, $d{'tabstop'});
3.1 knu 2639:
2640: # Add fontface, size
2641: $_ = "$fs $_$fe";
3.12 knu 2642:
3.1 knu 2643: #########
2644: # little state machine to parse unified-diff output (Hen, zeller@think.de)
2645: # in order to get some nice 'ediff'-mode output
2646: # states:
2647: # "dump" - just dump the value
2648: # "PreChangeRemove" - we began with '-' .. so this could be the start of a 'change' area or just remove
2649: # "PreChange" - okey, we got several '-' lines and moved to '+' lines -> this is a change block
2650: ##########
2651:
2652: if ($diffcode eq '+') {
2653: if ($state eq "dump") { # 'change' never begins with '+': just dump out value
2654: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td bgcolor=\"$diffcolorAdd\">$_</td></tr>\n";
2655: }
2656: else { # we got minus before
2657: $state = "PreChange";
2658: $rightCol[$rightRow++] = $_;
2659: }
3.12 knu 2660: }
3.1 knu 2661: elsif ($diffcode eq '-') {
2662: $state = "PreChangeRemove";
2663: $leftCol[$leftRow++] = $_;
2664: }
2665: else { # empty diffcode
2666: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2667: print "<tr><td>$_</td><td>$_</td></tr>\n";
2668: $state = "dump";
2669: $leftRow = 0;
2670: $rightRow = 0;
2671: }
2672: }
2673: }
2674: flush_diff_rows \@leftCol, \@rightCol, $leftRow, $rightRow;
2675:
2676: # state is empty if we didn't have any change
2677: if (!$state) {
2678: print "<tr><td colspan=2> </td></tr>";
2679: print "<tr bgcolor=\"$diffcolorEmpty\" >";
2680: print "<td colspan=2 align=center><b>- No viewable Change -</b></td></tr>";
2681: }
2682: print "</table>";
2683: close($fh);
2684:
2685: print "<br><hr noshade width=\"100%\">\n";
2686:
2687: print "<table border=0>";
2688:
2689: print "<tr><td>";
2690: # print legend
2691: print "<table border=1><tr><td>";
2692: print "Legend:<br><table border=0 cellspacing=0 cellpadding=1>\n";
2693: print "<tr><td align=center bgcolor=\"$diffcolorRemove\">Removed from v.$rev1</td><td bgcolor=\"$diffcolorEmpty\"> </td></tr>";
2694: print "<tr bgcolor=\"$diffcolorChange\"><td align=center colspan=2>changed lines</td></tr>";
2695: print "<tr><td bgcolor=\"$diffcolorEmpty\"> </td><td align=center bgcolor=\"$diffcolorAdd\">Added in v.$rev2</td></tr>";
2696: print "</table></td></tr></table>\n";
2697:
2698: print "<td>";
2699: # Print format selector
2700: print "<FORM METHOD=\"GET\" ACTION=\"${scriptwhere}\">\n";
2701: foreach my $var (keys %input) {
2702: next if ($var eq "f");
2703: next if (defined($DEFAULTVALUE{$var})
2704: && $DEFAULTVALUE{$var} eq $input{$var});
2705: print "<INPUT TYPE=HIDDEN NAME=\"",urlencode($var),"\" VALUE=\"",
2706: urlencode($input{$var}),"\">\n";
2707: }
2708: printDiffSelect($use_java_script);
2709: print "<INPUT TYPE=SUBMIT VALUE=\"Show\">\n";
2710: print "</FORM>\n";
2711: print "</td>";
2712:
2713: print "</tr></table>";
2714: }
2715:
3.12 knu 2716: sub navigateHeader($$$$$) {
3.1 knu 2717: my ($swhere,$path,$filename,$rev,$title) = @_;
2718: $swhere = "" if ($swhere eq $scriptwhere);
2719: $swhere = urlencode($filename) if ($swhere eq "");
3.43 knu 2720: print qq`<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">`;
3.1 knu 2721: print "<HTML>\n<HEAD>\n";
3.43 knu 2722: print qq`<META name="robots" content="nofollow">\n`;
3.53 ! knu 2723: print '<!-- CVSweb $zRevision: 1.104 $ $Revision: 3.52 $ -->';
3.1 knu 2724: print "\n<TITLE>$path$filename - $title - $rev</TITLE></HEAD>\n";
3.26 knu 2725: print "$body_tag_for_src\n";
3.1 knu 2726: print "<table width=\"100%\" border=0 cellspacing=0 cellpadding=1 bgcolor=\"$navigationHeaderColor\">";
2727: print "<tr valign=bottom><td>";
3.35 knu 2728: print &link($backicon, "$swhere$query#rev$rev");
3.1 knu 2729: print "</a> <b>Return to ", &link("$filename","$swhere$query#rev$rev")," CVS log";
2730: print "</b> $fileicon</td>";
3.12 knu 2731:
3.1 knu 2732: print "<td align=right>$diricon <b>Up to ", &clickablePath($path, 1), "</b></td>";
2733: print "</tr></table>";
2734: }
2735:
3.12 knu 2736: sub plural_write($$) {
3.1 knu 2737: my ($num,$text) = @_;
2738: if ($num != 1) {
3.36 knu 2739: $text .= "s";
3.1 knu 2740: }
2741: if ($num > 0) {
3.36 knu 2742: return join(' ', $num, $text);
3.1 knu 2743: }
2744: else {
2745: return "";
2746: }
2747: }
2748:
2749: ##
2750: # print readable timestamp in terms of
2751: # '..time ago'
2752: # H. Zeller <zeller@think.de>
2753: ##
3.12 knu 2754: sub readableTime($$) {
3.1 knu 2755: my ($i, $break, $retval);
2756: my ($secs,$long) = @_;
2757:
2758: # this function works correct for time >= 2 seconds
2759: if ($secs < 2) {
2760: return "very little time";
2761: }
2762:
2763: my %desc = (1 , 'second',
2764: 60, 'minute',
2765: 3600, 'hour',
2766: 86400, 'day',
2767: 604800, 'week',
2768: 2628000, 'month',
2769: 31536000, 'year');
2770: my @breaks = sort {$a <=> $b} keys %desc;
2771: $i = 0;
3.12 knu 2772: while ($i <= $#breaks && $secs >= 2 * $breaks[$i]) {
3.1 knu 2773: $i++;
2774: }
2775: $i--;
2776: $break = $breaks[$i];
3.3 knu 2777: $retval = plural_write(int ($secs / $break), $desc{$break});
3.1 knu 2778:
2779: if ($long == 1 && $i > 0) {
2780: my $rest = $secs % $break;
2781: $i--;
2782: $break = $breaks[$i];
3.12 knu 2783: my $resttime = plural_write(int ($rest / $break),
3.3 knu 2784: $desc{$break});
3.1 knu 2785: if ($resttime) {
3.36 knu 2786: $retval .= ", $resttime";
3.1 knu 2787: }
2788: }
2789:
2790: return $retval;
2791: }
2792:
2793: ##
2794: # clickablePath(String pathname, boolean last_item_clickable)
2795: #
2796: # returns a html-ified path whereas each directory is a link for
2797: # faster navigation. last_item_clickable controls whether the
2798: # basename (last directory/file) is a link as well
2799: ##
2800: sub clickablePath($$) {
3.12 knu 2801: my ($pathname,$clickLast) = @_;
3.1 knu 2802: my $retval = '';
3.12 knu 2803:
3.1 knu 2804: if ($pathname eq '/') {
2805: # this should never happen - chooseCVSRoot() is
2806: # intended to do this
2807: $retval = "[$cvstree]";
2808: }
2809: else {
3.35 knu 2810: $retval .= ' ' . &link("[$cvstree]", sprintf('%s/%s#dirlist',
2811: $scriptname,
2812: $query));
3.1 knu 2813: my $wherepath = '';
2814: my ($lastslash) = $pathname =~ m|/$|;
2815: foreach (split(/\//, $pathname)) {
3.36 knu 2816: $retval .= " / ";
2817: $wherepath .= "/$_";
3.1 knu 2818: my ($last) = "$wherepath/" eq "/$pathname"
3.3 knu 2819: || $wherepath eq "/$pathname";
3.1 knu 2820: if ($clickLast || !$last) {
3.35 knu 2821: $retval .= &link($_, join('',
2822: $scriptname,
2823: urlencode($wherepath),
2824: (!$last || $lastslash ? '/' : ''),
2825: $query,
2826: (!$last || $lastslash ? "#dirlist" : "")));
3.1 knu 2827: }
2828: else { # do not make a link to the current dir
3.35 knu 2829: $retval .= $_;
3.1 knu 2830: }
2831: }
2832: }
2833: return $retval;
2834: }
2835:
2836: sub chooseCVSRoot() {
2837: my @foo;
2838: foreach (sort keys %CVSROOT) {
2839: if (-d $CVSROOT{$_}) {
2840: push(@foo, $_);
2841: }
2842: }
2843: if (@foo > 1) {
2844: my ($k);
2845: print "<form method=\"GET\" action=\"${scriptwhere}\">\n";
2846: foreach $k (keys %input) {
3.12 knu 2847: print "<input type=hidden NAME=$k VALUE=$input{$k}>\n"
3.1 knu 2848: if ($input{$k}) && ($k ne "cvsroot");
2849: }
2850: # Form-Elements look wierd in Netscape if the background
2851: # isn't gray and the form elements are not placed
2852: # within a table ...
2853: print "<table><tr>";
2854: print "<td>CVS Root:</td>";
2855: print "<td>\n<select name=\"cvsroot\"";
2856: print " onchange=\"submit()\"" if ($use_java_script);
2857: print ">\n";
2858: foreach $k (@foo) {
2859: print "<option value=\"$k\"";
3.3 knu 2860: print " selected" if ($k eq $cvstree);
3.36 knu 2861: print ">", ($CVSROOTdescr{$k} ? $CVSROOTdescr{$k} : $k), "</option>\n";
3.1 knu 2862: }
2863: print "</select>\n</td>";
2864: print "<td><input type=submit value=\"Go\"></td>";
2865: print "</tr></table></form>";
2866: }
2867: else {
2868: # no choice ..
2869: print "CVS Root: <b>[$cvstree]</b>";
2870: }
2871: }
2872:
2873: sub chooseMirror() {
2874: my ($mirror,$moremirrors);
2875: $moremirrors = 0;
2876: # This code comes from the original BSD-cvsweb
2877: # and may not be useful for your site; If you don't
2878: # set %MIRRORS this won't show up, anyway
2879: #
3.12 knu 2880: # Should perhaps exlude the current site somehow..
3.1 knu 2881: if (keys %MIRRORS) {
2882: print "\nThis cvsweb is mirrored in:\n";
2883: foreach $mirror (keys %MIRRORS) {
2884: print ", " if ($moremirrors);
3.35 knu 2885: print &link(htmlquote($mirror),$MIRRORS{$mirror});
3.1 knu 2886: $moremirrors = 1;
2887: }
2888: print "<p>\n";
2889: }
2890: }
2891:
3.12 knu 2892: sub fileSortCmp() {
3.1 knu 2893: my ($comp) = 0;
2894: my ($c,$d,$af,$bf);
2895:
2896: ($af = $a) =~ s/,v$//;
2897: ($bf = $b) =~ s/,v$//;
2898: my ($rev1,$date1,$log1,$author1,$filename1) = @{$fileinfo{$af}}
2899: if (defined($fileinfo{$af}));
2900: my ($rev2,$date2,$log2,$author2,$filename2) = @{$fileinfo{$bf}}
2901: if (defined($fileinfo{$bf}));
2902:
2903: if (defined($filename1) && defined($filename2) && $af eq $filename1 && $bf eq $filename2) {
2904: # Two files
2905: $comp = -revcmp($rev1, $rev2) if ($byrev && $rev1 && $rev2);
2906: $comp = ($date2 <=> $date1) if ($bydate && $date1 && $date2);
2907: $comp = ($log1 cmp $log2) if ($bylog && $log1 && $log2);
2908: $comp = ($author1 cmp $author2) if ($byauthor && $author1 && $author2);
2909: }
2910: if ($comp == 0) {
2911: # Directories first, then sorted on name if no other sort critera
2912: # available.
2913: my $ad = ((-d "$fullname/$a")?"D":"F");
2914: my $bd = ((-d "$fullname/$b")?"D":"F");
2915: ($c=$a) =~ s|.*/||;
2916: ($d=$b) =~ s|.*/||;
2917: $comp = ("$ad$c" cmp "$bd$d");
2918: }
2919: return $comp;
2920: }
2921:
2922: # make A url for downloading
3.12 knu 2923: sub download_url($$;$) {
3.1 knu 2924: my ($url,$revision,$mimetype) = @_;
2925:
3.45 knu 2926: $revision =~ s/\b0\.//;
3.1 knu 2927:
3.35 knu 2928: if (defined($checkoutMagic)
3.1 knu 2929: && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
3.35 knu 2930: my $path = $where;
2931: $path =~ s|/[^/]*$|/|;
3.1 knu 2932: $url = "$scriptname/$checkoutMagic/${path}$url";
2933: }
2934: $url .= "?rev=$revision";
3.35 knu 2935: $url .= '&content-type=' . urlencode($mimetype) if (defined($mimetype));
3.1 knu 2936:
3.35 knu 2937: $url;
3.1 knu 2938: }
2939:
3.12 knu 2940: # Presents a link to download the
3.1 knu 2941: # selected revision
3.12 knu 2942: sub download_link($$$;$) {
3.35 knu 2943: my ($url, $revision, $textlink, $mimetype) = @_;
2944: my ($fullurl) = download_url($url, $revision, $mimetype);
2945:
3.46 knu 2946: printf '<A HREF="%s"', hrefquote("$fullurl$barequery");
3.35 knu 2947:
3.1 knu 2948: if ($open_extern_window && (!defined($mimetype) || $mimetype ne "text/x-cvsweb-markup")) {
3.35 knu 2949: print ' target="cvs_checkout"';
3.1 knu 2950: # we should have
2951: # 'if (document.cvswin==null) document.cvswin=window.open(...'
2952: # in order to allow the user to resize the window; otherwise
2953: # the user may resize the window, but on next checkout - zap -
2954: # its original (configured s. cvsweb.conf) size is back again
2955: # .. annoying (if $extern_window_(width|height) is defined)
2956: # but this if (..) solution is far from perfect
2957: # what we need to do as well is
2958: # 1) save cvswin in an invisible frame that always exists
2959: # (document.cvswin will be void on next load)
2960: # 2) on close of the cvs_checkout - window set the cvswin
2961: # variable to 'null' again - so that it will be
2962: # reopenend with the configured size
2963: # anyone a JavaScript programmer ?
2964: # .. so here without if (..):
2965: # currently, the best way is to comment out the size parameters
2966: # ($extern_window...) in cvsweb.conf.
2967: if ($use_java_script) {
3.35 knu 2968: my @attr = qw(resizeable scrollbars);
2969:
2970: push @attr, qw(status toolbar)
2971: if (defined($mimetype) && $mimetype eq "text/html");
2972:
2973: push @attr, "width=$extern_window_width"
2974: if (defined($extern_window_width));
2975:
2976: push @attr, "height=$extern_window_height"
2977: if (defined($extern_window_height));
2978:
2979: printf q` onClick="window.open('%s','cvs_checkout','%s');"`,
3.46 knu 2980: hrefquote($fullurl), join(',', @attr);
3.1 knu 2981: }
2982: }
2983: print "><b>$textlink</b></A>";
2984: }
2985:
2986: # Returns a Query string with the
2987: # specified parameter toggled
2988: sub toggleQuery($$) {
2989: my ($toggle,$value) = @_;
2990: my ($newquery,$var);
2991: my (%vars);
2992: %vars = %input;
2993: if (defined($value)) {
2994: $vars{$toggle} = $value;
2995: }
2996: else {
2997: $vars{$toggle} = $vars{$toggle} ? 0 : 1;
2998: }
2999: # Build a new query of non-default paramenters
3000: $newquery = "";
3001: foreach $var (@stickyvars) {
3002: my ($value) = defined($vars{$var}) ? $vars{$var} : "";
3003: my ($default) = defined($DEFAULTVALUE{$var}) ? $DEFAULTVALUE{$var} : "";
3004: if ($value ne $default) {
3.35 knu 3005: $newquery .= "&" if ($newquery ne "");
3.1 knu 3006: $newquery .= urlencode($var) . "=" . urlencode($value);
3007: }
3008: }
3009: if ($newquery) {
3010: return '?' . $newquery;
3011: }
3012: return "";
3013: }
3014:
3.12 knu 3015: sub urlencode($) {
3.35 knu 3016: local($_) = @_;
3017:
3018: s/[\000-+{-\377]/sprintf("%%%02x", ord($&))/ge;
3019:
3.46 knu 3020: $_;
3.35 knu 3021: }
3022:
3023: sub htmlquote($) {
3024: local($_) = @_;
3025:
3026: # Special Characters; RFC 1866
3027: s/&/&/g;
3028: s/\"/"/g;
3029: s/</</g;
3030: s/>/>/g;
3031:
3032: $_;
3.1 knu 3033: }
3034:
3.36 knu 3035: sub htmlunquote($) {
3036: local($_) = @_;
3037:
3038: # Special Characters; RFC 1866
3039: s/"/\"/g;
3040: s/</</g;
3041: s/>/>/g;
3042: s/&/&/g;
3043:
3044: $_;
3045: }
3046:
3.46 knu 3047: sub hrefquote($) {
3048: local($_) = @_;
3049:
3050: y/ /+/;
3051:
3052: htmlquote($_)
3053: }
3054:
3.12 knu 3055: sub http_header(;$) {
3.1 knu 3056: my $content_type = shift || "text/html";
3.50 knu 3057:
3058: $content_type .= "; charset=$charset"
3059: if $content_type =~ m,^text/, && defined($charset) && $charset;
3060:
3.1 knu 3061: if (defined($moddate)) {
3062: if ($is_mod_perl) {
3.23 knu 3063: Apache->request->header_out("Last-Modified" => scalar gmtime($moddate) . " GMT");
3.1 knu 3064: }
3065: else {
3.36 knu 3066: print "Last-Modified: ", scalar gmtime($moddate), " GMT\r\n";
3.1 knu 3067: }
3068: }
3069: if ($is_mod_perl) {
3070: Apache->request->content_type($content_type);
3071: }
3072: else {
3.4 knu 3073: print "Content-type: $content_type\r\n";
3.1 knu 3074: }
3075: if ($allow_compress && $maycompress) {
3.23 knu 3076: if ($has_zlib || (defined($GZIPBIN) && open(GZIP, "|$GZIPBIN -1 -c"))) {
3.1 knu 3077: if ($is_mod_perl) {
3078: Apache->request->content_encoding("x-gzip");
3079: Apache->request->header_out(Vary => "Accept-Encoding");
3080: Apache->request->send_http_header;
3081: }
3082: else {
3.4 knu 3083: print "Content-encoding: x-gzip\r\n";
3084: print "Vary: Accept-Encoding\r\n"; #RFC 2068, 14.43
3085: print "\r\n"; # Close headers
3.1 knu 3086: }
3087: $| = 1; $| = 0; # Flush header output
3.23 knu 3088: if ($has_zlib) {
3089: tie *GZIP, __PACKAGE__, \*STDOUT;
3090: }
3091: select(GZIP);
3092: $gzip_open = 1;
3.40 knu 3093: # print "<!-- gzipped -->" if ($content_type =~ m|^text/html\b|);
3.1 knu 3094: }
3095: else {
3096: if ($is_mod_perl) {
3097: Apache->request->send_http_header;
3098: }
3099: else {
3.4 knu 3100: print "\r\n"; # Close headers
3.1 knu 3101: }
3102: print "<font size=-1>Unable to find gzip binary in the \$PATH to compress output</font><br>";
3103: }
3104: }
3105: else {
3106: if ($is_mod_perl) {
3107: Apache->request->send_http_header;
3108: }
3109: else {
3.4 knu 3110: print "\r\n"; # Close headers
3.1 knu 3111: }
3112: }
3113: }
3114:
3115: sub html_header($) {
3116: my ($title) = @_;
3.53 ! knu 3117: my $version = '$zRevision: 1.104 $ $Revision: 3.52 $'; #'
3.50 knu 3118: http_header("text/html");
3.1 knu 3119: print <<EOH;
3120: <!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN"
3121: "http://www.w3.org/TR/REC-html40/loose.dtd">
3122: <html>
3.40 knu 3123: <head>
3.43 knu 3124: <meta name="robots" content="nofollow">
3.1 knu 3125: <title>$title</title>
3.3 knu 3126: <!-- CVSweb $version -->
3.1 knu 3127: </head>
3128: $body_tag
3129: $logo <h1 align="center">$title</h1>
3130: EOH
3131: }
3132:
3.12 knu 3133: sub html_footer() {
3.1 knu 3134: return "<hr noshade><address>$address</address>\n";
3135: }
3136:
3.12 knu 3137: sub link_tags($) {
3.1 knu 3138: my ($tags) = @_;
3139: my ($ret) = "";
3140: my ($fileurl,$filename);
3141:
3142: ($filename = $where) =~ s/^.*\///;
3143: $fileurl = urlencode($filename);
3144:
3145: foreach my $sym (split(", ", $tags)) {
3146: $ret .= ",\n" if ($ret ne "");
3.35 knu 3147: $ret .= &link($sym, $fileurl . toggleQuery('only_with_tag',$sym));
3.1 knu 3148: }
3.35 knu 3149: return "$ret\n";
3.1 knu 3150: }
3151:
3152: #
3153: # See if a module is listed in the config file's @HideModule list.
3154: #
3.12 knu 3155: sub forbidden_module($) {
3.1 knu 3156: my($module) = @_;
3.12 knu 3157:
3.1 knu 3158: for (my $i=0; $i < @HideModules; $i++) {
3159: return 1 if $module eq $HideModules[$i];
3160: }
3161:
3162: return 0;
3.25 knu 3163: }
3164:
3165: # Close the GZIP handle remove the tie.
3166:
3167: sub gzipclose {
3168: if ($gzip_open) {
3169: select(STDOUT);
3170: close(GZIP);
3171: untie *GZIP;
3172: $gzip_open = 0;
3173: }
3.23 knu 3174: }
3175:
3176: # implement a gzipped file handle via the Compress:Zlib compression
3177: # library.
3178:
3179: sub MAGIC1() { 0x1f }
3180: sub MAGIC2() { 0x8b }
3181: sub OSCODE() { 3 }
3182:
3183: sub TIEHANDLE {
3184: my ($class, $out) = @_;
3185: my ($d) = Compress::Zlib::deflateInit(-Level => Compress::Zlib::Z_BEST_COMPRESSION(),
3186: -WindowBits => -Compress::Zlib::MAX_WBITS()) or return undef;
3187: my ($o) = {
3188: handle => $out,
3189: dh => $d,
3190: crc => 0,
3191: len => 0,
3192: };
3193: my ($header) = pack("c10", MAGIC1, MAGIC2, Compress::Zlib::Z_DEFLATED(), 0,0,0,0,0,0, OSCODE);
3194: print {$o->{handle}} $header;
3195: return bless($o, $class);
3196: }
3197:
3198: sub PRINT {
3199: my ($o) = shift;
3200: my ($buf) = join(defined $, ? $, : "",@_);
3201: my ($len) = length($buf);
3202: my ($compressed, $status) = $o->{dh}->deflate($buf);
3203: print {$o->{handle}} $compressed if defined($compressed);
3204: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3205: $o->{len} += $len;
3206: return $len;
3207: }
3208:
3209: sub PRINTF {
3210: my ($o) = shift;
3211: my ($fmt) = shift;
3212: my ($buf) = sprintf($fmt, @_);
3213: my ($len) = length($buf);
3214: my ($compressed, $status) = $o->{dh}->deflate($buf);
3215: print {$o->{handle}} $compressed if defined($compressed);
3216: $o->{crc} = Compress::Zlib::crc32($buf, $o->{crc});
3217: $o->{len} += $len;
3218: return $len;
3219: }
3220:
3221: sub WRITE {
3222: my ($o, $buf, $len, $off) = @_;
3223: my ($compressed, $status) = $o->{dh}->deflate(substr($buf, 0, $len));
3224: print {$o->{handle}} $compressed if defined($compressed);
3225: $o->{crc} = Compress::Zlib::crc32(substr($buf, 0, $len), $o->{crc});
3226: $o->{len} += $len;
3227: return $len;
3228: }
3229:
3230: sub CLOSE {
3231: my ($o) = @_;
3232: return if !defined( $o->{dh});
3233: my ($buf) = $o->{dh}->flush();
3234: $buf .= pack("V V", $o->{crc}, $o->{len});
3235: print {$o->{handle}} $buf;
3236: undef $o->{dh};
3237: }
3238:
3239: sub DESTROY {
3240: my ($o) = @_;
3241: CLOSE($o);
1.1 jfieber 3242: }
CVSweb