diff options
author | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-02-18 23:20:21 +0000 |
---|---|---|
committer | Nicholas Marriott <nicholas.marriott@gmail.com> | 2013-02-18 23:20:21 +0000 |
commit | 293e331d69def60110bdc49b6453af905e0509b3 (patch) | |
tree | 3dbb4230607dc6bb0a40d3a1e9b71d0f56774c7a /cfg.c | |
parent | 2a91025581ddaa934ffa471f5b27a33d19e4ea2d (diff) | |
download | rtmux-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 'cfg.c')
-rw-r--r-- | cfg.c | 35 |
1 files changed, 19 insertions, 16 deletions
@@ -80,7 +80,7 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) char *buf, *copy, *line, *cause; size_t len, oldlen; struct cmd_list *cmdlist; - struct cmd_ctx ctx; + struct cmd_ctx *ctx; enum cmd_retval retval; if ((f = fopen(path, "rb")) == NULL) { @@ -90,6 +90,21 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) cfg_references++; + ctx = cmd_get_ctx(); + if (ctxin == NULL) { + ctx->msgdata = NULL; + ctx->curclient = NULL; + ctx->cmdclient = NULL; + } else { + ctx->msgdata = ctxin->msgdata; + ctx->curclient = ctxin->curclient; + ctx->cmdclient = ctxin->cmdclient; + } + + ctx->error = cfg_error; + ctx->print = cfg_print; + ctx->info = cfg_print; + n = 0; line = NULL; retval = CMD_RETURN_NORMAL; @@ -146,22 +161,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) if (cmdlist == NULL) continue; - if (ctxin == NULL) { - ctx.msgdata = NULL; - ctx.curclient = NULL; - ctx.cmdclient = NULL; - } else { - ctx.msgdata = ctxin->msgdata; - ctx.curclient = ctxin->curclient; - ctx.cmdclient = ctxin->cmdclient; - } - - ctx.error = cfg_error; - ctx.print = cfg_print; - ctx.info = cfg_print; - cfg_cause = NULL; - switch (cmd_list_exec(cmdlist, &ctx)) { + switch (cmd_list_exec(cmdlist, ctx)) { case CMD_RETURN_YIELD: if (retval != CMD_RETURN_ATTACH) retval = CMD_RETURN_YIELD; @@ -186,6 +187,8 @@ load_cfg(const char *path, struct cmd_ctx *ctxin, struct causelist *causes) } fclose(f); + cmd_free_ctx(ctx); + cfg_references--; return (retval); |