kentry.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. typedef struct kentry_s kentry_t;
  10. typedef faux_list_node_t kentry_entrys_node_t;
  11. typedef faux_list_node_t kentry_actions_node_t;
  12. // Mode of nested entrys list
  13. typedef enum {
  14. KENTRY_MODE_NONE, // Illegal
  15. KENTRY_MODE_SEQUENCE, // Sequence of entrys
  16. KENTRY_MODE_SWITCH, // Switch of entrys
  17. KENTRY_MODE_EMPTY, // Entry must not have a nested entrys
  18. } kentry_mode_e;
  19. // Purpose of ENTRY
  20. typedef enum {
  21. KENTRY_PURPOSE_NONE,
  22. KENTRY_PURPOSE_COMMON, // Common entry like view/command/param
  23. KENTRY_PURPOSE_PTYPE,
  24. KENTRY_PURPOSE_PROMPT, // Prompt for view
  25. KENTRY_PURPOSE_COND, // Conditional expression
  26. KENTRY_PURPOSE_COMPLETION, // Engine to generate completions
  27. KENTRY_PURPOSE_MAX,
  28. } kentry_purpose_e;
  29. // Number of max occurs
  30. typedef enum {
  31. KENTRY_OCCURS_UNBOUNDED = (size_t)(-1),
  32. } kentry_occurs_e;
  33. C_DECL_BEGIN
  34. kentry_t *kentry_new(const char *name);
  35. void kentry_free(kentry_t *entry);
  36. bool_t kentry_link(kentry_t *dst, const kentry_t *src);
  37. // Name
  38. const char *kentry_name(const kentry_t *entry);
  39. // Help
  40. const char *kentry_help(const kentry_t *entry);
  41. bool_t kentry_set_help(kentry_t *entry, const char *help);
  42. // Parent
  43. kentry_t *kentry_parent(const kentry_t *entry);
  44. bool_t kentry_set_parent(kentry_t *entry, kentry_t *parent);
  45. // Container
  46. bool_t kentry_container(const kentry_t *entry);
  47. bool_t kentry_set_container(kentry_t *entry, bool_t container);
  48. // Mode
  49. kentry_mode_e kentry_mode(const kentry_t *entry);
  50. bool_t kentry_set_mode(kentry_t *entry, kentry_mode_e mode);
  51. // Purpose
  52. kentry_purpose_e kentry_purpose(const kentry_t *entry);
  53. bool_t kentry_set_purpose(kentry_t *entry, kentry_purpose_e purpose);
  54. // Min occurs
  55. size_t kentry_min(const kentry_t *entry);
  56. bool_t kentry_set_min(kentry_t *entry, size_t min);
  57. // Max occurs
  58. size_t kentry_max(const kentry_t *entry);
  59. bool_t kentry_set_max(kentry_t *entry, size_t max);
  60. // Ref
  61. const char *kentry_ref_str(const kentry_t *entry);
  62. bool_t kentry_set_ref_str(kentry_t *entry, const char *ref_str);
  63. // Value
  64. const char *kentry_value(const kentry_t *entry);
  65. bool_t kentry_set_value(kentry_t *entry, const char *value);
  66. // Restore
  67. bool_t kentry_restore(const kentry_t *entry);
  68. bool_t kentry_set_restore(kentry_t *entry, bool_t restore);
  69. // Order
  70. bool_t kentry_order(const kentry_t *entry);
  71. bool_t kentry_set_order(kentry_t *entry, bool_t order);
  72. // Filter
  73. bool_t kentry_filter(const kentry_t *entry);
  74. bool_t kentry_set_filter(kentry_t *entry, bool_t filter);
  75. // Nested ENTRY list
  76. faux_list_t *kentry_entrys(const kentry_t *entry);
  77. bool_t kentry_add_entrys(kentry_t *entry, kentry_t *nested_entry);
  78. kentry_t *kentry_find_entry(const kentry_t *entry, const char *name);
  79. ssize_t kentry_entrys_len(const kentry_t *entry);
  80. bool_t kentry_entrys_is_empty(const kentry_t *entry);
  81. kentry_entrys_node_t *kentry_entrys_iter(const kentry_t *entry);
  82. kentry_t *kentry_entrys_each(kentry_entrys_node_t **iter);
  83. // ACTIONs
  84. faux_list_t *kentry_actions(const kentry_t *entry);
  85. bool_t kentry_add_actions(kentry_t *entry, kaction_t *action);
  86. ssize_t kentry_actions_len(const kentry_t *entry);
  87. kentry_actions_node_t *kentry_actions_iter(const kentry_t *entry);
  88. kaction_t *kentry_actions_each(kentry_actions_node_t **iter);
  89. // Fast access for nested entries with special purposes
  90. kentry_t *kentry_nested_by_purpose(const kentry_t *entry, kentry_purpose_e purpose);
  91. bool_t kentry_set_nested_by_purpose(kentry_t *entry, kentry_purpose_e purpose,
  92. kentry_t *nested);
  93. C_DECL_END
  94. #endif // _klish_kentry_h