Esempio n. 1
0
void
rexp_leaks(void)
{
    TRACE(("rexp_leaks\n"));
#ifdef LOCAL_REGEXP
    lookup_cclass(0);
    if (bv_base) {
	BV **p = bv_base;
	while (p != bv_next) {
	    RE_free(*p);
	    ++p;
	}
	RE_free(bv_base);
	bv_base = 0;
	bv_limit = 0;
	bv_next = 0;
    }
    if (RE_run_stack_base) {
	RE_free(RE_run_stack_base);
	RE_run_stack_base = 0;
    }
    if (RE_pos_stack_base) {
	RE_free(RE_pos_stack_base);
	RE_pos_stack_base = 0;
    }
#endif
}
Esempio n. 2
0
void
REdestroy(PTR ptr)
{
    int done = 0;
    int n = 0;
    STATE *q = (STATE *) ptr;

    TRACE(("REdestroy %p\n", ptr));
    while (!done) {
	TRACE(("...%d type %d\n", n, q->s_type));
	switch (q->s_type) {
	case M_ACCEPT:
	    done = 1;
	    break;
	case M_STR:
	    RE_free(q->s_data.str);
	    break;
	default:
	    if (q->s_type < 0 || q->s_type > END_ON)
		done = -1;
	    break;
	}
	++q;
	++n;
    }
    RE_free(ptr);
}
Esempio n. 3
0
void
RE_close(MACHINE * mp)
{
    register STATE *p;
    unsigned sz;

    sz = (unsigned) (mp->stop - mp->start + 1);

    if (!subre_accepts_empty(mp)) {
	/*
	 *          2JA end
	 * loop:
	 *          m
	 *          2JB loop
	 * end:
	 *          ACCEPT
	 */
	p = (STATE *) RE_malloc((sz + 2) * STATESZ);
	memcpy(p + 1, mp->start, sz * STATESZ);
	RE_free(mp->start);
	mp->start = p;
	mp->stop = p + (sz + 1);
	p->s_type = M_2JA;
	p->s_data.jump = (int) (sz + 1);
	(p += sz)->s_type = M_2JB;
	p->s_data.jump = -(int) (sz - 1);
	p->s_data.jump |= !(p->s_data.jump);
	(p + 1)->s_type = M_ACCEPT;
	return;
    }
    /*
     *          2JA end
     * loop:
     *          SAVE_POS
     *          m
     *          2JC loop
     * end:
     *          ACCEPT
     */
    p = (STATE *) RE_malloc((sz + 3) * STATESZ);
    memcpy(p + 2, mp->start, sz * STATESZ);
    RE_free(mp->start);
    mp->start = p;
    mp->stop = p + (sz + 2);
    p->s_type = M_2JA;
    p->s_data.jump = (int) (sz + 2);
    (++p)->s_type = M_SAVE_POS;
    (p += sz)->s_type = M_2JC;
    p->s_data.jump = -(int) sz;
    (p + 1)->s_type = M_ACCEPT;
}
Esempio n. 4
0
void
RE_poscl(MACHINE * mp)
{
    register STATE *p;
    unsigned sz;

    /*
     * loop:
     *          SAVE_POS
     *          m
     *          2JC loop
     *          ACCEPT
     */
    sz = (unsigned) (mp->stop - mp->start + 1);
    p = (STATE *) RE_malloc((sz + 2) * STATESZ);
    memcpy(p + 1, mp->start, sz * STATESZ);
    RE_free(mp->start);
    mp->start = p;
    mp->stop = p + (sz + 1);
    p++->s_type = M_SAVE_POS;
    p += sz - 1;
    p->s_type = M_2JC;
    p->limit = INT_MAX;
    p->s_data.jump = -((int) sz);
    (p + 1)->s_type = M_ACCEPT;
}
Esempio n. 5
0
void
RE_close(MACHINE * mp)
{
    register STATE *p;
    unsigned sz;

    /*
     *          2JA end
     * loop:
     *          SAVE_POS
     *          m
     *          2JC loop
     * end:
     *          ACCEPT
     */
    sz = (unsigned) (mp->stop - mp->start + 1);
    p = (STATE *) RE_malloc((sz + 3) * STATESZ);
    memcpy(p + 2, mp->start, sz * STATESZ);
    RE_free(mp->start);
    mp->start = p;
    mp->stop = p + (sz + 2);
    p->s_type = M_2JA;
    p->s_data.jump = (int) (sz + 2);
    (++p)->s_type = M_SAVE_POS;
    (p += sz)->s_type = M_2JC;
    p->limit = INT_MAX;
    p->s_data.jump = -(int) sz;
    (p + 1)->s_type = M_ACCEPT;
}
Esempio n. 6
0
void
RE_or(MACHINE * mp, MACHINE * np)
{
    register STATE *p;
    unsigned szm, szn;

    szm = (unsigned) (mp->stop - mp->start + 1);
    szn = (unsigned) (np->stop - np->start + 1);

    p = (STATE *) RE_malloc((szm + szn + 1) * STATESZ);
    memcpy(p + 1, mp->start, szm * STATESZ);
    RE_free(mp->start);
    mp->start = p;
    (mp->stop = p + szm + szn)->s_type = M_ACCEPT;
    p->s_type = M_2JA;
    p->s_data.jump = (int) (szm + 1);
    memcpy(p + szm + 1, np->start, szn * STATESZ);
    RE_free(np->start);
    (p += szm)->s_type = M_1J;
    p->s_data.jump = (int) szn;
}
Esempio n. 7
0
/*  replace m and n by a machine that recognizes  mn   */
void
RE_cat(MACHINE * mp, MACHINE * np)
{
    unsigned sz1, sz2, sz;

    sz1 = (unsigned) (mp->stop - mp->start);
    sz2 = (unsigned) (np->stop - np->start + 1);
    sz = sz1 + sz2;

    mp->start = (STATE *) RE_realloc(mp->start, sz * STATESZ);
    mp->stop = mp->start + (sz - 1);
    memcpy(mp->start + sz1, np->start, sz2 * STATESZ);
    RE_free(np->start);
}
Esempio n. 8
0
void
RE_01(MACHINE * mp)
{
    unsigned sz;
    register STATE *p;

    sz = (unsigned) (mp->stop - mp->start + 1);
    p = (STATE *) RE_malloc((sz + 1) * STATESZ);
    memcpy(p + 1, mp->start, sz * STATESZ);
    RE_free(mp->start);
    mp->start = p;
    mp->stop = p + sz;
    p->s_type = M_2JB;
    p->s_data.jump = (int) sz;
}
Esempio n. 9
0
void
RE_poscl(MACHINE * mp)
{
    register STATE *p;
    unsigned sz;

    sz = (unsigned) (mp->stop - mp->start + 1);

    if (!subre_accepts_empty(mp)) {
	/*
	 * loop:
	 *          m
	 *          2JB loop
	 * end:
	 *          ACCEPT
	 */
	mp->start = p = (STATE *) RE_realloc(mp->start, (sz + 1) * STATESZ);
	mp->stop = p + sz;
	p += --sz;
	p->s_type = M_2JB;
	p->s_data.jump = -sz;
	p->s_data.jump |= !(p->s_data.jump);
	(p + 1)->s_type = M_ACCEPT;
	return;
    }

    /*
     * loop:
     *          SAVE_POS
     *          m
     *          2JC loop
     *          ACCEPT
     */
    p = (STATE *) RE_malloc((sz + 2) * STATESZ);
    memcpy(p + 1, mp->start, sz * STATESZ);
    RE_free(mp->start);
    mp->start = p;
    mp->stop = p + (sz + 1);
    p++->s_type = M_SAVE_POS;
    p += sz - 1;
    p->s_type = M_2JC;
    p->s_data.jump = -((int) sz);
    (p + 1)->s_type = M_ACCEPT;
}
Esempio n. 10
0
void
RE_01(MACHINE * mp)
{
    unsigned sz;
    register STATE *p;

    /* 
     *          2JB end (jump desirable if not found) 
     *          m
     * end:
     *          ACCEPT
     */
    sz = (unsigned) (mp->stop - mp->start + 1);
    p = (STATE *) RE_malloc((sz + 1) * STATESZ);
    memcpy(p + 1, mp->start, sz * STATESZ);
    RE_free(mp->start);
    mp->start = p;
    mp->stop = p + sz;
    p->s_type = M_2JB;
    p->s_data.jump = (int) sz;
}