Commit c06ba047 authored by Lorenz Meier's avatar Lorenz Meier
Browse files

param lib: Fix index used routine

parent 43452040
......@@ -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++;
......
......@@ -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)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment