Browse Source

* util.c : db_usage_map -> simple wrapper

master
Alex 'AdUser' Z 10 years ago
parent
commit
1efe76d1f3
  1. 52
      src/util.c

52
src/util.c

@ -67,38 +67,34 @@ int search_similar(imdb_t *db, imdb_rec_t *sample, float tresh)
int db_usage_map(imdb_t *db, unsigned short int cols) int db_usage_map(imdb_t *db, unsigned short int cols)
{ {
const int blk_size = 4096; char *map = NULL;
unsigned int i, j = 0; char *m = NULL;
unsigned char *p, *t; char row[256];
char buf[256]; uint64_t records;
imdb_block_t blk; uint8_t rest = 0;
assert(db != NULL); memset(row, 0x0, sizeof(char) * 256);
assert(cols <= 256);
records = imdb_records_count(db);
memset(&blk, 0x0, sizeof(imdb_block_t)); CALLOC(map, records + 1, sizeof(char));
memset(buf, 0x0, sizeof(char) * 256);
if ((records = imdb_usage_map(db, map)) == 0) {
blk.start = 1; printf("Cant get database usage map\n");
blk.records = blk_size; FREE(map);
exit(1);
while (imdb_read_blk(db, &blk) > 0) {
p = blk.data;
for (i = 0; i < blk.records; i++, p += IMDB_REC_LEN) {
t = p + REC_OFF_RU;
buf[j] = (*t == 0xFF) ? CHAR_USED : CHAR_NONE;
if (j++ < cols)
continue;
puts(buf);
memset(buf, 0x0, sizeof(char) * 256);
j = 0;
} }
if (j > 0)
puts(buf); m = map;
FREE(blk.data); while (records) {
blk.start += blk_size; rest = (records > cols) ? cols : records;
memcpy(row, m, rest);
printf("%7d : %s\n", (m - map + 1), row);
m += rest;
records -= rest;
} }
FREE(map);
return 0; return 0;
} }

Loading…
Cancel
Save