diff options
author | Christian Grothoff <christian@grothoff.org> | 2024-03-25 12:46:53 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2024-03-25 12:47:52 +0100 |
commit | f5f1c083258e80f763db7c87d3357c8eab53019d (patch) | |
tree | f0a549eb0d41d7bdc70d754a1207371a236cf4b1 | |
parent | 133c3713f0ba2e5e383d7dce82903bee3caffdf2 (diff) |
import latest upstream from mustach
-rw-r--r-- | src/templating/AUTHORS | 1 | ||||
-rw-r--r-- | src/templating/mustach.c | 24 | ||||
-rw-r--r-- | src/templating/test-specs/test-specs-cjson.ref | 2 | ||||
-rw-r--r-- | src/templating/test-specs/test-specs-jansson.ref | 2 | ||||
-rw-r--r-- | src/templating/test-specs/test-specs-json-c.ref | 2 |
5 files changed, 17 insertions, 14 deletions
diff --git a/src/templating/AUTHORS b/src/templating/AUTHORS index fbe9e100c..110b36981 100644 --- a/src/templating/AUTHORS +++ b/src/templating/AUTHORS @@ -5,6 +5,7 @@ Contributors: Abhishek Mishra Atlas Ben Beasley + Christian Grothoff Dominik Kummer Gabriel Zachmann Harold L Marzan diff --git a/src/templating/mustach.c b/src/templating/mustach.c index 1bf482bce..9f5af131c 100644 --- a/src/templating/mustach.c +++ b/src/templating/mustach.c @@ -32,6 +32,7 @@ struct iwrap { int (*get)(void *closure, const char *name, struct mustach_sbuf *sbuf); int (*partial)(void *closure, const char *name, struct mustach_sbuf *sbuf); void *closure_partial; /* closure for partial */ + FILE *file; int flags; int nesting; }; @@ -226,17 +227,17 @@ static int iwrap_partial(void *closure, const char *name, struct mustach_sbuf *s return rc; } -static int emitprefix(struct iwrap *iwrap, FILE *file, struct prefix *prefix) +static int emitprefix(struct iwrap *iwrap, struct prefix *prefix) { if (prefix->prefix) { - int rc = emitprefix(iwrap, file, prefix->prefix); + int rc = emitprefix(iwrap, prefix->prefix); if (rc < 0) return rc; } - return prefix->len ? iwrap->emit(iwrap->closure, prefix->start, prefix->len, 0, file) : 0; + return prefix->len ? iwrap->emit(iwrap->closure, prefix->start, prefix->len, 0, iwrap->file) : 0; } -static int process(const char *template, size_t length, struct iwrap *iwrap, FILE *file, struct prefix *prefix) +static int process(const char *template, size_t length, struct iwrap *iwrap, struct prefix *prefix) { struct mustach_sbuf sbuf; char opstr[MUSTACH_MAX_DELIM_LENGTH], clstr[MUSTACH_MAX_DELIM_LENGTH]; @@ -262,11 +263,11 @@ static int process(const char *template, size_t length, struct iwrap *iwrap, FIL l = (beg != end) + (size_t)(beg - template); if (stdalone != 2 && enabled) { if (beg != template /* don't prefix empty lines */) { - rc = emitprefix(iwrap, file, &pref); + rc = emitprefix(iwrap, &pref); if (rc < 0) return rc; } - rc = iwrap->emit(iwrap->closure, template, l, 0, file); + rc = iwrap->emit(iwrap->closure, template, l, 0, iwrap->file); if (rc < 0) return rc; } @@ -279,7 +280,7 @@ static int process(const char *template, size_t length, struct iwrap *iwrap, FIL } else if (!isspace(c)) { if (stdalone == 2 && enabled) { - rc = emitprefix(iwrap, file, &pref); + rc = emitprefix(iwrap, &pref); if (rc < 0) return rc; pref.len = 0; @@ -361,7 +362,7 @@ get_name: if (stdalone) stdalone = 2; else if (enabled) { - rc = emitprefix(iwrap, file, &pref); + rc = emitprefix(iwrap, &pref); if (rc < 0) return rc; pref.len = 0; @@ -438,7 +439,7 @@ get_name: rc = iwrap->partial(iwrap->closure_partial, name, &sbuf); if (rc >= 0) { iwrap->nesting++; - rc = process(sbuf.value, sbuf_length(&sbuf), iwrap, file, &pref); + rc = process(sbuf.value, sbuf_length(&sbuf), iwrap, &pref); sbuf_release(&sbuf); iwrap->nesting--; } @@ -450,7 +451,7 @@ get_name: default: /* replacement */ if (enabled) { - rc = iwrap->put(iwrap->closure_put, name, c != '&', file); + rc = iwrap->put(iwrap->closure_put, name, c != '&', iwrap->file); if (rc < 0) return rc; } @@ -492,13 +493,14 @@ int mustach_file(const char *template, size_t length, const struct mustach_itf * iwrap.next = itf->next; iwrap.leave = itf->leave; iwrap.get = itf->get; + iwrap.file = file; iwrap.flags = flags; iwrap.nesting = 0; /* process */ rc = itf->start ? itf->start(closure) : 0; if (rc == 0) - rc = process(template, length, &iwrap, file, NULL); + rc = process(template, length, &iwrap, NULL); if (itf->stop) itf->stop(closure, rc); return rc; diff --git a/src/templating/test-specs/test-specs-cjson.ref b/src/templating/test-specs/test-specs-cjson.ref index 41e1c8de6..8897c66cc 100644 --- a/src/templating/test-specs/test-specs-cjson.ref +++ b/src/templating/test-specs/test-specs-cjson.ref @@ -52,7 +52,7 @@ processing file test-specs/spec/specs/delimiters.json [3] Inverted Sections Delimiters set outside inverted sections should persist. => SUCCESS -[4] Partial Inheritance +[4] Partial Inheritence Delimiters set in a parent template should not affect a partial. => SUCCESS [5] Post-Partial Behavior diff --git a/src/templating/test-specs/test-specs-jansson.ref b/src/templating/test-specs/test-specs-jansson.ref index 2e1e9185b..a1cef19c1 100644 --- a/src/templating/test-specs/test-specs-jansson.ref +++ b/src/templating/test-specs/test-specs-jansson.ref @@ -52,7 +52,7 @@ processing file test-specs/spec/specs/delimiters.json [3] Inverted Sections Delimiters set outside inverted sections should persist. => SUCCESS -[4] Partial Inheritance +[4] Partial Inheritence Delimiters set in a parent template should not affect a partial. => SUCCESS [5] Post-Partial Behavior diff --git a/src/templating/test-specs/test-specs-json-c.ref b/src/templating/test-specs/test-specs-json-c.ref index 41e1c8de6..8897c66cc 100644 --- a/src/templating/test-specs/test-specs-json-c.ref +++ b/src/templating/test-specs/test-specs-json-c.ref @@ -52,7 +52,7 @@ processing file test-specs/spec/specs/delimiters.json [3] Inverted Sections Delimiters set outside inverted sections should persist. => SUCCESS -[4] Partial Inheritance +[4] Partial Inheritence Delimiters set in a parent template should not affect a partial. => SUCCESS [5] Post-Partial Behavior |