kpargv.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /** @file kpargv.h
  2. *
  3. * @brief Parsed ARGuments Vector
  4. */
  5. #ifndef _klish_kpargv_h
  6. #define _klish_kpargv_h
  7. #include <faux/list.h>
  8. #include <faux/argv.h>
  9. #include <klish/kentry.h>
  10. typedef enum {
  11. KPARSE_NONE = 0x00,
  12. KPARSE_OK = 0x01,
  13. KPARSE_INPROGRESS = 0x02,
  14. KPARSE_NOTFOUND = 0x04,
  15. KPARSE_INCOMPLETED = 0x08,
  16. KPARSE_ILLEGAL = 0x10,
  17. KPARSE_ERROR = 0x20,
  18. KPARSE_NOACTION = 0x40,
  19. KPARSE_MAX = 8,
  20. } kpargv_status_e;
  21. #define KPARSE_NOTFIT (KPARSE_NOTFOUND | KPARSE_INCOMPLETED)
  22. typedef enum {
  23. KPURPOSE_NONE,
  24. KPURPOSE_EXEC,
  25. KPURPOSE_COMPLETION,
  26. KPURPOSE_HELP,
  27. KPURPOSE_MAX,
  28. } kpargv_purpose_e;
  29. typedef struct kpargv_s kpargv_t;
  30. typedef struct kparg_s kparg_t;
  31. typedef faux_list_node_t kpargv_pargs_node_t;
  32. typedef faux_list_node_t kpargv_completions_node_t;
  33. C_DECL_BEGIN
  34. // Parg
  35. kparg_t *kparg_new(const kentry_t *entry, const char *value);
  36. void kparg_free(kparg_t *parg);
  37. const kentry_t *kparg_entry(const kparg_t *parg);
  38. bool_t kparg_set_value(kparg_t *parg, const char *value);
  39. const char *kparg_value(const kparg_t *parg);
  40. // Pargv
  41. kpargv_t *kpargv_new();
  42. void kpargv_free(kpargv_t *pargv);
  43. // Status
  44. kpargv_status_e kpargv_status(const kpargv_t *pargv);
  45. bool_t kpargv_set_status(kpargv_t *pargv, kpargv_status_e status);
  46. const char *kpargv_status_decode(kpargv_status_e status);
  47. const char *kpargv_status_str(const kpargv_t *pargv);
  48. // Level
  49. size_t kpargv_level(const kpargv_t *pargv);
  50. bool_t kpargv_set_level(kpargv_t *pargv, size_t level);
  51. // Command
  52. const kentry_t *kpargv_command(const kpargv_t *pargv);
  53. bool_t kpargv_set_command(kpargv_t *pargv, const kentry_t *command);
  54. // Continuable
  55. bool_t kpargv_continuable(const kpargv_t *pargv);
  56. bool_t kpargv_set_continuable(kpargv_t *pargv, bool_t continuable);
  57. // Purpose
  58. kpargv_purpose_e kpargv_purpose(const kpargv_t *pargv);
  59. bool_t kpargv_set_purpose(kpargv_t *pargv, kpargv_purpose_e purpose);
  60. // Last argument
  61. bool_t kpargv_set_last_arg(kpargv_t *pargv, const char *last_arg);
  62. const char *kpargv_last_arg(const kpargv_t *pargv);
  63. // Candidate parg
  64. bool_t kpargv_set_candidate_parg(kpargv_t *pargv, kparg_t *candidate_parg);
  65. kparg_t *kpargv_candidate_parg(const kpargv_t *pargv);
  66. bool_t kpargv_accept_candidate_parg(kpargv_t *pargv);
  67. bool_t kpargv_decline_candidate_parg(kpargv_t *pargv);
  68. // Pargs
  69. faux_list_t *kpargv_pargs(const kpargv_t *pargv);
  70. ssize_t kpargv_pargs_len(const kpargv_t *pargv);
  71. bool_t kpargv_pargs_is_empty(const kpargv_t *pargv);
  72. bool_t kpargv_add_pargs(kpargv_t *pargv, kparg_t *parg);
  73. kpargv_pargs_node_t *kpargv_pargs_iter(const kpargv_t *pargv);
  74. kpargv_pargs_node_t *kpargv_pargs_iterr(const kpargv_t *pargv);
  75. kparg_t *kpargv_pargs_each(kpargv_pargs_node_t **iter);
  76. kparg_t *kpargv_pargs_eachr(kpargv_pargs_node_t **iter);
  77. kparg_t *kpargv_pargs_last(const kpargv_t *pargv);
  78. kparg_t *kpargv_entry_exists(const kpargv_t *pargv, const void *entry);
  79. kparg_t *kpargv_find(const kpargv_t *pargv, const char *entry_name);
  80. faux_list_t *kpargv_find_multi(const kpargv_t *pargv, const char *entry_name);
  81. // Completions
  82. faux_list_t *kpargv_completions(const kpargv_t *pargv);
  83. bool_t kpargv_add_completions(kpargv_t *pargv, const kentry_t *completion);
  84. ssize_t kpargv_completions_len(const kpargv_t *pargv);
  85. bool_t kpargv_completions_is_empty(const kpargv_t *pargv);
  86. kpargv_completions_node_t *kpargv_completions_iter(const kpargv_t *pargv);
  87. const kentry_t *kpargv_completions_each(kpargv_completions_node_t **iter);
  88. // Debug
  89. bool_t kpargv_debug(const kpargv_t *pargv);
  90. C_DECL_END
  91. #endif // _klish_kpargv_h