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 |   45 +++++++++++++++++++++++++++++++--------------
 src/main.c    |    4 ++--
 2 files changed, 33 insertions(+), 16 deletions(-)

diff --git a/src/command.c b/src/command.c
index 4dafcf4..2adc4c9 100644
--- a/src/command.c
+++ b/src/command.c
@@ -368,30 +368,47 @@ 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))
 {
+       bool show_outputs = false;
        int arg;
 
-        if( ! parse_int( argv[0], &arg ) || arg <= 0 ) {
-               DIE( "Not a positive integer\n" );
+       if (!mpd_command_list_begin(conn, false)) {
+               printErrorAndExit(conn);
+       }
+
+       for (int i = argc; i; --i, ++argv) {
+               if (!parse_int(*argv, &arg) || arg <= 0) {
+                       fprintf(stderr, "%s: not a positive integer\n", *argv);
+               } else {
+                       /* We decrement by 1 to make it natural to the user. */
+                       callback(conn, arg - 1);
+                       show_outputs = true;
+               }
+       }
+
+       if (!mpd_command_list_end(conn) || !mpd_response_finish(conn)) {
+               printErrorAndExit(conn);
+       }
+
+       if (show_outputs) {
+               cmd_outputs(0, NULL, conn);
        }
+       return 0;
+}
 
-       mpd_run_enable_output(conn, arg - 1);
-       return cmd_outputs(0, NULL, conn);
+int
+cmd_enable(int argc, char **argv, struct mpd_connection *conn)
+{
+       return enable_disable(argc, argv, conn, mpd_send_enable_output);
 }
 
 int
 cmd_disable(mpd_unused int argc, char **argv, struct mpd_connection *conn)
 {
-       int arg;
-
-        if( ! parse_int( argv[0], &arg ) || arg <= 0 ) {
-               DIE( "Not a positive integer\n" );
-       }
-
-       mpd_run_disable_output(conn, arg - 1);
-       return cmd_outputs(0, NULL, conn);
+       return enable_disable(argc, argv, conn, mpd_send_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

Reply via email to