int main(int argc, char **argv) { PValue v = NULL; StrTempl *st = NULL; char *res = NULL; char *jfile, *tfile; if (argc != 3) { jfile = "test.js"; tfile = "test.ctp"; } else { jfile = argv[1]; tfile = argv[2]; } printf("file '%s' '%s'\n",jfile,tfile); v = json_parse_file(jfile); if (value_is_error(v)) { printf("json error: %s\n",value_as_string(v)); goto err; } res = file_read_all(tfile,true); if (! res) { printf("cannot read '%s'\n",tfile); goto err; } st = str_templ_new(res,NULL); if (value_is_error(st)) { printf("template compilation error: %s\n",value_as_string(st)); goto err; } unref(res); str_templ_add_builtin("test",test_impl); res = str_templ_subst_values(st,v); if (value_is_error(res)) { printf("template evaluation error: %s\n",value_as_string(res)); goto err; } printf("%s\n",res); err: dispose(v,st,res); printf("kount = %d\n",obj_kount()); return 0; }
struct cavan_xml_document *cavan_xml_document_parse(const char *pathname) { size_t size; char *content; struct cavan_xml_document *doc; content = file_read_all(pathname, 0, &size); if (content == NULL) { return NULL; } doc = cavan_xml_document_parse_base(content, size); if (doc == NULL) { goto out_free_content; } cavan_xml_document_invert(doc); return doc; out_free_content: free(content); return NULL; }