UCL_EXTERN bool ucl_parser_set_filevars (struct ucl_parser *parser, const char *filename,
bool need_expand);
+/**
+ * Returns current file for the parser
+ * @param parser parser object
+ * @return current file or NULL if parsing memory
+ */
+UCL_EXTERN const char *ucl_parser_get_cur_file (struct ucl_parser *parser);
+
/**
* Defines special handler for certain types of data (identified by magic)
*/
};
/**
- * Add special handler for a parser
+ * Add special handler for a parser, handles special sequences identified by magic
* @param parser parser structure
* @param handler handler structure
*/
UCL_EXTERN void ucl_parser_add_special_handler (struct ucl_parser *parser,
struct ucl_parser_special_handler *handler);
+/**
+ * Handler for include traces:
+ * @param parser parser object
+ * @param parent where include is done from
+ * @param args arguments to an include
+ * @param path path of the include
+ * @param pathlen length of the path
+ * @param user_data opaque userdata
+ */
+typedef void (ucl_include_trace_func_t) (struct ucl_parser *parser,
+ const ucl_object_t *parent,
+ const ucl_object_t *args,
+ const char *path,
+ size_t pathlen,
+ void *user_data);
+
+/**
+ * Register trace function for an include handler
+ * @param parser parser object
+ * @param func function to trace includes
+ * @param user_data opaque data
+ */
+UCL_EXTERN void ucl_parser_set_include_tracer (struct ucl_parser *parser,
+ ucl_include_trace_func_t func,
+ void *user_data);
+
/** @} */
/**
struct ucl_stack *stack;
struct ucl_chunk *chunks;
struct ucl_pubkey *keys;
- struct ucl_parser_special_handler *special_handlers;
+ struct ucl_parser_special_handler *special_handlers;
+ ucl_include_trace_func_t *include_trace_func;
+ void *include_trace_ud;
struct ucl_variable *variables;
ucl_variable_handler var_handler;
void *var_data;
params.strat = UCL_DUPLICATE_APPEND;
params.must_exist = !default_try;
+ if (parser->include_trace_func) {
+ const ucl_object_t *parent = NULL;
+
+ if (parser->stack) {
+ parent = parser->stack->obj;
+ }
+
+ parser->include_trace_func (parser, parent, args,
+ data, len, parser->include_trace_ud);
+ }
+
/* Process arguments */
if (args != NULL && args->type == UCL_OBJECT) {
while ((param = ucl_object_iterate (args, &it, true)) != NULL) {
(const char *)&obj, sizeof (void *), true);
}
}
+
+void
+ucl_parser_set_include_tracer (struct ucl_parser *parser,
+ ucl_include_trace_func_t func,
+ void *user_data)
+{
+ parser->include_trace_func = func;
+ parser->include_trace_ud = user_data;
+}
+
+const char *
+ucl_parser_get_cur_file (struct ucl_parser *parser)
+{
+ return parser->cur_file;
+}
\ No newline at end of file