From a5eef06225f17890a0f49dc4c797ff0a3171cdd0 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 1 Mar 2016 22:11:09 +0100 Subject: msg: minor simplification Instead of playing ugly tricks with the buffer to append a \r or \n to the text buffer, extend print_terminal_line() to print a second string. --- common/msg.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/common/msg.c b/common/msg.c index 065ef46620..29dd5abbf5 100644 --- a/common/msg.c +++ b/common/msg.c @@ -236,7 +236,8 @@ static bool test_terminal_level(struct mp_log *log, int lev) !(lev == MSGL_STATUS && terminal_in_background()); } -static void print_terminal_line(struct mp_log *log, int lev, char *text) +static void print_terminal_line(struct mp_log *log, int lev, + char *text, char *trail) { if (!test_terminal_level(log, lev)) return; @@ -265,7 +266,7 @@ static void print_terminal_line(struct mp_log *log, int lev, char *text) } } - fprintf(stream, "%s", text); + fprintf(stream, "%s%s", text, trail); if (root->color) set_term_color(stream, -1); @@ -373,7 +374,7 @@ void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va) char *next = &end[1]; char saved = next[0]; next[0] = '\0'; - print_terminal_line(log, lev, text); + print_terminal_line(log, lev, text, ""); write_log_file(log, lev, text); write_msg_to_buffers(log, lev, text); next[0] = saved; @@ -381,14 +382,8 @@ void mp_msg_va(struct mp_log *log, int lev, const char *format, va_list va) } if (lev == MSGL_STATUS) { - if (text[0]) { - len = strlen(text); - if (len < max_len - 1) { - text[len] = root->termosd ? '\r' : '\n'; - text[len + 1] = '\0'; - } - print_terminal_line(log, lev, text); - } + if (text[0]) + print_terminal_line(log, lev, text, root->termosd ? "\r" : "\n"); } else { int leftover = strlen(text); memmove(root->buffer, text, leftover + 1); -- cgit v1.2.3