changes by Barry, e.g. font lock & email addresses
[python/dscho.git] / Mac / scripts / mkestrres.py
blobae9114b8b628f6d7e3d461312e6c4fc78cb1a9c3
2 # Create 'Estr' resource from error dictionary
3 from Res import *
4 import Res
5 from Resources import *
6 import MacOS
7 import string
9 READ = 1
10 WRITE = 2
11 smAllScripts = -3
13 def Pstring(str):
14 if len(str) > 255:
15 raise ValueError, 'String too large'
16 return chr(len(str))+str
18 def writeestr(dst, edict):
19 """Create Estr resource file given a dictionary of errors."""
22 FSpCreateResFile(dst, 'RSED', 'rsrc', smAllScripts)
23 output = FSpOpenResFile(dst, WRITE)
24 UseResFile(output)
25 for num in edict.keys():
26 res = Resource(Pstring(edict[num]))
27 res.AddResource('Estr', num, '')
28 res.WriteResource()
29 CloseResFile(output)
31 def parsefile(src):
32 fp = open(src)
33 lines = []
34 while 1:
35 x = fp.readline()
36 if not x:
37 break
38 x = x[:-1]
39 words = string.split(x)
40 if x[0] in (' ', '\t'):
41 # continuation line
42 x = string.join(words)
43 lines[-1] = lines[-1] + ' ' + x
44 else:
45 x = string.join(words)
46 lines.append(x)
47 dict = {}
48 for line in lines:
49 words = string.split(line)
50 index = eval(words[0])
51 if dict.has_key(index):
52 print '** Duplicate key:', index
53 x = string.join(words[2:])
54 if not x:
55 x = words[1]
56 dict[index] = x
57 return dict
60 if __name__ == '__main__':
61 dict = parsefile('errors.txt')
62 writeestr('errors.rsrc', dict)