mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-09 03:25:42 +01:00
axfer: truncate parsed arguments before operating subcommand
When subcommands are operated, top-most two arguments are already parsed in renewed command system, thus they're useless. Besides, they're possible to be parsed by getopt_long(3). This commit truncates these options before entering subcommand operation. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
a64a2371fb
commit
b8833717bb
3 changed files with 12 additions and 15 deletions
|
@ -251,8 +251,14 @@ int main(int argc, char *const *argv)
|
|||
// The second option should be either 'capture' or 'direction'
|
||||
// if subcommand is neither 'version' nor 'help'.
|
||||
if (subcmd != SUBCMD_VERSION && subcmd != SUBCMD_HELP) {
|
||||
if (!detect_direction(argc, argv, &direction))
|
||||
if (!detect_direction(argc, argv, &direction)) {
|
||||
subcmd = SUBCMD_HELP;
|
||||
} else {
|
||||
// argv[0] is needed for unparsed option to use
|
||||
// getopt_long(3).
|
||||
argc -= 2;
|
||||
argv += 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -233,11 +233,11 @@ static int detect_operation(int argc, char *const *argv, enum list_op *op)
|
|||
};
|
||||
int i;
|
||||
|
||||
if (strcmp(argv[1], "list") || argc < 3)
|
||||
if (argc < 2)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(ops); ++i) {
|
||||
if (!strcmp(argv[2], ops[i])) {
|
||||
if (!strcmp(argv[1], ops[i])) {
|
||||
*op = i;
|
||||
return true;
|
||||
}
|
||||
|
@ -252,11 +252,9 @@ int subcmd_list(int argc, char *const *argv, snd_pcm_stream_t direction)
|
|||
int err = 0;
|
||||
|
||||
// Renewed command system.
|
||||
if (argc > 1) {
|
||||
if (!detect_operation(argc, argv, &op) &&
|
||||
!decide_operation(argc, argv, &op))
|
||||
err = -EINVAL;
|
||||
}
|
||||
if (!detect_operation(argc, argv, &op) &&
|
||||
!decide_operation(argc, argv, &op))
|
||||
err = -EINVAL;
|
||||
|
||||
if (op == LIST_OP_DEVICE)
|
||||
err = list_devices(direction);
|
||||
|
|
|
@ -435,13 +435,6 @@ int subcmd_transfer(int argc, char *const *argv, snd_pcm_stream_t direction)
|
|||
uint64_t actual_frame_count = 0;
|
||||
int err = 0;
|
||||
|
||||
// Renewed command system.
|
||||
if (argc > 2 && !strcmp(argv[1], "transfer")) {
|
||||
// Go ahead to parse file paths properly.
|
||||
--argc;
|
||||
++argv;
|
||||
}
|
||||
|
||||
err = prepare_signal_handler(&ctx);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
|
Loading…
Reference in a new issue