| 1 | n/a | # Scan an Apple header file, generating a Python file of generator calls. |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | import sys |
|---|
| 4 | n/a | from bgenlocations import TOOLBOXDIR, BGENDIR |
|---|
| 5 | n/a | sys.path.append(BGENDIR) |
|---|
| 6 | n/a | from scantools import Scanner |
|---|
| 7 | n/a | |
|---|
| 8 | n/a | LONG = "Lists" |
|---|
| 9 | n/a | SHORT = "list" |
|---|
| 10 | n/a | OBJECT = "ListHandle" |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | def main(): |
|---|
| 13 | n/a | input = LONG + ".h" |
|---|
| 14 | n/a | output = SHORT + "gen.py" |
|---|
| 15 | n/a | defsoutput = TOOLBOXDIR + LONG + ".py" |
|---|
| 16 | n/a | scanner = MyScanner(input, output, defsoutput) |
|---|
| 17 | n/a | scanner.scan() |
|---|
| 18 | n/a | scanner.close() |
|---|
| 19 | n/a | print "=== Testing definitions output code ===" |
|---|
| 20 | n/a | execfile(defsoutput, {}, {}) |
|---|
| 21 | n/a | print "=== Done scanning and generating, now importing the generated code... ===" |
|---|
| 22 | n/a | exec "import " + SHORT + "support" |
|---|
| 23 | n/a | print "=== Done. It's up to you to compile it now! ===" |
|---|
| 24 | n/a | |
|---|
| 25 | n/a | class MyScanner(Scanner): |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | def destination(self, type, name, arglist): |
|---|
| 28 | n/a | classname = "Function" |
|---|
| 29 | n/a | listname = "functions" |
|---|
| 30 | n/a | if arglist: |
|---|
| 31 | n/a | t, n, m = arglist[-1] |
|---|
| 32 | n/a | # This is non-functional today |
|---|
| 33 | n/a | if t in ('ListHandle', 'ListRef') and m == "InMode": |
|---|
| 34 | n/a | classname = "Method" |
|---|
| 35 | n/a | listname = "methods" |
|---|
| 36 | n/a | return classname, listname |
|---|
| 37 | n/a | |
|---|
| 38 | n/a | def makeblacklistnames(self): |
|---|
| 39 | n/a | return [ |
|---|
| 40 | n/a | "LDispose", # Done by removing the object |
|---|
| 41 | n/a | "LSearch", # We don't want to handle procs just yet |
|---|
| 42 | n/a | "CreateCustomList", # done manually |
|---|
| 43 | n/a | "SetListDefinitionProc", |
|---|
| 44 | n/a | |
|---|
| 45 | n/a | # These have funny argument/return values |
|---|
| 46 | n/a | "GetListViewBounds", |
|---|
| 47 | n/a | "GetListCellIndent", |
|---|
| 48 | n/a | "GetListCellSize", |
|---|
| 49 | n/a | "GetListVisibleCells", |
|---|
| 50 | n/a | "GetListClickLocation", |
|---|
| 51 | n/a | "GetListMouseLocation", |
|---|
| 52 | n/a | "GetListDataBounds", |
|---|
| 53 | n/a | "SetListLastClick", |
|---|
| 54 | n/a | ] |
|---|
| 55 | n/a | |
|---|
| 56 | n/a | def makeblacklisttypes(self): |
|---|
| 57 | n/a | return [ |
|---|
| 58 | n/a | "ListClickLoopUPP", # Too difficult for now |
|---|
| 59 | n/a | "ListDefSpecPtr", # later |
|---|
| 60 | n/a | ] |
|---|
| 61 | n/a | |
|---|
| 62 | n/a | def makerepairinstructions(self): |
|---|
| 63 | n/a | return [ |
|---|
| 64 | n/a | ([('ListBounds_ptr', '*', 'InMode')], |
|---|
| 65 | n/a | [('Rect_ptr', '*', 'InMode')]), |
|---|
| 66 | n/a | |
|---|
| 67 | n/a | ([("Cell", "theCell", "OutMode")], |
|---|
| 68 | n/a | [("Cell", "theCell", "InOutMode")]), |
|---|
| 69 | n/a | |
|---|
| 70 | n/a | ([("void_ptr", "*", "InMode"), ("short", "*", "InMode")], |
|---|
| 71 | n/a | [("InBufferShortsize", "*", "*")]), |
|---|
| 72 | n/a | |
|---|
| 73 | n/a | ([("void", "*", "OutMode"), ("short", "*", "OutMode")], |
|---|
| 74 | n/a | [("VarOutBufferShortsize", "*", "InOutMode")]), |
|---|
| 75 | n/a | |
|---|
| 76 | n/a | # SetListCellIndent doesn't have const |
|---|
| 77 | n/a | ([("Point", "indent", "OutMode")], |
|---|
| 78 | n/a | [("Point_ptr", "indent", "InMode")]), |
|---|
| 79 | n/a | |
|---|
| 80 | n/a | ] |
|---|
| 81 | n/a | |
|---|
| 82 | n/a | def writeinitialdefs(self): |
|---|
| 83 | n/a | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") |
|---|
| 84 | n/a | |
|---|
| 85 | n/a | |
|---|
| 86 | n/a | if __name__ == "__main__": |
|---|
| 87 | n/a | main() |
|---|