Lines Matching refs:p

43 #define	PEEK()	(*p->next)
44 #define PEEK2() (*(p->next+1))
45 #define MORE() (p->next < p->end)
46 #define MORE2() (p->next+1 < p->end)
51 #define NEXT() (p->next++)
52 #define NEXT2() (p->next += 2)
53 #define NEXTn(n) (p->next += (n))
54 #define GETNEXT() (*p->next++)
55 #define SETERROR(e) seterr(p, (e))
60 #define EMIT(op, sopnd) doemit(p, (sop)(op), (size_t)(sopnd))
61 #define INSERT(op, pos) doinsert(p, (sop)(op), HERE()-(pos)+1, pos)
62 #define AHEAD(pos) dofwd(p, pos, HERE()-(pos))
64 #define HERE() (p->slen)
65 #define THERE() (p->slen - 1)
66 #define THERETHERE() (p->slen - 2)
67 #define DROP(n) (p->slen -= (n))
95 register struct parse *p = &pa; variable
120 p->ssize = len/(size_t)2*(size_t)3 + (size_t)1; /* ugh */
121 p->strip = (sop *)malloc(p->ssize * sizeof(sop));
122 p->slen = 0;
123 if (p->strip == NULL) {
129 p->g = g;
130 p->next = (unsigned char *)pattern; /* convenience; we do not modify it */
131 p->end = p->next + len;
132 p->error = 0;
133 p->ncsalloc = 0;
135 p->pbegin[i] = 0;
136 p->pend[i] = 0;
158 p_ere(p, OUT);
160 p_str(p);
162 p_bre(p, OUT, OUT);
167 categorize(p, g);
168 stripsnug(p, g);
169 findmust(p, g);
170 g->nplus = pluscount(p, g);
182 if (p->error != 0) /* lose */
184 return(p->error);
192 p_ere(p, stop) in p_ere() argument
193 register struct parse *p; in p_ere()
206 p_ere_exp(p);
238 p_ere_exp(p) in p_ere_exp() argument
239 register struct parse *p; in p_ere_exp()
255 p->g->nsub++;
256 subno = p->g->nsub;
258 p->pbegin[subno] = HERE();
261 p_ere(p, ')');
263 p->pend[subno] = HERE();
264 assert(p->pend[subno] != 0);
283 p->g->iflags |= USEBOL;
284 p->g->nbol++;
289 p->g->iflags |= USEEOL;
290 p->g->neol++;
301 if (p->g->cflags&REG_NEWLINE)
302 nonnewline(p);
307 p_bracket(p);
312 ordinary(p, c);
318 ordinary(p, c);
354 count = p_count(p);
357 count2 = p_count(p);
363 repeat(p, pos, count, count2);
387 p_str(p) in p_str() argument
388 register struct parse *p; in p_str()
392 ordinary(p, GETNEXT());
408 p_bre(p, end1, end2) in p_bre() argument
409 register struct parse *p; in p_bre()
419 p->g->iflags |= USEBOL;
420 p->g->nbol++;
423 wasdollar = p_simp_re(p, first);
429 p->g->iflags |= USEEOL;
430 p->g->neol++;
441 p_simp_re(p, starordinary) in p_simp_re() argument
442 register struct parse *p; in p_simp_re()
463 if (p->g->cflags&REG_NEWLINE)
464 nonnewline(p);
469 p_bracket(p);
475 p->g->nsub++;
476 subno = p->g->nsub;
478 p->pbegin[subno] = HERE();
482 p_bre(p, '\\', ')');
484 p->pend[subno] = HERE();
485 assert(p->pend[subno] != 0);
505 if (p->pend[i] != 0) {
506 assert(i <= p->g->nsub);
508 assert(p->pbegin[i] != 0);
509 assert(OP(p->strip[p->pbegin[i]]) == OLPAREN);
510 assert(OP(p->strip[p->pend[i]]) == ORPAREN);
511 (void) dupl(p, p->pbegin[i]+1, p->pend[i]);
515 p->g->backrefs = 1;
521 ordinary(p, (unsigned char)c); /* takes off BACKSL, if any */
532 count = p_count(p);
535 count2 = p_count(p);
541 repeat(p, pos, count, count2);
559 p_count(p) in p_count() argument
560 register struct parse *p; in p_count()
582 p_bracket(p) in p_bracket() argument
583 register struct parse *p; in p_bracket()
585 register cset *cs = allocset(p);
589 if (p->next + 5 < p->end && strncmp(p->next, "[:<:]]", 6) == 0) {
594 if (p->next + 5 < p->end && strncmp(p->next, "[:>:]]", 6) == 0) {
607 p_b_term(p, cs);
612 if (p->error != 0) /* don't mess things up further */
615 if (p->g->cflags&REG_ICASE) {
619 for (i = p->g->csetsize - 1; i >= 0; i--)
626 mccase(p, cs);
631 for (i = p->g->csetsize - 1; i >= 0; i--)
636 if (p->g->cflags&REG_NEWLINE)
639 mcinvert(p, cs);
644 if (nch(p, cs) == 1) { /* optimize singleton sets */
645 ordinary(p, firstch(p, cs));
646 freeset(p, cs);
648 EMIT(OANYOF, freezeset(p, cs));
656 p_b_term(p, cs) in p_b_term() argument
657 register struct parse *p; in p_b_term()
684 p_b_cclass(p, cs);
693 p_b_eclass(p, cs);
699 start = p_b_symbol(p);
706 finish = p_b_symbol(p);
722 p_b_cclass(p, cs) in p_b_cclass() argument
723 register struct parse *p; in p_b_cclass()
726 register unsigned char *sp = p->next;
734 len = p->next - sp;
748 MCadd(p, cs, u);
758 p_b_eclass(p, cs) in p_b_eclass() argument
759 register struct parse *p; in p_b_eclass()
764 c = p_b_coll_elem(p, '=');
773 p_b_symbol(p) in p_b_symbol() argument
774 register struct parse *p; in p_b_symbol()
783 value = p_b_coll_elem(p, '.');
793 p_b_coll_elem(p, endc) in p_b_coll_elem() argument
794 register struct parse *p; in p_b_coll_elem()
797 register unsigned char *sp = p->next;
807 len = p->next - sp;
841 bothcases(p, ch) in bothcases() argument
842 register struct parse *p; in bothcases()
845 register unsigned char *oldnext = p->next;
846 register unsigned char *oldend = p->end;
850 p->next = bracket;
851 p->end = bracket+2;
855 p_bracket(p);
856 assert(p->next == bracket+2);
857 p->next = oldnext;
858 p->end = oldend;
866 ordinary(p, ch) in ordinary() argument
867 register struct parse *p; in ordinary()
870 register cat_t *cap = p->g->categories;
872 if ((p->g->cflags&REG_ICASE) && isalpha(ch) && othercase(ch) != ch)
873 bothcases(p, ch);
877 cap[ch] = p->g->ncategories++;
888 nonnewline(p) in nonnewline() argument
889 register struct parse *p; in nonnewline()
891 register unsigned char *oldnext = p->next;
892 register unsigned char *oldend = p->end;
895 p->next = bracket;
896 p->end = bracket+3;
901 p_bracket(p);
902 assert(p->next == bracket+3);
903 p->next = oldnext;
904 p->end = oldend;
912 repeat(p, start, from, to) in repeat() argument
913 register struct parse *p; in repeat()
925 if (p->error != 0) /* head off possible runaway recursion */
939 repeat(p, start+1, 1, to);
957 copy = dupl(p, start+1, finish+1);
959 repeat(p, copy, 1, to-1);
966 copy = dupl(p, start, finish);
967 repeat(p, copy, from-1, to-1);
970 copy = dupl(p, start, finish);
971 repeat(p, copy, from-1, to);
984 seterr(p, e) in seterr() argument
985 register struct parse *p; in seterr()
988 if (p->error == 0) /* keep earliest error condition */
989 p->error = e;
990 p->next = nuls; /* try to bring things to a halt */
991 p->end = nuls;
1000 allocset(p) in allocset() argument
1001 register struct parse *p; in allocset()
1003 register int no = p->g->ncsets++;
1007 register size_t css = (size_t)p->g->csetsize;
1010 if (no >= p->ncsalloc) { /* need another column of space */
1011 p->ncsalloc += CHAR_BIT;
1012 nc = p->ncsalloc;
1015 if (p->g->sets == NULL)
1016 p->g->sets = (cset *)malloc(nc * sizeof(cset));
1018 p->g->sets = (cset *)realloc((unsigned char *)p->g->sets,
1020 if (p->g->setbits == NULL)
1021 p->g->setbits = (uch *)malloc(nbytes);
1023 p->g->setbits = (uch *)realloc((unsigned char *)p->g->setbits,
1027 p->g->sets[i].ptr = p->g->setbits + css*(i/CHAR_BIT);
1029 if (p->g->sets != NULL && p->g->setbits != NULL)
1030 (void) memset((unsigned char *)p->g->setbits + (nbytes - css),
1039 assert(p->g->sets != NULL); /* xxx */
1040 cs = &p->g->sets[no];
1041 cs->ptr = p->g->setbits + css*((no)/CHAR_BIT);
1055 freeset(p, cs) in freeset() argument
1056 register struct parse *p; in freeset()
1060 register cset *top = &p->g->sets[p->g->ncsets];
1061 register size_t css = (size_t)p->g->csetsize;
1066 p->g->ncsets--;
1080 freezeset(p, cs) in freezeset() argument
1081 register struct parse *p; in freezeset()
1086 register cset *top = &p->g->sets[p->g->ncsets];
1088 register size_t css = (size_t)p->g->csetsize;
1091 for (cs2 = &p->g->sets[0]; cs2 < top; cs2++)
1102 freeset(p, cs);
1106 return((int)(cs - p->g->sets));
1114 firstch(p, cs) in firstch() argument
1115 register struct parse *p; in firstch()
1119 register size_t css = (size_t)p->g->csetsize;
1133 nch(p, cs) in nch() argument
1134 register struct parse *p; in nch()
1138 register size_t css = (size_t)p->g->csetsize;
1153 mcadd(p, cs, cp) in mcadd() argument
1154 register struct parse *p; in mcadd()
1224 register unsigned char *p;
1228 for (p = cs->multis; *p != '\0'; p += strlen(p) + 1)
1229 if (strcmp(cp, p) == 0)
1230 return(p);
1243 mcinvert(p, cs) in mcinvert() argument
1244 register struct parse *p; in mcinvert()
1258 mccase(p, cs) in mccase() argument
1259 register struct parse *p; in mccase()
1312 categorize(p, g) in categorize() argument
1313 struct parse *p; in categorize()
1322 if (p->error != 0)
1340 dupl(p, start, finish) in dupl() argument
1341 register struct parse *p; in dupl()
1351 enlarge(p, p->ssize + len); /* this many unexpected additions */
1352 assert(p->ssize >= p->slen + len);
1353 (void) memcpy((char *)(p->strip + p->slen),
1354 (char *)(p->strip + start), (size_t)len*sizeof(sop));
1355 p->slen += len;
1368 doemit(p, op, opnd) in doemit() argument
1369 register struct parse *p; in doemit()
1374 if (p->error != 0)
1381 if (p->slen >= p->ssize)
1382 enlarge(p, (p->ssize+1) / 2 * 3); /* +50% */
1383 assert(p->slen < p->ssize);
1386 p->strip[p->slen++] = SOP(op, opnd);
1394 doinsert(p, op, opnd, pos) in doinsert() argument
1395 register struct parse *p; in doinsert()
1405 if (p->error != 0)
1411 s = p->strip[sn];
1416 if (p->pbegin[i] >= pos) {
1417 p->pbegin[i]++;
1419 if (p->pend[i] >= pos) {
1420 p->pend[i]++;
1424 memmove((char *)&p->strip[pos+1], (char *)&p->strip[pos],
1426 p->strip[pos] = s;
1434 dofwd(p, pos, value) in dofwd() argument
1435 register struct parse *p; in dofwd()
1440 if (p->error != 0)
1444 p->strip[pos] = OP(p->strip[pos]) | value;
1452 enlarge(p, size) in enlarge() argument
1453 register struct parse *p; in enlarge()
1458 if (p->ssize >= size)
1461 sp = (sop *)realloc(p->strip, size*sizeof(sop));
1466 p->strip = sp;
1467 p->ssize = size;
1475 stripsnug(p, g) in stripsnug() argument
1476 register struct parse *p; in stripsnug()
1479 g->nstates = p->slen;
1480 g->strip = (sop *)realloc((unsigned char *)p->strip, p->slen * sizeof(sop));
1483 g->strip = p->strip;
1498 findmust(p, g) in findmust() argument
1499 struct parse *p; in findmust()
1511 if (p->error != 0)
1584 pluscount(p, g) in pluscount() argument
1585 struct parse *p; in pluscount()
1593 if (p->error != 0)