ptype.h 3.4 KB

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