timekeeper

[Abandoned unfinished] CGI web application in C for time tracking. (My first, just a learning project)
Log | Files | Refs | README

commit 10e89d975acdef99f89a202e1bbe7e8963190ed0
parent 7f4a3304dea370c99688139566d40e7929201b9f
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Mon, 11 Mar 2024 19:39:32 -0700

Add htmlscript function

A simple function to make including scripts using kcgihtml(3) easier.

Diffstat:
Mhtml.c | 12++++++++++++
Mhtml.h | 1+
Mpages/main.c | 8++------
3 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/html.c b/html.c @@ -30,3 +30,15 @@ htmllink(struct pagedata *pd, char *link, char *text) return status; return KCGI_OK; } + +enum kcgi_err +htmlscript(struct pagedata *pd, char *src) +{ + enum kcgi_err status; + + if ((status = khtml_attr(&pd->html, KELEM_SCRIPT, + KATTR_SRC, src, KATTR__MAX)) != KCGI_OK || + (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK) + return status; + return KCGI_OK; +} diff --git a/html.h b/html.h @@ -1,2 +1,3 @@ enum kcgi_err htmlwithin(struct pagedata *pd, enum kelem e, char *text); enum kcgi_err htmllink(struct pagedata *pd, char *link, char *text); +enum kcgi_err htmlscript(struct pagedata *pd, char *src); diff --git a/pages/main.c b/pages/main.c @@ -325,12 +325,8 @@ pagemain(struct pagedata *pd) if ((status = htmlwithin(pd, KELEM_H1, "Timekeeper")) != KCGI_OK || (status = printtimes(pd, times)) != KCGI_OK || - (status = khtml_attr(&pd->html, KELEM_SCRIPT, - KATTR_SRC, "scripts/counter.js", KATTR__MAX)) != KCGI_OK || - (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK || - (status = khtml_attr(&pd->html, KELEM_SCRIPT, - KATTR_SRC, "scripts/localize.js", KATTR__MAX)) != KCGI_OK || - (status = khtml_closeelem(&pd->html, 1)) != KCGI_OK) { + (status = htmlscript(pd, "scripts/counter.js")) != KCGI_OK || + (status = htmlscript(pd, "scripts/localize.js")) != KCGI_OK) { freetimesheet(times); return status; }