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

Annotation of cvsweb/cvsweb.cgi, Revision 1.45.2.58

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

CVSweb