speechd-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 04/10] Cleanup execution of commands in dummy


From: Boris Dušek
Subject: [PATCH 04/10] Cleanup execution of commands in dummy
Date: Mon, 23 Jul 2012 15:24:15 +0200

From: Boris Dus?ek <address@hidden>
To: address@hidden

---
 src/modules/dummy.c |   46 ++++++++++++++++------------------------------
 1 files changed, 16 insertions(+), 30 deletions(-)

diff --git a/src/modules/dummy.c b/src/modules/dummy.c
index 28fd5e4..6784cb8 100644
--- a/src/modules/dummy.c
+++ b/src/modules/dummy.c
@@ -229,51 +229,37 @@ void _dummy_child()
        sigset_t some_signals;
 
        int ret;
-       char *try1, *try2, *try3;
 
+#define PLAY_CMD(cmd) #cmd " " DATADIR "/dummy-message.wav > /dev/null 2> 
/dev/null"
+       static const char *const play_cmds[] = {
+               PLAY_CMD(play),
+               PLAY_CMD(aplay),
+               PLAY_CMD(paplay),
+               NULL
+       };
+#undef PLAY_CMD
+       const char *const *play_cmd = NULL;
        sigfillset(&some_signals);
        module_sigunblockusr(&some_signals);
 
        DBG("Entering child loop\n");
        /* Read the waiting data */
 
-       try1 =
-           g_strdup("play " DATADIR
-                    "/dummy-message.wav > /dev/null 2> /dev/null");
-       try2 =
-           g_strdup("aplay  " DATADIR
-                    "/dummy-message.wav > /dev/null 2> /dev/null");
-       try3 =
-           g_strdup("paplay " DATADIR
-                    "/dummy-message.wav > /dev/null 2> /dev/null");
-
-       DBG("child: synth commands = |%s|%s|%s|", try1, try2, try3);
        DBG("Speaking in child...");
        module_sigblockusr(&some_signals);
 
-       ret = system(try1);
-       DBG("Executed shell command '%s' returned with %d", try1, ret);
-       if ((ret != 0)) {
-               DBG("Execution failed, trying seccond command");
-               ret = system(try2);
-               DBG("Executed shell command '%s' returned with %d", try1, ret);
-               if ((ret != 0)) {
-                       DBG("Execution failed, trying third command");
-                       ret = system(try3);
-                       DBG("Executed shell command '%s' returned with %d",
-                           try1, ret);
-                       if ((ret != 0) && (ret != 256)) {
-                               DBG("Failed, giving up.");
-                       }
+       for (play_cmd = play_cmds; *play_cmd != NULL; ++play_cmd) {
+               DBG("Executing shell command '%s'", *play_cmd);
+               ret = system(*play_cmd);
+               if (ret != 0) {
+                       DBG("Executing command failed with return code %d", 
ret);
+               } else {
+                       break;
                }
        }
 
        module_sigunblockusr(&some_signals);
 
-       g_free(try1);
-       g_free(try2);
-       g_free(try3);
-
        DBG("Done, exiting from child.");
        exit(0);
 }
-- 
1.7.7.5 (Apple Git-26)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]