User:Dysprosia~enwikinews
Jump to navigation
Jump to search
Use as
cat crossword | prep.pl | grid2wsyn.pl
and edit (or "script-add") extra text to finish off.
#!/usr/bin/perl
# prep.pl
# Autonumbers a textual grid.
# Copyright (c) Dysprosia, 2005, All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Dysprosia may be used to endorse or promote products
# derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
$\="\n";
while(<>)
{
chomp;
last if /^--$/;
@line = split /,/;
$j=0;
foreach (@line)
{
#print "'$_'";
$array[$i][$j] = $_;
$j++;
}
$i++;
}
$number=1;
for($y=0; $y < $i; $y++)
{
for($x=0; $x < $j; $x++)
{
my $sq = $array[$y][$x];
#Across cases
if($sq =~ /[\.#]/ && $x == 0 && $x != $j-1 && $array[$y][$x+1] =~ /[\.#]/)
{
$sq = $number;
$acclues .= ";$number. ".$\;
if($y != $i-1 && $array[$y+1][$x] =~ /[\.#]/ && $array[$y-1][$x] eq "*"){$dnclues .= ";$number. ".$\}
if($y == 0 && $array[$y+1][$x] =~ /[\.#]/){$dnclues.=";$number. ".$\};
$number++;
}
if($sq =~ /[\.#]/ && $x != $j-1 &&
$array[$y][$x-1] eq "*" && $array[$y][$x+1] =~ /[\.#]/)
{
$sq = $number;
$acclues .= ";$number. ".$\;
if($y != $i-1 && $array[$y+1][$x] =~ /[\.#]/ && $array[$y-1][$x] eq "*"){$dnclues .= ";$number. ".$\}
if($y == 0 && $array[$y+1][$x] =~ /[\.#]/){$dnclues.=";$number. ".$\};
$number++;
}
#Down cases
if($sq =~ /[\.#]/ && $y == 0 && $y != $i-1 && $array[$y+1][$x] =~ /[\.#]/)
{
$sq = $number;
$dnclues .= ";$number. ".$\;
$number++;
}
if($sq =~ /[\.#]/ && $y != $i-1 && $array[$y-1][$x] eq "*" && $array[$y+1][$x] =~ /^[\.#]/)
{
$sq = $number;
$dnclues .= ";$number. ".$\;
$number++;
}
$line .= $sq.",";
}
print $line;
$line = "";
}
print "--";
print $acclues;
print "--";
print $dnclues;
|
|
#!/usr/bin/perl
# grid2wsyn.pl
# Converts a textual grid into Wikitext format
# Copyright (c) Dysprosia, 2005, All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Dysprosia may be used to endorse or promote products
# derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Print the table headers and crossword headers
print $cwdframe_begin;
print $cwd_begin;
while(<>)
{
if(/--/)
{
# Set this if we're converting an grid with clues
# Otherwise we simply end
$clues="true";
last;
}
chomp $_;
@line = split /,/;
# Process a row.
print $cwd_rowsep;
foreach (@line)
{
print $cwd_blacksq if(/\*/);
print $cwd_whitesq if(/\./);
print $cwd_letterbegin.$1.$cwd_letterend if (/([a-z])/i);
print "|<sup>".$1."</sup>" if (/([0-9]+)/i);
if(/\#/)
{
print $cwd_numberbegin.$number.$cwd_numberend if(/\#/);
$number++;
}
}
}
print $cwd_end;
if(!$clues)
{
# We're printing an answers grid, so just close off the frame and quit.
print "|} <!-- Frame -->";
exit;
}
print $cwdframe_mid;
# Clues section.
print $ac_begin;
# Taken up from the main row processing loop.
while(<>)
{
chomp;
last if /--/;
print ";".$_;
}
print $ac_end;
print $cwdframe_cluesep;
print $dn_begin;
# Taken up from the across clues processing loop.
while(<>)
{
chomp;
last if /--/;
print ";".$_;
}
print $dn_end;
print "|} <!-- Frame -->";
BEGIN
{
# Constants.
$number = 1;
$\="\r\n";
$dimspec = 30;
# Strings.
$cwdframe_begin = '{| border=0 cellpadding=0 cellspacing=0 style="margin: 0em 0em 1em 1em;"'.$\."|colspan=2| <!-- Frame-->".$\;
$cwd_begin = "{| border=1 cellpadding=0 cellspacing=0";
$cwd_rowsep = "|- valign=top";
$cwd_blacksq = "|[[Image:Black 30x30.png|$dimspec"."px|]]";
$cwd_whitesq = "| " ;
$cwd_letterbegin = "|align=\"center\"|'''";
$cwd_letterend = "'''";
$cwd_numberbegin = "|<sup>";
$cwd_numberend = "</sup>";
$cwd_end = "|} <!-- Crossword -->";
$cwdframe_mid= "|- <!-- Frame -->".$\."|valign=top style=width:50%|";
$ac_begin = '{|align="left" <!-- Across -->'.$\."| <!-- Across -->".$\."==Across==";
$ac_end = "|} <!-- Across -->";
$cwdframe_cluesep= "|valign=top style=width:50%|";
$dn_begin = '{|align="left" <!-- Down -->'.$\."| <!-- Down -->".$\."==Down==";
$dn_end = "|} <!-- Down -->";
$cwdframe_end = "|} <!-- Frame -->";
}
|
|
#!/usr/bin/perl
# grid2text.pl
# Converts a textual crossword grid into Across Lite TEXT import syntax.
# Copyright (c) Dysprosia, 2005, All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Dysprosia may be used to endorse or promote products
# derived from this software without specific prior written permission.
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# Grid format: * - black square, # - numbered square, . - light square,
# or use a letter for a letter in the grid.
# Comma seperated units.
# eg:
# *,#,.,*
# .,.,A,*
# End the grid with --, then follow with the Across clues, --, then the Down clues, --
# This script assumes the clues are numbered! (it strips them since Across Lite doesn't need them)
$\="\r\n";
print $acr_puzhead;
print $acr_title;
print $ARGV[0];
print $acr_author;
print "";
print $acr_copyright;
print "";
# Get the answer grid (last in grid format)
$section = 0;
# Junk the empty grid.
while(<>) { last if /--/; }
# Across clues
while(<>)
{
chomp;
last if /--/;
push @across, $_;
}
# Down clues
while(<>)
{
chomp;
last if /--/;
push @down, $_;
}
# Answer grid (useful for Across lite)
while(<>)
{
chomp;
s/,//g;
s/\*/./g;
push @lines, $_;
}
# Compute the grid size for Across
$llen = length $lines[0];
$llen2 = 0;
foreach (@lines)
{
if(length($_) == $llen)
{
$llen = length $_;
}
else
{
die;
}
$llen2++;
}
print $acr_size;
print "$llen"."x"."$llen2";
# Print the grid
print $acr_grid;
foreach (@lines) { print; }
# Print across clues
print $acr_across;
foreach (@across)
{
my @clue = split / /;
print "@clue[1..$#across]";
}
print $acr_down;
foreach (@down)
{
my @clue = split / /;
print "@clue[1..$#down]";
}
BEGIN
{
$acr_puzhead = "<ACROSS PUZZLE>";
$acr_title = "<TITLE>";
$acr_author = "<AUTHOR>";
$acr_copyright = "<COPYRIGHT>";
$acr_size = "<SIZE>";
$acr_grid = "<GRID>";
$acr_across = "<ACROSS>";
$acr_down = "<DOWN>";
}
|