| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | # Scan an Apple header file, generating a Python file of generator calls. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-17 14:07:56 +00:00
										 |  |  | import sys | 
					
						
							|  |  |  | import os | 
					
						
							| 
									
										
										
										
											2002-08-05 15:39:30 +00:00
										 |  |  | from bgenlocations import TOOLBOXDIR, BGENDIR | 
					
						
							| 
									
										
										
										
											1998-04-17 14:07:56 +00:00
										 |  |  | sys.path.append(BGENDIR) | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | from scantools import Scanner | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | def main(): | 
					
						
							|  |  |  | 	input = "QuickDraw.h" | 
					
						
							|  |  |  | 	output = "qdgen.py" | 
					
						
							| 
									
										
										
										
											1996-04-12 16:29:23 +00:00
										 |  |  | 	defsoutput = TOOLBOXDIR + "QuickDraw.py" | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 	scanner = MyScanner(input, output, defsoutput) | 
					
						
							|  |  |  | 	scanner.scan() | 
					
						
							|  |  |  | 	scanner.close() | 
					
						
							| 
									
										
										
										
											1995-06-06 13:08:40 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	# Grmpf. Universal Headers have Text-stuff in a different include file... | 
					
						
							|  |  |  | 	input = "QuickDrawText.h" | 
					
						
							|  |  |  | 	output = "@qdgentext.py" | 
					
						
							|  |  |  | 	defsoutput = "@QuickDrawText.py" | 
					
						
							|  |  |  | 	have_extra = 0 | 
					
						
							|  |  |  | 	try: | 
					
						
							|  |  |  | 		scanner = MyScanner(input, output, defsoutput) | 
					
						
							|  |  |  | 		scanner.scan() | 
					
						
							|  |  |  | 		scanner.close() | 
					
						
							|  |  |  | 		have_extra = 1 | 
					
						
							|  |  |  | 	except IOError: | 
					
						
							|  |  |  | 		pass | 
					
						
							|  |  |  | 	if have_extra: | 
					
						
							|  |  |  | 		print "=== Copying QuickDrawText stuff into main files... ===" | 
					
						
							|  |  |  | 		ifp = open("@qdgentext.py") | 
					
						
							|  |  |  | 		ofp = open("qdgen.py", "a") | 
					
						
							|  |  |  | 		ofp.write(ifp.read()) | 
					
						
							|  |  |  | 		ifp.close() | 
					
						
							|  |  |  | 		ofp.close() | 
					
						
							|  |  |  | 		ifp = open("@QuickDrawText.py") | 
					
						
							| 
									
										
										
										
											1996-04-12 16:29:23 +00:00
										 |  |  | 		ofp = open(TOOLBOXDIR + "QuickDraw.py", "a") | 
					
						
							| 
									
										
										
										
											1995-06-06 13:08:40 +00:00
										 |  |  | 		ofp.write(ifp.read()) | 
					
						
							|  |  |  | 		ifp.close() | 
					
						
							|  |  |  | 		ofp.close() | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											2002-08-15 21:48:16 +00:00
										 |  |  | 	print "=== Testing definitions output code ===" | 
					
						
							|  |  |  | 	execfile(defsoutput, {}, {}) | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 	print "=== Done scanning and generating, now importing the generated code... ===" | 
					
						
							|  |  |  | 	import qdsupport | 
					
						
							|  |  |  | 	print "=== Done.  It's up to you to compile it now! ===" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class MyScanner(Scanner): | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def destination(self, type, name, arglist): | 
					
						
							|  |  |  | 		classname = "Function" | 
					
						
							|  |  |  | 		listname = "functions" | 
					
						
							|  |  |  | 		if arglist: | 
					
						
							|  |  |  | 			t, n, m = arglist[0] | 
					
						
							| 
									
										
										
										
											2002-11-29 23:40:48 +00:00
										 |  |  | 			if t in ('GrafPtr', 'CGrafPtr') and m == 'InMode': | 
					
						
							|  |  |  | 				classname = "Method" | 
					
						
							|  |  |  | 				listname = "gr_methods" | 
					
						
							|  |  |  | 			elif t == 'BitMapPtr' and m == 'InMode': | 
					
						
							|  |  |  | 				classname = "Method" | 
					
						
							|  |  |  | 				listname = "bm_methods" | 
					
						
							| 
									
										
										
										
											1995-11-15 15:18:01 +00:00
										 |  |  | ##			elif t == "PolyHandle" and m == "InMode": | 
					
						
							|  |  |  | ##				classname = "Method" | 
					
						
							|  |  |  | ##				listname = "p_methods" | 
					
						
							|  |  |  | ##			elif t == "RgnHandle" and m == "InMode": | 
					
						
							|  |  |  | ##				classname = "Method" | 
					
						
							|  |  |  | ##				listname = "r_methods" | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 		return classname, listname | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1998-04-23 13:21:09 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	def writeinitialdefs(self): | 
					
						
							| 
									
										
										
										
											1999-01-21 13:31:30 +00:00
										 |  |  | 		self.defsfile.write("""
 | 
					
						
							|  |  |  | def FOUR_CHAR_CODE(x): return x | 
					
						
							|  |  |  | normal						= 0 | 
					
						
							|  |  |  | bold						= 1 | 
					
						
							|  |  |  | italic						= 2 | 
					
						
							|  |  |  | underline					= 4 | 
					
						
							|  |  |  | outline						= 8 | 
					
						
							|  |  |  | shadow						= 0x10 | 
					
						
							|  |  |  | condense					= 0x20 | 
					
						
							|  |  |  | extend						= 0x40 | 
					
						
							|  |  |  | """)
 | 
					
						
							| 
									
										
										
										
											1998-04-23 13:21:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 	def makeblacklistnames(self): | 
					
						
							|  |  |  | 		return [ | 
					
						
							|  |  |  | 			'InitGraf', | 
					
						
							|  |  |  | 			'StuffHex', | 
					
						
							|  |  |  | 			'StdLine', | 
					
						
							|  |  |  | 			'StdComment', | 
					
						
							|  |  |  | 			'StdGetPic', | 
					
						
							| 
									
										
										
										
											1995-11-15 15:18:01 +00:00
										 |  |  | 			'OpenPort', | 
					
						
							|  |  |  | 			'InitPort', | 
					
						
							|  |  |  | 			'ClosePort', | 
					
						
							|  |  |  | 			'OpenCPort', | 
					
						
							|  |  |  | 			'InitCPort', | 
					
						
							|  |  |  | 			'CloseCPort', | 
					
						
							| 
									
										
										
										
											1995-11-16 22:48:29 +00:00
										 |  |  | 			'BitMapToRegionGlue', | 
					
						
							| 
									
										
										
										
											1998-02-20 16:02:09 +00:00
										 |  |  | 			'StdOpcode', 	# XXXX Missing from library... | 
					
						
							| 
									
										
										
										
											1998-04-21 15:23:55 +00:00
										 |  |  | 			# The following are for non-macos use: | 
					
						
							|  |  |  | 			'LockPortBits', | 
					
						
							|  |  |  | 			'UnlockPortBits', | 
					
						
							|  |  |  | 			'UpdatePort', | 
					
						
							|  |  |  | 			'GetPortNativeWindow', | 
					
						
							|  |  |  | 			'GetNativeWindowPort', | 
					
						
							|  |  |  | 			'NativeRegionToMacRegion', | 
					
						
							|  |  |  | 			'MacRegionToNativeRegion', | 
					
						
							|  |  |  | 			'GetPortHWND', | 
					
						
							|  |  |  | 			'GetHWNDPort', | 
					
						
							|  |  |  | 			'GetPICTFromDIB', | 
					
						
							| 
									
										
										
										
											2001-01-24 14:05:11 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			'HandleToRgn', # Funny signature | 
					
						
							| 
									
										
										
										
											1998-02-20 16:02:09 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2001-01-24 14:22:13 +00:00
										 |  |  | 			# Need Cm, which we don't want to drag in just yet | 
					
						
							|  |  |  | 			'OpenCursorComponent', | 
					
						
							|  |  |  | 			'CloseCursorComponent', | 
					
						
							|  |  |  | 			'SetCursorComponent', | 
					
						
							|  |  |  | 			'CursorComponentChanged', | 
					
						
							|  |  |  | 			'CursorComponentSetData', | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def makeblacklisttypes(self): | 
					
						
							|  |  |  | 		return [ | 
					
						
							| 
									
										
										
										
											1997-08-15 14:35:54 +00:00
										 |  |  | 			'CIconHandle', # Obsolete | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			'CQDProcs', | 
					
						
							| 
									
										
										
										
											2000-12-12 22:10:21 +00:00
										 |  |  | 			'CQDProcsPtr', | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			'CSpecArray', | 
					
						
							|  |  |  | 			'ColorComplementProcPtr', | 
					
						
							| 
									
										
										
										
											1995-06-06 13:08:40 +00:00
										 |  |  | 			'ColorComplementUPP', | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			'ColorSearchProcPtr', | 
					
						
							| 
									
										
										
										
											1995-06-06 13:08:40 +00:00
										 |  |  | 			'ColorSearchUPP', | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			'ConstPatternParam', | 
					
						
							|  |  |  | 			'DeviceLoopDrawingProcPtr', | 
					
						
							|  |  |  | 			'DeviceLoopFlags', | 
					
						
							|  |  |  | 			'GrafVerb', | 
					
						
							|  |  |  | 			'OpenCPicParams_ptr', | 
					
						
							|  |  |  | 			'Ptr', | 
					
						
							|  |  |  | 			'QDProcs', | 
					
						
							|  |  |  | 			'ReqListRec', | 
					
						
							|  |  |  | 			'void_ptr', | 
					
						
							| 
									
										
										
										
											2000-12-12 22:10:21 +00:00
										 |  |  | 			'CustomXFerProcPtr', | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def makerepairinstructions(self): | 
					
						
							|  |  |  | 		return [ | 
					
						
							|  |  |  | 			([('void_ptr', 'textBuf', 'InMode'), | 
					
						
							|  |  |  | 			  ('short', 'firstByte', 'InMode'), | 
					
						
							|  |  |  | 			  ('short', 'byteCount', 'InMode')], | 
					
						
							|  |  |  | 			 [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]), | 
					
						
							|  |  |  | 			 | 
					
						
							| 
									
										
										
										
											1996-01-08 23:47:31 +00:00
										 |  |  | 			# GetPen and SetPt use a point-pointer as output-only: | 
					
						
							|  |  |  | 			('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]), | 
					
						
							|  |  |  | 			('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			# All others use it as input/output: | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			([('Point', '*', 'OutMode')], | 
					
						
							|  |  |  | 			 [('*', '*', 'InOutMode')]), | 
					
						
							| 
									
										
										
										
											1995-11-14 10:46:01 +00:00
										 |  |  | 			  | 
					
						
							|  |  |  | 			 # InsetRect, OffsetRect | 
					
						
							|  |  |  | 			 ([('Rect', 'r', 'OutMode'), | 
					
						
							|  |  |  | 			 	('short', 'dh', 'InMode'), | 
					
						
							|  |  |  | 			 	('short', 'dv', 'InMode')], | 
					
						
							|  |  |  | 			  [('Rect', 'r', 'InOutMode'), | 
					
						
							|  |  |  | 			 	('short', 'dh', 'InMode'), | 
					
						
							|  |  |  | 			 	('short', 'dv', 'InMode')]), | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			 # MapRect | 
					
						
							|  |  |  | 			 ([('Rect', 'r', 'OutMode'), | 
					
						
							|  |  |  | 			 	('Rect_ptr', 'srcRect', 'InMode'), | 
					
						
							|  |  |  | 			 	('Rect_ptr', 'dstRect', 'InMode')], | 
					
						
							|  |  |  | 			  [('Rect', 'r', 'InOutMode'), | 
					
						
							|  |  |  | 			 	('Rect_ptr', 'srcRect', 'InMode'), | 
					
						
							|  |  |  | 			 	('Rect_ptr', 'dstRect', 'InMode')]), | 
					
						
							| 
									
										
										
										
											1995-12-12 15:02:03 +00:00
										 |  |  | 			 	 | 
					
						
							|  |  |  | 			 # CopyBits and friends | 
					
						
							|  |  |  | 			 ([('RgnHandle', 'maskRgn', 'InMode')], | 
					
						
							|  |  |  | 			  [('OptRgnHandle', 'maskRgn', 'InMode')]), | 
					
						
							| 
									
										
										
										
											2001-01-24 14:05:11 +00:00
										 |  |  | 			   | 
					
						
							| 
									
										
										
										
											2001-02-06 16:13:50 +00:00
										 |  |  | 			 ('QDFlushPortBuffer', | 
					
						
							|  |  |  | 			  [('RgnHandle', '*', 'InMode')], | 
					
						
							|  |  |  | 			  [('OptRgnHandle', '*', 'InMode')]), | 
					
						
							|  |  |  | 			   | 
					
						
							| 
									
										
										
										
											2001-01-24 14:05:11 +00:00
										 |  |  | 			 # Accessors with reference argument also returned. | 
					
						
							|  |  |  | 			 ([('Rect_ptr', 'GetPortBounds', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('RGBColor_ptr', 'GetPortForeColor', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('RGBColor_ptr', 'GetPortBackColor', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('RGBColor_ptr', 'GetPortOpColor', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('RGBColor_ptr', 'GetPortHiliteColor', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('Point_ptr', 'GetPortPenSize', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('Point_ptr', 'GetPortPenLocation', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('Rect_ptr', 'GetPixBounds', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('BitMap_ptr', 'GetQDGlobalsScreenBits', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('Cursor_ptr', 'GetQDGlobalsArrow', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('Rect_ptr', 'GetRegionBounds', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							|  |  |  | 			 | 
					
						
							|  |  |  | 			 ([('Pattern_ptr', '*', 'ReturnMode')], | 
					
						
							|  |  |  | 			  [('void', '*', 'ReturnMode')]), | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  | 	main() |