bool file_copy(FFILE f_in, FFILE f_out, int len) { char buffer[FILE_BUF_SIZE]; int readed; if(len) { int to_read; do { len -= FILE_BUF_SIZE; to_read = (len < 0) ? len+FILE_BUF_SIZE : FILE_BUF_SIZE; if((readed = fread(buffer,1,to_read,f_in))) { fwrite(buffer,1,readed,f_out); } if(readed != to_read) { pperror(1,"file_copy - missing data?"); } } while(to_read == FILE_BUF_SIZE); } else { while((readed = fread(buffer,1,FILE_BUF_SIZE,f_in))) { fwrite(buffer,1,readed,f_out); } } return(TRUE); }
/* { name = *** type = GENERATOR_MESH_CONFIG } */ void generator_mesh::load_section_generator_config(DATA_FILE_SECTION *p_section) { DATA_FILE_SECTION *p_line = p_section->section_child_get(); if(!p_line) return; // Set name of this generator name_set(p_section->name_get()); int modificator_index = -1; int target_index = -1; do { if(p_line->is_line()) { if(p_line->match_name("modificator")) { modificator_index++; target_index = -1; GENERATOR_MESH_MODIFICATOR_CONFIG *p_modificator = config.modificator_ref(modificator_index); strncpy(p_modificator->modificator_name, p_line->line_value_string_get(), MAX_NAME); p_line->line_mark_loaded(); continue; } else if(modificator_index >= 0) { GENERATOR_MESH_MODIFICATOR_CONFIG *p_modificator = config.modificator_ref(modificator_index); // modificator target - for unique targets (TEXTURE/MESH) if(p_line->match_name("modificator_target")) { target_index++; GENERATOR_MESH_MODIFICATOR_TARGET_CONFIG *p_target = p_modificator->target_config_ref(target_index); p_target->target_type = modificator_target_translate(p_line->line_value_string_get()); if(p_target->target_type == MODIFICATOR_TARGET_NONE) { ppset(p_line->source_file_get(), p_line->source_line_get()); pperror(TRUE, "'%s' is not a valid modificator target!",p_line->line_value_string_get()); ppclear(); } p_line->line_mark_loaded(); continue; } else { GENERATOR_MESH_MODIFICATOR_TARGET_CONFIG *p_target = p_modificator->target_config_ref(target_index); // For other targets (BITMAP/HEIGHTMAP/AUX) if(p_line->match_name("modificator_target_name")) { strncpy(p_target->target_name, p_line->line_value_string_get(), MAX_NAME); p_line->line_mark_loaded(); continue; } // Load repeat load_int(p_target->repeat,"modificator_repeat"); // Load mask p_target->mask.load_line(p_line, generator_get()); } } } } while((p_line = p_line->section_next())); }
yylex() { static int ifdef=0; static char *op2[]={"||", "&&" , ">>", "<<", ">=", "<=", "!=", "=="}; static int val2[]={OROR, ANDAND, RS, LS, GE, LE, NE, EQ}; static char *opc="b\bt\tn\nf\fr\r\\\\"; extern char fastab[]; extern char *outp,*inp,*newp; extern int flslvl; register char savc, *s; char *skipbl(); int val; register char **p2; struct symtab { char *name; char *value; } *sp, *lookup(); for (;;) { extern int passcom; /* this crap makes #if's work */ int opt_passcom = passcom; /* even with -C option */ passcom = 0; /* (else comments make syntax errs) */ newp=skipbl(newp); passcom = opt_passcom; /* nb: lint uses -C so its useful! */ if (*inp=='\n') return(stop); /* end of #if */ savc= *newp; *newp='\0'; for (p2=op2+8; --p2>=op2; ) /* check 2-char ops */ if (0==strcmp(*p2,inp)) {val=val2[p2-op2]; goto ret;} s="+-*/%<>&^|?:!~(),"; /* check 1-char ops */ while (*s) if (*s++== *inp) {val= *--s; goto ret;} if (*inp<='9' && *inp>='0') {/* a number */ if (*inp=='0') yylval= (inp[1]=='x' || inp[1]=='X') ? tobinary(inp+2,16) : tobinary(inp+1,8); else yylval=tobinary(inp,10); val=number; } else if (isid(*inp)) { if (0==strcmp(inp,"defined")) {ifdef=1; ++flslvl; val=DEFINED;} else { sp=lookup(inp,-1); if (ifdef!=0) {ifdef=0; --flslvl;} yylval= (sp->value==0) ? 0 : 1; val=number; } } else if (*inp=='\'') {/* character constant */ val=number; if (inp[1]=='\\') {/* escaped */ char c; if (newp[-1]=='\'') newp[-1]='\0'; s=opc; while (*s) if (*s++!=inp[2]) ++s; else {yylval= *s; goto ret;} if (inp[2]<='9' && inp[2]>='0') yylval=c=tobinary(inp+2,8); else yylval=inp[2]; } else yylval=inp[1]; } else if (0==strcmp("\\\n",inp)) {*newp=savc; continue;} else { *newp=savc; pperror("Illegal character %c in preprocessor if", *inp); continue; } ret: *newp=savc; outp=inp=newp; return(val); } }
// source is float bool line_tree::variable_node_convert_float(VARIABLE_NODE ch, VARIABLE_TYPE target, VARIABLE_NODE *p_result) { if(target == VARIABLE_INT) { p_result->type = VARIABLE_INT; p_result->vint = roundf(ch.vfloat); return(TRUE); } else { ppline(); pperror(TRUE, "type mismatch - can't convert type %s to %s", variable_type_translate(ch.type), variable_type_translate(target)); } return(FALSE); }
VARIABLE_NODE line_tree::variable_node_sub(VARIABLE_NODE ch1, VARIABLE_NODE ch2) { if(ch1.type == VARIABLE_FLOAT && ch2.type == VARIABLE_FLOAT) { return(variable_node_sub_float(ch1.vfloat, ch2.vfloat)); } else if(ch1.type == VARIABLE_RGBAF && ch2.type == VARIABLE_RGBAF) { return(variable_node_sub_color(ch1.vcolor, ch2.vcolor)); } else { ppline(); pperror(TRUE, "type mismatch - can't substract types %s and %s", variable_type_translate(ch1.type), variable_type_translate(ch2.type)); } }
// source is int bool line_tree::variable_node_convert_int(VARIABLE_NODE ch, VARIABLE_TYPE target, VARIABLE_NODE *p_result) { if(target == VARIABLE_FLOAT) { p_result->type = VARIABLE_FLOAT; p_result->vfloat = (float)ch.vint; return(TRUE); } else if(target == VARIABLE_RGBAF) { p_result->type = VARIABLE_RGBAF; rgba_float(ch.vint, &p_result->vcolor.r, &p_result->vcolor.g, &p_result->vcolor.b, &p_result->vcolor.a); return(TRUE); } else { ppline(); pperror(TRUE, "type mismatch - can't convert type %s to %s", variable_type_translate(ch.type), variable_type_translate(target)); } return(FALSE); }
bool line_tree::variable_node_convert(VARIABLE_NODE ch, VARIABLE_TYPE target, VARIABLE_NODE *p_result) { if(ch.type == VARIABLE_FLOAT) { // convert from float return(variable_node_convert_float(ch, target, p_result)); } else if(ch.type == VARIABLE_INT) { // convert from int return(variable_node_convert_int(ch, target, p_result)); } else if(ch.type == VARIABLE_RGBAF) { // convert from color return(variable_node_convert_color(ch, target, p_result)); } else { ppline(); pperror(TRUE, "type mismatch - can't convert type %s to %s", variable_type_translate(ch.type), variable_type_translate(target)); return(FALSE); } }
VARIABLE_NODE line_tree::execute_leaf(PARAM_NODE_LEAF *p_leaf, PIXEL_PARAMS *p_params) { VARIABLE_NODE ret; PARAM_NODE *p_node = &p_leaf->node; switch(p_node->content_type) { // Parameters from previous modificator case NODE_PARAM_PREV_0: case NODE_PARAM_PREV_1: case NODE_PARAM_PREV_2: case NODE_PARAM_PREV_3: case NODE_PARAM_PREV_4: case NODE_PARAM_PREV_5: case NODE_PARAM_PREV_6: case NODE_PARAM_PREV_7: case NODE_PARAM_PREV_8: case NODE_PARAM_PREV_9: { assert(p_params); MODIFICATOR_PARAMS *p_par = p_params->p_params; int parameter = p_node->content_type - NODE_PARAM_PREV_0; if(p_par->is_index(parameter)) { ret.type = VARIABLE_FLOAT; ret.vfloat = p_par->get(parameter); } else { ppline(); pperror(TRUE, "parametrizer::execute_leaf() - missing parameter %d", parameter); ret.type = VARIABLE_INT; ret.vint = FALSE; } break; } // random numbers case NODE_PARAM_RAND: ret.type = VARIABLE_FLOAT; ret.vfloat = random_generator::generator_rand_0(); break; case NODE_PARAM_RAND_HALF: ret.type = VARIABLE_FLOAT; ret.vfloat = random_generator::generator_rand(); break; case NODE_PARAM_GAUSS: ret.type = VARIABLE_FLOAT; ret.vfloat = random_generator::generator_gauss_0(); break; case NODE_PARAM_GAUSS_HALF: ret.type = VARIABLE_FLOAT; ret.vfloat = fabs(random_generator::generator_gauss_0()); break; case NODE_CONSTANT_INT: ret.type = VARIABLE_INT; ret.vint = p_node->cint; break; case NODE_CONSTANT_FLOAT: ret.type = VARIABLE_FLOAT; ret.vfloat = p_node->cfloat; break; case NODE_CONSTANT_RGBAF: ret.type = VARIABLE_RGBAF; ret.vcolor = p_node->ccolor; break; case NODE_CONSTANT_VECT3DF: ret.type = VARIABLE_VECT3DF; ret.vvector = p_node->cvector; break; case NODE_CONSTANT_RECT2DF: ret.type = VARIABLE_RECT2DI; ret.vrect = p_node->crect; break; case NODE_VAR_VARIABLE: ret = p_node->p_cvariable->value; break; case NODE_VAR_VARIABLE_R: case NODE_VAR_VARIABLE_G: case NODE_VAR_VARIABLE_B: case NODE_VAR_VARIABLE_A: { assert(p_node->p_cvariable->value.type == VARIABLE_RGBAF); ret.type = VARIABLE_FLOAT; ret.vfloat = variable_content_get(&p_node->p_cvariable->value, p_node->content_type); break; } case NODE_VAR_VARIABLE_X: case NODE_VAR_VARIABLE_Y: case NODE_VAR_VARIABLE_Z: { assert(p_node->p_cvariable->value.type == VARIABLE_VECT3DF); ret.type = VARIABLE_FLOAT; ret.vfloat = variable_content_get(&p_node->p_cvariable->value, p_node->content_type); break; } case NODE_VAR_VARIABLE_DX: case NODE_VAR_VARIABLE_DY: { ppline(); pperror(TRUE, "Rectangles are not yet implemented."); } case NODE_OP_ADD: // + { assert(p_leaf->p_child[0] && p_leaf->p_child[1]); VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params); VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params); ret = variable_node_add(ch1,ch2); break; } case NODE_OP_SUB: // - { assert(p_leaf->p_child[0] && p_leaf->p_child[1]); VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params); VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params); ret = variable_node_sub(ch1,ch2); break; } case NODE_OP_MULT: // * { assert(p_leaf->p_child[0] && p_leaf->p_child[1]); VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params); VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params); ret = variable_node_mult(ch1,ch2); break; } case NODE_OP_DIV: // / { assert(p_leaf->p_child[0] && p_leaf->p_child[1]); VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params); VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params); ret = variable_node_div(ch1,ch2); break; } case NODE_OP_EQ: // = { assert(p_leaf->p_child[0] && p_leaf->p_child[1]); assert(p_leaf->p_child[0]->node.node_type == NODE_VARIABLE); PARAM_NODE *p_target_node = &p_leaf->p_child[0]->node; VARIABLE_NODE *p_target = &(p_target_node->p_cvariable->value); VARIABLE_NODE source = execute_leaf(p_leaf->p_child[1],p_params); // Set whole variable if(p_target_node->content_type == NODE_VAR_VARIABLE) { if(p_target->type == VARIABLE_UNSET || p_target->type == source.type) { *p_target = source; } else { bool ret = variable_node_convert(source, p_target->type, p_target); if(!ret) { ppline(); pperror(TRUE, "Type mismatch: can't convert %s to %s", variable_type_translate(source.type), variable_type_translate(p_target->type)); } } } else if(p_target_node->content_type == NODE_VAR_VARIABLE_R || p_target_node->content_type == NODE_VAR_VARIABLE_G || p_target_node->content_type == NODE_VAR_VARIABLE_B || p_target_node->content_type == NODE_VAR_VARIABLE_A) { VARIABLE_NODE target; if(source.type == VARIABLE_FLOAT) { target = source; } else { bool ret = variable_node_convert(source, VARIABLE_FLOAT, &target); if(!ret) { ppline(); pperror(TRUE, "Type mismatch: can't convert %s to %s", variable_type_translate(source.type), variable_type_translate(VARIABLE_FLOAT)); } } target.type = VARIABLE_FLOAT; variable_content_set(p_target, p_target_node->content_type, target.vfloat); } else { ppline(); pperror(TRUE, "Assignment target is not a variable!"); } ret.type = VARIABLE_INT; ret.vint = TRUE; break; } case NODE_FUNC_SIN: // sin() { assert(p_leaf->p_child[0]); ret = execute_leaf(p_leaf->p_child[0],p_params); if(ret.type != VARIABLE_FLOAT) { ppline(); pperror(TRUE, "Type mismatch: sin() needs a parameter type FLOAT, not %s", variable_type_translate(ret.type)); } ret.vfloat = sinf(ret.vfloat); break; } case NODE_FUNC_COS: // cos() { assert(p_leaf->p_child[0]); ret = execute_leaf(p_leaf->p_child[0],p_params); if(ret.type != VARIABLE_FLOAT) { ppline(); pperror(TRUE, "Type mismatch: cos() needs a parameter type FLOAT, not %s", variable_type_translate(ret.type)); } ret.vfloat = cosf(ret.vfloat); break; } case NODE_FUNC_SQRT: // sqrt() { assert(p_leaf->p_child[0]); ret = execute_leaf(p_leaf->p_child[0],p_params); if(ret.type != VARIABLE_FLOAT) { ppline(); pperror(TRUE, "Type mismatch: sqrt() needs a parameter type FLOAT, not %s", variable_type_translate(ret.type)); } ret.vfloat = sqrtf(ret.vfloat); break; } case NODE_FUNC_NORM: // norm() { assert(p_leaf->p_child[0]); ret = execute_leaf(p_leaf->p_child[0],p_params); if(ret.type != VARIABLE_FLOAT) { ppline(); pperror(TRUE, "Type mismatch: norm() needs a parameter type FLOAT, not %s", variable_type_translate(ret.type)); } if(ret.vfloat > 1) { ret.vfloat = 1.0f; } else if(ret.vfloat < 0) { ret.vfloat = 0.0f; } break; } case NODE_FUNC_ABS: // abs() { assert(p_leaf->p_child[0]); ret = execute_leaf(p_leaf->p_child[0],p_params); if(ret.type != VARIABLE_FLOAT) { ppline(); pperror(TRUE, "Type mismatch: abs() needs a parameter type FLOAT, not %s", variable_type_translate(ret.type)); } ret.vfloat = fabs(ret.vfloat); break; } case NODE_FUNC_RGB: // rgb() { assert(p_leaf->p_child[0]); ret = execute_leaf(p_leaf->p_child[0],p_params); if(ret.type != VARIABLE_FLOAT) { ppline(); pperror(TRUE, "Type mismatch: rgb() needs a parameter type FLOAT, not %s", variable_type_translate(ret.type)); } if(ret.vfloat < 0) ret.vfloat = 0; else if(ret.vfloat > 255) ret.vfloat = 1; else ret.vfloat = ret.vfloat/255; break; } case NODE_FUNC_BLEND: // blend() { assert(p_leaf->p_child[0]); assert(p_leaf->p_child[1]); assert(p_leaf->p_child[2]); VARIABLE_NODE ch1 = execute_leaf(p_leaf->p_child[0],p_params); VARIABLE_NODE ch2 = execute_leaf(p_leaf->p_child[1],p_params); VARIABLE_NODE ch3 = execute_leaf(p_leaf->p_child[2],p_params); if(ch1.type != VARIABLE_RGBAF || ch2.type != VARIABLE_FLOAT || ch3.type != VARIABLE_RGBAF) { if(ret.type != VARIABLE_FLOAT) { ppline(); pperror(TRUE, "Type mismatch: blend() takes types COLOR, FLOAT, COLOR, but it got %s %s %s", variable_type_translate(ch1.type), variable_type_translate(ch2.type), variable_type_translate(ch3.type)); } } float alpha_dest = ch2.vfloat; float alpha_src = 1.0f - ch2.vfloat; RGBAF dest(ch1.vcolor); RGBAF src(ch3.vcolor); ret.type = VARIABLE_RGBAF; ret.vcolor = dest*alpha_dest + src*alpha_src; break; } default: ret.type = VARIABLE_INT; ret.vint = FALSE; break; } return(ret); }
// delit to bez tech mezer int parametrizer::tokens_get(DATA_FILE_SECTION *p_line, array<PARAM_NODE> &nodes) { assert(p_line); char *p_start = p_line->line_raw_string_get(); char *p_current = p_line->line_raw_string_get(); TOKEN_STATE state = STATE_TOKEN_START; do { switch(state) { case STATE_TOKEN_START: { assert(p_start == p_current); char c = *p_start; if(c == '\0') { state = STATE_STRING_END; } else if(isspace(c)) { p_start++; } else if(is_token_delim(c)) { state = STATE_TOKEN_END; } else { state = STATE_TOKEN_IN; } p_current++; break; } case STATE_TOKEN_IN: { char c = *p_current; if(c == '\0' || is_token_delim(c) || isspace(c)) { state = STATE_TOKEN_END; } else { p_current++; } break; } case STATE_TOKEN_END: { PARAM_NODE token; memset(&token,0,sizeof(token)); char c = *p_start; int length = p_current - p_start; assert(c != '\0' && !isspace(c)); assert(length != 0); if(is_token(p_start, length, token) || is_number(p_start, length, token)) { // It's a number or token nodes.append(token); } else { if(!is_token_delim(p_start[0])) { // We have a variable here if(p_start[length-2] == '.') { // it's a part of color variable (.r .g .b .a) // or a vector variable (.x .y .z) switch(p_start[length-1]) { case 'r': token.content_type = NODE_VAR_VARIABLE_R; length -= 2; break; case 'g': token.content_type = NODE_VAR_VARIABLE_G; length -= 2; break; case 'b': token.content_type = NODE_VAR_VARIABLE_B; length -= 2; break; case 'a': token.content_type = NODE_VAR_VARIABLE_A; length -= 2; break; case 'x': token.content_type = NODE_VAR_VARIABLE_X; length -= 2; break; case 'y': token.content_type = NODE_VAR_VARIABLE_Y; length -= 2; break; case 'z': token.content_type = NODE_VAR_VARIABLE_Z; length -= 2; break; default: p_line->ppline(); pperror(TRUE, "wrong tail .%c",p_start[length-1]); break; } } else { token.content_type = NODE_VAR_VARIABLE; } SYMBOL_TABLE_NODE *p_variable = symbol_table_get(symbol_table_get_active(), p_start, length); if(!p_variable) { p_variable = symbol_table_add(symbol_table_get_active(), p_start, length); } if(token.content_type == NODE_VAR_VARIABLE_R || token.content_type == NODE_VAR_VARIABLE_G || token.content_type == NODE_VAR_VARIABLE_B || token.content_type == NODE_VAR_VARIABLE_A) { if(p_variable->value.type == VARIABLE_UNSET) { p_variable->value.type = VARIABLE_RGBAF; } if(p_variable->value.type != VARIABLE_RGBAF) { p_line->ppline(); pperror(TRUE, "variable %s has to be a color type! (is %s)", p_variable->name, variable_type_translate(p_variable->value.type)); } } else if(token.content_type == NODE_VAR_VARIABLE_X || token.content_type == NODE_VAR_VARIABLE_Y || token.content_type == NODE_VAR_VARIABLE_Z) { if(p_variable->value.type == VARIABLE_UNSET) { p_variable->value.type = VARIABLE_VECT3DF; } if(p_variable->value.type != VARIABLE_VECT3DF) { p_line->ppline(); pperror(TRUE, "variable %s has to be a vector type! (is %s)", p_variable->name, variable_type_translate(p_variable->value.type)); } } token.node_type = NODE_VARIABLE; token.p_cvariable = p_variable; // Append it nodes.append(token); } } p_start = p_current; state = STATE_TOKEN_START; break; } default: break; } } while(state != STATE_STRING_END); return(nodes.num_get()); }
void line_tree::ppline(void) { ppset(p_param->parse_file_get(), source_line_number); pperror(FALSE, p_source_line); ppclear(); }
void data_file_section::ppline(void) { ppset(source_file_get(), line_number); pperror(FALSE, raw_string); ppclear(); }