00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include <stdlib.h>
00032 #include <math.h>
00033 #include "fatal.h"
00034 #include "common.h"
00035
00036 #include "splaytree_types.h"
00037 #include "splaytree.h"
00038 #include "tree_types.h"
00039
00040 #include "param_types.h"
00041 #include "param.h"
00042
00043 #include "expr_types.h"
00044 #include "eval.h"
00045
00046 #include "engine_vars.h"
00047
00048 void reset_param(param_t * param);
00049
00050 int is_valid_param_string(char * string);
00051
00052
00053
00054 splaytree_t * builtin_param_tree = NULL;
00055
00056 int insert_param_alt_name(param_t * param, char * alt_name);
00057
00058 int insert_builtin_param(param_t * param);
00059
00060
00061 int compare_param(char * name, char * name2);
00062
00063 int load_builtin_param_double(char * name, void * engine_val, void * matrix, short int flags,
00064 double init_val, double upper_bound, double lower_bound, char * alt_name);
00065
00066 int load_builtin_param_int(char * name, void * engine_val, short int flags,
00067 int init_val, int upper_bound, int lower_bound, char * alt_name);
00068
00069 int load_builtin_param_bool(char * name, void * engine_val, short int flags,
00070 int init_val, char * alt_name);
00071
00072
00073
00074 param_t * create_param (char * name, short int type, short int flags, void * engine_val, void * matrix,
00075 value_t default_init_val, value_t upper_bound, value_t lower_bound) {
00076
00077 param_t * param = NULL;
00078
00079 param = (param_t*)malloc(sizeof(param_t));
00080
00081 if (param == NULL) {
00082 printf("create_param: out of memory!!!\n");
00083 return NULL;
00084 }
00085
00086
00087
00088
00089
00090 strncpy(param->name, name, MAX_TOKEN_SIZE-1);
00091
00092
00093 param->type = type;
00094 param->flags = flags;
00095 param->matrix_flag = 0;
00096 param->matrix = matrix;
00097 param->engine_val = engine_val;
00098 param->default_init_val = default_init_val;
00099
00100 param->upper_bound = upper_bound;
00101 param->lower_bound = lower_bound;
00102
00103
00104 return param;
00105
00106 }
00107
00108
00109 param_t * create_user_param(char * name) {
00110
00111 param_t * param;
00112 value_t iv;
00113 value_t ub;
00114 value_t lb;
00115 double * engine_val;
00116
00117
00118 iv.double_val = DEFAULT_DOUBLE_IV;
00119 ub.double_val = DEFAULT_DOUBLE_UB;
00120 lb.double_val = DEFAULT_DOUBLE_LB;
00121
00122
00123 if (name == NULL)
00124 return NULL;
00125
00126
00127 if ((engine_val = (double*)malloc(sizeof(double))) == NULL)
00128 return NULL;
00129
00130 (*engine_val) = iv.double_val;
00131
00132
00133 if ((param = create_param(name, P_TYPE_DOUBLE, P_FLAG_USERDEF, engine_val, NULL, iv, ub, lb)) == NULL) {
00134 free(engine_val);
00135 return NULL;
00136 }
00137 if (PARAM_DEBUG) printf("create_param: \"%s\" initialized\n", param->name);
00138
00139 return param;
00140 }
00141
00142
00143
00144 int init_builtin_param_db() {
00145
00146
00147 if ((builtin_param_tree = create_splaytree(compare_string, copy_string, free_string)) == NULL) {
00148 if (PARAM_DEBUG) printf("init_builtin_param_db: failed to initialize database (FATAL)\n");
00149 return OUTOFMEM_ERROR;
00150 }
00151
00152 if (PARAM_DEBUG) {
00153 printf("init_builtin_param: loading database...");
00154 fflush(stdout);
00155 }
00156
00157
00158 if (load_all_builtin_param() < 0) {
00159 if (PARAM_DEBUG) printf("failed loading builtin parameters (FATAL)\n");
00160 return ERROR;
00161 }
00162
00163 if (PARAM_DEBUG) printf("success!\n");
00164
00165
00166 return SUCCESS;
00167 }
00168
00169
00170
00171 int destroy_builtin_param_db() {
00172
00173 splay_traverse(free_param, builtin_param_tree);
00174 destroy_splaytree(builtin_param_tree);
00175 builtin_param_tree = NULL;
00176 return SUCCESS;
00177
00178 }
00179
00180
00181
00182 int insert_param_alt_name(param_t * param, char * alt_name) {
00183
00184 if (param == NULL)
00185 return ERROR;
00186 if (alt_name == NULL)
00187 return ERROR;
00188
00189 splay_insert_link(alt_name, param->name, builtin_param_tree);
00190
00191 return SUCCESS;
00192 }
00193
00194
00195 param_t * find_builtin_param(char * name) {
00196
00197
00198 if (name == NULL)
00199 return NULL;
00200
00201 return splay_find(name, builtin_param_tree);
00202
00203 }
00204
00205
00206 param_t * find_param(char * name, preset_t * preset, int flags) {
00207
00208 param_t * param = NULL;
00209
00210
00211 if (name == NULL)
00212 return NULL;
00213 if (preset == NULL)
00214 return NULL;
00215
00216
00217 param = (param_t *)splay_find(name, builtin_param_tree);
00218
00219
00220 if (param == NULL) {
00221 param = (param_t*)splay_find(name, preset->user_param_tree);
00222 }
00223
00224
00225
00226
00227 if ((param == NULL) && (flags & P_CREATE)) {
00228
00229
00230 if (!is_valid_param_string(name)) {
00231 if (PARAM_DEBUG) printf("find_param: invalid parameter name:\"%s\"\n", name);
00232 return NULL;
00233 }
00234
00235 if ((param = create_user_param(name)) == NULL) {
00236 if (PARAM_DEBUG) printf("find_param: failed to create a new user parameter!\n");
00237 return NULL;
00238 }
00239
00240 if (splay_insert(param, param->name, preset->user_param_tree) < 0) {
00241 if (PARAM_DEBUG) printf("PARAM \"%s\" already exists in user parameter tree!\n", param->name);
00242 free_param(param);
00243 return NULL;
00244 }
00245
00246 }
00247
00248
00249 return param;
00250
00251 }
00252
00253
00254 int compare_param(char * name, char * name2) {
00255
00256 int cmpval;
00257 printf("am i used\n");
00258
00259 cmpval = strncmp(name, name2, MAX_TOKEN_SIZE-1);
00260
00261 return cmpval;
00262 }
00263
00264
00265 int load_all_builtin_param() {
00266
00267 load_builtin_param_double("fRating", (void*)&fRating, NULL, P_FLAG_NONE, 0.0 , 5.0, 0.0, NULL);
00268 load_builtin_param_double("fWaveScale", (void*)&fWaveScale, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00269 load_builtin_param_double("gamma", (void*)&fGammaAdj, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fGammaAdj");
00270 load_builtin_param_double("echo_zoom", (void*)&fVideoEchoZoom, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fVideoEchoZoom");
00271 load_builtin_param_double("echo_alpha", (void*)&fVideoEchoAlpha, NULL, P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fVideoEchoAlpha");
00272 load_builtin_param_double("wave_a", (void*)&fWaveAlpha, NULL, P_FLAG_NONE, 0.0, 1.0, 0, "fWaveAlpha");
00273 load_builtin_param_double("fWaveSmoothing", (void*)&fWaveSmoothing, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
00274 load_builtin_param_double("fModWaveAlphaStart", (void*)&fModWaveAlphaStart, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
00275 load_builtin_param_double("fModWaveAlphaEnd", (void*)&fModWaveAlphaEnd, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
00276 load_builtin_param_double("fWarpAnimSpeed", (void*)&fWarpAnimSpeed, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
00277
00278
00279 load_builtin_param_double("fShader", (void*)&fShader, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
00280 load_builtin_param_double("decay", (void*)&decay, NULL, P_FLAG_NONE, 0.0, 1.0, 0, "fDecay");
00281
00282 load_builtin_param_int("echo_orient", (void*)&nVideoEchoOrientation, P_FLAG_NONE, 0, 3, 0, "nVideoEchoOrientation");
00283 load_builtin_param_int("wave_mode", (void*)&nWaveMode, P_FLAG_NONE, 0, 7, 0, "nWaveMode");
00284
00285 load_builtin_param_bool("wave_additive", (void*)&bAdditiveWaves, P_FLAG_NONE, FALSE, "bAdditiveWaves");
00286 load_builtin_param_bool("bModWaveAlphaByVolume", (void*)&bModWaveAlphaByVolume, P_FLAG_NONE, FALSE, NULL);
00287 load_builtin_param_bool("wave_brighten", (void*)&bMaximizeWaveColor, P_FLAG_NONE, FALSE, "bMaximizeWaveColor");
00288 load_builtin_param_bool("wrap", (void*)&bTexWrap, P_FLAG_NONE, FALSE, "bTexWrap");
00289 load_builtin_param_bool("darken_center", (void*)&bDarkenCenter, P_FLAG_NONE, FALSE, "bDarkenCenter");
00290 load_builtin_param_bool("bRedBlueStereo", (void*)&bRedBlueStereo, P_FLAG_NONE, FALSE, NULL);
00291 load_builtin_param_bool("brighten", (void*)&bBrighten, P_FLAG_NONE, FALSE, "bBrighten");
00292 load_builtin_param_bool("darken", (void*)&bDarken, P_FLAG_NONE, FALSE, "bDarken");
00293 load_builtin_param_bool("solarize", (void*)&bSolarize, P_FLAG_NONE, FALSE, "bSolarize");
00294 load_builtin_param_bool("invert", (void*)&bInvert, P_FLAG_NONE, FALSE, "bInvert");
00295 load_builtin_param_bool("bMotionVectorsOn", (void*)&bMotionVectorsOn, P_FLAG_NONE, FALSE, NULL);
00296 load_builtin_param_bool("wave_dots", (void*)&bWaveDots, P_FLAG_NONE, FALSE, "bWaveDots");
00297 load_builtin_param_bool("wave_thick", (void*)&bWaveThick, P_FLAG_NONE, FALSE, "bWaveThick");
00298
00299
00300
00301 load_builtin_param_double("zoom", (void*)&zoom, zoom_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
00302 load_builtin_param_double("rot", (void*)&rot, rot_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, NULL);
00303 load_builtin_param_double("zoomexp", (void*)&zoomexp, zoomexp_mesh, P_FLAG_PER_PIXEL |P_FLAG_NONE, 0.0, MAX_DOUBLE_SIZE, 0, "fZoomExponent");
00304
00305 load_builtin_param_double("cx", (void*)&cx, cx_mesh, P_FLAG_PER_PIXEL | P_FLAG_DONT_FREE_MATRIX, 0.0, 1.0, 0, NULL);
00306 load_builtin_param_double("cy", (void*)&cy, cy_mesh, P_FLAG_PER_PIXEL | P_FLAG_DONT_FREE_MATRIX, 0.0, 1.0, 0, NULL);
00307 load_builtin_param_double("dx", (void*)&dx, dx_mesh, P_FLAG_PER_PIXEL | P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, NULL);
00308 load_builtin_param_double("dy", (void*)&dy, dy_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, MIN_DOUBLE_SIZE, NULL);
00309 load_builtin_param_double("sx", (void*)&sx, sx_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
00310 load_builtin_param_double("sy", (void*)&sy, sy_mesh, P_FLAG_PER_PIXEL |P_FLAG_DONT_FREE_MATRIX, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
00311
00312 load_builtin_param_double("wave_r", (void*)&wave_r, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00313 load_builtin_param_double("wave_g", (void*)&wave_g, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00314 load_builtin_param_double("wave_b", (void*)&wave_b, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00315 load_builtin_param_double("wave_x", (void*)&wave_x, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00316 load_builtin_param_double("wave_y", (void*)&wave_y, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00317 load_builtin_param_double("wave_mystery", (void*)&wave_mystery, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, "fWaveParam");
00318
00319 load_builtin_param_double("ob_size", (void*)&ob_size, NULL, P_FLAG_NONE, 0.0, 0.5, 0, NULL);
00320 load_builtin_param_double("ob_r", (void*)&ob_r, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00321 load_builtin_param_double("ob_g", (void*)&ob_g, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00322 load_builtin_param_double("ob_b", (void*)&ob_b, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00323 load_builtin_param_double("ob_a", (void*)&ob_a, NULL, P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00324
00325 load_builtin_param_double("ib_size", (void*)&ib_size, NULL,P_FLAG_NONE, 0.0, .5, 0.0, NULL);
00326 load_builtin_param_double("ib_r", (void*)&ib_r, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00327 load_builtin_param_double("ib_g", (void*)&ib_g, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00328 load_builtin_param_double("ib_b", (void*)&ib_b, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00329 load_builtin_param_double("ib_a", (void*)&ib_a, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00330
00331 load_builtin_param_double("mv_r", (void*)&mv_r, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00332 load_builtin_param_double("mv_g", (void*)&mv_g, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00333 load_builtin_param_double("mv_b", (void*)&mv_b, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00334 load_builtin_param_double("mv_x", (void*)&mv_x, NULL,P_FLAG_NONE, 0.0, 64.0, 0.0, "nMotionVectorsX");
00335 load_builtin_param_double("mv_y", (void*)&mv_y, NULL,P_FLAG_NONE, 0.0, 48.0, 0.0, "nMotionVectorsY");
00336 load_builtin_param_double("mv_l", (void*)&mv_l, NULL,P_FLAG_NONE, 0.0, 5.0, 0.0, NULL);
00337 load_builtin_param_double("mv_dy", (void*)&mv_dy, NULL, P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
00338 load_builtin_param_double("mv_dx", (void*)&mv_dx, NULL,P_FLAG_NONE, 0.0, 1.0, -1.0, NULL);
00339 load_builtin_param_double("mv_a", (void*)&mv_a, NULL,P_FLAG_NONE, 0.0, 1.0, 0.0, NULL);
00340
00341 load_builtin_param_double("time", (void*)&Time, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0.0, NULL);
00342 load_builtin_param_double("bass", (void*)&bass, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0.0, NULL);
00343 load_builtin_param_double("mid", (void*)&mid, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
00344 load_builtin_param_double("bass_att", (void*)&bass_att, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
00345 load_builtin_param_double("mid_att", (void*)&mid_att, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
00346 load_builtin_param_double("treb_att", (void*)&treb_att, NULL,P_FLAG_READONLY, 0.0, MAX_DOUBLE_SIZE, 0, NULL);
00347 load_builtin_param_int("frame", (void*)&frame, P_FLAG_READONLY, 0, MAX_INT_SIZE, 0, NULL);
00348 load_builtin_param_double("progress", (void*)&progress, NULL,P_FLAG_READONLY, 0.0, 1, 0, NULL);
00349 load_builtin_param_int("fps", (void*)&fps, P_FLAG_NONE, 15, MAX_INT_SIZE, 0, NULL);
00350
00351
00352
00353 load_builtin_param_double("x", (void*)&x_per_pixel, x_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX,
00354 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00355 load_builtin_param_double("y", (void*)&y_per_pixel, y_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX |P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX,
00356 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00357 load_builtin_param_double("ang", (void*)&ang_per_pixel, theta_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX,
00358 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00359 load_builtin_param_double("rad", (void*)&rad_per_pixel, rad_mesh, P_FLAG_PER_PIXEL |P_FLAG_ALWAYS_MATRIX | P_FLAG_READONLY | P_FLAG_DONT_FREE_MATRIX,
00360 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00361
00362
00363 load_builtin_param_double("q1", (void*)&q1, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00364 load_builtin_param_double("q2", (void*)&q2, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00365 load_builtin_param_double("q3", (void*)&q3, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00366 load_builtin_param_double("q4", (void*)&q4, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00367 load_builtin_param_double("q5", (void*)&q5, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00368 load_builtin_param_double("q6", (void*)&q6, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00369 load_builtin_param_double("q7", (void*)&q7, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00370 load_builtin_param_double("q8", (void*)&q8, NULL, P_FLAG_PER_PIXEL |P_FLAG_QVAR, 0, MAX_DOUBLE_SIZE, -MAX_DOUBLE_SIZE, NULL);
00371
00372
00373
00374
00375 load_builtin_param_int("meshx", (void*)&gx, P_FLAG_READONLY, 32, 96, 8, NULL);
00376 load_builtin_param_int("meshy", (void*)&gy, P_FLAG_READONLY, 24, 72, 6, NULL);
00377
00378 return SUCCESS;
00379
00380 }
00381
00382
00383 void free_param(param_t * param) {
00384 int x;
00385 if (param == NULL)
00386 return;
00387
00388 if (param->flags & P_FLAG_USERDEF) {
00389 free(param->engine_val);
00390
00391 }
00392
00393 if (!(param->flags & P_FLAG_DONT_FREE_MATRIX)) {
00394
00395 if (param->flags & P_FLAG_PER_POINT)
00396 free(param->matrix);
00397
00398 else if (param->flags & P_FLAG_PER_PIXEL) {
00399 for(x = 0; x < gx; x++)
00400 free(((double**)param->matrix)[x]);
00401 free(param->matrix);
00402 }
00403 }
00404
00405 if (PARAM_DEBUG) printf("free_param: freeing \"%s\".\n", param->name);
00406 free(param);
00407
00408 }
00409
00410
00411 int load_builtin_param_double(char * name, void * engine_val, void * matrix, short int flags,
00412 double init_val, double upper_bound, double lower_bound, char * alt_name) {
00413
00414 param_t * param = NULL;
00415 value_t iv, ub, lb;
00416
00417 iv.double_val = init_val;
00418 ub.double_val = upper_bound;
00419 lb.double_val = lower_bound;
00420
00421
00422 if (PARAM_DEBUG == 2) {
00423 printf("load_builtin_param_double: (name \"%s\") (alt_name = \"%s\") ", name, alt_name);
00424 fflush(stdout);
00425 }
00426
00427 if ((param = create_param(name, P_TYPE_DOUBLE, flags, engine_val, matrix, iv, ub, lb)) == NULL) {
00428 return OUTOFMEM_ERROR;
00429 }
00430
00431 if (PARAM_DEBUG == 2) {
00432 printf("created...");
00433 fflush(stdout);
00434 }
00435
00436
00437
00438 if (insert_builtin_param(param) < 0) {
00439 free_param(param);
00440 return ERROR;
00441 }
00442
00443 if (PARAM_DEBUG == 2) {
00444 printf("inserted...");
00445 fflush(stdout);
00446 }
00447
00448
00449
00450 if (alt_name != NULL) {
00451 insert_param_alt_name(param, alt_name);
00452
00453 if (PARAM_DEBUG == 2) {
00454 printf("alt_name inserted...");
00455 fflush(stdout);
00456 }
00457
00458
00459 }
00460
00461 if (PARAM_DEBUG == 2) printf("finished\n");
00462
00463 return SUCCESS;
00464 }
00465
00466
00467
00468
00469 param_t * new_param_double(char * name, short int flags, void * engine_val, void * matrix,
00470 double upper_bound, double lower_bound, double init_val) {
00471
00472 param_t * param;
00473 value_t iv, ub, lb;
00474
00475 iv.double_val = init_val;
00476 ub.double_val = upper_bound;
00477 lb.double_val = lower_bound;
00478
00479 if ((param = create_param(name, P_TYPE_DOUBLE, flags, engine_val, matrix,iv, ub, lb)) == NULL)
00480 return NULL;
00481
00482
00483
00484 return param;
00485 }
00486
00487
00488
00489 param_t * new_param_int(char * name, short int flags, void * engine_val,
00490 int upper_bound, int lower_bound, int init_val) {
00491
00492 param_t * param;
00493 value_t iv, ub, lb;
00494
00495 iv.int_val = init_val;
00496 ub.int_val = upper_bound;
00497 lb.int_val = lower_bound;
00498
00499 if ((param = create_param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb)) == NULL)
00500 return NULL;
00501
00502
00503
00504 return param;
00505 }
00506
00507
00508 param_t * new_param_bool(char * name, short int flags, void * engine_val,
00509 int upper_bound, int lower_bound, int init_val) {
00510
00511 param_t * param;
00512 value_t iv, ub, lb;
00513
00514 iv.bool_val = init_val;
00515 ub.bool_val = upper_bound;
00516 lb.bool_val = lower_bound;
00517
00518 if ((param = create_param(name, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb)) == NULL)
00519 return NULL;
00520
00521
00522
00523 return param;
00524 }
00525
00526
00527
00528 int load_builtin_param_int(char * name, void * engine_val, short int flags,
00529 int init_val, int upper_bound, int lower_bound, char * alt_name) {
00530
00531 param_t * param;
00532 value_t iv, ub, lb;
00533
00534 iv.int_val = init_val;
00535 ub.int_val = upper_bound;
00536 lb.int_val = lower_bound;
00537
00538 param = create_param(name, P_TYPE_INT, flags, engine_val, NULL, iv, ub, lb);
00539
00540 if (param == NULL) {
00541 return OUTOFMEM_ERROR;
00542 }
00543
00544 if (insert_builtin_param(param) < 0) {
00545 free_param(param);
00546 return ERROR;
00547 }
00548
00549 if (alt_name != NULL) {
00550 insert_param_alt_name(param, alt_name);
00551 }
00552
00553 return SUCCESS;
00554
00555 }
00556
00557
00558 int load_builtin_param_bool(char * name, void * engine_val, short int flags,
00559 int init_val, char * alt_name) {
00560
00561 param_t * param;
00562 value_t iv, ub, lb;
00563
00564 iv.int_val = init_val;
00565 ub.int_val = TRUE;
00566 lb.int_val = FALSE;
00567
00568 param = create_param(name, P_TYPE_BOOL, flags, engine_val, NULL, iv, ub, lb);
00569
00570 if (param == NULL) {
00571 return OUTOFMEM_ERROR;
00572 }
00573
00574 if (insert_builtin_param(param) < 0) {
00575 free_param(param);
00576 return ERROR;
00577 }
00578
00579 if (alt_name != NULL) {
00580 insert_param_alt_name(param, alt_name);
00581 }
00582
00583 return SUCCESS;
00584
00585 }
00586
00587
00588
00589
00590
00591 int is_valid_param_string(char * string) {
00592
00593 if (string == NULL)
00594 return FALSE;
00595
00596
00597 if( ((*string) >= 48) && ((*string) <= 57))
00598 return FALSE;
00599
00600
00601 if (*string == '.')
00602 return FALSE;
00603
00604 if (*string == '+')
00605 return FALSE;
00606
00607 if (*string == '-')
00608 return FALSE;
00609
00610
00611
00612 return TRUE;
00613
00614 }
00615
00616
00617 int insert_builtin_param(param_t * param) {
00618
00619 if (param == NULL)
00620 return FAILURE;
00621
00622 return splay_insert(param, param->name, builtin_param_tree);
00623 }
00624
00625
00626 int insert_param(param_t * param, splaytree_t * database) {
00627
00628 if (param == NULL)
00629 return FAILURE;
00630 if (database == NULL)
00631 return FAILURE;
00632
00633 return splay_insert(param, param->name, database);
00634 }
00635
00636
00637
00638
00639 void set_param(param_t * param, double val) {
00640
00641 switch (param->type) {
00642
00643 case P_TYPE_BOOL:
00644 if (val < 0)
00645 *((int*)param->engine_val) = 0;
00646 else if (val > 0)
00647 *((int*)param->engine_val) = 1;
00648 else
00649 *((int*)param->engine_val) = 0;
00650 break;
00651 case P_TYPE_INT:
00652
00653 val = floor(val);
00654 if (val < param->lower_bound.int_val)
00655 *((int*)param->engine_val) = param->lower_bound.int_val;
00656 else if (val > param->upper_bound.int_val)
00657 *((int*)param->engine_val) = param->upper_bound.int_val;
00658 else
00659 *((int*)param->engine_val) = val;
00660 break;
00661 case P_TYPE_DOUBLE:
00662
00663
00664
00665 if (val < param->lower_bound.double_val)
00666 *((double*)param->engine_val) = param->lower_bound.double_val;
00667 else if (val > param->upper_bound.double_val)
00668 *((double*)param->engine_val) = param->upper_bound.double_val;
00669 else
00670 *((double*)param->engine_val) = val;
00671 break;
00672 default:
00673 break;
00674
00675 }
00676
00677 return;
00678 }
00679
00680
00681
00682
00683
00684
00685 param_t * find_param_db(char * name, splaytree_t * database, int create_flag) {
00686
00687 param_t * param = NULL;
00688
00689
00690 if (name == NULL)
00691 return NULL;
00692 if (database == NULL)
00693 return NULL;
00694
00695
00696 param = (param_t *)splay_find(name, database);
00697
00698
00699 if (((param = (param_t *)splay_find(name, database)) == NULL) && (create_flag == TRUE)) {
00700
00701
00702 if (!is_valid_param_string(name))
00703 return NULL;
00704
00705
00706 if ((param = create_user_param(name)) == NULL)
00707 return NULL;
00708
00709
00710 if (splay_insert(param, param->name, database) < 0) {
00711 free_param(param);
00712 return NULL;
00713 }
00714
00715 }
00716
00717
00718 return param;
00719
00720 }
00721