From 1928d91553265b9735ee16310de5ea8de051b119 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Sun, 01 Oct 2017 16:22:13 -0400 Subject: mq_html_*_free(): Remove and merge with non-*_free() variants --- (limited to 'src') 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), diff --git a/src/html.c b/src/html.c index f3dc841..7ef43d0 100644 --- a/src/html.c +++ b/src/html.c @@ -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, "", NULL); \ - } \ - gchar * \ - mq_html_##ELEM##_free(gchar *text) \ + mq_html_##ELEM(GDestroyNotify destroy, gchar *text) \ { \ gchar *e; \ e = g_strconcat("<" #ELEM ">", text, "", 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("\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, "\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; diff --git a/src/html.h b/src/html.h index b2b3b32..82affa8 100644 --- a/src/html.h +++ b/src/html.h @@ -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, ...); -- cgit v0.9.1