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 <stdlib.h>
00031 #include <string.h>
00032
00033 #include "common.h"
00034 #include "fatal.h"
00035
00036 #include "param_types.h"
00037 #include "expr_types.h"
00038 #include "init_cond_types.h"
00039 #include "init_cond.h"
00040
00041 #include "splaytree_types.h"
00042 #include "splaytree.h"
00043 char init_cond_string_buffer[STRING_BUFFER_SIZE];
00044 int init_cond_string_buffer_index = 0;
00045
00046
00047 void init_cond_to_string(init_cond_t * init_cond);
00048
00049
00050 void free_init_cond(init_cond_t * init_cond) {
00051 free(init_cond);
00052 }
00053
00054
00055 void eval_init_cond(init_cond_t * init_cond) {
00056
00057 if (init_cond == NULL)
00058 return;
00059
00060
00061
00062
00063
00064
00065 init_cond->param->matrix_flag = 0;
00066 if (init_cond->param->type == P_TYPE_BOOL) {
00067 if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE BOOL)\n", init_cond->param->name, init_cond->init_val.bool_val);
00068 *((int*)init_cond->param->engine_val) = init_cond->init_val.bool_val;
00069 return;
00070 }
00071
00072
00073
00074 if (init_cond->param->type == P_TYPE_INT) {
00075 if (INIT_COND_DEBUG) printf("init_cond: %s = %d (TYPE INT)\n", init_cond->param->name, init_cond->init_val.int_val);
00076 *((int*)init_cond->param->engine_val) = init_cond->init_val.int_val;
00077 return;
00078 }
00079
00080
00081
00082 if (init_cond->param->type == P_TYPE_DOUBLE) {
00083 if (INIT_COND_DEBUG) printf("init_cond: %s = %f (TYPE DOUBLE)\n", init_cond->param->name, init_cond->init_val.double_val);
00084 *((double*)init_cond->param->engine_val) = init_cond->init_val.double_val;
00085 return;
00086 }
00087
00088
00089 return;
00090 }
00091
00092
00093 init_cond_t * new_init_cond(param_t * param, value_t init_val) {
00094
00095 init_cond_t * init_cond;
00096
00097 init_cond = (init_cond_t*)malloc(sizeof(init_cond_t));
00098
00099 if (init_cond == NULL)
00100 return NULL;
00101
00102 init_cond->param = param;
00103 init_cond->init_val = init_val;
00104 return init_cond;
00105 }
00106
00107
00108 void init_cond_to_string(init_cond_t * init_cond) {
00109
00110 int string_length;
00111 char string[MAX_TOKEN_SIZE];
00112
00113 if (init_cond == NULL)
00114 return;
00115
00116
00117 switch (init_cond->param->type) {
00118
00119 case P_TYPE_BOOL:
00120 sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.bool_val);
00121 break;
00122 case P_TYPE_INT:
00123 sprintf(string, "%s=%d\n", init_cond->param->name, init_cond->init_val.int_val);
00124 break;
00125 case P_TYPE_DOUBLE:
00126 sprintf(string, "%s=%f\n", init_cond->param->name, init_cond->init_val.double_val);
00127 break;
00128 default:
00129 return;
00130 }
00131
00132
00133 string_length = strlen(string);
00134
00135
00136 if ((init_cond_string_buffer_index + string_length + 1) > (STRING_BUFFER_SIZE - 1))
00137 return;
00138
00139
00140
00141 strncpy(init_cond_string_buffer + init_cond_string_buffer_index, string, string_length);
00142
00143
00144
00145 init_cond_string_buffer_index+= string_length + 1;
00146
00147 }
00148
00149
00150 char * create_init_cond_string_buffer(splaytree_t * init_cond_tree) {
00151
00152 if (init_cond_tree == NULL)
00153 return NULL;
00154
00155 init_cond_string_buffer_index = 0;
00156
00157 splay_traverse(init_cond_to_string, init_cond_tree);
00158
00159 return init_cond_string_buffer;
00160
00161 }