[ooo-build-commit] scratch/mso-dumper
Kohei Yoshida
kohei at kemper.freedesktop.org
Thu Dec 31 14:11:08 PST 2009
scratch/mso-dumper/src/formula.py | 10 +++--
scratch/mso-dumper/src/globals.py | 18 +++++++--
scratch/mso-dumper/src/xlsmodel.py | 1
scratch/mso-dumper/src/xlsrecord.py | 68 +++++++++++++++++++-----------------
4 files changed, 57 insertions(+), 40 deletions(-)
New commits:
commit d4986c4839a6846a88c9e84f9a1057a33c44f1d8
Author: Kohei Yoshida <kyoshida at novell.com>
Date: Thu Dec 31 17:10:12 2009 -0500
[xls-dump] Reworked SUPBOOK handler.
* scratch/mso-dumper/src/formula.py:
* scratch/mso-dumper/src/globals.py:
* scratch/mso-dumper/src/xlsmodel.py:
* scratch/mso-dumper/src/xlsrecord.py:
diff --git a/scratch/mso-dumper/src/formula.py b/scratch/mso-dumper/src/formula.py
index b1faa08..42fd82c 100644
--- a/scratch/mso-dumper/src/formula.py
+++ b/scratch/mso-dumper/src/formula.py
@@ -395,10 +395,12 @@ nested classes will be without the leading underscore (_)."""
def parse (self):
while not self.strm.isEndOfRecord():
b = self.strm.readUnsignedInt(1)
- if FormulaParser2.tokenMap.has_key(b):
- token = FormulaParser2.tokenMap[b](self.strm, b)
- token.parse()
- self.tokens.append(token)
+ if not FormulaParser2.tokenMap.has_key(b):
+ return
+
+ token = FormulaParser2.tokenMap[b](self.strm, b)
+ token.parse()
+ self.tokens.append(token)
def getText (self):
s = ''
diff --git a/scratch/mso-dumper/src/globals.py b/scratch/mso-dumper/src/globals.py
index dfd2293..0ae4959 100644
--- a/scratch/mso-dumper/src/globals.py
+++ b/scratch/mso-dumper/src/globals.py
@@ -81,6 +81,16 @@ class ByteStream(object):
bytes = self.readBytes(8)
return getDouble(bytes)
+ def moveBack (self, byteCount):
+ self.pos -= byteCount
+ if self.pos < 0:
+ self.pos = 0
+
+ def moveForward (self, byteCount):
+ self.pos += byteCount
+ if self.pos > self.size:
+ self.pos = self.size
+
def output (msg):
sys.stdout.write(msg)
@@ -119,10 +129,10 @@ def getUnicodeRichExtText (bytes):
flags = strm.readUnsignedInt(1)
# 0 0 0 0 0 0 0 0
# |-------|D|C|B|A|
- isDoubleByte = (flags & 0x01) == 1 # A
- ignored = ((flags/2) & 0x01) == 1 # B
- hasPhonetic = ((flags/4) & 0x01) == 1 # C
- isRichStr = ((flags/8) & 0x01) == 1 # D
+ isDoubleByte = (flags & 0x01) > 0 # A
+ ignored = (flags & 0x02) > 0 # B
+ hasPhonetic = (flags & 0x04) > 0 # C
+ isRichStr = (flags & 0x08) > 0 # D
numElem = 0
if isRichStr:
diff --git a/scratch/mso-dumper/src/xlsmodel.py b/scratch/mso-dumper/src/xlsmodel.py
index 538b7c6..feb7f70 100644
--- a/scratch/mso-dumper/src/xlsmodel.py
+++ b/scratch/mso-dumper/src/xlsmodel.py
@@ -84,6 +84,7 @@ class WorkbookGlobal(SheetBase):
self.__sheetData = []
self.__sharedStrings = []
+ self.__supbooks = []
def createDOM (self, wb):
nd = node.Element('workbook-global')
diff --git a/scratch/mso-dumper/src/xlsrecord.py b/scratch/mso-dumper/src/xlsrecord.py
index f8a52a7..4e6bf33 100644
--- a/scratch/mso-dumper/src/xlsrecord.py
+++ b/scratch/mso-dumper/src/xlsrecord.py
@@ -1070,45 +1070,49 @@ class Name(BaseRecordHandler):
class SupBook(BaseRecordHandler):
"""Supporting workbook"""
- def __parseSpecial (self):
- if self.bytes[2:4] == [0x01, 0x04]:
- # internal reference
- num = globals.getSignedInt(self.bytes[0:2])
- self.appendLine("sheet name count: %d (internal reference)"%num)
- elif self.bytes[0:4] == [0x00, 0x01, 0x01, 0x3A]:
- # add-in function
- self.appendLine("add-in function name stored in the following EXERNNAME record.")
-
- def __parseDDE (self):
- # not implemented yet.
- pass
+ class SBType:
+ Self = 0x0401
+ AddIn = 0x3A01
+
+ def __parseBytes (self):
+ self.ctab = self.readUnsignedInt(2)
+ self.sbType = self.readUnsignedInt(2)
+
+ if self.sbType > 0x00FF or self.sbType == 0x0000:
+ return
+
+ self.names = []
+ isFirst = True
+ self.moveBack(2)
+ pos = self.getCurrentPos()
+ while pos < self.size:
+ ret, bytesLen = globals.getUnicodeRichExtText(self.bytes[pos:])
+ name = ret.baseText
+ self.moveForward(bytesLen)
+ self.names.append(name)
+ pos = self.getCurrentPos()
def parseBytes (self):
- if self.size == 4:
- self.__parseSpecial()
+ self.__parseBytes()
+ if self.sbType == SupBook.SBType.Self:
+ # self-referencing supbook
+ self.appendLine("type: self-referencing")
+ self.appendLine("sheet name count: %d"%self.ctab)
return
- if self.bytes[0:2] == [0x00, 0x00]:
- self.__parseDDE()
+ if self.sbType == SupBook.SBType.AddIn:
+ self.appendLine("type: add-in referencing")
+ self.appendMultiLine("Add-in function name stored in the following EXTERNNAME record.")
return
- num = globals.getSignedInt(self.bytes[0:2])
- self.appendLine("sheet name count: %d"%num)
- i = 2
- isFirst = True
- while i < self.size:
- nameLen = globals.getSignedInt(self.bytes[i:i+2])
- i += 2
- flags = globals.getSignedInt(self.bytes[i:i+1])
- i += 1
- name = globals.getTextBytes(self.bytes[i:i+nameLen])
+ self.appendLine("sheet name count: %d"%self.ctab)
+ if len(self.names) == 0:
+ return
+
+ self.appendLine("document URL: %s"%globals.encodeName(self.names[0]))
+ for name in self.names[1:]:
name = globals.encodeName(name)
- i += nameLen
- if isFirst:
- isFirst = False
- self.appendLine("document URL: %s"%name)
- else:
- self.appendLine("sheet name: %s"%name)
+ self.appendLine("sheet name: %s"%name)
class ExternSheet(BaseRecordHandler):
More information about the ooo-build-commit
mailing list