On 12/05/2016 10:05, Andrew Jones wrote: > On Thu, May 12, 2016 at 09:19:08AM +0200, Andrew Jones wrote: >> On Wed, May 11, 2016 at 10:55:14PM +0200, Radim Krčmář wrote: >>> int main(int argc, char **argv) >>> @@ -115,33 +123,12 @@ int main(int argc, char **argv) >>> >>> report_prefix_push("rtas"); >>> >>> - if (argc < 2) >>> - report_abort("no test specified"); >>> - >>> - report_prefix_push(argv[1]); >>> - >>> - if (strcmp(argv[1], "get-time-of-day") == 0) { >>> - >>> - len = parse_keyval(argv[2], &val); >>> - if (len == -1) { >>> - printf("Missing parameter \"date\"\n"); >>> - abort(); >>> - } >>> - argv[2][len] = '\0'; >>> - >>> + if (parse_keyval(argc, argv, "get-time-of-day", &val)) >>> check_get_time_of_day(val); >>> >>> - } else if (strcmp(argv[1], "set-time-of-day") == 0) { >>> - >>> + if (find_key(argc, argv, "set-time-of-day")) >>> check_set_time_of_day(); >>> >>> - } else { >>> - printf("Unknown subtest\n"); >>> - abort(); >>> - } >>> - >>> - report_prefix_pop(); >>> - >> >> Also a nice cleanup. We could have kept the missing parameter abort >> with something like >> >> if (find_key(argc, argv, "get-time-of-day")) { >> if (!parse_keyval(argc, argv, "get-time-of-day", &val)) { >> printf("Missing parameter \"date\"\n"); >> abort(); >> } >> check_get_time_of_day(val); >> } > > Hmm, actually the above wouldn't work with the current > find_key implementation. Maybe we should change it to > just check for null? > > bool find_key(int argc, char **argv, char *key) > { > return find_keyval(argc, argv, key) != NULL; > } > > And change the documentation to explain it looks for @key > by itself, or with a paired =val, but doesn't parse val. I don't know if it can help, but instead of creating our own API, perhaps we can implement getopt() and getopt_long() and use them? Or is it over-engineered? Laurent -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html