kaction.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <faux/conv.h>
  7. #include <faux/list.h>
  8. #include <klish/khelper.h>
  9. #include <klish/kaction.h>
  10. #include <klish/ksym.h>
  11. struct kaction_s {
  12. char *sym_ref; // Text reference to symbol
  13. ksym_t *sym; // Symbol itself
  14. char *lock; // Named lock
  15. bool_t interrupt;
  16. bool_t interactive;
  17. kaction_cond_e exec_on;
  18. bool_t update_retcode;
  19. char *script;
  20. };
  21. // Simple methods
  22. // Sym reference (must be resolved later)
  23. KGET_STR(action, sym_ref);
  24. KSET_STR_ONCE(action, sym_ref);
  25. // Lock
  26. KGET_STR(action, lock);
  27. KSET_STR(action, lock);
  28. // Interrupt
  29. KGET_BOOL(action, interrupt);
  30. KSET_BOOL(action, interrupt);
  31. // Interactive
  32. KGET_BOOL(action, interactive);
  33. KSET_BOOL(action, interactive);
  34. // Exec_on
  35. KGET(action, kaction_cond_e, exec_on);
  36. KSET(action, kaction_cond_e, exec_on);
  37. // Update_retcode
  38. KGET_BOOL(action, update_retcode);
  39. KSET_BOOL(action, update_retcode);
  40. // Script
  41. KGET_STR(action, script);
  42. KSET_STR(action, script);
  43. // Symbol
  44. KGET(action, ksym_t *, sym);
  45. KSET(action, ksym_t *, sym);
  46. kaction_t *kaction_new(void)
  47. {
  48. kaction_t *action = NULL;
  49. action = faux_zmalloc(sizeof(*action));
  50. assert(action);
  51. if (!action)
  52. return NULL;
  53. // Initialize
  54. action->sym_ref = NULL;
  55. action->lock = NULL;
  56. action->interrupt = BOOL_FALSE;
  57. action->interactive = BOOL_FALSE;
  58. action->exec_on = KACTION_COND_SUCCESS;
  59. action->update_retcode = BOOL_TRUE;
  60. action->script = NULL;
  61. action->sym = NULL;
  62. return action;
  63. }
  64. void kaction_free(kaction_t *action)
  65. {
  66. if (!action)
  67. return;
  68. faux_str_free(action->sym_ref);
  69. faux_str_free(action->lock);
  70. faux_str_free(action->script);
  71. faux_free(action);
  72. }