]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Use buffered printers in fs_cli
authorTravis Cross <tc@traviscross.com>
Fri, 28 Mar 2014 00:01:33 +0000 (00:01 +0000)
committerTravis Cross <tc@traviscross.com>
Fri, 28 Mar 2014 00:01:33 +0000 (00:01 +0000)
Now that all output should end in a newline, we don't need to play
tricks with getting certain escape codes out ahead of buffered output.

This updates what we tried to do in commit
991b83d23cf014226aa97f01f4290a6e6554fee1.

This partially reverts commit
8056125077d5a2583272219d193b94e81c97a50c.

libs/esl/fs_cli.c

index dbfceb8367ca1f460cfca06345da92d7fabe0bfe..b7b764427d850db71ce1892e4d373807c3905c1a 100644 (file)
@@ -639,25 +639,6 @@ static int stdout_writable(void)
 #endif
 }
 
-#ifndef WIN32
-static int write_str(const char *s) {
-       int n, left = strlen(s);
-       while (1) {
-               n = write(STDOUT_FILENO, s, left);
-               if (n == left) return 1;
-               if (n < 0) return 0;
-               s += n; left -= n;
-       }
-       return 1;
-}
-
-static int write_char(int c) {
-       char s[2] = { c, 0 };
-       return write_str(s);
-}
-#endif
-
-#ifdef WIN32
 static void clear_line(void)
 {
        if (global_profile->batch_mode) return;
@@ -666,16 +647,6 @@ static void clear_line(void)
        fflush(stdout);
        return;
 }
-#else
-static void clear_line(void)
-{
-       if (global_profile->batch_mode) return;
-       if (!(write_char('\r'))) goto done;
-       if (!(write_str("\033[K"))) goto done;
- done:
-       return;
-}
-#endif
 
 static void redisplay(void)
 {
@@ -696,21 +667,20 @@ static void redisplay(void)
        const LineInfo *lf = el_line(el);
        const char *c = lf->buffer;
        if (global_profile->batch_mode) return;
-       if (!(write_str(prompt_str))) goto done;
+       printf("%s",prompt_str);
        while (c < lf->lastchar && *c) {
-               if (!(write_char(*c))) goto done;
+               putchar(*c);
                c++;
        }
        {
                int pos = (int)(lf->cursor - lf->buffer);
                char s1[12], s2[12];
-               if (!(write_char('\r'))) goto done;
+               putchar('\r');
                snprintf(s1, sizeof(s1), "\033[%dC", bare_prompt_str_len);
                snprintf(s2, sizeof(s2), "\033[%dC", pos);
-               if (!(write_str(s1))) goto done;
-               if (pos > 0) if (!(write_str(s2))) goto done;
+               printf("%s%s",s1,s2);
        }
- done:
+       fflush(stdout);
        return;
 #endif
 #endif
@@ -774,7 +744,6 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
                                                                if (global_profile->log_uuid && !esl_strlen_zero(userdata)) {
                                                                        printf("%s ", userdata);
                                                                }
-#if HAVE_DECL_EL_REFRESH
                                                                if (strcmp("\n",handle->last_event->body)) {
                                                                        char *c = handle->last_event->body;
                                                                        printf("%s", handle->last_event->body);
@@ -784,9 +753,6 @@ static void *msg_thread_run(esl_thread_t *me, void *obj)
                                                                                        printf("\n");
                                                                        }
                                                                }
-#else
-                                                               printf("%s", handle->last_event->body);
-#endif
                                                                if(!(global_profile->batch_mode)) {
                                                                        if (!feature_level) printf("%s", ESL_SEQ_DEFAULT_COLOR);
                                                                }