regcustom.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 redistributions
  11. * in source form retain this entire copyright notice and indicate the origin
  12. * and nature of any modifications.
  13. *
  14. * I'd appreciate being given credit for this package in the documentation of
  15. * 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. /*
  29. * Headers if any.
  30. */
  31. #include "regex.h"
  32. /*
  33. * Overrides for regguts.h definitions, if any.
  34. */
  35. #define FUNCPTR(name, args) (*name)args
  36. #define MALLOC(n) VS(attemptckalloc(n))
  37. #define FREE(p) ckfree(VS(p))
  38. #define REALLOC(p,n) VS(attemptckrealloc(VS(p),n))
  39. /*
  40. * Do not insert extras between the "begin" and "end" lines - this chunk is
  41. * automatically extracted to be fitted into regex.h.
  42. */
  43. /* --- begin --- */
  44. /* Ensure certain things don't sneak in from system headers. */
  45. #ifdef __REG_WIDE_T
  46. #undef __REG_WIDE_T
  47. #endif
  48. #ifdef __REG_WIDE_COMPILE
  49. #undef __REG_WIDE_COMPILE
  50. #endif
  51. #ifdef __REG_WIDE_EXEC
  52. #undef __REG_WIDE_EXEC
  53. #endif
  54. #ifdef __REG_REGOFF_T
  55. #undef __REG_REGOFF_T
  56. #endif
  57. #ifdef __REG_NOFRONT
  58. #undef __REG_NOFRONT
  59. #endif
  60. #ifdef __REG_NOCHAR
  61. #undef __REG_NOCHAR
  62. #endif
  63. /* Interface types */
  64. #define __REG_WIDE_T Tcl_UniChar
  65. #define __REG_REGOFF_T long /* Not really right, but good enough... */
  66. /* Names and declarations */
  67. #define __REG_WIDE_COMPILE TclReComp
  68. #define __REG_WIDE_EXEC TclReExec
  69. #define __REG_NOFRONT /* Don't want regcomp() and regexec() */
  70. #define __REG_NOCHAR /* Or the char versions */
  71. #define regfree TclReFree
  72. #define regerror TclReError
  73. /* --- end --- */
  74. /*
  75. * Internal character type and related.
  76. */
  77. typedef Tcl_UniChar chr; /* The type itself. */
  78. typedef int pchr; /* What it promotes to. */
  79. typedef unsigned uchr; /* Unsigned type that will hold a chr. */
  80. typedef int celt; /* Type to hold chr, or NOCELT */
  81. #define NOCELT (-1) /* Celt value which is not valid chr */
  82. #define CHR(c) (UCHAR(c)) /* Turn char literal into chr literal */
  83. #define DIGITVAL(c) ((c)-'0') /* Turn chr digit into its value */
  84. #if TCL_UTF_MAX > 4
  85. #define CHRBITS 32 /* Bits in a chr; must not use sizeof */
  86. #define CHR_MIN 0x00000000 /* Smallest and largest chr; the value */
  87. #define CHR_MAX 0xFFFFFFFF /* CHR_MAX-CHR_MIN+1 should fit in uchr */
  88. #else
  89. #define CHRBITS 16 /* Bits in a chr; must not use sizeof */
  90. #define CHR_MIN 0x0000 /* Smallest and largest chr; the value */
  91. #define CHR_MAX 0xFFFF /* CHR_MAX-CHR_MIN+1 should fit in uchr */
  92. #endif
  93. /*
  94. * Functions operating on chr.
  95. */
  96. #define iscalnum(x) Tcl_UniCharIsAlnum(x)
  97. #define iscalpha(x) Tcl_UniCharIsAlpha(x)
  98. #define iscdigit(x) Tcl_UniCharIsDigit(x)
  99. #define iscspace(x) Tcl_UniCharIsSpace(x)
  100. /*
  101. * Name the external functions.
  102. */
  103. #define compile TclReComp
  104. #define exec TclReExec
  105. /*
  106. & Enable/disable debugging code (by whether REG_DEBUG is defined or not).
  107. */
  108. #if 0 /* No debug unless requested by makefile. */
  109. #define REG_DEBUG /* */
  110. #endif
  111. /*
  112. * Method of allocating a local workspace. We used a thread-specific data
  113. * space to store this because the regular expression engine is never
  114. * reentered from the same thread; it doesn't make any callbacks.
  115. */
  116. #if 1
  117. #define AllocVars(vPtr) \
  118. static Tcl_ThreadDataKey varsKey; \
  119. struct vars *vPtr = (struct vars *) \
  120. Tcl_GetThreadData(&varsKey, sizeof(struct vars))
  121. #else
  122. /*
  123. * This strategy for allocating workspace is "more proper" in some sense, but
  124. * quite a bit slower. Using TSD (as above) leads to code that is quite a bit
  125. * faster in practice (measured!)
  126. */
  127. #define AllocVars(vPtr) \
  128. struct vars *vPtr = (struct vars *) MALLOC(sizeof(struct vars))
  129. #define FreeVars(vPtr) \
  130. FREE(vPtr)
  131. #endif
  132. /*
  133. * Local Variables:
  134. * mode: c
  135. * c-basic-offset: 4
  136. * fill-column: 78
  137. * End:
  138. */