compact some code, reorder function definitions
This commit is contained in:
parent
439619fd29
commit
e1d19dc2a0
1 changed files with 41 additions and 48 deletions
89
main.c
89
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue