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

Annotation of cvsweb/cvsweb.cgi, Revision 3.96

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

CVSweb