parameters: (self, data)
return_statement: return header, ordt1, ordt2
docstring: read INDX header
docstring_summary: read INDX header
docstring_tokens: read INDX header
function: def parseHeader(self, data):
          "read INDX header"
          if not data[:4] == b'INDX':
              print("Warning: index section is not INDX")
              return False
          words = (
                  'len', 'nul1', 'type', 'gen', 'start', 'count', 'code',
                  'lng', 'total', 'ordt', 'ligt', 'nligt', 'nctoc'
          )
          num = len(words)
          values = struct.unpack(bstr('>%dL' % num), data[4:4*(num+1)])
          header = {}
          for n in range(num):
              header[words[n]] = values[n]
  
          ordt1 = None
          ordt2 = None
  
          otype, oentries, op1, op2, otagx  = struct.unpack_from(b'>LLLLL',data, 0xa4)
          header['otype'] = otype
          header['oentries'] = oentries
  
          if DEBUG_DICT:
              print("otype %d, oentries %d, op1 %d, op2 %d, otagx %d" % (otype, oentries, op1, op2, otagx))
  
          if header['code'] == 0xfdea or oentries > 0:
              # some dictionaries seem to be codepage 65002 (0xFDEA) which seems
              # to be some sort of strange EBCDIC utf-8 or 16 encoded strings
              # So we need to look for them and store them away to process leading text
              # ORDT1 has 1 byte long entries, ORDT2 has 2 byte long entries
              # we only ever seem to use the second but ...
              #
              # if otype = 0, ORDT table uses 16 bit values as offsets into the table
              # if otype = 1, ORDT table uses 8 bit values as offsets inot the table
  
              assert(data[op1:op1+4] == b'ORDT')
              assert(data[op2:op2+4] == b'ORDT')
              ordt1 = struct.unpack_from(bstr('>%dB' % oentries), data, op1+4)
              ordt2 = struct.unpack_from(bstr('>%dH' % oentries), data, op2+4)
  
          if DEBUG_DICT:
              print("parsed INDX header:")
              for key in header:
                  print(key, "%x" % header[key],)
              print("\n")
          return header, ordt1, ordt2
function_tokens: def parseHeader ( self , data ) : if not data [ : 4 ] == b'INDX' : print ( "Warning: index section is not INDX" ) return False words = ( 'len' , 'nul1' , 'type' , 'gen' , 'start' , 'count' , 'code' , 'lng' , 'total' , 'ordt' , 'ligt' , 'nligt' , 'nctoc' ) num = len ( words ) values = struct . unpack ( bstr ( '>%dL' % num ) , data [ 4 : 4 * ( num + 1 ) ] ) header = { } for n in range ( num ) : header [ words [ n ] ] = values [ n ] ordt1 = None ordt2 = None otype , oentries , op1 , op2 , otagx = struct . unpack_from ( b'>LLLLL' , data , 0xa4 ) header [ 'otype' ] = otype header [ 'oentries' ] = oentries if DEBUG_DICT : print ( "otype %d, oentries %d, op1 %d, op2 %d, otagx %d" % ( otype , oentries , op1 , op2 , otagx ) ) if header [ 'code' ] == 0xfdea or oentries > 0 : # some dictionaries seem to be codepage 65002 (0xFDEA) which seems # to be some sort of strange EBCDIC utf-8 or 16 encoded strings # So we need to look for them and store them away to process leading text # ORDT1 has 1 byte long entries, ORDT2 has 2 byte long entries # we only ever seem to use the second but ... # # if otype = 0, ORDT table uses 16 bit values as offsets into the table # if otype = 1, ORDT table uses 8 bit values as offsets inot the table assert ( data [ op1 : op1 + 4 ] == b'ORDT' ) assert ( data [ op2 : op2 + 4 ] == b'ORDT' ) ordt1 = struct . unpack_from ( bstr ( '>%dB' % oentries ) , data , op1 + 4 ) ordt2 = struct . unpack_from ( bstr ( '>%dH' % oentries ) , data , op2 + 4 ) if DEBUG_DICT : print ( "parsed INDX header:" ) for key in header : print ( key , "%x" % header [ key ] , ) print ( "\n" ) return header , ordt1 , ordt2