]> git.tue.mpg.de Git - paraslash.git/commitdiff
Simplify i9e_line_handler.
authorAndre Noll <maan@systemlinux.org>
Tue, 2 Apr 2013 14:30:06 +0000 (14:30 +0000)
committerAndre Noll <maan@systemlinux.org>
Sat, 8 Jun 2013 12:31:01 +0000 (14:31 +0200)
The line handlers of all three users of the i9e API (play, client
and audioc) return immediately if the passed line is NULL or the
empty string. Hence we may call the line handler only if there is a
non-empty line to dispatch.

Moving the check for a non-empty line to generic i9e code simplifies
the three line handlers a bit and avoids code duplication.

audioc.c
client.c
interactive.c
play.c

index f68aee542e1ed2ef48694eae309112cccd3314f2..b2c6786a6573ba2636606cde09403e38a590e0c6 100644 (file)
--- a/audioc.c
+++ b/audioc.c
@@ -165,8 +165,6 @@ static int audioc_i9e_line_handler(char *line)
 {
        char *args = NULL;
        int ret;
-       if (!line || !*line)
-               return 0;
 
        PARA_DEBUG_LOG("line: %s\n", line);
        ret = create_argv(line, " ", &conf.inputs);
index 90dc432b8829426cd9d4ce081e4f8e20a5fb194e..c47dafe8afd300183c8d3853f9da7e0198b4c88d 100644 (file)
--- a/client.c
+++ b/client.c
@@ -445,9 +445,7 @@ static int client_i9e_line_handler(char *line)
        int ret;
 
        client_disconnect(ct);
-       if (!line || !*line)
-               return 0;
-       PARA_DEBUG_LOG("line handler: %s\n", line);
+       PARA_DEBUG_LOG("line: %s\n", line);
        ret = make_client_argv(line);
        if (ret < 0)
                return ret;
index ef6fc7620195188db8ccf491176142b29690a9ba..6d30e12aae63503061114e18b3e1fc7b4a118ec8 100644 (file)
@@ -290,21 +290,25 @@ static bool input_available(void)
 static void i9e_line_handler(char *line)
 {
        int ret;
-       struct btr_node *dummy = btr_new_node(&(struct btr_node_description)
+       struct btr_node *dummy;
+
+       if (!line) {
+               i9ep->input_eof = true;
+               return;
+       }
+       if (!*line)
+               goto free_line;
+       rl_set_prompt("");
+       dummy = btr_new_node(&(struct btr_node_description)
                EMBRACE(.name = "dummy line handler"));
        i9e_attach_to_stdout(dummy);
-
        ret = i9ep->ici->line_handler(line);
        if (ret < 0)
                PARA_WARNING_LOG("%s\n", para_strerror(-ret));
-       rl_set_prompt("");
-       if (line) {
-               if (*line)
-                       add_history(line);
-               free(line);
-       } else
-               i9ep->input_eof = true;
+       add_history(line);
        btr_remove_node(&dummy);
+free_line:
+       free(line);
 }
 
 static int i9e_post_select(__a_unused struct sched *s, __a_unused struct task *t)
diff --git a/play.c b/play.c
index 2cb0536dfc410eae63c0484ec9bd5535a50fe5ae..02128af0582aba2f724d70a459b427b096797a39 100644 (file)
--- a/play.c
+++ b/play.c
@@ -990,15 +990,7 @@ out:
 
 static int play_i9e_line_handler(char *line)
 {
-       struct play_task *pt = &play_task;
-       int ret;
-
-       if (line == NULL || !*line)
-               return 0;
-       ret = run_command(line, pt);
-       if (ret < 0)
-               return ret;
-       return 0;
+       return run_command(line, &play_task);
 }
 
 static int play_i9e_key_handler(int key)