return 0;
}
+static int _dict_from_file(dict_tokenize_ctx_t *ctx,
+ char const *dir_name, char const *filename,
+ char const *src_file, int src_line);
+
+/*
+ * Process the $INCLUDE command
+ */
+static int dict_read_process_include(dict_tokenize_ctx_t *ctx, char **argv, int argc, char const *dir, char *fn, int line)
+{
+ int rcode;
+ int stack_depth = ctx->stack_depth;
+
+ /*
+ * Allow "$INCLUDE" or "$INCLUDE-", but
+ * not anything else.
+ */
+ if ((argv[0][8] != '\0') && ((argv[0][8] != '-') || (argv[0][9] != '\0'))) {
+ fr_strerror_printf("Invalid keyword '%s'", argv[0]);
+ return -1;
+ }
+
+ if (argc != 2) {
+ fr_strerror_printf("Unexpected text after $INCLUDE at %s[%d]", fr_cwd_strip(fn), line);
+ return -1;
+ }
+
+ /*
+ * Allow limited macro capability, so
+ * people don't have to remember where
+ * the root dictionaries are located.
+ */
+ if (strncmp(argv[1], "${dictdir}/", 11) != 0) {
+ rcode = _dict_from_file(ctx, dir, argv[1], fn, line);
+ } else {
+ rcode = _dict_from_file(ctx, fr_dict_global_ctx_dir(), argv[1] + 11, fn, line);
+ }
+
+ if ((rcode == -2) && (argv[0][8] == '-')) {
+ fr_strerror_clear(); /* delete all errors */
+ return 0;
+ }
+
+ if (rcode < 0) {
+ fr_strerror_printf_push("from $INCLUDE at %s[%d]", fr_cwd_strip(fn), line);
+ return -1;
+ }
+
+ if (ctx->stack_depth < stack_depth) {
+ fr_strerror_printf_push("unexpected END-??? in $INCLUDE at %s[%d]",
+ fr_cwd_strip(fn), line);
+ return -1;
+ }
+
+ while (ctx->stack_depth > stack_depth) {
+ if (ctx->stack[ctx->stack_depth].nest == NEST_NONE) {
+ ctx->stack_depth--;
+ continue;
+ }
+
+ fr_strerror_printf_push("BEGIN-??? without END-... in file $INCLUDEd from %s[%d]",
+ fr_cwd_strip(fn), line);
+ return -1;
+ }
+
+ /*
+ * Reset the filename.
+ */
+ ctx->stack[ctx->stack_depth].filename = fn;
+
+ return 0;
+}
+
/*
* Process the MEMBER command
*/
* @param[in] dir_name Directory containing the dictionary we're loading.
* @param[in] filename we're parsing.
* @param[in] src_file The including file.
- * @param[in] src_line Line on which the $INCLUDE or $INCLUDE- statement was found.
+ * @param[in] src_line Line on which the $INCLUDE or $NCLUDE- statement was found.
* @return
* - 0 on success.
* - -1 on failure.
* See if we need to import another dictionary.
*/
if (strncasecmp(argv[0], "$INCLUDE", 8) == 0) {
- int ret;
- int stack_depth = ctx->stack_depth;
-
- /*
- * Allow "$INCLUDE" or "$INCLUDE-", but
- * not anything else.
- */
- if ((argv[0][8] != '\0') && ((argv[0][8] != '-') || (argv[0][9] != '\0'))) goto invalid_keyword;
-
/*
* Included files operate on a copy of the context.
*
* attribute", then it won't affect the
* parent.
*/
-
- /*
- * Allow limited macro capability, so
- * people don't have to remember where
- * the root dictionaries are located.
- */
- if (strncmp(argv[1], "${dictdir}/", 11) != 0) {
- ret = _dict_from_file(ctx, dir, argv[1], fn, line);
- } else {
- ret = _dict_from_file(ctx, fr_dict_global_ctx_dir(), argv[1] + 11, fn, line);
- }
-
- if ((ret == -2) && (argv[0][8] == '-')) {
- fr_strerror_clear(); /* delete all errors */
- ret = 0;
- }
-
- if (ret < 0) {
- fr_strerror_printf_push("from $INCLUDE at %s[%d]", fr_cwd_strip(fn), line);
- goto error;
- }
-
- if (ctx->stack_depth < stack_depth) {
- fr_strerror_printf_push("unexpected END-??? in $INCLUDE at %s[%d]",
- fr_cwd_strip(fn), line);
- goto error;
- }
-
- while (ctx->stack_depth > stack_depth) {
- if (ctx->stack[ctx->stack_depth].nest == NEST_NONE) {
- ctx->stack_depth--;
- continue;
- }
-
- fr_strerror_printf_push("BEGIN-??? without END-... in file $INCLUDEd from %s[%d]",
- fr_cwd_strip(fn), line);
- goto error;
- }
-
- /*
- * Reset the filename.
- */
- ctx->stack[ctx->stack_depth].filename = fn;
+ if (dict_read_process_include(ctx, argv, argc, dir, fn, line) < 0) goto error;
continue;
} /* $INCLUDE */
/*
* Any other string: We don't recognize it.
*/
- invalid_keyword:
fr_strerror_printf_push("Invalid keyword '%s'", argv[0]);
goto error;
}