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

View File

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

View File

@ -39,12 +39,8 @@ void mdb_free_handle(MdbHandle *mdb)
void mdb_free_catalog(MdbHandle *mdb)
{
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)
{

View File

@ -77,26 +77,18 @@ int len, i;
return table;
}
MdbColumn *mdb_read_column(MdbTableDef *table)
{
}
void mdb_table_dump(MdbCatalogEntry *entry)
GArray *mdb_read_columns(MdbHandle *mdb, MdbTableDef *table)
{
MdbColumn col;
GArray *columns;
int len, i;
int cur_col, cur_name;
int col_type, col_size;
int col_start, name_start;
char name[MDB_MAX_OBJ_NAME+1];
int name_sz;
MdbTableDef *table;
MdbHandle *mdb = entry->mdb;
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);
table->columns = g_array_new(FALSE,FALSE,sizeof(MdbColumn));
col_start = 43 + (table->num_pgs * 8);
name_start = col_start + (table->num_cols * 18);
@ -105,18 +97,43 @@ MdbHandle *mdb = entry->mdb;
cur_name = name_start;
for (i=0;i<table->num_cols;i++) {
col_type = mdb->pg_buf[cur_col];
col_size = mdb_get_int16(mdb,cur_col+16);
memset(&col,'\0', sizeof(MdbColumn));
col.col_type = mdb->pg_buf[cur_col];
col.col_size = mdb_get_int16(mdb,cur_col+16);
/* get the name */
name_sz = mdb->pg_buf[cur_name];
memcpy(name,&mdb->pg_buf[cur_name+1],name_sz);
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);
memcpy(col.name,&mdb->pg_buf[cur_name+1],name_sz);
col.name[name_sz]='\0';
cur_col += 18;
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;
unsigned char buf[2048];
MdbHandle *mdb;
MdbCatalogEntry *entry;
MdbCatalogEntry entry;
GList *l;
@ -39,10 +39,10 @@ GList *l;
mdb_read_catalog(mdb, MDB_TABLE);
for (l=g_list_first(mdb->catalog);l;l=g_list_next(l)) {
entry = l->data;
if (!strcmp(entry->object_name,argv[2])) {
mdb_table_dump(entry);
for (i=0;i<mdb->num_catalog;i++) {
entry = g_array_index(mdb->catalog,MdbCatalogEntry,i);
if (!strcmp(entry.object_name,argv[2])) {
mdb_table_dump(&entry);
}
}