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