comparison http.c @ 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
comparison
equal deleted inserted replaced
8:0f1d65d5ea89 9:e8f61741aaec
316 316
317 /* Default to month. */ 317 /* Default to month. */
318 return PASTE_MONTH; 318 return PASTE_MONTH;
319 } 319 }
320 320
321 static void
322 render_languages(struct kreq *req, const struct paste *paste)
323 {
324 for (const char **l = languages; *l != NULL; ++l) {
325 const char *line;
326
327 if (paste->language && strcmp(paste->language, *l) == 0)
328 line = bprintf("<option value=\"%s\" selected>%s</option>", *l, *l);
329 else
330 line = bprintf("<option value=\"%s\">%s</option>", *l, *l);
331
332 khttp_puts(req, line);
333 }
334 }
335
321 static int 336 static int
322 tmpl_paste(size_t index, void *arg) 337 tmpl_paste(size_t index, void *arg)
323 { 338 {
324 struct tmpl_paste *data = arg; 339 struct tmpl_paste *data = arg;
325 struct paste *paste = &data->paste; 340 struct paste *paste = &data->paste;
430 break; 445 break;
431 case 3: 446 case 3:
432 /* Add checked attribute to combobox. */ 447 /* Add checked attribute to combobox. */
433 if (!paste->visible) 448 if (!paste->visible)
434 khttp_puts(data->req, "checked"); 449 khttp_puts(data->req, "checked");
435 break;; 450 break;
436 case 4: 451 case 4:
437 /* TODO: fragment? */ 452 render_languages(data->req, paste);
438 for (const char **l = languages; *l != NULL; ++l)
439 khttp_puts(data->req,
440 bprintf("<option value=\"%s\">%s</option>", *l, *l));
441 break; 453 break;
442 default: 454 default:
443 break; 455 break;
444 }; 456 };
445 457