00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #if defined(LIBC_SCCS) && !defined(lint)
00041 static char sccsid[] = "@(#)regexec.c 8.3 (Berkeley) 3/20/94";
00042 #endif
00043
00044
00045
00046
00047
00048
00049
00050
00051 #include <sys/types.h>
00052 #include <stdio.h>
00053 #include <stdlib.h>
00054 #include <string.h>
00055 #include <limits.h>
00056 #include <ctype.h>
00057 #include "regex.h"
00058
00059 #include "utils.h"
00060 #include "regex2.h"
00061
00062 static int nope = 0;
00063
00064
00065 #define states long
00066 #define states1 states
00067 #define CLEAR(v) ((v) = 0)
00068 #define SET0(v, n) ((v) &= ~(1 << (n)))
00069 #define SET1(v, n) ((v) |= 1 << (n))
00070 #define ISSET(v, n) ((v) & (1 << (n)))
00071 #define ASSIGN(d, s) ((d) = (s))
00072 #define EQ(a, b) ((a) == (b))
00073 #define STATEVARS int dummy
00074 #define STATESETUP(m, n)
00075 #define STATETEARDOWN(m)
00076 #define SETUP(v) ((v) = 0)
00077 #define onestate int
00078 #define INIT(o, n) ((o) = (unsigned)1 << (n))
00079 #define INC(o) ((o) <<= 1)
00080 #define ISSTATEIN(v, o) ((v) & (o))
00081
00082
00083 #define FWD(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) << (n))
00084 #define BACK(dst, src, n) ((dst) |= ((unsigned)(src)&(here)) >> (n))
00085 #define ISSETBACK(v, n) ((v) & ((unsigned)here >> (n)))
00086
00087 #define SNAMES
00088
00089 #include "engine.ci"
00090
00091
00092 #undef states
00093 #undef CLEAR
00094 #undef SET0
00095 #undef SET1
00096 #undef ISSET
00097 #undef ASSIGN
00098 #undef EQ
00099 #undef STATEVARS
00100 #undef STATESETUP
00101 #undef STATETEARDOWN
00102 #undef SETUP
00103 #undef onestate
00104 #undef INIT
00105 #undef INC
00106 #undef ISSTATEIN
00107 #undef FWD
00108 #undef BACK
00109 #undef ISSETBACK
00110 #undef SNAMES
00111
00112
00113 #define states char *
00114 #define CLEAR(v) memset(v, 0, m->g->nstates)
00115 #define SET0(v, n) ((v)[n] = 0)
00116 #define SET1(v, n) ((v)[n] = 1)
00117 #define ISSET(v, n) ((v)[n])
00118 #define ASSIGN(d, s) memcpy(d, s, m->g->nstates)
00119 #define EQ(a, b) (memcmp(a, b, m->g->nstates) == 0)
00120 #define STATEVARS int vn; char *space
00121 #define STATESETUP(m, nv) { (m)->space = malloc((nv)*(m)->g->nstates); \
00122 if ((m)->space == NULL) return(REG_ESPACE); \
00123 (m)->vn = 0; }
00124 #define STATETEARDOWN(m) { free((m)->space); }
00125 #define SETUP(v) ((v) = &m->space[m->vn++ * m->g->nstates])
00126 #define onestate int
00127 #define INIT(o, n) ((o) = (n))
00128 #define INC(o) ((o)++)
00129 #define ISSTATEIN(v, o) ((v)[o])
00130
00131
00132 #define FWD(dst, src, n) ((dst)[here+(n)] |= (src)[here])
00133 #define BACK(dst, src, n) ((dst)[here-(n)] |= (src)[here])
00134 #define ISSETBACK(v, n) ((v)[here - (n)])
00135
00136 #define LNAMES
00137
00138 #include "engine.ci"
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 int __stdcall
00156 regexec(preg, string, nmatch, pmatch, eflags)
00157 const regex_t *preg;
00158 const char *string;
00159 size_t nmatch;
00160 regmatch_t pmatch[];
00161 int eflags;
00162 {
00163 register struct re_guts *g = preg->re_g;
00164 #ifdef REDEBUG
00165 # define GOODFLAGS(f) (f)
00166 #else
00167 # define GOODFLAGS(f) ((f)&(REG_NOTBOL|REG_NOTEOL|REG_STARTEND))
00168 #endif
00169
00170 if (preg->re_magic != MAGIC1 || g->magic != MAGIC2)
00171 return(REG_BADPAT);
00172 assert(!(g->iflags&BAD));
00173 if (g->iflags&BAD)
00174 return(REG_BADPAT);
00175 eflags = GOODFLAGS(eflags);
00176
00177 if (g->nstates <= CHAR_BIT*sizeof(states1) && !(eflags®_LARGE))
00178 return(smatcher(g, (char *)string, nmatch, pmatch, eflags));
00179 else
00180 return(lmatcher(g, (char *)string, nmatch, pmatch, eflags));
00181 }