upconvert is fully working for 1.2.x -> 1.3.x conversions,

so the old Perl version and the regression test script can go away.
This commit is contained in:
Eric S. Raymond 2007-04-24 17:24:13 +00:00
parent 4f3589c25c
commit 2d0cbe8fb9
3 changed files with 2 additions and 326 deletions

View file

@ -124,6 +124,8 @@ Version 1.3.1+svn:
* New tool, macroscope, generates cross-reference reports on macro usage.
* The old find-unused-images and find-unused-sounds scripts are deleted
(replaced by macroscope).
* New tool upconvert handles converting maps and resource file names
between versions. It replaces map_convert.pl, which is now gone.
* New tool to create the unit tree in html, as used for units.wesnoth.org
(written by elricz)
* miscellanous changes and bug fixes

View file

@ -1,288 +0,0 @@
#!/usr/bin/perl -w
#script to convert from single char maps to multiple character maps
sub printUsage{
print "map_convert.pl terrain.cfg map_file.cfg [new_map_file.cfg]\n";
}
sub get_adjacent{
#returns string of original location+adjacent locations on hex 1-char map
$x=shift(@_);
$y=shift(@_);
local @map=@_;
foreach(@map){
chomp;
}
# $orig=substr($map[$y],$x,1);
$odd=($x) % 2;
# print "$orig($x,$y) : $odd";
$adj=substr($map[$y],$x,1);
if($x>0){
$adj.=substr($map[$y],$x-1,1);
# print "\tW";
}
if($x<length($map[$y])){
$adj.=substr($map[$y],$x+1,1);
# print "\tE";
}
if($y>0){
$adj.=substr($map[$y-1],$x,1);
# print "\tN";
}
if($y<$#_){
$adj.=substr($map[$y+1],$x,1);
# print "\tS";
}
if($x>0 && $y>0 && !$odd){
$adj.=substr($map[$y-1],$x-1,1);
# print "\tNW";
}
if($x<length($map[$y]) && $y>0 && !$odd){
$adj.=substr($map[$y-1],$x+1,1);
# print "\tNE";
}
if($x>0 && $y<$#_ && $odd){
$adj.=substr($map[$y+1],$x-1,1);
# print "\tSW";
}
if($x<length($map[$y]) && $y<$#_ && $odd){
$adj.=substr($map[$y+1],$x+1,1);
# print "\tSE";
}
# print "\n";
return($adj);
}
if($#ARGV <1 ||$#ARGV>2){
printUsage();
exit;
}
$terrain_file=shift(@ARGV);
$map_file=shift(@ARGV);
if($#ARGV < 0){
$new_map_file=$map_file;
$backup=$map_file.".bak";
system("cp $map_file $backup") && die "could not create backup file: $backup\n";
}else{
$new_map_file=shift(@ARGV);
if(-e "$new_map_file"){ die "New map file already exists: $new_map_file\n";}
}
if(! -r "$terrain_file"){ die "can not read terrain file: $terrain_file\n";}
if(! -r "$map_file"){ die "can not read map file: $map_file\n";}
$conversion{1}='1 _K';
$conversion{2}='2 _K';
$conversion{3}='3 _K';
$conversion{4}='4 _K';
$conversion{5}='5 _K';
$conversion{6}='6 _K';
$conversion{7}='7 _K';
$conversion{8}='8 _K';
$conversion{9}='9 _K';
$conversion{' '}='_s';
#parse terrain_file
open(TERRAIN, "<$terrain_file");
$countdef=0;
$max_len=0;
while($line=<TERRAIN>){
if($line=~/^\#ifdef/){
#skip ifdef'd comments
$countdef+=1;
while(($countdef >0) && ($line=<TERRAIN>)){
if($line=~/^\#ifdef/){
$countdef+=1;
}
if($line=~/^\#endif/){
$countdef-=1;
}
}
}
elsif($line=~/^\#/){}
else{
#parse [terrain] blocks
if($line=~/^\[terrain\]/){
$char='';
$string='';
$in=1;
while(($in>0) && ($line=<TERRAIN>)){
$line=~s/\s+//;
if($line=~/^char/){
$char=$line;
$char=~s/char//;
($dummy,$char)=split('=',$char);
$char=~s/\"//g;
$char=~s/\s+//g;
$char=substr($char,0,1);
}elsif($line=~/^string/){
$string=$line;
$string=~s/^string//;
($dummy,$string)=split('=',$string);
$string=~s/\"//g;
$string=~s/\s+//g;
}elsif($line=~/\[\/terrain\]/){
$in=0;
if((length($char)>0) && (length($string)>0)){
# print "$char ---> $string\n";
if(length($string)>$max_len){
$max_len=length($string);
}
$conversion{$char}=$string;
}
}
}
}
}
}
close(TERRAIN);
#while (($k, $v) = each(%conversion)) {
# print "$k -> $v\n";
#}
$width=$max_len+2;
open(MAP, "<$map_file");
@mfile=();
if ($map_file=~/.cfg$/) {
$map_only=0;
} else {
$map_only=1;
}
while($line=<MAP>){
push(@mfile,$line);
if($line=~/map_data/){
$map_only=0;
}
}
push(@mfile,"\n");
@map=();
close(MAP);
$lineno = $baseline = 0;
while($#mfile){
$line=shift(@mfile);
$lineno++;
# Don't start parsing on map_data="{, let the WML preprocessor have it
# Non-alphanumerics that can appear are / | \ & _ ~ ? [ ]'
if($map_only || ($line=~/map_data=\"[A-Za-z0-9\/|\\&_~?\[\]]{2,}\r?/)){
$baseline = $lineno;
$cont=1;
#read map assumes map is more than 1 line long.
if(!$map_only){
($dummy,$line)=split('"',$line);
}
if((defined($line)) && (length($line))){push(@map,$line)};
# print "$line\n";
while(($cont) && ($#mfile)){
$line=shift(@mfile);
$lineno++;
if($line=~/^#/) {
push(@newfile,$line);
next;
}
if($line=~/\"/){
$cont=0;
($line,$dummy)=split('"',$line);
}
if (!$line=~/\n/){
$line.="\n"
}
if(defined($line) && length($line)){push(@map,$line)};
}
if(! $map_only){
$line="map_data=\"\n";
push(@newfile,$line);
}
$y=0;
$format="%${width}.${max_len}s";
foreach(@map){
chomp;
if($_=~/,/){die "map file appears to be converted already\n";}
$line='';
for($x=0;$x!=length($_);$x++){
$hex='';
$char=substr($_,$x,1);
# print "$char";
if ($char=~/\r/) {
$hex="\r"
}elsif(defined($conversion{$char})){
$hex=sprintf($format,$conversion{$char});
}else{
$ord=ord($char);
$errline = $baseline + $y + 1;
print "mapconvert.pl: \"$map_file\", line $errline: unrecognized map character '$char' ($ord) at ($x,$y)\n";
exit 1;
# $hex=sprintf($format,$char);
}
if($hex=~/_K/){
#convert keeps according to adjacent hexes
$adj=get_adjacent($x,$y,@map);
# print "adjacent: $adj\n";
%hexcount=();
for($i=1;$i<length($adj);$i++){
#intentionally skipping 0 as it is original hex
$a=(substr($adj,$i,1));
$ca=$conversion{$a};
if(!defined($ca)){
$ord=ord($a);
$errline = $baseline + $y + 1;
print "mapconvert.pl: \"$map_file\", line $errline: error in adjacent hexes: ($x,$y,$i)[$ord]:$a\n";
}
if($ca=~/^C/){ #this is a castle hex
$hexcount{$ca}++;
}
}
$maxc=0;
$maxk="Ch";
# Next line is a hack to make this code pass regression
# testing against the Python port. Without the sort, when
# there are two terrain types that occur in equal numbers
# greater than any others, which one gets picked will be
# randomly dependent on Perl's dictionary hash function.
@sorted = sort keys(%hexcount);
foreach(@sorted){
if($hexcount{$_}>$maxc){
$maxc=$hexcount{$_};
$maxk=$_;
}
# print "$_ $hexcount{$_}\n";
}
# print "Dominated by $maxk\n";
$maxk=~s/^C/K/;
$hex=~s/_K/$maxk/;
}
$line.=$hex;
if($x!=length($_)-1){$line.=','};
}
$line.="\n";
push(@newfile,$line);
# print "$line\n";
$y++;
}
if($map_only){
$line="\n";
}else{
$line="\"\n";
}
push(@newfile,$line);
}else{
push(@newfile,$line);
}
}
open(NEWMAP,">$new_map_file");
foreach(@newfile){
print NEWMAP "$_";
}

View file

@ -1,38 +0,0 @@
#!/bin/bash
#
# Test map_convert.py against map_convert.pl.
# If these scripts are really equivalent, we should see no diffs.
# UMC should point at a mirror of the campaign server
UMC=../../umc
TERRAIN=../terrain.cfg
# Clear the decks
find $UMC -type f -regex '.*-p[ly]' -exec rm {} \;
# The enumeration relies on $ not being in any filename
for file in `find $UMC -name '*.cfg' | tr ' ' '$'; find $UMC -type f \! -name '*.png' \! -name '*.jpg' -wholename '*/maps/*'`
do
file=`echo $file | tr '$' ' '`
if map_convert.pl ${TERRAIN} "${file}" "${file}-pl"
then
if map_convert.py "${file}" "${file}-py"
then
if diff -u "${file}-pl" "${file}-py"
then
rm "${file}-pl" "${file}-py"
else
echo "${file}: regression failed"
fi
else
echo "${file}: Python conversion failed"
rm "${file}-pl"
exit 1
fi
else
echo "${file}: Perl conversion failed"
continue
fi
done
exit 0