Browse Source

* bitmap operation

master
Alex 'AdUser' Z 11 years ago
parent
commit
eefdbd2e15
  1. 6
      src/Makefile
  2. 34
      src/main.c

6
src/Makefile

@ -1,13 +1,13 @@
CFLAGS=-Wall -Wextra -O0 -g -ggdb -pedantic CFLAGS=-Wall -Wextra -O0 -g -ggdb -pedantic
all: test all: util
%.o: %.c %.o: %.c
gcc $(CFLAGS) -c $< gcc $(CFLAGS) -c $<
test: main.c database.o bitmap.o util: main.c database.o bitmap.o
gcc $(CFLAGS) -o $@ $^ gcc $(CFLAGS) -o $@ $^
clean: clean:
rm -f *.o rm -f *.o
rm -f test rm -f util

34
src/main.c

@ -58,13 +58,39 @@ int db_search(db_t *db, rec_t *sample, float tresh, match_t **matches)
return found; return found;
} }
int rec_bitmap(db_t *db, rec_t *sample)
{
uint16_t row;
uint8_t i, j;
assert(db != NULL);
assert(sample != NULL);
if (db_rd_rec(db, sample) != 1)
return -1;
for (i = 0; i < 16; i++) {
row = *(((uint16_t *) sample->data) + i);
for (j = 0; j < 16; j++) {
putchar((row & 1) == 1 ? '1' : '0');
row >>= 1;
}
putchar('\n');
}
return 0;
}
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
db_t db; db_t db;
rec_t sample; rec_t sample;
if (argc < 3) { if (argc < 3) {
printf("Usage: test <path> <int>\n"); printf(
"Usage:\n"
" util search <num>\n"
" util bitmap <num>\n"
);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -74,13 +100,17 @@ int main(int argc, char **argv)
assert(sample.num > 0); assert(sample.num > 0);
if (db_open(&db, argv[1]) == -1) { if (db_open(&db, "test.db") == -1) {
printf("%s\n", db.errstr); printf("%s\n", db.errstr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (strcmp(argv[1], "search") == 0)
db_search(&db, &sample, 0.15, NULL); db_search(&db, &sample, 0.15, NULL);
if (strcmp(argv[1], "bitmap") == 0)
rec_bitmap(&db, &sample);
db_close(&db); db_close(&db);
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);

Loading…
Cancel
Save