[ooo-build-commit] scratch/mso-dumper

Kohei Yoshida kohei at kemper.freedesktop.org
Thu Dec 31 10:29:31 PST 2009


 scratch/mso-dumper/ppt-dump.py      |    2 
 scratch/mso-dumper/src/globals.py   |   17 ++++-
 scratch/mso-dumper/src/xlsrecord.py |  107 +++++++++++++++++++-----------------
 scratch/mso-dumper/xls-dump.py      |    2 
 4 files changed, 73 insertions(+), 55 deletions(-)

New commits:
commit 6fa0393a904e8ae5e21e0607bd1bfe6901348205
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Dec 31 13:28:00 2009 -0500

    [xls-dump] Refactored xlsrecord.Name.
    
    Also changed name of global function decodeName() to encodeName(),
    since what it does is actually encoding, not decoding.
    
    * scratch/mso-dumper/ppt-dump.py:
    * scratch/mso-dumper/src/globals.py:
    * scratch/mso-dumper/src/xlsrecord.py:
    * scratch/mso-dumper/xls-dump.py:

diff --git a/scratch/mso-dumper/ppt-dump.py b/scratch/mso-dumper/ppt-dump.py
index 445c08f..25d0a31 100755
--- a/scratch/mso-dumper/ppt-dump.py
+++ b/scratch/mso-dumper/ppt-dump.py
@@ -37,7 +37,7 @@ class PPTDumper(object):
         self.params = params
 
     def __printDirHeader (self, dirname, byteLen):
-        dirname = globals.decodeName(dirname)
+        dirname = globals.encodeName(dirname)
         print("")
         print("="*68)
         print("%s (size: %d bytes)"%(dirname, byteLen))
diff --git a/scratch/mso-dumper/src/globals.py b/scratch/mso-dumper/src/globals.py
index 8c9dcf0..dfd2293 100644
--- a/scratch/mso-dumper/src/globals.py
+++ b/scratch/mso-dumper/src/globals.py
@@ -89,8 +89,8 @@ def error (msg):
     sys.stderr.write("Error: " + msg)
 
 
-def decodeName (name):
-    """decode name that contains unprintable characters."""
+def encodeName (name):
+    """Encode name that contains unprintable characters."""
 
     n = len(name)
     if n == 0:
@@ -99,7 +99,7 @@ def decodeName (name):
     newname = ''
     for i in xrange(0, n):
         if ord(name[i]) <= 20:
-            newname += "<%2.2Xh>"%ord(name[i])
+            newname += "\\x%2.2X"%ord(name[i])
         else:
             newname += name[i]
 
@@ -154,7 +154,16 @@ def getUnicodeRichExtText (bytes):
 
 
 def getRichText (bytes, textLen=None):
-    """parse a string of the rich-text format that Excel uses."""
+    """parse a string of the rich-text format that Excel uses.
+
+Note the following:
+
+  * The 1st byte always contains flag.
+  * The actual number of bytes read may differ depending on the values of the 
+    flags, so the client code should pass an open-ended stream of bytes and 
+    always query for the actual bytes read to adjust for the new stream 
+    position when this function returns.
+"""
 
     strm = ByteStream(bytes)
     flags = strm.readUnsignedInt(1)
diff --git a/scratch/mso-dumper/src/xlsrecord.py b/scratch/mso-dumper/src/xlsrecord.py
index ca5f474..2485041 100644
--- a/scratch/mso-dumper/src/xlsrecord.py
+++ b/scratch/mso-dumper/src/xlsrecord.py
@@ -927,30 +927,19 @@ class Row(BaseRecordHandler):
 class Name(BaseRecordHandler):
     """internal defined name"""
 
-    def __getInt (self, offset, size):
-        return globals.getSignedInt(self.bytes[offset:offset+size])
-
-    def __parseOptionFlags (self, flags):
+    def __writeOptionFlags (self):
         self.appendLine("option flags:")
-        isHidden       = (flags & 0x0001) != 0
-        isFuncMacro    = (flags & 0x0002) != 0
-        isVBMacro      = (flags & 0x0004) != 0
-        isMacroName    = (flags & 0x0008) != 0
-        isComplFormula = (flags & 0x0010) != 0
-        isBuiltinName  = (flags & 0x0020) != 0
-        funcGrp        = (flags & 0x0FC0) / 64
-        isBinary       = (flags & 0x1000) != 0
-
-        if isHidden:
+
+        if self.isHidden:
             self.appendLine("  hidden")
         else:
             self.appendLine("  visible")
 
-        if isMacroName:
+        if self.isMacroName:
             self.appendLine("  macro name")
-            if isFuncMacro:
+            if self.isFuncMacro:
                 self.appendLine("  function macro")
-                self.appendLine("  function group: %d"%funcGrp)
+                self.appendLine("  function group: %d"%self.funcGrp)
             else:
                 self.appendLine("  command macro")
             if isVBMacro:
@@ -960,51 +949,71 @@ class Name(BaseRecordHandler):
         else:
             self.appendLine("  standard name")
 
-        if isComplFormula:
+        if self.isComplFormula:
             self.appendLine("  complex formula")
         else:
             self.appendLine("  simple formula")
-        if isBuiltinName:
+        if self.isBuiltinName:
             self.appendLine("  built-in name")
         else:
             self.appendLine("  user-defined name")
