diff options
author | Vincent Sanders <vince@kyllikki.org> | 2015-08-10 18:00:07 +0100 |
---|---|---|
committer | Vincent Sanders <vince@kyllikki.org> | 2015-08-10 18:00:07 +0100 |
commit | 26b75830ab942bc9116e8769652afa24d0d9550d (patch) | |
tree | 107f401c7f85f79fb23c242af228cacd18e49e53 /src | |
parent | 63745977ad219ca9474462268651f77e49218956 (diff) | |
download | nsgenbind-26b75830ab942bc9116e8769652afa24d0d9550d.tar.gz nsgenbind-26b75830ab942bc9116e8769652afa24d0d9550d.tar.bz2 |
Add dry run feature
Diffstat (limited to 'src')
-rw-r--r-- | src/nsgenbind.c | 6 | ||||
-rw-r--r-- | src/options.h | 2 | ||||
-rw-r--r-- | src/utils.c | 17 |
3 files changed, 22 insertions, 3 deletions
diff --git a/src/nsgenbind.c b/src/nsgenbind.c index 173f23d..9558b95 100644 --- a/src/nsgenbind.c +++ b/src/nsgenbind.c @@ -39,7 +39,7 @@ static struct options* process_cmdline(int argc, char **argv) return NULL; } - while ((opt = getopt(argc, argv, "vgDW::I:")) != -1) { + while ((opt = getopt(argc, argv, "vngDW::I:")) != -1) { switch (opt) { case 'I': options->idlpath = strdup(optarg); @@ -49,6 +49,10 @@ static struct options* process_cmdline(int argc, char **argv) options->verbose = true; break; + case 'n': + options->dryrun = true; + break; + case 'D': options->debug = true; break; diff --git a/src/options.h b/src/options.h index 02674b7..5b7d73d 100644 --- a/src/options.h +++ b/src/options.h @@ -18,6 +18,8 @@ struct options { bool verbose; /**< verbose processing */ bool debug; /**< debug enabled */ bool dbglog; /**< embed debug logging in output */ + bool dryrun; /**< output is not generated */ + unsigned int warnings; /**< warning flags */ }; diff --git a/src/utils.c b/src/utils.c index 0952744..85d26f2 100644 --- a/src/utils.c +++ b/src/utils.c @@ -48,7 +48,11 @@ FILE *genb_fopen(const char *fname, const char *mode) char *fpath; FILE *filef; - fpath = genb_fpath(fname); + if (options->dryrun) { + fpath = strdup("/dev/null"); + } else { + fpath = genb_fpath(fname); + } filef = fopen(fpath, mode); if (filef == NULL) { @@ -68,7 +72,11 @@ FILE *genb_fopen_tmp(const char *fname) char *fpath; FILE *filef; - fpath = genb_fpath_tmp(fname); + if (options->dryrun) { + fpath = strdup("/dev/null"); + } else { + fpath = genb_fpath_tmp(fname); + } filef = fopen(fpath, "w+"); if (filef == NULL) { @@ -92,6 +100,11 @@ int genb_fclose_tmp(FILE *filef_tmp, const char *fname) size_t trd; size_t frd; + if (options->dryrun) { + fclose(filef_tmp); + return 0; + } + fpath = genb_fpath(fname); tpath = genb_fpath_tmp(fname); |