speechd-discuss
[Top][All Lists]
Advanced

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

[PATCH 2/3] Cleanup execution of commands in dummy


From: Boris Dušek
Subject: [PATCH 2/3] Cleanup execution of commands in dummy
Date: Tue, 24 Jul 2012 22:13:04 +0200

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

Current code that tries to play the dummy message using 3 command
line players is ugly and unmaintainable. Generalize it by storing
the 3 commands in an array and iterating over the array to execute
them.
---
 src/modules/dummy.c |   48 +++++++++++++++++-------------------------------
 1 files changed, 17 insertions(+), 31 deletions(-)

diff --git a/src/modules/dummy.c b/src/modules/dummy.c
index 28fd5e4..984e6f9 100644
--- a/src/modules/dummy.c
+++ b/src/modules/dummy.c
@@ -5,7 +5,7 @@
  * A simplific output module that just tries to play an
  * an error message in various ways.
  *
- * Copyright (C) 2008 Brailcom, o.p.s.
+ * Copyright (C) 2008, 2012 Brailcom, o.p.s.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License as published by
@@ -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]