mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-11-10 05:55:42 +01:00
axfer: use second argument in command line for transmission direction
In renewed command system, axfer uses first argument for subcommand. In popular subcommand such as transfer, transmission direction is required. At present, some options in aplay(1) are used for this purpose however it's understandable to use second argument for this purpose. This commit uses second argument as fixed position to indicate direction for renewed command system. Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp> Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
parent
81a275acf9
commit
1d5f3e61ed
1 changed files with 60 additions and 18 deletions
70
axfer/main.c
70
axfer/main.c
|
@ -72,12 +72,6 @@ static void print_help(void)
|
|||
|
||||
static void decide_subcmd(int argc, char *const *argv, enum subcmds *subcmd)
|
||||
{
|
||||
static const char *const subcmds[] = {
|
||||
[SUBCMD_TRANSFER] = "transfer",
|
||||
[SUBCMD_LIST] = "list",
|
||||
[SUBCMD_HELP] = "help",
|
||||
[SUBCMD_VERSION] = "version",
|
||||
};
|
||||
static const struct {
|
||||
const char *const name;
|
||||
enum subcmds subcmd;
|
||||
|
@ -103,14 +97,6 @@ static void decide_subcmd(int argc, char *const *argv, enum subcmds *subcmd)
|
|||
return;
|
||||
}
|
||||
|
||||
// sub-command system.
|
||||
for (i = 0; i < ARRAY_SIZE(subcmds); ++i) {
|
||||
if (!strcmp(argv[1], subcmds[i])) {
|
||||
*subcmd = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Original command system. For long options.
|
||||
for (i = 0; i < ARRAY_SIZE(long_opts); ++i) {
|
||||
for (j = 0; j < argc; ++j) {
|
||||
|
@ -203,16 +189,72 @@ static bool decide_direction(int argc, char *const *argv,
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool detect_subcmd(int argc, char *const *argv, enum subcmds *subcmd)
|
||||
{
|
||||
static const char *const subcmds[] = {
|
||||
[SUBCMD_TRANSFER] = "transfer",
|
||||
[SUBCMD_LIST] = "list",
|
||||
[SUBCMD_HELP] = "help",
|
||||
[SUBCMD_VERSION] = "version",
|
||||
};
|
||||
int i;
|
||||
|
||||
if (argc < 2)
|
||||
return false;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(subcmds); ++i) {
|
||||
if (!strcmp(argv[1], subcmds[i])) {
|
||||
*subcmd = i;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool detect_direction(int argc, char *const *argv,
|
||||
snd_pcm_stream_t *direction)
|
||||
{
|
||||
if (argc < 3)
|
||||
return false;
|
||||
|
||||
if (!strcmp(argv[2], "capture")) {
|
||||
*direction = SND_PCM_STREAM_CAPTURE;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!strcmp(argv[2], "playback")) {
|
||||
*direction = SND_PCM_STREAM_PLAYBACK;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int main(int argc, char *const *argv)
|
||||
{
|
||||
snd_pcm_stream_t direction;
|
||||
enum subcmds subcmd;
|
||||
int err = 0;
|
||||
|
||||
// For compatibility to aplay(1) implementation.
|
||||
if (strstr(argv[0], "arecord") == argv[0] + strlen(argv[0]) - 7 ||
|
||||
strstr(argv[0], "aplay") == argv[0] + strlen(argv[0]) - 5) {
|
||||
if (!decide_direction(argc, argv, &direction))
|
||||
subcmd = SUBCMD_HELP;
|
||||
else
|
||||
decide_subcmd(argc, argv, &subcmd);
|
||||
} else {
|
||||
// The first option should be one of subcommands.
|
||||
if (!detect_subcmd(argc, argv, &subcmd))
|
||||
subcmd = SUBCMD_HELP;
|
||||
// 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))
|
||||
subcmd = SUBCMD_HELP;
|
||||
}
|
||||
}
|
||||
|
||||
if (subcmd == SUBCMD_TRANSFER)
|
||||
err = subcmd_transfer(argc, argv, direction);
|
||||
|
|
Loading…
Reference in a new issue