1
0

action.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. this->permanent = BOOL_FALSE;
  21. }
  22. /*--------------------------------------------------------- */
  23. static void clish_action_fini(clish_action_t *this)
  24. {
  25. lub_string_free(this->script);
  26. lub_string_free(this->shebang);
  27. }
  28. /*--------------------------------------------------------- */
  29. clish_action_t *clish_action_new(void)
  30. {
  31. clish_action_t *this = malloc(sizeof(clish_action_t));
  32. if (this)
  33. clish_action_init(this);
  34. return this;
  35. }
  36. /*--------------------------------------------------------- */
  37. void clish_action_delete(clish_action_t *this)
  38. {
  39. clish_action_fini(this);
  40. free(this);
  41. }
  42. CLISH_SET_STR(action, script);
  43. CLISH_GET_STR(action, script);
  44. CLISH_SET(action, const clish_sym_t *, builtin);
  45. CLISH_GET(action, const clish_sym_t *, builtin);
  46. CLISH_SET(action, bool_t, lock);
  47. CLISH_GET(action, bool_t, lock);
  48. CLISH_SET(action, bool_t, interrupt);
  49. CLISH_GET(action, bool_t, interrupt);
  50. CLISH_SET(action, bool_t, interactive);
  51. CLISH_GET(action, bool_t, interactive);
  52. CLISH_SET(action, bool_t, permanent);
  53. CLISH_GET(action, bool_t, permanent);
  54. _CLISH_SET_STR(action, shebang)
  55. {
  56. const char *prog = val;
  57. const char *prefix = "#!";
  58. lub_string_free(inst->shebang);
  59. if (lub_string_nocasestr(val, prefix) == val)
  60. prog += strlen(prefix);
  61. inst->shebang = lub_string_dup(prog);
  62. }
  63. CLISH_GET_STR(action, shebang);