clean up for kkd / mdb-props, from Nirgal Vourgère

This commit is contained in:
Brian Bruns 2011-02-07 22:06:48 -05:00
parent 5c7e4216fa
commit 3adb7d6bab
4 changed files with 30 additions and 29 deletions

View File

@ -109,11 +109,13 @@ MdbHandle *mdb = entry->mdb;
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 @@ int rowid = entry->kkd_rowid;
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);

View File

@ -30,14 +30,14 @@ mdb_read_props_list(gchar *kkd, int len)
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 @@ mdb_read_props_list(gchar *kkd, int len)
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 @@ mdb_read_props(MdbHandle *mdb, GPtrArray *names, gchar *kkd, int len)
MdbProperties *props;
int i = 0;
#ifdef MDB_DEBUG
#if MDB_DEBUG
buffer_dump(kkd, 0, len);
#endif
pos = 0;
@ -108,7 +108,7 @@ mdb_read_props(MdbHandle *mdb, GPtrArray *names, gchar *kkd, int len)
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);

View File

@ -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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
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 @@ main(int argc, char **argv)
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 @@ void dump_kkd(MdbHandle *mdb, void *kkd, size_t len)
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 @@ void dump_kkd(MdbHandle *mdb, void *kkd, size_t len)
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 @@ void dump_kkd(MdbHandle *mdb, void *kkd, size_t len)
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:

View File

@ -23,10 +23,10 @@ main(int argc, char **argv)
{
#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 @@ main(int argc, char **argv)
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);
}