#! /usr/local/bin/perl ####################################################### #BooCrossWordPazzleMaker,v1.05 / this program is free.# # (C) BooBooClub 2001-2005 # ####################################################### #set data $dat = './bcwp.dat'; $wcolor = '#00aa00'; $hcolor = '#8800ff'; $answer = '#ff0000'; $border = '#aaaaaa'; #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{'set'}){ &set; } elsif($FORM{'next'}){ &next; } elsif($FORM{'back'}){ &back; } elsif($FORM{'next2'}){ &next2; } elsif($FORM{'make'}){ &make; } elsif($FORM{'read'}){ &read; } sub set{ $wide = $FORM{'wide'}; $high = $FORM{'high'}; if($wide == 0 || $high == 0 || $wide eq '' || $high eq ''){ &error; } print "Content-type: text/html\n\n"; print ''."\n"; print ''."\n"; print 'Boo CrossWord Pazzle -MakingPage-'."\n"; print ''."\n"; print ''."\n"; print ''; print '
'."\n"; print '
'."\n"; print '
'."\n"; print 'Boo CrossWord Pazzle -MakingPage-
'."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; print ''."\n"; for($h = 0; $h <= $high; $h++){ print ''."\n"; for($w = 0; $w <= $wide; $w++){ if($w == 0 && $h == 0){ print ''."\n"; } elsif($h == 0){ print ''."\n"; } elsif($w == 0){ print ''."\n"; } else{ $box = $w.'-'.$h; if($FORM{$box} ne ''){ print ''."\n"; } else{ print ''."\n"; } } } print ''."\n"; } print '
'."$w".''."$h".'
'."\n"; print '
'."\n"; print ''."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; unlink("$lockfile"); exit 0; } sub next{ $wide = $FORM{'wide'}; $high = $FORM{'high'}; for($h = 1; $h <= $high; $h++){ $wline = $hline = $twline = $thline = ''; for($w = 1; $w <= $wide; $w++){ $wbox = $w.'-'.$h; $hbox = $h.'-'.$w; $wline .= "$FORM{$wbox}".','; $hline .= "$FORM{$hbox}".','; $twline .= "$w-$h:$FORM{$wbox}".','; $thline .= "$h-$w:$FORM{$hbox}".','; } push(@wline,$wline); push(@hline,$hline); push(@twline,$twline); push(@thline,$thline); } $twline = ''.join('',@twline); $twline =~ s/\d+?-\d+?:,//g; $twline =~ s/,\d+?-\d+?://g; $twline =~ s/()+//g; $twline =~ s/,//g; @twline = split(//,$twline); $thline = ''.join('',@thline); $thline =~ s/\d+?-\d+?:,//g; $thline =~ s/,\d+?-\d+?://g; $thline =~ s/()+//g; $thline =~ s/,//g; @thline = split(//,$thline); print "Content-type: text/html\n\n"; print ''."\n"; print ''."\n"; print 'Boo CrossWord Pazzle -MakingPage-'."\n"; print ''."\n"; print ''."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print 'Boo CrossWord Pazzle -MakingPage-
'."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; print ''."\n"; for($h = 0; $h <= $high; $h++){ print ''."\n"; for($w = 0; $w <= $wide; $w++){ if($w == 0 && $h == 0){ print ''."\n"; } elsif($h == 0){ print ''."\n"; } elsif($w == 0){ print ''."\n"; } else{ $box = $w.'-'.$h; if($FORM{$box} eq '' || $FORM{$box} !~ /[^\s]/){ $FORM{$box} = ''; print ''."\n"; } else{ print ''."\n"; } } } print ''."\n"; } print '
'."$w".''."$h".''.$FORM{$box}.''.$FORM{$box}.'
'."\n"; print '
'."\n"; print ''."\n"; print '    '; print ''."\n"; print '

