예제 #1
0
파일: jsregexp.c 프로젝트: RareHare/reactos
HRESULT create_regexp(script_ctx_t *ctx, jsstr_t *src, DWORD flags, jsdisp_t **ret)
{
    RegExpInstance *regexp;
    HRESULT hres;

    TRACE("%s %x\n", debugstr_jsstr(src), flags);

    hres = alloc_regexp(ctx, NULL, &regexp);
    if(FAILED(hres))
        return hres;

    regexp->str = jsstr_addref(src);
    regexp->last_index_val = jsval_number(0);

    regexp->jsregexp = regexp_new(ctx, &ctx->tmp_heap, regexp->str->str,
            jsstr_length(regexp->str), flags, FALSE);
    if(FAILED(hres)) {
        WARN("regexp_new failed\n");
        jsdisp_release(&regexp->dispex);
        return E_FAIL;
    }

    *ret = &regexp->dispex;
    return S_OK;
}
예제 #2
0
파일: vbregexp.c 프로젝트: Dimillian/wine
static HRESULT WINAPI RegExp2_Test(IRegExp2 *iface, BSTR sourceString, VARIANT_BOOL *pMatch)
{
    RegExp2 *This = impl_from_IRegExp2(iface);
    match_state_t *result;
    heap_pool_t *mark;
    HRESULT hres;

    TRACE("(%p)->(%s %p)\n", This, debugstr_w(sourceString), pMatch);

    if(!This->pattern) {
        *pMatch = VARIANT_TRUE;
        return S_OK;
    }

    if(!This->regexp) {
        This->regexp = regexp_new(NULL, &This->pool, This->pattern,
                strlenW(This->pattern), This->flags, FALSE);
        if(!This->regexp)
            return E_FAIL;
    }else {
        hres = regexp_set_flags(&This->regexp, NULL, &This->pool, This->flags);
        if(FAILED(hres))
            return hres;
    }

    mark = heap_pool_mark(&This->pool);
    result = alloc_match_state(This->regexp, &This->pool, sourceString);
    if(!result) {
        heap_pool_clear(mark);
        return E_OUTOFMEMORY;
    }

    hres = regexp_execute(This->regexp, NULL, &This->pool,
            sourceString, SysStringLen(sourceString), result);

    heap_pool_clear(mark);

    if(hres == S_OK) {
        *pMatch = VARIANT_TRUE;
    }else if(hres == S_FALSE) {
        *pMatch = VARIANT_FALSE;
        hres = S_OK;
    }
    return hres;
}
예제 #3
0
파일: temuterm.c 프로젝트: sfraize/TemuTerm
void
temu_parse_config (terms_t *terms)
{
	struct regexp *bind_action = regexp_new("^bind:[ \t]+([a-zA-Z_]+)[ \t]+([0-9]+)[ \t]+([a-zA-Z0-9_]+)$", 0);
	struct regexp *bind_switch = regexp_new("^bind:[ \t]+([0-9]+)[ \t]+([0-9]+)[ \t]+([a-zA-Z0-9_]+)(-([a-zA-Z0-9_]+))?([ \t]+(.*?))?$", 0);
	struct regexp *color = regexp_new("^color:[ \t]+([0-9]+)[ \t]+(.*?)$", 0);
	struct regexp *font = regexp_new("^font:[ \t]+(.*?)$", 0);
	struct regexp *size = regexp_new("^size:[ \t]+([0-9]+)x([0-9]+)$", 0);
	struct regexp_iterator *iterator = NULL;
	char **subs = NULL;
	FILE *f;
	char *file = NULL;
	long f_len;
	int j;
	char *t1, *t2;
	char conffile[512] = { 0 };

	if (!bind_action || !bind_switch || !color || !font || !size) {
		printf("Unable to compile regexp for config file parsing!\n");
		goto done;
	}

	snprintf(conffile, sizeof(conffile) - 1, "%s/.temuterm/config", getenv("HOME"));
	f = fopen(conffile, "r");
	if (!f)
		goto done;
	fseek(f, 0, SEEK_END);
	f_len = ftell(f);
	fseek(f, 0, SEEK_SET);
	file = calloc (1, f_len + 1);
	fread (file, f_len, 1, f);
	fclose(f);

	t1 = file;
	while (*t1) {
		t2 = strchr (t1, '\n');
		*t2++ = '\0';

		j = t1[0] == '#' ? 1 : 0;

		if (!j) {
			j = regexp_find_first_str (t1, &subs, bind_action, &iterator);
			if (j)
				temu_parse_bind_action (terms, subs);
			regexp_find_free (&subs, bind_action, &iterator);
		}

		if (!j) {
			j = regexp_find_first_str (t1, &subs, bind_switch, &iterator);
			if (j)
				temu_parse_bind_switch (terms, subs, BIND_ACT_SWITCH);
			regexp_find_free (&subs, bind_switch, &iterator);
		}

		if (!j) {
			j = regexp_find_first_str (t1, &subs, color, &iterator);
			if (j)
				temu_parse_color (terms, subs);
			regexp_find_free (&subs, color, &iterator);
		}

		if (!j) {
			j = regexp_find_first_str (t1, &subs, font, &iterator);
			if (j)
				temu_parse_font (terms, subs);
			regexp_find_free (&subs, font, &iterator);
		}

		if (!j) {
			j = regexp_find_first_str (t1, &subs, size, &iterator);
			if (j)
				temu_parse_size (terms, subs);
			regexp_find_free (&subs, size, &iterator);
		}

		if (!j)
			fprintf (stderr, "Unable to parse line in config: '%s'\n", t1);

		t1 = t2;
	}

done:
	if (bind_action) 
		regexp_free (bind_action);
	if (bind_switch)
		regexp_free (bind_switch);
	if (color)
		regexp_free (color);
	if (font)
		regexp_free (font);
	if (size)
		regexp_free (size);
	if (file)
		free (file);

	return;
}
예제 #4
0
파일: vbregexp.c 프로젝트: Dimillian/wine
static HRESULT WINAPI RegExp2_Execute(IRegExp2 *iface,
        BSTR sourceString, IDispatch **ppMatches)
{
    RegExp2 *This = impl_from_IRegExp2(iface);
    match_state_t *result;
    const WCHAR *pos;
    IMatchCollection2 *match_collection;
    IMatch2 *add = NULL;
    HRESULT hres;

    TRACE("(%p)->(%s %p)\n", This, debugstr_w(sourceString), ppMatches);

    if(!This->pattern) {
        DWORD i, len = SysStringLen(sourceString);

        hres = create_match_collection2(&match_collection);
        if(FAILED(hres))
            return hres;

        for(i=0; i<=len; i++) {
            hres = create_match2(i, NULL, &add);
            if(FAILED(hres))
                break;

            hres = add_match(match_collection, add);
            if(FAILED(hres))
                break;
            IMatch2_Release(add);

            if(!(This->flags & REG_GLOB))
                break;
        }

        if(FAILED(hres)) {
            IMatchCollection2_Release(match_collection);
            return hres;
        }

        *ppMatches = (IDispatch*)match_collection;
        return S_OK;
    }

    if(!This->regexp) {
        This->regexp = regexp_new(NULL, &This->pool, This->pattern,
                strlenW(This->pattern), This->flags, FALSE);
        if(!This->regexp)
            return E_FAIL;
    }else {
        hres = regexp_set_flags(&This->regexp, NULL, &This->pool, This->flags);
        if(FAILED(hres))
            return hres;
    }

    hres = create_match_collection2(&match_collection);
    if(FAILED(hres))
        return hres;

    pos = sourceString;
    while(1) {
        result = alloc_match_state(This->regexp, NULL, pos);
        if(!result) {
            hres = E_OUTOFMEMORY;
            break;
        }

        hres = regexp_execute(This->regexp, NULL, &This->pool,
                sourceString, SysStringLen(sourceString), result);
        if(hres != S_OK) {
            heap_free(result);
            break;
        }
        pos = result->cp;

        hres = create_match2(result->cp-result->match_len-sourceString, &result, &add);
        heap_free(result);
        if(FAILED(hres))
            break;
        hres = add_match(match_collection, add);
        IMatch2_Release(add);
        if(FAILED(hres))
            break;

        if(!(This->flags & REG_GLOB))
            break;
    }

    if(FAILED(hres)) {
        IMatchCollection2_Release(match_collection);
        return hres;
    }

    *ppMatches = (IDispatch*)match_collection;
    return S_OK;
}