From 05ce1932c60cc303e808255b43950f63012ca665 Mon Sep 17 00:00:00 2001 From: "Alfred E. Heggestad" Date: Sat, 28 Jan 2017 23:14:23 +0100 Subject: cmd: make struct commands opaque --- src/cmd.c | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) (limited to 'src/cmd.c') diff --git a/src/cmd.c b/src/cmd.c index 14b0ee1..78c3522 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -28,6 +28,10 @@ struct cmd_ctx { bool is_long; }; +struct commands { + struct list cmdl; /**< List of command blocks (struct cmds) */ +}; + static int cmd_print_all(struct re_printf *pf, const struct commands *commands, @@ -51,6 +55,14 @@ static void ctx_destructor(void *arg) } +static void commands_destructor(void *data) +{ + struct commands *commands = data; + + list_flush(&commands->cmdl); +} + + static int ctx_alloc(struct cmd_ctx **ctxp, const struct cmd *cmd) { struct cmd_ctx *ctx; @@ -703,21 +715,20 @@ int cmd_print(struct re_printf *pf, const struct commands *commands) } -int cmd_init(struct commands *commands) +int cmd_init(struct commands **commandsp) { - if (!commands) - return EINVAL; + struct commands *commands; - list_init(&commands->cmdl); + if (!commandsp) + return EINVAL; - return 0; -} + commands = mem_zalloc(sizeof(*commands), commands_destructor); + if (!commands) + return ENOMEM; + list_init(&commands->cmdl); -void cmd_close(struct commands *commands) -{ - if (!commands) - return; + *commandsp = commands; - list_flush(&commands->cmdl); + return 0; } -- cgit v1.2.3