pline.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 = 0x0000,
  14. PAT_CONTAINER = 0x0001,
  15. PAT_LIST = 0x0002,
  16. PAT_LIST_KEY = 0x0004,
  17. PAT_LIST_KEY_INCOMPLETED = 0x0008,
  18. PAT_LEAF = 0x0010,
  19. PAT_LEAF_VALUE = 0x0020,
  20. PAT_LEAF_EMPTY = 0x0040,
  21. PAT_LEAFLIST = 0x0080,
  22. PAT_LEAFLIST_VALUE = 0x0100,
  23. } pat_e;
  24. // Type of pline expression
  25. // P(line) T(ype)
  26. typedef enum {
  27. PT_COMPL_ALL =
  28. PAT_CONTAINER |
  29. PAT_LIST |
  30. PAT_LIST_KEY |
  31. PAT_LIST_KEY_INCOMPLETED |
  32. PAT_LEAF |
  33. PAT_LEAF_VALUE |
  34. PAT_LEAF_EMPTY |
  35. PAT_LEAFLIST |
  36. PAT_LEAFLIST_VALUE,
  37. PT_SET =
  38. PAT_CONTAINER |
  39. PAT_LIST_KEY |
  40. PAT_LEAF_VALUE |
  41. PAT_LEAF_EMPTY |
  42. PAT_LEAFLIST_VALUE,
  43. PT_NOT_SET =
  44. 0,
  45. PT_COMPL_SET =
  46. PAT_CONTAINER |
  47. PAT_LIST |
  48. PAT_LIST_KEY |
  49. PAT_LIST_KEY_INCOMPLETED |
  50. PAT_LEAF |
  51. PAT_LEAF_VALUE |
  52. PAT_LEAF_EMPTY |
  53. PAT_LEAFLIST |
  54. PAT_LEAFLIST_VALUE,
  55. PT_DEL =
  56. PAT_CONTAINER |
  57. PAT_LIST_KEY |
  58. PAT_LEAF |
  59. PAT_LEAF_EMPTY |
  60. PAT_LEAFLIST |
  61. PAT_LEAFLIST_VALUE,
  62. PT_NOT_DEL =
  63. PAT_LEAF_VALUE,
  64. PT_COMPL_DEL =
  65. PAT_CONTAINER |
  66. PAT_LIST |
  67. PAT_LIST_KEY |
  68. PAT_LIST_KEY_INCOMPLETED |
  69. PAT_LEAF |
  70. PAT_LEAF_EMPTY |
  71. PAT_LEAFLIST |
  72. PAT_LEAFLIST_VALUE,
  73. PT_EDIT =
  74. PAT_CONTAINER |
  75. PAT_LIST_KEY,
  76. PT_NOT_EDIT =
  77. PAT_LEAF |
  78. PAT_LEAF_VALUE |
  79. PAT_LEAFLIST |
  80. PAT_LEAFLIST_VALUE,
  81. PT_COMPL_EDIT =
  82. PAT_CONTAINER |
  83. PAT_LIST |
  84. PAT_LIST_KEY |
  85. PAT_LIST_KEY_INCOMPLETED,
  86. PT_INSERT =
  87. PAT_LIST_KEY |
  88. PAT_LEAFLIST_VALUE,
  89. PT_NOT_INSERT =
  90. PAT_LEAF |
  91. PAT_LEAF_VALUE,
  92. PT_COMPL_INSERT =
  93. PAT_CONTAINER |
  94. PAT_LIST |
  95. PAT_LIST_KEY |
  96. PAT_LIST_KEY_INCOMPLETED |
  97. PAT_LEAFLIST |
  98. PAT_LEAFLIST_VALUE,
  99. } pt_e;
  100. // Plain EXPRession
  101. typedef struct {
  102. char *xpath;
  103. char *value;
  104. bool_t active;
  105. pat_e pat;
  106. size_t args_num;
  107. size_t list_pos;
  108. char *last_keys;
  109. } pexpr_t;
  110. // Possible types of completion source
  111. typedef enum {
  112. PCOMPL_NODE = 0,
  113. PCOMPL_TYPE = 1,
  114. } pcompl_type_e;
  115. // Plain COMPLetion
  116. typedef struct {
  117. pcompl_type_e type;
  118. const struct lysc_node *node;
  119. char *xpath;
  120. sr_datastore_t xpath_ds;
  121. pat_e pat;
  122. } pcompl_t;
  123. // Plain LINE
  124. typedef struct pline_s {
  125. sr_session_ctx_t *sess;
  126. bool_t invalid;
  127. faux_list_t *exprs;
  128. faux_list_t *compls;
  129. } pline_t;
  130. // Parse/show settings
  131. typedef struct {
  132. char begin_bracket;
  133. char end_bracket;
  134. bool_t show_brackets;
  135. bool_t show_semicolons;
  136. bool_t first_key_w_stmt;
  137. bool_t keys_w_stmt;
  138. bool_t colorize;
  139. uint8_t indent;
  140. bool_t default_keys;
  141. bool_t show_default_keys;
  142. bool_t hide_passwords;
  143. bool_t enable_nacm;
  144. bool_t oneliners;
  145. } pline_opts_t;
  146. #define SRP_NODETYPE_CONF (LYS_CONTAINER | LYS_LIST | LYS_LEAF | LYS_LEAFLIST | LYS_CHOICE | LYS_CASE)
  147. C_DECL_BEGIN
  148. pline_t *pline_new(sr_session_ctx_t *sess);
  149. void pline_opts_init(pline_opts_t *opts);
  150. int pline_opts_parse(const char *conf, pline_opts_t *opts);
  151. pline_t *pline_parse(sr_session_ctx_t *sess, faux_argv_t *argv, pline_opts_t *opts);
  152. pexpr_t *pline_current_expr(pline_t *pline);
  153. void pline_free(pline_t *pline);
  154. void pline_debug(pline_t *pline);
  155. void pline_print_completions(const pline_t *pline, bool_t help, pt_e enabled_types);
  156. size_t num_of_keys(const struct lysc_node *node);
  157. C_DECL_END
  158. #endif /* _pline_h */