| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. | 
 | 2 |  | 
| Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 3 | import sys | 
 | 4 | import os | 
| Jack Jansen | aaebdd6 | 2002-08-05 15:39:30 +0000 | [diff] [blame] | 5 | from bgenlocations import TOOLBOXDIR, BGENDIR | 
| Jack Jansen | 0c4d947 | 1998-04-17 14:07:56 +0000 | [diff] [blame] | 6 | sys.path.append(BGENDIR) | 
| Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 7 |  | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 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" | 
| Jack Jansen | 46d9e79 | 1996-04-12 16:29:23 +0000 | [diff] [blame] | 17 | 	defsoutput = TOOLBOXDIR + LONG + ".py" | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 18 | 	scanner = MyScanner(input, output, defsoutput) | 
 | 19 | 	scanner.scan() | 
 | 20 | 	scanner.close() | 
| Jack Jansen | 87eea88 | 2002-08-15 21:48:16 +0000 | [diff] [blame^] | 21 | 	print "=== Testing definitions output code ===" | 
 | 22 | 	execfile(defsoutput, {}, {}) | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 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] | 
| Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 34 | 			if t in ("DialogPtr", "DialogRef") and m == "InMode": | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 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', | 
| Guido van Rossum | 9784295 | 1995-02-19 15:59:49 +0000 | [diff] [blame] | 47 | 			'UpdtDialog', | 
 | 48 | 			'CouldAlert', | 
 | 49 | 			'FreeAlert', | 
 | 50 | 			'CouldDialog', | 
 | 51 | 			'FreeDialog', | 
| Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 52 | 			'GetStdFilterProc', | 
| Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 53 | 			'GetDialogParent', | 
| Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 54 | ##			# Can't find these in the CW Pro 3 libraries | 
| Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 55 | 			'SetDialogMovableModal', | 
 | 56 | 			'GetDialogControlNotificationProc', | 
| Jack Jansen | bd00884 | 2001-11-05 16:16:39 +0000 | [diff] [blame] | 57 | 			'SetGrafPortOfDialog', # Funny, and probably not useful | 
| Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 58 | 			# Can't find these: | 
 | 59 | 			'CloseStandardSheet', | 
 | 60 | 			'RunStandardAlert', | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 61 | 			] | 
 | 62 |  | 
| Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 63 | 	def makegreylist(self): | 
 | 64 | 		return [ | 
| Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 65 | 			('#if TARGET_API_MAC_CARBON', [ | 
 | 66 | 				'InsertDialogItem', | 
 | 67 | 				'RemoveDialogItems', | 
 | 68 | 				'GetParamText', | 
| Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 69 | 				'CloseStandardSheet', | 
 | 70 | 				'RunStandardAlert', | 
| Jack Jansen | e79dc76 | 2000-06-02 21:35:07 +0000 | [diff] [blame] | 71 | 			])] | 
 | 72 | 			 | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 73 | 	def makeblacklisttypes(self): | 
 | 74 | 		return [ | 
| Jack Jansen | 21f9687 | 1998-02-20 16:02:09 +0000 | [diff] [blame] | 75 | 			"AlertStdAlertParamPtr",	# Too much work, for now | 
| Jack Jansen | f7d5aa6 | 2000-12-10 23:43:49 +0000 | [diff] [blame] | 76 | 			"AlertStdAlertParamRec",	# ditto | 
 | 77 | 			"AlertStdAlertParamRec_ptr",	# ditto | 
| Jack Jansen | 2168e9d | 2001-12-16 20:18:40 +0000 | [diff] [blame] | 78 | 			"AlertStdCFStringAlertParamPtr",	# ditto | 
 | 79 | 			"AlertStdCFStringAlertParamRec", | 
 | 80 | 			"AlertStdCFStringAlertParamRec_ptr", | 
| Jack Jansen | 1c4e614 | 1998-04-21 15:23:55 +0000 | [diff] [blame] | 81 | 			"QTModelessCallbackProcPtr", | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 82 | 			] | 
 | 83 |  | 
 | 84 | 	def makerepairinstructions(self): | 
 | 85 | 		return [ | 
 | 86 | 			([("Str255", "*", "InMode")], | 
 | 87 | 			 [("*", "*", "OutMode")]), | 
 | 88 | 			 | 
 | 89 | 			([("void_ptr", "*", "InMode"), ("long", "*", "InMode")], | 
 | 90 | 			 [("InBuffer", "*", "*")]), | 
 | 91 | 			 | 
 | 92 | 			([("void", "*", "OutMode"), ("long", "*", "InMode"), | 
 | 93 | 			                            ("long", "*", "OutMode")], | 
 | 94 | 			 [("VarVarOutBuffer", "*", "InOutMode")]), | 
| Jack Jansen | 91a6398 | 1995-08-17 14:30:52 +0000 | [diff] [blame] | 95 | 			  | 
 | 96 | 			# GetDialogItem return handle is optional | 
 | 97 | 			([("Handle", "item", "OutMode")], | 
 | 98 | 			 [("OptHandle", "item", "OutMode")]), | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 99 | 			 | 
 | 100 | 			# NewDialog ETC. | 
 | 101 | 			([("void", "*", "OutMode")], | 
 | 102 | 			 [("NullStorage", "*", "InMode")]), | 
 | 103 | 			 | 
 | 104 | 			([("DialogPtr", "*", "OutMode")], | 
 | 105 | 			 [("ExistingDialogPtr", "*", "*")]), | 
| Jack Jansen | ae8a68f | 1995-06-06 12:55:40 +0000 | [diff] [blame] | 106 | 			([("DialogRef", "*", "OutMode")], | 
 | 107 | 			 [("ExistingDialogPtr", "*", "*")]), | 
| Jack Jansen | b8c4c7b | 2000-08-25 22:25:54 +0000 | [diff] [blame] | 108 | 			([("WindowPtr", "*", "OutMode")], | 
 | 109 | 			 [("ExistingWindowPtr", "*", "*")]), | 
 | 110 | 			([("WindowPtr", "*", "ReturnMode")], | 
 | 111 | 			 [("ExistingWindowPtr", "*", "*")]), | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 112 | 			] | 
 | 113 |  | 
| Jack Jansen | a05ac60 | 1999-12-12 21:41:51 +0000 | [diff] [blame] | 114 | 	def writeinitialdefs(self): | 
 | 115 | 		self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n") | 
 | 116 |  | 
 | 117 |  | 
| Guido van Rossum | 17448e2 | 1995-01-30 11:53:55 +0000 | [diff] [blame] | 118 | if __name__ == "__main__": | 
 | 119 | 	main() |