ptype.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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/argv.h"
  11. #include "clish/action.h"
  12. #include <stddef.h>
  13. /* The means by which the pattern is interpreted and validated. */
  14. typedef enum {
  15. /* [default] - A POSIX regular expression. */
  16. CLISH_PTYPE_METHOD_REGEXP,
  17. /* A numeric definition "min..max" signed and unsigned versions */
  18. CLISH_PTYPE_METHOD_INTEGER,
  19. CLISH_PTYPE_METHOD_UNSIGNEDINTEGER,
  20. /* A list of possible values. The syntax of the string is of the form:
  21. * "valueOne(ONE) valueTwo(TWO) valueThree(THREE)" where the text before
  22. * the parethesis defines the syntax that the user must use, and the
  23. * value within the parenthesis is the result expanded as a parameter value.
  24. */
  25. CLISH_PTYPE_METHOD_SELECT,
  26. /* User-defined code in ACTION */
  27. CLISH_PTYPE_METHOD_CODE,
  28. /* Used to detect errors */
  29. CLISH_PTYPE_METHOD_MAX
  30. } clish_ptype_method_e;
  31. /* This defines the pre processing which is to be performed before a string is validated. */
  32. typedef enum {
  33. /* [default] - do nothing */
  34. CLISH_PTYPE_PRE_NONE,
  35. /* before validation convert to uppercase. */
  36. CLISH_PTYPE_PRE_TOUPPER,
  37. /* before validation convert to lowercase. */
  38. CLISH_PTYPE_PRE_TOLOWER,
  39. /* Used to detect errors */
  40. CLISH_PTYPE_PRE_MAX
  41. } clish_ptype_preprocess_e;
  42. int clish_ptype_compare(const void *first, const void *second);
  43. const char *clish_ptype__get_method_name(clish_ptype_method_e method);
  44. clish_ptype_method_e clish_ptype_method_resolve(const char *method_name);
  45. const char *clish_ptype__get_preprocess_name(clish_ptype_preprocess_e preprocess);
  46. clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char *preprocess_name);
  47. clish_ptype_t *clish_ptype_new(const char *name, const char *text,
  48. const char *pattern, clish_ptype_method_e method,
  49. clish_ptype_preprocess_e preprocess);
  50. void clish_ptype_free(void *instance);
  51. /**
  52. * This is the validation method for the specified type.
  53. * \return
  54. * - NULL if the validation is negative.
  55. * - A pointer to a string containing the validated text. NB. this
  56. * may not be identical to that passed in. e.g. it may have been
  57. * a case-modified "select" or a preprocessed value.
  58. */
  59. char *clish_ptype_validate(clish_ptype_t * instance, const char *text);
  60. /**
  61. * This is the translation method for the specified type. The text is
  62. * first validated then translated into the form which should be used
  63. * for variable substitutions in ACTION or VIEW_ID fields.
  64. * \return
  65. * - NULL if the validation is negative.
  66. * - A pointer to a string containing the translated text. NB. this
  67. * may not be identical to that passed in. e.g. it may have been
  68. * a translated "select" value.
  69. */
  70. char *clish_ptype_translate(clish_ptype_t * instance, const char *text);
  71. /**
  72. * This is used to perform parameter auto-completion
  73. */
  74. void clish_ptype_word_generator(clish_ptype_t * instance,
  75. lub_argv_t *matches, const char *text);
  76. void clish_ptype_dump(clish_ptype_t * instance);
  77. _CLISH_GET_STR(ptype, name);
  78. _CLISH_SET_STR_ONCE(ptype, text);
  79. _CLISH_GET_STR(ptype, text);
  80. _CLISH_SET_STR_ONCE(ptype, completion);
  81. _CLISH_GET_STR(ptype, completion);
  82. _CLISH_GET(ptype, clish_ptype_preprocess_e, preprocess);
  83. _CLISH_SET_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
  84. _CLISH_GET_STR(ptype, range);
  85. _CLISH_GET(ptype, clish_action_t *, action);
  86. _CLISH_GET_STR(ptype, pattern);
  87. _CLISH_GET(ptype, clish_ptype_method_e, method);
  88. void clish_ptype__set_pattern(clish_ptype_t * instance,
  89. const char *pattern, clish_ptype_method_e method);
  90. const char *clish_ptype_method__get_name(clish_ptype_method_e
  91. method);
  92. clish_ptype_method_e clish_ptype_method_resolve(const char *name);
  93. const char *clish_ptype_preprocess__get_name(clish_ptype_preprocess_e
  94. preprocess);
  95. clish_ptype_preprocess_e clish_ptype_preprocess_resolve(const char *name);
  96. #endif /* _clish_ptype_h */