Introduction
Introduction Statistics Contact Development Disclaimer Help
writepage(): simplify key matching... - saait - the most boring static page gen…
git clone git://git.codemadness.org/saait
Log
Files
Refs
README
LICENSE
---
commit 0007e983fbd257049d360f1347c4266ac9e83847
parent ee17d39756e30ba8fc6c6b46eecdcb08399f4d34
Author: Hiltjo Posthuma <[email protected]>
Date: Mon, 4 Dec 2017 23:20:49 +0100
writepage(): simplify key matching...
...for errors prefix the line with "filename:linenumber".
Diffstat:
M saait.c | 38 ++++++++++++-----------------…
1 file changed, 15 insertions(+), 23 deletions(-)
---
diff --git a/saait.c b/saait.c
@@ -247,10 +247,10 @@ readconfig(const char *file)
void
writepage(FILE *fp, const char *filename, struct variable *c, char *s)
{
- struct variable *var, *v;
- char *key, *e, *value;
+ struct variable *v;
+ char *key;
size_t keylen, line = 0;
- int op;
+ int op, tmpc;
for (; *s; s++) {
op = *s;
@@ -280,34 +280,26 @@ writepage(FILE *fp, const char *filename, struct variable…
for (; keylen && isspace(key[keylen - 1]); )
keylen--;
- /* page config variables */
- v = NULL;
- for (var = c; var && !v; var = var->next) {
- if (keylen == strlen(var->key) && !strncmp(var->key, k…
- v = var;
- break;
- }
- }
- /* global config variables */
- for (var = global; var && !v; var = var->next) {
- if (keylen == strlen(var->key) && !strncmp(var->key, k…
- v = var;
- break;
- }
- }
+ /* temporary NUL terminate */
+ tmpc = key[keylen];
+ key[keylen] = '\0';
+
+ if (!c || !(v = getvar(c, key)))
+ v = getvar(global, key);
+ key[keylen] = tmpc; /* restore NUL terminator to original */
+
if (!v) {
- fprintf(stderr, "%s: unknown variable: '%.*s' on line …
- filename, (int)keylen, key, line + 1);
+ fprintf(stderr, "%s:%zu: unknown variable: '%.*s'\n",
+ filename, line + 1, (int)keylen, key);
exit(1);
}
- value = v->value;
switch (op) {
case '$':
- xmlencode(value, fp);
+ xmlencode(v->value, fp);
break;
case '#':
- fputs(value, fp);
+ fputs(v->value, fp);
break;
}
}
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.