blob: 621033ba87b73ab6f9cc121e63f28670d4d742fe [file] [log] [blame]
Jack Jansen7d0a6092003-12-02 23:01:43 +00001# Scan an Apple header file, generating a Python file of generator calls.
2
3import sys
4import os
5from bgenlocations import TOOLBOXDIR, BGENDIR
6sys.path.append(BGENDIR)
7from scantools import Scanner
8
9LONG = "LaunchServices"
10SHORT = "launch"
11OBJECT = "NOTUSED"
12
13def main():
Tim Peters182b5ac2004-07-18 06:16:08 +000014 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 scanner.gentypetest(SHORT+"typetest.py")
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! ==="
Jack Jansen7d0a6092003-12-02 23:01:43 +000026
27class MyScanner(Scanner):
28
Tim Peters182b5ac2004-07-18 06:16:08 +000029 def destination(self, type, name, arglist):
30 classname = "Function"
31 listname = "functions"
32 if arglist:
33 t, n, m = arglist[0]
34 # This is non-functional today
35 if t == OBJECT and m == "InMode":
36 classname = "Method"
37 listname = "methods"
38 return classname, listname
Jack Jansen7d0a6092003-12-02 23:01:43 +000039
Tim Peters182b5ac2004-07-18 06:16:08 +000040 def writeinitialdefs(self):
41 self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
42 self.defsfile.write("from Carbon.Files import *\n")
43 self.defsfile.write("kLSRequestAllInfo = -1\n")
44 self.defsfile.write("kLSRolesAll = -1\n")
45 self.defsfile.write("kLSUnknownType = FOUR_CHAR_CODE('\\0\\0\\0\\0')\n")
46 self.defsfile.write("kLSUnknownCreator = FOUR_CHAR_CODE('\\0\\0\\0\\0')\n")
47 self.defsfile.write("kLSInvalidExtensionIndex = -1\n")
Jack Jansen7d0a6092003-12-02 23:01:43 +000048
Tim Peters182b5ac2004-07-18 06:16:08 +000049 def makeblacklistnames(self):
50 return [
51 "LSInit",
52 "LSTerm",
53 "kLSRequestAllInfo",
54 "kLSRolesAll",
55 "kLSInvalidExtensionIndex",
56 "kLSUnknownType",
57 "kLSUnknownCreator"
58 ]
Jack Jansen7d0a6092003-12-02 23:01:43 +000059
Tim Peters182b5ac2004-07-18 06:16:08 +000060 def makeblacklisttypes(self):
61 return [
62 "LSLaunchFSRefSpec_ptr",
63 "LSLaunchURLSpec_ptr",
64 ]
Jack Jansen7d0a6092003-12-02 23:01:43 +000065
Tim Peters182b5ac2004-07-18 06:16:08 +000066 def makerepairinstructions(self):
67 return [
68 # LSGetApplicationForInfo
69 ([('CFStringRef', 'inExtension', 'InMode')],
70 [('OptCFStringRef', 'inExtension', 'InMode')]),
Jack Jansenda6081f2003-12-03 23:20:13 +000071
Tim Peters182b5ac2004-07-18 06:16:08 +000072 # LSFindApplicationForInfo
73 ([('CFStringRef', 'inBundleID', 'InMode')],
74 [('OptCFStringRef', 'inBundleID', 'InMode')]),
75 ([('CFStringRef', 'inName', 'InMode')],
76 [('OptCFStringRef', 'inName', 'InMode')]),
77
78 # Unicode filenames passed as length, buffer. LSGetExtensionInfo
79 ([('UniCharCount', '*', 'InMode'),
80 ('UniChar_ptr', '*', 'InMode')],
81 [('UnicodeReverseInBuffer', '*', 'InMode')]
82 ),
83 ]
84
Jack Jansen7d0a6092003-12-02 23:01:43 +000085if __name__ == "__main__":
Tim Peters182b5ac2004-07-18 06:16:08 +000086 main()