mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-09 03:35:41 +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;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue