static int ep_parse_param_assignment_val(struct effect_parser *ep, struct ep_param *param) { if (param->is_texture) return ep_parse_param_assign_texture(ep, param); else if (strcmp(param->type, "int") == 0) return ep_parse_param_assign_intfloat(ep, param, false); else if (strcmp(param->type, "float") == 0) return ep_parse_param_assign_intfloat(ep, param, true); else if (astrcmp_n(param->type, "float", 5) == 0) return ep_parse_param_assign_float_array(ep, param); cf_adderror(&ep->cfp, "Invalid type '$1' used for assignment", LEX_ERROR, param->type, NULL, NULL); return PARSE_CONTINUE; }
/* * parses assignment for float1, float2, float3, float4, int1, int2, int3, int4, * and any combination for float3x3, float4x4, int3x3, int4x4, etc */ static inline int ep_parse_param_assign_intfloat_array(struct effect_parser *ep, struct ep_param *param, bool is_float) { const char *intfloat_type = param->type + (is_float ? 5 : 3); int intfloat_count = 0, code, i; /* -------------------------------------------- */ if (intfloat_type[0] < '1' || intfloat_type[0] > '4') cf_adderror(&ep->cfp, "Invalid row count", LEX_ERROR, NULL, NULL, NULL); intfloat_count = intfloat_type[0]-'0'; if (intfloat_type[1] == 'x') { if (intfloat_type[2] < '1' || intfloat_type[2] > '4') cf_adderror(&ep->cfp, "Invalid column count", LEX_ERROR, NULL, NULL, NULL); intfloat_count *= intfloat_type[2]-'0'; } /* -------------------------------------------- */ code = cf_next_token_should_be(&ep->cfp, "{", ";", NULL); if (code != PARSE_SUCCESS) return code; for (i = 0; i < intfloat_count; i++) { char *next = ((i+1) < intfloat_count) ? "," : "}"; code = ep_parse_param_assign_intfloat(ep, param, is_float); if (code != PARSE_SUCCESS) return code; code = cf_next_token_should_be(&ep->cfp, next, ";", NULL); if (code != PARSE_SUCCESS) return code; } return PARSE_SUCCESS; }