1 """Parse sys/errno.h and Errors.h and create Estr resource"""
12 ERRNO_PROG
="#define[ \t]+" \
20 ERRORS_PROG
="[ \t]*" \
28 ERRORS_PROG_2
="[ \t]*" \
36 raise ValueError, 'String too large'
37 return chr(len(str))+str
39 def writeestr(dst
, edict
):
40 """Create Estr resource file given a dictionary of errors."""
42 os
.unlink(dst
.as_pathname())
43 Res
.FSpCreateResFile(dst
, 'RSED', 'rsrc', smAllScripts
)
44 output
= Res
.FSpOpenResFile(dst
, WRITE
)
45 Res
.UseResFile(output
)
46 for num
in edict
.keys():
47 res
= Res
.Resource(Pstring(edict
[num
][0]))
48 res
.AddResource('Estr', num
, '')
50 Res
.CloseResFile(output
)
52 def writepython(fp
, dict):
56 fp
.write("%s\t=\t%d\t#%s\n"%(dict[i
][1], i
, dict[i
][0]))
59 def parse_errno_h(fp
, dict):
60 errno_prog
= re
.compile(ERRNO_PROG
)
61 for line
in fp
.readlines():
62 m
= errno_prog
.match(line
)
64 number
= string
.atoi(m
.group(2))
66 desc
= string
.strip(m
.group(3))
68 if not dict.has_key(number
):
69 dict[number
] = desc
, name
71 print 'DUPLICATE', number
72 print '\t', dict[number
]
73 print '\t', (desc
, name
)
75 def parse_errors_h(fp
, dict):
76 errno_prog
= re
.compile(ERRORS_PROG
)
77 errno_prog_2
= re
.compile(ERRORS_PROG_2
)
78 for line
in fp
.readlines():
80 m
= errno_prog
.match(line
)
81 m2
= errno_prog_2
.match(line
)
83 number
= string
.atoi(m
.group(2))
85 desc
= string
.strip(m
.group(3))
88 number
= string
.atoi(m2
.group(2))
93 if number
> 0: continue
95 if not dict.has_key(number
):
96 dict[number
] = desc
, name
98 print 'DUPLICATE', number
99 print '\t', dict[number
]
100 print '\t', (desc
, name
)
101 if len(desc
) > len(dict[number
][0]):
102 print 'Pick second one'
103 dict[number
] = desc
, name
107 pathname
= EasyDialogs
.AskFileForOpen(message
="Where is GUSI sys/errno.h?")
110 parse_errno_h(fp
, dict)
113 pathname
= EasyDialogs
.AskFileForOpen(message
="Select cerrno (MSL) or cancel")
116 parse_errno_h(fp
, dict)
119 pathname
= EasyDialogs
.AskFileForOpen(message
="Where is MacErrors.h?")
122 parse_errors_h(fp
, dict)
125 pathname
= EasyDialogs
.AskFileForOpen(message
="Where is mkestrres-MacErrors.h?")
128 parse_errors_h(fp
, dict)
134 pathname
= EasyDialogs
.AskFileForSave(message
="Resource output file?", savedFileName
="errors.rsrc")
138 pathname
= EasyDialogs
.AskFileForSave(message
="Python output file?", savedFileName
="macerrors.py")
140 fp
= open(pathname
, "w")
141 writepython(fp
, dict)
143 fss
.SetCreatorType('Pyth', 'TEXT')
145 pathname
= EasyDialogs
.AskFileForSave(message
="Text output file?", savedFileName
="errors.txt")
147 fp
= open(pathname
, "w")
152 fp
.write("%d\t%s\t%s\n"%(i
, dict[i
][1], dict[i
][0]))
156 if __name__
== '__main__':