summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2016-07-22 21:39:52 +0200
committerAlfred E. Heggestad <aeh@db.org>2016-07-22 21:39:52 +0200
commited9ea7fd82a529966eee2919ddf82762cf741d91 (patch)
tree606c2059135d2259d6ceb573edc6892d97b5c0f7 /src
parent3625c3196fe1ba7f3695d30379316c2e250ee54b (diff)
cmd: add application data to cmd_arg
Diffstat (limited to 'src')
-rw-r--r--src/cmd.c16
-rw-r--r--src/ui.c6
2 files changed, 13 insertions, 9 deletions
diff --git a/src/cmd.c b/src/cmd.c
index 7562081..5fdc59f 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -165,7 +165,7 @@ static int editor_input(struct mbuf *mb, char key,
static int cmd_report(const struct cmd *cmd, struct re_printf *pf,
- struct mbuf *mb, bool compl)
+ struct mbuf *mb, bool compl, void *data)
{
struct cmd_arg arg;
int err;
@@ -177,6 +177,7 @@ static int cmd_report(const struct cmd *cmd, struct re_printf *pf,
arg.key = cmd->key;
arg.complete = compl;
+ arg.data = data;
err = cmd->h(pf, &arg);
@@ -187,7 +188,7 @@ static int cmd_report(const struct cmd *cmd, struct re_printf *pf,
static int cmd_process_edit(struct cmd_ctx **ctxp, char key,
- struct re_printf *pf)
+ struct re_printf *pf, void *data)
{
struct cmd_ctx *ctx;
bool compl = (key == '\n'), del = false;
@@ -203,7 +204,7 @@ static int cmd_process_edit(struct cmd_ctx **ctxp, char key,
return err;
if (compl || ctx->cmd->flags & CMD_PROG)
- err = cmd_report(ctx->cmd, pf, ctx->mb, compl);
+ err = cmd_report(ctx->cmd, pf, ctx->mb, compl, data);
if (del)
*ctxp = mem_deref(*ctxp);
@@ -261,10 +262,12 @@ void cmd_unregister(const struct cmd *cmdv)
* @param ctxp Pointer to context for editor (optional)
* @param key Input character
* @param pf Print function
+ * @param data Application data
*
* @return 0 if success, otherwise errorcode
*/
-int cmd_process(struct cmd_ctx **ctxp, char key, struct re_printf *pf)
+int cmd_process(struct cmd_ctx **ctxp, char key, struct re_printf *pf,
+ void *data)
{
const struct cmd *cmd;
@@ -274,7 +277,7 @@ int cmd_process(struct cmd_ctx **ctxp, char key, struct re_printf *pf)
if (key == REL)
return 0;
- return cmd_process_edit(ctxp, key, pf);
+ return cmd_process_edit(ctxp, key, pf, data);
}
cmd = cmd_find_by_key(key);
@@ -292,12 +295,13 @@ int cmd_process(struct cmd_ctx **ctxp, char key, struct re_printf *pf)
return cmd_process_edit(ctxp,
isdigit(key) ? key : 0,
- pf);
+ pf, data);
}
arg.key = key;
arg.prm = NULL;
arg.complete = true;
+ arg.data = data;
return cmd->h(pf, &arg);
}
diff --git a/src/ui.c b/src/ui.c
index 6562b7c..88bbda0 100644
--- a/src/ui.c
+++ b/src/ui.c
@@ -15,7 +15,7 @@ static struct cmd_ctx *uictx;
static void ui_handler(char key, struct re_printf *pf)
{
- (void)cmd_process(&uictx, key, pf);
+ (void)cmd_process(&uictx, key, pf, NULL);
}
@@ -117,11 +117,11 @@ int ui_input_pl(struct re_printf *pf, const struct pl *pl)
return EINVAL;
for (i=0; i<pl->l; i++) {
- err |= cmd_process(&ctx, pl->p[i], pf);
+ err |= cmd_process(&ctx, pl->p[i], pf, NULL);
}
if (pl->l > 1 && ctx)
- err |= cmd_process(&ctx, '\n', pf);
+ err |= cmd_process(&ctx, '\n', pf, NULL);
return err;
}