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



Author: kyoshida
Date: Thu Jan 24 17:30:51 2008
New Revision: 11409
URL: http://svn.gnome.org/viewvc/ooo-build?rev=11409&view=rev

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

	* scratch/sc-xlsutil/src/stream.py:
	* scratch/sc-xlsutil/xls_dump.py: parse records in the 'Revision Log'
	directory stream.


Modified:
   trunk/ChangeLog
   trunk/scratch/sc-xlsutil/src/stream.py
   trunk/scratch/sc-xlsutil/xls_dump.py

Modified: trunk/scratch/sc-xlsutil/src/stream.py
==============================================================================
--- trunk/scratch/sc-xlsutil/src/stream.py	(original)
+++ trunk/scratch/sc-xlsutil/src/stream.py	Thu Jan 24 17:30:51 2008
@@ -3,6 +3,11 @@
 import ole, globals
 from globals import output
 
+class EndOfStream(Exception): 
+    def __init__ (self):
+        pass
+
+
 recData = {
     0x0006: ["FORMULA", "Formula Token Array and Result"],
     0x000A: ["EOF", "End of File"],
@@ -294,9 +299,15 @@
         print(prefix + c*w)
 
     def readRecord (self):
+        if self.size - self.pos < 4:
+            raise EndOfStream
+
         pos = self.pos
         header = self.readRaw(2)
+        if header == 0x0000:
+            raise EndOfStream
         size = self.readRaw(2)
+
         print("")
         self.__printSep('=', 61, "%4.4Xh: "%header)
         if recData.has_key(header):

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 24 17:30:51 2008
@@ -9,6 +9,14 @@
     def __init__ (self, filepath):
         self.filepath = filepath
 
+    def __printDirHeader (self, dirname, byteLen):
+        if ord(dirname[0]) <= 5:
+            dirname = "<%2.2Xh>%s"%(ord(dirname[0]), dirname[1:])
+        print("")
+        print("="*68)
+        print("%s (size: %d bytes)"%(dirname, byteLen))
+        print("-"*68)
+
     def dump (self):
         file = open(self.filepath, 'rb')
         strm = stream.XLStream(file.read())
@@ -25,21 +33,23 @@
                 continue
 
             dirstrm = strm.getDirectoryStreamByName(dirname)
+            self.__printDirHeader(dirname, len(dirstrm.bytes))
             if dirname == "Workbook":
                 success = True
                 while success: 
-                    success = self.__read(dirstrm)
+                    success = self.__readSheetSubStream(dirstrm)
+            elif dirname == "Revision Log":
+                try:
+                    header = 0x0000
+                    while header != 0x000A:
+                        header = dirstrm.readRecord()
+                except stream.EndOfStream:
+                    continue
             else:
-                if ord(dirname[0]) <= 5:
-                    dirname = "<%2.2Xh>%s"%(ord(dirname[0]), dirname[1:])
-                print("")
-                print("="*68)
-                print("%s (size: %d bytes)"%(dirname, len(dirstrm.bytes)))
-                print("-"*68)
                 globals.dumpBytes(dirstrm.bytes, 512)
 
 
-    def __read (self, strm):
+    def __readSheetSubStream (self, strm):
         # read bytes from BOF to EOF.
         strm.seekBOF()
         try:
@@ -48,7 +58,7 @@
                 header = strm.readRecord()
             return True
 
-        except IndexError:
+        except stream.EndOfStream:
             return False
 
 def usage ():



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