aboutsummaryrefslogtreecommitdiff
path: root/cmd.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicholas.marriott@gmail.com>2013-02-18 23:20:21 +0000
committerNicholas Marriott <nicholas.marriott@gmail.com>2013-02-18 23:20:21 +0000
commit293e331d69def60110bdc49b6453af905e0509b3 (patch)
tree3dbb4230607dc6bb0a40d3a1e9b71d0f56774c7a /cmd.c
parent2a91025581ddaa934ffa471f5b27a33d19e4ea2d (diff)
downloadrtmux-293e331d69def60110bdc49b6453af905e0509b3.tar.gz
rtmux-293e331d69def60110bdc49b6453af905e0509b3.tar.bz2
rtmux-293e331d69def60110bdc49b6453af905e0509b3.zip
Add functions to allocate and free command contexts rather than doing it all on
the stack.
Diffstat (limited to 'cmd.c')
-rw-r--r--cmd.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/cmd.c b/cmd.c
index 52c1a303..23e86cff 100644
--- a/cmd.c
+++ b/cmd.c
@@ -132,6 +132,39 @@ struct winlink *cmd_find_window_offset(const char *, struct session *, int *);
int cmd_find_index_offset(const char *, struct session *, int *);
struct window_pane *cmd_find_pane_offset(const char *, struct winlink *);
+struct cmd_ctx *
+cmd_get_ctx(void)
+{
+ struct cmd_ctx *ctx;
+
+ ctx = xcalloc(1, sizeof *ctx);
+ ctx->references = 0;
+
+ cmd_ref_ctx(ctx);
+ return (ctx);
+}
+
+void
+cmd_free_ctx(struct cmd_ctx *ctx)
+{
+ if (ctx->cmdclient != NULL)
+ ctx->cmdclient->references--;
+ if (ctx->curclient != NULL)
+ ctx->curclient->references--;
+ if (--ctx->references == 0)
+ free(ctx);
+}
+
+void
+cmd_ref_ctx(struct cmd_ctx *ctx)
+{
+ ctx->references++;
+ if (ctx->cmdclient != NULL)
+ ctx->cmdclient->references++;
+ if (ctx->curclient != NULL)
+ ctx->curclient->references++;
+}
+
int
cmd_pack_argv(int argc, char **argv, char *buf, size_t len)
{
@@ -281,19 +314,6 @@ usage:
return (NULL);
}
-enum cmd_retval
-cmd_exec(struct cmd *cmd, struct cmd_ctx *ctx)
-{
- return (cmd->entry->exec(cmd, ctx));
-}
-
-void
-cmd_free(struct cmd *cmd)
-{
- args_free(cmd->args);
- free(cmd);
-}
-
size_t
cmd_print(struct cmd *cmd, char *buf, size_t len)
{