kentry.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /** @file kentry.h
  2. *
  3. * @brief Klish scheme's "ENTRY" entry
  4. */
  5. #ifndef _klish_kentry_h
  6. #define _klish_kentry_h
  7. #include <faux/list.h>
  8. #include <klish/kaction.h>
  9. #include <klish/khotkey.h>
  10. typedef struct kentry_s kentry_t;
  11. typedef faux_list_node_t kentry_entrys_node_t;
  12. typedef faux_list_node_t kentry_actions_node_t;
  13. typedef faux_list_node_t kentry_hotkeys_node_t;
  14. // Mode of nested entrys list
  15. typedef enum {
  16. KENTRY_MODE_NONE, // Illegal
  17. KENTRY_MODE_SEQUENCE, // Sequence of entrys
  18. KENTRY_MODE_SWITCH, // Switch of entrys
  19. KENTRY_MODE_EMPTY, // Entry must not have a nested entrys
  20. } kentry_mode_e;
  21. // Purpose of ENTRY
  22. typedef enum {
  23. KENTRY_PURPOSE_NONE,
  24. KENTRY_PURPOSE_COMMON, // Common entry like view/command/param
  25. KENTRY_PURPOSE_PTYPE,
  26. KENTRY_PURPOSE_PROMPT, // Prompt for view
  27. KENTRY_PURPOSE_COND, // Conditional expression
  28. KENTRY_PURPOSE_COMPLETION, // Engine to generate completions
  29. KENTRY_PURPOSE_HELP,
  30. KENTRY_PURPOSE_MAX,
  31. } kentry_purpose_e;
  32. // Filter flag
  33. typedef enum {
  34. KENTRY_FILTER_NONE, // Illegal
  35. KENTRY_FILTER_FALSE, // Entry is not a filter
  36. KENTRY_FILTER_TRUE, // Entry is a filter
  37. KENTRY_FILTER_DUAL, // Entry can be filter or non-filter
  38. } kentry_filter_e;
  39. // Number of max occurs
  40. typedef enum {
  41. KENTRY_OCCURS_UNBOUNDED = (size_t)(-1),
  42. } kentry_occurs_e;
  43. typedef bool_t (*kentry_udata_free_fn)(void *data);
  44. C_DECL_BEGIN
  45. kentry_t *kentry_new(const char *name);
  46. void kentry_free(kentry_t *entry);
  47. bool_t kentry_link(kentry_t *dst, const kentry_t *src);
  48. // Name
  49. const char *kentry_name(const kentry_t *entry);
  50. // Help
  51. const char *kentry_help(const kentry_t *entry);
  52. bool_t kentry_set_help(kentry_t *entry, const char *help);
  53. // Parent
  54. kentry_t *kentry_parent(const kentry_t *entry);
  55. bool_t kentry_set_parent(kentry_t *entry, kentry_t *parent);
  56. // Container
  57. bool_t kentry_container(const kentry_t *entry);
  58. bool_t kentry_set_container(kentry_t *entry, bool_t container);
  59. // Mode
  60. kentry_mode_e kentry_mode(const kentry_t *entry);
  61. bool_t kentry_set_mode(kentry_t *entry, kentry_mode_e mode);
  62. // Purpose
  63. kentry_purpose_e kentry_purpose(const kentry_t *entry);
  64. bool_t kentry_set_purpose(kentry_t *entry, kentry_purpose_e purpose);
  65. // Min occurs
  66. size_t kentry_min(const kentry_t *entry);
  67. bool_t kentry_set_min(kentry_t *entry, size_t min);
  68. // Max occurs
  69. size_t kentry_max(const kentry_t *entry);
  70. bool_t kentry_set_max(kentry_t *entry, size_t max);
  71. // Ref
  72. const char *kentry_ref_str(const kentry_t *entry);
  73. bool_t kentry_set_ref_str(kentry_t *entry, const char *ref_str);
  74. // Value
  75. const char *kentry_value(const kentry_t *entry);
  76. bool_t kentry_set_value(kentry_t *entry, const char *value);
  77. // Restore
  78. bool_t kentry_restore(const kentry_t *entry);
  79. bool_t kentry_set_restore(kentry_t *entry, bool_t restore);
  80. // Order
  81. bool_t kentry_order(const kentry_t *entry);
  82. bool_t kentry_set_order(kentry_t *entry, bool_t order);
  83. // Filter
  84. kentry_filter_e kentry_filter(const kentry_t *entry);
  85. bool_t kentry_set_filter(kentry_t *entry, kentry_filter_e filter);
  86. // User data
  87. void *kentry_udata(const kentry_t *entry);
  88. bool_t kentry_set_udata(kentry_t *entry, void *data, kentry_udata_free_fn udata_free_fn);
  89. // Nested ENTRY list
  90. faux_list_t *kentry_entrys(const kentry_t *entry);
  91. bool_t kentry_add_entrys(kentry_t *entry, kentry_t *nested_entry);
  92. kentry_t *kentry_find_entry(const kentry_t *entry, const char *name);
  93. ssize_t kentry_entrys_len(const kentry_t *entry);
  94. bool_t kentry_entrys_is_empty(const kentry_t *entry);
  95. kentry_entrys_node_t *kentry_entrys_iter(const kentry_t *entry);
  96. kentry_t *kentry_entrys_each(kentry_entrys_node_t **iter);
  97. // ACTIONs
  98. faux_list_t *kentry_actions(const kentry_t *entry);
  99. bool_t kentry_add_actions(kentry_t *entry, kaction_t *action);
  100. ssize_t kentry_actions_len(const kentry_t *entry);
  101. kentry_actions_node_t *kentry_actions_iter(const kentry_t *entry);
  102. kaction_t *kentry_actions_each(kentry_actions_node_t **iter);
  103. kaction_io_e kentry_in(const kentry_t *entry);
  104. kaction_io_e kentry_out(const kentry_t *entry);
  105. // HOTKEYs
  106. faux_list_t *kentry_hotkeys(const kentry_t *entry);
  107. bool_t kentry_add_hotkeys(kentry_t *entry, khotkey_t *hotkey);
  108. ssize_t kentry_hotkeys_len(const kentry_t *entry);
  109. kentry_hotkeys_node_t *kentry_hotkeys_iter(const kentry_t *entry);
  110. khotkey_t *kentry_hotkeys_each(kentry_hotkeys_node_t **iter);
  111. int kentry_hotkey_compare(const void *first, const void *second);
  112. // Fast access for nested entries with special purposes
  113. kentry_t *kentry_nested_by_purpose(const kentry_t *entry, kentry_purpose_e purpose);
  114. bool_t kentry_set_nested_by_purpose(kentry_t *entry, kentry_purpose_e purpose,
  115. kentry_t *nested);
  116. C_DECL_END
  117. #endif // _klish_kentry_h