Lines Matching +full:1 +full:g
19 * 1. Redistributions of source code must retain the above copyright
92 struct re_guts *g; member
93 # define NPAREN 10 /* we need to remember () 1-9 for back refs */
151 static void stripsnug(struct parse *p, struct re_guts *g);
152 static void findmust(struct parse *p, struct re_guts *g);
154 static void computejumps(struct parse *p, struct re_guts *g);
155 static void computematchjumps(struct parse *p, struct re_guts *g);
156 static sopno pluscount(struct parse *p, struct re_guts *g);
171 #define PEEK2() (*(p->next+1))
173 #define MORE2() (p->end - p->next > 1)
177 #define EAT(c) ((SEE(c)) ? (NEXT(), 1) : 0)
178 #define EATTWO(a, b) ((SEETWO(a, b)) ? (NEXT2(), 1) : 0)
191 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
195 #define THERE() (p->slen - 1)
208 struct re_guts *g; in regcomp_internal() local
231 g = (struct re_guts *)malloc(sizeof(struct re_guts)); in regcomp_internal()
232 if (g == NULL) in regcomp_internal()
243 maxlen = ((size_t)-1 >> 1) / sizeof(sop) * 2 / 3; in regcomp_internal()
245 free((char *)g); in regcomp_internal()
248 p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ in regcomp_internal()
254 free((char *)g); in regcomp_internal()
259 p->g = g; in regcomp_internal()
290 g->sets = NULL; in regcomp_internal()
291 g->ncsets = 0; in regcomp_internal()
292 g->cflags = cflags; in regcomp_internal()
293 g->iflags = 0; in regcomp_internal()
294 g->nbol = 0; in regcomp_internal()
295 g->neol = 0; in regcomp_internal()
296 g->must = NULL; in regcomp_internal()
297 g->moffset = -1; in regcomp_internal()
298 g->charjump = NULL; in regcomp_internal()
299 g->matchjump = NULL; in regcomp_internal()
300 g->mlen = 0; in regcomp_internal()
301 g->nsub = 0; in regcomp_internal()
302 g->backrefs = 0; in regcomp_internal()
306 g->firststate = THERE(); in regcomp_internal()
312 g->laststate = THERE(); in regcomp_internal()
315 stripsnug(p, g); in regcomp_internal()
316 findmust(p, g); in regcomp_internal()
320 if(g->mlen > 3) { in regcomp_internal()
321 computejumps(p, g); in regcomp_internal()
322 computematchjumps(p, g); in regcomp_internal()
323 if(g->matchjump == NULL && g->charjump != NULL) { in regcomp_internal()
324 free(&g->charjump[CHAR_MIN]); in regcomp_internal()
325 g->charjump = NULL; in regcomp_internal()
328 g->nplus = pluscount(p, g); in regcomp_internal()
329 g->magic = MAGIC2; in regcomp_internal()
330 preg->re_nsub = g->nsub; in regcomp_internal()
331 preg->re_g = g; in regcomp_internal()
335 if (g->iflags&BAD) in regcomp_internal()
413 p->g->nsub++; in p_ere_exp()
414 subno = p->g->nsub; in p_ere_exp()
441 p->g->iflags |= USEBOL; in p_ere_exp()
442 p->g->nbol++; in p_ere_exp()
443 wascaret = 1; in p_ere_exp()
447 p->g->iflags |= USEEOL; in p_ere_exp()
448 p->g->neol++; in p_ere_exp()
462 if (p->g->cflags®_NEWLINE) in p_ere_exp()
475 handled = 1; in p_ere_exp()
495 case '1': in p_ere_exp()
507 assert(i <= p->g->nsub); in p_ere_exp()
512 (void) dupl(p, p->pbegin[i]+1, p->pend[i]); in p_ere_exp()
516 p->g->backrefs = 1; in p_ere_exp()
719 else if ((ate > 1 || (bc->outer && !MORE())) && !p_branch_empty(p, bc)) in p_branch_do()
743 p->g->iflags |= USEBOL; in p_bre_pre_parse()
744 p->g->nbol++; in p_bre_pre_parse()
754 DROP(1); in p_bre_post_parse()
756 p->g->iflags |= USEEOL; in p_bre_post_parse()
757 p->g->neol++; in p_bre_post_parse()
834 # define BACKSL (1<<CHAR_BIT) in p_simp_re()
876 if (p->g->cflags®_NEWLINE) in p_simp_re()
894 p->g->nsub++; in p_simp_re()
895 subno = p->g->nsub; in p_simp_re()
915 case BACKSL|'1': in p_simp_re()
927 assert(i <= p->g->nsub); in p_simp_re()
932 (void) dupl(p, p->pbegin[i]+1, p->pend[i]); in p_simp_re()
936 p->g->backrefs = 1; in p_simp_re()
1042 if (p->g->cflags®_ICASE) in p_bracket()
1043 cs->icase = 1; in p_bracket()
1045 cs->invert = 1; in p_bracket()
1059 if (cs->invert && p->g->cflags®_NEWLINE) in p_bracket()
1060 cs->bmp['\n' >> 3] |= 1 << ('\n' & 7); in p_bracket()
1066 EMIT(OANYOF, (int)(cs - p->g->sets)); in p_bracket()
1079 s1[1] = L'\0'; in p_range_cmp()
1081 s2[1] = L'\0'; in p_range_cmp()
1147 if (table->__collate_load_error || MB_CUR_MAX > 1) {
1149 if (MB_CUR_MAX > 1) {
1177 if (p->g->cflags®_ICASE)
1178 cs->icase = 1;
1182 cs->invert = 1;
1189 cs->invert = 1;
1198 EMIT(OANYOF, (int)(cs - p->g->sets));
1199 return(1);
1216 if (len >= sizeof(clname) - 1) {
1301 else if (clen == (size_t)-1 || clen == (size_t)-2)
1329 * special meaning, e.g. \b, \B, \w, \W, \s, \S.
1336 if (!(p->g->cflags®_EXTENDED))
1392 assert(n != (size_t)-1);
1394 bracket[n + 1] = '\0';
1395 p->end = bracket+n+1;
1411 if ((p->g->cflags®_ICASE) && iswalpha(ch) && othercase(ch) != ch)
1423 EMIT(OANYOF, (int)(cs - p->g->sets));
1443 bracket[1] = '\n';
1466 # define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
1478 case REP(0, 1): /* as x{1,1}? */
1479 case REP(0, N): /* as x{1,n}? */
1480 case REP(0, INF): /* as x{1,}? */
1483 repeat(p, start+1, 1, to);
1490 case REP(1, 1): /* trivial case */
1493 case REP(1, N): /* as x?x{1,n-1} */
1501 copy = dupl(p, start+1, finish+1);
1503 repeat(p, copy, 1, to-1);
1505 case REP(1, INF): /* as x+ */
1509 case REP(N, N): /* as xx{m-1,n-1} */
1511 repeat(p, copy, from-1, to-1);
1513 case REP(N, INF): /* as xx{n-1,INF} */
1515 repeat(p, copy, from-1, to);
1537 if (n == (size_t)-1 || n == (size_t)-2) {
1542 n = 1;
1570 ncs = reallocarray(p->g->sets, p->g->ncsets + 1, sizeof(*ncs));
1575 p->g->sets = ncs;
1576 cs = &p->g->sets[p->g->ncsets++];
1589 cset *top = &p->g->sets[p->g->ncsets];
1595 if (cs == top-1) /* recover only the easy case */
1596 p->g->ncsets--;
1612 if (cs->nwides > 1)
1622 if (n > 1)
1625 if (n == 1) {
1631 if (cs->nwides == 1)
1646 cs->bmp[ch >> 3] |= 1 << (ch & 7);
1648 newwides = reallocarray(cs->wides, cs->nwides + 1,
1659 cs->bmp[nch >> 3] |= 1 << (nch & 7);
1661 cs->bmp[nch >> 3] |= 1 << (nch & 7);
1677 newranges = reallocarray(cs->ranges, cs->nranges + 1,
1701 newtypes = reallocarray(cs->types, cs->ntypes + 1,
1750 assert(opnd < 1<<OPSHIFT);
1754 if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */
1778 assert(HERE() == sn+1);
1783 for (i = 1; i < NPAREN; i++) {
1792 memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos],
1793 (HERE()-pos-1)*sizeof(sop));
1808 assert(value < 1<<OPSHIFT);
1822 return 1;
1831 return 1;
1836 == static void stripsnug(struct parse *p, struct re_guts *g);
1839 stripsnug(struct parse *p, struct re_guts *g) argument
1841 g->nstates = p->slen;
1842 g->strip = reallocarray((char *)p->strip, p->slen, sizeof(sop));
1843 if (g->strip == NULL) {
1845 g->strip = p->strip;
1851 == static void findmust(struct parse *p, struct re_guts *g);
1860 findmust(struct parse *p, struct re_guts *g) argument
1882 if (MB_CUR_MAX > 1 &&
1889 g->moffset = 0;
1890 scan = g->strip + 1;
1897 newstart = scan - 1;
1900 if (clen == (size_t)-1)
1918 g->iflags |= BAD;
1934 if (newlen > (sopno)g->mlen) { /* ends one */
1936 g->mlen = newlen;
1937 if (offset > -1) {
1938 g->moffset += offset;
1941 g->moffset = offset;
1943 if (offset > -1)
1949 if (newlen > (sopno)g->mlen) { /* ends one */
1951 g->mlen = newlen;
1952 if (offset > -1) {
1953 g->moffset += offset;
1956 g->moffset = offset;
1958 if (offset > -1)
1961 if (offset > -1)
1967 if (newlen > (sopno)g->mlen) { /* ends one */
1969 g->mlen = newlen;
1970 if (offset > -1) {
1971 g->moffset += offset;
1974 g->moffset = offset;
1976 if (offset > -1)
1979 if (offset > -1)
1990 if (newlen > (sopno)g->mlen) { /* ends one */
1992 g->mlen = newlen;
1993 if (offset > -1)
1994 g->moffset += offset;
1996 g->moffset = offset;
1998 offset = -1;
2004 if (g->mlen == 0) { /* there isn't one */
2005 g->moffset = -1;
2010 g->must = malloc((size_t)g->mlen + 1);
2011 if (g->must == NULL) { /* argh; just forget it */
2012 g->mlen = 0;
2013 g->moffset = -1;
2016 cp = g->must;
2019 while (cp < g->must + g->mlen) {
2023 assert(clen != (size_t)-1);
2026 assert(cp == g->must + g->mlen);
2045 if (offset == -1)
2046 return -1;
2061 if (try == -1)
2062 return -1;
2069 return -1;
2089 try = -1;
2092 if (try == -1)
2093 return -1;
2105 == static void computejumps(struct parse *p, struct re_guts *g);
2107 * This algorithm assumes g->must exists and is has size greater than
2115 computejumps(struct parse *p, struct re_guts *g) argument
2124 g->charjump = (int *)malloc((NC_MAX + 1) * sizeof(int));
2125 if (g->charjump == NULL) /* Not a fatal error */
2128 g->charjump = &g->charjump[-(CHAR_MIN)];
2133 for (ch = CHAR_MIN; ch < (CHAR_MAX + 1); ch++)
2134 g->charjump[ch] = g->mlen;
2141 for (mindex = 0; mindex < g->mlen; mindex++)
2142 g->charjump[(int)g->must[mindex]] = g->mlen - mindex - 1;
2147 == static void computematchjumps(struct parse *p, struct re_guts *g);
2149 * This algorithm assumes g->must exists and is has size greater than
2155 * Notice that all values here are minus (g->mlen-1), because of the way
2159 computematchjumps(struct parse *p, struct re_guts *g) argument
2165 * such that i+1...mlen is a substring
2166 * of k+1...k+mlen-i-1
2173 pmatches = (int*) malloc(g->mlen * sizeof(int));
2175 g->matchjump = NULL;
2179 g->matchjump = (int*) malloc(g->mlen * sizeof(int));
2180 if (g->matchjump == NULL) { /* Not a fatal error */
2186 for (mindex = 0; mindex < g->mlen; mindex++)
2187 g->matchjump[mindex] = 2*g->mlen - mindex - 1;
2190 for (mindex = g->mlen - 1, suffix = g->mlen; mindex >= 0;
2200 while (suffix < g->mlen
2201 && g->must[mindex] != g->must[suffix]) {
2202 g->matchjump[suffix] = MIN(g->matchjump[suffix],
2203 g->mlen - mindex - 1);
2213 g->matchjump[mindex] = MIN(g->matchjump[mindex],
2214 g->mlen + suffix - mindex);
2217 while (suffix < g->mlen) {
2218 while (suffix <= ssuffix && suffix < g->mlen) {
2219 g->matchjump[suffix] = MIN(g->matchjump[suffix],
2220 g->mlen + ssuffix - suffix);
2223 if (suffix < g->mlen)
2232 == static sopno pluscount(struct parse *p, struct re_guts *g);
2235 pluscount(struct parse *p, struct re_guts *g) argument
2245 scan = g->strip + 1;
2260 g->iflags |= BAD;