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