ooo-build r11477 - in trunk: . scratch/sc-xlsutil scratch/sc-xlsutil/src



Author: kyoshida
Date: Thu Jan 31 06:07:50 2008
New Revision: 11477
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11477&view=rev

Log:
2008-01-31  Kohei Yoshida  <kyoshida novell com>

	* scratch/sc-xlsutil/src/formula.py:
	* scratch/sc-xlsutil/src/globals.py:
	* scratch/sc-xlsutil/src/ole.py:
	* scratch/sc-xlsutil/src/record.py:
	* scratch/sc-xlsutil/xls_dump.py: more fixes & handling of large files
	with additional MSAT sectors.


Modified:
   trunk/ChangeLog
   trunk/scratch/sc-xlsutil/src/formula.py
   trunk/scratch/sc-xlsutil/src/globals.py
   trunk/scratch/sc-xlsutil/src/ole.py
   trunk/scratch/sc-xlsutil/src/record.py
   trunk/scratch/sc-xlsutil/xls_dump.py

Modified: trunk/scratch/sc-xlsutil/src/formula.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/formula.py	(original)
+++ trunk/scratch/sc-xlsutil/src/formula.py	Thu Jan 31 06:07:50 2008
@@ -6,6 +6,7 @@
 
 def toColName (colID):
     if colID > 255:
+        globals.error("Column ID greater than 255")
         raise InvalidCellAddress
     n1 = colID % 26
     n2 = int(colID/26)
@@ -43,6 +44,7 @@
 
 def parseCellAddress (bytes):
     if len(bytes) != 4:
+        globals.error("Byte size is %d but expected 4 bytes for cell address.\n"%len(bytes))
         raise InvalidCellAddress
 
     row = globals.getSignedInt(bytes[0:2])
