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;
1188 cs->invert = 1;
1197 EMIT(OANYOF, (int)(cs - p->g->sets));
1198 return(1);
1215 if (len >= sizeof(clname) - 1) {
1300 else if (clen == (size_t)-1 || clen == (size_t)-2)
1328 * special meaning, e.g. \b, \B, \w, \W, \s, \S.
1335 if (!(p->g->cflags®_EXTENDED))
1391 assert(n != (size_t)-1);
1393 bracket[n + 1] = '\0';
1394 p->end = bracket+n+1;
1410 if ((p->g->cflags®_ICASE) && iswalpha(ch) && othercase(ch) != ch)
1422 EMIT(OANYOF, (int)(cs - p->g->sets));
1442 bracket[1] = '\n';
1465 # define MAP(n) (((n) <= 1) ? (n) : ((n) == INFINITY) ? INF : N)
1477 case REP(0, 1): /* as x{1,1}? */
1478 case REP(0, N): /* as x{1,n}? */
1479 case REP(0, INF): /* as x{1,}? */
1482 repeat(p, start+1, 1, to);
1489 case REP(1, 1): /* trivial case */
1492 case REP(1, N): /* as x?x{1,n-1} */
1500 copy = dupl(p, start+1, finish+1);
1502 repeat(p, copy, 1, to-1);
1504 case REP(1, INF): /* as x+ */
1508 case REP(N, N): /* as xx{m-1,n-1} */
1510 repeat(p, copy, from-1, to-1);
1512 case REP(N, INF): /* as xx{n-1,INF} */
1514 repeat(p, copy, from-1, to);
1536 if (n == (size_t)-1 || n == (size_t)-2) {
1541 n = 1;
1569 ncs = reallocarray(p->g->sets, p->g->ncsets + 1, sizeof(*ncs));
1574 p->g->sets = ncs;
1575 cs = &p->g->sets[p->g->ncsets++];
1588 cset *top = &p->g->sets[p->g->ncsets];
1594 if (cs == top-1) /* recover only the easy case */
1595 p->g->ncsets--;
1611 if (cs->nwides > 1)
1621 if (n > 1)
1624 if (n == 1) {
1630 if (cs->nwides == 1)
1645 cs->bmp[ch >> 3] |= 1 << (ch & 7);
1647 newwides = reallocarray(cs->wides, cs->nwides + 1,
1658 cs->bmp[nch >> 3] |= 1 << (nch & 7);
1660 cs->bmp[nch >> 3] |= 1 << (nch & 7);
1676 newranges = reallocarray(cs->ranges, cs->nranges + 1,
1700 newtypes = reallocarray(cs->types, cs->ntypes + 1,
1749 assert(opnd < 1<<OPSHIFT);
1753 if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */
1777 assert(HERE() == sn+1);
1782 for (i = 1; i < NPAREN; i++) {
1791 memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos],
1792 (HERE()-pos-1)*sizeof(sop));
1807 assert(value < 1<<OPSHIFT);
1821 return 1;
1830 return 1;
1835 == static void stripsnug(struct parse *p, struct re_guts *g);
1838 stripsnug(struct parse *p, struct re_guts *g) argument
1840 g->nstates = p->slen;
1841 g->strip = reallocarray((char *)p->strip, p->slen, sizeof(sop));
1842 if (g->strip == NULL) {
1844 g->strip = p->strip;
1850 == static void findmust(struct parse *p, struct re_guts *g);
1859 findmust(struct parse *p, struct re_guts *g) argument
1881 if (MB_CUR_MAX > 1 &&
1888 g->moffset = 0;
1889 scan = g->strip + 1;
1896 newstart = scan - 1;
1899 if (clen == (size_t)-1)
1917 g->iflags |= BAD;
1933 if (newlen > (sopno)g->mlen) { /* ends one */
1935 g->mlen = newlen;
1936 if (offset > -1) {
1937 g->moffset += offset;
1940 g->moffset = offset;
1942 if (offset > -1)
1948 if (newlen > (sopno)g->mlen) { /* ends one */
1950 g->mlen = newlen;
1951 if (offset > -1) {
1952 g->moffset += offset;
1955 g->moffset = offset;
1957 if (offset > -1)
1960 if (offset > -1)
1966 if (newlen > (sopno)g->mlen) { /* ends one */
1968 g->mlen = newlen;
1969 if (offset > -1) {
1970 g->moffset += offset;
1973 g->moffset = offset;
1975 if (offset > -1)
1978 if (offset > -1)
1989 if (newlen > (sopno)g->mlen) { /* ends one */
1991 g->mlen = newlen;
1992 if (offset > -1)
1993 g->moffset += offset;
1995 g->moffset = offset;
1997 offset = -1;
2003 if (g->mlen == 0) { /* there isn't one */
2004 g->moffset = -1;
2009 g->must = malloc((size_t)g->mlen + 1);
2010 if (g->must == NULL) { /* argh; just forget it */
2011 g->mlen = 0;
2012 g->moffset = -1;
2015 cp = g->must;
2018 while (cp < g->must + g->mlen) {
2022 assert(clen != (size_t)-1);
2025 assert(cp == g->must + g->mlen);
2044 if (offset == -1)
2045 return -1;
2060 if (try == -1)
2061 return -1;
2068 return -1;
2088 try = -1;
2091 if (try == -1)
2092 return -1;
2104 == static void computejumps(struct parse *p, struct re_guts *g);
2106 * This algorithm assumes g->must exists and is has size greater than
2114 computejumps(struct parse *p, struct re_guts *g) argument
2123 g->charjump = (int *)malloc((NC_MAX + 1) * sizeof(int));
2124 if (g->charjump == NULL) /* Not a fatal error */
2127 g->charjump = &g->charjump[-(CHAR_MIN)];
2132 for (ch = CHAR_MIN; ch < (CHAR_MAX + 1); ch++)
2133 g->charjump[ch] = g->mlen;
2140 for (mindex = 0; mindex < g->mlen; mindex++)
2141 g->charjump[(int)g->must[mindex]] = g->mlen - mindex - 1;
2146 == static void computematchjumps(struct parse *p, struct re_guts *g);
2148 * This algorithm assumes g->must exists and is has size greater than
2154 * Notice that all values here are minus (g->mlen-1), because of the way
2158 computematchjumps(struct parse *p, struct re_guts *g) argument
2164 * such that i+1...mlen is a substring
2165 * of k+1...k+mlen-i-1
2172 pmatches = (int*) malloc(g->mlen * sizeof(int));
2174 g->matchjump = NULL;
2178 g->matchjump = (int*) malloc(g->mlen * sizeof(int));
2179 if (g->matchjump == NULL) { /* Not a fatal error */
2185 for (mindex = 0; mindex < g->mlen; mindex++)
2186 g->matchjump[mindex] = 2*g->mlen - mindex - 1;
2189 for (mindex = g->mlen - 1, suffix = g->mlen; mindex >= 0;
2199 while (suffix < g->mlen
2200 && g->must[mindex] != g->must[suffix]) {
2201 g->matchjump[suffix] = MIN(g->matchjump[suffix],
2202 g->mlen - mindex - 1);
2212 g->matchjump[mindex] = MIN(g->matchjump[mindex],
2213 g->mlen + suffix - mindex);
2216 while (suffix < g->mlen) {
2217 while (suffix <= ssuffix && suffix < g->mlen) {
2218 g->matchjump[suffix] = MIN(g->matchjump[suffix],
2219 g->mlen + ssuffix - suffix);
2222 if (suffix < g->mlen)
2231 == static sopno pluscount(struct parse *p, struct re_guts *g);
2234 pluscount(struct parse *p, struct re_guts *g) argument
2244 scan = g->strip + 1;
2259 g->iflags |= BAD;