Warnings fixes and better use of GLib

This commit is contained in:
whydoubt
2004-07-17 07:48:11 +00:00
parent e121a82946
commit 4a245f2af7
8 changed files with 74 additions and 75 deletions

View File

@@ -30,7 +30,7 @@
char *mdb_money_to_string(MdbHandle *mdb, int start, char *s);
static int _mdb_attempt_bind(MdbHandle *mdb,
MdbColumn *col, unsigned char isnull, int offset, int len);
char *mdb_num_to_string(MdbHandle *mdb, int start, int datatype, int prec, int scale);
static char *mdb_num_to_string(MdbHandle *mdb, int start, int datatype, int prec, int scale);
int mdb_copy_ole(MdbHandle *mdb, char *dest, int start, int size);
static char date_fmt[64] = "%x %X";
@@ -137,7 +137,7 @@ mdb_xfer_bound_bool(MdbHandle *mdb, MdbColumn *col, int value)
}
static int mdb_xfer_bound_ole(MdbHandle *mdb, int start, MdbColumn *col, int len)
{
int ret;
int ret = 0;
if (len) {
col->cur_value_start = start;
col->cur_value_len = len;
@@ -168,17 +168,18 @@ int ret;
col->cur_value_len = 0;
}
if (col->bind_ptr) {
if (len) {
//fprintf(stdout,"len %d size %d\n",len, col->col_size);
if (col->col_type == MDB_NUMERIC) {
strcpy(col->bind_ptr,
mdb_num_to_string(mdb, start, col->col_type, col->col_prec, col->col_scale));
} else {
strcpy(col->bind_ptr,
mdb_col_to_string(mdb, mdb->pg_buf, start, col->col_type, len));
}
if (!len) {
strcpy(col->bind_ptr, "");
} else if (col->col_type == MDB_NUMERIC) {
//fprintf(stdout,"len %d size %d\n",len, col->col_size);
char *str = mdb_num_to_string(mdb, start, col->col_type,
col->col_prec, col->col_scale);
strcpy(col->bind_ptr, str);
g_free(str);
} else {
strcpy(col->bind_ptr, "");
//fprintf(stdout,"len %d size %d\n",len, col->col_size);
strcpy(col->bind_ptr,
mdb_col_to_string(mdb, mdb->pg_buf, start, col->col_type, len));
}
ret = strlen(col->bind_ptr);
if (col->len_ptr) {
@@ -188,7 +189,7 @@ int ret;
}
return 0;
}
int mdb_read_row(MdbTableDef *table, int row)
int mdb_read_row(MdbTableDef *table, unsigned int row)
{
MdbHandle *mdb = table->entry->mdb;
MdbFormatConstants *fmt = mdb->fmt;
@@ -436,9 +437,9 @@ static int _mdb_attempt_bind(MdbHandle *mdb,
int
mdb_read_next_dpg_by_map0(MdbTableDef *table)
{
MdbCatalogEntry *entry = table->entry;
MdbHandle *mdb = entry->mdb;
int pgnum, i, bitn;
MdbCatalogEntry *entry = table->entry;
MdbHandle *mdb = entry->mdb;
unsigned int pgnum, i, bitn;
pgnum = mdb_get_int32(table->usage_map,1);
/* the first 5 bytes of the usage map mean something */
@@ -951,8 +952,7 @@ guint16 len;
len = row_stop - row_start;
strncat(text, &mdb->pg_buf[row_start+4],
strlen(text) + len - 4 > MDB_BIND_SIZE ?
MDB_BIND_SIZE - strlen(text) :
len - 4);
MDB_BIND_SIZE - strlen(text) : len - 4);
/* find next lval page */
memo_row = mdb->pg_buf[row_start];
@@ -968,31 +968,19 @@ guint16 len;
*/
}
}
char *
static char *
mdb_num_to_string(MdbHandle *mdb, int start, int datatype, int prec, int scale)
{
/* FIX ME -- not thread safe */
static char text[MDB_BIND_SIZE];
char tmpbuf[MDB_BIND_SIZE];
char mask[20];
gint32 l;
char *text;
gint32 l;
l = mdb->pg_buf[start+16] * 256 * 256 * 256 +
mdb->pg_buf[start+15] * 256 * 256 +
mdb->pg_buf[start+14] * 256 +
mdb->pg_buf[start+13];
memcpy(&l, mdb->pg_buf+start+13, 4);
sprintf(mask,"%%0%dld",prec);
sprintf(tmpbuf,mask,l);
//strcpy(text, tmpbuf);
//return text;
if (!scale) {
strcpy(text,tmpbuf);
} else {
memset(text,0,sizeof(text));
strncpy(text,tmpbuf,prec-scale);
strcat(text,".");
strcat(text,&tmpbuf[strlen(tmpbuf)-scale]);
text = (char *) g_malloc(prec+2);
sprintf(text, "%0*" G_GINT32_FORMAT, prec, GINT32_FROM_LE(l));
if (scale) {
memmove(text+prec-scale, text+prec-scale+1, scale+1);
text[prec-scale] = '.';
}
return text;
}

View File

@@ -55,7 +55,7 @@ MdbHandle *mdb = entry->mdb;
GHashTable *mdb_get_column_def(MdbCatalogEntry *entry, int start)
{
GHashTable *hash;
GHashTable *hash = NULL;
MdbHandle *mdb = entry->mdb;
MdbColumnProp prop;
int tmp, pos, col_num, val_len, i;

View File

@@ -38,7 +38,8 @@
*/
int mdb_like_cmp(char *s, char *r)
{
int i, ret;
unsigned int i;
int ret;
mdb_debug(MDB_DEBUG_LIKE, "comparing %s and %s", s, r);
switch (r[0]) {

View File

@@ -339,8 +339,10 @@ guint32 pgnum;
}
if (table->usage_map) {
printf("pages reserved by this object\n");
printf("usage map pg %lu\n", table->map_base_pg);
printf("free map pg %lu\n", table->freemap_base_pg);
printf("usage map pg %" G_GUINT32_FORMAT "\n",
table->map_base_pg);
printf("free map pg %" G_GUINT32_FORMAT "\n",
table->freemap_base_pg);
pgnum = mdb_get_int32(table->usage_map,1);
/* the first 5 bytes of the usage map mean something */
coln = 0;
@@ -348,10 +350,12 @@ guint32 pgnum;
for (bitn=0;bitn<8;bitn++) {
if (table->usage_map[i] & 1 << bitn) {
coln++;
printf("%6lu ",(long unsigned) pgnum);
printf("%6" G_GUINT32_FORMAT, pgnum);
if (coln==10) {
printf("\n");
coln = 0;
} else {
printf(" ");
}
}
pgnum++;

View File

@@ -642,7 +642,8 @@ mdb_update_index(MdbTableDef *table, MdbIndex *idx, int num_fields, MdbField *fi
mdb_index_find_row(mdb, idx, chain, pgnum, rownum);
printf("chain depth = %d\n", chain->cur_depth);
printf("pg = %lu\n", chain->pages[chain->cur_depth-1].pg);
printf("pg = %" G_GUINT32_FORMAT "\n",
chain->pages[chain->cur_depth-1].pg);
//mdb_copy_index_pg(table, idx, &chain->pages[chain->cur_depth-1]);
mdb_add_row_to_leaf_pg(table, idx, &chain->pages[chain->cur_depth-1], idx_fields);
@@ -915,7 +916,8 @@ mdb_copy_index_pg(MdbTableDef *table, MdbIndex *idx, MdbIndexPage *ipg)
mdb_index_swap_n(&mdb->pg_buf[ipg->offset + 1], col->col_size, key_hash);
key_hash[col->col_size - 1] &= 0x7f;
printf("length = %d\n", ipg->len);
printf("iflag = %d pg = %lu row = %d\n", iflag, pg, row);
printf("iflag = %d pg = %" G_GUINT32_FORMAT
" row = %" G_GUINT16_FORMAT "\n", iflag, pg, row);
buffer_dump(mdb->pg_buf, ipg->offset, ipg->offset + ipg->len - 1);
buffer_dump(mdb->pg_buf, ipg->offset + 1, ipg->offset + col->col_size);
buffer_dump(key_hash, 0, col->col_size - 1);