ptype.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_ONCE(ptype, clish_ptype_preprocess_e, preprocess);
  81. _CLISH_GET_STR(ptype, range);
  82. _CLISH_GET(ptype, clish_action_t *, action);
  83. void clish_ptype__set_pattern(clish_ptype_t * instance,
  84. const char *pattern, clish_ptype_method_e method);
  85. #endif /* _clish_ptype_h */