From 7d3b0b917cdb93d249dc356db8471fe9e6863424 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Wed, 5 Dec 2018 18:42:19 -0500 Subject: Added more documentation Added documentation for each function in the include/ctemplates.h file Also did some spellchecking on the readme. --- include/ctemplates.h | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/ctemplates.h b/include/ctemplates.h index df41085..ca77391 100644 --- a/include/ctemplates.h +++ b/include/ctemplates.h @@ -16,31 +16,48 @@ //Length of error messages #define ERR_MSG_LEN 500 +/* A variable list, holds key-value pairs as (string -> (string | loop)) */ struct TMPL_varlist; +/* A list structure, holds an array of varlists to be looped over*/ struct TMPL_loop; /* Holdes all the data needed for a template*/ struct TMPL_templates; +/* Adds a variable to a variable list under a certain name */ void TMPL_add_var_to_varlist(struct TMPL_varlist* vl, const char* name, const char* value); + +/* Adds a loop to a variable list under a certain name */ void TMPL_add_loop_to_varlist(struct TMPL_varlist* vl, const char* name, struct TMPL_loop* loop); -void TMPL_add_varlist_to_loop(struct TMPL_loop* l, struct TMPL_varlist* vl); +/* Adds a variable list as one of the varlists in a loop */ +void TMPL_add_varlist_to_loop(struct TMPL_loop* l, struct TMPL_varlist* vl); +/* Create a new varlist. If allocation fails, the struct retuned will be NULL */ struct TMPL_varlist* TMPL_alloc_varlist(void); +/* Frees a varlist (and recursively, any loops under it, any varlists under those loops, ect.) */ void TMPL_free_varlist(struct TMPL_varlist* t); +/* Allocate a new template. If allocation fails, the struct retunred will be NULL */ struct TMPL_templates* TMPL_alloc_template(const char* t); +/* Free a template. Do not use the string returned by TMPL_render() the template is freed */ void TMPL_free_template(struct TMPL_templates* t); +/* Create a new loop. If allocation fails, the struct returned will be NULL */ struct TMPL_loop* TMPL_alloc_loop(void); +/* Free a loop. If the loop is added to a varlist, just call free on the varlist +and any loops that have been added to it will automatically be freed.*/ void TMPL_free_loop(struct TMPL_loop* tl); +/* Takes a template and varlist, and collapses it into a string. +If size_p is non-null, the size of the resulting string will be placed in it. +If any errors happened the t->error will be non-zero and the error can be +retreived with TMPL_err(t,&size)*/ char* TMPL_render(struct TMPL_templates* t, struct TMPL_varlist* varlist, size_t* size_p); const char* TMPL_err(struct TMPL_templates* t,size_t* size); -/*A debug function*/ +/* A debug functions */ void print_varlist(struct TMPL_varlist* vl); void print_ast(struct TMPL_templates* root); -- cgit v1.2.3-70-g09d2