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

Annotation of cvsweb/cvsweb.cgi, Revision 1.1.1.22

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

CVSweb