From d1a1990c4177653fd2379c227142e6208ecfc20d Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Wed, 4 Sep 2019 20:29:20 -0400 Subject: Fix typos in headers --- Makefile | 12 ++++++++++++ README.md | 18 ++++++++++-------- include/ctemplates.h | 16 +++++++++++----- src/ctemplates.h | 9 ++++++++- 4 files changed, 41 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 906d19d..f772350 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,10 @@ objfiles = $(objs:%=build/%.o) TEST_1_NAME = t/test_1$(BIN_POSTFIX) TEST_2_NAME = t/test_2$(BIN_POSTFIX) +examples=hello variable +example_bins=$(examples:%=examples/%$(BIN_POSTFIX)) +example_objs=$(examples:%=examples/%.o) + $(LIBNAME): $(objfiles) ar rc $@ $^ ranlib $@ @@ -36,6 +40,14 @@ test: $(TEST_1_NAME) $(TEST_2_NAME) #$(TEST_1_NAME) $(TEST_2_NAME) +examples: $(example_bins) + $(example_bins) +$(example_bins): %$(BIN_POSTFIX) : %.o + $(CC) $(CFLAGS) -o $@ $< -lctemplates + +$(example_objs): %.o : %.c + $(CC) -I./include -L. -c -o $@ $< -lctemplates + install: $(LIBNAME) cp $(LIBNAME) /usr/local/lib mkdir -p /usr/local/include/ctemplates diff --git a/README.md b/README.md index 043aca3..28bf1b5 100644 --- a/README.md +++ b/README.md @@ -159,6 +159,7 @@ For example: *output* Output: Hello, world! + Length: 13 ### Variable substitution @@ -168,7 +169,9 @@ For example: *main.c* - #include + #include + #include + #include int main(){ /* @@ -185,11 +188,13 @@ For example: } fseek(fp,0,SEEK_END); size_t file_len = ftell(fp); + fseek(fp,0,SEEK_SET); char template[file_len]; fread(template,sizeof(char),file_len,fp); struct TMPL_templates* t; struct TMPL_varlist* vl; + size_t dummy; /* Render the template without a variable named "varname" @@ -201,9 +206,8 @@ For example: */ t = TMPL_alloc_template(template); vl = TMPL_alloc_varlist(); - size_t dummy; char* without_variable = TMPL_render(t,vl,&dummy); - printf("Without variable: %s\n",without_variable); + printf("Without variable:\n%s\n",without_variable); TMPL_free_template(t); TMPL_free_varlist(vl); @@ -215,9 +219,8 @@ For example: t = TMPL_alloc_template(template); vl = TMPL_alloc_varlist(); TMPL_add_var_to_varlist(vl,"varname","Hello, world!"); - size_t dummy; char* with_variable = TMPL_render(t,vl,&dummy); - printf("With variable:%s\n",with_variable); + printf("With variable:\n%s\n",with_variable); TMPL_free_template(t); TMPL_free_varlist(vl); @@ -229,7 +232,6 @@ For example: Without variable: Value is:optional default - With variable: Value is:Hello, world! @@ -252,7 +254,7 @@ If and elseif statements check if strings are the same. They do a strcmp(), so b #include #include - #include + #include int main(){ /* @@ -342,7 +344,7 @@ only variables that have been added to the namespace are accessible in the loop. #include #include - #include + #include int main(){ /* diff --git a/include/ctemplates.h b/include/ctemplates.h index ca77391..7c8e57c 100644 --- a/include/ctemplates.h +++ b/include/ctemplates.h @@ -1,11 +1,17 @@ /* - * C TemplateS Library 0.1 - - * Forked from C Template Library 1.0 by Stephen C. Losen. + * C TemplateS : template expander + * Based on the original libctemplate by Stephen C. Losen + * + * Version 0.1 + * + * Copyright (c) 2017-2019 Alexander M. Pickering (alex@cogarr.net) * * Copyright 2017 Alexander M. Pickering Distributed under the terms * of the GNU General Public License (GPL) */ +#include + #ifndef _CTEMPLATE_H #define _CTEMPLATE_H @@ -37,18 +43,18 @@ 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); +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); +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); +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. diff --git a/src/ctemplates.h b/src/ctemplates.h index b422b77..da56b97 100644 --- a/src/ctemplates.h +++ b/src/ctemplates.h @@ -1,5 +1,12 @@ /* - * C TemplateS Library 0.1 - + * C TemplateS : template expander + * Based on the original libctemplate by Stephen C. Losen + * + * Version 0.1 + * + * Copyright (c) 2017-2019 Alexander M. Pickering (alex@cogarr.net) + * + * Distributed under GPL V3, see COPYING for more information. * Forked from C Template Library 1.0 by Stephen C. Losen. * * Copyright 2017 Alexander M. Pickering Distributed under the terms -- cgit v1.2.3-70-g09d2