| 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 |
|
|---|
| 8 | from scantools import Scanner
|
|---|
| 9 |
|
|---|
| 10 | LONG = "Dialogs"
|
|---|
| 11 | SHORT = "dlg"
|
|---|
| 12 | OBJECT = "DialogPtr"
|
|---|
| 13 |
|
|---|
| 14 | def main():
|
|---|
| 15 | input = LONG + ".h"
|
|---|
| 16 | output = SHORT + "gen.py"
|
|---|
| 17 | defsoutput = TOOLBOXDIR + LONG + ".py"
|
|---|
| 18 | scanner = MyScanner(input, output, defsoutput)
|
|---|
| 19 | scanner.scan()
|
|---|
| 20 | scanner.close()
|
|---|
| 21 | print "=== Testing definitions output code ==="
|
|---|
| 22 | execfile(defsoutput, {}, {})
|
|---|
| 23 | print "=== Done scanning and generating, now importing the generated code... ==="
|
|---|
| 24 | exec "import " + SHORT + "support"
|
|---|
| 25 | print "=== Done. It's up to you to compile it now! ==="
|
|---|
| 26 |
|
|---|
| 27 | class MyScanner(Scanner):
|
|---|
| 28 |
|
|---|
| 29 | def destination(self, type, name, arglist):
|
|---|
| 30 | classname = "Function"
|
|---|
| 31 | listname = "functions"
|
|---|
| 32 | if arglist:
|
|---|
| 33 | t, n, m = arglist[0]
|
|---|
| 34 | if t in ("DialogPtr", "DialogRef") and m == "InMode":
|
|---|
| 35 | classname = "Method"
|
|---|
| 36 | listname = "methods"
|
|---|
| 37 | return classname, listname
|
|---|
| 38 |
|
|---|
| 39 | def makeblacklistnames(self):
|
|---|
| 40 | return [
|
|---|
| 41 | 'InitDialogs',
|
|---|
| 42 | 'ErrorSound',
|
|---|
| 43 | # Dialogs are disposed when the object is deleted
|
|---|
| 44 | 'CloseDialog',
|
|---|
| 45 | 'DisposDialog',
|
|---|
| 46 | 'DisposeDialog',
|
|---|
| 47 | 'UpdtDialog',
|
|---|
| 48 | 'CouldAlert',
|
|---|
| 49 | 'FreeAlert',
|
|---|
| 50 | 'CouldDialog',
|
|---|
| 51 | 'FreeDialog',
|
|---|
| 52 | 'GetStdFilterProc',
|
|---|
| 53 | 'GetDialogParent',
|
|---|
| 54 | ## # Can't find these in the CW Pro 3 libraries
|
|---|
| 55 | 'SetDialogMovableModal',
|
|---|
| 56 | 'GetDialogControlNotificationProc',
|
|---|
| 57 | 'SetGrafPortOfDialog', # Funny, and probably not useful
|
|---|
| 58 | # Can't find these:
|
|---|
| 59 | 'CloseStandardSheet',
|
|---|
| 60 | 'RunStandardAlert',
|
|---|
| 61 | ]
|
|---|
| 62 |
|
|---|
| 63 | def makeblacklisttypes(self):
|
|---|
| 64 | return [
|
|---|
| 65 | "AlertStdAlertParamPtr", # Too much work, for now
|
|---|
| 66 | "AlertStdAlertParamRec", # ditto
|
|---|
| 67 | "AlertStdAlertParamRec_ptr", # ditto
|
|---|
| 68 | "AlertStdCFStringAlertParamPtr", # ditto
|
|---|
| 69 | "AlertStdCFStringAlertParamRec",
|
|---|
| 70 | "AlertStdCFStringAlertParamRec_ptr",
|
|---|
| 71 | "QTModelessCallbackProcPtr",
|
|---|
| 72 | ]
|
|---|
| 73 |
|
|---|
| 74 | def makerepairinstructions(self):
|
|---|
| 75 | return [
|
|---|
| 76 | ([("Str255", "*", "InMode")],
|
|---|
| 77 | [("*", "*", "OutMode")]),
|
|---|
| 78 |
|
|---|
| 79 | ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
|
|---|
| 80 | [("InBuffer", "*", "*")]),
|
|---|
| 81 |
|
|---|
| 82 | ([("void", "*", "OutMode"), ("long", "*", "InMode"),
|
|---|
| 83 | ("long", "*", "OutMode")],
|
|---|
| 84 | [("VarVarOutBuffer", "*", "InOutMode")]),
|
|---|
| 85 |
|
|---|
| 86 | # GetDialogItem return handle is optional
|
|---|
| 87 | ([("Handle", "item", "OutMode")],
|
|---|
| 88 | [("OptHandle", "item", "OutMode")]),
|
|---|
| 89 |
|
|---|
| 90 | # NewDialog ETC.
|
|---|
| 91 | ([("void", "*", "OutMode")],
|
|---|
| 92 | [("NullStorage", "*", "InMode")]),
|
|---|
| 93 |
|
|---|
| 94 | ([("DialogPtr", "*", "OutMode")],
|
|---|
| 95 | [("ExistingDialogPtr", "*", "*")]),
|
|---|
| 96 | ([("DialogRef", "*", "OutMode")],
|
|---|
| 97 | [("ExistingDialogPtr", "*", "*")]),
|
|---|
| 98 | ([("WindowPtr", "*", "OutMode")],
|
|---|
| 99 | [("ExistingWindowPtr", "*", "*")]),
|
|---|
| 100 | ([("WindowPtr", "*", "ReturnMode")],
|
|---|
| 101 | [("ExistingWindowPtr", "*", "*")]),
|
|---|
| 102 |
|
|---|
| 103 | # StdFilterProc
|
|---|
| 104 | ([('EventRecord', 'event', 'OutMode'),
|
|---|
| 105 | ('DialogItemIndex', 'itemHit', 'OutMode')],
|
|---|
| 106 | [('EventRecord', 'event', 'InOutMode'),
|
|---|
| 107 | ('DialogItemIndex', 'itemHit', 'InOutMode')])
|
|---|
| 108 |
|
|---|
| 109 | ]
|
|---|
| 110 |
|
|---|
| 111 | def writeinitialdefs(self):
|
|---|
| 112 | self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
|
|---|
| 113 |
|
|---|
| 114 |
|
|---|
| 115 | if __name__ == "__main__":
|
|---|
| 116 | main()
|
|---|