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