| 
									
										
										
										
											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 | 
					
						
							|  |  |  | BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen') | 
					
						
							|  |  |  | sys.path.append(BGENDIR) | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | from scantools import Scanner | 
					
						
							| 
									
										
										
										
											1996-04-12 16:29:23 +00:00
										 |  |  | from bgenlocations import TOOLBOXDIR | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 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() | 
					
						
							|  |  |  | 		 | 
					
						
							| 
									
										
										
										
											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] | 
					
						
							| 
									
										
										
										
											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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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... | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	def makeblacklisttypes(self): | 
					
						
							|  |  |  | 		return [ | 
					
						
							| 
									
										
										
										
											1997-08-15 14:35:54 +00:00
										 |  |  | ##			'CCrsrHandle', | 
					
						
							|  |  |  | 			'CIconHandle', # Obsolete | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			'CQDProcs', | 
					
						
							|  |  |  | 			'CSpecArray', | 
					
						
							| 
									
										
										
										
											1997-08-15 14:35:54 +00:00
										 |  |  | ##			'CTabHandle', | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			'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', | 
					
						
							| 
									
										
										
										
											1996-01-11 16:17:14 +00:00
										 |  |  | ##			'FontInfo', | 
					
						
							| 
									
										
										
										
											1997-08-15 14:35:54 +00:00
										 |  |  | ##			'GDHandle', | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			'GrafVerb', | 
					
						
							|  |  |  | 			'OpenCPicParams_ptr', | 
					
						
							|  |  |  | 			'Ptr', | 
					
						
							|  |  |  | 			'QDProcs', | 
					
						
							|  |  |  | 			'ReqListRec', | 
					
						
							|  |  |  | 			'void_ptr', | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	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')]), | 
					
						
							| 
									
										
										
										
											1995-03-19 22:49:50 +00:00
										 |  |  | 			 | 
					
						
							|  |  |  | 			] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if __name__ == "__main__": | 
					
						
							|  |  |  | 	main() |