1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- /*
- * context.c
- */
- #include <stdlib.h>
- #include <assert.h>
- #include <string.h>
- #include "private.h"
- /*--------------------------------------------------------- */
- clish_context_t *clish_context_new(clish_shell_t *shell)
- {
- clish_context_t *this;
- if (!shell)
- return NULL;
- if (!(this = malloc(sizeof(*this))))
- return NULL;
- memset(this, 0, sizeof(*this));
- this->shell = shell;
- return this;
- }
- /*--------------------------------------------------------- */
- /* Note it will not free all content because it's a
- * container only.
- */
- void clish_context_free(clish_context_t *this)
- {
- if (!this)
- return;
- free(this);
- }
- /*--------------------------------------------------------- */
- clish_shell_t *clish_context__get_shell(const void *this)
- {
- const clish_context_t *context = (const clish_context_t *)this;
- return context->shell;
- }
- /*--------------------------------------------------------- */
- void clish_context__set_cmd(void *this, clish_command_t *cmd)
- {
- clish_context_t *context = (clish_context_t *)this;
- assert(context);
- context->cmd = cmd;
- }
- /*--------------------------------------------------------- */
- const clish_command_t *clish_context__get_cmd(const void *this)
- {
- const clish_context_t *context = (const clish_context_t *)this;
- return context->cmd;
- }
- /*--------------------------------------------------------- */
- void clish_context__set_pargv(void *this, clish_pargv_t *pargv)
- {
- clish_context_t *context = (clish_context_t *)this;
- assert(context);
- context->pargv = pargv;
- }
- /*--------------------------------------------------------- */
- clish_pargv_t *clish_context__get_pargv(const void *this)
- {
- const clish_context_t *context = (const clish_context_t *)this;
- return context->pargv;
- }
- /*--------------------------------------------------------- */
- void clish_context__set_action(void *this, clish_action_t *action)
- {
- clish_context_t *context = (clish_context_t *)this;
- assert(context);
- context->action = action;
- }
- /*--------------------------------------------------------- */
- const clish_action_t *clish_context__get_action(const void *this)
- {
- const clish_context_t *context = (const clish_context_t *)this;
- return context->action;
- }
- /*--------------------------------------------------------- */
|