/usr.bin/grep/regex/glue.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 67 lines · 53 code · 13 blank · 1 comment · 5 complexity · 51cd084db88d6accd6030fb75d1c430c MD5 · raw file

  1. /* $FreeBSD$ */
  2. #ifndef GLUE_H
  3. #define GLUE_H
  4. #include <limits.h>
  5. #undef RE_DUP_MAX
  6. #include <regex.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #define TRE_WCHAR 1
  10. #define TRE_MULTIBYTE 1
  11. #define HAVE_MBSTATE_T 1
  12. #define TRE_CHAR(n) L##n
  13. #define CHF "%lc"
  14. #define tre_char_t wchar_t
  15. #define tre_mbrtowc(pwc, s, n, ps) (mbrtowc((pwc), (s), (n), (ps)))
  16. #define tre_strlen wcslen
  17. #define tre_isspace iswspace
  18. #define tre_isalnum iswalnum
  19. #define REG_OK 0
  20. #define REG_LITERAL 0020
  21. #define REG_WORD 0100
  22. #define REG_GNU 0400
  23. #define TRE_MB_CUR_MAX MB_CUR_MAX
  24. #ifndef _GREP_DEBUG
  25. #define DPRINT(msg)
  26. #else
  27. #define DPRINT(msg) do {printf msg; fflush(stdout);} while(/*CONSTCOND*/0)
  28. #endif
  29. #define MIN(a,b) ((a > b) ? (b) : (a))
  30. #define MAX(a,b) ((a > b) ? (a) : (b))
  31. typedef enum { STR_WIDE, STR_BYTE, STR_MBS, STR_USER } tre_str_type_t;
  32. #define CALL_WITH_OFFSET(fn) \
  33. do \
  34. { \
  35. size_t slen = (size_t)(pmatch[0].rm_eo - pmatch[0].rm_so); \
  36. size_t offset = pmatch[0].rm_so; \
  37. int ret; \
  38. \
  39. if ((long long)pmatch[0].rm_eo - pmatch[0].rm_so < 0) \
  40. return REG_NOMATCH; \
  41. ret = fn; \
  42. for (unsigned i = 0; (!(eflags & REG_NOSUB) && (i < nmatch)); i++)\
  43. { \
  44. pmatch[i].rm_so += offset; \
  45. pmatch[i].rm_eo += offset; \
  46. } \
  47. return ret; \
  48. } while (0 /*CONSTCOND*/)
  49. int
  50. tre_convert_pattern(const char *regex, size_t n, tre_char_t **w,
  51. size_t *wn);
  52. void
  53. tre_free_pattern(tre_char_t *wregex);
  54. #endif