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 /kbfunc.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 'kbfunc.c')
-rw-r--r-- | kbfunc.c | 32 |
1 files changed, 8 insertions, 24 deletions
@@ -15,7 +15,7 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * - * $OpenBSD: kbfunc.c,v 1.86 2014/01/03 15:29:06 okan Exp $ + * $OpenBSD: kbfunc.c,v 1.87 2014/01/20 18:58:03 okan Exp $ */ #include <sys/param.h> @@ -151,13 +151,8 @@ kbfunc_client_search(struct client_ctx *cc, union arg *arg) old_cc = client_current(); TAILQ_INIT(&menuq); - - TAILQ_FOREACH(cc, &Clientq, entry) { - mi = xcalloc(1, sizeof(*mi)); - (void)strlcpy(mi->text, cc->name, sizeof(mi->text)); - mi->ctx = cc; - TAILQ_INSERT_TAIL(&menuq, mi, entry); - } + TAILQ_FOREACH(cc, &Clientq, entry) + menuq_add(&menuq, cc, "%s", cc->name); if ((mi = menu_filter(sc, &menuq, "window", NULL, 0, search_match_client, search_print_client)) != NULL) { @@ -182,13 +177,8 @@ kbfunc_menu_search(struct client_ctx *cc, union arg *arg) struct menu_q menuq; TAILQ_INIT(&menuq); - - TAILQ_FOREACH(cmd, &Conf.cmdq, entry) { - mi = xcalloc(1, sizeof(*mi)); - (void)strlcpy(mi->text, cmd->label, sizeof(mi->text)); - mi->ctx = cmd; - TAILQ_INSERT_TAIL(&menuq, mi, entry); - } + TAILQ_FOREACH(cmd, &Conf.cmdq, entry) + menuq_add(&menuq, cmd, "%s", cmd->label); if ((mi = menu_filter(sc, &menuq, "application", NULL, 0, search_match_text, NULL)) != NULL) @@ -284,12 +274,8 @@ kbfunc_exec(struct client_ctx *cc, union arg *arg) /* check for truncation etc */ if (l == -1 || l >= (int)sizeof(tpath)) continue; - if (access(tpath, X_OK) == 0) { - mi = xcalloc(1, sizeof(*mi)); - (void)strlcpy(mi->text, - dp->d_name, sizeof(mi->text)); - TAILQ_INSERT_TAIL(&menuq, mi, entry); - } + if (access(tpath, X_OK) == 0) + menuq_add(&menuq, NULL, "%s", dp->d_name); } (void)closedir(dirp); } @@ -360,9 +346,7 @@ kbfunc_ssh(struct client_ctx *cc, union arg *arg) if (p - buf + 1 > sizeof(hostbuf)) continue; (void)strlcpy(hostbuf, buf, p - buf + 1); - mi = xcalloc(1, sizeof(*mi)); - (void)strlcpy(mi->text, hostbuf, sizeof(mi->text)); - TAILQ_INSERT_TAIL(&menuq, mi, entry); + menuq_add(&menuq, NULL, hostbuf); } free(lbuf); (void)fclose(fp); |