timekeeper

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

commit b655c44b20bfc273a2b54f451afaf0ca0697bab2
parent f1b82b09f6cce82298673864b2d712f595508748
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Sun, 24 Mar 2024 13:55:04 -0700

Add tk_htmlerror function

This function writes an error message to the HTML document using
the error class.

Diffstat:
Mpages/common.c | 22++++++++++++++++++++++
Mpages/common.h | 1+
2 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/pages/common.c b/pages/common.c @@ -1,4 +1,5 @@ #include <ctype.h> +#include <stdio.h> #include <string.h> #include "common.h" @@ -83,3 +84,24 @@ tk_startpage(struct pagedata *pd, struct pagetemplate *t, enum khttp code) return status; return KCGI_OK; } + +enum kcgi_err +tk_htmlerror(struct pagedata *pd, char *fmt, ...) +{ + enum kcgi_err status; + char ebuf[128]; + va_list ap; + + va_start(ap, fmt); + /* intentionally ignore truncated message */ + if (vsnprintf(ebuf, sizeof(ebuf), fmt, ap) < 0) + return KCGI_SYSTEM; + va_end(ap); + + if ((status = khtml_attr(&pd->html, KELEM_P, + KATTR_CLASS, "error", KATTR__MAX)) != KCGI_OK || + (status = khtml_puts(&pd->html, "Error: ")) != KCGI_OK || + (status = khtml_puts(&pd->html, ebuf)) != KCGI_OK) + return status; + return khtml_closeelem(&pd->html, 1); +} diff --git a/pages/common.h b/pages/common.h @@ -14,3 +14,4 @@ enum kcgi_err htmlheader(struct pagedata *pd); enum kcgi_err tk_startpage(struct pagedata *pd, struct pagetemplate *t, enum khttp code); +enum kcgi_err tk_htmlerror(struct pagedata *pd, char *fmt, ...);