blob: 0c0ff4948fbb65b9bd89dab86ba11434d3f5dafa [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001# Scan an Apple header file, generating a Python file of generator calls.
2
Jack Jansen0c4d9471998-04-17 14:07:56 +00003import sys
4import os
Jack Jansenaaebdd62002-08-05 15:39:30 +00005from bgenlocations import TOOLBOXDIR, BGENDIR
Jack Jansen0c4d9471998-04-17 14:07:56 +00006sys.path.append(BGENDIR)
Guido van Rossum17448e21995-01-30 11:53:55 +00007from scantools import Scanner
8
9LONG = "Events"
10SHORT = "evt"
11OBJECT = "NOTUSED"
12
13def main():
14 input = LONG + ".h"
15 output = SHORT + "gen.py"
Jack Jansen46d9e791996-04-12 16:29:23 +000016 defsoutput = TOOLBOXDIR + LONG + ".py"
Guido van Rossum17448e21995-01-30 11:53:55 +000017 scanner = MyScanner(input, output, defsoutput)
18 scanner.scan()
19 scanner.close()
Jack Jansen87eea882002-08-15 21:48:16 +000020 print "=== Testing definitions output code ==="
21 execfile(defsoutput, {}, {})
Guido van Rossum17448e21995-01-30 11:53:55 +000022 print "=== Done scanning and generating, now importing the generated code... ==="
23 exec "import " + SHORT + "support"
24 print "=== Done. It's up to you to compile it now! ==="
25
26class MyScanner(Scanner):
27
28 def destination(self, type, name, arglist):
29 classname = "Function"
30 listname = "functions"
31 if arglist:
32 t, n, m = arglist[0]
33 # This is non-functional today
34 if t == OBJECT and m == "InMode":
35 classname = "Method"
36 listname = "methods"
37 return classname, listname
38
Jack Jansenabf17032000-06-20 07:42:23 +000039 def makegreylist(self):
40 return [
Jack Jansen74a1e632000-07-14 22:37:27 +000041 ('#if !TARGET_API_MAC_CARBON', [
Jack Jansenabf17032000-06-20 07:42:23 +000042 'SystemEvent',
43 'SystemTask',
44 'SystemClick',
45 'GetOSEvent',
46 'OSEventAvail',
Jack Jansenf7d5aa62000-12-10 23:43:49 +000047 ]),
48 ('#if TARGET_API_MAC_CARBON', [
49 'CheckEventQueueForUserCancel',
50 'GetCurrentKeyModifiers',
51 'GetGlobalMouse',
Jack Jansenabf17032000-06-20 07:42:23 +000052 ])]
53
Guido van Rossum17448e21995-01-30 11:53:55 +000054 def makeblacklistnames(self):
55 return [
Jack Jansen7d0bc831995-06-09 20:56:31 +000056 "KeyTranslate",
57 "GetEventMask", # I cannot seem to find this routine...
Jack Jansenb1b78d81999-12-14 15:47:01 +000058 "WaitNextEvent", # Manually generated because of optional region
59 # Constants with funny definitions
60 "osEvtMessageMask",
Guido van Rossum17448e21995-01-30 11:53:55 +000061 ]
62
63 def makeblacklisttypes(self):
64 return [
Jack Jansenb81cf9d1995-06-06 13:08:40 +000065 "EvQElPtr", "QHdrPtr"
Guido van Rossum17448e21995-01-30 11:53:55 +000066 ]
67
68 def makerepairinstructions(self):
69 return [
70 ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
71 [("InBuffer", "*", "*")]),
72
73 ([("void", "*", "OutMode"), ("long", "*", "InMode"),
74 ("long", "*", "OutMode")],
75 [("VarVarOutBuffer", "*", "InOutMode")]),
76
77 ([("void", "wStorage", "OutMode")],
78 [("NullStorage", "*", "InMode")]),
79
80 # GetKeys
81 ([('KeyMap', 'theKeys', 'InMode')],
82 [('*', '*', 'OutMode')]),
Jack Jansenb81cf9d1995-06-06 13:08:40 +000083
84 # GetTicker
85 ([('unsigned long', '*', '*')],
86 [('unsigned_long', '*', '*')]),
Guido van Rossum17448e21995-01-30 11:53:55 +000087 ]
Jack Jansenb81cf9d1995-06-06 13:08:40 +000088
Guido van Rossum17448e21995-01-30 11:53:55 +000089if __name__ == "__main__":
90 main()