summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPatrick McDermott <pj@pehjota.net>2017-11-04 13:40:12 (EDT)
committer Patrick McDermott <pj@pehjota.net>2017-11-04 13:40:12 (EDT)
commit3ff77f34e416392dd930a3655d59ff08f25e1129 (patch)
tree11bd4b13c70c9856386160d4908221b654c248c6 /src
parentcf8d241f10ce65ba49e15f4ede20223a2066051b (diff)
downloadmarquee-3ff77f34e416392dd930a3655d59ff08f25e1129.zip
marquee-3ff77f34e416392dd930a3655d59ff08f25e1129.tar.gz
marquee-3ff77f34e416392dd930a3655d59ff08f25e1129.tar.bz2
mq_html_input_select(): Allow label to be disabled
Diffstat (limited to 'src')
-rw-r--r--src/utils/html.c39
1 files changed, 26 insertions, 13 deletions
diff --git a/src/utils/html.c b/src/utils/html.c
index 4fd71ea..b8abbac 100644
--- a/src/utils/html.c
+++ b/src/utils/html.c
@@ -761,11 +761,15 @@ mq_html_input_select(const gchar *name, const gchar *label,
g_assert(selected && selected[0]); /* Would cause buffer overflow */
/* Calculate length. */
- len = strlen("<label for=\"");
- len += strlen(name);
- len += strlen("\">\n<span>");
- len += strlen(label);
- len += strlen(":</span>\n<select name=\"");
+ len = 0;
+ if (label && label[0]) {
+ len += strlen("<label for=\"");
+ len += strlen(name);
+ len += strlen("\">\n<span>");
+ len += strlen(label);
+ len += strlen(":</span>\n");
+ }
+ len += strlen("<select name=\"");
len += strlen(name);
len += strlen("\" id=\"");
len += strlen(name);
@@ -782,16 +786,22 @@ mq_html_input_select(const gchar *name, const gchar *label,
}
va_end(ap);
len += strlen(" selected=\"selected\"");
- len += strlen("</select>\n</label>\n");
+ len += strlen("</select>\n");
+ if (label && label[0]) {
+ len += strlen("</label>\n");
+ }
++len; /* NUL byte */
/* Build string. */
- select = g_new(gchar, len);
- ptr = g_stpcpy(select, "<label for=\"");
- ptr = g_stpcpy(ptr, name);
- ptr = g_stpcpy(ptr, "\">\n<span>");
- ptr = g_stpcpy(ptr, label);
- ptr = g_stpcpy(ptr, ":</span>\n<select name=\"");
+ ptr = select = g_new(gchar, len);
+ if (label && label[0]) {
+ ptr = g_stpcpy(ptr, "<label for=\"");
+ ptr = g_stpcpy(ptr, name);
+ ptr = g_stpcpy(ptr, "\">\n<span>");
+ ptr = g_stpcpy(ptr, label);
+ ptr = g_stpcpy(ptr, ":</span>\n");
+ }
+ ptr = g_stpcpy(ptr, "<select name=\"");
ptr = g_stpcpy(ptr, name);
ptr = g_stpcpy(ptr, "\" id=\"");
ptr = g_stpcpy(ptr, name);
@@ -816,7 +826,10 @@ mq_html_input_select(const gchar *name, const gchar *label,
ptr = g_stpcpy(ptr, "</option>\n");
}
va_end(ap);
- ptr = g_stpcpy(ptr, "</select>\n</label>\n"); /* g_stpcpy() adds NUL */
+ ptr = g_stpcpy(ptr, "</select>\n");
+ if (label && label[0]) {
+ ptr = g_stpcpy(ptr, "</label>\n"); /* g_stpcpy() adds NUL */
+ }
return select;
}