From 26b75830ab942bc9116e8769652afa24d0d9550d Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Mon, 10 Aug 2015 18:00:07 +0100 Subject: Add dry run feature --- README | 28 ++++++++++++++++------------ src/nsgenbind.c | 6 +++++- src/options.h | 2 ++ src/utils.c | 17 +++++++++++++++-- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/README b/README index a6efd38..f2a8bf3 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ nsgenbind This is a tool to generate JavaScript to DOM bindings from w3c webidl files and a binding configuration file. -building +Building -------- The tool requires bison and flex as pre-requisites @@ -12,29 +12,33 @@ The tool requires bison and flex as pre-requisites Commandline ----------- -nsgenbind [-v] [-g] [-D] [-W] [-I idlpath] inputfile outputdir +nsgenbind [-v] [-n] [-g] [-D] [-W] [-I idlpath] inputfile outputdir -v -The verbose switch makes the tool verbose about what operations it is -performing instead of the default of only reporting errors. + The verbose switch makes the tool verbose about what operations it + is performing instead of the default of only reporting errors. + +-n + The tool will not generate any output but will perform all other + operations as if it was. Useful for debugging bindings -g -The generated code will be augmented with runtime debug logging so it -can be traced + The generated code will be augmented with runtime debug logging so + it can be traced -D -The tool will generate output to allow debugging of output conversion. -This includes dumps of the binding and IDL files AST + The tool will generate output to allow debugging of output + conversion. This includes dumps of the binding and IDL files AST -W -This switch will make the tool generate warnings about various issues -with the binding or IDL files being processed. + This switch will make the tool generate warnings about various + issues with the binding or IDL files being processed. -I -An additional search path may be given so idl files can be located. + An additional search path may be given so idl files can be located. The tool requires a binding file as input and an output directory in -which to place its output. + which to place its output. Debug output 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); -- cgit v1.2.3