Skip to content
Snippets Groups Projects
Commit 5b404411 authored by Corey Farrell's avatar Corey Farrell
Browse files

core: Minor cleanup of ast_el_read_char.

* Define CHAR_T_LIBEDIT and CHAR_TO_LIBEDIT based on
  HAVE_LIBEDIT_IS_UNICODE.  This avoids needing to repeatedly use
  conditional blocks, eliminates having multiple function prototypes.
* Remove parenthesis from return values.
* Add missing code block brackets {}.
* Reduce use of 'else' conditional statements where possible.

Change-Id: I4315328ebea2f62641faf6881de2ac20a9f9d08e
parent d5bfba60
No related branches found
No related tags found
No related merge requests found
...@@ -2732,10 +2732,14 @@ static void send_rasterisk_connect_commands(void) ...@@ -2732,10 +2732,14 @@ static void send_rasterisk_connect_commands(void)
} }
#ifdef HAVE_LIBEDIT_IS_UNICODE #ifdef HAVE_LIBEDIT_IS_UNICODE
static int ast_el_read_char(EditLine *editline, wchar_t *cp) #define CHAR_T_LIBEDIT wchar_t
#define CHAR_TO_LIBEDIT(c) btowc(c)
#else #else
static int ast_el_read_char(EditLine *editline, char *cp) #define CHAR_T_LIBEDIT char
#define CHAR_TO_LIBEDIT(c) c
#endif #endif
static int ast_el_read_char(EditLine *editline, CHAR_T_LIBEDIT *cp)
{ {
int num_read = 0; int num_read = 0;
int lastpos = 0; int lastpos = 0;
...@@ -2756,28 +2760,29 @@ static int ast_el_read_char(EditLine *editline, char *cp) ...@@ -2756,28 +2760,29 @@ static int ast_el_read_char(EditLine *editline, char *cp)
} }
res = ast_poll(fds, max, -1); res = ast_poll(fds, max, -1);
if (res < 0) { if (res < 0) {
if (sig_flags.need_quit || sig_flags.need_quit_handler) if (sig_flags.need_quit || sig_flags.need_quit_handler) {
break; break;
if (errno == EINTR) }
if (errno == EINTR) {
continue; continue;
}
fprintf(stderr, "poll failed: %s\n", strerror(errno)); fprintf(stderr, "poll failed: %s\n", strerror(errno));
break; break;
} }
if (!ast_opt_exec && fds[1].revents) { if (!ast_opt_exec && fds[1].revents) {
char c = '\0'; char c = '\0';
num_read = read(STDIN_FILENO, &c, 1); num_read = read(STDIN_FILENO, &c, 1);
if (num_read < 1) { if (num_read < 1) {
break; break;
} else {
#ifdef HAVE_LIBEDIT_IS_UNICODE
*cp = btowc(c);
#else
*cp = c;
#endif
return (num_read);
} }
*cp = CHAR_TO_LIBEDIT(c);
return num_read;
} }
if (fds[0].revents) { if (fds[0].revents) {
res = read(ast_consock, buf, sizeof(buf) - 1); res = read(ast_consock, buf, sizeof(buf) - 1);
/* if the remote side disappears exit */ /* if the remote side disappears exit */
...@@ -2788,6 +2793,7 @@ static int ast_el_read_char(EditLine *editline, char *cp) ...@@ -2788,6 +2793,7 @@ static int ast_el_read_char(EditLine *editline, char *cp)
} else { } else {
int tries; int tries;
int reconnects_per_second = 20; int reconnects_per_second = 20;
fprintf(stderr, "Attempting to reconnect for 30 seconds\n"); fprintf(stderr, "Attempting to reconnect for 30 seconds\n");
for (tries = 0; tries < 30 * reconnects_per_second; tries++) { for (tries = 0; tries < 30 * reconnects_per_second; tries++) {
if (ast_tryconnect()) { if (ast_tryconnect()) {
...@@ -2796,8 +2802,9 @@ static int ast_el_read_char(EditLine *editline, char *cp) ...@@ -2796,8 +2802,9 @@ static int ast_el_read_char(EditLine *editline, char *cp)
WELCOME_MESSAGE; WELCOME_MESSAGE;
send_rasterisk_connect_commands(); send_rasterisk_connect_commands();
break; break;
} else }
usleep(1000000 / reconnects_per_second);
usleep(1000000 / reconnects_per_second);
} }
if (tries >= 30 * reconnects_per_second) { if (tries >= 30 * reconnects_per_second) {
fprintf(stderr, "Failed to reconnect for 30 seconds. Quitting.\n"); fprintf(stderr, "Failed to reconnect for 30 seconds. Quitting.\n");
...@@ -2818,25 +2825,17 @@ static int ast_el_read_char(EditLine *editline, char *cp) ...@@ -2818,25 +2825,17 @@ static int ast_el_read_char(EditLine *editline, char *cp)
console_print(buf); console_print(buf);
if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (res >= 2 && buf[res-2] == '\n'))) { if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (res >= 2 && buf[res-2] == '\n'))) {
#ifdef HAVE_LIBEDIT_IS_UNICODE *cp = CHAR_TO_LIBEDIT(CC_REFRESH);
*cp = btowc(CC_REFRESH);
#else return 1;
*cp = CC_REFRESH;
#endif
return(1);
} else {
lastpos = 1;
} }
lastpos = 1;
} }
} }
#ifdef HAVE_LIBEDIT_IS_UNICODE *cp = CHAR_TO_LIBEDIT('\0');
*cp = btowc('\0');
#else
*cp = '\0';
#endif
return (0); return 0;
} }
static struct ast_str *prompt = NULL; static struct ast_str *prompt = NULL;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment