Lines Matching refs:p

128 static void p_ere(struct parse *p, int stop, size_t reclimit);
129 static void p_ere_exp(struct parse *p, size_t reclimit);
130 static void p_str(struct parse *p);
131 static void p_bre(struct parse *p, int end1, int end2, size_t reclimit);
132 static int p_simp_re(struct parse *p, int starordinary, size_t reclimit);
133 static int p_count(struct parse *p);
134 static void p_bracket(struct parse *p);
135 static void p_b_term(struct parse *p, cset *cs);
136 static void p_b_cclass(struct parse *p, cset *cs);
137 static void p_b_eclass(struct parse *p, cset *cs);
138 static char p_b_symbol(struct parse *p);
139 static char p_b_coll_elem(struct parse *p, int endc);
141 static void bothcases(struct parse *p, int ch);
142 static void ordinary(struct parse *p, int ch);
143 static void nonnewline(struct parse *p);
144 static void repeat(struct parse *p, sopno start, int from, int to, size_t reclimit);
145 static int seterr(struct parse *p, int e);
146 static cset *allocset(struct parse *p);
147 static void freeset(struct parse *p, cset *cs);
148 static sopno freezeset(struct parse *p, cset *cs);
149 static int firstch(struct parse *p, cset *cs);
150 static int nch(struct parse *p, cset *cs);
151 static void mcadd(struct parse *p, cset *cs, const char *cp);
157 static void mcinvert(struct parse *p, cset *cs);
158 static void mccase(struct parse *p, cset *cs);
161 static void categorize(struct parse *p, struct re_guts *g);
162 static sopno dupl(struct parse *p, sopno start, sopno finish);
163 static void doemit(struct parse *p, sop op, sopno opnd);
164 static void doinsert(struct parse *p, sop op, sopno opnd, sopno pos);
165 static void dofwd(struct parse *p, sopno pos, sopno value);
166 static int enlarge(struct parse *p, sopno size);
167 static void stripsnug(struct parse *p, struct re_guts *g);
168 static void findmust(struct parse *p, struct re_guts *g);
169 static sopno pluscount(struct parse *p, struct re_guts *g);
182 #define PEEK() (*p->next)
183 #define PEEK2() (*(p->next+1))
184 #define MORE() (p->next < p->end)
185 #define MORE2() (p->next+1 < p->end)
190 #define NEXT() (p->next++)
191 #define NEXT2() (p->next += 2)
192 #define NEXTn(n) (p->next += (n))
193 #define GETNEXT() (*p->next++)
194 #define SETERROR(e) seterr(p, (e))
199 #define EMIT(op, sopnd) doemit(p, (sop)(op), sopnd)
200 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
201 #define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
203 #define HERE() (p->slen)
204 #define THERE() (p->slen - 1)
205 #define THERETHERE() (p->slen - 2)
206 #define DROP(n) (p->slen -= (n))
215 #define MEMSIZE(p) \ argument
216 ((p)->ncsalloc / CHAR_BIT * (p)->g->csetsize + \
217 (p)->ncsalloc * sizeof(cset) + \
218 (p)->ssize * sizeof(sop))
241 struct parse *p = &pa; in regcomp() local
268 p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ in regcomp()
269 p->strip = calloc(p->ssize, sizeof(sop)); in regcomp()
270 p->slen = 0; in regcomp()
271 if (p->strip == NULL) { in regcomp()
277 p->g = g; in regcomp()
278 p->next = pattern; in regcomp()
279 p->end = p->next + len; in regcomp()
280 p->error = 0; in regcomp()
281 p->ncsalloc = 0; in regcomp()
283 p->pbegin[i] = 0; in regcomp()
284 p->pend[i] = 0; in regcomp()
306 p_ere(p, OUT, 0); in regcomp()
308 p_str(p); in regcomp()
310 p_bre(p, OUT, OUT, 0); in regcomp()
315 categorize(p, g); in regcomp()
316 stripsnug(p, g); in regcomp()
317 findmust(p, g); in regcomp()
318 g->nplus = pluscount(p, g); in regcomp()
330 if (p->error != 0) /* lose */ in regcomp()
332 return(p->error); in regcomp()
341 struct parse *p, in p_ere() argument
351 _DIAGASSERT(p != NULL); in p_ere()
353 if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) { in p_ere()
354 p->error = REG_ESPACE; in p_ere()
362 p_ere_exp(p, reclimit); in p_ere()
395 struct parse *p, in p_ere_exp() argument
405 _DIAGASSERT(p != NULL); in p_ere_exp()
414 p->g->nsub++; in p_ere_exp()
415 subno = p->g->nsub; in p_ere_exp()
417 p->pbegin[subno] = HERE(); in p_ere_exp()
420 p_ere(p, ')', reclimit); in p_ere_exp()
422 p->pend[subno] = HERE(); in p_ere_exp()
423 assert(p->pend[subno] != 0); in p_ere_exp()
442 p->g->iflags |= USEBOL; in p_ere_exp()
443 p->g->nbol++; in p_ere_exp()
448 p->g->iflags |= USEEOL; in p_ere_exp()
449 p->g->neol++; in p_ere_exp()
460 if (p->g->cflags&REG_NEWLINE) in p_ere_exp()
461 nonnewline(p); in p_ere_exp()
466 p_bracket(p); in p_ere_exp()
471 ordinary(p, c); in p_ere_exp()
477 if (p->error != 0) in p_ere_exp()
479 ordinary(p, c); in p_ere_exp()
515 count = p_count(p); in p_ere_exp()
518 count2 = p_count(p); in p_ere_exp()
524 repeat(p, pos, count, count2, 0); in p_ere_exp()
549 struct parse *p) in p_str() argument
552 _DIAGASSERT(p != NULL); in p_str()
556 ordinary(p, GETNEXT()); in p_str()
573 struct parse *p, in p_bre() argument
582 _DIAGASSERT(p != NULL); in p_bre()
584 if (reclimit++ > RECLIMIT || p->error == REG_ESPACE) { in p_bre()
585 p->error = REG_ESPACE; in p_bre()
593 p->g->iflags |= USEBOL; in p_bre()
594 p->g->nbol++; in p_bre()
597 wasdollar = p_simp_re(p, first, reclimit); in p_bre()
603 p->g->iflags |= USEEOL; in p_bre()
604 p->g->neol++; in p_bre()
616 struct parse *p, in p_simp_re() argument
627 _DIAGASSERT(p != NULL); in p_simp_re()
639 if (p->g->cflags&REG_NEWLINE) in p_simp_re()
640 nonnewline(p); in p_simp_re()
645 p_bracket(p); in p_simp_re()
651 p->g->nsub++; in p_simp_re()
652 subno = p->g->nsub; in p_simp_re()
654 p->pbegin[subno] = HERE(); in p_simp_re()
658 p_bre(p, '\\', ')', reclimit); in p_simp_re()
660 p->pend[subno] = HERE(); in p_simp_re()
661 assert(p->pend[subno] != 0); in p_simp_re()
681 if (p->pend[i] != 0) { in p_simp_re()
682 assert(i <= p->g->nsub); in p_simp_re()
684 assert(p->pbegin[i] != 0); in p_simp_re()
685 assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); in p_simp_re()
686 assert(OP(p->strip[p->pend[i]]) == ORPAREN); in p_simp_re()
687 (void) dupl(p, p->pbegin[i]+1, p->pend[i]); in p_simp_re()
691 p->g->backrefs = 1; in p_simp_re()
697 if (p->error != 0) in p_simp_re()
699 ordinary(p, c &~ BACKSL); in p_simp_re()
710 count = p_count(p); in p_simp_re()
713 count2 = p_count(p); in p_simp_re()
719 repeat(p, pos, count, count2, 0); in p_simp_re()
738 struct parse *p) in p_count() argument
743 _DIAGASSERT(p != NULL); in p_count()
763 struct parse *p) in p_bracket() argument
767 _DIAGASSERT(p != NULL); in p_bracket()
769 cs = allocset(p); in p_bracket()
774 if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", in p_bracket()
780 if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", in p_bracket()
794 p_b_term(p, cs); in p_bracket()
799 if (p->error != 0) /* don't mess things up further */ in p_bracket()
802 if (p->g->cflags&REG_ICASE) { in p_bracket()
806 for (i = p->g->csetsize - 1; i >= 0; i--) in p_bracket()
813 mccase(p, cs); in p_bracket()
818 for (i = p->g->csetsize - 1; i >= 0; i--) in p_bracket()
823 if (p->g->cflags&REG_NEWLINE) in p_bracket()
826 mcinvert(p, cs); in p_bracket()
831 if (nch(p, cs) == 1) { /* optimize singleton sets */ in p_bracket()
832 ordinary(p, firstch(p, cs)); in p_bracket()
833 freeset(p, cs); in p_bracket()
835 EMIT(OANYOF, freezeset(p, cs)); in p_bracket()
844 struct parse *p, in p_b_term() argument
851 _DIAGASSERT(p != NULL); in p_b_term()
875 p_b_cclass(p, cs); in p_b_term()
884 p_b_eclass(p, cs); in p_b_term()
890 start = p_b_symbol(p); in p_b_term()
897 finish = p_b_symbol(p); in p_b_term()
914 struct parse *p, in p_b_cclass() argument
923 _DIAGASSERT(p != NULL); in p_b_cclass()
926 sp = p->next; in p_b_cclass()
930 len = p->next - sp; in p_b_cclass()
944 MCadd(p, cs, u); in p_b_cclass()
955 struct parse *p, in p_b_eclass() argument
960 _DIAGASSERT(p != NULL); in p_b_eclass()
963 c = p_b_coll_elem(p, '='); in p_b_eclass()
973 struct parse *p) in p_b_symbol() argument
977 _DIAGASSERT(p != NULL); in p_b_symbol()
984 value = p_b_coll_elem(p, '.'); in p_b_symbol()
995 struct parse *p, in p_b_coll_elem() argument
1002 _DIAGASSERT(p != NULL); in p_b_coll_elem()
1004 sp = p->next; in p_b_coll_elem()
1012 len = p->next - sp; in p_b_coll_elem()
1047 struct parse *p, in bothcases() argument
1054 _DIAGASSERT(p != NULL); in bothcases()
1056 oldnext = p->next; in bothcases()
1057 oldend = p->end; in bothcases()
1060 p->next = bracket; in bothcases()
1061 p->end = bracket+2; in bothcases()
1065 p_bracket(p); in bothcases()
1066 assert(p->next == bracket+2); in bothcases()
1067 p->next = oldnext; in bothcases()
1068 p->end = oldend; in bothcases()
1077 struct parse *p, in ordinary() argument
1083 _DIAGASSERT(p != NULL); in ordinary()
1085 cap = p->g->categories; in ordinary()
1086 if ((p->g->cflags & REG_ICASE) && isalpha(uc) && othercase(uc) != uc) in ordinary()
1087 bothcases(p, uc); in ordinary()
1092 p->g->ncategories + 1)); in ordinary()
1093 cap[uc] = (unsigned char)p->g->ncategories++; in ordinary()
1106 struct parse *p) in nonnewline() argument
1112 _DIAGASSERT(p != NULL); in nonnewline()
1114 oldnext = p->next; in nonnewline()
1115 oldend = p->end; in nonnewline()
1117 p->next = bracket; in nonnewline()
1118 p->end = bracket+3; in nonnewline()
1123 p_bracket(p); in nonnewline()
1124 assert(p->next == bracket+3); in nonnewline()
1125 p->next = oldnext; in nonnewline()
1126 p->end = oldend; in nonnewline()
1136 struct parse *p, in repeat() argument
1149 _DIAGASSERT(p != NULL); in repeat()
1152 p->error = REG_ESPACE; in repeat()
1153 if (p->error) in repeat()
1169 repeat(p, start+1, 1, to, reclimit); in repeat()
1187 copy = dupl(p, start+1, finish+1); in repeat()
1189 repeat(p, copy, 1, to-1, reclimit); in repeat()
1196 copy = dupl(p, start, finish); in repeat()
1197 repeat(p, copy, from-1, to-1, reclimit); in repeat()
1200 copy = dupl(p, start, finish); in repeat()
1201 repeat(p, copy, from-1, to, reclimit); in repeat()
1215 struct parse *p, in seterr() argument
1219 _DIAGASSERT(p != NULL); in seterr()
1221 if (p->error == 0) /* keep earliest error condition */ in seterr()
1222 p->error = e; in seterr()
1223 p->next = nuls; /* try to bring things to a halt */ in seterr()
1224 p->end = nuls; in seterr()
1234 struct parse *p) in allocset() argument
1244 _DIAGASSERT(p != NULL); in allocset()
1246 no = p->g->ncsets++; in allocset()
1247 css = (size_t)p->g->csetsize; in allocset()
1248 if (no >= p->ncsalloc) { /* need another column of space */ in allocset()
1249 p->ncsalloc += CHAR_BIT; in allocset()
1250 nc = p->ncsalloc; in allocset()
1253 if (MEMSIZE(p) > MEMLIMIT) in allocset()
1255 if (reallocarr(&p->g->sets, nc, sizeof(cset))) in allocset()
1257 old_ptr = p->g->setbits; in allocset()
1258 if (reallocarr(&p->g->setbits, nc / CHAR_BIT, css)) { in allocset()
1262 if (old_ptr != p->g->setbits) { in allocset()
1264 p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT); in allocset()
1266 (void) memset((char *)p->g->setbits + (nbytes - css), 0, css); in allocset()
1269 cs = &p->g->sets[no]; in allocset()
1270 cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); in allocset()
1290 struct parse *p, in freeset() argument
1297 _DIAGASSERT(p != NULL); in freeset()
1300 top = &p->g->sets[p->g->ncsets]; in freeset()
1301 css = (size_t)p->g->csetsize; in freeset()
1306 p->g->ncsets--; in freeset()
1321 struct parse *p, in freezeset() argument
1330 _DIAGASSERT(p != NULL); in freezeset()
1334 top = &p->g->sets[p->g->ncsets]; in freezeset()
1335 css = (size_t)p->g->csetsize; in freezeset()
1338 for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) in freezeset()
1349 freeset(p, cs); in freezeset()
1353 return (sopno)(cs - p->g->sets); in freezeset()
1362 struct parse *p, in firstch() argument
1368 _DIAGASSERT(p != NULL); in firstch()
1371 css = (size_t)p->g->csetsize; in firstch()
1386 struct parse *p, in nch() argument
1393 _DIAGASSERT(p != NULL); in nch()
1396 css = (size_t)p->g->csetsize; in nch()
1411 struct parse *p, in mcadd() argument
1417 _DIAGASSERT(p != NULL); in mcadd()
1496 char *p;
1503 for (p = cs->multis; *p != '\0'; p += strlen(p) + 1)
1504 if (strcmp(cp, p) == 0)
1505 return(p);
1520 struct parse *p, in mcinvert() argument
1524 _DIAGASSERT(p != NULL); in mcinvert()
1540 struct parse *p, in mccase() argument
1544 _DIAGASSERT(p != NULL); in mccase()
1609 struct parse *p, in categorize() argument
1617 _DIAGASSERT(p != NULL); in categorize()
1623 if (p->error != 0) in categorize()
1644 struct parse *p, in dupl() argument
1651 _DIAGASSERT(p != NULL); in dupl()
1658 if (!enlarge(p, p->ssize + len))/* this many unexpected additions */ in dupl()
1660 (void)memcpy(p->strip + p->slen, p->strip + start, in dupl()
1662 p->slen += len; in dupl()
1676 struct parse *p, in doemit() argument
1680 _DIAGASSERT(p != NULL); in doemit()
1683 if (p->error != 0) in doemit()
1690 if (p->slen >= p->ssize) in doemit()
1691 if (!enlarge(p, (p->ssize+1) / 2 * 3)) /* +50% */ in doemit()
1695 p->strip[p->slen++] = (sop)SOP(op, opnd); in doemit()
1704 struct parse *p, in doinsert() argument
1713 _DIAGASSERT(p != NULL); in doinsert()
1716 if (p->error != 0) in doinsert()
1722 s = p->strip[sn]; in doinsert()
1727 if (p->pbegin[i] >= pos) { in doinsert()
1728 p->pbegin[i]++; in doinsert()
1730 if (p->pend[i] >= pos) { in doinsert()
1731 p->pend[i]++; in doinsert()
1735 memmove(&p->strip[pos+1], &p->strip[pos], (HERE()-pos-1)*sizeof(sop)); in doinsert()
1736 p->strip[pos] = s; in doinsert()
1745 struct parse *p, in dofwd() argument
1750 _DIAGASSERT(p != NULL); in dofwd()
1753 if (p->error != 0) in dofwd()
1757 p->strip[pos] = (sop)(OP(p->strip[pos]) | value); in dofwd()
1765 enlarge(struct parse *p, sopno size) in enlarge() argument
1767 _DIAGASSERT(p != NULL); in enlarge()
1769 if (p->ssize >= size) in enlarge()
1772 if (MEMSIZE(p) > MEMLIMIT || reallocarr(&p->strip, size, sizeof(sop))) { in enlarge()
1776 p->ssize = size; in enlarge()
1786 struct parse *p, in stripsnug() argument
1790 _DIAGASSERT(p != NULL); in stripsnug()
1793 g->nstates = p->slen; in stripsnug()
1794 g->strip = p->strip; in stripsnug()
1795 reallocarr(&g->strip, p->slen, sizeof(sop)); in stripsnug()
1811 struct parse *p, in findmust() argument
1822 _DIAGASSERT(p != NULL); in findmust()
1826 if (p->error != 0) in findmust()
1898 struct parse *p, in pluscount() argument
1906 _DIAGASSERT(p != NULL); in pluscount()
1909 if (p->error != 0) in pluscount()