diff options
author | June McEnroe <june@causal.agency> | 2020-07-09 15:50:19 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2020-07-09 15:50:19 -0400 |
commit | 949048079b4bd8ed947903ae56f11571fc4a9966 (patch) | |
tree | 4be7fe794ff20d0e102bc8348ca3ab3fdf0d209d | |
parent | Implement basic networks list (diff) | |
download | scooper-949048079b4bd8ed947903ae56f11571fc4a9966.tar.gz scooper-949048079b4bd8ed947903ae56f11571fc4a9966.zip |
Refactor HTML generation somewhat
Diffstat (limited to '')
-rw-r--r-- | scooper.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/scooper.c b/scooper.c index afbbda5..99e7a05 100644 --- a/scooper.c +++ b/scooper.c @@ -100,24 +100,24 @@ static enum kcgi_err fail(struct kreq *req, enum khttp http) { } static const char *stylesheet; +static enum kcgi_err htmlStylesheet(struct khtmlreq *html) { + if (!stylesheet) return KCGI_OK; + return khtml_attr( + html, KELEM_LINK, + KATTR_REL, "stylesheet", + KATTR_HREF, stylesheet, + KATTR__MAX + ); +} static enum kcgi_err htmlHead(struct khtmlreq *html, const char *title) { - enum kcgi_err error = khtml_elem(html, KELEM_DOCTYPE) + return khtml_elem(html, KELEM_DOCTYPE) || khtml_attr(html, KELEM_META, KATTR_CHARSET, "utf-8", KATTR__MAX) || khtml_elem(html, KELEM_TITLE) || khtml_puts(html, title) - || khtml_closeelem(html, 1); - if (error) return error; - if (stylesheet) { - error = khtml_attr( - html, KELEM_LINK, - KATTR_REL, "stylesheet", - KATTR_HREF, stylesheet, - KATTR__MAX - ); - if (error) return error; - } - return khtml_elem(html, KELEM_H1) + || khtml_closeelem(html, 1) + || htmlStylesheet(html) + || khtml_elem(html, KELEM_H1) || khtml_puts(html, title) || khtml_closeelem(html, 1); } @@ -135,11 +135,11 @@ static enum kcgi_err networks(struct kreq *req) { || khtml_open(&html, req, KHTML_PRETTY) || htmlHead(&html, "Networks") || khtml_elem(&html, KELEM_UL); - if (error) goto fail; + if (error) return error; int result; while (SQLITE_ROW == (result = sqlite3_step(stmt.networks))) { - const char *network = sqlite3_column_text(stmt.networks, 0); + const char *network = (const char *)sqlite3_column_text(stmt.networks, 0); char *href = khttp_urlpart( NULL, NULL, Pages[Contexts], Keys[Network].name, network, NULL ); @@ -150,15 +150,12 @@ static enum kcgi_err networks(struct kreq *req) { || khtml_puts(&html, network) || khtml_closeelem(&html, 2); free(href); - if (error) goto fail; + if (error) break; } if (result != SQLITE_DONE) errx(EX_SOFTWARE, "%s", sqlite3_errmsg(db)); - error = khtml_close(&html); - -fail: sqlite3_reset(stmt.networks); - return error; + return error || khtml_close(&html); } static enum kcgi_err contexts(struct kreq *req) { |