Browse Source

* fix utils after prev commit

master
Alex 'AdUser' Z 8 years ago
parent
commit
249df4ae1e
  1. 21
      src/imdb-query.c
  2. 29
      src/imdb-write.c

21
src/imdb-query.c

@ -179,13 +179,12 @@ int main(int argc, char **argv)
const char *db_path = NULL;
float maxdiff = 0.10;
unsigned short int cols = 64, map = 0, ret = 0;
imdb_db_t db;
imdb_db_t *db = NULL;
uint64_t a = 0, b = 0;
char *c = NULL;
int err;
char opt = '\0';
memset(&db, 0x0, sizeof(imdb_db_t));
if (argc < 3)
usage(EXIT_FAILURE);
@ -243,8 +242,8 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE);
}
if (imdb_open(&db, db_path, 0) == -1) {
fprintf(stderr, "database open: %s\n", db.error);
if ((db = imdb_open(db_path, 0, &err)) == NULL) {
fprintf(stderr, "database open: %d\n", err);
exit(EXIT_FAILURE);
}
@ -254,34 +253,34 @@ int main(int argc, char **argv)
fprintf(stderr, "can't parse number\n");
usage(EXIT_FAILURE);
}
ret = search_similar(&db, a, maxdiff);
ret = search_similar(db, a, maxdiff);
break;
case bitmap :
if (a <= 0) {
fprintf(stderr, "can't parse number\n");
usage(EXIT_FAILURE);
}
ret = rec_bitmap(&db, a);
ret = rec_bitmap(db, a);
break;
case usage_map :
ret = db_usage_map(&db, cols);
ret = db_usage_map(db, cols);
break;
case usage_slice :
ret = db_usage_slice(&db, a, b);
ret = db_usage_slice(db, a, b);
break;
case diff :
if (a <= 0 || b <= 0) {
fprintf(stderr, "both numbers must be set\n");
exit(EXIT_FAILURE);
}
ret = rec_diff(&db, a, b, map);
ret = rec_diff(db, a, b, map);
break;
default :
usage(EXIT_SUCCESS);
break;
}
imdb_close(&db);
imdb_close(db);
return ret;
}

29
src/imdb-write.c

@ -25,10 +25,10 @@ int main(int argc, char **argv)
const char *db_path = NULL;
const char *sample = NULL;
const char *c = NULL;
imdb_db_t db;
imdb_db_t *db = NULL;
imdb_rec_t rec;
int err;
memset(&db, 0x0, sizeof(imdb_db_t));
memset(&rec, 0x0, sizeof(imdb_rec_t));
if (argc < 3)
@ -67,8 +67,14 @@ int main(int argc, char **argv)
usage(EXIT_FAILURE);
}
if (mode != init && imdb_open(&db, db_path, 1) != 0) {
fprintf(stderr, "can't open database: %s\n", db.error);
if (mode == init) {
if (!imdb_create(db_path)) {
fprintf(stderr, "database init: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
}
if ((db = imdb_open(db_path, 1, &err)) == NULL) {
fprintf(stderr, "can't open database: %d\n", err);
exit(EXIT_FAILURE);
}
@ -80,28 +86,25 @@ int main(int argc, char **argv)
fprintf(stderr, "sampler failure\n");
exit(EXIT_FAILURE);
}
if (imdb_write_rec(&db, &rec) < 1) {
fprintf(stderr, "%s\n", db.error);
if (imdb_write_rec(db, &rec) < 1) {
fprintf(stderr, "%s\n", db->error);
exit(EXIT_FAILURE);
}
break;
case del :
if (imdb_write_rec(&db, &rec) < 1) {
fprintf(stderr, "%s\n", db.error);
if (imdb_write_rec(db, &rec) < 1) {
fprintf(stderr, "%s\n", db->error);
exit(EXIT_FAILURE);
}
break;
case init :
if (!imdb_create(db_path)) {
fprintf(stderr, "database init: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
/* this case already handled above */
break;
default:
usage(EXIT_FAILURE);
break;
}
imdb_close(&db);
imdb_close(db);
exit(EXIT_SUCCESS);
}

Loading…
Cancel
Save