diff options
author | okan | 2014-01-20 18:58:03 +0000 |
---|---|---|
committer | okan | 2014-01-20 18:58:03 +0000 |
commit | 749175e23624a43a35824edada4545a6115dd4d1 (patch) | |
tree | 36997c1c39ae9c0e0881ff9083394c29aa3a3e12 /menu.c | |
parent | 7c3d7c7e009aba5952f235258aecebf4a42fcd3a (diff) | |
download | cwm-749175e23624a43a35824edada4545a6115dd4d1.tar.gz |
Add a function that adds an entry to a menuq, normalizing a common code
path; from Tiago Cunha.
Diffstat (limited to '')
-rw-r--r-- | menu.c | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -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 <sys/param.h> @@ -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> @@ -605,6 +606,22 @@ menu_keycode(XKeyEvent *ev, enum ctltype *ctl, char *chr) } 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) { struct menu *mi; |