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

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.68

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

CVSweb