[patch] kkd / mdb-props

Nirgal Vourgère <[email protected]> Mon, 7 Feb 2011 22:16:12 +0000
Newsgroups gmane.comp.db.mdb-tools.devel
Message-ID <[email protected]>
... and here's a little clean up for kkd / mdb-props. It applies to github repository.

mdb-props used to output a lot of debug messages. This is because we are using #ifdef MDB_DEBUG rather than #if MDB_DEBUG. Note that mdbtools.h #defines MDB_DEBUG 0.

mdb-props used to want a 3rd argument, the name of the *MSysObject* column. It now defaults to "LvProp", that is the column containing the most useful information.

I also fixed a few changes in the obsolete file prkkd.c. It's really not usefull, now that mdb-props works ok. But since I did it, you can merge nevertheless.

Cheers

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb

_______________________________________________
mdbtools-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mdbtools-dev
kkd.diff (text/x-patch, 5.2 KB)
Index: mdbtools-0.6pre1/src/libmdb/kkd.c
===================================================================
--- mdbtools-0.6pre1.orig/src/libmdb/kkd.c
+++ mdbtools-0.6pre1/src/libmdb/kkd.c
@@ -109,11 +109,13 @@
 int rowid = entry->kkd_rowid;
 
 
+	fprintf(stdout, "kkd_pg=%d kkd_rowid=%d\n", entry->kkd_pg, rowid);
+
 	mdb_read_pg(mdb, entry->kkd_pg);
 	rows = mdb_get_int16(mdb->pg_buf, 8);
 	fprintf(stdout,"number of rows = %d\n",rows);
 	kkd_start = mdb_get_int16(mdb->pg_buf, 10+rowid*2);
-	fprintf(stdout,"kkd start = %d %04x\n",kkd_start,kkd_start);
+	fprintf(stdout,"kkd start = %d 0x%04x\n",kkd_start,kkd_start);
 	kkd_end = mdb->fmt->pg_size;
 	for (i=0;i<rows;i++) {
 		tmp = mdb_get_int16(mdb->pg_buf, 10+i*2);
@@ -123,7 +125,7 @@
 			kkd_end = tmp;
 		}
 	}
