[gnumeric] Excel: improve debug stuff.



commit bfd1d7dc9546f25d0041d91a51be48b3f3cbc8c5
Author: Morten Welinder <terra gnome org>
Date:   Thu Jan 6 10:34:05 2011 -0500

    Excel: improve debug stuff.

 plugins/excel/.gitignore      |    1 +
 plugins/excel/Makefile.am     |    8 ++++++++
 plugins/excel/biff-types.h    |    2 ++
 plugins/excel/ms-excel-read.c |   16 +++++++++++++---
 tools/ChangeLog               |    4 ++++
 tools/Makefile.am             |    3 ++-
 tools/biffnames               |   33 +++++++++++++++++++++++++++++++++
 7 files changed, 63 insertions(+), 4 deletions(-)
---
diff --git a/plugins/excel/.gitignore b/plugins/excel/.gitignore
index 6429675..cafa7e6 100644
--- a/plugins/excel/.gitignore
+++ b/plugins/excel/.gitignore
@@ -7,3 +7,4 @@ Makefile.in
 plugin.xml
 *.loT
 *.sw*
+biff-types.c
diff --git a/plugins/excel/Makefile.am b/plugins/excel/Makefile.am
index b6fa9d5..97691bb 100644
--- a/plugins/excel/Makefile.am
+++ b/plugins/excel/Makefile.am
@@ -3,6 +3,9 @@ AM_CPPFLAGS = \
     -I$(top_srcdir)/src	-I$(top_builddir)/src		\
     $(GNUMERIC_CFLAGS) $(Z_CPPFLAGS)
 
+BUILT_SOURCES =					\
+	biff-types.c
+
 gnumeric_plugin_exceldir = $(gnumeric_plugindir)/excel
 xmldir = $(gnumeric_plugin_exceldir)
 gnumeric_plugin_excel_LTLIBRARIES = excel.la
@@ -27,6 +30,7 @@ excel_la_SOURCES =		\
 	ms-excel-biff.h		\
 	ms-biff.c		\
 	ms-biff.h		\
+	biff-types.c		\
 	biff-types.h		\
 	escher-types.h		\
 	ms-container.c		\
@@ -65,6 +69,10 @@ excel_la_SOURCES =		\
 	xlsx-read.c		\
 	xlsx-write.c
 
+biff-types.c: biff-types.h $(top_srcdir)/tools/biffnames
+	$(PERL) $(top_srcdir)/tools/biffnames <$< >$  tmp
+	mv $  tmp $@
+
 xml_in_files = plugin.xml.in
 xml_DATA = $(xml_in_files:.xml.in=.xml)
 
diff --git a/plugins/excel/biff-types.h b/plugins/excel/biff-types.h
index 432dd06..d758e24 100644
--- a/plugins/excel/biff-types.h
+++ b/plugins/excel/biff-types.h
@@ -13,6 +13,8 @@
  * (C) 2002-2005 Jody Goldberg
  */
 
+const char *biff_opcode_name (unsigned int opcode);
+
 #define BIFF_DIMENSIONS_v0		0x000
 #define BIFF_DIMENSIONS_v2			0x200
 #define BIFF_BLANK_v0			0x001
diff --git a/plugins/excel/ms-excel-read.c b/plugins/excel/ms-excel-read.c
index cc22460..0d60e52 100644
--- a/plugins/excel/ms-excel-read.c
+++ b/plugins/excel/ms-excel-read.c
@@ -4334,7 +4334,7 @@ excel_read_GUTS (BiffQuery *q, ExcelReadSheet *esheet)
 	if (row_gut >= 1)
 		row_gut--;
 	col_gut = GSF_LE_GET_GUINT16 (q->data + 6);
-	d (2, g_printerr ("col_gut = %d", col_gut););
+	d (2, g_printerr ("col_gut = %d\n", col_gut););
 	if (col_gut >= 1)
 		col_gut--;
 	sheet_colrow_gutter (esheet->sheet, TRUE, col_gut);
@@ -6343,7 +6343,12 @@ excel_read_sheet (BiffQuery *q, GnmXLImporter *importer,
 	for (; ms_biff_query_next (q) ;
 	     go_io_value_progress_update (importer->context, q->streamPos)) {
 
-		d (5, g_printerr ("Opcode: 0x%x\n", q->opcode););
+		d (5, {
+			const char *opname = biff_opcode_name (q->opcode);
+			g_printerr ("Opcode: 0x%x %s\n",
+				    q->opcode,
+				    opname ? opname : "unknown");
+			});
 
 		switch (q->opcode) {
 		case BIFF_DIMENSIONS_v0: break; /* ignore ancient XL2 variant */
@@ -6864,7 +6869,12 @@ excel_read_workbook (GOIOContext *context, WorkbookView *wb_view, GsfInput *inpu
 	       problem_loading == NULL && /* there were no problems so far */
 	       ms_biff_query_next (q)) {  /* we can load the record */
 
-		d (5, g_printerr ("Opcode: 0x%x\n", q->opcode););
+		d (5, {
+			const char *opname = biff_opcode_name (q->opcode);
+			g_printerr ("Opcode: 0x%x %s\n",
+				    q->opcode,
+				    opname ? opname : "unknown");
+			});
 
 		switch (q->opcode) {
 		case BIFF_BOF_v0:
diff --git a/tools/ChangeLog b/tools/ChangeLog
index 689a9b7..3990060 100644
--- a/tools/ChangeLog
+++ b/tools/ChangeLog
@@ -1,3 +1,7 @@
+2011-01-06  Morten Welinder  <terra gnome org>
+
+	* biffnames: New file.
+
 2010-11-25  Morten Welinder <terra gnome org>
 
 	* Release 1.10.12
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 6f5fd5c..5d6884f 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -5,4 +5,5 @@ EXTRA_DIST = dumpdef.pl \
 	check-gtk-includes \
 	check-null-false-returns \
 	check-glade-parsing \
-	handle-conf-options
+	handle-conf-options \
+	biffnames
diff --git a/tools/biffnames b/tools/biffnames
new file mode 100755
index 0000000..9d8f93a
--- /dev/null
+++ b/tools/biffnames
@@ -0,0 +1,33 @@
+#!/usr/bin/perl -w
+
+my %names;
+
+while (<STDIN>) {
+    chomp;
+    s{/\*.*\*/}{ };
+    if (/^\s*\#\s*define\s+([A-Za-z_][A-Za-z_0-9]*)\s+(.*\S)\s*/) {
+	my $name = $1;
+	my $opcode = $2;
+
+	if (exists $names{$opcode}) {
+	    $names{$opcode} .= "/$name";
+	} else {
+	    $names{$opcode} .= $name;
+	}
+    }
+}
+
+print "#include <stdlib.h>\n";
+print "#include <biff-types.h>\n";
+print "\n";
+print "const char *\n";
+print "biff_opcode_name (unsigned int opcode)\n";
+print "{\n";
+print "  switch (opcode) {\n";
+foreach my $opcode (sort keys %names) {
+    my $name = $names{$opcode};
+    print "  case $opcode: return \"$name\";\n";
+}
+print "  default: return NULL;\n";
+print "  }\n";
+print "}\n";



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