summaryrefslogtreecommitdiff
path: root/src/cmd.c
diff options
context:
space:
mode:
authorAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-01-28 23:14:23 +0100
committerAlfred E. Heggestad <alfred.heggestad@gmail.com>2017-01-28 23:14:23 +0100
commit05ce1932c60cc303e808255b43950f63012ca665 (patch)
tree88602e09542e3aa0947edf75872a5493d6e86a48 /src/cmd.c
parent903ce9869c933e4f13995cd9f10c1498665cfd58 (diff)
cmd: make struct commands opaque
Diffstat (limited to 'src/cmd.c')
-rw-r--r--src/cmd.c33
1 files changed, 22 insertions, 11 deletions
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;
}