From eefdbd2e153f2ecdca904b99020afafb5d9367cb Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 3 Apr 2014 11:42:35 +1100 Subject: [PATCH] * bitmap operation --- src/Makefile | 6 +++--- src/main.c | 36 +++++++++++++++++++++++++++++++++--- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Makefile b/src/Makefile index 9abe92a..d51acf4 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,13 +1,13 @@ CFLAGS=-Wall -Wextra -O0 -g -ggdb -pedantic -all: test +all: util %.o: %.c gcc $(CFLAGS) -c $< -test: main.c database.o bitmap.o +util: main.c database.o bitmap.o gcc $(CFLAGS) -o $@ $^ clean: rm -f *.o - rm -f test + rm -f util diff --git a/src/main.c b/src/main.c index f53b045..35dfdcf 100644 --- a/src/main.c +++ b/src/main.c @@ -58,13 +58,39 @@ int db_search(db_t *db, rec_t *sample, float tresh, match_t **matches) 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) { db_t db; rec_t sample; if (argc < 3) { - printf("Usage: test \n"); + printf( +"Usage:\n" +" util search \n" +" util bitmap \n" +); exit(EXIT_FAILURE); } @@ -74,12 +100,16 @@ int main(int argc, char **argv) assert(sample.num > 0); - if (db_open(&db, argv[1]) == -1) { + if (db_open(&db, "test.db") == -1) { printf("%s\n", db.errstr); exit(EXIT_FAILURE); } - db_search(&db, &sample, 0.15, NULL); + if (strcmp(argv[1], "search") == 0) + db_search(&db, &sample, 0.15, NULL); + + if (strcmp(argv[1], "bitmap") == 0) + rec_bitmap(&db, &sample); db_close(&db);