more index work

fixed gnome detection (i think)
added back/forward navigation to gui debugger
This commit is contained in:
brianb
2003-01-09 20:24:19 +00:00
parent c3386d2a43
commit f35c3f05b9
6 changed files with 514 additions and 62 deletions

View File

@@ -23,18 +23,34 @@ char idx_to_text[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 8-15 0x09-0x0f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 16-23 0x10-0x17 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 24-31 0x19-0x1f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 32-39 0x20-0x27 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 40-47 0x29-0x2f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 48-55 0x30-0x37 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 56-63 0x39-0x3f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 64-71 0x40-0x47 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 72-79 0x49-0x4f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, '0', '1', /* 80-87 0x50-0x57 */
'2', '3', '4', '5', '6', '7', '8', '9', /* 88-95 0x59-0x5f */
'A', 'B', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 96-103 0x60-0x67 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 104-111 0x69-0x6f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 112-119 0x70-0x77 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 /* 120-127 0x79-0x7f */
' ', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 32-39 0x20-0x27 */
0x00, 0x00, 0x00, 0x00, 0x00, ' ', ' ', 0x00, /* 40-47 0x29-0x2f */
'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', /* 48-55 0x30-0x37 */
'^', '_', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 56-63 0x39-0x3f */
0x00, '`', 'a', 'b', 'd', 'f', 'g', 'h', /* 64-71 0x40-0x47 */
'i', 'j', 'k', 'l', 'm', 'o', 'p', 'r', /* 72-79 0x49-0x4f H */
's', 't', 'u', 'v', 'w', 'x', 'z', '{', /* 80-87 0x50-0x57 P */
'|', '}', '~', '5', '6', '7', '8', '9', /* 88-95 0x59-0x5f */
0x00, '`', 'a', 'b', 'd', 'f', 'g', 'h', /* 96-103 0x60-0x67 */
'i', 'j', 'k', 'l', 'm', 'o', 'p', 'r', /* 014-111 0x69-0x6f h */
's', 't', 'u', 'v', 'w', 'x', 'z', '{', /* 112-119 0x70-0x77 p */
'|', '}', '~', 0x00, 0x00, 0x00, 0x00, 0x00, /* 120-127 0x78-0x7f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 128-135 0x80-0x87 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x88-0x8f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x90-0x97 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0x98-0x9f */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa0-0xa7 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xa8-0xaf */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb0-0xb7 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xb8-0xbf */
0x00, 0x00, 0x00, 0x00, 0x00, '`', 0x00, 0x00, /* 0xc0-0xc7 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xc8-0xcf */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd0-0xd7 */
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xd8-0xdf */
0x00, '`', 0x00, '`', '`', '`', 0x00, 0x00, /* 0xe0-0xe7 */
'f', 'f', 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* 0xe8-0xef */
0x00, 0x00, 0x00, 'r', 0x00, 0x00, 'r', 0x00, /* 0xf0-0xf7 */
0x81, 0x00, 0x00, 0x00, 'x', 0x00, 0x00, 0x00, /* 0xf8-0xff */
};
GPtrArray *mdb_read_indices(MdbTableDef *table)
@@ -54,6 +70,7 @@ int name_sz;
for (i=0;i<table->num_idxs;i++) {
memset(&idx, '\0', sizeof(MdbIndex));
idx.table = table;
idx.index_num = mdb_get_int16(mdb, cur_pos);
cur_pos += 19;
idx.index_type = mdb->pg_buf[cur_pos++];
@@ -110,6 +127,192 @@ int name_sz;
pidx->flags = mdb->pg_buf[cur_pos++];
}
}
void
mdb_index_hash_text(guchar *text, guchar *hash)
{
int k;
for (k=0;k<strlen(text);k++) {
hash[k] = idx_to_text[text[k]];
if (!(hash[k])) fprintf(stderr,
"No translation available for %02x %d\n",
text[k],text[k]);
}
hash[strlen(text)]=0;
}
guint32
mdb_index_swap_int32(guint32 l)
{
unsigned char *c, *c2;
guint32 l2;
c = &l;
c2 = &l2;
c2[0]=c[3];
c2[1]=c[2];
c2[2]=c[1];
c2[3]=c[0];
return l2;
}
void mdb_index_cache_sarg(MdbColumn *col, MdbSarg *sarg, MdbSarg *idx_sarg)
{
guint32 cache_int;
unsigned char *c;
switch (col->col_type) {
case MDB_TEXT:
mdb_index_hash_text(sarg->value.s, idx_sarg->value.s);
break;
case MDB_LONGINT:
idx_sarg->value.i = mdb_index_swap_int32(sarg->value.i);
//cache_int = sarg->value.i * -1;
c = &(idx_sarg->value.i);
c[0] |= 0x80;
printf("int %08x %02x %02x %02x %02x\n", sarg->value.i, c[0], c[1], c[2], c[3]);
break;
case MDB_INT:
break;
default:
break;
}
}
int
mdb_index_test_sargs(MdbHandle *mdb, MdbIndex *idx, int offset, int len)
{
int i, j;
MdbColumn *col;
MdbTableDef *table = idx->table;
MdbSarg *idx_sarg;
MdbSarg *sarg;
int c_offset = 0, c_len;
for (i=0;i<idx->num_keys;i++) {
c_offset++; /* the per column null indicator/flags */
col=g_ptr_array_index(table->columns,idx->key_col_num[i]-1);
/*
* This will go away eventually
*/
if (col->col_type==MDB_TEXT) {
c_len = strlen(&mdb->pg_buf[offset + c_offset]);
} else {
c_len = col->col_size;
fprintf(stderr,"Only text types currently supported. How did we get here?\n");
}
/*
* If we have no cached index values for this column,
* create them.
*/
if (col->num_sargs && !col->idx_sarg_cache) {
col->idx_sarg_cache = g_ptr_array_new();
for (j=0;j<col->num_sargs;j++) {
sarg = g_ptr_array_index (col->sargs, j);
idx_sarg = g_memdup(sarg,sizeof(MdbSarg));
printf("calling mdb_index_cache_sarg\n");
mdb_index_cache_sarg(col, sarg, idx_sarg);
g_ptr_array_add(col->idx_sarg_cache, idx_sarg);
}
}
for (j=0;j<col->num_sargs;j++) {
sarg = g_ptr_array_index (col->idx_sarg_cache, j);
if (!mdb_test_sarg(mdb, col, sarg, offset + c_offset, c_len)) {
/* sarg didn't match, no sense going on */
return 0;
}
}
}
return 1;
}
int
mdb_index_find_next_on_page(MdbHandle *mdb, MdbIndexPage *ipg)
{
do {
//fprintf(stdout, "%d %d\n", ipg->mask_bit, ipg->mask_byte);
ipg->mask_bit++;
if (ipg->mask_bit==8) {
ipg->mask_bit=0;
ipg->mask_pos++;
}
ipg->mask_byte = mdb->pg_buf[ipg->mask_pos];
ipg->len++;
} while (ipg->mask_pos <= 0xf8 &&
!((1 << ipg->mask_bit) & ipg->mask_byte));
if (ipg->mask_pos>=0xf8)
return 0;
return ipg->len;
}
void mdb_index_page_init(MdbIndexPage *ipg)
{
ipg->offset = 0xf8; /* start byte of the index entries */
ipg->mask_pos = 0x16;
ipg->mask_bit=0;
ipg->len = 0;
}
int
mdb_find_next_leaf(MdbHandle *mdb, MdbIndexChain *chain)
{
MdbIndexPage *ipg;
/*
* If we are at the first page deep and it's not an index page then
* we are simply done. (there is no page to find
*/
if (chain->cur_depth==1) {
ipg = &(chain->pages[0]);
if (mdb->pg_buf[0]==MDB_PAGE_LEAF ||
mdb->pg_buf[0]==MDB_PAGE_DATA) {
return ipg->pg;
}
}
ipg = &(chain->pages[chain->cur_depth - 1]);
/* no more pages */
return 0;
}
int
mdb_index_find_next(MdbHandle *mdb, MdbIndex *idx, MdbIndexChain *chain, guint32 *pg, guint16 *row)
{
MdbIndexPage *ipg;
int passed = 0;
if (!chain->cur_depth) {
ipg = &(chain->pages[0]);
mdb_index_page_init(ipg);
chain->cur_depth = 1;
ipg->pg = idx->first_pg;
if (!mdb_find_next_leaf(mdb, chain))
return 0;
} else {
ipg = &(chain->pages[chain->cur_depth - 1]);
ipg->len = 0;
}
mdb_read_pg(mdb, ipg->pg);
do {
ipg->len = 0;
if (!mdb_index_find_next_on_page(mdb, ipg))
return 0;
*row = mdb->pg_buf[ipg->offset + ipg->len - 1];
*pg = mdb_get_int24_msb(mdb, ipg->offset + ipg->len - 4);
passed = mdb_index_test_sargs(mdb, idx, ipg->offset, ipg->len);
ipg->offset += ipg->len;
} while (!passed);
//fprintf(stdout,"len = %d pos %d\n", ipg->len, ipg->mask_pos);
//buffer_dump(mdb->pg_buf, ipg->offset, ipg->offset+ipg->len-1);
return ipg->len;
}
void mdb_index_walk(MdbTableDef *table, MdbIndex *idx)
{
MdbHandle *mdb = table->entry->mdb;

View File

@@ -23,16 +23,6 @@
#define MDB_DEBUG_WRITE 1
typedef struct {
void *value;
int siz;
int start;
unsigned char is_null;
unsigned char is_fixed;
int colnum;
int offset;
} MdbField;
void
_mdb_put_int16(unsigned char *buf, guint32 offset, guint32 value)
{
@@ -141,7 +131,7 @@ int eod, len; /* end of data */
bit_num = i % 8;
/* logic on nulls is reverse, 1 is not null, 0 is null */
fields[i].is_null = nullmask[byte_num] & 1 << bit_num ? 0 : 1;
printf("col %d is %s\n", i, fields[i].is_null ? "null" : "not null");
//printf("col %d is %s\n", i, fields[i].is_null ? "null" : "not null");
}
/* find the end of data pointer */
@@ -150,7 +140,7 @@ int eod, len; /* end of data */
} else {
eod = mdb->pg_buf[row_end-1-var_cols-bitmask_sz];
}
printf("eod is %d\n", eod);
//printf("eod is %d\n", eod);
if (IS_JET4(mdb)) {
col_start = 2;
@@ -178,7 +168,7 @@ int eod, len; /* end of data */
if (!mdb_is_fixed_col(col) && ++var_cols_found <= var_cols) {
if (var_cols_found==var_cols) {
len=eod - col_start;
printf("len = %d eod %d col_start %d\n",len, eod, col_start);
//printf("len = %d eod %d col_start %d\n",len, eod, col_start);
} else {
if (IS_JET4(mdb)) {
/* position of the var table
@@ -195,7 +185,7 @@ int eod, len; /* end of data */
bitmask_sz -
var_cols_found - 1;
len=mdb->pg_buf[var_entry_pos] - mdb->pg_buf[var_entry_pos+1];
printf("%d %d %d %d\n", mdb->pg_buf[var_entry_pos-1],mdb->pg_buf[var_entry_pos],len, col_start);
//printf("%d %d %d %d\n", mdb->pg_buf[var_entry_pos-1],mdb->pg_buf[var_entry_pos],len, col_start);
}
} /* if found==var_cols */
if (len<0) len+=256;