• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Scan an Apple header file, generating a Python file of generator calls.
2
3import sys
4from bgenlocations import TOOLBOXDIR, BGENDIR
5sys.path.append(BGENDIR)
6from scantools import Scanner
7
8LONG = "LaunchServices"
9SHORT = "launch"
10OBJECT = "NOTUSED"
11
12def main():
13    input = LONG + ".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
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
39    def writeinitialdefs(self):
40        self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
41        self.defsfile.write("from Carbon.Files import *\n")
42        self.defsfile.write("kLSRequestAllInfo = -1\n")
43        self.defsfile.write("kLSRolesAll = -1\n")
44        self.defsfile.write("kLSUnknownType = FOUR_CHAR_CODE('\\0\\0\\0\\0')\n")
45        self.defsfile.write("kLSUnknownCreator = FOUR_CHAR_CODE('\\0\\0\\0\\0')\n")
46        self.defsfile.write("kLSInvalidExtensionIndex = -1\n")
47
48    def makeblacklistnames(self):
49        return [
50                "LSInit",
51                "LSTerm",
52                "kLSRequestAllInfo",
53                "kLSRolesAll",
54                "kLSInvalidExtensionIndex",
55                "kLSUnknownType",
56                "kLSUnknownCreator"
57                ]
58
59    def makeblacklisttypes(self):
60        return [
61                "LSLaunchFSRefSpec_ptr",
62                "LSLaunchURLSpec_ptr",
63                ]
64
65    def makerepairinstructions(self):
66        return [
67                # LSGetApplicationForInfo
68                ([('CFStringRef', 'inExtension', 'InMode')],
69         [('OptCFStringRef', 'inExtension', 'InMode')]),
70
71                # LSFindApplicationForInfo
72                ([('CFStringRef', 'inBundleID', 'InMode')],
73         [('OptCFStringRef', 'inBundleID', 'InMode')]),
74                ([('CFStringRef', 'inName', 'InMode')],
75         [('OptCFStringRef', 'inName', 'InMode')]),
76
77                # Unicode filenames passed as length, buffer. LSGetExtensionInfo
78                ([('UniCharCount', '*', 'InMode'),
79                  ('UniChar_ptr', '*', 'InMode')],
80                 [('UnicodeReverseInBuffer', '*', 'InMode')]
81                ),
82                ]
83
84if __name__ == "__main__":
85    main()
86