param.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * param.h
  3. * Parameter instances are assocated with a command line and used to validate the
  4. * the arguments which a user is inputing for a command.
  5. */
  6. #ifndef _clish_param_h
  7. #define _clish_param_h
  8. typedef struct clish_paramv_s clish_paramv_t;
  9. typedef struct clish_param_s clish_param_t;
  10. #include "clish/types.h"
  11. #include "clish/ptype.h"
  12. #include "clish/pargv.h"
  13. #include "clish/var.h"
  14. /* The means by which the param is interpreted */
  15. typedef enum {
  16. /* A common parameter */
  17. CLISH_PARAM_COMMON,
  18. /* A swich parameter. Choose the only one of nested parameters. */
  19. CLISH_PARAM_SWITCH,
  20. /* A subcomand. Identified by it's name. */
  21. CLISH_PARAM_SUBCOMMAND
  22. } clish_param_mode_e;
  23. /* Class param */
  24. clish_param_t *clish_param_new(const char *name,
  25. const char *text, const char *ptype_name);
  26. void clish_param_delete(clish_param_t * instance);
  27. void clish_param_help(const clish_param_t * instance, clish_help_t *help);
  28. void clish_param_help_arrow(const clish_param_t * instance, size_t offset);
  29. char *clish_param_validate(const clish_param_t * instance, const char *text);
  30. void clish_param_dump(const clish_param_t * instance);
  31. void clish_param_insert_param(clish_param_t * instance, clish_param_t * param);
  32. _CLISH_SET_STR(param, ptype_name);
  33. _CLISH_GET_STR(param, ptype_name);
  34. _CLISH_SET_STR(param, access);
  35. _CLISH_GET_STR(param, access);
  36. _CLISH_GET_STR(param, name);
  37. _CLISH_GET_STR(param, text);
  38. _CLISH_GET_STR(param, range);
  39. _CLISH_SET_STR_ONCE(param, value);
  40. _CLISH_GET_STR(param, value);
  41. _CLISH_SET(param, clish_ptype_t *, ptype);
  42. _CLISH_GET(param, clish_ptype_t *, ptype);
  43. _CLISH_SET_STR_ONCE(param, defval);
  44. _CLISH_GET_STR(param, defval);
  45. _CLISH_SET_STR_ONCE(param, test);
  46. _CLISH_GET_STR(param, test);
  47. _CLISH_SET_STR_ONCE(param, completion);
  48. _CLISH_GET_STR(param, completion);
  49. _CLISH_SET(param, clish_param_mode_e, mode);
  50. _CLISH_GET(param, clish_param_mode_e, mode);
  51. _CLISH_GET(param, clish_paramv_t *, paramv);
  52. _CLISH_SET(param, bool_t, optional);
  53. _CLISH_GET(param, bool_t, optional);
  54. _CLISH_SET(param, bool_t, order);
  55. _CLISH_GET(param, bool_t, order);
  56. _CLISH_SET(param, bool_t, hidden);
  57. _CLISH_GET(param, bool_t, hidden);
  58. _CLISH_GET(param, unsigned int, param_count);
  59. clish_param_t *clish_param__get_param(const clish_param_t * instance,
  60. unsigned int index);
  61. /* Class paramv */
  62. clish_paramv_t *clish_paramv_new(void);
  63. void clish_paramv_delete(clish_paramv_t * instance);
  64. void clish_paramv_insert(clish_paramv_t * instance, clish_param_t * param);
  65. int clish_paramv_remove(clish_paramv_t *instance, unsigned int index); /* Remove param from vector */
  66. clish_param_t *clish_paramv__get_param(const clish_paramv_t * instance,
  67. unsigned index);
  68. unsigned int clish_paramv__get_count(const clish_paramv_t * instance);
  69. clish_param_t *clish_paramv_find_param(const clish_paramv_t * instance,
  70. const char *name);
  71. const char *clish_paramv_find_default(const clish_paramv_t * instance,
  72. const char *name);
  73. #endif /* _clish_param_h */