-        if isBinary:
+        if self.isBinary:
             self.appendLine("  binary data")
         else:
             self.appendLine("  formula definition")
 
+    def __parseBytes (self):
+        flag = self.readUnsignedInt(2)
+        self.isHidden       = (flag & 0x0001) != 0
+        self.isFuncMacro    = (flag & 0x0002) != 0
+        self.isVBMacro      = (flag & 0x0004) != 0
+        self.isMacroName    = (flag & 0x0008) != 0
+        self.isComplFormula = (flag & 0x0010) != 0
+        self.isBuiltinName  = (flag & 0x0020) != 0
+        self.funcGrp        = (flag & 0x0FC0) / 64
+        self.isBinary       = (flag & 0x1000) != 0
+
+        self.keyShortCut      = self.readUnsignedInt(1)
+        nameLen               = self.readUnsignedInt(1)
+        self.formulaLen       = self.readUnsignedInt(2)
+        self.localNameSheetId = self.readUnsignedInt(2)
+        # 1-based index into the sheets in the current book, where the list is
+        # arranged by the visible order of the tabs.
+        self.sheetId          = self.readUnsignedInt(2) 
 
-    def parseBytes (self):
-        optionFlags = self.__getInt(0, 2)
+        # these optional texts may come after the formula token bytes.
+        self.menuTextLen = self.readUnsignedInt(1)
+        self.descTextLen = self.readUnsignedInt(1)
+        self.helpTextLen = self.readUnsignedInt(1)
+        self.statTextLen = self.readUnsignedInt(1)
+        pos = self.getCurrentPos()
+        self.name, byteLen = globals.getRichText(self.bytes[pos:], nameLen)
+        self.readBytes(byteLen)
+        self.name = globals.encodeName(self.name)
+        self.tokenBytes = self.readBytes(self.formulaLen)
 
-        keyShortCut = self.__getInt(2, 1)
-        nameLen     = self.__getInt(3, 1)
-        formulaLen  = self.__getInt(4, 2)
-        sheetId     = self.__getInt(8, 2)
+    def parseBytes (self):
+        self.__parseBytes()
 
-        # these optional texts may come after the formula token bytes.
-        menuTextLen = self.__getInt(10, 1)
-        descTextLen = self.__getInt(11, 1)
-        helpTextLen = self.__getInt(12, 1)
-        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.header, self.bytes[tokenPos:tokenPos+formulaLen], False)
+        tokenText = globals.getRawBytes(self.tokenBytes, True, False)
+        o = formula.FormulaParser(self.header, self.tokenBytes, False)
         o.parse()
-        self.appendLine("name: %s"%name)
-        self.__parseOptionFlags(optionFlags)
-
-        self.appendLine("sheet ID: %d"%sheetId)
-        self.appendLine("menu text length: %d"%menuTextLen)
-        self.appendLine("description length: %d"%descTextLen)
-        self.appendLine("help tip text length: %d"%helpTextLen)
-        self.appendLine("status bar text length: %d"%statTextLen)
-        self.appendLine("formula length: %d"%formulaLen)
+        formulaText = o.getText()
+        self.appendLine("name: %s"%self.name)
+        self.__writeOptionFlags()
+
+        self.appendLine("sheet ID: %d"%self.sheetId)
+        self.appendLine("menu text length: %d"%self.menuTextLen)
+        self.appendLine("description length: %d"%self.descTextLen)
+        self.appendLine("help tip text length: %d"%self.helpTextLen)
+        self.appendLine("status bar text length: %d"%self.statTextLen)
+        self.appendLine("formula length: %d"%self.formulaLen)
         self.appendLine("formula bytes: " + tokenText)
-        self.appendLine("formula: " + o.getText())
+        self.appendLine("formula: " + formulaText)
+
+    def fillModel (self, model):
+        self.__parseBytes()
+        
 
 
 
@@ -1043,7 +1052,7 @@ class SupBook(BaseRecordHandler):
             flags = globals.getSignedInt(self.bytes[i:i+1])
             i += 1
             name = globals.getTextBytes(self.bytes[i:i+nameLen])
-            name = globals.decodeName(name)
+            name = globals.encodeName(name)
             i += nameLen
             if isFirst:
                 isFirst = False
@@ -1147,7 +1156,7 @@ class Crn(BaseRecordHandler):
                 # string
                 text, length = globals.getRichText(self.bytes[i:])
                 i += length
-                text = globals.decodeName(text)
+                text = globals.encodeName(text)
                 self.appendLine("* string value (%s)"%text)
             elif typeId == 0x04:
                 # boolean
diff --git a/scratch/mso-dumper/xls-dump.py b/scratch/mso-dumper/xls-dump.py
index 63c2672..71c2874 100755
--- a/scratch/mso-dumper/xls-dump.py
+++ b/scratch/mso-dumper/xls-dump.py
@@ -15,7 +15,7 @@ class XLDumper(object):
         self.strmData = None
 
     def __printDirHeader (self, dirname, byteLen):
-        dirname = globals.decodeName(dirname)
+        dirname = globals.encodeName(dirname)
         print("")
         print("="*68)
         print("%s (size: %d bytes)"%(dirname, byteLen))


More information about the ooo-build-commit mailing list