| 1 | # Scan an Apple header file, generating a Python file of generator calls.
|
|---|
| 2 |
|
|---|
| 3 | import sys
|
|---|
| 4 | import os
|
|---|
| 5 | from bgenlocations import TOOLBOXDIR, BGENDIR
|
|---|
| 6 | sys.path.append(BGENDIR)
|
|---|
| 7 | from scantools import Scanner
|
|---|
| 8 |
|
|---|
| 9 | LONG = "Events"
|
|---|
| 10 | SHORT = "evt"
|
|---|
| 11 | OBJECT = "NOTUSED"
|
|---|
| 12 |
|
|---|
| 13 | def main():
|
|---|
| 14 | input = LONG + ".h"
|
|---|
| 15 | output = SHORT + "gen.py"
|
|---|
| 16 | defsoutput = TOOLBOXDIR + LONG + ".py"
|
|---|
| 17 | scanner = MyScanner(input, output, defsoutput)
|
|---|
| 18 | scanner.scan()
|
|---|
| 19 | scanner.close()
|
|---|
| 20 | print "=== Testing definitions output code ==="
|
|---|
| 21 | execfile(defsoutput, {}, {})
|
|---|
| 22 | 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 |
|
|---|
| 26 | class 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 |
|
|---|
| 39 | def makeblacklistnames(self):
|
|---|
| 40 | return [
|
|---|
| 41 | "KeyTranslate",
|
|---|
| 42 | "GetEventMask", # I cannot seem to find this routine...
|
|---|
| 43 | "WaitNextEvent", # Manually generated because of optional region
|
|---|
| 44 | # Constants with funny definitions
|
|---|
| 45 | "osEvtMessageMask",
|
|---|
| 46 | # OS8 calls
|
|---|
| 47 | 'SystemEvent',
|
|---|
| 48 | 'SystemTask',
|
|---|
| 49 | 'SystemClick',
|
|---|
| 50 | 'GetOSEvent',
|
|---|
| 51 | 'OSEventAvail',
|
|---|
| 52 | ]
|
|---|
| 53 |
|
|---|
| 54 | def makeblacklisttypes(self):
|
|---|
| 55 | return [
|
|---|
| 56 | "EvQElPtr", "QHdrPtr"
|
|---|
| 57 | ]
|
|---|
| 58 |
|
|---|
| 59 | def makerepairinstructions(self):
|
|---|
| 60 | return [
|
|---|
| 61 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
|
|---|
| 62 | [("InBuffer", "*", "*")]),
|
|---|
| 63 |
|
|---|
| 64 | ([("void", "*", "OutMode"), ("long", "*", "InMode"),
|
|---|
| 65 | ("long", "*", "OutMode")],
|
|---|
| 66 | [("VarVarOutBuffer", "*", "InOutMode")]),
|
|---|
| 67 |
|
|---|
| 68 | ([("void", "wStorage", "OutMode")],
|
|---|
| 69 | [("NullStorage", "*", "InMode")]),
|
|---|
| 70 |
|
|---|
| 71 | # GetKeys
|
|---|
| 72 | ([('KeyMap', 'theKeys', 'InMode')],
|
|---|
| 73 | [('*', '*', 'OutMode')]),
|
|---|
| 74 |
|
|---|
| 75 | # GetTicker
|
|---|
| 76 | ([('unsigned long', '*', '*')],
|
|---|
| 77 | [('unsigned_long', '*', '*')]),
|
|---|
| 78 | ]
|
|---|
| 79 |
|
|---|
| 80 | if __name__ == "__main__":
|
|---|
| 81 | main()
|
|---|