Lines Matching refs:p
113 #define PEEK() (*p->next)
114 #define PEEK2() (*(p->next+1))
115 #define MORE() (p->next < p->end)
116 #define MORE2() (p->next+1 < p->end)
121 #define NEXT() (p->next++)
122 #define NEXT2() (p->next += 2)
123 #define NEXTn(n) (p->next += (n))
124 #define GETNEXT() (*p->next++)
125 #define SETERROR(e) seterr(p, (e))
130 #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
131 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
132 #define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
134 #define HERE() (p->slen)
135 #define THERE() (p->slen - 1)
136 #define THERETHERE() (p->slen - 2)
137 #define DROP(n) (p->slen -= (n))
153 struct parse *p = &pa; in regcomp() local
178 p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */ in regcomp()
179 p->strip = (sop *)calloc(p->ssize, sizeof(sop)); in regcomp()
180 p->slen = 0; in regcomp()
181 if (p->strip == NULL) { in regcomp()
187 p->g = g; in regcomp()
188 p->next = (char *)pattern; /* convenience; we do not modify it */ in regcomp()
189 p->end = p->next + len; in regcomp()
190 p->error = 0; in regcomp()
191 p->ncsalloc = 0; in regcomp()
193 p->pbegin[i] = 0; in regcomp()
194 p->pend[i] = 0; in regcomp()
216 p_ere(p, OUT); in regcomp()
218 p_str(p); in regcomp()
220 p_bre(p, OUT, OUT); in regcomp()
225 categorize(p, g); in regcomp()
226 stripsnug(p, g); in regcomp()
227 findmust(p, g); in regcomp()
228 g->nplus = pluscount(p, g); in regcomp()
240 if (p->error != 0) /* lose */ in regcomp()
242 return(p->error); in regcomp()
249 p_ere(struct parse *p, int stop) /* character this ERE should end at */ in p_ere() argument
261 p_ere_exp(p); in p_ere()
292 p_ere_exp(struct parse *p) in p_ere_exp() argument
308 p->g->nsub++; in p_ere_exp()
309 subno = p->g->nsub; in p_ere_exp()
311 p->pbegin[subno] = HERE(); in p_ere_exp()
314 p_ere(p, ')'); in p_ere_exp()
316 p->pend[subno] = HERE(); in p_ere_exp()
317 assert(p->pend[subno] != 0); in p_ere_exp()
336 p->g->iflags |= USEBOL; in p_ere_exp()
337 p->g->nbol++; in p_ere_exp()
342 p->g->iflags |= USEEOL; in p_ere_exp()
343 p->g->neol++; in p_ere_exp()
354 if (p->g->cflags®_NEWLINE) in p_ere_exp()
355 nonnewline(p); in p_ere_exp()
360 p_bracket(p); in p_ere_exp()
365 ordinary(p, c); in p_ere_exp()
371 ordinary(p, c); in p_ere_exp()
407 count = p_count(p); in p_ere_exp()
410 count2 = p_count(p); in p_ere_exp()
416 repeat(p, pos, count, count2); in p_ere_exp()
439 p_str(struct parse *p) in p_str() argument
443 ordinary(p, GETNEXT()); in p_str()
457 p_bre(struct parse *p, in p_bre() argument
467 p->g->iflags |= USEBOL; in p_bre()
468 p->g->nbol++; in p_bre()
471 wasdollar = p_simp_re(p, first); in p_bre()
477 p->g->iflags |= USEEOL; in p_bre()
478 p->g->neol++; in p_bre()
488 p_simp_re(struct parse *p, in p_simp_re() argument
509 if (p->g->cflags®_NEWLINE) in p_simp_re()
510 nonnewline(p); in p_simp_re()
515 p_bracket(p); in p_simp_re()
521 p->g->nsub++; in p_simp_re()
522 subno = p->g->nsub; in p_simp_re()
524 p->pbegin[subno] = HERE(); in p_simp_re()
528 p_bre(p, '\\', ')'); in p_simp_re()
530 p->pend[subno] = HERE(); in p_simp_re()
531 assert(p->pend[subno] != 0); in p_simp_re()
551 if (p->pend[i] != 0) { in p_simp_re()
552 assert(i <= p->g->nsub); in p_simp_re()
554 assert(p->pbegin[i] != 0); in p_simp_re()
555 assert(OP(p->strip[p->pbegin[i]]) == OLPAREN); in p_simp_re()
556 assert(OP(p->strip[p->pend[i]]) == ORPAREN); in p_simp_re()
557 (void) dupl(p, p->pbegin[i]+1, p->pend[i]); in p_simp_re()
561 p->g->backrefs = 1; in p_simp_re()
567 ordinary(p, (char)c); in p_simp_re()
578 count = p_count(p); in p_simp_re()
581 count2 = p_count(p); in p_simp_re()
587 repeat(p, pos, count, count2); in p_simp_re()
604 p_count(struct parse *p) in p_count() argument
625 p_bracket(struct parse *p) in p_bracket() argument
631 if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) { in p_bracket()
636 if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) { in p_bracket()
642 if ((cs = allocset(p)) == NULL) { in p_bracket()
654 p_b_term(p, cs); in p_bracket()
659 if (p->error != 0) { /* don't mess things up further */ in p_bracket()
660 freeset(p, cs); in p_bracket()
664 if (p->g->cflags®_ICASE) { in p_bracket()
668 for (i = p->g->csetsize - 1; i >= 0; i--) in p_bracket()
675 mccase(p, cs); in p_bracket()
680 for (i = p->g->csetsize - 1; i >= 0; i--) in p_bracket()
685 if (p->g->cflags®_NEWLINE) in p_bracket()
688 mcinvert(p, cs); in p_bracket()
693 if (nch(p, cs) == 1) { /* optimize singleton sets */ in p_bracket()
694 ordinary(p, firstch(p, cs)); in p_bracket()
695 freeset(p, cs); in p_bracket()
697 EMIT(OANYOF, freezeset(p, cs)); in p_bracket()
704 p_b_term(struct parse *p, cset *cs) in p_b_term() argument
730 p_b_cclass(p, cs); in p_b_term()
739 p_b_eclass(p, cs); in p_b_term()
745 start = p_b_symbol(p); in p_b_term()
752 finish = p_b_symbol(p); in p_b_term()
767 p_b_cclass(struct parse *p, cset *cs) in p_b_cclass() argument
769 char *sp = p->next; in p_b_cclass()
777 len = p->next - sp; in p_b_cclass()
791 MCadd(p, cs, u); in p_b_cclass()
800 p_b_eclass(struct parse *p, cset *cs) in p_b_eclass() argument
804 c = p_b_coll_elem(p, '='); in p_b_eclass()
812 p_b_symbol(struct parse *p) in p_b_symbol() argument
821 value = p_b_coll_elem(p, '.'); in p_b_symbol()
830 p_b_coll_elem(struct parse *p, in p_b_coll_elem() argument
833 char *sp = p->next; in p_b_coll_elem()
843 len = p->next - sp; in p_b_coll_elem()
875 bothcases(struct parse *p, int ch) in bothcases() argument
877 char *oldnext = p->next; in bothcases()
878 char *oldend = p->end; in bothcases()
883 p->next = bracket; in bothcases()
884 p->end = bracket+2; in bothcases()
888 p_bracket(p); in bothcases()
889 assert(p->next == bracket+2); in bothcases()
890 p->next = oldnext; in bothcases()
891 p->end = oldend; in bothcases()
898 ordinary(struct parse *p, int ch) in ordinary() argument
900 cat_t *cap = p->g->categories; in ordinary()
902 if ((p->g->cflags®_ICASE) && isalpha((uch)ch) && othercase(ch) != ch) in ordinary()
903 bothcases(p, ch); in ordinary()
907 cap[ch] = p->g->ncategories++; in ordinary()
917 nonnewline(struct parse *p) in nonnewline() argument
919 char *oldnext = p->next; in nonnewline()
920 char *oldend = p->end; in nonnewline()
923 p->next = bracket; in nonnewline()
924 p->end = bracket+3; in nonnewline()
929 p_bracket(p); in nonnewline()
930 assert(p->next == bracket+3); in nonnewline()
931 p->next = oldnext; in nonnewline()
932 p->end = oldend; in nonnewline()
939 repeat(struct parse *p, in repeat() argument
951 if (p->error != 0) /* head off possible runaway recursion */ in repeat()
965 repeat(p, start+1, 1, to); in repeat()
983 copy = dupl(p, start+1, finish+1); in repeat()
985 repeat(p, copy, 1, to-1); in repeat()
992 copy = dupl(p, start, finish); in repeat()
993 repeat(p, copy, from-1, to-1); in repeat()
996 copy = dupl(p, start, finish); in repeat()
997 repeat(p, copy, from-1, to); in repeat()
1009 seterr(struct parse *p, int e) in seterr() argument
1011 if (p->error == 0) /* keep earliest error condition */ in seterr()
1012 p->error = e; in seterr()
1013 p->next = nuls; /* try to bring things to a halt */ in seterr()
1014 p->end = nuls; in seterr()
1022 allocset(struct parse *p) in allocset() argument
1024 int no = p->g->ncsets++; in allocset()
1028 size_t css = (size_t)p->g->csetsize; in allocset()
1031 if (no >= p->ncsalloc) { /* need another column of space */ in allocset()
1034 p->ncsalloc += CHAR_BIT; in allocset()
1035 nc = p->ncsalloc; in allocset()
1039 ptr = (cset *)realloc((char *)p->g->sets, nc * sizeof(cset)); in allocset()
1042 p->g->sets = ptr; in allocset()
1044 ptr = (uch *)realloc((char *)p->g->setbits, nbytes); in allocset()
1047 p->g->setbits = ptr; in allocset()
1050 p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT); in allocset()
1052 (void) memset((char *)p->g->setbits + (nbytes - css), 0, css); in allocset()
1055 if (p->g->sets == NULL || p->g->setbits == NULL) in allocset()
1058 cs = &p->g->sets[no]; in allocset()
1059 cs->ptr = p->g->setbits + css*((no)/CHAR_BIT); in allocset()
1067 free(p->g->sets); in allocset()
1068 p->g->sets = NULL; in allocset()
1069 free(p->g->setbits); in allocset()
1070 p->g->setbits = NULL; in allocset()
1081 freeset(struct parse *p, cset *cs) in freeset() argument
1084 cset *top = &p->g->sets[p->g->ncsets]; in freeset()
1085 size_t css = (size_t)p->g->csetsize; in freeset()
1090 p->g->ncsets--; in freeset()
1103 freezeset(struct parse *p, cset *cs) in freezeset() argument
1107 cset *top = &p->g->sets[p->g->ncsets]; in freezeset()
1109 size_t css = (size_t)p->g->csetsize; in freezeset()
1112 for (cs2 = &p->g->sets[0]; cs2 < top; cs2++) in freezeset()
1123 freeset(p, cs); in freezeset()
1127 return((int)(cs - p->g->sets)); in freezeset()
1134 firstch(struct parse *p, cset *cs) in firstch() argument
1137 size_t css = (size_t)p->g->csetsize; in firstch()
1150 nch(struct parse *p, cset *cs) in nch() argument
1153 size_t css = (size_t)p->g->csetsize; in nch()
1166 mcadd( struct parse *p, cset *cs, char *cp) in mcadd() argument
1193 mcinvert(struct parse *p, cset *cs) in mcinvert() argument
1206 mccase(struct parse *p, cset *cs) in mccase() argument
1250 categorize(struct parse *p, struct re_guts *g) in categorize() argument
1258 if (p->error != 0) in categorize()
1275 dupl(struct parse *p, in dupl() argument
1285 enlarge(p, p->ssize + len); /* this many unexpected additions */ in dupl()
1286 assert(p->ssize >= p->slen + len); in dupl()
1287 (void) memcpy((char *)(p->strip + p->slen), in dupl()
1288 (char *)(p->strip + start), (size_t)len*sizeof(sop)); in dupl()
1289 p->slen += len; in dupl()
1301 doemit(struct parse *p, sop op, size_t opnd) in doemit() argument
1304 if (p->error != 0) in doemit()
1311 if (p->slen >= p->ssize) in doemit()
1312 enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */ in doemit()
1313 assert(p->slen < p->ssize); in doemit()
1316 p->strip[p->slen++] = SOP(op, opnd); in doemit()
1323 doinsert(struct parse *p, sop op, size_t opnd, sopno pos) in doinsert() argument
1330 if (p->error != 0) in doinsert()
1336 s = p->strip[sn]; in doinsert()
1341 if (p->pbegin[i] >= pos) { in doinsert()
1342 p->pbegin[i]++; in doinsert()
1344 if (p->pend[i] >= pos) { in doinsert()
1345 p->pend[i]++; in doinsert()
1349 memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos], in doinsert()
1351 p->strip[pos] = s; in doinsert()
1358 dofwd(struct parse *p, sopno pos, sop value) in dofwd() argument
1361 if (p->error != 0) in dofwd()
1365 p->strip[pos] = OP(p->strip[pos]) | value; in dofwd()
1372 enlarge(struct parse *p, sopno size) in enlarge() argument
1376 if (p->ssize >= size) in enlarge()
1379 sp = (sop *)realloc(p->strip, size*sizeof(sop)); in enlarge()
1384 p->strip = sp; in enlarge()
1385 p->ssize = size; in enlarge()
1392 stripsnug(struct parse *p, struct re_guts *g) in stripsnug() argument
1394 g->nstates = p->slen; in stripsnug()
1395 g->strip = (sop *)realloc((char *)p->strip, p->slen * sizeof(sop)); in stripsnug()
1398 g->strip = p->strip; in stripsnug()
1412 findmust(struct parse *p, struct re_guts *g) in findmust() argument
1423 if (p->error != 0) in findmust()
1490 pluscount(struct parse *p, struct re_guts *g) in pluscount() argument
1497 if (p->error != 0) in pluscount()