Skip to content

Instantly share code, notes, and snippets.

@andoriyu
Created April 8, 2020 08:22
Show Gist options
  • Save andoriyu/7d8e148e706a1d8fefbacadb656a7e44 to your computer and use it in GitHub Desktop.
Save andoriyu/7d8e148e706a1d8fefbacadb656a7e44 to your computer and use it in GitHub Desktop.
#include "libucl/include/ucl.h"
#include <sys/types.h>
#include <unistd.h>
bool handler(const unsigned char *data, size_t len,
unsigned char **replace, size_t *replace_len, bool *need_free, void* ud) {
write(1, data, len);
if (memcmp(data, "WAT", len)) {
const char *val = "xxx";
*replace = malloc(3);
*replace_len = 3;
memcpy (*replace, val, 3);
*need_free=true;
return true;
}
return false;
}
int
main (int argc, char **argv)
{
struct ucl_parser *parser = NULL;
ucl_object_t *obj;
int flags;
const char *fname_in = NULL;
fname_in = argv[0];
flags = UCL_PARSER_DEFAULT;
parser = ucl_parser_new (flags);
ucl_parser_set_variables_handler (parser, handler, NULL);
ucl_parser_add_file(parser, "test.ucl");
if (ucl_parser_get_error (parser) != NULL) {
fprintf (stdout, "Error occurred (phase 1): %s\n",
ucl_parser_get_error(parser));
exit(1);
}
obj = ucl_parser_get_object (parser);
ucl_parser_free (parser);
ucl_object_unref (obj);
}
key = "${VAR}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment