ptype.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * ptype.h
  3. * Types are a syntatical template which parameters reference.
  4. */
  5. #ifndef _clish_ptype_h
  6. #define _clish_ptype_h
  7. typedef struct clish_ptype_s clish_ptype_t;
  8. #include "lub/types.h"
  9. #include "clish/macros.h"
  10. #include "lub/bintree.h"
  11. #include "lub/argv.h"
  12. #include "clish/action.h"
  13. #include <stddef.h>
  14. /**
  15. * The means by which the pattern is interpreted and
  16. * validated.
  17. */
  18. typedef enum {
  19. /**
  20. * [default] - A POSIX regular expression.
  21. */
  22. CLISH_PTYPE_REGEXP,
  23. /**
  24. * A numeric definition "min..max" signed and unsigned versions
  25. */
  26. CLISH_PTYPE_INTEGER,
  27. CLISH_PTYPE_UNSIGNEDINTEGER,
  28. /**
  29. * A list of possible values.
  30. * The syntax of the string is of the form:
  31. * "valueOne(ONE) valueTwo(TWO) valueThree(THREE)"
  32. * where the text before the parethesis defines the syntax
  33. * that the user must use, and the value within the parenthesis
  34. * is the result expanded as a parameter value.
  35. */
  36. CLISH_PTYPE_SELECT
  37. } clish_ptype_method_e;
  38. /**
  39. * This defines the pre processing which is to be
  40. * performed before a string is validated.
  41. */
  42. typedef enum {
  43. /**
  44. * [default] - do nothing
  45. */
  46. CLISH_PTYPE_NONE,
  47. /**
  48. * before validation convert to uppercase.
  49. */
  50. CLISH_PTYPE_TOUPPER,
  51. /**
  52. * before validation convert to lowercase.
  53. */
  54. CLISH_PTYPE_TOLOWER
  55. } clish_ptype_preprocess_e;
  56. int clish_ptype_bt_compare(const void *clientnode, const void *clientkey);
  57. void clish_ptype_bt_getkey(const void *clientnode, lub_bintree_key_t * key);
  58. size_t clish_ptype_bt_offset(void);
  59. const char *clish_ptype_method__get_name(clish_ptype_method_e method);
  60. clish_ptype_method_e clish_ptype_method_resolve(const char *method_name);
  61. const char *clish_ptype_preprocess__get_name(clish_ptype_preprocess_e
  62. preprocess);
  63. clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char
  64. *preprocess_name);
  65. clish_ptype_t *clish_ptype_new(const char *name, const char *text,
  66. const char *pattern, clish_ptype_method_e method,
  67. clish_ptype_preprocess_e preprocess);
  68. void clish_ptype_delete(clish_ptype_t * instance);
  69. /**
  70. * This is the validation method for the specified type.
  71. * \return
  72. * - NULL if the validation is negative.
  73. * - A pointer to a string containing the validated text. NB. this
  74. * may not be identical to that passed in. e.g. it may have been
  75. * a case-modified "select" or a preprocessed value.
  76. */
  77. char *clish_ptype_validate(const clish_ptype_t * instance, const char *text);
  78. /**
  79. * This is the translation method for the specified type. The text is
  80. * first validated then translated into the form which should be used
  81. * for variable substitutions in ACTION or VIEW_ID fields.
  82. * \return
  83. * - NULL if the validation is negative.
  84. * - A pointer to a string containing the translated text. NB. this
  85. * may not be identical to that passed in. e.g. it may have been
  86. * a translated "select" value.
  87. */
  88. char *clish_ptype_translate(const clish_ptype_t * instance, const char *text);
  89. /**
  90. * This is used to perform parameter auto-completion
  91. */
  92. void clish_ptype_word_generator(clish_ptype_t * instance,
  93. lub_argv_t *matches, const char *text);
  94. void clish_ptype_dump(clish_ptype_t * instance);
  95. _CLISH_GET_STR(ptype, name);
  96. _CLISH_SET_STR_ONCE(ptype, text);
  97. _CLISH_GET_STR(ptype, text);
  98. _CLISH_SET_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
  99. _CLISH_GET_STR(ptype, range);
  100. _CLISH_GET(ptype, clish_action_t *, action);
  101. void clish_ptype__set_pattern(clish_ptype_t * instance,
  102. const char *pattern, clish_ptype_method_e method);
  103. #endif /* _clish_ptype_h */