Remove unneeded code
authorMichael Petch <mpetch@capp-sysware.com>
Mon, 30 Dec 2013 03:19:26 +0000 (20:19 -0700)
committerMichael Petch <mpetch@capp-sysware.com>
Mon, 30 Dec 2013 03:19:26 +0000 (20:19 -0700)
xgstruct.py

index b82048a..a3aca49 100755 (executable)
@@ -254,7 +254,6 @@ class HeaderMatchEntry(object):
     def __init__(self):
         self.name = 'MatchInfo'
         self.entrytype = GameFileRecord.ENTRYTYPE_HEADERMATCH
-        self.realrecsize = 0
         self.splayer1 = None
         self.splayer2 = None
         self.matchlength = 0
@@ -322,7 +321,6 @@ class HeaderMatchEntry(object):
         unpacked_data = _struct.unpack(
             '<9x41B41BxllBBBBddlld129BxxxlllBBB129BlB129BxxllLl2lBBB'
             'xllBxxxfflfll', stream.read(612))
-        self.realrecsize += 612
         self.splayer1 = _xgutils.delphishortstrtostr(unpacked_data[0:41])
         self.splayer2 = _xgutils.delphishortstrtostr(unpacked_data[41:82])
         self.matchlength = unpacked_data[82]
@@ -366,13 +364,11 @@ class HeaderMatchEntry(object):
         self.siteid = unpacked_data[505]
         if self.version >= 8:
             unpacked_data = _struct.unpack('<ll', stream.read(8))
-            self.realrecsize += 8
             self.cubelimit = unpacked_data[0]
             self.autodoublemax = unpacked_data[1]
         if self.version >= 24:
             unpacked_data = _struct.unpack('<Bx129H129H129H129H129H',
                                            stream.read(1292))
-            self.realrecsize += 1292
             self.transcribed = bool(unpacked_data[0])
             self.event = _xgutils.utf16intarraytostr(unpacked_data[1:130],
                                                      'utf-8')
@@ -386,17 +382,14 @@ class HeaderMatchEntry(object):
                                                      'utf-8')
         if self.version >= 25:
             self.timesetting = TimeSettingRecord().fromstream(stream)
-            self.realrecsize += self.timesetting.SIZEOFREC
         if self.version >= 26:
             unpacked_data = _struct.unpack('<llll', stream.read(16))
-            self.realrecsize += 16
             self.tottimedelaymove = unpacked_data[0]
             self.tottimedelaycube = unpacked_data[1]
             self.tottimedelaymovedone = unpacked_data[2]
             self.tottimedelaycubedone = unpacked_data[3]
         if self.version >= 30:
             unpacked_data = _struct.unpack('<129H', stream.read(258))
-            self.realrecsize += 258
             self.transcriber = _xgutils.utf16intarraytostr(
                 unpacked_data[0:129], 'utf-8')
 
@@ -447,7 +440,6 @@ class FooterGameEntry(object):
     def __init__(self):
         self.name = 'GameFooter'
         self.entrytype = GameFileRecord.ENTRYTYPE_FOOTERGAME
-        self.realrecsize = 0
         self.score1g = 0
         self.score2g = 0
         self.crawfordapplyg = False
@@ -467,7 +459,6 @@ class FooterGameEntry(object):
 
     def fromstream(self, stream):
         unpacked_data = _struct.unpack('<9xxxxllBxxxlllxxxxdd7dl', stream.read(116))
-        self.realrecsize += 116
         self.score1g = unpacked_data[0]
         self.score2g = unpacked_data[1]
         self.crawfordapplyg = bool(unpacked_data[2])
@@ -496,7 +487,6 @@ class MissingEntry(object):
     def __init__(self):
         self.name = 'Missing'
         self.entrytype = GameFileRecord.ENTRYTYPE_MISSING
-        self.realrecsize = 0
         self.missingerrluck = 0.0
         self.missingwinner = 0
         self.missingpoints = 0
@@ -509,7 +499,6 @@ class MissingEntry(object):
 
     def fromstream(self, stream):
         unpacked_data = _struct.unpack('<9xxxxxxxxdll', stream.read(32))