'."\n"; print '
'."\n"; print '
'."\n"; print '
ヨコのカギ作成
'."\n"; print '
'."\n"; print '
タテのカギ作成
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; foreach $line(@twline){ if($line eq '' && $line !~ /[^\s]/){ next; } @line = split(/:/,$line); $word = 'w:'.$line[0]; $delword = 'dw:'.$line[0]; if($FORM{$delword} eq 'del'){ $checked = ' checked'; } else{ $checked = ''; } if($FORM{$word} ne ''){ $wvalue = ' value="'."$FORM{$word}".'"'; } else{ $wvalue = ''; } $line =~ s/(\d+?)-(\d+?):(.+)/$2<\/font>-$1<\/font>:$3<\/font>/; print ''."\n"; } print '
削除カギ
'.$line.'
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; foreach $line(@thline){ if($line eq '' && $line !~ /[^\s]/){ next; } @line = split(/:/,$line); $word = 'h:'.$line[0]; $delword = 'dh:'.$line[0]; if($FORM{$delword} eq 'del'){ $checked = ' checked'; } else{ $checked = ''; } if($FORM{$word} ne ''){ $wvalue = ' value="'."$FORM{$word}".'"'; } else{ $wvalue = ''; } $line =~ s/(\d+?)-(\d+?):(.+)/$2<\/font>-$1<\/font>:$3<\/font>/; print ''."\n"; } print '
削除カギ
'.$line.'
'."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print '    '; print ''."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; unlink("$lockfile"); exit 0; } sub next2{ $wide = $FORM{'wide'}; $high = $FORM{'high'}; for($h = 1; $h <= $high; $h++){ $wline = $hline = $twline = $thline = ''; for($w = 1; $w <= $wide; $w++){ $wbox = $w.'-'.$h; $hbox = $h.'-'.$w; $wline .= "$FORM{$wbox}".','; $hline .= "$FORM{$hbox}".','; $twline .= "$w-$h:$FORM{$wbox}".','; $thline .= "$h-$w:$FORM{$hbox}".','; } push(@wline,$wline); push(@hline,$hline); push(@twline,$twline); push(@thline,$thline); } $twline = ''.join('',@twline); $twline =~ s/\d+?-\d+?:,//g; $twline =~ s/,\d+?-\d+?://g; $twline =~ s/()+//g; $twline =~ s/,//g; @twline = split(//,$twline); $thline = ''.join('',@thline); $thline =~ s/\d+?-\d+?:,//g; $thline =~ s/,\d+?-\d+?://g; $thline =~ s/()+//g; $thline =~ s/,//g; @thline = split(//,$thline); print "Content-type: text/html\n\n"; print ''."\n"; print ''."\n"; print 'Boo CrossWord Pazzle -MakingPage-'."\n"; print ''."\n"; print ''."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print 'Boo CrossWord Pazzle -MakingPage-
'."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; print ''."\n"; for($h = 0; $h <= $high; $h++){ print ''."\n"; for($w = 0; $w <= $wide; $w++){ if($w == 0 && $h == 0){ print ''."\n"; } elsif($h == 0){ print ''."\n"; } elsif($w == 0){ print ''."\n"; } else{ $box = $w.'-'.$h; if($FORM{$box} eq '' || $FORM{$box} !~ /[^\s]/){ $FORM{$box} = ''; print ''."\n"; } else{ print ''."\n"; } } } print ''."\n"; } print '
'."$w".''."$h".''.$FORM{$box}.''.$FORM{$box}.'
'."\n"; print '
'."\n"; print ''."\n"; print '    '; print ''."\n"; print '