-	fprintf(stdout,"kkd end = %d %04x\n",kkd_end,kkd_end);
+	fprintf(stdout,"kkd end = %d 0x%04x\n",kkd_end,kkd_end);
 	pos = kkd_start + 4; /* 4 = K K D \0 */
 	while (pos < kkd_end) {
 		tmp = mdb_pg_get_int16(mdb,pos);
Index: mdbtools-0.6pre1/src/util/mdb-prop.c
===================================================================
--- mdbtools-0.6pre1.orig/src/util/mdb-prop.c
+++ mdbtools-0.6pre1/src/util/mdb-prop.c
@@ -20,9 +20,6 @@
 
 #include "mdbtools.h"
 
-#undef MDB_DEBUG
-//#define MDB_DEBUG 1
-
 void dump_kkd(MdbHandle *mdb, void *kkd, size_t len);
 
 int
@@ -31,15 +28,20 @@
 	MdbHandle *mdb;
 	MdbTableDef *table;
 	gchar name[256];
+	gchar *propColName;
 	void *buf;
 	int col_num;
 	int found = 0;
 
-	if (argc < 4) {
-		fprintf(stderr,"Usage: %s <file> <object name> <prop col>\n",
+	if (argc < 3) {
+		fprintf(stderr,"Usage: %s <file> <object name> [<prop col>]\n",
 			argv[0]);
 		return 1;
 	}
+	if (argc < 4)
+		propColName = "LvProp";
+	else
+		propColName = argv[3];
 
 	mdb_init();
 
@@ -60,12 +62,13 @@
 
 	mdb_bind_column_by_name(table, "Name", name, NULL);
 	buf = g_malloc(MDB_BIND_SIZE);
-	col_num = mdb_bind_column_by_name(table, argv[3], buf, NULL);
+	col_num = mdb_bind_column_by_name(table, propColName, buf, NULL);
 	if (col_num < 1) {
 		g_free(buf);
 		mdb_free_tabledef(table);
 		mdb_close(mdb);
 		mdb_exit();
+		printf("Column %s not found!\n", argv[3]);
 		return 1;
 	}
 
@@ -81,7 +84,6 @@
 		gchar kkd_ptr[MDB_MEMO_OVERHEAD];
 		void *kkd_pg = g_malloc(200000);
 		size_t len, pos;
-
 		memcpy(kkd_ptr, buf, MDB_MEMO_OVERHEAD);
 		col = g_ptr_array_index(table->columns, col_num - 1);
 		len = mdb_ole_read(mdb, col, kkd_ptr, MDB_BIND_SIZE);
@@ -114,7 +116,7 @@
 	GPtrArray *names = NULL;
 	MdbProperties *props;
 
-#ifdef MDB_DEBUG
+#if MDB_DEBUG
 	buffer_dump(kkd, 0, len);
 #endif
 	if (strcmp("KKD", kkd)) {
@@ -140,6 +142,7 @@
 				props = mdb_read_props(mdb, names, kkd+pos+6, record_len - 6);
 				printf("type 0x00 name %s\n", props->name ? props->name : "(none)");
 				g_hash_table_foreach(props->hash, print_keyvalue, NULL);
+				putchar('\n');
 				mdb_free_props(props);
 				break;
 			case 0x01:
@@ -150,6 +153,7 @@
 				props = mdb_read_props(mdb, names, kkd+pos+6, record_len - 6);
 				printf("type 0x01 name %s\n", props->name ? props->name : "(none)");
 				g_hash_table_foreach(props->hash, print_keyvalue, NULL);
+				putchar('\n');
 				mdb_free_props(props);
 				break;
 			default:
Index: mdbtools-0.6pre1/src/util/prkkd.c
===================================================================
--- mdbtools-0.6pre1.orig/src/util/prkkd.c
+++ mdbtools-0.6pre1/src/util/prkkd.c
@@ -23,10 +23,10 @@
 {
 
 #if 0
-	int i;
-	MdbCatalogEntry entry;
+	MdbHandle *mdb;
+	MdbTableDef *table;
 
-	if (argc<2) {
+	if (argc<3) {
 		fprintf(stderr,"Usage: %s <file> <table>\n",argv[0]);
 		exit(1);
 	}
@@ -34,21 +34,16 @@
 	mdb_init();
 	mdb = mdb_open(argv[1], MDB_NOFLAGS);
 
-	mdb_read_pg(mdb, MDB_CATALOG_PG);
-	rows = mdb_catalog_rows(mdb);
-
-	for (i=0;i<rows;i++) {
-  		if (mdb_read_catalog_entry(mdb, i, &entry)) {
-			if (!strcmp(entry.object_name,argv[2])) {
-				mdb_kkd_dump(&entry);
-  			}
-		}
+	table = mdb_read_table_by_name(mdb, argv[2], MDB_TABLE);
+	if (!table) {
+		fprintf(stderr,"No table named %s found.\n", argv[2]);
+		exit(1);
 	}
+	/* FIXME: table->entry->*kkd* are not initialized */
+	mdb_kkd_dump(table->entry);
 
 	mdb_close(mdb);
 	mdb_exit();
 #endif
-
 	exit(0);
 }
-
Index: mdbtools-0.6pre1/src/libmdb/props.c
===================================================================
--- mdbtools-0.6pre1.orig/src/libmdb/props.c
+++ mdbtools-0.6pre1/src/libmdb/props.c
@@ -30,14 +30,14 @@
 	int i = 0;
 
 	names = g_ptr_array_new();
-#ifdef MDB_DEBUG
+#if MDB_DEBUG
 	buffer_dump(kkd, 0, len);
 #endif
 	pos = 0;
 	while (pos < len) {
 		record_len = mdb_get_int16(kkd, pos);
 		pos += 2;
-#ifdef MDB_DEBUG
+#if MDB_DEBUG
 		printf("%02d ",i++);
 		buffer_dump(kkd, pos - 2, record_len + 2);
 #endif
@@ -46,7 +46,7 @@
 		name[record_len] = '\0';
 		pos += record_len;
 		g_ptr_array_add(names, name);
-#ifdef MDB_DEBUG
+#if MDB_DEBUG
 		printf("new len = %d\n", names->len);
 #endif
 	}
@@ -79,7 +79,7 @@
 	MdbProperties *props;
 	int i = 0;
 
-#ifdef MDB_DEBUG
+#if MDB_DEBUG
 	buffer_dump(kkd, 0, len);
 #endif
 	pos = 0;
@@ -108,7 +108,7 @@
 		strncpy(value, &kkd[pos + 8], dsize);
 		value[dsize] = '\0';
 		name = g_ptr_array_index(names,elem);
-#ifdef MDB_DEBUG
+#if MDB_DEBUG
 		printf("%02d ",i++);
 		buffer_dump(kkd, pos, record_len);
 		printf("elem %d dsize %d dtype %d\n", elem, dsize, dtype);