changeset 9:e8f61741aaec

pasterd: bring language into /fork
author David Demelier <markand@malikania.fr>
date Wed, 05 Feb 2020 14:26:19 +0100
parents 0f1d65d5ea89
children 75cfe3795de3
files http.c
diffstat 1 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/http.c	Wed Feb 05 14:16:00 2020 +0100
+++ b/http.c	Wed Feb 05 14:26:19 2020 +0100
@@ -318,6 +318,21 @@
 	return PASTE_MONTH;
 }
 
+static void
+render_languages(struct kreq *req, const struct paste *paste)
+{
+	for (const char **l = languages; *l != NULL; ++l) {
+		const char *line;
+
+		if (paste->language && strcmp(paste->language, *l) == 0)
+			line = bprintf("<option value=\"%s\" selected>%s</option>", *l, *l);
+		else
+			line = bprintf("<option value=\"%s\">%s</option>", *l, *l);
+
+		khttp_puts(req, line);
+	}
+}
+
 static int
 tmpl_paste(size_t index, void *arg)
 {
@@ -432,12 +447,9 @@
 		/* Add checked attribute to combobox. */
 		if (!paste->visible)
 			khttp_puts(data->req, "checked");
-		break;;
+		break;
 	case 4:
-		/* TODO: fragment? */
-		for (const char **l = languages; *l != NULL; ++l)
-			khttp_puts(data->req,
-			    bprintf("<option value=\"%s\">%s</option>", *l, *l));
+		render_languages(data->req, paste);
 		break;
 	default:
 		break;