[BACK]Return to cvsweb.cgi CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / cvsweb

Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.10

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

CVSweb