Home | History | Annotate | Download | only in mlte
      1 # Scan an Apple header file, generating a Python file of generator calls.
      2 
      3 import sys
      4 from bgenlocations import TOOLBOXDIR, BGENDIR
      5 sys.path.append(BGENDIR)
      6 from scantools import Scanner_OSX
      7 
      8 LONG = "MacTextEditor"
      9 SHORT = "mlte"
     10 OBJECTS = ("TXNObject", "TXNFontMenuObject")
     11 # ADD object typenames here
     12 
     13 def main():
     14     input = "MacTextEditor.h"
     15     output = SHORT + "gen.py"
     16     defsoutput = TOOLBOXDIR + LONG + ".py"
     17     scanner = MyScanner(input, output, defsoutput)
     18     scanner.scan()
     19     scanner.gentypetest(SHORT+"typetest.py")
     20     scanner.close()
     21     print "=== Testing definitions output code ==="
     22     execfile(defsoutput, {}, {})
     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_OSX):
     28 
     29     def destination(self, type, name, arglist):
     30         classname = "Function"
     31         listname = "functions"
     32         if arglist:
     33             t, n, m = arglist[0]
     34             if t in OBJECTS and m == "InMode":
     35                 classname = "Method"
     36                 listname = t + "_methods"
     37         return classname, listname
     38 
     39     def writeinitialdefs(self):
     40         self.defsfile.write("""
     41 def FOUR_CHAR_CODE(x): return x
     42 false = 0
     43 true = 1
     44 kTXNClearThisControl = 0xFFFFFFFF
     45 kTXNClearTheseFontFeatures = 0x80000000
     46 kTXNDontCareTypeSize = 0xFFFFFFFF
     47 kTXNDecrementTypeSize = 0x80000000
     48 kTXNUseCurrentSelection = 0xFFFFFFFF
     49 kTXNStartOffset = 0
     50 kTXNEndOffset = 0x7FFFFFFF
     51 MovieFileType = FOUR_CHAR_CODE('moov')
     52 kTXNUseEncodingWordRulesMask = 0x80000000
     53 kTXNFontSizeAttributeSize = 4
     54 normal = 0
     55 """)
     56 
     57     def makeblacklistnames(self):
     58         return [
     59                 "TXNGetFontDefaults", # Arg is too difficult
     60                 "TXNSetFontDefaults", # Arg is too difficult
     61                 "TXNInitTextension", # done manually
     62 
     63                 # Constants with funny definitions
     64                 "kTXNClearThisControl",
     65                 "kTXNClearTheseFontFeatures",
     66                 "kTXNDontCareTypeSize",
     67                 "kTXNDecrementTypeSize",
     68                 "kTXNUseCurrentSelection",
     69                 "kTXNStartOffset",
     70                 "kTXNEndOffset",
     71                 "kTXNQDFontNameAttributeSize",
     72                 "kTXNQDFontFamilyIDAttributeSize",
     73                 "kTXNQDFontSizeAttributeSize",
     74                 "kTXNQDFontStyleAttributeSize",
     75                 "kTXNQDFontColorAttributeSize",
     76                 "kTXNTextEncodingAttributeSize",
     77                 "kTXNUseEncodingWordRulesMask",
     78                 "kTXNFontSizeAttributeSize",
     79                 "status",
     80                 "justification",
     81                 'TXNTSMCheck', # OS8
     82                 ]
     83 
     84     def makeblacklisttypes(self):
     85         return [
     86                 "TXNTab", # TBD
     87                 "TXNMargins", # TBD
     88                 "TXNControlData", #TBD
     89                 "TXNATSUIFeatures", #TBD
     90                 "TXNATSUIVariations", #TBD
     91                 "TXNAttributeData", #TBD
     92                 "TXNTypeAttributes", #TBD
     93                 "TXNMatchTextRecord", #TBD
     94                 "TXNBackground", #TBD
     95                 "TXNFindUPP",
     96                 "ATSUStyle", #TBD
     97                 "TXNBackground_ptr", #TBD
     98                 "TXNControlData_ptr", #TBD
     99                 "TXNControlTag_ptr", #TBD
    100                 "TXNLongRect", #TBD
    101                 "TXNLongRect_ptr", #TBD
    102                 "TXNTypeAttributes_ptr", #TBD
    103 
    104                 "TXNActionKeyMapperProcPtr",
    105                 "TXNActionKeyMapperUPP",
    106                 "TXNTextBoxOptionsData",
    107                 "TXNCountOptions",
    108                 "void_ptr",
    109                 ]
    110 
    111     def makerepairinstructions(self):
    112         return [
    113                 # TXNNewObject has a lot of optional parameters
    114                 ([("FSSpec_ptr", "iFileSpec", "InMode")],
    115                  [("OptFSSpecPtr", "*", "*")]),
    116                 ([("Rect", "iFrame", "OutMode")],
    117                  [("OptRectPtr", "*", "InMode")]),
    118 
    119                 # In UH 332 some of the "const" are missing for input parameters passed
    120                 # by reference. We fix that up here.
    121                 ([("EventRecord", "iEvent", "OutMode")],
    122                  [("EventRecord_ptr", "*", "InMode")]),
    123                 ([("FSSpec", "iFileSpecification", "OutMode")],
    124                  [("FSSpec_ptr", "*", "InMode")]),
    125                 ([("TXNMacOSPreferredFontDescription", "iFontDefaults", "OutMode")],
    126                  [("TXNMacOSPreferredFontDescription_ptr", "*", "InMode")]),
    127 
    128                 # In buffers are passed as void *
    129                 ([("void", "*", "OutMode"), ("ByteCount", "*", "InMode")],
    130                  [("MlteInBuffer", "*", "InMode")]),
    131 
    132                 # The AdjustCursor region handle is optional
    133                 ([("RgnHandle", "ioCursorRgn", "InMode")],
    134                  [("OptRgnHandle", "*", "*")]),
    135 
    136                 # The GWorld for TXNDraw is optional
    137                 ([('GWorldPtr', 'iDrawPort', 'InMode')],
    138                  [('OptGWorldPtr', '*', '*')]),
    139                 ]
    140 
    141 if __name__ == "__main__":
    142     main()
    143