Add a function that adds an entry to a menuq, normalizing a common code

path; from Tiago Cunha.
This commit is contained in:
okan
2014-01-20 18:58:03 +00:00
parent 43ccf4eae0
commit 720b5452aa
6 changed files with 34 additions and 49 deletions

17
menu.c
View File

@@ -25,6 +25,7 @@
#include <ctype.h>
#include <err.h>
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -604,6 +605,22 @@ menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr)
return (0);
}
void
menuq_add(struct menu_q *mq, void *ctx, const char *fmt, ...)
{
va_list ap;
struct menu *mi;
mi = xcalloc(1, sizeof(*mi));
mi->ctx = ctx;
va_start(ap, fmt);
(void)vsnprintf(mi->text, sizeof(mi->text), fmt, ap);
va_end(ap);
TAILQ_INSERT_TAIL(mq, mi, entry);
}
void
menuq_clear(struct menu_q *mq)
{