From b9899c6cbe2f694c9db36e9d4e15c532d10b546f Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Thu, 25 Oct 2018 12:08:54 -0400 Subject: Started refactoring code Added a src/ and build/ directory Added a include/ directory Included file is smaller --- include/ctemplates.h | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 include/ctemplates.h (limited to 'include') diff --git a/include/ctemplates.h b/include/ctemplates.h new file mode 100644 index 0000000..a8855a8 --- /dev/null +++ b/include/ctemplates.h @@ -0,0 +1,60 @@ +/* + * C TemplateS Library 0.1 - + * Forked from C Template Library 1.0 by Stephen C. Losen. + * + * Copyright 2017 Alexander M. Pickering Distributed under the terms + * of the GNU General Public License (GPL) + */ + +#ifndef _CTEMPLATE_H +#define _CTEMPLATE_H + +#define MAX_TEMPLATE_LENGTH 2147384647 + +#define ERRBUF_HINTLEN 50 + +//Length of error messages +#define ERR_MSG_LEN 500 + +struct TMPL_varlist{ + map_t map; +}TMPL_varlist; + +struct TMPL_loop{ + struct TMPL_varlist* varlist; + size_t loop_len; + struct TMPL_loop* next; + struct TMPL_loop* tail; +}; + +/* Holdes all the data needed for a template*/ +struct TMPL_templates{ + struct TMPL_buf* out; + struct TMPL_buf* errout; + struct TMPL_tagnode* roottag; + int linenum; + int error; +} TMPL_templates; + + +void TMPL_add_var_to_varlist(struct TMPL_varlist* vl, char* name, char* value); +void TMPL_add_loop_to_varlist(struct TMPL_varlist* vl, char* name, struct TMPL_loop* loop); +void TMPL_add_varlist_to_loop(struct TMPL_loop* l, struct TMPL_varlist* vl); + + +struct TMPL_varlist* TMPL_alloc_varlist(void); +void TMPL_free_varlist(struct TMPL_varlist* t); + +struct TMPL_templates* TMPL_alloc_template(char* t); +void TMPL_free_template(struct TMPL_templates* t); + +struct TMPL_loop* TMPL_alloc_loop(void); +void TMPL_free_loop(struct TMPL_loop* tl); + +char* TMPL_render(struct TMPL_templates* t, struct TMPL_varlist* varlist, size_t* size_p); + +/*A debug function*/ +void print_varlist(struct TMPL_varlist* vl); +void print_ast(struct TMPL_templates* root); + +#endif -- cgit v1.2.3-70-g09d2