kpargv.h 3.3 KB

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