-        self.realrecsize += 32
         self.missingerrluck = unpacked_data[0]
         self.missingwinner = unpacked_data[1]
         self.missingpoints = unpacked_data[2]
@@ -528,7 +517,6 @@ class FooterMatchEntry(object):
     def __init__(self):
         self.name = 'MatchFooter'
         self.entrytype = GameFileRecord.ENTRYTYPE_FOOTERMATCH
-        self.realrecsize = 0
         self.score1m = 0
         self.score2m = 0
         self.winnerm = 0
@@ -546,7 +534,6 @@ class FooterMatchEntry(object):
 
     def fromstream(self, stream):
         unpacked_data = _struct.unpack('<9xxxxlllddlld', stream.read(56))
-        self.realrecsize += 56
         self.score1m = unpacked_data[0]
         self.score2m = unpacked_data[1]
         self.winnerm = unpacked_data[2]
@@ -572,7 +559,6 @@ class HeaderGameEntry(object):
     def __init__(self):
         self.name = 'GameHeader'
         self.entrytype = GameFileRecord.ENTRYTYPE_HEADERGAME
-        self.realrecsize = 0
         self.score1 = 0
         self.score2 = 0
         self.crawfordapply = False
@@ -591,7 +577,6 @@ class HeaderGameEntry(object):
 
     def fromstream(self, stream):
         unpacked_data = _struct.unpack('<9xxxxllB26bxlBxxxlll', stream.read(68))
-        self.realrecsize += 68
         self.score1 = unpacked_data[0]
         self.score2 = unpacked_data[1]
         self.crawfordapply = bool(unpacked_data[2])
@@ -621,7 +606,6 @@ class CubeEntry(object):
     def __init__(self):
         self.name = 'Cube'
         self.entrytype = GameFileRecord.ENTRYTYPE_HEADERMATCH
-        self.realrecsize = 0
         self.actifp = 0
         self.double = 0
         self.take = 0
@@ -662,7 +646,6 @@ class CubeEntry(object):
     def fromstream(self, stream):
         unpacked_data = _struct.unpack('<9xxxxllllll26bxx',
                                        stream.read(64))
-        self.realrecsize += 64
         self.actifp = unpacked_data[0]
         self.double = unpacked_data[1]
         self.take = unpacked_data[2]
@@ -671,11 +654,9 @@ class CubeEntry(object):
         self.cubeb = unpacked_data[5]
         self.position = unpacked_data[6:32]
         self.doubled = EngineStructDoubleAction().fromstream(stream)
-        self.realrecsize += self.doubled.SIZEOFREC
         unpacked_data = _struct.unpack('<xxxxd3Bxxxxxdlllxxxx' \
                                        'ddllbbxxxxxxddBxxxlBBBxlll',
                                        stream.read(116))
-        self.realrecsize += 116
         self.errcube = unpacked_data[0]
         self.dicerolled = _xgutils.delphishortstrtostr(unpacked_data[1:4]) 
         self.errtake = unpacked_data[4]
@@ -733,7 +714,6 @@ class MoveEntry(object):
     def __init__(self):
         self.name = 'Move'
         self.entrytype = GameFileRecord.ENTRYTYPE_MOVE
-        self.realrecsize = 0
         self.positioni = None
         self.positionend = None
         self.actifp = 0
@@ -772,7 +752,6 @@ class MoveEntry(object):
     def fromstream(self, stream):
         unpacked_data = _struct.unpack('<9x26b26bxxxl8l2lldl',
                                        stream.read(124))
-        self.realrecsize += 124
         self.positioni = unpacked_data[0:26]
         self.positionend = unpacked_data[26:52]
         self.actifp = unpacked_data[52]
@@ -782,11 +761,9 @@ class MoveEntry(object):
         self.errorm = unpacked_data[64] # Not used
         self.nmoveeval = unpacked_data[65]
         self.datamoves = EngineStructBestMoveRecord().fromstream(stream)
-        self.realrecsize += self.datamoves.SIZEOFREC
 
         unpacked_data = _struct.unpack('<Bxxxddlxxxxd32llll26bbxdBxxxl',
                                        stream.read(220))
