kpargv.h 3.3 KB

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