summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-01 15:56:23 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-01 15:56:23 (EDT)
commit5606936b03f66f2f62caf1330addc815d2453af8 (patch)
tree490fb30d6dfea3fc609c735613372da98e5423ff /src
parent8dd98917acb6ee2078c6d4a9e176a016b2648695 (diff)
downloadmarquee-5606936b03f66f2f62caf1330addc815d2453af8.zip
marquee-5606936b03f66f2f62caf1330addc815d2453af8.tar.gz
marquee-5606936b03f66f2f62caf1330addc815d2453af8.tar.bz2
mq_html_list_free(): New function
Diffstat (limited to 'src')
-rw-r--r--src/html.c57
-rw-r--r--src/html.h3
2 files changed, 45 insertions, 15 deletions
diff --git a/src/html.c b/src/html.c
index 16882f6..38cc3f0 100644
--- a/src/html.c
+++ b/src/html.c
@@ -185,47 +185,74 @@ TEXT_ELEMENT(h6)
TEXT_ELEMENT(p)
#undef TEXT_ELEMENT
-gchar *
-mq_html_list(const gchar *type, ...)
+static gchar *
+vlist(const gchar *type, va_list len_ap, va_list str_ap, GDestroyNotify destroy)
{
gsize len;
- va_list ap;
gchar *child;
- gchar *form;
+ gchar *list;
gchar *ptr;
/* TODO: Doesn't support specification of <ol> list types. */
/* Calculate length. */
len = strlen("<ul>\n");
- va_start(ap, type);
- while ((child = va_arg(ap, gchar *))) {
+ while ((child = va_arg(len_ap, gchar *))) {
len += strlen("<li>\n");
len += strlen(child);
len += strlen("</li>\n");
}
- va_end(ap);
len += strlen("</ul>\n");
++len; /* NUL byte */
/* Build string. */
- form = g_new(gchar, len);
+ list = g_new(gchar, len);
if (type && type[0]) {
- ptr = g_stpcpy(form, "<ol>\n");
+ ptr = g_stpcpy(list, "<ol>\n");
} else {
- ptr = g_stpcpy(form, "<ul>\n");
+ ptr = g_stpcpy(list, "<ul>\n");
}
- va_start(ap, type);
- while ((child = va_arg(ap, gchar *))) {
+ while ((child = va_arg(str_ap, gchar *))) {
ptr = g_stpcpy(ptr, "<li>\n");
ptr = g_stpcpy(ptr, child);
- g_free(child);
+ if (destroy) {
+ destroy(child);
+ }
ptr = g_stpcpy(ptr, "</li>\n");
}
- va_end(ap);
ptr = g_stpcpy(ptr, "</ul>\n"); /* g_stpcpy() adds the NUL. */
- return form;
+ 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 *
diff --git a/src/html.h b/src/html.h
index 82ab94f..b2b3b32 100644
--- a/src/html.h
+++ b/src/html.h
@@ -48,6 +48,9 @@ gchar *
mq_html_list(const gchar *type, ...);
gchar *
+mq_html_list_free(const gchar *type, ...);
+
+gchar *
mq_html_notebook(gboolean vertical, const gchar *name, guint current_page, ...);
gchar *