action.c 1.6 KB

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