From f0624ccf890d769c658c846dac1174ccb7eced22 Mon Sep 17 00:00:00 2001 From: Quantum Date: Fri, 27 Aug 2021 02:30:17 -0400 Subject: [PATCH] [common] option: implement ability to dump config into ini This is intended to be used for saving filter options into an ini file. --- common/include/common/option.h | 4 ++++ common/src/option.c | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/common/include/common/option.h b/common/include/common/option.h index 8f3dcdf9..324f72de 100644 --- a/common/include/common/option.h +++ b/common/include/common/option.h @@ -22,6 +22,7 @@ #define _H_COMMON_OPTION_ #include +#include #include "common/stringlist.h" enum OptionType @@ -94,6 +95,9 @@ bool option_validate(void); // print out the options, help, and their current values void option_print(void); +// dump the options in ini format into the file +bool option_dump(FILE * file, const char * module); + // final cleanup void option_free(void); diff --git a/common/src/option.c b/common/src/option.c index 8cd9065a..8c0ec93e 100644 --- a/common/src/option.c +++ b/common/src/option.c @@ -747,6 +747,25 @@ void option_print(void) } } +// dump the options in ini format into the file +bool option_dump(FILE * file, const char * module) +{ + fprintf(file, "[%s]\n", module); + + for (int i = 0; i < state.oCount; ++i) + { + struct Option * o = state.options[i]; + if (strcasecmp(o->module, module) != 0) + continue; + char * value = o->toString(o); + fprintf(file, "%s=%s\n", o->name, value); + free(value); + } + + fputc('\n', file); + return true; +} + struct Option * option_get(const char * module, const char * name) { for(int i = 0; i < state.oCount; ++i)