ptype.h 3.4 KB

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