Convert extract-pnames script to Python.

This commit is contained in:
Simon Howard 2008-12-24 18:42:19 +00:00
parent 5abf2dccfe
commit c9e8446050
2 changed files with 36 additions and 33 deletions

View file

@ -69,13 +69,13 @@ textures/shareware/texture1.txt: textures/combined.txt
$(CPP) -DSHAREWARE < $< > $@ $(CPP) -DSHAREWARE < $< > $@
textures/shareware/pnames.txt: textures/shareware/texture1.txt textures/shareware/pnames.txt: textures/shareware/texture1.txt
./extract-pnames.pl < $< > $@ ./extract-pnames.py < $< > $@
textures/doom/pnames.txt: textures/doom/texture1.txt textures/doom/pnames.txt: textures/doom/texture1.txt
./extract-pnames.pl -a > $@ ./extract-pnames.py -a > $@
textures/doom2/pnames.txt: textures/doom2/texture1.txt textures/doom2/pnames.txt: textures/doom2/texture1.txt
./extract-pnames.pl -a > $@ ./extract-pnames.py -a > $@
textures/freedm/pnames.txt: textures/freedm/texture1.txt textures/freedm/pnames.txt: textures/freedm/texture1.txt
./extract-pnames.pl -a > $@ ./extract-pnames.py -a > $@
# update wadinfo.txt # update wadinfo.txt

View file

@ -1,4 +1,5 @@
#!/usr/bin/env perl #!/usr/bin/env python
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
# Contributors to the Freedoom project. All rights reserved. # Contributors to the Freedoom project. All rights reserved.
# #
@ -27,44 +28,46 @@
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
use strict; import os
my %patches; import sys
import re
import glob
texture_re = re.compile(r'\*\s+(\w+)')
# Parse a TEXTURE1 file and generate a list of patches # Parse a TEXTURE1 file and generate a list of patches
sub parse_texture_file { def parse_texture_file():
patches = {}
while (<>) { for line in sys.stdin:
if (/^\*/) { match = texture_re.match(line)
my ($name) = /^\*\s+(\w+)/;
$name = uc $name;
$patches{$name} = 1;
}
}
print "; autogenerated patch list\n\n"; if match:
name = match.group(1)
foreach (sort keys %patches) { print "$_\n"; } patches[name] = True
}
print "; autogenerated patch list\n"
for name in sorted(patches.keys()):
print name
# Generate a full list of textures from the files in the # Generate a full list of textures from the files in the
# patches/ directory # patches/ directory
sub list_all_textures { def list_all_textures():
print "; autogenerated patch list\n\n"; print "; autogenerated patch list\n"
foreach my $file (glob("patches/*.gif")) { for filename in sorted(glob.glob("patches/*.gif")):
if ($file =~ /\/(.*)\.gif/) { base = os.path.basename(filename)
print "$1\n"; patch_name = base[0:-4]
} print patch_name
}
}
if (scalar @ARGV == 0) { if len(sys.argv) == 1:
parse_texture_file(); parse_texture_file()
} elsif ($ARGV[0] == "-a") { elif sys.argv[1] == "-a":
list_all_textures(); list_all_textures()
} else { else:
print "Usage: extract-pnames.pl [-a]\n"; print "Usage: extract-pnames.pl [-a]"
}