X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fwgtpkg-mustach.c;h=110f11befc851593c019db43eb15112b9bc4e00b;hb=dcf194289a6af8c0a6b6263a2686af8fa44a37f2;hp=6c3311d887b11f24f25d13baa2860efb3d6c99b0;hpb=2aaf35ab55872771af5dcd3d4140215fec506e53;p=src%2Fapp-framework-main.git diff --git a/src/wgtpkg-mustach.c b/src/wgtpkg-mustach.c index 6c3311d..110f11b 100644 --- a/src/wgtpkg-mustach.c +++ b/src/wgtpkg-mustach.c @@ -28,7 +28,9 @@ #define MAX_DEPTH 256 - +/* + * exploration state when instanciating mustache + */ struct expl { struct json_object *root; int depth; @@ -110,6 +112,31 @@ static char *first(char **name, int isptr) return r; } +/* + * Returns the unescaped version of the first value + * and update 'val' to point the next value if any. + */ +static char *value(char **val) +{ + char *r, *read, *write, c; + + c = *(read = *val); + if (!c) + r = NULL; + else { + r = write = read; + while (c && c != '|') { + if (c == '\\' && (read[1] == '|' || read[1] == '\\')) + c = *++read; + *write++ = c; + c = *++read; + } + *write = 0; + *val = read + !!c; + } + return r; +} + /* * Replace the last occurence of ':' followed by * any character not being '*' by ':*', the @@ -179,7 +206,11 @@ static struct json_object *find(struct expl *e, const char *name) /* check the value if requested */ if (v) { i = v[0] == '!'; - if (i == !strcmp(&v[i], json_object_get_string(o))) + v += i; + do { + c = value(&v); + } while (c && strcmp(c, json_object_get_string(o))); + if (i != !c) o = NULL; } return o; @@ -279,6 +310,15 @@ static struct mustach_itf itf = { .leave = leave }; +/* + * Apply the object 'root' to the mustache 'template'. + * In case of success, the function returns 0, the pointer + * 'result' receives the allocated instanciation and + * the pointer 'size' its size. Note that the real size + * is one byte more to effectively store the terminating + * null. + * In case of error, it returns a negative error code. + */ int apply_mustach(const char *template, struct json_object *root, char **result, size_t *size) { struct expl e;