1
0

action.c 1.9 KB

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