int config_read(config_t *config, FILE *stream) { yyscan_t scanner; struct parse_context ctx; int r; /* Reinitialize the config (keep the destructor) */ void (*destructor)(void *) = config->destructor; config_destroy(config); config_init(config); config->destructor = destructor; ctx.config = config; ctx.parent = config->root; ctx.setting = config->root; __config_locale_override(); libconfig_yylex_init(&scanner); libconfig_yyrestart(stream, scanner); r = libconfig_yyparse(scanner, &ctx); libconfig_yylex_destroy(scanner); __config_locale_restore(); return(r == 0 ? CONFIG_TRUE : CONFIG_FALSE); }
void config_write(const config_t *config, FILE *stream) { __config_locale_override(); __config_write_setting(config->root, stream, 0, config->tab_width); __config_locale_restore(); }
static int __config_read(config_t *config, FILE *stream, const char *filename, const char *str) { yyscan_t scanner; struct scan_context scan_ctx; struct parse_context parse_ctx; YY_BUFFER_STATE buffer = NULL; int r; /* Reinitialize the config */ void (*destructor)(void *) = config->destructor; unsigned short tab_width = config->tab_width; unsigned short flags = config->flags; config_destroy(config); config_init(config); config->destructor = destructor; config->tab_width = tab_width; config->flags = flags; parsectx_init(&parse_ctx); parse_ctx.config = config; parse_ctx.parent = config->root; parse_ctx.setting = config->root; __config_locale_override(); scanctx_init(&scan_ctx, filename); scan_ctx.config = config; libconfig_yylex_init_extra(&scan_ctx, &scanner); if(stream) libconfig_yyrestart(stream, scanner); else /* read from string */ buffer = libconfig_yy_scan_string(str, scanner); r = libconfig_yyparse(scanner, &parse_ctx, &scan_ctx); if(r != 0) { config->error_file = scanctx_current_filename(&scan_ctx); config->error_type = CONFIG_ERR_PARSE; } libconfig_yylex_destroy(scanner); config->filenames = scanctx_cleanup(&scan_ctx, &(config->num_filenames)); parsectx_cleanup(&parse_ctx); __config_locale_restore(); return(r == 0 ? CONFIG_TRUE : CONFIG_FALSE); }
static int __config_read(config_t *config, FILE *stream, const char *filename, const char *str) { yyscan_t scanner; struct scan_context scan_ctx; struct parse_context parse_ctx; int r; /* Reinitialize the config */ void (*destructor)(void *) = config->destructor; const char *include_dir = config->include_dir; unsigned short tab_width = config->tab_width; int options = config->options; config->include_dir = NULL; config_destroy(config); config_init(config); config->destructor = destructor; config->include_dir = include_dir; config->tab_width = tab_width; config->options = options; parsectx_init(&parse_ctx); parse_ctx.config = config; parse_ctx.parent = config->root; parse_ctx.setting = config->root; __config_locale_override(); scanctx_init(&scan_ctx, filename); config->root->file = scanctx_current_filename(&scan_ctx); scan_ctx.config = config; libconfig_yylex_init_extra(&scan_ctx, &scanner); if(stream) libconfig_yyrestart(stream, scanner); else /* read from string */ (void)libconfig_yy_scan_string(str, scanner); libconfig_yyset_lineno(1, scanner); r = libconfig_yyparse(scanner, &parse_ctx, &scan_ctx); if(r != 0) { YY_BUFFER_STATE buf; config->error_file = scanctx_current_filename(&scan_ctx); config->error_type = CONFIG_ERR_PARSE; /* Unwind the include stack, freeing the buffers and closing the files. */ while((buf = (YY_BUFFER_STATE)scanctx_pop_include(&scan_ctx)) != NULL) libconfig_yy_delete_buffer(buf, scanner); } libconfig_yylex_destroy(scanner); config->filenames = scanctx_cleanup(&scan_ctx, &(config->num_filenames)); parsectx_cleanup(&parse_ctx); __config_locale_restore(); return(r == 0 ? CONFIG_TRUE : CONFIG_FALSE); }