1 #ifndef _HTPL_H 2 #define _HTPL_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 #include <huskylib/compiler.h> 9 #include <huskylib/huskylib.h> 10 11 /* Error buffer. I think it is enough 1024 characters for error message. */ 12 /* Enlarge it if I was wrong. */ 13 #define HTPLERRORSIZE 1024 14 HUSKYEXT char htplError[HTPLERRORSIZE]; 15 16 /* types of variables */ 17 typedef enum { 18 T_STRING = 0, 19 T_INT 20 } e_vartype; 21 22 typedef struct s_line { 23 char *text; 24 int lineNo; 25 struct s_line *next; 26 } sectionLine; 27 28 typedef struct { 29 short state, inelse; 30 } ifstack; 31 32 typedef struct s_section { 33 char *name; 34 char *file; 35 sectionLine *firstLine; 36 struct s_section *next; 37 short condition; 38 int iflevel; 39 int maxif; 40 ifstack *ifstack; 41 } section; 42 43 typedef struct s_variable { 44 char *label; 45 void **value; 46 e_vartype type; 47 struct s_variable *next; 48 } variable; 49 50 typedef struct s_template { 51 section *firstSection; 52 section *currentSection; 53 variable *firstVariable; 54 } template; 55 56 57 /* makes a new template */ 58 HUSKYEXT template *newTemplate(); 59 60 /* reads template and makea a structure of sections */ 61 /* returns 1 on success, and 0 if any error occured, */ 62 /* parseSection() should not be called in this case or it */ 63 /* will fail with the same error */ 64 HUSKYEXT int parseTemplate(template *tpl, char *file); 65 66 /* parses section's lines and prints output into output buffer */ 67 /* returns 1 on success, and 0 if any error occured */ 68 HUSKYEXT int parseSection(template *tpl, char *name, char **output); 69 70 /* add variable to list */ 71 /* returns 1 on success, and 0 if any error occured */ 72 HUSKYEXT int registerVariable(template *tpl, char *label, void **value, e_vartype type); 73 74 /* removes variable from list */ 75 /* returns 1 on success, and 0 if any error occured */ 76 HUSKYEXT int unregisterVariable(template *tpl, char *name); 77 78 /* removes all variables from list */ 79 /* returns 1 on success, and 0 if any error occured */ 80 HUSKYEXT int unregisterAllVariables(template *tpl); 81 82 /* removes the template */ 83 /* returns 1 on success, and 0 if any error occured */ 84 HUSKYEXT int deleteTemplate(template *tpl); 85 86 #ifdef __cplusplus 87 } 88 #endif 89 90 #endif 91