summaryrefslogtreecommitdiffstats
path: root/src/html.c
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-01 16:22:13 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-01 16:22:13 (EDT)
commit1928d91553265b9735ee16310de5ea8de051b119 (patch)
treef2a6cc0742eca3c8ff2b43cf2b6d80714a712884 /src/html.c
parent78877f2ab6034745e1cabbfe8bd049ea2b98b7d1 (diff)
downloadmarquee-1928d91553265b9735ee16310de5ea8de051b119.zip
marquee-1928d91553265b9735ee16310de5ea8de051b119.tar.gz
marquee-1928d91553265b9735ee16310de5ea8de051b119.tar.bz2
mq_html_*_free(): Remove and merge with non-*_free() variants
Diffstat (limited to 'src/html.c')
-rw-r--r--src/html.c54
1 files changed, 13 insertions, 41 deletions
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, "</" #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;