Ejemplo n.º 1
0
void convert_sampler_info(struct gs_sampler_state *sampler,
		struct gs_sampler_info *info)
{
	GLint max_anisotropy_max;
	convert_filter(info->filter, &sampler->min_filter,
			&sampler->mag_filter);
	sampler->address_u      = convert_address_mode(info->address_u);
	sampler->address_v      = convert_address_mode(info->address_v);
	sampler->address_w      = convert_address_mode(info->address_w);
	sampler->max_anisotropy = info->max_anisotropy;

	max_anisotropy_max = 1;
	glGetIntegerv(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT, &max_anisotropy_max);
	gl_success("glGetIntegerv(GL_MAX_TEXTURE_ANISOTROPY_MAX)");

	if (1 <= sampler->max_anisotropy &&
	    sampler->max_anisotropy <= max_anisotropy_max)
		return;

	if (sampler->max_anisotropy < 1)
		sampler->max_anisotropy = 1;
	else if (sampler->max_anisotropy > max_anisotropy_max)
		sampler->max_anisotropy = max_anisotropy_max;

	blog(LOG_INFO, "convert_sampler_info: 1 <= max_anisotropy <= "
	               "%d violated, selected: %d, set: %d",
	               max_anisotropy_max,
	               info->max_anisotropy, sampler->max_anisotropy);
}
Ejemplo n.º 2
0
item_location game::get_item_from_inventory( player &p, const std::string &title )
{
    const std::string msg = p.is_npc() ? string_format( _( "%s's inventory is empty." ),
                            p.name.c_str() ) :
                            std::string( _( "Your inventory is empty." ) );

    return inv_internal( p,
    inventory_filter_preset( convert_filter( [ &p ]( const item & it ) {
        return !p.is_worn( it ) && &p.weapon != &it;
    } ) ), title, -1, msg );
}
Ejemplo n.º 3
0
int gen_lua_func(char *name, char *filter, char **content)
{
    char *converted = (char*)calloc(2 * strlen(filter), 1);
    if (convert_filter(converted, filter, 2 * strlen(filter))) {
        printf("failed to convert filter\n");
        return 1;
    }

    sprintf(*content, LUA_FUNC_CONTENT, name, converted);
    free(converted);

    return 0;
}
Ejemplo n.º 4
0
int gen_lua_file(char *filter)
{
    char *converted = (char*)calloc(2 * strlen(filter), 1);
    if (convert_filter(converted, filter, 2 * strlen(filter))) {
        printf("failed to convert filter\n");
        return 1;
    }

    FILE *fp = fopen(file_name, "w");
    if(fp == NULL) {
        return;
    }
    char content[8192];
    bzero(content, sizeof(content));

    sprintf(content, LUA_CONTENT, converted);

    fputs(content, fp);
    fflush(fp);
    fclose(fp);
    free(converted);
    return 0;
}
Ejemplo n.º 5
0
item_location game::inv_map_splice( item_filter filter, const std::string &title, int radius,
                                    const std::string &none_message )
{
    return inv_internal( u, inventory_filter_preset( convert_filter( filter ) ),
                         title, radius, none_message );
}
Ejemplo n.º 6
0
void test_convert_filter()
{
    char filter[4096];
    char converted[8192];

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent == \"Wget/1.15 (linux-gnu)\" and req.host == \"1.1.1.2\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, filter));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent == \"Wget/1.15 (linux-gnu)\" and req.host != \"1.1.1.2\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "req.user_agent == \"Wget/1.15 (linux-gnu)\" and req.host ~= \"1.1.1.2\""));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent == \"!=\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "req.user_agent == \"!=\""));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent contains \"Wget/1.15 (linux-gnu)\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "string.match(req.user_agent, \"Wget/1.15 (linux-gnu)\")"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent contains \"abc\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "string.match(req.user_agent, \"abc\")"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent contains \"contains\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "string.match(req.user_agent, \"contains\")"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent not-contains \"Wget/1.15 (linux-gnu)\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "not string.match(req.user_agent, \"Wget/1.15 (linux-gnu)\")"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent not-contains \"abc\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "not string.match(req.user_agent, \"abc\")"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent not-contains abc");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "not string.match(req.user_agent, abc)"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "req.user_agent not-contains \"not-contains\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "not string.match(req.user_agent, \"not-contains\")"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "(http.user_agent contains \"curl.*0\" and http.url == \"/\")");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "(string.match(http.user_agent, \"curl.*0\") and http.url == \"/\")"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "((http.user_agent contains \"curl.*0\") and (http.url == \"/\"))");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "((string.match(http.user_agent, \"curl.*0\")) and (http.url == \"/\"))"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "http.accept_encoding contains \"gzip\" or http.accept_encoding contains \"deflat*\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "string.match(http.accept_encoding, \"gzip\") or string.match(http.accept_encoding, \"deflat*\")"));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "http.url==\"/\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "http.url==\"/\""));

    bzero(filter, sizeof(filter));
    bzero(converted, sizeof(converted));
    strcpy(filter, "http.url contains \"a\\\"b\\\"c\"");
    convert_filter(converted, filter, sizeof(converted));
    assert(!strcmp(converted, "string.match(http.url, \"a\\\"b\\\"c\")"));
}