diff options
-rw-r--r-- | src/about/version.c | 4 | ||||
-rw-r--r-- | src/html.c | 54 | ||||
-rw-r--r-- | src/html.h | 9 |
3 files changed, 17 insertions, 50 deletions
diff --git a/src/about/version.c b/src/about/version.c index a7f20d0..3e938db 100644 --- a/src/about/version.c +++ b/src/about/version.c @@ -738,8 +738,8 @@ mq_about_version_response(MqApplication __attribute__((unused)) *application, PACKAGE_NAME, PACKAGE_VERSION_GIT), "About", mq_html_container("div", - mq_html_h3("Authors"), - mq_html_list(NULL, + mq_html_h3(NULL, "Authors"), + mq_html_list(NULL, NULL, "Patrick McDermott " "<pj@pehjota.net>", NULL), @@ -164,16 +164,13 @@ mq_html_document(const gchar *title, ...) #define TEXT_ELEMENT(ELEM) \ gchar * \ - mq_html_##ELEM(gchar *text) \ - { \ - return g_strconcat("<" #ELEM ">", text, "</" #ELEM ">", NULL); \ - } \ - gchar * \ - mq_html_##ELEM##_free(gchar *text) \ + mq_html_##ELEM(GDestroyNotify destroy, gchar *text) \ { \ gchar *e; \ e = g_strconcat("<" #ELEM ">", text, "</" #ELEM ">", NULL); \ - g_free(text); \ + if (destroy) { \ + destroy(text); \ + } \ return e; \ } TEXT_ELEMENT(h1) @@ -185,10 +182,11 @@ TEXT_ELEMENT(h6) TEXT_ELEMENT(p) #undef TEXT_ELEMENT -static gchar * -vlist(const gchar *type, va_list len_ap, va_list str_ap, GDestroyNotify destroy) +gchar * +mq_html_list(const gchar *type, GDestroyNotify destroy, ...) { gsize len; + va_list ap; gchar *child; gchar *list; gchar *ptr; @@ -197,11 +195,13 @@ vlist(const gchar *type, va_list len_ap, va_list str_ap, GDestroyNotify destroy) /* Calculate length. */ len = strlen("<ul>\n"); - while ((child = va_arg(len_ap, gchar *))) { + va_start(ap, destroy); + while ((child = va_arg(ap, gchar *))) { len += strlen("<li>\n"); len += strlen(child); len += strlen("</li>\n"); } + va_end(ap); len += strlen("</ul>\n"); ++len; /* NUL byte */ @@ -212,7 +212,8 @@ vlist(const gchar *type, va_list len_ap, va_list str_ap, GDestroyNotify destroy) } else { ptr = g_stpcpy(list, "<ul>\n"); } - while ((child = va_arg(str_ap, gchar *))) { + va_start(ap, destroy); + while ((child = va_arg(ap, gchar *))) { ptr = g_stpcpy(ptr, "<li>\n"); ptr = g_stpcpy(ptr, child); if (destroy) { @@ -220,42 +221,13 @@ vlist(const gchar *type, va_list len_ap, va_list str_ap, GDestroyNotify destroy) } ptr = g_stpcpy(ptr, "</li>\n"); } + va_end(ap); ptr = g_stpcpy(ptr, "</ul>\n"); /* g_stpcpy() adds the NUL. */ return list; } gchar * -mq_html_list(const gchar *type, ...) -{ - va_list len_ap; - va_list str_ap; - gchar *list; - - va_start(len_ap, type); - va_start(str_ap, type); - list = vlist(type, len_ap, str_ap, NULL); - va_end(len_ap); - va_end(str_ap); - return list; -} - -gchar * -mq_html_list_free(const gchar *type, ...) -{ - va_list len_ap; - va_list str_ap; - gchar *list; - - va_start(len_ap, type); - va_start(str_ap, type); - list = vlist(type, len_ap, str_ap, g_free); - va_end(len_ap); - va_end(str_ap); - return list; -} - -gchar * mq_html_container(const gchar *element, ...) { gsize len; @@ -29,9 +29,7 @@ mq_html_document(const gchar *title, ...); #define TEXT_ELEMENT(ELEM) \ gchar * \ - mq_html_##ELEM(gchar *text); \ - gchar * \ - mq_html_##ELEM##_free(gchar *text); + mq_html_##ELEM(GDestroyNotify destroy, gchar *text); TEXT_ELEMENT(h1) TEXT_ELEMENT(h2) TEXT_ELEMENT(h3) @@ -45,10 +43,7 @@ gchar * mq_html_container(const gchar *element, ...); gchar * -mq_html_list(const gchar *type, ...); - -gchar * -mq_html_list_free(const gchar *type, ...); +mq_html_list(const gchar *type, GDestroyNotify destroy, ...); gchar * mq_html_notebook(gboolean vertical, const gchar *name, guint current_page, ...); |