1996-09-05 12:22:16 -03:00
|
|
|
"""Parse sys/errno.h and Errors.h and create Estr resource"""
|
|
|
|
|
2001-01-02 18:02:02 -04:00
|
|
|
import re
|
1996-09-05 12:22:16 -03:00
|
|
|
import macfs
|
1995-02-05 13:01:45 -04:00
|
|
|
import string
|
2001-08-25 09:15:04 -03:00
|
|
|
from Carbon import Res
|
1996-09-05 12:22:16 -03:00
|
|
|
import os
|
1995-02-05 13:01:45 -04:00
|
|
|
|
|
|
|
READ = 1
|
|
|
|
WRITE = 2
|
|
|
|
smAllScripts = -3
|
|
|
|
|
1996-09-05 12:22:16 -03:00
|
|
|
ERRNO_PROG="#define[ \t]+" \
|
2001-01-02 18:02:02 -04:00
|
|
|
"([A-Z0-9a-z_]+)" \
|
1996-09-05 12:22:16 -03:00
|
|
|
"[ \t]+" \
|
2001-01-02 18:02:02 -04:00
|
|
|
"([0-9]+)" \
|
1996-09-05 12:22:16 -03:00
|
|
|
"[ \t]*/\*[ \t]*" \
|
2001-01-02 18:02:02 -04:00
|
|
|
"(.*)" \
|
1996-09-05 12:22:16 -03:00
|
|
|
"[ \t]*\*/"
|
|
|
|
|
|
|
|
ERRORS_PROG="[ \t]*" \
|
2001-01-02 18:02:02 -04:00
|
|
|
"([A-Z0-9a-z_]+)" \
|
1996-09-05 12:22:16 -03:00
|
|
|
"[ \t]*=[ \t]*" \
|
2001-01-02 18:02:02 -04:00
|
|
|
"([-0-9]+)" \
|
1996-09-05 12:22:16 -03:00
|
|
|
"[, \t]*/\*[ \t]*" \
|
2001-01-02 18:02:02 -04:00
|
|
|
"(.*)" \
|
1996-09-05 12:22:16 -03:00
|
|
|
"[ \t]*\*/"
|
1998-04-21 12:27:45 -03:00
|
|
|
|
|
|
|
ERRORS_PROG_2="[ \t]*" \
|
2001-01-02 18:02:02 -04:00
|
|
|
"([A-Z0-9a-z_]+)" \
|
1998-04-21 12:27:45 -03:00
|
|
|
"[ \t]*=[ \t]*" \
|
2001-01-02 18:02:02 -04:00
|
|
|
"([-0-9]+)" \
|
1998-04-21 12:27:45 -03:00
|
|
|
"[, \t]*"
|
1996-09-05 12:22:16 -03:00
|
|
|
|
1995-02-05 13:01:45 -04:00
|
|
|
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."""
|
|
|
|
|
1996-09-05 12:22:16 -03:00
|
|
|
os.unlink(dst.as_pathname())
|
|
|
|
Res.FSpCreateResFile(dst, 'RSED', 'rsrc', smAllScripts)
|
|
|
|
output = Res.FSpOpenResFile(dst, WRITE)
|
|
|
|
Res.UseResFile(output)
|
1995-02-05 13:01:45 -04:00
|
|
|
for num in edict.keys():
|
1996-09-05 12:22:16 -03:00
|
|
|
res = Res.Resource(Pstring(edict[num][0]))
|
1995-02-05 13:01:45 -04:00
|
|
|
res.AddResource('Estr', num, '')
|
|
|
|
res.WriteResource()
|
1996-09-05 12:22:16 -03:00
|
|
|
Res.CloseResFile(output)
|
|
|
|
|
|
|
|
def writepython(fp, dict):
|
|
|
|
k = dict.keys()
|
|
|
|
k.sort()
|
|
|
|
for i in k:
|
|
|
|
fp.write("%s\t=\t%d\t#%s\n"%(dict[i][1], i, dict[i][0]))
|
|
|
|
|
|
|
|
|
|
|
|
def parse_errno_h(fp, dict):
|
2001-01-02 18:02:02 -04:00
|
|
|
errno_prog = re.compile(ERRNO_PROG)
|
1996-09-05 12:22:16 -03:00
|
|
|
for line in fp.readlines():
|
2001-01-02 18:02:02 -04:00
|
|
|
m = errno_prog.match(line)
|
|
|
|
if m:
|
|
|
|
number = string.atoi(m.group(2))
|
|
|
|
name = m.group(1)
|
|
|
|
desc = string.strip(m.group(3))
|
1995-02-05 13:01:45 -04:00
|
|
|
|
1996-09-05 12:22:16 -03:00
|
|
|
if not dict.has_key(number):
|
|
|
|
dict[number] = desc, name
|
|
|
|
else:
|
|
|
|
print 'DUPLICATE', number
|
|
|
|
print '\t', dict[number]
|
|
|
|
print '\t', (desc, name)
|
|
|
|
|
|
|
|
def parse_errors_h(fp, dict):
|
2001-01-02 18:02:02 -04:00
|
|
|
errno_prog = re.compile(ERRORS_PROG)
|
|
|
|
errno_prog_2 = re.compile(ERRORS_PROG_2)
|
1996-09-05 12:22:16 -03:00
|
|
|
for line in fp.readlines():
|
1998-04-21 12:27:45 -03:00
|
|
|
match = 0
|
2001-01-02 18:02:02 -04:00
|
|
|
m = errno_prog.match(line)
|
|
|
|
m2 = errno_prog_2.match(line)
|
|
|
|
if m:
|
|
|
|
number = string.atoi(m.group(2))
|
|
|
|
name = m.group(1)
|
|
|
|
desc = string.strip(m.group(3))
|
1998-04-21 12:27:45 -03:00
|
|
|
match=1
|
2001-01-02 18:02:02 -04:00
|
|
|
elif m2:
|
|
|
|
number = string.atoi(m2.group(2))
|
|
|
|
name = m2.group(1)
|
1998-04-21 12:27:45 -03:00
|
|
|
desc = name
|
|
|
|
match=1
|
|
|
|
if match:
|
1996-09-05 12:22:16 -03:00
|
|
|
if number > 0: continue
|
|
|
|
|
|
|
|
if not dict.has_key(number):
|
|
|
|
dict[number] = desc, name
|
|
|
|
else:
|
|
|
|
print 'DUPLICATE', number
|
|
|
|
print '\t', dict[number]
|
|
|
|
print '\t', (desc, name)
|
1998-04-21 12:27:45 -03:00
|
|
|
if len(desc) > len(dict[number][0]):
|
|
|
|
print 'Pick second one'
|
|
|
|
dict[number] = desc, name
|
1996-09-05 12:22:16 -03:00
|
|
|
|
|
|
|
def main():
|
|
|
|
dict = {}
|
2001-01-01 18:57:59 -04:00
|
|
|
fss, ok = macfs.PromptGetFile("Where is GUSI sys/errno.h?")
|
1996-09-05 12:22:16 -03:00
|
|
|
if not ok: return
|
|
|
|
fp = open(fss.as_pathname())
|
|
|
|
parse_errno_h(fp, dict)
|
|
|
|
fp.close()
|
|
|
|
|
2002-01-22 19:25:12 -04:00
|
|
|
fss, ok = macfs.PromptGetFile("Select cerrno (MSL) or cancel")
|
1997-05-15 08:18:13 -03:00
|
|
|
if not ok: return
|
|
|
|
fp = open(fss.as_pathname())
|
|
|
|
parse_errno_h(fp, dict)
|
|
|
|
fp.close()
|
|
|
|
|
2002-01-22 19:25:12 -04:00
|
|
|
fss, ok = macfs.PromptGetFile("Where is MacErrors.h?")
|
1996-09-05 12:22:16 -03:00
|
|
|
if not ok: return
|
|
|
|
fp = open(fss.as_pathname())
|
|
|
|
parse_errors_h(fp, dict)
|
|
|
|
fp.close()
|
|
|
|
|
2002-04-22 08:44:26 -03:00
|
|
|
fss, ok = macfs.PromptGetFile("Where is mkestrres-MacErrors.h?")
|
|
|
|
if not ok: return
|
|
|
|
fp = open(fss.as_pathname())
|
|
|
|
parse_errors_h(fp, dict)
|
|
|
|
fp.close()
|
|
|
|
|
1996-09-05 12:22:16 -03:00
|
|
|
if not dict:
|
|
|
|
return
|
|
|
|
|
|
|
|
fss, ok = macfs.StandardPutFile("Resource output file?", "errors.rsrc")
|
|
|
|
if ok:
|
|
|
|
writeestr(fss, dict)
|
|
|
|
|
|
|
|
fss, ok = macfs.StandardPutFile("Python output file?", "macerrors.py")
|
|
|
|
if ok:
|
|
|
|
fp = open(fss.as_pathname(), "w")
|
|
|
|
writepython(fp, dict)
|
|
|
|
fp.close()
|
|
|
|
fss.SetCreatorType('Pyth', 'TEXT')
|
|
|
|
|
|
|
|
fss, ok = macfs.StandardPutFile("Text output file?", "errors.txt")
|
|
|
|
if ok:
|
|
|
|
fp = open(fss.as_pathname(), "w")
|
|
|
|
|
|
|
|
k = dict.keys()
|
|
|
|
k.sort()
|
|
|
|
for i in k:
|
|
|
|
fp.write("%d\t%s\t%s\n"%(i, dict[i][1], dict[i][0]))
|
|
|
|
fp.close()
|
|
|
|
|
1995-02-05 13:01:45 -04:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
1996-09-05 12:22:16 -03:00
|
|
|
main()
|
|
|
|
|