-        self.realrecsize += 220
         self.played = bool(unpacked_data[0])
         self.errmove = unpacked_data[1]
         self.errluck = unpacked_data[2]
@@ -804,19 +781,15 @@ class MoveEntry(object):
         if self.version >= 24:
             unpacked_data = _struct.unpack('<B', stream.read(1))
             self.editedmove = bool(unpacked_data[0])
-            self.realrecsize += 1
         if self.version >= 26:
             unpacked_data = _struct.unpack('<xxxLL', stream.read(11))
             self.timedelaymove = unpacked_data[0]
             self.timedelaymovedone = unpacked_data[1]
-            self.realrecsize += 11
         if self.version >= 27:
             unpacked_data = _struct.unpack('<l', stream.read(4))
             self.numberofautodoublemove = unpacked_data[0]
-            self.realrecsize += 4
         unpacked_data = _struct.unpack('<4l', stream.read(16))
         self.filler = unpacked_data
-        self.realrecsize += 16
         
         return self
 
@@ -849,7 +822,6 @@ class UnimplementedEntry(object):
 
     def fromstream(self, stream):
         self.name = 'Unimplemented'
-        self.realrecsize = 0
         return self
 
     def todict(self):
@@ -888,6 +860,7 @@ class GameFileRecord(object):
         # Read the header. First 8 bytes are unused. 9th byte is record type
         # The record type determines what object to create and load.
         # If we catch a struct.error we have hit the EOF.
+        startpos = stream.tell()
         try:
             unpacked_data = _struct.unpack('<8xB', 
                                            stream.read(self.__SIZEOFSRHDR))
@@ -904,11 +877,11 @@ class GameFileRecord(object):
         self.record = self.__REC_CLASSES[self.entrytype]()
         self.record.version = self.version
         self.record.fromstream(stream)
+        realrecsize = stream.tell() - startpos
 
         # Each record is actually 2560 bytes long. We need to advance past
         # the unused filler data to be at the start of the next record
-        stream.seek(self.record.SIZEOFREC - self.record.realrecsize, 
-                    _os.SEEK_CUR)
+        stream.seek(self.record.SIZEOFREC - realrecsize, _os.SEEK_CUR)
 
         return self.record
 
@@ -923,7 +896,6 @@ class RolloutContextEntry(object):
     def __init__(self):
         self.name = 'Rollout'
         self.entrytype = RolloutFileRecord.ROLLOUTCONTEXT
-        self.realrecsize = 0
         self.truncated = False
         self.errorlimited = False
         self.truncate = 0
@@ -989,10 +961,9 @@ class RolloutContextEntry(object):
 
     def fromstream(self, stream):
         unpacked_data = _struct.unpack('<BBxxllxxxxdllllBBBxllLlllBxxx' \
-                                       'flBBBxlBxxxxxxx37d37d37d37d37d37d37lff7f7fff' \
-                                       'l7fllllllBBxxffBxxxlBxHH',
+                                       'flBBBxlBxxxxxxx37d37d37d37d37d37d37l' \
+                                       'ff7f7fffl7fllllllBBxxffBxxxlBxHH',
                                        stream.read(2174))
-        self.realrecsize += 2174
         self.truncated = unpacked_data[0] # bool
         self.errorlimited = unpacked_data[1] # bool
         self.truncate = unpacked_data[2]
@@ -1111,16 +1082,16 @@ class RolloutFileRecord(object):
         if stream.read(1) == '':
             return None
         stream.seek(-1, _os.SEEK_CUR)
+        startpos = stream.tell()
 
         # Using the appropriate class, read the data stream 
         self.record = RolloutContextEntry()
         self.record.version = self.version
         self.record.fromstream(stream)
-
+        realrecsize = stream.tell() - startpos
         # Each record is actually 2184 bytes long. We need to advance past
         # the unused filler data to be at the start of the next record
-        stream.seek(self.record.SIZEOFREC - self.record.realrecsize, 
-                    _os.SEEK_CUR)
+        stream.seek(self.record.SIZEOFREC - realrecsize, _os.SEEK_CUR)
 
         return self.record