=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/cmd.c,v retrieving revision 1.76 retrieving revision 1.77 diff -u -r1.76 -r1.77 --- src/usr.bin/tmux/cmd.c 2013/03/21 16:22:48 1.76 +++ src/usr.bin/tmux/cmd.c 2013/03/22 15:49:55 1.77 @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.76 2013/03/21 16:22:48 nicm Exp $ */ +/* $OpenBSD: cmd.c,v 1.77 2013/03/22 15:49:55 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -133,6 +133,39 @@ 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) { @@ -280,19 +313,6 @@ args_free(args); xasprintf(cause, "usage: %s %s", entry->name, entry->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