'."\n"; print '
'."\n"; print '
'."\n"; print '
ヨコのカギ
'."\n"; print '
'."\n"; print '
タテのカギ
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; foreach $line(@twline){ if($line eq '' && $line !~ /[^\s]/){ next; } @line = split(/:/,$line); $word = 'w:'.$line[0]; $delword = 'dw:'.$line[0]; if($FORM{'next2'} eq ''){ $word =~ s/(\d+?)-(\d+?)/$2-$1/; $delword =~ s/(\d+?)-(\d+?)/$2-$1/; } if($FORM{$delword} ne 'del' && $FORM{$word} ne '' && $FORM{$word} =~ /[^\s]/){ $line =~ s/(\d+?)-(\d+?):(.+)/$2<\/font>-$1<\/font>:$3<\/font>/; print ''."\n"; print ''."\n"; } if($FORM{$delword} eq 'del'){ print ''."\n"; } } print '
カギ
'.$line.''.$FORM{$word}.'
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; foreach $line(@thline){ if($line eq '' && $line !~ /[^\s]/){ next; } @line = split(/:/,$line); $word = 'h:'.$line[0]; $delword = 'dh:'.$line[0]; if($FORM{'next2'} eq ''){ $word =~ s/(\d+?)-(\d+?)/$2-$1/; $delword =~ s/(\d+?)-(\d+?)/$2-$1/; } if($FORM{$delword} ne 'del' && $FORM{$word} ne '' && $FORM{$word} =~ /[^\s]/){ $line =~ s/(\d+?)-(\d+?):(.+)/$2<\/font>-$1<\/font>:$3<\/font>/; print ''."\n"; print ''."\n"; } if($FORM{$delword} eq 'del'){ print ''."\n"; } } print '
カギ
'.$line.''.$FORM{$word}.'
'."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print '    '; print ''."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; unlink("$lockfile"); exit 0; } sub make{ $wide = $FORM{'wide'}; $high = $FORM{'high'}; for($h = 1; $h <= $high; $h++){ $wline = $hline = $twline = $thline = ''; for($w = 1; $w <= $wide; $w++){ $wbox = $w.'-'.$h; $hbox = $h.'-'.$w; $wline .= "$FORM{$wbox}".','; $hline .= "$FORM{$hbox}".','; $twline .= "$w-$h:$FORM{$wbox}".','; $thline .= "$w-$h:$FORM{$hbox}".','; } push(@wline,$wline); push(@hline,$hline); push(@twline,$twline); push(@thline,$thline); } $twline = ''.join('',@twline); $twline =~ s/\d+?-\d+?:,//g; $twline =~ s/,\d+?-\d+?://g; $twline =~ s/()+//g; $twline =~ s/,//g; @twline = split(//,$twline); $thline = ''.join('',@thline); $thline =~ s/\d+?-\d+?:,//g; $thline =~ s/,\d+?-\d+?://g; $thline =~ s/()+//g; $thline =~ s/,//g; @thline = split(//,$thline); $wspace = ' '; map{ $_ =~ s/^,/$wspace,/g; $_ =~ s/,,/,$wspace,/g; $_ =~ s/,,/,$wspace,/g; }@wline; $wline = join("\n",@wline); $key = 'w:'; map{ $_ =~ s/(\d+?)-(\d+?)(:).*/$1-$2$3$FORM{$key.$1.'-'.$2}/g; }@twline; $key = 'h:'; map{ $_ =~ s/(\d+?)-(\d+?)(:).*/$1-$2$3$FORM{$key.$2.'-'.$1}/g; }@thline; $twline = join("\n",@twline)."\n"; $twline =~ s/\d+?-\d+?:\s*\n//g; $twline =~ s/^(\s+|\n+)//g; $twline =~ s/\n+$//; $thline = join("\n",@thline)."\n"; $thline =~ s/\d+?-\d+?:\s*\n//g; $thline =~ s/^(\s+|\n+)//g; $thline =~ s/\n+$//; $data = 'size='.$wide.'-'.$high."\n\n"; $data .= 'data='."\n".$wline."\n\n"; $data .= 'wkey='."\n".$twline."\n\n"; $data .= 'hkey='."\n".$thline."\n\n"; open (DAT,">$dat"); print DAT $data; close (DAT); print "Content-type: text/html\n\n"; print ''."\n"; print ''."\n"; print 'Boo CrossWord Pazzle -MakingPage-'."\n"; print ''."\n"; print ''."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print 'Boo CrossWord Pazzle -MakingPage-
'."\n"; print '
'."\n"; print '
'."\n"; print '
'."\n"; print 'パズルデータの作成が完了しました。'."\n"; print '
'."\n"; print '
'."\n"; print '作成画面トップに戻る
'."\n"; print '
'."\n"; print '
'."\n"; print ''."\n"; print ''."\n"; unlink("$lockfile"); exit 0; } sub read{ 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); 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); foreach $data(@data){ @edata = split(/:/,$data); foreach $edata(@edata){ $key = 'h:'.$edata[0]; $FORM{$key} = $edata[1]; } } } } &next2; } 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; } sub error{ print "Content-type: text/html\n\n"; print "Error!\n"; print "\n"; print "

Error!



\n"; print "縦横のサイズ指定に誤りがあります。\n"; print "
\n"; unlink("$lockfile"); exit 0; }