| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | # Scan an Apple header file, generating a Python file of generator calls. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import sys | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2002-08-05 15:39:30 +00:00
										 |  |  | from bgenlocations import TOOLBOXDIR, BGENDIR | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | sys.path.append(BGENDIR) | 
					
						
							|  |  |  | from scantools import Scanner_OSX | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | LONG = "CoreFoundation" | 
					
						
							|  |  |  | SHORT = "cf" | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | OBJECTS = ("CFTypeRef",  | 
					
						
							|  |  |  | 		"CFArrayRef", "CFMutableArrayRef", | 
					
						
							|  |  |  | 		"CFDataRef", "CFMutableDataRef", | 
					
						
							|  |  |  | 		"CFDictionaryRef", "CFMutableDictionaryRef", | 
					
						
							| 
									
										
										
										
											2001-06-28 22:08:26 +00:00
										 |  |  | 		"CFStringRef", "CFMutableStringRef", | 
					
						
							|  |  |  | 		"CFURLRef", | 
					
						
							| 
									
										
										
										
											2002-05-10 22:51:58 +00:00
										 |  |  | ##		"CFPropertyListRef", | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 		) | 
					
						
							|  |  |  | # ADD object typenames here | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							|  |  |  | 	input = [ | 
					
						
							|  |  |  | 		"CFBase.h", | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 		"CFArray.h", | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | ##		"CFBag.h", | 
					
						
							|  |  |  | ##		"CFBundle.h", | 
					
						
							|  |  |  | ##		"CFCharacterSet.h", | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 		"CFData.h", | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | ##		"CFDate.h", | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 		"CFDictionary.h", | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | ##		"CFNumber.h", | 
					
						
							|  |  |  | ##		"CFPlugIn.h", | 
					
						
							| 
									
										
										
										
											2002-05-13 21:21:49 +00:00
										 |  |  | 		"CFPreferences.h", | 
					
						
							| 
									
										
										
										
											2002-05-10 22:51:58 +00:00
										 |  |  | 		"CFPropertyList.h", | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | ##		"CFSet.h", | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 		"CFString.h", | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | ##		"CFStringEncodingExt.h", | 
					
						
							|  |  |  | ##		"CFTimeZone.h", | 
					
						
							| 
									
										
										
										
											2001-06-28 22:08:26 +00:00
										 |  |  | 		"CFURL.h", | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | 		] | 
					
						
							|  |  |  | 	output = SHORT + "gen.py" | 
					
						
							|  |  |  | 	defsoutput = TOOLBOXDIR + LONG + ".py" | 
					
						
							|  |  |  | 	scanner = MyScanner(input, output, defsoutput) | 
					
						
							|  |  |  | 	scanner.scan() | 
					
						
							|  |  |  | 	scanner.gentypetest(SHORT+"typetest.py") | 
					
						
							|  |  |  | 	scanner.close() | 
					
						
							|  |  |  | 	print "=== Done scanning and generating, now importing the generated code... ===" | 
					
						
							|  |  |  | 	exec "import " + SHORT + "support" | 
					
						
							|  |  |  | 	print "=== Done.  It's up to you to compile it now! ===" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MyScanner(Scanner_OSX): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def destination(self, type, name, arglist): | 
					
						
							|  |  |  | 		classname = "Function" | 
					
						
							|  |  |  | 		listname = "functions" | 
					
						
							| 
									
										
										
										
											2002-05-13 21:21:49 +00:00
										 |  |  | 		if arglist and name[:13] != 'CFPreferences': | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | 			t, n, m = arglist[0] | 
					
						
							|  |  |  | 			if t in OBJECTS and m == "InMode": | 
					
						
							|  |  |  | 				classname = "Method" | 
					
						
							|  |  |  | 				listname = t + "_methods" | 
					
						
							| 
									
										
										
										
											2001-07-17 20:47:13 +00:00
										 |  |  | 			# Special case for the silly first AllocatorRef argument | 
					
						
							|  |  |  | 			if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1: | 
					
						
							|  |  |  | 				t, n, m = arglist[1] | 
					
						
							|  |  |  | 				if t in OBJECTS and m == "InMode": | 
					
						
							|  |  |  | 					classname = "MethodSkipArg1" | 
					
						
							|  |  |  | 					listname = t + "_methods" | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | 		return classname, listname | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def writeinitialdefs(self): | 
					
						
							|  |  |  | 		self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def makeblacklistnames(self): | 
					
						
							|  |  |  | 		return [ | 
					
						
							|  |  |  | 			# Memory allocator functions | 
					
						
							|  |  |  | 			"CFAllocatorGetDefault", | 
					
						
							|  |  |  | 			"CFAllocatorSetDefault", | 
					
						
							|  |  |  | 			"CFAllocatorAllocate", | 
					
						
							|  |  |  | 			"CFAllocatorReallocate", | 
					
						
							|  |  |  | 			"CFAllocatorDeallocate", | 
					
						
							|  |  |  | 			"CFGetAllocator", | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 			# Array functions we skip for now. | 
					
						
							|  |  |  | 			"CFArrayGetValueAtIndex", | 
					
						
							|  |  |  | 			# Data pointer functions. Skip for now. | 
					
						
							|  |  |  | 			"CFDataGetBytePtr", | 
					
						
							|  |  |  | 			"CFDataGetMutableBytePtr", | 
					
						
							|  |  |  | 			"CFDataGetBytes",   # XXXX Should support this one | 
					
						
							|  |  |  | 			# String functions | 
					
						
							|  |  |  | 			"CFStringGetPascalString", # Use the C-string methods. | 
					
						
							|  |  |  | 			"CFStringGetPascalStringPtr", # TBD automatically | 
					
						
							|  |  |  | 			"CFStringGetCStringPtr",  | 
					
						
							| 
									
										
										
										
											2001-06-28 22:08:26 +00:00
										 |  |  | 			"CFStringGetCharactersPtr", | 
					
						
							| 
									
										
										
										
											2001-07-01 22:04:02 +00:00
										 |  |  | 			"CFStringGetCString",  | 
					
						
							|  |  |  | 			"CFStringGetCharacters", | 
					
						
							| 
									
										
										
										
											2001-07-17 20:47:13 +00:00
										 |  |  | 			"CFURLCreateStringWithFileSystemPath", # Gone in later releases | 
					
						
							| 
									
										
										
										
											2002-01-01 22:43:13 +00:00
										 |  |  | 			"CFStringCreateMutableWithExternalCharactersNoCopy", # Not a clue... | 
					
						
							|  |  |  | 			"CFStringSetExternalCharactersNoCopy", | 
					
						
							|  |  |  | 			"CFStringGetCharacterAtIndex", # No format for single unichars yet. | 
					
						
							| 
									
										
										
										
											2002-03-24 23:04:18 +00:00
										 |  |  | 			"kCFStringEncodingInvalidId", # incompatible constant declaration | 
					
						
							| 
									
										
										
										
											2002-05-12 22:04:14 +00:00
										 |  |  | 			"CFPropertyListCreateFromXMLData", # Manually generated | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | 			] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def makegreylist(self): | 
					
						
							|  |  |  | 		return [] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def makeblacklisttypes(self): | 
					
						
							|  |  |  | 		return [ | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 			"CFComparatorFunction", # Callback function pointer | 
					
						
							|  |  |  | 			"CFAllocatorContext", # Not interested in providing our own allocator | 
					
						
							|  |  |  | 			"void_ptr_ptr",  # Tricky. This is the initializer for arrays... | 
					
						
							|  |  |  | 			"void_ptr", # Ditto for various array lookup methods | 
					
						
							|  |  |  | 			"CFArrayApplierFunction", # Callback function pointer | 
					
						
							|  |  |  | 			"CFDictionaryApplierFunction", # Callback function pointer | 
					
						
							|  |  |  | 			"va_list", # For printf-to-a-cfstring. Use Python. | 
					
						
							|  |  |  | 			"const_CFStringEncoding_ptr", # To be done, I guess | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | 			] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def makerepairinstructions(self): | 
					
						
							|  |  |  | 		return [ | 
					
						
							| 
									
										
										
										
											2001-06-28 22:08:26 +00:00
										 |  |  | 			# Buffers in CF seem to be passed as UInt8 * normally. | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 			([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")], | 
					
						
							|  |  |  | 			 [("UcharInBuffer", "*", "*")]), | 
					
						
							| 
									
										
										
										
											2001-06-28 22:08:26 +00:00
										 |  |  | 			  | 
					
						
							| 
									
										
										
										
											2002-01-01 22:43:13 +00:00
										 |  |  | 			([("UniChar_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")], | 
					
						
							|  |  |  | 			 [("UnicodeInBuffer", "*", "*")]), | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-06-28 22:08:26 +00:00
										 |  |  | 			# Some functions return a const char *. Don't worry, we won't modify it. | 
					
						
							| 
									
										
										
										
											2001-06-27 22:00:55 +00:00
										 |  |  | 			([("const_char_ptr", "*", "ReturnMode")], | 
					
						
							|  |  |  | 			 [("return_stringptr", "*", "*")]), | 
					
						
							| 
									
										
										
										
											2001-06-28 22:08:26 +00:00
										 |  |  | 			  | 
					
						
							|  |  |  | 			# base URLs are optional (pass None for NULL) | 
					
						
							|  |  |  | 			([("CFURLRef", "baseURL", "InMode")], | 
					
						
							|  |  |  | 			 [("OptionalCFURLRef", "*", "*")]), | 
					
						
							|  |  |  | 			  | 
					
						
							| 
									
										
										
										
											2002-05-10 22:51:58 +00:00
										 |  |  | 			# We handle CFPropertyListRef objects as plain CFTypeRef | 
					
						
							|  |  |  | 			([("CFPropertyListRef", "*", "*")], | 
					
						
							|  |  |  | 			 [("CFTypeRef", "*", "*")]), | 
					
						
							| 
									
										
										
										
											2001-06-26 21:51:18 +00:00
										 |  |  | 			] | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  | 	main() |