1 """Parse sys/errno.h and Errors.h and create Estr resource"""
13 ERRNO_PROG
="#define[ \t]+" \
21 ERRORS_PROG
="[ \t]*" \
29 ERRORS_PROG_2
="[ \t]*" \
37 raise ValueError, 'String too large'
38 return chr(len(str))+str
40 def writeestr(dst
, edict
):
41 """Create Estr resource file given a dictionary of errors."""
43 os
.unlink(dst
.as_pathname())
44 Res
.FSpCreateResFile(dst
, 'RSED', 'rsrc', smAllScripts
)
45 output
= Res
.FSpOpenResFile(dst
, WRITE
)
46 Res
.UseResFile(output
)
47 for num
in edict
.keys():
48 res
= Res
.Resource(Pstring(edict
[num
][0]))
49 res
.AddResource('Estr', num
, '')
51 Res
.CloseResFile(output
)
53 def writepython(fp
, dict):
57 fp
.write("%s\t=\t%d\t#%s\n"%(dict[i
][1], i
, dict[i
][0]))
60 def parse_errno_h(fp
, dict):
61 errno_prog
= re
.compile(ERRNO_PROG
)
62 for line
in fp
.readlines():
63 m
= errno_prog
.match(line
)
65 number
= string
.atoi(m
.group(2))
67 desc
= string
.strip(m
.group(3))
69 if not dict.has_key(number
):
70 dict[number
] = desc
, name
72 print 'DUPLICATE', number
73 print '\t', dict[number
]
74 print '\t', (desc
, name
)
76 def parse_errors_h(fp
, dict):
77 errno_prog
= re
.compile(ERRORS_PROG
)
78 errno_prog_2
= re
.compile(ERRORS_PROG_2
)
79 for line
in fp
.readlines():
81 m
= errno_prog
.match(line
)
82 m2
= errno_prog_2
.match(line
)
84 number
= string
.atoi(m
.group(2))
86 desc
= string
.strip(m
.group(3))
89 number
= string
.atoi(m2
.group(2))
94 if number
> 0: continue
96 if not dict.has_key(number
):
97 dict[number
] = desc
, name
99 print 'DUPLICATE', number
100 print '\t', dict[number
]
101 print '\t', (desc
, name
)
102 if len(desc
) > len(dict[number
][0]):
103 print 'Pick second one'
104 dict[number
] = desc
, name
108 fss
, ok
= macfs
.PromptGetFile("Where is GUSI sys/errno.h?")
110 fp
= open(fss
.as_pathname())
111 parse_errno_h(fp
, dict)
114 fss
, ok
= macfs
.PromptGetFile("Select 2nd errno.h (MSL) or cancel")
116 fp
= open(fss
.as_pathname())
117 parse_errno_h(fp
, dict)
120 fss
, ok
= macfs
.PromptGetFile("Where is Errors.h?")
122 fp
= open(fss
.as_pathname())
123 parse_errors_h(fp
, dict)
129 fss
, ok
= macfs
.StandardPutFile("Resource output file?", "errors.rsrc")
133 fss
, ok
= macfs
.StandardPutFile("Python output file?", "macerrors.py")
135 fp
= open(fss
.as_pathname(), "w")
136 writepython(fp
, dict)
138 fss
.SetCreatorType('Pyth', 'TEXT')
140 fss
, ok
= macfs
.StandardPutFile("Text output file?", "errors.txt")
142 fp
= open(fss
.as_pathname(), "w")
147 fp
.write("%d\t%s\t%s\n"%(i
, dict[i
][1], dict[i
][0]))
151 if __name__
== '__main__':