Ejemplo n.º 1
0
fa *mkdfa(const char *s, int anchor)	/* does the real work of making a dfa */
/* anchor = 1 for anchored matches, else 0 */
{
    Node *p, *p1;
    fa *f;

    p = reparse(s);
    p1 = op2(CAT, op2(STAR, op2(ALL, NIL, NIL), NIL), p);
    /* put ALL STAR in front of reg.  exp. */
    p1 = op2(CAT, p1, op2(FINAL, NIL, NIL));
    /* put FINAL after reg.  exp. */

    poscnt = 0;
    penter(p1);	/* enter parent pointers and leaf indices */
    if ((f = (fa *) calloc(1, sizeof(fa) + poscnt*sizeof(rrow))) == NULL)
        overflo("out of space for fa");
    f->accept = poscnt-1;	/* penter has computed number of positions in re */
    cfoll(f, p1);	/* set up follow sets */
    freetr(p1);
    if ((f->posns[0] = (int *) calloc(1, *(f->re[0].lfollow)*sizeof(int))) == NULL)
        overflo("out of space in makedfa");
    if ((f->posns[1] = (int *) calloc(1, sizeof(int))) == NULL)
        overflo("out of space in makedfa");
    *f->posns[1] = 0;
    f->initstat = makeinit(f, anchor);
    f->anchor = anchor;
    f->restr = (uschar *) tostring(s);
    return f;
}
Ejemplo n.º 2
0
void penter(Node *p)	/* set up parent pointers and leaf indices */
{
	switch (type(p)) {
	LEAF
		info(p) = poscnt;
		poscnt++;
		break;
	UNARY
		penter(left(p));
		parent(left(p)) = p;
		break;
	case CAT:
	case OR:
		penter(left(p));
		penter(right(p));
		parent(left(p)) = p;
		parent(right(p)) = p;
		break;
	default:	/* can't happen */
		ERROR "can't happen: unknown type %d in penter", type(p) FATAL;
		break;
	}
}