pline.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /** @file pline.h
  2. * @brief Plain line.
  3. */
  4. #ifndef _pline_h
  5. #define _pline_h
  6. #include <faux/list.h>
  7. #include <faux/argv.h>
  8. #include <sysrepo.h>
  9. #include <sysrepo/xpath.h>
  10. // Type of positional pline argument
  11. // P(line) A(rg) T(ype)
  12. typedef enum {
  13. PAT_NONE = 0x0001,
  14. PAT_CONTAINER = 0x0002,
  15. PAT_LIST = 0x0004,
  16. PAT_LIST_KEY = 0x0008,
  17. PAT_LIST_KEY_INCOMPLETED = 0x0010,
  18. PAT_LEAF = 0x0020,
  19. PAT_LEAF_VALUE = 0x0040,
  20. PAT_LEAF_EMPTY = 0x0080,
  21. PAT_LEAFLIST = 0x0100,
  22. PAT_LEAFLIST_VALUE = 0x0200,
  23. } pat_e;
  24. // Type of pline expression
  25. // P(line) T(ype)
  26. typedef enum {
  27. PT_SET =
  28. PAT_CONTAINER |
  29. PAT_LIST_KEY |
  30. PAT_LEAF_VALUE |
  31. PAT_LEAF_EMPTY |
  32. PAT_LEAFLIST_VALUE,
  33. PT_NOT_SET =
  34. 0,
  35. PT_DEL =
  36. PAT_CONTAINER |
  37. PAT_LIST_KEY |
  38. PAT_LEAF |
  39. PAT_LEAF_EMPTY |
  40. PAT_LEAFLIST |
  41. PAT_LEAFLIST_VALUE,
  42. PT_NOT_DEL =
  43. PAT_LEAF_VALUE,
  44. PT_EDIT =
  45. PAT_CONTAINER |
  46. PAT_LIST_KEY,
  47. PT_NOT_EDIT =
  48. PAT_LEAF |
  49. PAT_LEAF_VALUE |
  50. PAT_LEAFLIST |
  51. PAT_LEAFLIST_VALUE,
  52. PT_INSERT =
  53. PAT_LIST_KEY |
  54. PAT_LEAFLIST_VALUE,
  55. PT_NOT_INSERT =
  56. PAT_LEAF |
  57. PAT_LEAF_VALUE,
  58. } pt_e;
  59. // Plain EXPRession
  60. typedef struct {
  61. char *xpath;
  62. char *value;
  63. bool_t active;
  64. pat_e pat;
  65. size_t args_num;
  66. size_t list_pos;
  67. char *last_keys;
  68. } pexpr_t;
  69. // Possible types of completion source
  70. typedef enum {
  71. PCOMPL_NODE = 0,
  72. PCOMPL_TYPE = 1,
  73. } pcompl_type_e;
  74. // Plain COMPLetion
  75. typedef struct {
  76. pcompl_type_e type;
  77. const struct lysc_node *node;
  78. char *xpath;
  79. } pcompl_t;
  80. // Plain LINE
  81. typedef struct pline_s {
  82. sr_session_ctx_t *sess;
  83. bool_t invalid;
  84. faux_list_t *exprs;
  85. faux_list_t *compls;
  86. } pline_t;
  87. // Parse options
  88. typedef enum {
  89. PPARSE_SINGLE_KEY_W_STMT = 0x01,
  90. PPARSE_MULTI_KEYS_W_STMT = 0x02,
  91. } pparse_flags_e;
  92. #define SRP_NODETYPE_CONF (LYS_CONTAINER | LYS_LIST | LYS_LEAF | LYS_LEAFLIST)
  93. C_DECL_BEGIN
  94. pline_t *pline_new(sr_session_ctx_t *sess);
  95. pline_t *pline_parse(sr_session_ctx_t *sess, faux_argv_t *argv, uint32_t flags);
  96. pexpr_t *pline_current_expr(pline_t *pline);
  97. void pline_free(pline_t *pline);
  98. void pline_debug(pline_t *pline);
  99. void pline_print_completions(const pline_t *pline, bool_t help);
  100. size_t num_of_keys(const struct lysc_node *node);
  101. bool_t list_key_with_stmt(const struct lysc_node *node, uint32_t flags);
  102. C_DECL_END
  103. #endif /* _pline_h */