openfile(): Go back to opening the files in text mode. This undoes
[python/dscho.git] / Mac / Modules / cg / cgscan.py
blob5d84500d6eb6a8ba23989fe654cbd76cde49df40
1 # Scan an Apple header file, generating a Python file of generator calls.
3 import sys
4 import os
5 from bgenlocations import TOOLBOXDIR, BGENDIR
6 sys.path.append(BGENDIR)
7 from scantools import Scanner_OSX
9 LONG = "CoreGraphics"
10 SHORT = "cg"
11 OBJECTS = ("CGContextRef",
13 # ADD object typenames here
15 def main():
16 input = [
17 "CGContext.h",
19 output = SHORT + "gen.py"
20 defsoutput = TOOLBOXDIR + LONG + ".py"
21 scanner = MyScanner(input, output, defsoutput)
22 scanner.scan()
23 scanner.gentypetest(SHORT+"typetest.py")
24 scanner.close()
25 print "=== Testing definitions output code ==="
26 execfile(defsoutput, {}, {})
27 print "=== Done scanning and generating, now importing the generated code... ==="
28 exec "import " + SHORT + "support"
29 print "=== Done. It's up to you to compile it now! ==="
31 class MyScanner(Scanner_OSX):
33 def destination(self, type, name, arglist):
34 classname = "Function"
35 listname = "functions"
36 if arglist:
37 t, n, m = arglist[0]
38 if t in OBJECTS and m == "InMode":
39 classname = "Method"
40 listname = t + "_methods"
41 # Special case for the silly first AllocatorRef argument
42 if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
43 t, n, m = arglist[1]
44 if t in OBJECTS and m == "InMode":
45 classname = "MethodSkipArg1"
46 listname = t + "_methods"
47 return classname, listname
49 def writeinitialdefs(self):
50 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
52 def makeblacklistnames(self):
53 return [
54 "CGContextRetain",
55 "CGContextRelease",
58 def makegreylist(self):
59 return []
61 def makeblacklisttypes(self):
62 return [
63 "float_ptr",
64 "CGRect_ptr",
65 "CGPoint_ptr",
66 "CGColorSpaceRef",
67 "CGColorRenderingIntent",
68 "CGFontRef",
69 # "char_ptr",
70 "CGGlyph_ptr",
71 "CGImageRef",
72 "CGPDFDocumentRef",
75 def makerepairinstructions(self):
76 return [
77 ([("char_ptr", "cstring", "InMode"), ("size_t", "length", "InMode")],
78 [("InBuffer", "*", "*")]),
79 # ([("char_ptr", "name", "InMode"),],
80 # [("CCCCC", "*", "*")]),
83 if __name__ == "__main__":
84 main()