mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-10 06:45:42 +01:00
axfer: apply refactoring in list subcommand for new command system
This commit splits option parser for new command system into a function for readability. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
ac3e1d904b
commit
81a275acf9
1 changed files with 24 additions and 17 deletions
|
@ -225,30 +225,37 @@ static bool decide_operation(int argc, char *const *argv, enum list_op *op)
|
||||||
return false;
|
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 {
|
static const char *const ops[] = {
|
||||||
const char *const category;
|
[LIST_OP_DEVICE] = "device",
|
||||||
int (*func)(snd_pcm_stream_t direction);
|
[LIST_OP_PCM] = "pcm",
|
||||||
} ops[] = {
|
|
||||||
{"device", list_devices},
|
|
||||||
{"pcm", list_pcms},
|
|
||||||
};
|
};
|
||||||
enum list_op op;
|
|
||||||
int i;
|
int i;
|
||||||
int err;
|
|
||||||
|
|
||||||
// Renewed command system.
|
if (strcmp(argv[1], "list") || argc < 3)
|
||||||
if (argc > 2 && !strcmp(argv[1], "list")) {
|
return false;
|
||||||
for (i = 0; i < ARRAY_SIZE(ops); ++i) {
|
|
||||||
if (!strcmp(ops[i].category, argv[2]))
|
for (i = 0; i < ARRAY_SIZE(ops); ++i) {
|
||||||
return ops[i].func(direction);
|
if (!strcmp(argv[2], ops[i])) {
|
||||||
|
*op = i;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!decide_operation(argc, argv, &op)) {
|
return false;
|
||||||
err = -EINVAL;
|
}
|
||||||
op = LIST_OP_HELP;
|
|
||||||
|
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)
|
if (op == LIST_OP_DEVICE)
|
||||||
|
|
Loading…
Reference in a new issue