diff --git a/Makefile b/Makefile index 7b4b14ec..ccb880eb 100644 --- a/Makefile +++ b/Makefile @@ -69,13 +69,13 @@ textures/shareware/texture1.txt: textures/combined.txt $(CPP) -DSHAREWARE < $< > $@ textures/shareware/pnames.txt: textures/shareware/texture1.txt - ./extract-pnames.pl < $< > $@ + ./extract-pnames.py < $< > $@ textures/doom/pnames.txt: textures/doom/texture1.txt - ./extract-pnames.pl -a > $@ + ./extract-pnames.py -a > $@ textures/doom2/pnames.txt: textures/doom2/texture1.txt - ./extract-pnames.pl -a > $@ + ./extract-pnames.py -a > $@ textures/freedm/pnames.txt: textures/freedm/texture1.txt - ./extract-pnames.pl -a > $@ + ./extract-pnames.py -a > $@ # update wadinfo.txt diff --git a/extract-pnames.pl b/extract-pnames.py similarity index 68% rename from extract-pnames.pl rename to extract-pnames.py index 6a49ffd4..ccfabe2b 100755 --- a/extract-pnames.pl +++ b/extract-pnames.py @@ -1,4 +1,5 @@ -#!/usr/bin/env perl +#!/usr/bin/env python +# # Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 # 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 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -use strict; -my %patches; +import os +import sys +import re +import glob + +texture_re = re.compile(r'\*\s+(\w+)') # Parse a TEXTURE1 file and generate a list of patches -sub parse_texture_file { +def parse_texture_file(): + patches = {} - while (<>) { - if (/^\*/) { - my ($name) = /^\*\s+(\w+)/; - $name = uc $name; - $patches{$name} = 1; - } - } + for line in sys.stdin: + match = texture_re.match(line) - 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 # patches/ directory -sub list_all_textures { - print "; autogenerated patch list\n\n"; +def list_all_textures(): + print "; autogenerated patch list\n" - foreach my $file (glob("patches/*.gif")) { - if ($file =~ /\/(.*)\.gif/) { - print "$1\n"; - } - } -} + for filename in sorted(glob.glob("patches/*.gif")): + base = os.path.basename(filename) + patch_name = base[0:-4] + print patch_name -if (scalar @ARGV == 0) { - parse_texture_file(); -} elsif ($ARGV[0] == "-a") { - list_all_textures(); -} else { - print "Usage: extract-pnames.pl [-a]\n"; -} +if len(sys.argv) == 1: + parse_texture_file() +elif sys.argv[1] == "-a": + list_all_textures() +else: + print "Usage: extract-pnames.pl [-a]"