param command: Fix error handling if param is not found

This commit is contained in:
Lorenz Meier 2015-06-25 09:28:22 +02:00
parent 3bad91dd3b
commit 475c28803e
1 changed files with 13 additions and 12 deletions

View File

@ -62,8 +62,8 @@ __EXPORT int param_main(int argc, char *argv[]);
static int do_save(const char *param_file_name);
static int do_load(const char *param_file_name);
static int 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 int do_show(const char *search_string);
static int do_show_index(const char *index, bool used_index);
static void do_show_print(void *arg, param_t param);
static int do_set(const char *name, const char *val, bool fail_on_not_found);
static int do_compare(const char *name, char *vals[], unsigned comparisons);
@ -121,12 +121,10 @@ param_main(int argc, char *argv[])
if (!strcmp(argv[1], "show")) {
if (argc >= 3) {
do_show(argv[2]);
return 0;
return do_show(argv[2]);
} else {
do_show(NULL);
return 0;
return do_show(NULL);
}
}
@ -177,7 +175,7 @@ param_main(int argc, char *argv[])
if (!strcmp(argv[1], "index_used")) {
if (argc >= 3) {
do_show_index(argv[2], true);
return do_show_index(argv[2], true);
} else {
warnx("no index provided");
return 1;
@ -186,7 +184,7 @@ param_main(int argc, char *argv[])
if (!strcmp(argv[1], "index")) {
if (argc >= 3) {
do_show_index(argv[2], false);
return do_show_index(argv[2], false);
} else {
warnx("no index provided");
return 1;
@ -265,15 +263,17 @@ do_import(const char *param_file_name)
return 0;
}
static void
static int
do_show(const char *search_string)
{
printf("Symbols: x = used, + = saved, * = unsaved\n");
param_foreach(do_show_print, (char *)search_string, false, false);
printf("\n %u parameters total, %u used.\n", param_count(), param_count_used());
return 0;
}
static void
static int
do_show_index(const char *index, bool used_index)
{
char *end;
@ -289,7 +289,8 @@ do_show_index(const char *index, bool used_index)
}
if (param == PARAM_INVALID) {
return;
warnx("param not found for index %u", i);
return 1;
}
printf("index %d: %c %c %s [%d,%d] : ", i, (param_used(param) ? 'x' : ' '),
@ -314,7 +315,7 @@ do_show_index(const char *index, bool used_index)
printf("<unknown type %d>\n", 0 + param_type(param));
}
exit(0);
return 0;
}
static void