Debian Codegraph @

generic/regcustom.h

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