@@ -87,6 +89,7 @@
 """
     def __init__ (self, tokens):
         self.tokens = tokens
+        self.size = len(self.tokens)
 
     def parse (self, i):
         return i
@@ -132,15 +135,24 @@
 class Ref3d(TokenBase):
     """3D reference or external reference to a cell"""
 
+    def __init__ (self, tokens):
+        TokenBase.__init__(self, tokens)
+        self.cell = None
+
     def parse (self, i):
-        i += 1
-        self.refEntryId = globals.getSignedInt(self.tokens[i:i+2])
-        i += 2
-        self.cell = parseCellAddress(self.tokens[i:i+4])
-        i += 4
+        try:
+            i += 1
+            self.refEntryId = globals.getSignedInt(self.tokens[i:i+2])
+            i += 2
+            self.cell = parseCellAddress(self.tokens[i:i+4])
+            i += 4
+        except InvalidCellAddress:
+            pass
         return i
 
     def getText (self):
+        if self.cell == None:
+            return ''
         cellName = self.cell.getName()
         return "<3dref externSheetID='%d' cellAddress='%s'>"%(self.refEntryId, cellName)
 
@@ -178,7 +190,7 @@
     0x7A: Ref3d,
 
     # last item
-    0xFF: None
+  0xFFFF: None
 }
 
 class FormulaParser(object):

Modified: trunk/scratch/sc-xlsutil/src/globals.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/globals.py	(original)
+++ trunk/scratch/sc-xlsutil/src/globals.py	Thu Jan 31 06:07:50 2008
@@ -6,14 +6,15 @@
 
 class Params(object):
     def __init__ (self):
-        self.Debug = False
+        self.debug = False
+        self.showSectorChain = False
 
 
 def output (msg):
     sys.stdout.write(msg)
 
 def error (msg):
-    sys.stderr.write(msg)
+    sys.stderr.write("Error: " + msg)
 
 
 def decodeName (name):
@@ -22,7 +23,7 @@
     if len(name) == 0:
         return name
 
-    if ord(name[0]) <= 5:
+    if ord(name[0]) <= 20:
         name = "<%2.2Xh>"%ord(name[0]) + name[1:]
 
     return name

Modified: trunk/scratch/sc-xlsutil/src/ole.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/ole.py	(original)
+++ trunk/scratch/sc-xlsutil/src/ole.py	Thu Jan 31 06:07:50 2008
@@ -17,7 +17,7 @@
     BigEndian    = 1
     Unknown      = 2
 
-class SectorType:
+class BlockType:
     MSAT      = 0
     SAT       = 1
     SSAT      = 2
@@ -72,12 +72,12 @@
         return 2**self.secSizeShort
 
 
-    def getFirstSectorID (self, sectorType):
-        if sectorType == SectorType.MSAT:
+    def getFirstSectorID (self, blockType):
+        if blockType == BlockType.MSAT:
             return self.__secIDFirstMSAT
-        elif sectorType == SectorType.SSAT:
+        elif blockType == BlockType.SSAT:
             return self.__secIDFirstSSAT
-        elif sectorType == SectorType.Directory:
+        elif blockType == BlockType.Directory:
             return self.__secIDFirstDirStrm
         return -2
 
@@ -96,7 +96,7 @@
         print("Compound Document Header")
         printSep('-', 68)
 
-        if self.params.Debug:
+        if self.params.debug:
             globals.dumpBytes(self.bytes[0:512])
             printSep('-', 68)
 
@@ -145,7 +145,7 @@
             print("Sector ID of the first MSAT sector: [end of chain]")
         else:
             # There is more sector IDs than 109 IDs stored in the header.
-            print("Sector ID of the first MSAT sector: %d"%(512+self.__secIDFirstMSAT*(2**self.secSize)))
+            print("Sector ID of the first MSAT sector: %d"%(self.__secIDFirstMSAT))
 
         print("Total number of sectors used to store additional MSAT: %d"%self.numSecMSAT)
 
@@ -193,7 +193,29 @@
 
             self.MSAT.appendSectorID(id)
 
-        return 512
+        if self.__secIDFirstMSAT != -2:
+            # additional sectors are used to store more SAT sector IDs.
+            secID = self.__secIDFirstMSAT
+            size = self.getSectorSize()
+            inLoop = True
+            while inLoop:
+                pos = 512 + secID*size
+                bytes = self.bytes[pos:pos+size]
+                n = int(size/4)
+                for i in xrange(0, n):
+                    pos = i*4
+                    id = getSignedInt(bytes[pos:pos+4])
+                    if id < 0:
+                        inLoop = False
+                        break
+                    elif i == n-1:
+                        # last sector ID - points to the next MSAT sector.
+                        secID = id
+                        break
+                    else:
+                        self.MSAT.appendSectorID(id)
+
+        return 512 
 
 
     def getMSAT (self):
@@ -205,7 +227,7 @@
 
 
     def getSSAT (self):
-        ssatID = self.getFirstSectorID(SectorType.SSAT)
+        ssatID = self.getFirstSectorID(BlockType.SSAT)
         if ssatID < 0:
             return None
         chain = self.getSAT().getSectorIDChain(ssatID)
@@ -219,7 +241,7 @@
 
 
     def getDirectory (self):
-        dirID = self.getFirstSectorID(SectorType.Directory)
+        dirID = self.getFirstSectorID(BlockType.Directory)
         if dirID < 0:
             return None
         chain = self.getSAT().getSectorIDChain(dirID)
@@ -367,7 +389,7 @@
         print("="*68)
         print("Sector Allocation Table (SAT)")
         print("-"*68)
-        if self.params.Debug:
+        if self.params.debug:
             self.outputRawBytes()
             print("-"*68)
             for i in xrange(0, len(self.array)):
@@ -405,7 +427,7 @@
         print("="*68)
         print("Short Sector Allocation Table (SSAT)")
         print("-"*68)
-        if self.params.Debug:
+        if self.params.debug:
             self.outputRawBytes()
             print("-"*68)
             for i in xrange(0, len(self.array)):
@@ -555,7 +577,7 @@
         else:
             print("name: [empty]   (name buffer size: %d bytes)"%entry.CharBufferSize)
 
-        if self.params.Debug:
+        if self.params.debug:
             print("-"*68)
             globals.dumpBytes(entry.bytes)
             print("-"*68)
@@ -614,8 +636,8 @@
                 chain = satObj.getSectorIDChain(entry.StreamSectorID)
                 print("sector count: %d"%len(chain))
                 print("total sector size: %d"%(len(chain)*secSize))
-                self.__outputSectorChain(chain)
-
+                if self.params.showSectorChain:
+                    self.__outputSectorChain(chain)
 
 
     def __outputSectorChain (self, chain):

Modified: trunk/scratch/sc-xlsutil/src/record.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/record.py	(original)
+++ trunk/scratch/sc-xlsutil/src/record.py	Thu Jan 31 06:07:50 2008
@@ -235,6 +235,7 @@
         statTextLen = self.__getInt(13, 1)
 
         name, byteLen = globals.getRichText(self.bytes[14:], nameLen)
+        name = globals.decodeName(name)
         tokenPos = 14 + byteLen
         tokenText = globals.getRawBytes(self.bytes[tokenPos:tokenPos+formulaLen], True, False)
         o = formula.FormulaParser(self.bytes[tokenPos:tokenPos+formulaLen], False)

Modified: trunk/scratch/sc-xlsutil/xls_dump.py
==============================================================================
--- trunk/scratch/sc-xlsutil/xls_dump.py	(original)
+++ trunk/scratch/sc-xlsutil/xls_dump.py	Thu Jan 31 06:07:50 2008
@@ -84,13 +84,15 @@
 
     params = globals.Params()
     try:
-        opts, args = getopt.getopt(args, "h", ["help", "debug"])
+        opts, args = getopt.getopt(args, "h", ["help", "debug", "show-sector-chain"])
         for opt, arg in opts:
             if opt in ['-h', '--help']:
                 usage(exname)
                 return
             elif opt in ['--debug']:
-                params.Debug = True
+                params.debug = True
+            elif opt in ['--show-sector-chain']:
+                params.showSectorChain = True
             else:
                 error("unknown option %s\n"%opt)
                 usage()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]