From 717659ff878f364072136227e03a6ded977ca4f9 Mon Sep 17 00:00:00 2001 From: daniel-k Date: Wed, 22 Nov 2017 15:53:19 +0100 Subject: [PATCH] tools/conf2json: supply input as argument and use path as include dir Passing via stdin does not allow to use the input file path for include lookup, because we only see the stdin file stream from our program. --- tools/conf2json.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/tools/conf2json.c b/tools/conf2json.c index 2b63a18e7..1ed5823a4 100644 --- a/tools/conf2json.c +++ b/tools/conf2json.c @@ -20,6 +20,8 @@ * along with this program. If not, see . *********************************************************************************/ +#include +#include #include #include @@ -28,7 +30,7 @@ void usage() { - printf("Usage: conf2json < input.conf > output.json\n\n"); + printf("Usage: conf2json input.conf > output.json\n\n"); print_copyright(); } @@ -40,22 +42,30 @@ int main(int argc, char *argv[]) config_setting_t *cfg_root; json_t *json; - if (argc != 1) { + if (argc != 2) { usage(); exit(EXIT_FAILURE); } + FILE *f = fopen(argv[1], "r"); + if(f == NULL) + return -1; + + const char *confdir = dirname(argv[1]); + config_init(&cfg); - ret = config_read(&cfg, stdin); + config_set_include_dir(&cfg, confdir); + + ret = config_read(&cfg, f); if (ret != CONFIG_TRUE) - return ret; + return -2; cfg_root = config_root_setting(&cfg); json = config_to_json(cfg_root); if (!json) - return -1; + return -3; ret = json_dumpf(json, stdout, JSON_INDENT(2)); fflush(stdout); if (ret)