| 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 = "OSAconst"
|
|---|
| 10 | SHORT = "osa"
|
|---|
| 11 |
|
|---|
| 12 | def main():
|
|---|
| 13 | input = "OSA.h"
|
|---|
| 14 | output = SHORT + "gen.py"
|
|---|
| 15 | defsoutput = TOOLBOXDIR + LONG + ".py"
|
|---|
| 16 | scanner = MyScanner(input, output, defsoutput)
|
|---|
| 17 | scanner.scan()
|
|---|
| 18 | scanner.close()
|
|---|
| 19 | scanner.gentypetest(SHORT+"typetest.py")
|
|---|
| 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 | if t == "ComponentInstance" and m == "InMode":
|
|---|
| 34 | classname = "Method"
|
|---|
| 35 | listname = "methods"
|
|---|
| 36 | return classname, listname
|
|---|
| 37 |
|
|---|
| 38 | def writeinitialdefs(self):
|
|---|
| 39 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
|
|---|
| 40 | self.defsfile.write("from Carbon.AppleEvents import *\n")
|
|---|
| 41 | self.defsfile.write("kAEUseStandardDispatch = -1\n")
|
|---|
| 42 |
|
|---|
| 43 | def makeblacklistnames(self):
|
|---|
| 44 | return [
|
|---|
| 45 | "OSACopyScript",
|
|---|
| 46 | ]
|
|---|
| 47 |
|
|---|
| 48 | def makeblacklisttypes(self):
|
|---|
| 49 | return [
|
|---|
| 50 | "OSALocalOrGlobal",
|
|---|
| 51 | "OSACreateAppleEventUPP",
|
|---|
| 52 | "OSAActiveUPP",
|
|---|
| 53 | "AEEventHandlerUPP",
|
|---|
| 54 | "OSASendUPP",
|
|---|
| 55 | ]
|
|---|
| 56 |
|
|---|
| 57 | def makerepairinstructions(self):
|
|---|
| 58 | return [
|
|---|
| 59 | ]
|
|---|
| 60 |
|
|---|
| 61 | if __name__ == "__main__":
|
|---|
| 62 | main()
|
|---|