1
0

action.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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/bintree.h"
  12. #include "lub/string.h"
  13. /*--------------------------------------------------------- */
  14. static void clish_action_init(clish_action_t *this)
  15. {
  16. this->script = NULL;
  17. this->builtin = NULL;
  18. this->shebang = NULL;
  19. this->lock = BOOL_TRUE;
  20. this->interrupt = 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_STR(action, shebang)
  53. {
  54. const char *prog = val;
  55. const char *prefix = "#!";
  56. lub_string_free(inst->shebang);
  57. if (lub_string_nocasestr(val, prefix) == val)
  58. prog += strlen(prefix);
  59. inst->shebang = lub_string_dup(prog);
  60. }
  61. CLISH_GET_STR(action, shebang);