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

Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.21

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

CVSweb