diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-25 15:06:39 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2012-03-25 15:06:39 +0200 |
commit | 44742f8aadb7a8a969f11d9b1d50c8be2573a576 (patch) | |
tree | 90c1b692df9a41627ac8413c68a569b29ae9008b /src/config.c | |
parent | 59a5b833216b62f28c816df7c9129bf0954993e0 (diff) | |
download | fastd-44742f8aadb7a8a969f11d9b1d50c8be2573a576.tar fastd-44742f8aadb7a8a969f11d9b1d50c8be2573a576.zip |
Add include command
Diffstat (limited to 'src/config.c')
-rw-r--r-- | src/config.c | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/src/config.c b/src/config.c index d584264..db178df 100644 --- a/src/config.c +++ b/src/config.c @@ -88,31 +88,32 @@ static bool config_match(const char *opt, ...) { return match; } -static void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filename) { - yyscan_t scanner; - fastd_config_pstate *ps; - int token; - YYSTYPE token_val; +void fastd_read_config(fastd_context *ctx, fastd_config *conf, const char *filename, int depth) { + if (depth >= MAX_CONFIG_DEPTH) + exit_error(ctx, "maximum config include depth exceeded"); - FILE *file; bool use_stdin = !strcmp(filename, "-"); + FILE *file; if (use_stdin) file = stdin; else file = fopen(filename, "r"); + yyscan_t scanner; fastd_config_yylex_init(&scanner); fastd_config_yyset_in(file, scanner); - ps = fastd_config_pstate_new(); + fastd_config_pstate *ps = fastd_config_pstate_new(); + int token; + YYSTYPE token_val; do { token = fastd_config_yylex(&token_val, scanner); if (token < 0) exit_error(ctx, "config error: %s", token_val.str); - } while(fastd_config_push_parse(ps, token, &token_val, ctx, conf) == YYPUSH_MORE); + } while(fastd_config_push_parse(ps, token, &token_val, ctx, conf, depth+1) == YYPUSH_MORE); fastd_config_pstate_delete(ps); fastd_config_yylex_destroy(scanner); @@ -145,7 +146,7 @@ void fastd_configure(fastd_context *ctx, fastd_config *conf, int argc, char *con while (i < argc) { IF_OPTION_ARG("-c", "--config") { - fastd_read_config(ctx, conf, arg); + fastd_read_config(ctx, conf, arg, 0); continue; } |