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

29
src/imdb-write.c

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

Loading…
Cancel
Save