Browse Source

* move init to imdb-write

master
Alex 'AdUser' Z 10 years ago
parent
commit
85cb3ee694
  1. 54
      src/imdb-query.c
  2. 20
      src/imdb-write.c

54
src/imdb-query.c

@ -28,7 +28,6 @@ void usage(int exitcode) {
" -t <int> Maximum difference pct (0 - 50, default: 10%)\n" " -t <int> Maximum difference pct (0 - 50, default: 10%)\n"
); );
puts( puts(
" -I Create database (init)\n"
" -B <num> Show bitmap for this sample\n" " -B <num> Show bitmap for this sample\n"
" -C <a>,<b> Show difference percent for this samples\n" " -C <a>,<b> Show difference percent for this samples\n"
" -D <a>,<b> Show difference bitmap for this samples\n" " -D <a>,<b> Show difference bitmap for this samples\n"
@ -154,7 +153,7 @@ int rec_diff(imdb_db_t *db, uint64_t a, uint64_t b, unsigned short int showmap)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
enum { undef, init, search, bitmap, usage_map, diff } mode = undef; enum { undef, search, bitmap, usage_map, diff } mode = undef;
const char *db_path = NULL; const char *db_path = NULL;
float maxdiff = 0.10; float maxdiff = 0.10;
unsigned short int cols = 64, map = 0; unsigned short int cols = 64, map = 0;
@ -168,7 +167,7 @@ int main(int argc, char **argv)
if (argc < 3) if (argc < 3)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
while ((opt = getopt(argc, argv, "b:t:IB:C:D:S:U:")) != -1) { while ((opt = getopt(argc, argv, "b:t:B:C:D:S:U:")) != -1) {
switch (opt) { switch (opt) {
case 'b' : case 'b' :
db_path = optarg; db_path = optarg;
@ -181,9 +180,6 @@ int main(int argc, char **argv)
} }
maxdiff /= 100; maxdiff /= 100;
break; break;
case 'I' :
mode = init;
break;
case 'B' : case 'B' :
mode = bitmap; mode = bitmap;
a = atoll(optarg); a = atoll(optarg);
@ -213,36 +209,40 @@ int main(int argc, char **argv)
} }
} }
if ((mode == search || mode == bitmap) && a <= 0)
usage(EXIT_FAILURE);
if (mode == diff && (a <= 0 || b <= 0))
usage(EXIT_FAILURE);
if (mode == init) {
if (imdb_init(&db, db_path) == -1) {
printf("database init: %s\n", db.errstr);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
if (imdb_open(&db, db_path, 0) == -1) { if (imdb_open(&db, db_path, 0) == -1) {
printf("database open: %s\n", db.errstr); printf("database open: %s\n", db.errstr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (mode == search) switch (mode) {
case search :
if (a <= 0) {
puts("can't parse number");
usage(EXIT_FAILURE);
}
search_similar(&db, a, maxdiff); search_similar(&db, a, maxdiff);
break;
if (mode == bitmap) case bitmap :
if (a <= 0) {
puts("can't parse number");
usage(EXIT_FAILURE);
}
rec_bitmap(&db, a); rec_bitmap(&db, a);
break;
if (mode == usage_map) case usage_map :
db_usage_map(&db, cols); db_usage_map(&db, cols);
break;
if (mode == diff) case diff :
if (a <= 0 || b <= 0) {
puts("both numbers must be set");
exit(EXIT_FAILURE);
}
rec_diff(&db, a, b, map); rec_diff(&db, a, b, map);
break;
default :
usage(EXIT_SUCCESS);
break;
}
imdb_close(&db); imdb_close(&db);

20
src/imdb-write.c

@ -13,13 +13,14 @@ void usage(int exitcode) {
puts( puts(
" -A <num>,<path> Add sample from 'path' as record 'num'\n" " -A <num>,<path> Add sample from 'path' as record 'num'\n"
" -D <num> Delete record <num>\n" " -D <num> Delete record <num>\n"
" -I Create database (init)\n"
); );
exit(exitcode); exit(exitcode);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
enum { undef, add, del } mode = undef; enum { undef, add, del, init } mode = undef;
char opt; char opt;
const char *db_path = NULL; const char *db_path = NULL;
const char *sample = NULL; const char *sample = NULL;
@ -33,7 +34,7 @@ int main(int argc, char **argv)
if (argc < 3) if (argc < 3)
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
while ((opt = getopt(argc, argv, "b:A:D:")) != -1) { while ((opt = getopt(argc, argv, "b:A:D:I")) != -1) {
switch (opt) { switch (opt) {
case 'b' : case 'b' :
db_path = optarg; db_path = optarg;
@ -52,16 +53,21 @@ int main(int argc, char **argv)
mode = del; mode = del;
rec.num = atoll(optarg); rec.num = atoll(optarg);
break; break;
case 'I' :
mode = init;
break;
default : default :
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
break; break;
} }
} }
if (db_path == NULL) if (db_path == NULL) {
puts("db path not set");
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
}
if (imdb_open(&db, db_path, 1) != 0) { if (mode != init && imdb_open(&db, db_path, 1) != 0) {
puts(db.errstr); puts(db.errstr);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -86,6 +92,12 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
break; break;
case init :
if (imdb_init(&db, db_path) == -1) {
printf("database init: %s\n", db.errstr);
exit(EXIT_FAILURE);
}
break;
default: default:
usage(EXIT_FAILURE); usage(EXIT_FAILURE);
break; break;

Loading…
Cancel
Save