From 29118bc6c0eb0e354d6e86066284e0c070c98736 Mon Sep 17 00:00:00 2001 From: mcmartin Date: Tue, 15 Oct 2002 10:48:05 +0000 Subject: [PATCH] A script checking and inspection utility. git-svn-id: svn://svn.code.sf.net/p/sc2/code/trunk@125 8092fc87-c524-0410-9efc-e669fe64eaf9 --- tools/script/README | 13 ++++ tools/script/scriptcheck.py | 128 ++++++++++++++++++++++++++++++++++++ 2 files changed, 141 insertions(+) create mode 100644 tools/script/README create mode 100755 tools/script/scriptcheck.py diff --git a/tools/script/README b/tools/script/README new file mode 100644 index 000000000..facd884da --- /dev/null +++ b/tools/script/README @@ -0,0 +1,13 @@ +Scriptcheck, v0.1 + +This is a simple Python (v.2 and up) script to look for unusual +properties in the conversation files. It looks for spaces at the +beginnings and ends of lines where this would suppress "..." creation +(see docs/SCRIPT for more details on this) and compares the +identifiers named in the .txt file with the values of the enums in the +corresponding strings.h files. + +Run it from this directory or it won't be able to find the necessary +.txt and .h files. + +v0.1, 15 Oct 2002: Initial release (Michael Martin) diff --git a/tools/script/scriptcheck.py b/tools/script/scriptcheck.py new file mode 100755 index 000000000..57588f3d1 --- /dev/null +++ b/tools/script/scriptcheck.py @@ -0,0 +1,128 @@ +#!/usr/local/bin/python2.2 + +import string +import os.path + +class Speech: + def __init__(self, id=None, audio=None): + self.id = id + self.audio = audio + self.lines = [] + def add_line (self, line): + if len(line) != 0 and line[-1] == '\n': line = line[:-1] + self.lines.append(line) + def clean (self): + while self.lines != []: + if self.lines[-1].strip() != "": break + self.lines.pop() + def check (self): + # Check that non-first lines don't start with space + weird = 0 + ever_weird = 0 + for line in self.lines[1:]: + if len(line) != 0 and line[0] in string.whitespace: + if line.strip() != "": weird = 1 + if weird: + print "Warning: "+self.id+" has whitespace preceding an internal line" + ever_weird = 1 + # Now check for non-last lines ending with space + weird = 0 + for line in self.lines[:-1]: + if len(line) != 0 and line[-1] in string.whitespace: + if line.strip() != "": + if line.strip()[-1] not in string.punctuation: weird = 1 + if weird: + print "Warning: "+self.id+" has whitespace trailing an internal line" + ever_weird = 1 + if ever_weird: + print_boring_style(self) + +def print_old_style(speech): + header = "#("+speech.id+")" + if speech.audio is not None: + header += "\t"+speech.audio + print header + for line in speech.lines: + if line == "": + print " " + else: + print line + print "" + +def print_boring_style(speech): + print 'ID is "'+speech.id+'"' + if speech.audio is not None: + print 'Audio is "'+speech.audio+'"' + for line in speech.lines: + print '\t"'+line+'"' + print "" + +def read_old_file(filename): + current = None + speeches = [] + for line in file(filename): + if line[0] == '#': + lparen = line.index('(') + rparen = line.rindex(')') + if (lparen > rparen): raise ValueError + id = line[(lparen+1):rparen] + if (lparen != 1): + print "Warning: Speech "+id+" in "+filename+" isn't flush left" + audio = line[rparen+1:].strip() + if audio == "": audio = None + current = Speech(id, audio) + speeches.append(current) + else: + current.add_line(line) + for speech in speeches: + speech.clean() + return speeches + +def read_source_header(filename): + ids = [] + active = 0 + for line in file(filename): + if active == 0 and line.find('{') != -1: + active = 1 + elif active == 1 and line.find('}') != -1: + active = 2 + elif active == 1: + try: + id = line[:line.rindex(',')].strip() + if id[0] != "/": ids.append (id) + except ValueError: + id = line.strip() + if id != "": ids.append (id) + return ids + +races = ['arilou', 'blackur', 'chmmr', 'comandr', 'druuge', + 'ilwrath', 'melnorm', 'mycon', 'orz', 'pkunk', 'rebel', + 'shofixt', 'slyhome', 'slyland', 'spahome', 'spathi', + 'starbas', 'supox', 'syreen', 'talkpet', 'utwig', + 'vux', 'yehat', 'zoqfot'] + +root = os.path.join('..','..','sc2') + +for race in races: + try: + filename = os.path.join(root,'content','comm',race,race+'.txt') + source = os.path.join(root,'src','sc2code','comm',race,'strings.h') + print "Checking: "+race + data = read_old_file(filename) + id_seq = read_source_header(source) + for speech in data: + speech.check() + if id_seq[0] != "NULL_PHRASE": + print "Error! First element of enum not NULL_PHRASE!" + id_seq = id_seq[1:] + for x in map (None, data, id_seq): + if x[0] == None: + print "Error! enum "+x[1]+" has no partner!" + elif x[1] == None: + print "Warning! Data entry "+x[0].id+" is never referenced!" + elif x[0].id != x[1]: + print "Warning! text identifier "+x[0].id+" doesn't match enum constant "+x[1]+"!" + except ValueError: + print "Malformed header line" + except IOError: + print "I/O Error"