param lib: Fix index used routine

This commit is contained in:
Lorenz Meier 2015-05-18 23:15:20 +02:00
parent 4345204064
commit c06ba047e2
2 changed files with 64 additions and 1 deletions

View File

@ -313,7 +313,7 @@ param_for_used_index(unsigned index)
* return the param value
*/
if (index == count) {
return (param_t)i;
return (param_t)(i * 8 + j);
}
count++;

View File

@ -62,6 +62,7 @@ static void do_save(const char *param_file_name);
static void do_load(const char *param_file_name);
static void do_import(const char *param_file_name);
static void do_show(const char *search_string);
static void do_show_index(const char *index, bool used_index);
static void do_show_print(void *arg, param_t param);
static void do_set(const char *name, const char *val, bool fail_on_not_found);
static void do_compare(const char *name, char *vals[], unsigned comparisons);
@ -168,6 +169,24 @@ param_main(int argc, char *argv[])
do_reset_nostart(NULL, 0);
}
}
if (!strcmp(argv[1], "index_used")) {
if (argc >= 3) {
do_show_index(argv[2], true);
} else {
warnx("no index provided");
return 1;
}
}
if (!strcmp(argv[1], "index")) {
if (argc >= 3) {
do_show_index(argv[2], false);
} else {
warnx("no index provided");
return 1;
}
}
}
errx(1, "expected a command, try 'load', 'import', 'show', 'set', 'compare', 'select' or 'save'");
@ -242,6 +261,50 @@ do_show(const char *search_string)
exit(0);
}
static void
do_show_index(const char *index, bool used_index)
{
char *end;
int i = strtol(index, &end, 10);
param_t param;
int32_t ii;
float ff;
if (used_index) {
param = param_for_used_index(i);
} else {
param = param_for_index(i);
}
if (param == PARAM_INVALID) {
return;
}
printf("index %d: %c %c %s [%d,%d] : ", i, (param_used(param) ? 'x' : ' '),
param_value_unsaved(param) ? '*' : (param_value_is_default(param) ? ' ' : '+'),
param_name(param), param_get_used_index(param), param_get_index(param));
switch (param_type(param)) {
case PARAM_TYPE_INT32:
if (!param_get(param, &ii)) {
printf("%d\n", ii);
}
break;
case PARAM_TYPE_FLOAT:
if (!param_get(param, &ff)) {
printf("%4.4f\n", (double)ff);
}
break;
default:
printf("<unknown type %d>\n", 0 + param_type(param));
}
exit(0);
}
static void
do_show_print(void *arg, param_t param)
{