| 1 |
#!/usr/bin/perl |
| 2 |
# |
| 3 |
# This script goes and fixes the *_style names for random maps. |
| 4 |
# It is aimed at the mlab maps. the original mlab maps used |
| 5 |
# uppercase file names, which were quite ugly, and also put the |
| 6 |
# new styles with old styles, which isn't good when it comes to |
| 7 |
# random styles. Instead, I put those style maps into their own |
| 8 |
# subdirectory so they should only show up on mlab maps. |
| 9 |
# |
| 10 |
|
| 11 |
&maplist("."); |
| 12 |
|
| 13 |
while ($file = shift (@maps)) { |
| 14 |
&updatemap; |
| 15 |
} |
| 16 |
|
| 17 |
|
| 18 |
exit; |
| 19 |
|
| 20 |
# return table containing all objects in the map |
| 21 |
sub updatemap { |
| 22 |
local ($m, $made_change=0); |
| 23 |
$last = ""; |
| 24 |
$parent = ""; |
| 25 |
|
| 26 |
if (! open (IN, $file)) { |
| 27 |
print "Can't open map file $file\n"; |
| 28 |
return; |
| 29 |
} |
| 30 |
if (! open(OUT, ">$file.new")) { |
| 31 |
print "Can't open output file $file.new\n"; |
| 32 |
return; |
| 33 |
} |
| 34 |
if ($VERBOSE) { |
| 35 |
print "Testing $file, "; |
| 36 |
} |
| 37 |
while (<IN>) { |
| 38 |
if (/(.*style) (MLAB.*)/) { |
| 39 |
$style= $1 . "style"; |
| 40 |
$dest = "mlab/" . $2; |
| 41 |
$dest =~ tr /A-Z/a-z/; |
| 42 |
print OUT "$style $dest\n"; |
| 43 |
$made_change=1; |
| 44 |
} else { |
| 45 |
print OUT $_; |
| 46 |
} |
| 47 |
} # while <IN> LOOP |
| 48 |
close (IN); |
| 49 |
close(OUT); |
| 50 |
if ($made_change) { |
| 51 |
print "$file has changed\n"; |
| 52 |
unlink($file); |
| 53 |
rename("$file.new", $file); |
| 54 |
} |
| 55 |
else { |
| 56 |
unlink("$file.new"); |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
# @maps contains all filenames |
| 61 |
sub maplist { |
| 62 |
local ($dir, $file, @dirs) = shift; |
| 63 |
|
| 64 |
opendir (DIR , $dir) || die "Can't open directory : $dir\n"; |
| 65 |
while ($file = readdir (DIR)) { |
| 66 |
next if ($file eq "." || $file eq ".." || $file eq "CVS"); |
| 67 |
|
| 68 |
$file = "$dir/$file"; |
| 69 |
next if (-l $file); # don't process symbolic links |
| 70 |
push (@dirs, $file) if (-d $file); |
| 71 |
push (@maps, $file) if (-f $file); |
| 72 |
} |
| 73 |
closedir (DIR); |
| 74 |
|
| 75 |
# recursive handle sub-dirs too |
| 76 |
while ($_ = shift @dirs) { |
| 77 |
&maplist ($_); |
| 78 |
} |
| 79 |
} |
| 80 |
|