regcustom.h 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * Copyright (c) 1998, 1999 Henry Spencer. All rights reserved.
  3. *
  4. * Development of this software was funded, in part, by Cray Research Inc.,
  5. * UUNET Communications Services Inc., Sun Microsystems Inc., and Scriptics
  6. * Corporation, none of whom are responsible for the results. The author
  7. * thanks all of them.
  8. *
  9. * Redistribution and use in source and binary forms -- with or without
  10. * modification -- are permitted for any purpose, provided that
  11. * redistributions in source form retain this entire copyright notice and
  12. * indicate the origin and nature of any modifications.
  13. *
  14. * I'd appreciate being given credit for this package in the documentation
  15. * of software which uses it, but that is not a requirement.
  16. *
  17. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
  18. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  19. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  20. * HENRY SPENCER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  21. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  22. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  23. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  24. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  25. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. *
  28. * src/include/regex/regcustom.h
  29. */
  30. /* headers if any */
  31. #include "postgres.h"
  32. #include <ctype.h>
  33. #include <limits.h>
  34. /*
  35. * towlower() and friends should be in <wctype.h>, but some pre-C99 systems
  36. * declare them in <wchar.h>.
  37. */
  38. #ifdef HAVE_WCHAR_H
  39. #include <wchar.h>
  40. #endif
  41. #ifdef HAVE_WCTYPE_H
  42. #include <wctype.h>
  43. #endif
  44. #include "mb/pg_wchar.h"
  45. /* overrides for regguts.h definitions, if any */
  46. #define FUNCPTR(name, args) (*name) args
  47. #define MALLOC(n) malloc(n)
  48. #define FREE(p) free(VS(p))
  49. #define REALLOC(p,n) realloc(VS(p),n)
  50. #define assert(x) Assert(x)
  51. /* internal character type and related */
  52. typedef pg_wchar chr; /* the type itself */
  53. typedef unsigned uchr; /* unsigned type that will hold a chr */
  54. typedef int celt; /* type to hold chr, or NOCELT */
  55. #define NOCELT (-1) /* celt value which is not valid chr */
  56. #define CHR(c) ((unsigned char) (c)) /* turn char literal into chr literal */
  57. #define DIGITVAL(c) ((c)-'0') /* turn chr digit into its value */
  58. #define CHRBITS 32 /* bits in a chr; must not use sizeof */
  59. #define CHR_MIN 0x00000000 /* smallest and largest chr; the value */
  60. #define CHR_MAX 0x7ffffffe /* CHR_MAX-CHR_MIN+1 must fit in an int, and
  61. * CHR_MAX+1 must fit in both chr and celt */
  62. /*
  63. * Check if a chr value is in range. Ideally we'd just write this as
  64. * ((c) >= CHR_MIN && (c) <= CHR_MAX)
  65. * However, if chr is unsigned and CHR_MIN is zero, the first part of that
  66. * is a no-op, and certain overly-nannyish compilers give warnings about it.
  67. * So we leave that out here. If you want to make chr signed and/or CHR_MIN
  68. * not zero, redefine this macro as above. Callers should assume that the
  69. * macro may multiply evaluate its argument, even though it does not today.
  70. */
  71. #define CHR_IS_IN_RANGE(c) ((c) <= CHR_MAX)
  72. /* functions operating on chr */
  73. #define iscalnum(x) pg_wc_isalnum(x)
  74. #define iscalpha(x) pg_wc_isalpha(x)
  75. #define iscdigit(x) pg_wc_isdigit(x)
  76. #define iscspace(x) pg_wc_isspace(x)
  77. /* and pick up the standard header */
  78. #include "regex.h"