diff options
| author | Alexander Pickering <alexandermpickering@gmail.com> | 2017-12-28 21:34:34 -0500 |
|---|---|---|
| committer | Alexander Pickering <alexandermpickering@gmail.com> | 2017-12-28 21:34:34 -0500 |
| commit | 780fcb523eaa2feb3882967e7b2debf21aa569f2 (patch) | |
| tree | ef92ac5e971763b370bff8b598e562479e827a2d | |
| parent | 25dbc260962154cc07fa6e131d096bdcf55a6693 (diff) | |
| download | libctemplates-780fcb523eaa2feb3882967e7b2debf21aa569f2.tar.gz libctemplates-780fcb523eaa2feb3882967e7b2debf21aa569f2.tar.bz2 libctemplates-780fcb523eaa2feb3882967e7b2debf21aa569f2.zip | |
changed prototypes
Changed function prototypes that previously took no arguments like
void dothing();
to
void dothing(void);
| -rw-r--r-- | ctemplates.c | 19 | ||||
| -rw-r--r-- | ctemplates.h | 25 | ||||
| -rw-r--r-- | ctemplates_i.h | 234 | ||||
| -rw-r--r-- | fbuf.h | 2 |
4 files changed, 12 insertions, 268 deletions
diff --git a/ctemplates.c b/ctemplates.c index d497095..5befdd4 100644 --- a/ctemplates.c +++ b/ctemplates.c @@ -30,9 +30,9 @@ #include <stdio.h> #include <sys/stat.h> #include <stdarg.h> -#include <ctemplates_i.h> +#include <ctemplates.h> -struct TMPL_token* TMPL_alloc_token(); +struct TMPL_token* TMPL_alloc_token(void); void TMPL_free_token(struct TMPL_token* token); enum TMPL_tagtype starts_with_token(char* str, size_t strlen); size_t tagtype_len(enum TMPL_tagtype t); @@ -47,7 +47,7 @@ struct TMPL_token* scan_tag( size_t* consumed ); void print_tokens(struct TMPL_token* head); -struct TMPL_varitem* TMPL_alloc_varitem(); +struct TMPL_varitem* TMPL_alloc_varitem(void); void TMPL_free_varitem(struct TMPL_varitem* vi); void TMPL_add_var_to_varlist( struct TMPL_varlist* t, @@ -60,7 +60,7 @@ void print_ast_helper( ); void print_ast(struct TMPL_tagnode* root); struct TMPL_token* TMPL_tokenize(char* tmplstr, size_t strlen); -struct TMPL_tagnode* alloc_tagnode(); +struct TMPL_tagnode* alloc_tagnode(void); size_t get_quoted_string(char* start, size_t len); struct TMPL_tagnode* parse_text( struct TMPL_token* head, @@ -86,10 +86,10 @@ struct TMPL_tagnode* parse_variable( struct TMPL_token* head, struct TMPL_buf* errbuf ); -struct TMPL_varlist* TMPL_alloc_varlist(); +struct TMPL_varlist* TMPL_alloc_varlist(void); int TMPL_free_hashmapitems(any_t a, any_t b); void TMPL_free_varlist(struct TMPL_varlist* vl); -struct TMPL_loop* TMPL_alloc_loop(); +struct TMPL_loop* TMPL_alloc_loop(void); void TMPL_free_loop(struct TMPL_loop* tl); void TMPL_add_varlist_to_loop( struct TMPL_loop* tl, @@ -104,7 +104,7 @@ struct TMPL_tagnode* parse( struct TMPL_token* head, struct TMPL_buf* errbuf ); -struct TMPL_templates* alloc_templates(); +struct TMPL_templates* alloc_templates(void); struct TMPL_templates* compile(char* tmplstr); int render_variable( struct TMPL_templates* t, @@ -149,7 +149,10 @@ struct TMPL_templates* TMPL_alloc_template(char* tmplstr); void TMPL_free_template(struct TMPL_templates* t); void TMPL_free_tagnode(struct TMPL_tagnode* tn); char* TMPL_get_error(struct TMPL_templates* t); -void print_varlist_helper(struct TMPL_varlist* vl, int indent); +void print_varlist_helper( + struct TMPL_varlist* vl, + int indent + ); /*Allocates a token*/ diff --git a/ctemplates.h b/ctemplates.h index 0e76fc3..a2d33a1 100644 --- a/ctemplates.h +++ b/ctemplates.h @@ -10,7 +10,6 @@ #define _CTEMPLATE_H - #include "fbuf.h" #include "kmp.h" #include "hashmap.h" @@ -159,30 +158,6 @@ struct TMPL_fmtlist{ char* name; } TMPL_fmtlist; -struct TMPL_varlist; -struct TMPL_loop; - -/* - * TMPL_varlist is a variable list of simple variables and/or - * loop variables - */ -//struct TMPL_varlist { - //struct TMPL_varlist *next; [> next variable list on a list <] - //struct TMPL_var *var; [> list of my simple variables <] - //struct TMPL_loop *loop; [> list of my loop variables <] - //struct TMPL_loop *parent; [> my parent loop variable (if any) <] -//}; - -/* TMPL_loop is a loop variable, which is a list of variable lists */ - -//struct TMPL_loop { - //struct TMPL_loop *next; [> next loop variable on a list <] - //const char *name; [> my name <] - //struct TMPL_varlist *varlist; [> list of my variable lists <] - //struct TMPL_varlist *tail; [> tail of "varlist" <] - //struct TMPL_varlist *parent; [> my parent variable list <] -//}; - /* Holdes all the data needed for a template*/ struct TMPL_templates{ struct TMPL_buf* out; diff --git a/ctemplates_i.h b/ctemplates_i.h deleted file mode 100644 index 767c1c2..0000000 --- a/ctemplates_i.h +++ /dev/null @@ -1,234 +0,0 @@ -/* - * 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 - - -#include "fbuf.h" -#include "kmp.h" -#include "hashmap.h" - -#define MAX_TEMPLATE_LENGTH 2147384647 - -/* -typedef struct TMPL_varlist TMPL_varlist; -typedef struct TMPL_loop TMPL_loop; -typedef struct TMPL_fmtlist TMPL_fmtlist; -typedef struct TMPL_fmtlists TMPL_fmtlists; -*/ -#define TAG_NULL_TEXT "" -#define TAG_TEXT_TEXT "" -#define TAG_VAR_TEXT "TMPL_VAR" -#define TAG_IF_TEXT "TMPL_IF" -#define TAG_ELSEIF_TEXT "TMPL_ELSEIF" -#define TAG_ELSE_TEXT "TMPL_ELSE" -#define TAG_LOOP_TEXT "TMPL_LOOP" -#define TAG_BREAK_TEXT "TMPL_BREAK" -#define TAG_CONTINUE_TEXT "TMPL_CONTINUE" -#define TAG_END_TEXT "TMPL_END" - -#define ATTRIBUTE_VARNAME "name=\"" -#define ATTRIBUTE_DEFAULT "default=\"" -#define ATTRIBUTE_VALUE "value=\"" - -#define ERRBUF_HINTLEN 50 - -#define SIZEOF(x) (sizeof(x) / sizeof(x[0])) - -#define TAG_NULL_LENGTH 0 -#define TAG_TEXT_LENGTH 0 -#define TAG_VAR_LENGTH SIZEOF(TAG_VAR_TEXT) -#define TAG_IF_LENGTH SIZEOF(TAG_IF_TEXT) -#define TAG_ELSEIF_LENGTH SIZEOF(TAG_ELSEIF_TEXT) -#define TAG_ELSE_LENGTH SIZEOF(TAG_ELSE_TEXT) -#define TAG_LOOP_LENGTH SIZEOF(TAG_LOOP_TEXT) -#define TAG_BREAK_LENGTH SIZEOF(TAG_BREAK_TEXT) -#define TAG_CONTINUE_LENGTH SIZEOF(TAG_CONTINUE_TEXT) -#define TAG_END_LENGTH SIZEOF(TAG_END_TEXT) - -//I guess it counts the backslash? -#define ATTRIBUTE_VARNAME_LENGTH SIZEOF(ATTRIBUTE_VARNAME) - 1 -#define ATTRIBUTE_DEFAULT_LENGTH SIZEOF(ATTRIBUTE_DEFAULT) - 1 -#define ATTRIBUTE_VALUE_LENGTH SIZEOF(ATTRIBUTE_VALUE) - 1 - -//Define to 0 for slight speedup improvements, no errors -#define DEBUGGING 1 -//Length of error messages -#define ERR_MSG_LEN 500 - -/*The different kind of nodes we can have*/ -enum TMPL_tagtype{ - tag_null = 0,/*Should never show up*/ - tag_text = 1,/*A text sequence*/ - tag_var = 2,/*A variable to replace*/ - tag_if = 3,/*If*/ - tag_elseif = 4,/*Else if*/ - tag_else = 5,/*Else*/ - tag_end = 6,/*end if, end loop*/ - tag_loop = 7,/*Loop*/ - tag_break = 9,/*Break*/ - tag_continue = 10,/*Skip the rest of the loop and go again*/ -}; - -struct TMPL_light_string{ - const char* start; - size_t len; -}; - -enum TMPL_vartype{ - vartype_loop, - vartype_var -}; - - -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; -}; - -struct TMPL_varitem{ - enum TMPL_vartype type; - union { - struct TMPL_loop* l; - char* s; - }item; -}; - -/*Holds all the data needed for a single node in a template*/ -struct TMPL_tagnode{ - enum TMPL_tagtype type; - struct TMPL_tagnode* next; - union{ - /*Text*/ - struct{ - const char* start; - size_t len; - }text; - /*Var*/ - struct{ - char* varname; - size_t name_len; - char* defaultval; - size_t default_len; - }var; - - /*If, elseif*/ - struct{ - char* varname; - char* testval; - struct TMPL_tagnode* tbranch; - struct TMPL_tagnode* fbranch; - }ifelse; - - /*Loop*/ - struct{ - char* loopname; - struct TMPL_tagnode* body; - }loop; - - /*Break and Continue*/ - struct{ - int level; - }breakcont; - }TMPL_tag; -}TMPL_tagnode; - -//typedef void (*TMPL_fmtfuncs) (const char*, struct TMPL_buf*); -/* - * TMPL_fmtlist is a list of format functions, which are passed to - * a template. A TMPL_VAR tag can specify a format function for - * outputting the variable with the fmt="fmtname" attribute. - */ -struct TMPL_fmtlist{ - struct TMPL_fmtlist* next; - void* fmtfunc; - char* name; -} TMPL_fmtlist; - -/* 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; - - -struct TMPL_token{ - char* start;//Start of token - char* end;//End of token - enum TMPL_tagtype type;//The type of token - size_t length;//Length of token, should always be end-start - struct TMPL_token* next;//The next token -}TMPL_token; - - - -typedef void (*TMPL_fmtfunc) (const char *, FILE *); - -/* - -TMPL_varlist *TMPL_add_var(TMPL_varlist *varlist, - const char *varname1, const char *value1, ... , 0); -*/ - -//TMPL_varlist *TMPL_add_var(TMPL_varlist *varlist, ...); -extern struct TMPL_varlist* TMPL_add_var(struct TMPL_varlist* varlist, ...); - -/*TMPL_varlist *TMPL_add_loop(TMPL_varlist *varlist, - const char *name, TMPL_loop *loop); - */ -extern struct TMPL_varlist* TMPL_add_loop(struct TMPL_varlist* varlist, - const char* name, struct TMPL_loop* loop); - - -//TMPL_loop *TMPL_add_varlist(TMPL_loop *loop, TMPL_varlist *varlist); -struct TMPL_loop* TMPL_add_varlist(struct TMPL_loop* loop, struct TMPL_varlist* varlist); - -//void TMPL_free_varlist(TMPL_varlist *varlist); -void TMPL_free_varlist(struct TMPL_varlist* varlist); - -//TMPL_fmtlist *TMPL_add_fmt(TMPL_fmtlist *fmtlist, - //const char *name, TMPL_fmtfunc fmtfunc); -struct TMPL_fmtlist* TMPL_add_fmt(struct TMPL_fmtlist* fmtlist, - const char* name, void* fmtfunc); - -void TMPL_free_fmtlist(struct TMPL_fmtlist* fmtlist); - -/*int TMPL_write(const char *filename, const char *tmplstr, - const TMPL_fmtlist *fmtlist, const TMPL_varlist *varlist, - FILE *out, FILE *errout); -*/ - -struct TMPL_varlist* TMPL_alloc_varlist(); -void TMPL_free_varlist(struct TMPL_varlist* t); - -struct TMPL_varitem* TMPL_alloc_varitem(); -void TMPL_free_varitem(struct TMPL_varitem* vi); - -struct TMPL_templates* TMPL_alloc_template(char* t); -void TMPL_free_template(struct TMPL_templates* t); - -char* TMPL_render(struct TMPL_templates* t, struct TMPL_varlist* varlist); - -struct TMPL_tagnode* TMPL_alloc_tagnode(enum TMPL_tagtype); -void TMPL_free_tagnode(struct TMPL_tagnode* tn); - -/* TODO: Remove this after testing is done */ -struct TMPL_token* TMPL_tokenize(char* tmplstr, size_t strlen); - - -#endif @@ -20,7 +20,7 @@ void bputsn(struct TMPL_buf* b, char* s, size_t size); void bputc(struct TMPL_buf* b, char s); -struct TMPL_buf* alloc_tmpl_buf(); +struct TMPL_buf* alloc_tmpl_buf(void); void free_tmpl_buf(struct TMPL_buf* b); |
