From f8931d4607fdf8cb98761b9814d068256d2925a3 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 2 Apr 2013 14:30:06 +0000 Subject: [PATCH] Simplify i9e_line_handler. 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 | 2 -- client.c | 4 +--- interactive.c | 22 +++++++++++++--------- play.c | 10 +--------- 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/audioc.c b/audioc.c index f68aee54..b2c6786a 100644 --- 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); diff --git a/client.c b/client.c index 90dc432b..c47dafe8 100644 --- 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; diff --git a/interactive.c b/interactive.c index ef6fc762..6d30e12a 100644 --- a/interactive.c +++ b/interactive.c @@ -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 2cb0536d..02128af0 100644 --- 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) -- 2.39.2