summaryrefslogtreecommitdiff
path: root/src/cmd.c
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/cmd.c
parent3625c3196fe1ba7f3695d30379316c2e250ee54b (diff)
cmd: add application data to cmd_arg
Diffstat (limited to 'src/cmd.c')
-rw-r--r--src/cmd.c16
1 files changed, 10 insertions, 6 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);
}