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 29 /* headers if any */ 30 #include "tclInt.h" 31 32 /* overrides for regguts.h definitions, if any */ 33 #define FUNCPTR(name, args) (*name) _ANSI_ARGS_(args) 34 #define MALLOC(n) ckalloc(n) 35 #define FREE(p) ckfree(VS(p)) 36 #define REALLOC(p,n) ckrealloc(VS(p),n) 37 38 39 40 /* 41 * Do not insert extras between the "begin" and "end" lines -- this 42 * chunk is automatically extracted to be fitted into regex.h. 43 */ 44 /* --- begin --- */ 45 /* ensure certain things don't sneak in from system headers */ 46 #ifdef __REG_WIDE_T 47 #undef __REG_WIDE_T 48 #endif 49 #ifdef __REG_WIDE_COMPILE 50 #undef __REG_WIDE_COMPILE 51 #endif 52 #ifdef __REG_WIDE_EXEC 53 #undef __REG_WIDE_EXEC 54 #endif 55 #ifdef __REG_REGOFF_T 56 #undef __REG_REGOFF_T 57 #endif 58 #ifdef __REG_VOID_T 59 #undef __REG_VOID_T 60 #endif 61 #ifdef __REG_CONST 62 #undef __REG_CONST 63 #endif 64 #ifdef __REG_NOFRONT 65 #undef __REG_NOFRONT 66 #endif 67 #ifdef __REG_NOCHAR 68 #undef __REG_NOCHAR 69 #endif 70 /* interface types */ 71 #define __REG_WIDE_T Tcl_UniChar 72 #define __REG_REGOFF_T long /* not really right, but good enough... */ 73 #define __REG_VOID_T VOID 74 #define __REG_CONST CONST 75 /* names and declarations */ 76 #define __REG_WIDE_COMPILE TclReComp 77 #define __REG_WIDE_EXEC TclReExec 78 #define __REG_NOFRONT /* don't want regcomp() and regexec() */ 79 #define __REG_NOCHAR /* or the char versions */ 80 #define regfree TclReFree 81 #define regerror TclReError 82 /* --- end --- */ 83 84 85 86 /* internal character type and related */ 87 typedef Tcl_UniChar chr; /* the type itself */ 88 typedef int pchr; /* what it promotes to */ 89 typedef unsigned uchr; /* unsigned type that will hold a chr */ 90 typedef int celt; /* type to hold chr, MCCE number, or NOCELT */ 91 #define NOCELT (-1) /* celt value which is not valid chr or MCCE */ 92 #define CHR(c) (UCHAR(c)) /* turn char literal into chr literal */ 93 #define DIGITVAL(c) ((c)-'0') /* turn chr digit into its value */ 94 #if TCL_UTF_MAX > 3 95 #define CHRBITS 32 /* bits in a chr; must not use sizeof */ 96 #define CHR_MIN 0x00000000 /* smallest and largest chr; the value */ 97 #define CHR_MAX 0xffffffff /* CHR_MAX-CHR_MIN+1 should fit in uchr */ 98 #else 99 #define CHRBITS 16 /* bits in a chr; must not use sizeof */ 100 #define CHR_MIN 0x0000 /* smallest and largest chr; the value */ 101 #define CHR_MAX 0xffff /* CHR_MAX-CHR_MIN+1 should fit in uchr */ 102 #endif 103 104 /* functions operating on chr */ 105 #define iscalnum(x) Tcl_UniCharIsAlnum(x) 106 #define iscalpha(x) Tcl_UniCharIsAlpha(x) 107 #define iscdigit(x) Tcl_UniCharIsDigit(x) 108 #define iscspace(x) Tcl_UniCharIsSpace(x) 109 110 /* name the external functions */ 111 #define compile TclReComp 112 #define exec TclReExec 113 114 /* enable/disable debugging code (by whether REG_DEBUG is defined or not) */ 115 #if 0 /* no debug unless requested by makefile */ 116 #define REG_DEBUG /* */ 117 #endif 118 119 /* and pick up the standard header */ 120 #include "regex.h" 121