khotkey.c 805 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <assert.h>
  5. #include <faux/str.h>
  6. #include <klish/khelper.h>
  7. #include <klish/khotkey.h>
  8. struct khotkey_s {
  9. char *key;
  10. char *cmd;
  11. };
  12. // Simple methods
  13. // Key
  14. KGET_STR(hotkey, key);
  15. // Command
  16. KGET_STR(hotkey, cmd);
  17. khotkey_t *khotkey_new(const char *key, const char *cmd)
  18. {
  19. khotkey_t *hotkey = NULL;
  20. // Mandatory key
  21. if (!key)
  22. return NULL;
  23. // Mandatory cmd
  24. if (!cmd)
  25. return NULL;
  26. hotkey = faux_zmalloc(sizeof(*hotkey));
  27. assert(hotkey);
  28. if (!hotkey)
  29. return NULL;
  30. // Initialize
  31. hotkey->key = faux_str_dup(key);
  32. hotkey->cmd = faux_str_dup(cmd);
  33. return hotkey;
  34. }
  35. void khotkey_free(khotkey_t *hotkey)
  36. {
  37. if (!hotkey)
  38. return;
  39. faux_str_free(hotkey->key);
  40. faux_str_free(hotkey->cmd);
  41. faux_free(hotkey);
  42. }