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