1168 |
|
|
1169 |
void slv_destroy_parms(slv_parameters_t *p) { |
void slv_destroy_parms(slv_parameters_t *p) { |
1170 |
int32 i,j; |
int32 i,j; |
1171 |
for (i = 0; i < p->num_parms; i++) { |
for(i = 0; i < p->num_parms; i++){ |
1172 |
switch(p->parms[i].type) { |
switch(p->parms[i].type) { |
1173 |
case char_parm: |
case char_parm: |
1174 |
ascfree(p->parms[i].info.c.value); |
ASC_FREE(p->parms[i].info.c.value); |
1175 |
for (j = 0; j < p->parms[i].info.c.high; j++) { |
for (j = 0; j < p->parms[i].info.c.high; j++) { |
1176 |
ascfree(p->parms[i].info.c.argv[j]); |
ASC_FREE(p->parms[i].info.c.argv[j]); |
1177 |
} |
} |
1178 |
ascfree(p->parms[i].info.c.argv); |
ASC_FREE(p->parms[i].info.c.argv); |
1179 |
/* FALL THROUGH */ |
/* FALL THROUGH */ |
1180 |
case int_parm: |
case int_parm: |
1181 |
case bool_parm: |
case bool_parm: |
1182 |
case real_parm: |
case real_parm: |
1183 |
ascfree(p->parms[i].name); |
ASC_FREE(p->parms[i].name); |
1184 |
ascfree(p->parms[i].interface_label); |
ASC_FREE(p->parms[i].interface_label); |
1185 |
ascfree(p->parms[i].description); |
ASC_FREE(p->parms[i].description); |
1186 |
break; |
break; |
1187 |
default: |
default: |
1188 |
ERROR_REPORTER_NOLINE(ASC_PROG_WARNING,"Unrecognized parameter type in slv_destroy_parms."); |
ERROR_REPORTER_NOLINE(ASC_PROG_WARNING,"Unrecognized parameter type in slv_destroy_parms."); |
1189 |
} |
} |
1190 |
} |
} |
1191 |
if (p->parms && p->dynamic_parms) { |
if (p->parms && p->dynamic_parms) { |
1192 |
ascfree(p->parms); |
ASC_FREE(p->parms); |
1193 |
} |
} |
1194 |
|
CONSOLE_DEBUG("Destroyed slv_parameters_t"); |
1195 |
|
} |
1196 |
|
|
1197 |
|
/*------------------------------------------------------------------------------ |
1198 |
|
IMPROVED (says I) FUNCTIONS FOR DECLARING SOLVER PARAMETERS -- JP |
1199 |
|
*/ |
1200 |
|
/** @page solver-parameters |
1201 |
|
|
1202 |
|
Additional info on new solver parameter routines. This routine attempts |
1203 |
|
to make declaration of new parameters possible with simple syntax, without |
1204 |
|
requiring changes to the underlying data structure. Also aim to eliminate |
1205 |
|
the extensive #defines used in the old approach, and eliminate the risk of |
1206 |
|
messing up the parameter list by forgetting to update something. |
1207 |
|
|
1208 |
|
Usage: |
1209 |
|
1. declare IDs for the parameters you'll be using via an 'enum' |
1210 |
|
(last ID is XXXX_PARAMS_COUNT) |
1211 |
|
2. allocate space for your slv_parameters_t::parms of size XXXX_PARAMS_COUNT |
1212 |
|
3. for each parameter, call slv_param_* as follows: |
1213 |
|
|
1214 |
|
slv_param_int(p,XXXX_PARAM_NAME,(SlvParameterInitInt){ |
1215 |
|
{"codename","guiname",3 (==guipagenum) "description"} |
1216 |
|
,1 (==default value) ,0 (==min), 100 (==max) |
1217 |
|
}); |
1218 |
|
|
1219 |
|
4. to access a value from your code, use SLV_PARAM_BOOL(p,XXX_PARAM_NAME) etc |
1220 |
|
(as defined in slv_common.h) |
1221 |
|
|
1222 |
|
See example stuff in ida.c |
1223 |
|
*/ |
1224 |
|
|
1225 |
|
static void slv_define_param_meta(struct slv_parameter *p1, const SlvParameterInitMeta *meta, const int index){ |
1226 |
|
/* copy the codename, guiname and description */ |
1227 |
|
asc_assert(meta!=NULL); |
1228 |
|
asc_assert(p1!=NULL); |
1229 |
|
p1->name = ascstrdup(meta->codename); |
1230 |
|
p1->interface_label = ascstrdup(meta->guiname); |
1231 |
|
p1->description = ascstrdup(meta->description); |
1232 |
|
p1->display = meta->guipagenum; |
1233 |
|
|
1234 |
|
/* record the index of this parameter */ |
1235 |
|
p1->number = index; |
1236 |
|
} |
1237 |
|
|
1238 |
|
int slv_param_int(slv_parameters_t *p, const int index |
1239 |
|
,const SlvParameterInitInt init |
1240 |
|
){ |
1241 |
|
struct slv_parameter *p1; |
1242 |
|
if(p == NULL)return -1; |
1243 |
|
p1 = &(p->parms[index]); |
1244 |
|
|
1245 |
|
p1->type = int_parm; |
1246 |
|
p1->info.i.value = init.val; |
1247 |
|
p1->info.i.low = init.low; |
1248 |
|
p1->info.i.high = init.high; |
1249 |
|
|
1250 |
|
slv_define_param_meta(p1, &(init.meta), index); |
1251 |
|
return ++(p->num_parms); |
1252 |
|
} |
1253 |
|
|
1254 |
|
int slv_param_bool(slv_parameters_t *p, const int index |
1255 |
|
,const SlvParameterInitBool init |
1256 |
|
){ |
1257 |
|
struct slv_parameter *p1; |
1258 |
|
if(p == NULL)return -1; |
1259 |
|
p1 = &(p->parms[index]); |
1260 |
|
|
1261 |
|
p1->type = bool_parm; |
1262 |
|
p1->info.b.value = init.val; |
1263 |
|
p1->info.b.low = 0; |
1264 |
|
p1->info.b.high = 1; |
1265 |
|
|
1266 |
|
slv_define_param_meta(p1, &(init.meta), index); |
1267 |
|
return ++(p->num_parms); |
1268 |
|
} |
1269 |
|
|
1270 |
|
int slv_param_real(slv_parameters_t *p, const int index |
1271 |
|
,const SlvParameterInitReal init |
1272 |
|
){ |
1273 |
|
struct slv_parameter *p1; |
1274 |
|
|
1275 |
|
if(p == NULL)return -1; |
1276 |
|
p1 = &(p->parms[index]); |
1277 |
|
|
1278 |
|
p1->type = real_parm; |
1279 |
|
p1->info.r.value = init.val; |
1280 |
|
p1->info.r.low = init.low; |
1281 |
|
p1->info.r.high = init.high; |
1282 |
|
|
1283 |
|
slv_define_param_meta(p1, &(init.meta), index); |
1284 |
|
return ++(p->num_parms); |
1285 |
|
} |
1286 |
|
|
1287 |
|
int slv_param_char(slv_parameters_t *p, const int index |
1288 |
|
,const SlvParameterInitChar init |
1289 |
|
){ |
1290 |
|
int i, noptions; |
1291 |
|
struct slv_parameter *p1; |
1292 |
|
if(p == NULL)return -1; |
1293 |
|
p1 = &(p->parms[index]); |
1294 |
|
|
1295 |
|
/* find the length by hunting for the NULL at the end */ |
1296 |
|
for(i=0; init.options[i]!=NULL; ++i); |
1297 |
|
noptions = i; |
1298 |
|
CONSOLE_DEBUG("THERE ARE %d CHAR OPTIONS IN PARAMETER '%s'", noptions, init.meta.codename); |
1299 |
|
|
1300 |
|
p1->info.c.high = noptions; |
1301 |
|
p1->info.c.value = strdup(init.val); |
1302 |
|
p1->info.c.argv = ASC_NEW_ARRAY(char *,noptions); |
1303 |
|
|
1304 |
|
for(i = 0; i < noptions; ++i){ |
1305 |
|
p1->info.c.argv[i] = ascstrdup(init.options[i]); |
1306 |
|
} |
1307 |
|
|
1308 |
|
slv_define_param_meta(p1, &(init.meta), index); |
1309 |
|
return ++(p->num_parms); |
1310 |
} |
} |
1311 |
|
|
1312 |
int32 slv_define_parm(slv_parameters_t *p, |
int32 slv_define_parm(slv_parameters_t *p, |
1391 |
return p->num_parms; |
return p->num_parms; |
1392 |
} |
} |
1393 |
|
|
1394 |
|
/*--------------------------------*/ |
1395 |
|
|
1396 |
|
|
1397 |
int slv_get_selected_solver(slv_system_t sys) |
int slv_get_selected_solver(slv_system_t sys) |
1398 |
{ |
{ |
1399 |
if (sys!=NULL) return sys->solver; |
if (sys!=NULL) return sys->solver; |
1468 |
} |
} |
1469 |
if (parameters->whose != sys->solver) { |
if (parameters->whose != sys->solver) { |
1470 |
ERROR_REPORTER_NOLINE(ASC_PROG_ERROR, |
ERROR_REPORTER_NOLINE(ASC_PROG_ERROR, |
1471 |
"slv_set_parameters can give parameters from one client to a different client."); |
"slv_set_parameters cannot pass parameters from one solver to a" |
1472 |
|
" another."); |
1473 |
return; |
return; |
1474 |
} |
} |
1475 |
SF(sys,setparam)(sys,sys->ct,parameters); |
SF(sys,setparam)(sys,sys->ct,parameters); |