diff options
author | Guido van Rossum <guido@python.org> | 1995-02-05 17:01:45 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 1995-02-05 17:01:45 (GMT) |
commit | 3c3eda2b7baee203da5d3f7d35c28aa8ff04f456 (patch) | |
tree | e8ca80d9d15a1f4cbe74683ef98d45ff56b736fe /Mac/scripts/mkestrres.py | |
parent | 81920f1b755d073eadbb9712708a02caacff998c (diff) | |
download | cpython-3c3eda2b7baee203da5d3f7d35c28aa8ff04f456.zip cpython-3c3eda2b7baee203da5d3f7d35c28aa8ff04f456.tar.gz cpython-3c3eda2b7baee203da5d3f7d35c28aa8ff04f456.tar.bz2 |
stuff by jack to create a set of Estr resources
Diffstat (limited to 'Mac/scripts/mkestrres.py')
-rw-r--r-- | Mac/scripts/mkestrres.py | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/Mac/scripts/mkestrres.py b/Mac/scripts/mkestrres.py new file mode 100644 index 0000000..ae9114b --- /dev/null +++ b/Mac/scripts/mkestrres.py @@ -0,0 +1,62 @@ +# +# Create 'Estr' resource from error dictionary +from Res import * +import Res +from Resources import * +import MacOS +import string + +READ = 1 +WRITE = 2 +smAllScripts = -3 + +def Pstring(str): + if len(str) > 255: + raise ValueError, 'String too large' + return chr(len(str))+str + +def writeestr(dst, edict): + """Create Estr resource file given a dictionary of errors.""" + + + FSpCreateResFile(dst, 'RSED', 'rsrc', smAllScripts) + output = FSpOpenResFile(dst, WRITE) + UseResFile(output) + for num in edict.keys(): + res = Resource(Pstring(edict[num])) + res.AddResource('Estr', num, '') + res.WriteResource() + CloseResFile(output) + +def parsefile(src): + fp = open(src) + lines = [] + while 1: + x = fp.readline() + if not x: + break + x = x[:-1] + words = string.split(x) + if x[0] in (' ', '\t'): + # continuation line + x = string.join(words) + lines[-1] = lines[-1] + ' ' + x + else: + x = string.join(words) + lines.append(x) + dict = {} + for line in lines: + words = string.split(line) + index = eval(words[0]) + if dict.has_key(index): + print '** Duplicate key:', index + x = string.join(words[2:]) + if not x: + x = words[1] + dict[index] = x + return dict + + +if __name__ == '__main__': + dict = parsefile('errors.txt') + writeestr('errors.rsrc', dict) |