Reconcile code/documentation inconsistencies

This commit is contained in:
whydoubt 2004-06-18 05:10:44 +00:00
parent 6e8c4d3436
commit 00d9fddc69
6 changed files with 61 additions and 65 deletions

View File

@ -1,3 +1,9 @@
Fri Jun 18 00:08:24 CDT 2004 Jeff Smith <whydoubt@yahoo.com>
* HACKING:
* src/libmdb/index.c:
* src/libmdb/mem.c:
* include/mdbtools.h: Reconcile code/documentation inconsistencies
Thu Jun 17 20:56:44 EDT 2004 Brian Bruns <brian@bruns.com>
* configure.in: temporarily remove building of reference manual. It broke 'make dist'

View File

@ -346,11 +346,12 @@ next_pg field.
| ???? | 4 bytes | first_dp | Data pointer of the index page |
| ???? | 1 byte | flags | See flags table for indexes |
+-------------------------------------------------------------------------+
| Iterate for the number of num_real_idx |
| Iterate for the number of num_real_idx (20 bytes) |
+-------------------------------------------------------------------------+
| ???? | 4 bytes | index_num | Number of the index |
| | | |(warn: not always in the sequential order)|
| ???? | 4 bytes | index_num2 | Number of the index (repeat) |
| 0x00 | 1 byte | ??? | |
| 0xFF | 4 bytes | ??? | |
| 0x00 | 4 bytes | ??? | |
| 0x04 | 2 bytes | ??? | |
@ -412,7 +413,7 @@ next_pg field.
| ???? | 2 bytes | col_name_len| len of the name of the column |
| ???? | n bytes | col_name | Name of the column (UCS-2 format) |
+-------------------------------------------------------------------------+
| Iterate for the number of num_real_idx (30+9 = 39 bytes) |
| Iterate for the number of num_real_idx (30+22 = 52 bytes) |
+-------------------------------------------------------------------------+
| ???? | 4 bytes | ??? | |
+-------------------------------------------------------------------------+
@ -426,12 +427,13 @@ next_pg field.
| ???? | 1 byte | flags | See flags table for indexes |
| ???? | 9 bytes | unknown | |
+-------------------------------------------------------------------------+
| Iterate for the number of num_real_idx (27 bytes) |
| Iterate for the number of num_real_idx (28 bytes) |
+-------------------------------------------------------------------------+
| ???? | 4 bytes | unknown | matches first unknown definition block |
| ???? | 4 bytes | index_num | Number of the index |
| | | |(warn: not always in the sequential order)|
| ???? | 4 bytes | index_num2 | Number of the index (repeat) |
| 0x00 | 1 byte | ??? | |
| 0xFF | 4 bytes | ??? | |
| 0x00 | 4 bytes | ??? | |
| 0x04 | 2 bytes | ??? | |

View File

@ -48,7 +48,6 @@ mdb_table_dump
mdb_free_tabledef
<SUBSECTION>
mdb_read_columns
mdb_append_index
mdb_get_objtype_string
mdb_bind_column_by_name
mdb_data_dump

View File

@ -383,8 +383,6 @@ extern MdbTableDef *mdb_alloc_tabledef(MdbCatalogEntry *entry);
extern void mdb_free_tabledef(MdbTableDef *table);
extern void mdb_append_column(GPtrArray *columns, MdbColumn *in_col);
extern void mdb_free_columns(GPtrArray *columns);
extern void mdb_append_index(GPtrArray *indices, MdbIndex *in_idx);
extern void mdb_free_indices(GPtrArray *indices);
/* file.c */
extern size_t mdb_read_pg(MdbHandle *mdb, unsigned long pg);
@ -475,6 +473,7 @@ extern void mdb_index_hash_text(guchar *text, guchar *hash);
extern void mdb_index_scan_init(MdbHandle *mdb, MdbTableDef *table);
extern int mdb_index_find_row(MdbHandle *mdb, MdbIndex *idx, MdbIndexChain *chain, guint32 pg, guint16 row);
extern void mdb_index_swap_n(unsigned char *src, int sz, unsigned char *dest);
extern void mdb_free_indices(GPtrArray *indices);
/* stats.c */

View File

