From: Michal Nazarewicz <min...@mina86.com> This commit changes enable and disable commands in such a way that they accept more then one output number. This allows enabling or disabling multiple outputs with one mpc command. --- src/command.c | 37 ++++++++++++++++++++++--------------- src/main.c | 4 ++-- 2 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/src/command.c b/src/command.c index 4dafcf4..3239517 100644 --- a/src/command.c +++ b/src/command.c @@ -368,30 +368,37 @@ cmd_outputs(mpd_unused int argc, mpd_unused char **argv, struct mpd_connection * return( 0 ); } -int -cmd_enable(mpd_unused int argc, char **argv, struct mpd_connection *conn) +static int enable_disable(int argc, char **argv, struct mpd_connection *conn, + bool (*callback)(struct mpd_connection *conn, unsigned id)) { - int arg; + int arg, ret = 0; - if( ! parse_int( argv[0], &arg ) || arg <= 0 ) { - DIE( "Not a positive integer\n" ); + for (int i = argc; i; --i, ++argv) { + if (!parse_int(*argv, &arg) || arg < 0) { + fprintf(stderr, "%s: not a positive integer\n", *argv); + ++ret; + } else { + /* We decrement by 1 to make it natural to the user. */ + callback(conn, arg - 1); + } } - mpd_run_enable_output(conn, arg - 1); - return cmd_outputs(0, NULL, conn); + if (ret != argc) { + cmd_outputs(0, NULL, conn); + } + return ret; } int -cmd_disable(mpd_unused int argc, char **argv, struct mpd_connection *conn) +cmd_enable(int argc, char **argv, struct mpd_connection *conn) { - int arg; - - if( ! parse_int( argv[0], &arg ) || arg <= 0 ) { - DIE( "Not a positive integer\n" ); - } + return enable_disable(argc, argv, conn, mpd_run_enable_output); +} - mpd_run_disable_output(conn, arg - 1); - return cmd_outputs(0, NULL, conn); +int +cmd_disable(mpd_unused int argc, char **argv, struct mpd_connection *conn) +{ + return enable_disable(argc, argv, conn, mpd_run_disable_output); } int cmd_play ( int argc, char ** argv, struct mpd_connection *conn ) diff --git a/src/main.c b/src/main.c index e4b7db5..36868e9 100644 --- a/src/main.c +++ b/src/main.c @@ -73,8 +73,8 @@ static struct command { {"seek", 1, 1, 0, cmd_seek, "[+-][HH:MM:SS]|<0-100>%", "Seeks to the specified position"}, {"clear", 0, 0, 0, cmd_clear, "", "Clear the current playlist"}, {"outputs", 0, 0, 0, cmd_outputs, "", "Show the current outputs"}, - {"enable", 1, 1, 0, cmd_enable, "<output #>", "Enable a output"}, - {"disable", 1, 1, 0, cmd_disable, "<output #>", "Disable a output"}, + {"enable", 1, -1, 0, cmd_enable, "<output #> [...]", "Enable output(s)"}, + {"disable", 1, -1, 0, cmd_disable, "<output #> [...]", "Disable output(s)"}, {"shuffle", 0, 0, 0, cmd_shuffle, "", "Shuffle the current playlist"}, {"move", 2, 2, 0, cmd_move, "<from> <to>", "Move song in playlist"}, {"playlist", 0, 0, 0, cmd_playlist, "", "Print the current playlist"}, -- 1.7.7.3 ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Musicpd-dev-team mailing list Musicpd-dev-team@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/musicpd-dev-team