| 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_OSX
|
|---|
| 8 |
|
|---|
| 9 | LONG = "CoreFoundation"
|
|---|
| 10 | SHORT = "cf"
|
|---|
| 11 | OBJECTS = ("CFTypeRef",
|
|---|
| 12 | "CFArrayRef", "CFMutableArrayRef",
|
|---|
| 13 | "CFDataRef", "CFMutableDataRef",
|
|---|
| 14 | "CFDictionaryRef", "CFMutableDictionaryRef",
|
|---|
| 15 | "CFStringRef", "CFMutableStringRef",
|
|---|
| 16 | "CFURLRef",
|
|---|
| 17 | ## "CFPropertyListRef",
|
|---|
| 18 | )
|
|---|
| 19 | # ADD object typenames here
|
|---|
| 20 |
|
|---|
| 21 | def main():
|
|---|
| 22 | input = [
|
|---|
| 23 | "CFBase.h",
|
|---|
| 24 | "CFArray.h",
|
|---|
| 25 | ## "CFBag.h",
|
|---|
| 26 | ## "CFBundle.h",
|
|---|
| 27 | ## "CFCharacterSet.h",
|
|---|
| 28 | "CFData.h",
|
|---|
| 29 | ## "CFDate.h",
|
|---|
| 30 | "CFDictionary.h",
|
|---|
| 31 | ## "CFNumber.h",
|
|---|
| 32 | ## "CFPlugIn.h",
|
|---|
| 33 | "CFPreferences.h",
|
|---|
| 34 | "CFPropertyList.h",
|
|---|
| 35 | ## "CFSet.h",
|
|---|
| 36 | "CFString.h",
|
|---|
| 37 | ## "CFStringEncodingExt.h",
|
|---|
| 38 | ## "CFTimeZone.h",
|
|---|
| 39 | "CFURL.h",
|
|---|
| 40 | ]
|
|---|
| 41 | output = SHORT + "gen.py"
|
|---|
| 42 | defsoutput = TOOLBOXDIR + LONG + ".py"
|
|---|
| 43 | scanner = MyScanner(input, output, defsoutput)
|
|---|
| 44 | scanner.scan()
|
|---|
| 45 | scanner.gentypetest(SHORT+"typetest.py")
|
|---|
| 46 | scanner.close()
|
|---|
| 47 | print "=== Testing definitions output code ==="
|
|---|
| 48 | execfile(defsoutput, {}, {})
|
|---|
| 49 | print "=== Done scanning and generating, now importing the generated code... ==="
|
|---|
| 50 | exec "import " + SHORT + "support"
|
|---|
| 51 | print "=== Done. It's up to you to compile it now! ==="
|
|---|
| 52 |
|
|---|
| 53 | class MyScanner(Scanner_OSX):
|
|---|
| 54 |
|
|---|
| 55 | def destination(self, type, name, arglist):
|
|---|
| 56 | classname = "Function"
|
|---|
| 57 | listname = "functions"
|
|---|
| 58 | if arglist and name[:13] != 'CFPreferences':
|
|---|
| 59 | t, n, m = arglist[0]
|
|---|
| 60 | if t in OBJECTS and m == "InMode":
|
|---|
| 61 | classname = "Method"
|
|---|
| 62 | listname = t + "_methods"
|
|---|
| 63 | # Special case for the silly first AllocatorRef argument
|
|---|
|
|---|