#! /usr/local/bin/perl ###################################################### #BooCrossWordPazzle,v1.05 / this program is free. # # (C) BooBooClub 2001-2005 # ###################################################### #set data $view = './view.html'; $dat = './bcwp.dat'; $wcolor = '#00aa00'; $hcolor = '#8800ff'; $border = '#aaaaaa'; $good = './good.html'; $bad = './retry.html'; #set lib require './jcode.pl'; #lock &lock; #read if ($ENV{'REQUEST_METHOD'} eq "POST"){ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else{ $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ tr/+/ /; $name =~ s/\cM\n//g; $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $name =~ s/\,//g; $name =~ s//>/ig; $name =~ s/\r\n|[\r\n]/
/ig; $value =~ tr/+/ /; $value =~ s/\cM\n//g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\,//g; $value =~ s//>/ig; $value =~ s/\r\n|[\r\n]/
/ig; &jcode'convert(*value,'sjis'); $FORM{$name} = $value; } #branch if($FORM{'check'}){ ✓ } else{ &view; } sub check{ open (DAT,"$dat"); @dat = ; close (DAT); $dat = join('',@dat); @dat = split(/\n\n/,$dat); foreach $dat(@dat){ if($dat =~ /data=/){ $dat =~ s/data=.*?\n//; @data = split(/\n/,$dat); map{$_ =~ s/,$//;}@data; $h = 1; foreach $data(@data){ @edata = split(/,/,$data); $w = 1; foreach $edata(@edata){ if($edata ne ' ' && $edata !~ /[\s]/ && $edata ne ''){ $box = $w.'-'.$h; push(@box,$box); $DAT{$box} = $edata; } $w++; } $h++; } } } $i = 0; foreach $box(@box){ if($DAT{$box} ne ' ' && $DAT{$box} ne $FORM{$box}){ $i++; last; } } if($i == 0){ open (HTML,"$good"); @html = ; close (HTML); } else{ open (HTML,"$bad"); @html = ; close (HTML); } print "Content-type: text/html\n\n"; print @html; unlink("$lockfile"); exit 0; } sub view{ open (DAT,"$dat"); @dat = ; close (DAT); $dat = join('',@dat); @dat = split(/\n\n/,$dat); foreach $dat(@dat){ if($dat =~ /size=/){ @size = split(/=/,$dat); ($FORM{'wide'},$FORM{'high'}) = split(/-/,$size[1]); } if($dat =~ /data=/){ $dat =~ s/data=.*?\n//; @data = split(/\n/,$dat); map{$_ =~ s/,$//;}@data; $h = 1; foreach $data(@data){ @edata = split(/,/,$data); $w = 1; foreach $edata(@edata){ if($edata ne ' ' && $edata !~ /[\s]/ && $edata ne ''){ $box = $w.'-'.$h; $FORM{$box} = $edata; } $w++; } $h++; } } if($dat =~ /wkey=/){ $dat =~ s/wkey=.*?\n//; @data = split(/\n/,$dat); @wkey = @data; foreach $data(@data){ @edata = split(/:/,$data); foreach $edata(@edata){ $key = 'w:'.$edata[0]; $FORM{$key} = $edata[1]; } } } if($dat =~ /hkey=/){ $dat =~ s/hkey=.*?\n//; @data = split(/\n/,$dat); @hkey = @data; foreach $data(@data){ @edata = split(/:/,$data); foreach $edata(@edata){ $key = 'h:'.$edata[0]; $FORM{$key} = $edata[1]; } } } } open (HTML,"$view"); @view = ; close (HTML); $html = join('',@view); $wide = $FORM{'wide'}; $high = $FORM{'high'}; #BCWP $vw = ''; $vw .= ''."\n"; $vw .= ''."\n"; $vw .= ''."\n"; for($h = 0; $h <= $high; $h++){ $vw .= ''."\n"; for($w = 0; $w <= $wide; $w++){ if($w == 0 && $h == 0){ $vw .= ''."\n"; } elsif($h == 0){ $vw .= ''."\n"; } elsif($w == 0){ $vw .= ''."\n"; } else{ $box = $w.'-'.$h; if($FORM{$box} ne ''){ $vw .= ''."\n"; } else{ $vw .= ''."\n"; } } } $vw .= ''."\n"; } $vw .= '
'."$w".''."$h".'
'."\n"; #KEY map{ $_ =~ s/(\d+?)-(\d+?):(.+)/$1<\/font>-$2<\/font>:$3
/; }@wkey; $wkey = join('',@wkey); map{ $_ =~ s/(\d+?)-(\d+?):(.+)/$2<\/font>-$1<\/font>:$3
/; }@hkey; $hkey = join('',@hkey); $html =~ s//$vw/; $html =~ s//$wkey/; $html =~ s//$hkey/; print "Content-type: text/html\n\n"; print $html; unlink("$lockfile"); exit 0; } sub lock{ $lockfile = './lock/lockfile'; $retry = 1; until (symlink("$dat", "$lockfile")){ if (++$retry >= 30){ &lockerror; exit 0; } sleep(1); } } sub lockerror{ print "Content-type: text/html\n\n"; print "Busy!\n"; print "\n"; print "

現在サーバが混雑しています。



\n"; print "恐れ入りますがもうしばらくして再度操作を行ってください。\n"; print "
\n"; unlink("$lockfile"); exit 0; }