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

Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.9

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

CVSweb