action.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_STR(action, shebang)
  45. {
  46. const char *prog = val;
  47. const char *prefix = "#!";
  48. lub_string_free(inst->shebang);
  49. if (lub_string_nocasestr(val, prefix) == val)
  50. prog += strlen(prefix);
  51. inst->shebang = lub_string_dup(prog);
  52. }
  53. CLISH_GET_STR(action, shebang);