Got rid of the GList thing in catalog.

This commit is contained in:
brianb 2000-03-05 13:10:42 +00:00
parent c461a46d22
commit 2475fae882
5 changed files with 63 additions and 47 deletions

View File

@ -62,14 +62,15 @@ typedef struct {
guint16 row_num; guint16 row_num;
unsigned int cur_pos; unsigned int cur_pos;
unsigned char pg_buf[MDB_PGSIZE]; unsigned char pg_buf[MDB_PGSIZE];
GList *catalog; int num_catalog;
GArray *catalog;
} MdbHandle; } MdbHandle;
typedef struct { typedef struct {
MdbHandle *mdb; MdbHandle *mdb;
char object_name[MDB_MAX_OBJ_NAME+1]; char object_name[MDB_MAX_OBJ_NAME+1];
int object_type; int object_type;
unsigned long table_pg; unsigned long table_pg; /* misnomer since object may not be a table */
unsigned long kkd_pg; unsigned long kkd_pg;
unsigned int kkd_rowid; unsigned int kkd_rowid;
int num_props; int num_props;
@ -92,6 +93,8 @@ typedef struct {
typedef struct { typedef struct {
char name[MDB_MAX_OBJ_NAME+1]; char name[MDB_MAX_OBJ_NAME+1];
int col_type;
int col_size;
GHashTable *properties; GHashTable *properties;
} MdbColumn; } MdbColumn;

View File

@ -84,7 +84,7 @@ int mdb_catalog_rows(MdbHandle *mdb)
{ {
return mdb_get_int16(mdb, 0x08); return mdb_get_int16(mdb, 0x08);
} }
GList *mdb_read_catalog(MdbHandle *mdb, int obj_type) GArray *mdb_read_catalog(MdbHandle *mdb, int obj_type)
{ {
int i; int i;
int rows; int rows;
@ -126,6 +126,7 @@ int next_pg, next_pg_off;
} }
return (mdb->catalog); return (mdb->catalog);
#endif #endif
mdb->catalog = g_array_new(FALSE,FALSE,sizeof(MdbCatalogEntry));
next_pg=0; next_pg=0;
while (mdb_read_pg(mdb,next_pg)) { while (mdb_read_pg(mdb,next_pg)) {
if (mdb->pg_buf[0]==0x01 && if (mdb->pg_buf[0]==0x01 &&
@ -135,8 +136,8 @@ int next_pg, next_pg_off;
for (i=0;i<rows;i++) { for (i=0;i<rows;i++) {
if (mdb->pg_buf[11 + 2 * i] & 0x40) continue; if (mdb->pg_buf[11 + 2 * i] & 0x40) continue;
if (mdb_read_catalog_entry(mdb, i, &entry)) { if (mdb_read_catalog_entry(mdb, i, &entry)) {
data = g_memdup(&entry,sizeof(MdbCatalogEntry)); mdb->num_catalog++;
mdb->catalog = g_list_append(mdb->catalog, data); mdb->catalog = g_array_append_val(mdb->catalog, entry);
} }
} }
} }
@ -145,20 +146,19 @@ int next_pg, next_pg_off;
} }
void mdb_dump_catalog(MdbHandle *mdb, int obj_type) void mdb_dump_catalog(MdbHandle *mdb, int obj_type)
{ {
int rows; int rows, i;
GList *l; MdbCatalogEntry entry;
MdbCatalogEntry *entryp;
mdb_read_catalog(mdb, obj_type); mdb_read_catalog(mdb, obj_type);
for (l=g_list_first(mdb->catalog);l;l=g_list_next(l)) { for (i=0;i<mdb->num_catalog;i++) {
entryp = l->data; entry = g_array_index(mdb->catalog,MdbCatalogEntry,i);
if (obj_type==-1 || entryp->object_type==obj_type) { if (obj_type==-1 || entry.object_type==obj_type) {
fprintf(stdout,"Type: %-10s Name: %-18s T pg: %04x KKD pg: %04x row: %2d\n", fprintf(stdout,"Type: %-10s Name: %-18s T pg: %04x KKD pg: %04x row: %2d\n",
mdb_get_objtype_string(entryp->object_type), mdb_get_objtype_string(entry.object_type),
entryp->object_name, entry.object_name,
entryp->table_pg, entry.table_pg,
entryp->kkd_pg, entry.kkd_pg,
entryp->kkd_rowid); entry.kkd_rowid);
} }
} }
return; return;

View File

@ -39,12 +39,8 @@ void mdb_free_handle(MdbHandle *mdb)
void mdb_free_catalog(MdbHandle *mdb) void mdb_free_catalog(MdbHandle *mdb)
{ {
GList *l; GList *l;
MdbCatalogEntry *entryp; MdbCatalogEntry entry;
for (l=g_list_first(mdb->catalog);l;l=g_list_next(l)) {
entryp = l->data;
g_free(entryp);
}
} }
MdbTableDef *mdb_alloc_tabledef(MdbCatalogEntry *entry) MdbTableDef *mdb_alloc_tabledef(MdbCatalogEntry *entry)
{ {

View File

@ -77,26 +77,18 @@ int len, i;
return table; return table;
} }
MdbColumn *mdb_read_column(MdbTableDef *table) GArray *mdb_read_columns(MdbHandle *mdb, MdbTableDef *table)
{
}
void mdb_table_dump(MdbCatalogEntry *entry)
{ {
MdbColumn col;
GArray *columns;
int len, i; int len, i;
int cur_col, cur_name; int cur_col, cur_name;
int col_type, col_size; int col_type, col_size;
int col_start, name_start; int col_start, name_start;
char name[MDB_MAX_OBJ_NAME+1]; char name[MDB_MAX_OBJ_NAME+1];
int name_sz; int name_sz;
MdbTableDef *table;
MdbHandle *mdb = entry->mdb;
table = mdb_read_table(entry); table->columns = g_array_new(FALSE,FALSE,sizeof(MdbColumn));
fprintf(stdout,"number of datarows = %d\n",table->num_rows);
fprintf(stdout,"number of columns = %d\n",table->num_cols);
fprintf(stdout,"number of datapages = %d\n",table->num_pgs);
fprintf(stdout,"first data page = %d\n",table->first_data_pg);
col_start = 43 + (table->num_pgs * 8); col_start = 43 + (table->num_pgs * 8);
name_start = col_start + (table->num_cols * 18); name_start = col_start + (table->num_cols * 18);
@ -105,18 +97,43 @@ MdbHandle *mdb = entry->mdb;
cur_name = name_start; cur_name = name_start;
for (i=0;i<table->num_cols;i++) { for (i=0;i<table->num_cols;i++) {
col_type = mdb->pg_buf[cur_col]; memset(&col,'\0', sizeof(MdbColumn));
col_size = mdb_get_int16(mdb,cur_col+16);
col.col_type = mdb->pg_buf[cur_col];
col.col_size = mdb_get_int16(mdb,cur_col+16);
/* get the name */ /* get the name */
name_sz = mdb->pg_buf[cur_name]; name_sz = mdb->pg_buf[cur_name];
memcpy(name,&mdb->pg_buf[cur_name+1],name_sz); memcpy(col.name,&mdb->pg_buf[cur_name+1],name_sz);
name[name_sz]='\0'; col.name[name_sz]='\0';
fprintf(stdout,"column %2d %s\n",i,name);
fprintf(stdout,"column type %s\n",mdb_get_coltype_string(col_type));
fprintf(stdout,"column size %d\n",col_size);
cur_col += 18; cur_col += 18;
cur_name += name_sz + 1; cur_name += name_sz + 1;
g_array_append_val(table->columns, col);
}
return table->columns;
}
void mdb_table_dump(MdbCatalogEntry *entry)
{
MdbTableDef *table;
MdbColumn col;
MdbHandle *mdb = entry->mdb;
int i;
table = mdb_read_table(entry);
fprintf(stdout,"number of datarows = %d\n",table->num_rows);
fprintf(stdout,"number of columns = %d\n",table->num_cols);
fprintf(stdout,"number of datapages = %d\n",table->num_pgs);
fprintf(stdout,"first data page = %d\n",table->first_data_pg);
mdb_read_columns(mdb, table);
for (i=0;i<table->num_cols;i++) {
col = g_array_index(table->columns,MdbColumn,i);
fprintf(stdout,"column %2d %s\n",i,col.name);
fprintf(stdout,"column type %s\n",
mdb_get_coltype_string(col.col_type));
fprintf(stdout,"column size %d\n",col.col_size);
} }
} }

View File

@ -26,7 +26,7 @@ int rows;
int i; int i;
unsigned char buf[2048]; unsigned char buf[2048];
MdbHandle *mdb; MdbHandle *mdb;
MdbCatalogEntry *entry; MdbCatalogEntry entry;
GList *l; GList *l;
@ -39,10 +39,10 @@ GList *l;
mdb_read_catalog(mdb, MDB_TABLE); mdb_read_catalog(mdb, MDB_TABLE);
for (l=g_list_first(mdb->catalog);l;l=g_list_next(l)) { for (i=0;i<mdb->num_catalog;i++) {
entry = l->data; entry = g_array_index(mdb->catalog,MdbCatalogEntry,i);
if (!strcmp(entry->object_name,argv[2])) { if (!strcmp(entry.object_name,argv[2])) {
mdb_table_dump(entry); mdb_table_dump(&entry);
} }
} }