2222
2323static const char * nodetype [4 ] = {"none" , "scalar" , "sequence" , "mapping" };
2424
25+ static const char * PC_NO_PATH = "<string>" ;
26+
27+ static inline void pc_path_free (const char * path )
28+ {
29+ if (path != PC_NO_PATH ) free ((void * )path );
30+ }
31+
32+ static inline void pc_set_path (PC_tree_t tree , const char * path )
33+ {
34+ pc_path_free (tree .pcdoc -> path );
35+ size_t pathlen = strlen (path );
36+ char * pathcpy = malloc ((pathlen + 1 ) * sizeof (char ));
37+ strncpy (pathcpy , path , pathlen );
38+ tree .pcdoc -> path = pathcpy ;
39+ }
40+
41+ uint64_t PC_version ()
42+ {
43+ return PARACONF_VERSION ;
44+ }
45+
2546PC_tree_t PC_parse_path (const char * path )
2647{
2748 PC_tree_t restree = {PC_OK , NULL , NULL };
@@ -41,6 +62,7 @@ PC_tree_t PC_parse_path(const char* path)
4162 }
4263
4364 fclose (conf_file );
65+ pc_set_path (restree , path );
4466 return restree ;
4567
4668err1 :
@@ -169,10 +191,17 @@ PC_tree_t PC_parse_file(FILE* conf_file)
169191
170192PC_tree_t PC_root (yaml_document_t * document )
171193{
172- PC_tree_t restree = {PC_OK , document , yaml_document_get_root_node (document )};
194+ PC_tree_t restree = {PC_OK , malloc (sizeof (PC_document_t )), yaml_document_get_root_node (document )};
195+ PC_document_t pcdoc = {* document , PC_NO_PATH };
196+ * restree .pcdoc = pcdoc ;
173197 return restree ;
174198}
175199
200+ const char * PC_path (PC_tree_t tree )
201+ {
202+ return tree .pcdoc -> path ;
203+ }
204+
176205PC_tree_t PC_get (const PC_tree_t tree , const char * index_fmt , ...)
177206{
178207 va_list ap ;
@@ -364,8 +393,11 @@ PC_status_t PC_bool(const PC_tree_t tree, int* res)
364393
365394PC_status_t PC_tree_destroy (PC_tree_t * tree )
366395{
367- yaml_document_delete (tree -> document );
368- free (tree -> document );
396+ yaml_document_delete (& tree -> pcdoc -> document );
397+ pc_path_free (tree -> pcdoc -> path );
398+ tree -> pcdoc -> path = NULL ;
399+ free (tree -> pcdoc );
400+ tree -> pcdoc = NULL ;
369401 tree -> node = NULL ;
370402 return tree -> status ;
371403}
0 commit comments