| Guido van Rossum | e56db43 | 1995-03-19 22:49:50 +0000 | [diff] [blame] | 1 | # Scan an Apple header file, generating a Python file of generator calls. | 
|  | 2 |  | 
|  | 3 | import addpack | 
| Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 4 | addpack.addpack(':Tools:bgen:bgen') | 
| Guido van Rossum | e56db43 | 1995-03-19 22:49:50 +0000 | [diff] [blame] | 5 |  | 
|  | 6 | from scantools import Scanner | 
|  | 7 |  | 
|  | 8 | def main(): | 
|  | 9 | input = "QuickDraw.h" | 
|  | 10 | output = "qdgen.py" | 
|  | 11 | defsoutput = "QuickDraw.py" | 
|  | 12 | scanner = MyScanner(input, output, defsoutput) | 
|  | 13 | scanner.scan() | 
|  | 14 | scanner.close() | 
| Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 15 |  | 
|  | 16 | # Grmpf. Universal Headers have Text-stuff in a different include file... | 
|  | 17 | input = "QuickDrawText.h" | 
|  | 18 | output = "@qdgentext.py" | 
|  | 19 | defsoutput = "@QuickDrawText.py" | 
|  | 20 | have_extra = 0 | 
|  | 21 | try: | 
|  | 22 | scanner = MyScanner(input, output, defsoutput) | 
|  | 23 | scanner.scan() | 
|  | 24 | scanner.close() | 
|  | 25 | have_extra = 1 | 
|  | 26 | except IOError: | 
|  | 27 | pass | 
|  | 28 | if have_extra: | 
|  | 29 | print "=== Copying QuickDrawText stuff into main files... ===" | 
|  | 30 | ifp = open("@qdgentext.py") | 
|  | 31 | ofp = open("qdgen.py", "a") | 
|  | 32 | ofp.write(ifp.read()) | 
|  | 33 | ifp.close() | 
|  | 34 | ofp.close() | 
|  | 35 | ifp = open("@QuickDrawText.py") | 
|  | 36 | ofp = open("QuickDraw.py", "a") | 
|  | 37 | ofp.write(ifp.read()) | 
|  | 38 | ifp.close() | 
|  | 39 | ofp.close() | 
|  | 40 |  | 
| Guido van Rossum | e56db43 | 1995-03-19 22:49:50 +0000 | [diff] [blame] | 41 | print "=== Done scanning and generating, now importing the generated code... ===" | 
|  | 42 | import qdsupport | 
|  | 43 | print "=== Done.  It's up to you to compile it now! ===" | 
|  | 44 |  | 
|  | 45 | class MyScanner(Scanner): | 
|  | 46 |  | 
|  | 47 | def destination(self, type, name, arglist): | 
|  | 48 | classname = "Function" | 
|  | 49 | listname = "functions" | 
|  | 50 | if arglist: | 
|  | 51 | t, n, m = arglist[0] | 
| Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 52 | if t in ("WindowPtr", "WindowPeek", "WindowRef") and m == "InMode": | 
| Guido van Rossum | e56db43 | 1995-03-19 22:49:50 +0000 | [diff] [blame] | 53 | classname = "Method" | 
|  | 54 | listname = "methods" | 
|  | 55 | return classname, listname | 
|  | 56 |  | 
|  | 57 | def makeblacklistnames(self): | 
|  | 58 | return [ | 
|  | 59 | 'InitGraf', | 
|  | 60 | 'StuffHex', | 
|  | 61 | 'StdLine', | 
|  | 62 | 'StdComment', | 
|  | 63 | 'StdGetPic', | 
|  | 64 | 'StdLine', | 
|  | 65 | ] | 
|  | 66 |  | 
|  | 67 | def makeblacklisttypes(self): | 
|  | 68 | return [ | 
|  | 69 | 'BitMap_ptr', | 
|  | 70 | 'CCrsrHandle', | 
|  | 71 | 'CGrafPtr', | 
|  | 72 | 'CIconHandle', | 
|  | 73 | 'CQDProcs', | 
|  | 74 | 'CSpecArray', | 
|  | 75 | 'CTabHandle', | 
|  | 76 | 'ColorComplementProcPtr', | 
| Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 77 | 'ColorComplementUPP', | 
| Guido van Rossum | e56db43 | 1995-03-19 22:49:50 +0000 | [diff] [blame] | 78 | 'ColorSearchProcPtr', | 
| Jack Jansen | b81cf9d | 1995-06-06 13:08:40 +0000 | [diff] [blame^] | 79 | 'ColorSearchUPP', | 
| Guido van Rossum | e56db43 | 1995-03-19 22:49:50 +0000 | [diff] [blame] | 80 | 'ConstPatternParam', | 
|  | 81 | 'Cursor_ptr', | 
|  | 82 | 'DeviceLoopDrawingProcPtr', | 
|  | 83 | 'DeviceLoopFlags', | 
|  | 84 | 'FontInfo', | 
|  | 85 | 'GDHandle', | 
|  | 86 | 'GrafVerb', | 
|  | 87 | 'OpenCPicParams_ptr', | 
|  | 88 | 'PenState', | 
|  | 89 | 'PenState_ptr', | 
|  | 90 | 'Ptr', | 
|  | 91 | 'QDProcs', | 
|  | 92 | 'RGBColor', | 
|  | 93 | 'RGBColor_ptr', | 
|  | 94 | 'ReqListRec', | 
|  | 95 | 'void_ptr', | 
|  | 96 | ] | 
|  | 97 |  | 
|  | 98 | def makerepairinstructions(self): | 
|  | 99 | return [ | 
|  | 100 | ([('void_ptr', 'textBuf', 'InMode'), | 
|  | 101 | ('short', 'firstByte', 'InMode'), | 
|  | 102 | ('short', 'byteCount', 'InMode')], | 
|  | 103 | [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]), | 
|  | 104 |  | 
|  | 105 | ([('Point', '*', 'OutMode')], | 
|  | 106 | [('*', '*', 'InOutMode')]), | 
|  | 107 |  | 
|  | 108 | ] | 
|  | 109 |  | 
|  | 110 | if __name__ == "__main__": | 
|  | 111 | main() |