| 1 | # Scan an Apple header file, generating a Python file of generator calls.
|
|---|
| 2 |
|
|---|
| 3 | import sys
|
|---|
| 4 | import os
|
|---|
| 5 | from bgenlocations import TOOLBOXDIR, BGENDIR
|
|---|
| 6 | sys.path.append(BGENDIR)
|
|---|
| 7 |
|
|---|
| 8 | from scantools import Scanner
|
|---|
| 9 |
|
|---|
| 10 | def main():
|
|---|
| 11 | input = "QuickDraw.h"
|
|---|
| 12 | output = "qdgen.py"
|
|---|
| 13 | defsoutput = TOOLBOXDIR + "QuickDraw.py"
|
|---|
| 14 | scanner = MyScanner(input, output, defsoutput)
|
|---|
| 15 | scanner.scan()
|
|---|
| 16 | scanner.close()
|
|---|
| 17 |
|
|---|
| 18 | # Grmpf. Universal Headers have Text-stuff in a different include file...
|
|---|
| 19 | input = "QuickDrawText.h"
|
|---|
| 20 | output = "@qdgentext.py"
|
|---|
| 21 | defsoutput = "@QuickDrawText.py"
|
|---|
| 22 | have_extra = 0
|
|---|
| 23 | try:
|
|---|
| 24 | scanner = MyScanner(input, output, defsoutput)
|
|---|
| 25 | scanner.scan()
|
|---|
| 26 | scanner.close()
|
|---|
| 27 | have_extra = 1
|
|---|
| 28 | except IOError:
|
|---|
| 29 | pass
|
|---|
| 30 | if have_extra:
|
|---|
| 31 | print "=== Copying QuickDrawText stuff into main files... ==="
|
|---|
| 32 | ifp = open("@qdgentext.py")
|
|---|
| 33 | ofp = open("qdgen.py", "a")
|
|---|
| 34 | ofp.write(ifp.read())
|
|---|
| 35 | ifp.close()
|
|---|
| 36 | ofp.close()
|
|---|
| 37 | ifp = open("@QuickDrawText.py")
|
|---|
| 38 | ofp = open(TOOLBOXDIR + "QuickDraw.py", "a")
|
|---|
| 39 | ofp.write(ifp.read())
|
|---|
| 40 | ifp.close()
|
|---|
| 41 | ofp.close()
|
|---|
| 42 |
|
|---|
| 43 | print "=== Testing definitions output code ==="
|
|---|
| 44 | execfile(defsoutput, {}, {})
|
|---|
| 45 | print "=== Done scanning and generating, now importing the generated code... ==="
|
|---|
| 46 | import qdsupport
|
|---|
| 47 | print "=== Done. It's up to you to compile it now! ==="
|
|---|
| 48 |
|
|---|
| 49 | class MyScanner(Scanner):
|
|---|
| 50 |
|
|---|
| 51 | def destination(self, type, name, arglist):
|
|---|
| 52 | classname = "Function"
|
|---|
| 53 | listname = "functions"
|
|---|
| 54 | if arglist:
|
|---|
| 55 | t, n, m = arglist[0]
|
|---|
| 56 | if t in ('GrafPtr', 'CGrafPtr') and m == 'InMode':
|
|---|
| 57 | classname = "Method"
|
|---|
| 58 | listname = "gr_methods"
|
|---|
| 59 | elif t == 'BitMapPtr' and m == 'InMode':
|
|---|
| 60 | classname = "Method"
|
|---|
| 61 | listname = "bm_methods"
|
|---|
| 62 | ## elif t == "PolyHandle" and m == "InMode":
|
|---|
| 63 | ## classname = "Method"
|
|---|
| 64 | ## listname = "p_methods"
|
|---|
| 65 | ## elif t == "RgnHandle" and m == "InMode":
|
|---|
| 66 | ## classname = "Method"
|
|---|
| 67 | ## listname = "r_methods"
|
|---|
| 68 | return classname, listname
|
|---|
| 69 |
|
|---|
| 70 |
|
|---|
| 71 | def writeinitialdefs(self):
|
|---|
| 72 | self.defsfile.write("""
|
|---|
| 73 | def FOUR_CHAR_CODE(x): return x
|
|---|
| 74 | normal = 0
|
|---|
| 75 | bold = 1
|
|---|
| 76 | italic = 2
|
|---|
| 77 | underline = 4
|
|---|
| 78 | outline = 8
|
|---|
| 79 | shadow = 0x10
|
|---|
| 80 | condense = 0x20
|
|---|
| 81 | extend = 0x40
|
|---|
| 82 | """)
|
|---|
| 83 |
|
|---|
| 84 | def makeblacklistnames(self):
|
|---|
| 85 | return [
|
|---|
| 86 | 'InitGraf',
|
|---|
| 87 | 'StuffHex',
|
|---|
| 88 | 'StdLine',
|
|---|
| 89 | 'StdComment',
|
|---|
| 90 | 'StdGetPic',
|
|---|
| 91 | 'OpenPort',
|
|---|
| 92 | 'InitPort',
|
|---|
| 93 | 'ClosePort',
|
|---|
| 94 | 'OpenCPort',
|
|---|
| 95 | 'InitCPort',
|
|---|
| 96 | 'CloseCPort',
|
|---|
| 97 | 'BitMapToRegionGlue',
|
|---|
| 98 | 'StdOpcode', # XXXX Missing from library...
|
|---|
| 99 | # The following are for non-macos use:
|
|---|
| 100 | 'LockPortBits',
|
|---|
| 101 | 'UnlockPortBits',
|
|---|
| 102 | 'UpdatePort',
|
|---|
| 103 | 'GetPortNativeWindow',
|
|---|
| 104 | 'GetNativeWindowPort',
|
|---|
| 105 | 'NativeRegionToMacRegion',
|
|---|
| 106 | 'MacRegionToNativeRegion',
|
|---|
| 107 | 'GetPortHWND',
|
|---|
| 108 | 'GetHWNDPort',
|
|---|
| 109 | 'GetPICTFromDIB',
|
|---|
| 110 |
|
|---|
| 111 | 'HandleToRgn', # Funny signature
|
|---|
| 112 |
|
|---|
| 113 | # Need Cm, which we don't want to drag in just yet
|
|---|
| 114 | 'OpenCursorComponent',
|
|---|
| 115 | 'CloseCursorComponent',
|
|---|
| 116 | 'SetCursorComponent',
|
|---|
| 117 | 'CursorComponentChanged',
|
|---|
| 118 | 'CursorComponentSetData',
|
|---|
| 119 | ]
|
|---|
| 120 |
|
|---|
| 121 | def makeblacklisttypes(self):
|
|---|
| 122 | return [
|
|---|
| 123 | "QDRegionBitsRef", # Should do this, but too lazy now.
|
|---|
| 124 | 'CIconHandle', # Obsolete
|
|---|
| 125 | 'CQDProcs',
|
|---|
| 126 | 'CQDProcsPtr',
|
|---|
| 127 | 'CSpecArray',
|
|---|
| 128 | 'ColorComplementProcPtr',
|
|---|
| 129 | 'ColorComplementUPP',
|
|---|
| 130 | 'ColorSearchProcPtr',
|
|---|
| 131 | 'ColorSearchUPP',
|
|---|
| 132 | 'ConstPatternParam',
|
|---|
| 133 | 'DeviceLoopDrawingProcPtr',
|
|---|
| 134 | 'DeviceLoopFlags',
|
|---|
| 135 | 'GrafVerb',
|
|---|
| 136 | 'OpenCPicParams_ptr',
|
|---|
| 137 | 'Ptr',
|
|---|
| 138 | 'QDProcs',
|
|---|
| 139 | 'ReqListRec',
|
|---|
| 140 | 'void_ptr',
|
|---|
| 141 | 'CustomXFerProcPtr',
|
|---|
| 142 | ]
|
|---|
| 143 |
|
|---|
| 144 | def makerepairinstructions(self):
|
|---|
| 145 | return [
|
|---|
| 146 | ([('void_ptr', 'textBuf', 'InMode'),
|
|---|
| 147 | ('short', 'firstByte', 'InMode'),
|
|---|
| 148 | ('short', 'byteCount', 'InMode')],
|
|---|
| 149 | [('TextThingie', '*', '*'), ('*', '*', '*'), ('*', '*', '*')]),
|
|---|
| 150 |
|
|---|
| 151 | # GetPen and SetPt use a point-pointer as output-only:
|
|---|
| 152 | ('GetPen', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
|
|---|
| 153 | ('SetPt', [('Point', '*', 'OutMode')], [('*', '*', 'OutMode')]),
|
|---|
| 154 |
|
|---|
| 155 | # All others use it as input/output:
|
|---|
| 156 | ([('Point', '*', 'OutMode')],
|
|---|
| 157 | [('*', '*', 'InOutMode')]),
|
|---|
| 158 |
|
|---|
| 159 | # InsetRect, OffsetRect
|
|---|
| 160 | ([('Rect', 'r', 'OutMode'),
|
|---|
| 161 | ('short', 'dh', 'InMode'),
|
|---|
| 162 | ('short', 'dv', 'InMode')],
|
|---|
| 163 | [('Rect', 'r', 'InOutMode'),
|
|---|
| 164 | ('short', 'dh', 'InMode'),
|
|---|
| 165 | ('short', 'dv', 'InMode')]),
|
|---|
| 166 |
|
|---|
| 167 | # MapRect
|
|---|
| 168 | ([('Rect', 'r', 'OutMode'),
|
|---|
| 169 | ('Rect_ptr', 'srcRect', 'InMode'),
|
|---|
| 170 | ('Rect_ptr', 'dstRect', 'InMode')],
|
|---|
| 171 | [('Rect', 'r', 'InOutMode'),
|
|---|
| 172 | ('Rect_ptr', 'srcRect', 'InMode'),
|
|---|
| 173 | ('Rect_ptr', 'dstRect', 'InMode')]),
|
|---|
| 174 |
|
|---|
| 175 | # CopyBits and friends
|
|---|
| 176 | ([('RgnHandle', 'maskRgn', 'InMode')],
|
|---|
| 177 | [('OptRgnHandle', 'maskRgn', 'InMode')]),
|
|---|
| 178 |
|
|---|
| 179 | ('QDFlushPortBuffer',
|
|---|
| 180 | [('RgnHandle', '*', 'InMode')],
|
|---|
| 181 | [('OptRgnHandle', '*', 'InMode')]),
|
|---|
| 182 |
|
|---|
| 183 | # Accessors with reference argument also returned.
|
|---|
| 184 | ([('Rect_ptr', 'GetPortBounds', 'ReturnMode')],
|
|---|
| 185 | [('void', '*', 'ReturnMode')]),
|
|---|
| 186 |
|
|---|
| 187 | ([('RGBColor_ptr', 'GetPortForeColor', 'ReturnMode')],
|
|---|
| 188 | [('void', '*', 'ReturnMode')]),
|
|---|
| 189 |
|
|---|
| 190 | ([('RGBColor_ptr', 'GetPortBackColor', 'ReturnMode')],
|
|---|
| 191 | [('void', '*', 'ReturnMode')]),
|
|---|
| 192 |
|
|---|
| 193 | ([('RGBColor_ptr', 'GetPortOpColor', 'ReturnMode')],
|
|---|
| 194 | [('void', '*', 'ReturnMode')]),
|
|---|
| 195 |
|
|---|
| 196 | ([('RGBColor_ptr', 'GetPortHiliteColor', 'ReturnMode')],
|
|---|
| 197 | [('void', '*', 'ReturnMode')]),
|
|---|
| 198 |
|
|---|
| 199 | ([('Point_ptr', 'GetPortPenSize', 'ReturnMode')],
|
|---|
| 200 | [('void', '*', 'ReturnMode')]),
|
|---|
| 201 |
|
|---|
| 202 | ([('Point_ptr', 'GetPortPenLocation', 'ReturnMode')],
|
|---|
| 203 | [('void', '*', 'ReturnMode')]),
|
|---|
| 204 |
|
|---|
| 205 | ([('Rect_ptr', 'GetPixBounds', 'ReturnMode')],
|
|---|
| 206 | [('void', '*', 'ReturnMode')]),
|
|---|
| 207 |
|
|---|
| 208 | ([('BitMap_ptr', 'GetQDGlobalsScreenBits', 'ReturnMode')],
|
|---|
| 209 | [('void', '*', 'ReturnMode')]),
|
|---|
| 210 |
|
|---|
| 211 | ([('Cursor_ptr', 'GetQDGlobalsArrow', 'ReturnMode')],
|
|---|
| 212 | [('void', '*', 'ReturnMode')]),
|
|---|
| 213 |
|
|---|
| 214 | ([('Rect_ptr', 'GetRegionBounds', 'ReturnMode')],
|
|---|
| 215 | [('void', '*', 'ReturnMode')]),
|
|---|
| 216 |
|
|---|
| 217 | ([('Pattern_ptr', '*', 'ReturnMode')],
|
|---|
| 218 | [('void', '*', 'ReturnMode')]),
|
|---|
| 219 |
|
|---|
| 220 | ([('Point_ptr', 'QDLocalToGlobalPoint', 'ReturnMode')],
|
|---|
| 221 | [('void', '*', 'ReturnMode')]),
|
|---|
| 222 |
|
|---|
| 223 | ([('Rect_ptr', 'QDLocalToGlobalRect', 'ReturnMode')],
|
|---|
| 224 | [('void', '*', 'ReturnMode')]),
|
|---|
| 225 |
|
|---|
| 226 | ([('Point_ptr', 'QDGlobalToLocalPoint', 'ReturnMode')],
|
|---|
| 227 | [('void', '*', 'ReturnMode')]),
|
|---|
| 228 |
|
|---|
| 229 | ([('Rect_ptr', 'QDGlobalToLocalRect', 'ReturnMode')],
|
|---|
| 230 | [('void', '*', 'ReturnMode')]),
|
|---|
| 231 |
|
|---|
| 232 | ]
|
|---|
| 233 |
|
|---|
| 234 | if __name__ == "__main__":
|
|---|
| 235 | main()
|
|---|