1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
#!/usr/local/bin/perl
#eval 'exec /usr/local/bin/perl -S $0 ${1+"$@"}'
# if $running_under_some_shell;
require "getopts.pl";
&Getopts('o:b:');
#die "Usage: map2g [-o outfile] [-b base-module] [infile]\n" if @ARGV > 1;
#
# Get stdout set up and the default module name
#
if ( $opt_o ) {
#
# If they give us an output file name, open it
# and use it as the module name (minus path and extension).
#
open(STDOUT, ">$opt_o") || die "Couldn't open $opt_o for output: $!\n";
($m = $opt_o) =~ s#(.*/)?(.*)\.g$#$2#;
} elsif (@ARGV) {
#
# If they give us an input file,
# use it as the output file name (minus path and extension plus .g)
# and use it as the module name (minus path and extension).
#
($m = $ARGV[0]) =~ s#(.*/)?(.*)\.map$#$2#;
unless ( -e "$m.g" ) {
open(STDOUT, ">$m.g") || die "Couldn't open $m.g for output: $!\n";
}
} else {
#
# OK, we got nothin', output is stdout and module name is junk.
#
$m = 'xxx';
}
#
# This is the base-module option
#
if ( $opt_b ) {
# Try to open it as a file
if ( open(BM, "$opt_b") ) {
# assume that it's an old-style map, period or scenario file.
@types = grep(s/^\s*"(.)"\s+.*\s+ttype\s*(;.*)*$/$1/, <BM>);
$c = join('', @types);
}
# strip the path and extension (if there is one).
$opt_b =~ s#(.*/)?(.*)\.(map|per|scn)$#$2#;
# otherwise it's probably just a name.
$b = qq/ (default-base-module "$opt_b")\n/;
}
while (<>) {
# Nab the header line...
if (/^Xconq . [\+-]* \s*(.*)$/) {
print qq/(game-module "$m"\n$b (blurb "$1")\n )\n/;
next;
}
# Get the world size...
if (/^Map ([0-9]*) ([0-9]*) /) {
local($i);
# if this is .map file the the world is cylindrical.
print qq/(area $1 $2) (world $1)\n (area (terrain (by-char "$c")\n/;
for ($i = 0; $i < $2; ++$i) {
$_ = <>;
chop;
print qq/ "$_"\n/;
}
# close the parens at the end of the map.
print " ))\n";
next;
}
s/^/;/;
print;
}
|