@@ -110,39 +110,58 @@ static void parse(CfgParseContext *ctx) {
}
}
-int xlu_cfg_readfile(XLU_Config *cfg, const char *real_filename) {
- FILE *f = 0;
+int xlu_cfg_readfile(XLU_Config *cfg, const char *name)
+{
+ FILE *file;
+ int ret;
+
+ file = fopen(name, "r");
+ if (file) {
+ ret = xlu__cfg_readfile(cfg, cfg->report, cfg->config_source,
+ &cfg->settings, file, name);
+ fclose(file);
+ } else {
+ ret = errno;
+ fprintf(cfg->report,"%s: unable to open configuration file: %s\n",
+ name, strerror(ret));
+ }
+
+ return ret;
+}
+
+int xlu__cfg_readfile(XLU_Config *cfg, FILE *msgfile, const char *msgprefix,
+ XLU_ConfigSetting **psettings, FILE *f, const char *name)
+{
int e;
CfgParseContext ctx;
- e = ctx_prep(&ctx, cfg, &cfg->settings);
+ e = ctx_prep(&ctx, cfg, psettings);
if (e) { ctx.err= e; goto xe; }
- f= fopen(real_filename, "r");
- if (!f) {
- ctx.err = errno;
- fprintf(cfg->report,"%s: unable to open configuration file: %s\n",
- real_filename, strerror(e));
- goto xe;
- }
-
xlu__cfg_yyrestart(f, ctx.scanner);
parse(&ctx);
xe:
ctx_dispose(&ctx);
- if (f) fclose(f);
return ctx.err;
}
-int xlu_cfg_readdata(XLU_Config *cfg, const char *data, int length) {
+int xlu_cfg_readdata(XLU_Config *cfg, const char *data, int length)
+{
+ return xlu__cfg_readdata(cfg, cfg->report, cfg->config_source,
+ &cfg->settings, data, length);
+}
+
+int xlu__cfg_readdata(XLU_Config *cfg, FILE *msgfile, const char *msgprefix,
+ XLU_ConfigSetting **psettings, const char *data, int length)
+{
int e;
YY_BUFFER_STATE buf= 0;
CfgParseContext ctx;
- e = ctx_prep(&ctx, cfg, &cfg->settings);
+ e = ctx_prep(&ctx, cfg, psettings);
if (e) { ctx.err= e; goto xe; }
buf = xlu__cfg_yy_scan_bytes(data, length, ctx.scanner);
@@ -39,6 +39,12 @@ extern int xlu_cfg_printf(const XLU_Config *cfg, const char *format, ...)
* Internals for file parser *only*, NOT to be used by other parsing/lexing
*/
extern void xlu__cfg_set_free(XLU_ConfigSetting *set);
+extern int xlu__cfg_readfile(XLU_Config *cfg, FILE *msgfile,
+ const char *msgprefix, XLU_ConfigSetting **psettings, FILE *file,
+ const char *name);
+extern int xlu__cfg_readdata(XLU_Config *cfg, FILE *msgfile,
+ const char *msgprefix, XLU_ConfigSetting **psettings, const char *data,
+ int length);
#endif /*LIBXLU_INTERNAL_H*/
These functions needs to cross the boundary between core and lower-layer. As such split them in two. Pass most of the values from XLU_Config as they can be used by the lower-layer. Signed-off-by: Elliott Mitchell <ehem+xen@m5p.com> --- tools/libs/util/libxlu_cfg.c | 47 ++++++++++++++++++++++--------- tools/libs/util/libxlu_internal.h | 6 ++++ 2 files changed, 39 insertions(+), 14 deletions(-)