context.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * context.c
  3. */
  4. #include <stdlib.h>
  5. #include <assert.h>
  6. #include <string.h>
  7. #include "private.h"
  8. /*--------------------------------------------------------- */
  9. clish_context_t *clish_context_new(clish_shell_t *shell)
  10. {
  11. clish_context_t *this;
  12. if (!shell)
  13. return NULL;
  14. if (!(this = malloc(sizeof(*this))))
  15. return NULL;
  16. memset(this, 0, sizeof(*this));
  17. this->shell = shell;
  18. return this;
  19. }
  20. /*--------------------------------------------------------- */
  21. /* Note it will not free all content because it's a
  22. * container only.
  23. */
  24. void clish_context_free(clish_context_t *this)
  25. {
  26. if (!this)
  27. return;
  28. free(this);
  29. }
  30. /*--------------------------------------------------------- */
  31. clish_shell_t *clish_context__get_shell(const void *this)
  32. {
  33. const clish_context_t *context = (const clish_context_t *)this;
  34. return context->shell;
  35. }
  36. /*--------------------------------------------------------- */
  37. void clish_context__set_cmd(void *this, clish_command_t *cmd)
  38. {
  39. clish_context_t *context = (clish_context_t *)this;
  40. assert(context);
  41. context->cmd = cmd;
  42. }
  43. /*--------------------------------------------------------- */
  44. const clish_command_t *clish_context__get_cmd(const void *this)
  45. {
  46. const clish_context_t *context = (const clish_context_t *)this;
  47. return context->cmd;
  48. }
  49. /*--------------------------------------------------------- */
  50. void clish_context__set_pargv(void *this, clish_pargv_t *pargv)
  51. {
  52. clish_context_t *context = (clish_context_t *)this;
  53. assert(context);
  54. context->pargv = pargv;
  55. }
  56. /*--------------------------------------------------------- */
  57. clish_pargv_t *clish_context__get_pargv(const void *this)
  58. {
  59. const clish_context_t *context = (const clish_context_t *)this;
  60. return context->pargv;
  61. }
  62. /*--------------------------------------------------------- */
  63. void clish_context__set_action(void *this, clish_action_t *action)
  64. {
  65. clish_context_t *context = (clish_context_t *)this;
  66. assert(context);
  67. context->action = action;
  68. }
  69. /*--------------------------------------------------------- */
  70. const clish_action_t *clish_context__get_action(const void *this)
  71. {
  72. const clish_context_t *context = (const clish_context_t *)this;
  73. return context->action;
  74. }
  75. /*--------------------------------------------------------- */