kaction.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. // bool_t permanent; // Should it be executed on 'dry-run'
  18. // bool_t async;
  19. kaction_cond_e exec_on;
  20. bool_t update_retcode;
  21. char *script;
  22. };
  23. // Simple methods
  24. // Sym reference (must be resolved later)
  25. KGET_STR(action, sym_ref);
  26. KSET_STR_ONCE(action, sym_ref);
  27. // Lock
  28. KGET_STR(action, lock);
  29. KSET_STR(action, lock);
  30. // Interrupt
  31. KGET_BOOL(action, interrupt);
  32. KSET_BOOL(action, interrupt);
  33. // Interactive
  34. KGET_BOOL(action, interactive);
  35. KSET_BOOL(action, interactive);
  36. // Exec_on
  37. KGET(action, kaction_cond_e, exec_on);
  38. KSET(action, kaction_cond_e, exec_on);
  39. // Update_retcode
  40. KGET_BOOL(action, update_retcode);
  41. KSET_BOOL(action, update_retcode);
  42. // Script
  43. KGET_STR(action, script);
  44. KSET_STR(action, script);
  45. // Symbol
  46. KGET(action, ksym_t *, sym);
  47. KSET(action, ksym_t *, sym);
  48. kaction_t *kaction_new(void)
  49. {
  50. kaction_t *action = NULL;
  51. action = faux_zmalloc(sizeof(*action));
  52. assert(action);
  53. if (!action)
  54. return NULL;
  55. // Initialize
  56. action->sym_ref = NULL;
  57. action->lock = NULL;
  58. action->interrupt = BOOL_FALSE;
  59. action->interactive = BOOL_FALSE;
  60. action->exec_on = KACTION_COND_SUCCESS;
  61. action->update_retcode = BOOL_TRUE;
  62. action->script = NULL;
  63. action->sym = NULL;
  64. return action;
  65. }
  66. void kaction_free(kaction_t *action)
  67. {
  68. if (!action)
  69. return;
  70. faux_str_free(action->sym_ref);
  71. faux_str_free(action->lock);
  72. faux_str_free(action->script);
  73. faux_free(action);
  74. }