", f); + fpmetatemplate(f, l, s); + fputs("
", f); + return 1; +} + +int fpul(FILE* f, Lexicon* l, char* s) { + fputs("", f);
+ fputs(s, f);
+ fputs("
", f);
+ return 1;
+}
+
+int fpbold(FILE* f, char* s) {
+ fputs("", f);
+ fputs(s, f);
+ fputs("", f);
+ return 1;
+}
+
+int fpitalic(FILE* f, char* s) {
+ fputs("", f);
+ fputs(s, f);
+ fputs("", f);
+ return 1;
+}
+
+int fpstrike(FILE* f, char* s) {
+ fputs("", f); + fputs(s, f); + fputs("", f); + return 1; +} + +int fpquote(FILE* f, char* s) { + fputs("
", f); + fputs(s, f); + fputs("", f); + return 1; +} + +int fpblock(FILE* f, char* s) { + fputs("
", f); + fputs(s, f); + fputs("", f); + return 1; +} + +int fpmetatemplate(FILE* f, Lexicon* l, char* s) { + int bopen, bclose; + char ss[4096]; + 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) > 4095) + return error("Templating error", "text block over 16k"); + if (t) { + ccat(ss, *s); + } else + fprintf(f, "%c", *s); + s++; + } + return 1; +} + int fptemplate(FILE* f, Lexicon* l, char* s) { - int target; - if (s[0] == '/') - return fpportal(f, l, s + 1, 1); - if (s[0] == '*') - return fphref(f, s + 1); - if (s[0] == ':') - return fpimg(f, s + 1); - if (s[0] == '?') - return fphimg(f, s + 1); - if (s[0] == '_') - return fpaudio(f, s + 1); - target = findf(l, s); + int target = 0; + switch (s[0]) { + case '/': + return fpportal(f, l, s + 1, 1); + case '*': + return fphref(f, s + 1); + case ':': + return fpimg(f, s + 1); + case '?': + return fphimg(f, s + 1); + case '_': + return fpaudio(f, s + 1); + case '`': + return fpcode(f, s + 1); + case '~': + return fpitalic(f, s + 1); + case '>': + return fpblock(f, s + 1); + case '\'': + return fpquote(f, s + 1); + case '$': + return fppre(f, s + 1); + case '@': + return fpbold(f, s + 1); + case '\\': + return fpstrike(f, s + 1); + case '!': + return fph3(f, s + 1); + case '.': + return fph4(f, s + 1); + case '+': + return fppublish(f, s + 1); + case '#': + return fpol(f, l, s + 1); + case ',': + return fpul(f, l, s + 1); + case '-': + return fpli(f, l, s + 1); + case '&': + return fppara(f, l, s + 1); + } + if (s[0]) + target = findf(l, s); if (target < 0) return error("Missing link", s); - fprintf(f, "", scsw(stlc(s), ' ', '_')); + fprintf(f, "", scsw(stlc(s), ' ', '_')); fprintf(f, "%s", scsw(stlc(s), '_', ' ')); l->refs[target]++; return 1; @@ -306,25 +458,43 @@ int fptemplate(FILE* f, Lexicon* l, char* s) { int fpinject(FILE* f, Lexicon* l, char* filepath) { FILE* inc; - char c, s[1024]; + int bopen, bclose; + char c, s[4096]; unsigned char t = 0; + /*fprintf(stderr, "Building: %s\n", filepath);*/ + bopen = 0; + bclose = 0; scsw(filepath, ' ', '_'); if (!(inc = fopen(filepath, "r"))) return error("Missing include", filepath); s[0] = 0; while ((c = fgetc(inc)) != EOF) { if (c == '}') { - t = 0; - if (!fptemplate(f, l, s)) - return 0; - continue; + bclose++; + if (bopen == bclose) { + t = 0; + bopen = 0; + bclose = 0; + } + + if (bopen == bclose) { + if (!fptemplate(f, l, s)) { + return 0; + } + continue; + } } if (c == '{') { - s[0] = 0; - t = 1; - continue; + bopen++; + if (bopen == 1) { + + s[0] = 0; + t = 1; + + continue; + } } - if (slen(s) > 1023) + if (slen(s) > 4095) return error("Templating error", filepath); if (t) ccat(s, c);