summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-10-01 02:08:56 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-10-01 02:08:56 (EDT)
commit2276a1f342ce58d4d7f6111b169df0b0d562a7a4 (patch)
tree1e1a3142288392b9c9e2ffcdba05e933ca1e0ade
parenta13a3a2f89f13d42529f11c8a803c417114bf144 (diff)
downloadmarquee-2276a1f342ce58d4d7f6111b169df0b0d562a7a4.zip
marquee-2276a1f342ce58d4d7f6111b169df0b0d562a7a4.tar.gz
marquee-2276a1f342ce58d4d7f6111b169df0b0d562a7a4.tar.bz2
mq_html_document(): New function
-rw-r--r--src/html.c43
-rw-r--r--src/html.h3
2 files changed, 46 insertions, 0 deletions
diff --git a/src/html.c b/src/html.c
index bf4f18c..0a0bd40 100644
--- a/src/html.c
+++ b/src/html.c
@@ -23,10 +23,53 @@
#include <string.h>
#include <glib.h>
+#include <gtk/gtk.h>
#include "html.h"
gchar *
+mq_html_document(const gchar *title, ...)
+{
+ gsize len;
+ va_list ap;
+ gchar *child;
+ gchar *document;
+ gchar *ptr;
+
+ /* Calculate length. */
+ len = strlen("<!doctype html>\n<html dir=\"");
+ len += 3; /* "ltr" or "rtl" */
+ len += strlen("\">\n<head>\n<meta charset=\"utf-8\">\n<title>");
+ len += strlen(title);
+ len += strlen("</title>\n</head>\n<body>\n");
+ va_start(ap, title);
+ while ((child = va_arg(ap, gchar *))) {
+ len += strlen(child);
+ }
+ va_end(ap);
+ len += strlen("</body>\n</html>\n");
+ ++len; /* NUL byte */
+
+ /* Build string. */
+ document = g_new(gchar, len);
+ ptr = g_stpcpy(document, "<!doctype html>\n<html dir=\"");
+ ptr = g_stpcpy(ptr, gtk_widget_get_default_direction() ==
+ GTK_TEXT_DIR_RTL ? "rtl" : "ltr");
+ ptr = g_stpcpy(ptr, "\">\n<head>\n<meta charset=\"utf-8\">\n<title>");
+ ptr = g_stpcpy(ptr, title);
+ ptr = g_stpcpy(ptr, "</title>\n</head>\n<body>\n");
+ va_start(ap, title);
+ while ((child = va_arg(ap, gchar *))) {
+ ptr = g_stpcpy(ptr, child);
+ g_free(child);
+ }
+ va_end(ap);
+ ptr = g_stpcpy(ptr, "</body>\n</html>\n"); /* g_stpcpy() adds NUL. */
+
+ return document;
+}
+
+gchar *
mq_html_container(const gchar *element, ...)
{
gsize len;
diff --git a/src/html.h b/src/html.h
index b31179d..d0bd8db 100644
--- a/src/html.h
+++ b/src/html.h
@@ -25,6 +25,9 @@
#include <glib.h>
gchar *
+mq_html_document(const gchar *title, ...);
+
+gchar *
mq_html_container(const gchar *element, ...);
gchar *