#!/usr/bin/perl -w # $Revision: 1.4 $ # $Author: mmueller $ # $Date: 2003/12/11 09:01:36 $ use strict; use CGI; # ------------------------------------------------------------- # config vars # ------------------------------------------------------------- my $sPage = "0"; my $p = 1; my $pm = 0; my $pn = 0; my $mode = "clm"; my $sFile = "tur.txt"; my $sTitle = "Mc Mahon Tabelle"; my $sH1 = "Tabelle"; # ------------------------------------------------------------- # global vars # ------------------------------------------------------------- my %line; my %line_special; my @msg; my $max = 0; # found max players (on place 1..max) my $q = new CGI; # ------------------------------------------------------------- # process CGI params # ------------------------------------------------------------- $sPage = $q->param("page") if (defined $q->param("page")); $sFile = $q->param("f") if (defined $q->param("f")); $mode = $q->param("mode") if (defined $q->param("mode")); $p = $q->param("p") if (defined $q->param("p")); $pm = $q->param("pm") if (defined $q->param("pm")); $pn = $q->param("pn") if (defined $q->param("pn")); { if (open (IF, "<$sFile.msg")) { while () { chomp(); push (@msg, $_); } close (IF); $sTitle = $msg[0] if ((defined $msg[0]) && $msg[0] ne ""); $sH1 = $msg[1] if ((defined $msg[1]) && $msg[1] ne ""); } } my $script = $q->script_name() . "?f=$sFile"; my $bUseColor = (index($mode, 'c') >= 0) ? 1 : 0; my $bUseLinks = (index($mode, 'L') >= 0) ? 2 : (index($mode, 'l') >= 0) ? 1 : 0; my $bResultMarks = (index($mode, 'm') >= 0) ? 1 : 0; my $bTopNavigation = (index($mode, 't') >= 0) ? 1 : 0; my $bBottomNavigation = (index($mode, 'b') >= 0) ? 1 : 0; my $bDebug = (index($mode, '@') >= 0) ? 1 : 0; my $nRounds = 0; my $nColFirstRound = 0; my $nColLastRound = 0; # ------------------------------------------------------------- # main # ------------------------------------------------------------- header(); debug(); read_file(); SWITCH: { if ($sPage eq "1") { page_1 (); last SWITCH; } if ($sPage eq "0") { page_0 (); last SWITCH; } } footer(); sub debug { if ($bDebug) { print ("\$sTitle=$sTitle
\n"); print ("\$bUseColor=$bUseColor
\n"); print ("\$bUseLinks=$bUseLinks
\n"); print ("\$bResultMarks=$bResultMarks
\n"); print ("\$sPage=$sPage
\n"); print ("\$sFile=$sFile
\n"); print ("\$mode=$mode
\n"); print ("\$p=$p
\n"); print ("\$pm=$pm
\n"); print ("\$pn=$pn
\n"); } } # ------------------------------------------------------------- # helper # ------------------------------------------------------------- sub read_file { $sFile =~ qr"^\w+\.txt$" or die "invalid filename\n"; open(IF, "<", $sFile) || print "error opening file\n"; while () { my @row = split(/\t/); if (not defined $row[0]) { } elsif ($row[0] =~ /^Pl/) { $line_special{0} = [@row[0..scalar(@row)-1]]; my $nStatus = 1; for (my $nCol = 0; $nCol < @row; $nCol++) { if ($nStatus == 1) { if ($row[$nCol] eq "1") { $nRounds = 1; $nStatus = 2; $nColFirstRound = $nCol; } } elsif ($nStatus == 2) { if ($row[$nCol] eq $nRounds+1) { $nRounds = $nRounds+1; $nStatus = 2; } else { $nStatus = 3; $nColLastRound = $nCol-1; } } elsif ($nStatus == 3) { } } } else { $line{$max++} = [@row[0..scalar(@row)-1]]; } } } sub page_0 { my $bg = ""; if ($bUseColor) { $bg = " bgcolor=\"#eeeeee\""; } print "\n"; my $l = ($bUseLinks) ? "l" : ""; print_line_special (0, "Rr$l"); for (my $i = 0; $i < $max; $i++) { if (($i >= ($p-1)-($pm-1) || ($pm == 0 && $i >= $p-1)) && ($i <= ($p-1)+($pn-1) || $pn == 0)) { print_line ($i, "Rrc$l"); } } print "\n"; } sub page_1 { my $bg = ""; if ($bUseColor) { $bg = " bgcolor=\"#eeeeee\""; } my $l = ($bUseLinks) ? "l" : ""; print "\n"; print_line_special (0, "R+r"); print "Player"; print_line ($p-1, "rc$l"); print_line_dummy (0, "Rw+r"); print_line_special (0, "R+ro"); my @row = @{$line{$p-1}}; for (my $nCol = $nColFirstRound; $nCol <= $nColLastRound; $nCol++) { my $nOpp = $row[$nCol]; $nOpp =~ s/[^0-9]*//g; my $nRound = $nCol-4; print "Round $nRound"; if ($nOpp =~ /^[0-9]+$/) { print_line ($nOpp-1, "rc$l"); } else { print_line_dummy (0, "r"); } } print "\n"; } # ------------------------------------------------------------- # header, footer # ------------------------------------------------------------- sub print_line ( $$ ) { my $i = shift; my $o = shift; my @row = @{$line{$i}}; if (index($o,'R') >= 0) { print "" ; if (index($o,'g') >= 0) { print "" ; } } if (index($o,'+') >= 0) { print " "; } { print ""; p_html($row[0]); print ""; } { my $t = $i+1; print ""; print "" if (index($o,'l') >= 0); p_html($row[1]); print "" if (index($o,'l') >= 0); print ""; } for (my $nCol = 2; $nCol < $nColFirstRound; $nCol++) { print ""; p_html($row[$nCol]); print ""; } for (my $nCol = $nColFirstRound; $nCol <= $nColLastRound; $nCol++) { print "\= 0); print "\>"; p_html($row[$nCol]); print ""; } for (my $nCol = $nColLastRound+1; $nCol < @row; $nCol++) { print ""; p_html($row[$nCol]); print ""; } if (index($o,'r') >= 0) { print "" ; } } sub print_line_special ( $$ ) { my $i = shift; my $o = shift; my @row = @{$line_special{$i}}; if (index($o,'R') >= 0) { print "" ; } if (index($o,'+') >= 0) { print " "; } if (index($o,'u') >= 0) { print "up"; } { print ""; p_html($row[0]); print ""; } { print ""; if (index($o,'o') >= 0) { p_html("Opponent"); } else { p_html("Name"); }; print ""; } for (my $nCol = 2; $nCol < @row; $nCol++) { print ""; p_html($row[$nCol]); print ""; } if (index($o,'r') >= 0) { print "" ; } } sub print_line_dummy ( $$ ) { my $i = shift; my $o = shift; my @row = @{$line_special{0}}; if (index($o,'R') >= 0) { print "= 0) { print " bgcolor=\"#ffffff\"" ; } print ">"; } if (index($o,'+') >= 0) { if ($i == -1 || $i == +1) { my $t = $p+$i; my $text = ($i == 1) ? "next" : "prev"; print "$text"; } else { print " "; }; } for (my $nCol = 0; $nCol < @row; $nCol++) { print " "; } if (index($o,'r') >= 0) { print "" ; } } # ------------------------------------------------------------- # header, footer # ------------------------------------------------------------- sub header { print "Content-type: text/html\n\n"; print ""; print "" . $sTitle . ""; print "\n "; if ($sH1) { print "

$sH1

"; } print "

"; if ($bTopNavigation) { print "Top"; print "Bottom"; print "
"; } } sub footer { if ($sPage eq "1") { print "
"; print "up"; print ", "; if ($p > 1) { my $t = $p-1; print "prev"; } else { print "prev"; } print ", "; if ($p < $max) { my $t = $p+1; print "next"; } else { print "next"; } if ($bBottomNavigation) { print "
"; print "Top"; print "Bottom"; } } print "

"; print "\n"; } # ------------------------------------------------------------- # helper # ------------------------------------------------------------- sub get_result_bg_color ( $ ) { my $cell = shift; my $bg = ""; if ($bUseColor) { $bg = " bgcolor=\"#ddddee\"" if ($cell =~ /^free$/); $bg = " bgcolor=\"#ddddee\"" if ($cell =~ /^--$/); $bg = " bgcolor=\"#ddeedd\"" if ($cell =~ /\+[!]?$/); $bg = " bgcolor=\"#eedddd\"" if ($cell =~ /[^-]-[!]?$/); $bg = " bgcolor=\"#f8f8dd\"" if ($cell =~ /=[!]?$/); } return $bg } sub wash_result_marks ( $ ) { my $s = shift; if (!$bResultMarks) { $s =~ s/\+$//; $s =~ s/\+!$/!/; $s =~ s/\-$//; $s =~ s/\-!$/!/; $s =~ s/\=$//; $s =~ s/\=!$/!/; $s =~ s/-/--/; } return $s; } sub s2html ( $ ) { my $s = shift; return " " if (not defined $s); $s =~ s/&/&/g; $s =~ s//>/g; $s =~ s/¼/¼/g; $s =~ s/½/½/g; $s =~ s/¾/¾/g; $s =~ s/\n/
/g; $s =~ s/ / /g; $s=" " if ($s eq " "); $s=" " if ($s eq ""); return $s; } sub p_html ( $ ) { my $s = shift; print s2html($s); }