From d679458d803052bf8dcfdc3ae41b191827cbacea Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 28 May 2015 15:04:28 +1000 Subject: [PATCH] * -W option to imdb-query --- src/imdb-query.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/imdb-query.c b/src/imdb-query.c index 4e75b05..6d3df8b 100644 --- a/src/imdb-query.c +++ b/src/imdb-query.c @@ -34,6 +34,8 @@ void usage(int exitcode) { " -S Search for images similar ot this sample\n" " -U Show db usage map, entries per column\n" " Special case - 0, output will be single line\n" +" -W , Show usage map starting from , but no more\n" +" than entries (limit)\n" ); exit(exitcode); } @@ -105,6 +107,17 @@ int db_usage_map(imdb_db_t *db, unsigned short int cols) return 0; } +int db_usage_slice(imdb_db_t *db, uint64_t offset, uint16_t limit) +{ + char *map = NULL; + + limit = imdb_usage_slice(db, &map, offset, limit); + puts(map); + FREE(map); + + return 0; +} + int rec_bitmap(imdb_db_t *db, uint64_t number) { imdb_rec_t rec; @@ -162,7 +175,7 @@ int rec_diff(imdb_db_t *db, uint64_t a, uint64_t b, unsigned short int showmap) int main(int argc, char **argv) { - enum { undef, search, bitmap, usage_map, diff } mode = undef; + enum { undef, search, bitmap, usage_map, usage_slice, diff } mode = undef; const char *db_path = NULL; float maxdiff = 0.10; unsigned short int cols = 64, map = 0, ret = 0; @@ -176,7 +189,7 @@ int main(int argc, char **argv) if (argc < 3) usage(EXIT_FAILURE); - while ((opt = getopt(argc, argv, "b:t:B:C:D:S:U:")) != -1) { + while ((opt = getopt(argc, argv, "b:t:B:C:D:S:U:W:")) != -1) { switch (opt) { case 'b' : db_path = optarg; @@ -212,6 +225,13 @@ int main(int argc, char **argv) if (cols >= 256) cols = 100; break; + case 'W' : + mode = usage_slice; + if ((c = strchr(optarg, ',')) == NULL) + usage(EXIT_FAILURE); + a = atoll(optarg); + b = atoll(c + 1); + break; default : usage(EXIT_FAILURE); break; @@ -246,6 +266,9 @@ int main(int argc, char **argv) case usage_map : ret = db_usage_map(&db, cols); break; + case usage_slice : + ret = db_usage_slice(&db, a, b); + break; case diff : if (a <= 0 || b <= 0) { fprintf(stderr, "both numbers must be set\n");