compact some code, reorder function definitions

This commit is contained in:
Iris Lightshard 2022-02-14 18:06:06 -07:00
parent 439619fd29
commit e1d19dc2a0
Signed by: Iris Lightshard
GPG key ID: 3B7FBC22144E6398

89
main.c
View file

@ -361,49 +361,6 @@ int fpblock(FILE* f, char* s) {
return 1; 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 fptemplate(FILE* f, Lexicon* l, char* s) {
int target = 0; int target = 0;
switch (s[0]) { switch (s[0]) {
@ -456,6 +413,47 @@ int fptemplate(FILE* f, Lexicon* l, char* s) {
return 1; 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) { int fpinject(FILE* f, Lexicon* l, char* filepath) {
FILE* inc; FILE* inc;
int bopen, bclose; int bopen, bclose;
@ -475,9 +473,6 @@ int fpinject(FILE* f, Lexicon* l, char* filepath) {
t = 0; t = 0;
bopen = 0; bopen = 0;
bclose = 0; bclose = 0;
}
if (bopen == bclose) {
if (!fptemplate(f, l, s)) { if (!fptemplate(f, l, s)) {
return 0; return 0;
} }
@ -487,10 +482,8 @@ int fpinject(FILE* f, Lexicon* l, char* filepath) {
if (c == '{') { if (c == '{') {
bopen++; bopen++;
if (bopen == 1) { if (bopen == 1) {
s[0] = 0; s[0] = 0;
t = 1; t = 1;
continue; continue;
} }
} }