action.c 1.8 KB

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