saait

Simple static page generator
git clone https://git.sinitax.com/codemadness/saait
Log | Files | Refs | README | LICENSE | Upstream | sfeed.txt

commit 0debc54499a6b64f5498f5f3746cd5cebb83d54b
parent c8d25c5c048770baa20b974084a77da70d130ffc
Author: Hiltjo Posthuma <hiltjo@codemadness.org>
Date:   Sun,  4 Dec 2016 14:33:37 +0100

cfg: allow spaces around =, simplify a bit

Diffstat:
MTODO | 2+-
Msaait.c | 30+++++++++++++-----------------
2 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/TODO b/TODO @@ -1,9 +1,9 @@ +x cfgfile: spaces around = skip x optimize readfile: don't copy data twice (memcpy). x reduce memory usage. x allow to override output filename (for no prefix number). - writepage() improve error messages for filenames (error on line ...). show template name and filename. -- cfgfile: spaces around = skip x don't use strndup or wrap it. - improve documentation diff --git a/saait.c b/saait.c @@ -231,25 +231,21 @@ parsevars(const char *s) continue; } - keystart = keyend = s; - valuestart = valueend = NULL; - - /* variable: key=value */ - for (; *s && *s != '\n'; s++) { - if (*s == '=') { - keyend = s; - valuestart = ++s; - break; - } - } - for (; *s; s++) { - if (*s == '\n') { - valueend = s++; - break; - } + keystart = s; + s = &s[strcspn(s, "=\n")]; + if (*s != '=') { + s++; + continue; } + for (keyend = s; keyend > keystart && isspace(keyend[-1]); keyend--) + ; + for (s++; *s && *s != '\n' && isspace(*s); s++) + ; + valuestart = s; + valueend = &s[strcspn(s, "\n")]; + /* no variable: skip */ - if (!*keystart || !valuestart || !valueend) + if (keystart == keyend) continue; v = ecalloc(1, sizeof(*v));