diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/html.c | 57 | ||||
-rw-r--r-- | src/html.h | 3 |
2 files changed, 45 insertions, 15 deletions
@@ -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 * @@ -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 * |