ihotkey.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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/error.h>
  8. #include <klish/khelper.h>
  9. #include <klish/khotkey.h>
  10. #include <klish/ihotkey.h>
  11. #define TAG "HOTKEY"
  12. /*
  13. bool_t ihotkey_parse(const ihotkey_t *info, khotkey_t *hotkey, faux_error_t *error)
  14. {
  15. bool_t retcode = BOOL_TRUE;
  16. if (!info)
  17. return BOOL_FALSE;
  18. if (!hotkey)
  19. return BOOL_FALSE;
  20. return retcode;
  21. }
  22. */
  23. khotkey_t *ihotkey_load(const ihotkey_t *ihotkey, faux_error_t *error)
  24. {
  25. khotkey_t *khotkey = NULL;
  26. // Key [mandatory]
  27. if (faux_str_is_empty(ihotkey->key)) {
  28. faux_error_add(error, TAG": Empty 'key' attribute");
  29. return NULL;
  30. }
  31. // Command [mandatory]
  32. if (faux_str_is_empty(ihotkey->cmd)) {
  33. faux_error_add(error, TAG": Empty 'cmd' attribute");
  34. return NULL;
  35. }
  36. khotkey = khotkey_new(ihotkey->key, ihotkey->cmd);
  37. if (!khotkey) {
  38. faux_error_add(error, TAG": Can't create object");
  39. return NULL;
  40. }
  41. // if (!ihotkey_parse(ihotkey, khotkey, error)) {
  42. // khotkey_free(khotkey);
  43. // return NULL;
  44. // }
  45. return khotkey;
  46. }
  47. char *ihotkey_deploy(const khotkey_t *khotkey, int level)
  48. {
  49. char *str = NULL;
  50. char *tmp = NULL;
  51. if (!khotkey)
  52. return NULL;
  53. tmp = faux_str_sprintf("%*chotkey {\n", level, ' ');
  54. faux_str_cat(&str, tmp);
  55. faux_str_free(tmp);
  56. attr2ctext(&str, "key", khotkey_key(khotkey), level + 1);
  57. attr2ctext(&str, "cmd", khotkey_cmd(khotkey), level + 1);
  58. tmp = faux_str_sprintf("%*c},\n\n", level, ' ');
  59. faux_str_cat(&str, tmp);
  60. faux_str_free(tmp);
  61. return str;
  62. }