[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 20/22] tools/utils: add wrapper for readfile()/readdata() functions
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@xxxxxxx> --- tools/libs/util/libxlu_cfg.c | 47 ++++++++++++++++++++++--------- tools/libs/util/libxlu_internal.h | 6 ++++ 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/tools/libs/util/libxlu_cfg.c b/tools/libs/util/libxlu_cfg.c index 3c0703f9df..cb99b0aab0 100644 --- a/tools/libs/util/libxlu_cfg.c +++ b/tools/libs/util/libxlu_cfg.c @@ -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); diff --git a/tools/libs/util/libxlu_internal.h b/tools/libs/util/libxlu_internal.h index cc98efba27..34c6c7a443 100644 --- a/tools/libs/util/libxlu_internal.h +++ b/tools/libs/util/libxlu_internal.h @@ -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*/ -- (\___(\___(\______ --=> 8-) EHM <=-- ______/)___/)___/) \BS ( | ehem+sigmsg@xxxxxxx PGP 87145445 | ) / \_CS\ | _____ -O #include <stddisclaimer.h> O- _____ | / _/ 8A19\___\_|_/58D2 7E3D DDF4 7BA6 <-PGP-> 41D1 B375 37D0 8714\_|_/___/5445
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |