<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8566">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">core: Minor cleanup of ast_el_read_char.<br><br>* Define CHAR_T_LIBEDIT and CHAR_TO_LIBEDIT based on<br> HAVE_LIBEDIT_IS_UNICODE. This avoids needing to repeatedly use<br> conditional blocks, eliminates having multiple function prototypes.<br>* Remove parenthesis from return values.<br>* Add missing code block brackets {}.<br>* Reduce use of 'else' conditional statements where possible.<br>* Replace ESC code directly in text with macro from term.h.<br><br>Change-Id: I4315328ebea2f62641faf6881de2ac20a9f9d08e<br>---<br>M main/asterisk.c<br>1 file changed, 27 insertions(+), 28 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/66/8566/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/asterisk.c b/main/asterisk.c<br>index bec992f..6625c3a 100644<br>--- a/main/asterisk.c<br>+++ b/main/asterisk.c<br>@@ -2732,10 +2732,14 @@<br> }<br> <br> #ifdef HAVE_LIBEDIT_IS_UNICODE<br>-static int ast_el_read_char(EditLine *editline, wchar_t *cp)<br>+#define CHAR_T_LIBEDIT wchar_t<br>+#define CHAR_TO_LIBEDIT(c) btowc(c)<br> #else<br>-static int ast_el_read_char(EditLine *editline, char *cp)<br>+#define CHAR_T_LIBEDIT char<br>+#define CHAR_TO_LIBEDIT(c) c<br> #endif<br>+<br>+static int ast_el_read_char(EditLine *editline, CHAR_T_LIBEDIT *cp)<br> {<br> int num_read = 0;<br> int lastpos = 0;<br>@@ -2756,28 +2760,29 @@<br> }<br> res = ast_poll(fds, max, -1);<br> if (res < 0) {<br>- if (sig_flags.need_quit || sig_flags.need_quit_handler)<br>+ if (sig_flags.need_quit || sig_flags.need_quit_handler) {<br> break;<br>- if (errno == EINTR)<br>+ }<br>+ if (errno == EINTR) {<br> continue;<br>+ }<br> fprintf(stderr, "poll failed: %s\n", strerror(errno));<br> break;<br> }<br> <br> if (!ast_opt_exec && fds[1].revents) {<br> char c = '\0';<br>+<br> num_read = read(STDIN_FILENO, &c, 1);<br> if (num_read < 1) {<br> break;<br>- } else {<br>-#ifdef HAVE_LIBEDIT_IS_UNICODE<br>- *cp = btowc(c);<br>-#else<br>- *cp = c;<br>-#endif<br>- return (num_read);<br> }<br>+<br>+ *cp = CHAR_TO_LIBEDIT(c);<br>+<br>+ return num_read;<br> }<br>+<br> if (fds[0].revents) {<br> res = read(ast_consock, buf, sizeof(buf) - 1);<br> /* if the remote side disappears exit */<br>@@ -2788,6 +2793,7 @@<br> } else {<br> int tries;<br> int reconnects_per_second = 20;<br>+<br> fprintf(stderr, "Attempting to reconnect for 30 seconds\n");<br> for (tries = 0; tries < 30 * reconnects_per_second; tries++) {<br> if (ast_tryconnect()) {<br>@@ -2796,8 +2802,9 @@<br> WELCOME_MESSAGE;<br> send_rasterisk_connect_commands();<br> break;<br>- } else<br>- usleep(1000000 / reconnects_per_second);<br>+ }<br>+<br>+ usleep(1000000 / reconnects_per_second);<br> }<br> if (tries >= 30 * reconnects_per_second) {<br> fprintf(stderr, "Failed to reconnect for 30 seconds. Quitting.\n");<br>@@ -2811,32 +2818,24 @@<br> <br> /* Write over the CLI prompt */<br> if (!ast_opt_exec && !lastpos) {<br>- if (write(STDOUT_FILENO, "\r[0K", 5) < 0) {<br>+ if (write(STDOUT_FILENO, "\r%c[0K", ESC, 5) < 0) {<br> }<br> }<br> <br> console_print(buf);<br> <br> if ((res < EL_BUF_SIZE - 1) && ((buf[res-1] == '\n') || (res >= 2 && buf[res-2] == '\n'))) {<br>-#ifdef HAVE_LIBEDIT_IS_UNICODE<br>- *cp = btowc(CC_REFRESH);<br>-#else<br>- *cp = CC_REFRESH;<br>-#endif<br>- return(1);<br>- } else {<br>- lastpos = 1;<br>+ *cp = CHAR_TO_LIBEDIT(CC_REFRESH);<br>+<br>+ return 1;<br> }<br>+ lastpos = 1;<br> }<br> }<br> <br>-#ifdef HAVE_LIBEDIT_IS_UNICODE<br>- *cp = btowc('\0');<br>-#else<br>- *cp = '\0';<br>-#endif<br>+ *cp = CHAR_TO_LIBEDIT('\0');<br> <br>- return (0);<br>+ return 0;<br> }<br> <br> static struct ast_str *prompt = NULL;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8566">change 8566</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8566"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I4315328ebea2f62641faf6881de2ac20a9f9d08e </div>
<div style="display:none"> Gerrit-Change-Number: 8566 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>