diff --git a/axfer/subcmd-list.c b/axfer/subcmd-list.c index 0876e07..f8f0952 100644 --- a/axfer/subcmd-list.c +++ b/axfer/subcmd-list.c @@ -225,30 +225,37 @@ static bool decide_operation(int argc, char *const *argv, enum list_op *op) return false; } -int subcmd_list(int argc, char *const *argv, snd_pcm_stream_t direction) +static int detect_operation(int argc, char *const *argv, enum list_op *op) { - static const struct { - const char *const category; - int (*func)(snd_pcm_stream_t direction); - } ops[] = { - {"device", list_devices}, - {"pcm", list_pcms}, + static const char *const ops[] = { + [LIST_OP_DEVICE] = "device", + [LIST_OP_PCM] = "pcm", }; - enum list_op op; int i; - int err; - // Renewed command system. - if (argc > 2 && !strcmp(argv[1], "list")) { - for (i = 0; i < ARRAY_SIZE(ops); ++i) { - if (!strcmp(ops[i].category, argv[2])) - return ops[i].func(direction); + if (strcmp(argv[1], "list") || argc < 3) + return false; + + for (i = 0; i < ARRAY_SIZE(ops); ++i) { + if (!strcmp(argv[2], ops[i])) { + *op = i; + return true; } } - if (!decide_operation(argc, argv, &op)) { - err = -EINVAL; - op = LIST_OP_HELP; + return false; +} + +int subcmd_list(int argc, char *const *argv, snd_pcm_stream_t direction) +{ + enum list_op op = LIST_OP_HELP; + int err = 0; + + // Renewed command system. + if (argc > 1) { + if (!detect_operation(argc, argv, &op) && + !decide_operation(argc, argv, &op)) + err = -EINVAL; } if (op == LIST_OP_DEVICE)