kcontext.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <faux/conv.h>
  7. #include <faux/list.h>
  8. #include <klish/khelper.h>
  9. #include <klish/kcontext.h>
  10. #include <klish/kscheme.h>
  11. struct kcontext_s {
  12. kcontext_type_e type;
  13. int retcode;
  14. kplugin_t *plugin;
  15. ksym_t *sym;
  16. kaction_t *action;
  17. kcommand_t *command;
  18. };
  19. // Simple methods
  20. // Type
  21. KGET(context, kcontext_type_e, type);
  22. KSET(context, kcontext_type_e, type);
  23. // RetCode
  24. KGET(context, int, retcode);
  25. KSET(context, int, retcode);
  26. // Plugin
  27. KGET(context, kplugin_t *, plugin);
  28. KSET(context, kplugin_t *, plugin);
  29. // Sym
  30. KGET(context, ksym_t *, sym);
  31. KSET(context, ksym_t *, sym);
  32. // Action
  33. KGET(context, kaction_t *, action);
  34. KSET(context, kaction_t *, action);
  35. // Command
  36. KGET(context, kcommand_t *, command);
  37. KSET(context, kcommand_t *, command);
  38. kcontext_t *kcontext_new(kcontext_type_e type)
  39. {
  40. kcontext_t *context = NULL;
  41. context = faux_zmalloc(sizeof(*context));
  42. assert(context);
  43. if (!context)
  44. return NULL;
  45. // Initialize
  46. context->type = type;
  47. context->plugin = NULL;
  48. context->sym = NULL;
  49. context->action = NULL;
  50. return context;
  51. }
  52. void kcontext_free(kcontext_t *context)
  53. {
  54. if (!context)
  55. return;
  56. faux_free(context);
  57. }