@ -65,63 +65,63 @@ char idx_to_text[] = {
GPtrArray *
mdb_read_indices(MdbTableDef *table)
{
MdbCatalogEntry *entry = table->entry;
MdbHandle *mdb = entry->mdb;
MdbFormatConstants *fmt = mdb->fmt;
MdbIndex idx, *pidx;
int i, j;
int idx_num, key_num, col_num;
int cur_pos;
int name_sz, idx2_sz;
gchar *tmpbuf;
/* FIX ME -- doesn't handle multipage table headers */
MdbCatalogEntry *entry = table->entry;
MdbHandle *mdb = entry->mdb;
MdbFormatConstants *fmt = mdb->fmt;
MdbIndex *pidx;
int i, j;
int idx_num, key_num, col_num;
int cur_pos, name_sz, idx2_sz, type_offset;
int index_start_pg = mdb->cur_pg;
gchar *tmpbuf;
table->indices = g_ptr_array_new();
if (IS_JET4(mdb)) {
cur_pos = table->index_start + 52 * table->num_real_idxs;
idx2_sz = 27;
idx2_sz = 28;
type_offset = 23;
} else {
cur_pos = table->index_start + 39 * table->num_real_idxs;
idx2_sz = 19;
idx2_sz = 20;
type_offset = 19;
}
tmpbuf = (gchar *) g_malloc(idx2_sz);
for (i=0;i<table->num_idxs;i++) {
memset(&idx, '\0', sizeof(MdbIndex));
idx.table = table;
cur_pos +=4;
idx.index_num = read_pg_if_16(mdb, &cur_pos);
read_pg_if(mdb, &cur_pos, idx2_sz - 4);
cur_pos += idx2_sz - 4;
idx.index_type = mdb->pg_buf[cur_pos++];
mdb_append_index(table->indices, &idx);
read_pg_if_n(mdb, tmpbuf, &cur_pos, idx2_sz);
cur_pos += idx2_sz;
pidx = (MdbIndex *) g_malloc0(sizeof(MdbIndex));
pidx->table = table;
pidx->index_num = mdb_get_int16(tmpbuf, 4);
pidx->index_type = tmpbuf[type_offset];
g_ptr_array_add(table->indices, pidx);
}
g_free(tmpbuf);
for (i=0;i<table->num_idxs;i++) {
pidx = g_ptr_array_index (table->indices, i);
read_pg_if(mdb, &cur_pos, 0);
if (IS_JET4(mdb)) {
name_sz=read_pg_if_16(mdb, &cur_pos);
cur_pos += 2;
tmpbuf = g_malloc((name_sz + 1)*2);
read_pg_if_n(mdb, tmpbuf, &cur_pos, name_sz*2);
tmpbuf = g_malloc(name_sz);
read_pg_if_n(mdb, tmpbuf, &cur_pos, name_sz);
cur_pos += name_sz;
mdb_unicode2ascii(mdb, tmpbuf, 0, name_sz, pidx->name);
g_free(tmpbuf);
cur_pos += name_sz;
} else {
read_pg_if(mdb, &cur_pos, 0);
name_sz=mdb->pg_buf[cur_pos++];
read_pg_if_n(mdb, pidx->name, &cur_pos, name_sz);
pidx->name[name_sz]='\0';
cur_pos += name_sz;
pidx->name[name_sz]='\0';
}
//fprintf(stderr, "index name %s\n", pidx->name);
}
cur_pos = table->index_start;
mdb_read_alt_pg(mdb, entry->table_pg);
mdb_read_pg(mdb, entry->table_pg);
mdb_read_pg(mdb, index_start_pg);
cur_pos = table->index_start;
idx_num=0;
for (i=0;i<table->num_real_idxs;i++) {
if (IS_JET4(mdb)) cur_pos += 4;
@ -146,23 +146,22 @@ gchar *tmpbuf;
for (j=0;j<MDB_MAX_IDX_COLS;j++) {
col_num=read_pg_if_16(mdb,&cur_pos);
cur_pos += 2;
if (col_num != 0xFFFF) {
/* set column number to a 1 based column number and store */
pidx->key_col_num[key_num]=col_num + 1;
if (mdb->pg_buf[cur_pos]) {
pidx->key_col_order[key_num]=MDB_ASC;
} else {
pidx->key_col_order[key_num]=MDB_DESC;
}
key_num++;
}
read_pg_if(mdb, &cur_pos, 0);
cur_pos++;
if (col_num == 0xFFFF)
continue;
/* set column number to a 1 based column number and store */
pidx->key_col_num[key_num] = col_num + 1;
pidx->key_col_order[key_num] =
(mdb->pg_buf[cur_pos-1]) ? MDB_ASC : MDB_DESC;
key_num++;
}
pidx->num_keys = key_num;
cur_pos += 4;
pidx->first_pg = read_pg_if_32(mdb, &cur_pos);
cur_pos += 4;
read_pg_if(mdb, &cur_pos, 1);
read_pg_if(mdb, &cur_pos, 0);
pidx->flags = mdb->pg_buf[cur_pos++];
if (IS_JET4(mdb)) cur_pos += 9;
}
@ -889,3 +888,13 @@ mdb_index_scan_free(MdbTableDef *table)
table->mdbidx = NULL;
}
}
void mdb_free_indices(GPtrArray *indices)
{
unsigned int i;
if (!indices) return;
for (i=0; i<indices->len; i++)
g_free (g_ptr_array_index(indices, i));
g_ptr_array_free(indices, TRUE);
}

View File

@ -117,22 +117,3 @@ mdb_free_columns(GPtrArray *columns)
g_free (g_ptr_array_index(columns, i));
g_ptr_array_free(columns, TRUE);
}
void
mdb_append_index(GPtrArray *indices, MdbIndex *in_idx)
{
MdbIndex *idx;
idx = g_memdup(in_idx,sizeof(MdbIndex));
g_ptr_array_add(indices, idx);
}
void
mdb_free_indices(GPtrArray *indices)
{
unsigned int i;
if (!indices) return;
for (i=0; i<indices->len; i++)
g_free (g_ptr_array_index(indices, i));
g_ptr_array_free(indices, TRUE);
}