From c1bd3b5824027f23b41bbac77c5e28f856c5dc18 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 21 Sep 2015 11:24:49 -0700 Subject: Eliminate global variables associated with builtin IO This change eliminates global variables like stdout_buffer. Instead we wrap up the IO information into a new struct io_streams_t, and thread that through every builtin. This makes the intent clearer, gives us a place to hang new IO data, and eliminates the ugly global state management like builtin_push_io. --- src/common.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/common.cpp') diff --git a/src/common.cpp b/src/common.cpp index 50cb1102..2d844129 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -641,9 +641,7 @@ static bool should_debug(int level) static void debug_shared(const wcstring &msg) { const wcstring sb = wcstring(program_name) + L": " + msg; - wcstring sb2; - write_screen(sb, sb2); - fwprintf(stderr, L"%ls", sb2.c_str()); + fwprintf(stderr, L"%ls", reformat_for_screen(sb).c_str()); } void debug(int level, const wchar_t *msg, ...) @@ -806,8 +804,9 @@ void format_long_safe(wchar_t buff[64], long val) } } -void write_screen(const wcstring &msg, wcstring &buff) +wcstring reformat_for_screen(const wcstring &msg) { + wcstring buff; int line_width = 0; int screen_width = common_get_width(); @@ -892,6 +891,7 @@ void write_screen(const wcstring &msg, wcstring &buff) buff.append(msg); } buff.push_back(L'\n'); + return buff; } /* Escape a string, storing the result in out_str */ -- cgit v1.2.3