From e1d19dc2a041a393db8cce4f9d902dea2397b175 Mon Sep 17 00:00:00 2001 From: Derek Stevens Date: Mon, 14 Feb 2022 18:06:06 -0700 Subject: [PATCH] compact some code, reorder function definitions --- main.c | 89 +++++++++++++++++++++++++++------------------------------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/main.c b/main.c index 039b8dd..d6805fb 100644 --- a/main.c +++ b/main.c @@ -361,49 +361,6 @@ int fpblock(FILE* f, char* s) { return 1; } -int fpmetatemplate(FILE* f, Lexicon* l, char* s) { - int bopen, bclose; - char ss[TAG_BODY_SIZE]; - unsigned char t = 0; - bopen = 0; - bclose = 0; - - while (*s) { - if (*s == '}') { - bclose++; - if (bopen == bclose) { - t = 0; - bopen = 0; - bclose = 0; - } - if (bopen == bclose) { - s++; - if (!fptemplate(f, l, ss)) { - return 0; - } - continue; - } - } - if (*s == '{') { - bopen++; - if (bopen == 1) { - ss[0] = 0; - t = 1; - s++; - continue; - } - } - if (slen(s) >= TAG_BODY_SIZE) - return error("Templating error", "text block exceeds tag body size"); - if (t) { - ccat(ss, *s); - } else - fprintf(f, "%c", *s); - s++; - } - return 1; -} - int fptemplate(FILE* f, Lexicon* l, char* s) { int target = 0; switch (s[0]) { @@ -456,6 +413,47 @@ int fptemplate(FILE* f, Lexicon* l, char* s) { return 1; } +int fpmetatemplate(FILE* f, Lexicon* l, char* s) { + int bopen, bclose; + char ss[TAG_BODY_SIZE]; + unsigned char t = 0; + bopen = 0; + bclose = 0; + + while (*s) { + if (*s == '}') { + bclose++; + if (bopen == bclose) { + t = 0; + bopen = 0; + bclose = 0; + s++; + if (!fptemplate(f, l, ss)) { + return 0; + } + continue; + } + } + if (*s == '{') { + bopen++; + if (bopen == 1) { + ss[0] = 0; + t = 1; + s++; + continue; + } + } + if (slen(s) >= TAG_BODY_SIZE) + return error("Templating error", "text block exceeds tag body size"); + if (t) { + ccat(ss, *s); + } else + fprintf(f, "%c", *s); + s++; + } + return 1; +} + int fpinject(FILE* f, Lexicon* l, char* filepath) { FILE* inc; int bopen, bclose; @@ -475,9 +473,6 @@ int fpinject(FILE* f, Lexicon* l, char* filepath) { t = 0; bopen = 0; bclose = 0; - } - - if (bopen == bclose) { if (!fptemplate(f, l, s)) { return 0; } @@ -487,10 +482,8 @@ int fpinject(FILE* f, Lexicon* l, char* filepath) { if (c == '{') { bopen++; if (bopen == 1) { - s[0] = 0; t = 1; - continue; } }