1
0

action.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * action.c
  3. *
  4. * This file provides the implementation of a action definition
  5. */
  6. #include <stdlib.h>
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <assert.h>
  10. #include "private.h"
  11. #include "lub/string.h"
  12. /*--------------------------------------------------------- */
  13. static void clish_action_init(clish_action_t *this)
  14. {
  15. this->script = NULL;
  16. this->builtin = NULL;
  17. this->shebang = NULL;
  18. this->lock = BOOL_TRUE;
  19. this->interrupt = BOOL_FALSE;
  20. }
  21. /*--------------------------------------------------------- */
  22. static void clish_action_fini(clish_action_t *this)
  23. {
  24. lub_string_free(this->script);
  25. lub_string_free(this->shebang);
  26. }
  27. /*--------------------------------------------------------- */
  28. clish_action_t *clish_action_new(void)
  29. {
  30. clish_action_t *this = malloc(sizeof(clish_action_t));
  31. if (this)
  32. clish_action_init(this);
  33. return this;
  34. }
  35. /*--------------------------------------------------------- */
  36. void clish_action_delete(clish_action_t *this)
  37. {
  38. clish_action_fini(this);
  39. free(this);
  40. }
  41. CLISH_SET_STR(action, script);
  42. CLISH_GET_STR(action, script);
  43. CLISH_SET(action, const clish_sym_t *, builtin);
  44. CLISH_GET(action, const clish_sym_t *, builtin);
  45. CLISH_SET(action, bool_t, lock);
  46. CLISH_GET(action, bool_t, lock);
  47. CLISH_SET(action, bool_t, interrupt);
  48. CLISH_GET(action, bool_t, interrupt);
  49. CLISH_SET(action, bool_t, interactive);
  50. CLISH_GET(action, bool_t, interactive);
  51. _CLISH_SET_STR(action, shebang)
  52. {
  53. const char *prog = val;
  54. const char *prefix = "#!";
  55. lub_string_free(inst->shebang);
  56. if (lub_string_nocasestr(val, prefix) == val)
  57. prog += strlen(prefix);
  58. inst->shebang = lub_string_dup(prog);
  59. }
  60. CLISH_GET_STR(action, shebang);