From c9712f656b8b05602382dbe9f055e5118ecefdf3 Mon Sep 17 00:00:00 2001 From: Alex 'AdUser' Z Date: Thu, 9 Apr 2015 15:16:25 +1000 Subject: [PATCH] * sampler.c : improved usage --- src/sampler.c | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/src/sampler.c b/src/sampler.c index 6e025c2..328b836 100644 --- a/src/sampler.c +++ b/src/sampler.c @@ -3,22 +3,44 @@ #include "bitmap.h" #include "sample.h" +void usage() { + puts("Usage: imdb-sample "); + exit(EXIT_FAILURE); +} + int main(int argc, char **argv) { + imdb_t db; imdb_rec_t rec; - if (argc < 2) { - puts("Usage: sampler-test "); - exit(EXIT_FAILURE); + memset(&db, 0x0, sizeof(imdb_t)); + memset(&rec, 0x0, sizeof(imdb_rec_t)); + + if (argc < 4) + usage(); + + rec.num = strtoll(argv[2], NULL, 10); + if (errno != 0) { + puts("arg 1 not a number"); + usage(); } - memset(&rec, 0x0, sizeof(imdb_rec_t)); + if (imdb_open(&db, argv[1]) != 0) { + puts(db.errstr); + usage(); + } - if (imdb_sample(&rec, argv[1]) != 0) { + if (imdb_sample(&rec, argv[3]) != 0) { puts("sampler failure"); - exit(EXIT_FAILURE); + usage(); + } + + if(imdb_write_rec(&db, &rec) < 1) { + puts(db.errstr); + usage(); } + imdb_close(&db); bitmap_print(&rec.data[REC_OFF_BM]); exit(EXIT_SUCCESS);