Make better use of read_pg_if_n

This commit is contained in:
whydoubt
2004-06-14 12:13:25 +00:00
parent 2a6d21ce6d
commit 2dd710e5c4
2 changed files with 54 additions and 100 deletions

View File

@@ -1,3 +1,6 @@
Mon Jun 14 07:12:37 CDT 2004 Jeff Smith <whydoubt@yahoo.com>
* src/libmdb/table.c: Make better use of read_pg_if_n
Fri Jun 11 16:56:06 CDT 200 Jeff Smith <whydoubt@yahoo.com> Fri Jun 11 16:56:06 CDT 200 Jeff Smith <whydoubt@yahoo.com>
* src/libmdb/table.c: Fix bug in read_pg_if_n * src/libmdb/table.c: Fix bug in read_pg_if_n

View File

@@ -159,16 +159,16 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
{ {
MdbHandle *mdb = table->entry->mdb; MdbHandle *mdb = table->entry->mdb;
MdbFormatConstants *fmt = mdb->fmt; MdbFormatConstants *fmt = mdb->fmt;
MdbColumn col, *pcol; MdbColumn *pcol;
int len, i,j; unsigned char *col;
unsigned char low_byte, high_byte; int i, cur_pos, name_sz;
int cur_col, cur_name;
int name_sz;
GSList *slist = NULL; GSList *slist = NULL;
table->columns = g_ptr_array_new(); table->columns = g_ptr_array_new();
cur_col = fmt->tab_cols_start_offset + col = (unsigned char *) g_malloc(fmt->tab_col_entry_size);
cur_pos = fmt->tab_cols_start_offset +
(table->num_real_idxs * fmt->tab_ridx_entry_size); (table->num_real_idxs * fmt->tab_ridx_entry_size);
/* new code based on patch submitted by Tim Nelson 2000.09.27 */ /* new code based on patch submitted by Tim Nelson 2000.09.27 */
@@ -179,66 +179,51 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
for (i=0;i<table->num_cols;i++) { for (i=0;i<table->num_cols;i++) {
#ifdef MDB_DEBUG #ifdef MDB_DEBUG
/* printf("column %d\n", i); /* printf("column %d\n", i);
buffer_dump(mdb->pg_buf, cur_col ,cur_col + 18); */ buffer_dump(mdb->pg_buf, cur_pos ,cur_pos + 18); */
#endif #endif
memset(&col, 0, sizeof(col)); read_pg_if_n(mdb, col, &cur_pos, fmt->tab_col_entry_size);
cur_pos += fmt->tab_col_entry_size;
pcol = (MdbColumn *) g_malloc0(sizeof(MdbColumn));
read_pg_if(mdb, &cur_col, 0); pcol->col_type = col[0];
col.col_type = mdb->pg_buf[cur_col];
read_pg_if(mdb, &cur_col, fmt->col_num_offset); // col_num_offset == 1 or 5 // col_num_offset == 1 or 5
col.col_num = mdb->pg_buf[cur_col + fmt->col_num_offset]; pcol->col_num = col[fmt->col_num_offset];
//fprintf(stdout,"----- column %d -----\n",col.col_num); //fprintf(stdout,"----- column %d -----\n",pcol->col_num);
read_pg_if(mdb, &cur_col, fmt->tab_col_offset_var); // col_var == 3 or 7 // col_var == 3 or 7
low_byte = mdb->pg_buf[cur_col + fmt->tab_col_offset_var]; pcol->var_col_num = mdb_get_int16(col, fmt->tab_col_offset_var);
read_pg_if(mdb, &cur_col, fmt->tab_col_offset_var + 1); //fprintf(stdout,"var column pos %d\n",pcol->var_col_num);
high_byte = mdb->pg_buf[cur_col + fmt->tab_col_offset_var + 1];
col.var_col_num = high_byte * 256 + low_byte;
//fprintf(stdout,"var column pos %d\n",col.var_col_num);
read_pg_if(mdb, &cur_col, fmt->tab_row_col_num_offset); // col_var == 5 or 9 // col_var == 5 or 9
low_byte = mdb->pg_buf[cur_col + fmt->tab_row_col_num_offset]; pcol->row_col_num = mdb_get_int16(col, fmt->tab_row_col_num_offset);
read_pg_if(mdb, &cur_col, fmt->tab_row_col_num_offset + 1); //fprintf(stdout,"row column num %d\n",pcol->row_col_num);
high_byte = mdb->pg_buf[cur_col + fmt->tab_row_col_num_offset + 1];
col.row_col_num = high_byte * 256 + low_byte;
//fprintf(stdout,"row column num %d\n",col.row_col_num);
/* FIXME: can this be right in Jet3 and Jet4? */ /* FIXME: can this be right in Jet3 and Jet4? */
if (col.col_type == MDB_NUMERIC) { if (pcol->col_type == MDB_NUMERIC) {
read_pg_if(mdb, &cur_col, 11); pcol->col_prec = col[11];
col.col_prec = mdb->pg_buf[cur_col + 11]; pcol->col_scale = col[12];
read_pg_if(mdb, &cur_col, 12);
col.col_scale = mdb->pg_buf[cur_col + 12];
} }
read_pg_if(mdb, &cur_col, fmt->col_fixed_offset); // col_fixed_offset == 13 or 15 // col_fixed_offset == 13 or 15
col.is_fixed = mdb->pg_buf[cur_col + fmt->col_fixed_offset] & pcol->is_fixed = col[fmt->col_fixed_offset] & 0x01 ? 1 : 0;
0x01 ? 1 : 0;
read_pg_if(mdb, &cur_col, fmt->tab_col_offset_fixed); // col_fixed_offset == 13 or 15 // col_fixed_offset == 13 or 15
low_byte = mdb->pg_buf[cur_col + fmt->tab_col_offset_fixed]; pcol->fixed_offset = mdb_get_int16(col, fmt->tab_col_offset_fixed);
read_pg_if(mdb, &cur_col, fmt->tab_col_offset_fixed + 1); //fprintf(stdout,"fixed column offset %d\n",pcol->fixed_offset);
high_byte = mdb->pg_buf[cur_col + fmt->tab_col_offset_fixed + 1]; //fprintf(stdout,"col type %s\n",pcol->is_fixed ? "fixed" : "variable");
col.fixed_offset = high_byte * 256 + low_byte;
//fprintf(stdout,"fixed column offset %d\n",col.fixed_offset);
//fprintf(stdout,"col type %s\n",col.is_fixed ? "fixed" : "variable");
if (col.col_type != MDB_BOOL) { if (pcol->col_type != MDB_BOOL) {
read_pg_if(mdb, &cur_col, fmt->col_size_offset); // col_size_offset == 16 or 23 // col_size_offset == 16 or 23
low_byte = mdb->pg_buf[cur_col + fmt->col_size_offset]; pcol->col_size = mdb_get_int16(col, fmt->col_size_offset);
read_pg_if(mdb, &cur_col, fmt->col_size_offset + 1); } else {
high_byte = mdb->pg_buf[cur_col + fmt->col_size_offset + 1]; pcol->col_size=0;
col.col_size += high_byte * 256 + low_byte; }
} else
col.col_size=0;
pcol = g_memdup(&col, sizeof(MdbColumn));
slist = g_slist_insert_sorted(slist,pcol,(GCompareFunc)mdb_col_comparer); slist = g_slist_insert_sorted(slist,pcol,(GCompareFunc)mdb_col_comparer);
cur_col += fmt->tab_col_entry_size;
} }
cur_name = cur_col; g_free (col);
/* /*
** column names ** column names
@@ -247,56 +232,22 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
/* fetch the column */ /* fetch the column */
pcol = g_slist_nth_data (slist, i); pcol = g_slist_nth_data (slist, i);
/* we have reached the end of page */
read_pg_if(mdb, &cur_name, 0);
name_sz = mdb->pg_buf[cur_name];
if (IS_JET4(mdb)) { if (IS_JET4(mdb)) {
/* FIX ME - for now just skip the high order byte */ char *tmp_buf;
cur_name += 2; name_sz = read_pg_if_16(mdb, &cur_pos);
/* determine amount of name on this page */ cur_pos += 2;
len = ((cur_name + name_sz) > fmt->pg_size) ? tmp_buf = (char *) g_malloc(name_sz);
fmt->pg_size - cur_name : read_pg_if_n(mdb, tmp_buf, &cur_pos, name_sz);
name_sz; mdb_unicode2ascii(mdb, tmp_buf, 0, name_sz, pcol->name);
g_free(tmp_buf);
/* strip high order (second) byte from unicode string */ cur_pos += name_sz;
for (j=0;j<len;j+=2) {
pcol->name[j/2] = mdb->pg_buf[cur_name + j];
}
/* name wrapped over page */
if (len < name_sz) {
/* read the next pg */
mdb_read_pg(mdb, mdb_pg_get_int32(mdb,4));
cur_name = 8 - (fmt->pg_size - cur_name);
/* get the rest of the name */
for (j=len;j<name_sz;j++) {
if (!(j%2))
pcol->name[j/2] = mdb->pg_buf[cur_name + j];
}
}
pcol->name[name_sz/2]='\0';
cur_name += name_sz;
} else if (IS_JET3(mdb)) { } else if (IS_JET3(mdb)) {
/* determine amount of name on this page */ read_pg_if(mdb, &cur_pos, 0);
len = ((cur_name + name_sz) > fmt->pg_size) ? name_sz = mdb->pg_buf[cur_pos];
fmt->pg_size - cur_name : cur_pos++;
name_sz; read_pg_if_n(mdb, pcol->name, &cur_pos, name_sz);
if (len) {
memcpy(pcol->name, &mdb->pg_buf[cur_name+1], len);
}
/* name wrapped over page */
if (len < name_sz) {
/* read the next pg */
mdb_read_pg(mdb, mdb_pg_get_int32(mdb,4));
cur_name = 8 - (fmt->pg_size - cur_name);
/* get the rest of the name */
memcpy(&pcol->name[len], &mdb->pg_buf[cur_name], name_sz - len);
}
pcol->name[name_sz]='\0'; pcol->name[name_sz]='\0';
cur_pos += name_sz;
cur_name += name_sz + 1;
} else { } else {
fprintf(stderr,"Unknown MDB version\n"); fprintf(stderr,"Unknown MDB version\n");
} }
@@ -309,7 +260,7 @@ GPtrArray *mdb_read_columns(MdbTableDef *table)
g_slist_free(slist); g_slist_free(slist);
table->index_start = cur_name; table->index_start = cur_pos;
return table->columns; return table->columns;
} }