From 749175e23624a43a35824edada4545a6115dd4d1 Mon Sep 17 00:00:00 2001 From: okan Date: Mon, 20 Jan 2014 18:58:03 +0000 Subject: Add a function that adds an entry to a menuq, normalizing a common code path; from Tiago Cunha. --- menu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'menu.c') diff --git a/menu.c b/menu.c index c19bc4b..790282d 100644 --- a/menu.c +++ b/menu.c @@ -16,7 +16,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: menu.c,v 1.72 2014/01/03 15:29:06 okan Exp $ + * $OpenBSD: menu.c,v 1.73 2014/01/20 18:58:03 okan Exp $ */ #include @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -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) { -- cgit v1.2.3-2-gb3c3