diff options
-rw-r--r-- | builtin_printf.cpp | 11 | ||||
-rw-r--r-- | builtin_set_color.cpp | 6 | ||||
-rw-r--r-- | common.h | 2 |
3 files changed, 13 insertions, 6 deletions
diff --git a/builtin_printf.cpp b/builtin_printf.cpp index 6ff66495..b2484e14 100644 --- a/builtin_printf.cpp +++ b/builtin_printf.cpp @@ -56,7 +56,10 @@ struct builtin_printf_state_t { + /* The status of the operation */ int exit_code; + + /* Whether we should stop outputting. This gets set in the case of an error, and also with the \c specifier. */ bool early_exit; builtin_printf_state_t() : exit_code(0), early_exit(false) @@ -172,8 +175,12 @@ void builtin_printf_state_t::fatal_error(const wchar_t *fmt, ...) va_list va; va_start(va, fmt); - append_formatv(stderr_buffer, fmt, va); + wcstring errstr = vformat_string(fmt, va); va_end(va); + stderr_buffer.append(errstr); + if (! string_suffixes_string(L"\n", errstr)) + stderr_buffer.push_back(L'\n'); + this->exit_code = STATUS_BUILTIN_ERROR; this->early_exit = true; } @@ -682,7 +689,7 @@ no_more_flag_characters: unsigned wchar_t conversion = *f; if (! ok[conversion]) { - this->fatal_error(_("%.*ls: invalid conversion specification"), (int)(f + 1 - direc_start), direc_start); + this->fatal_error(_(L"%.*ls: invalid conversion specification"), (int)(f + 1 - direc_start), direc_start); return 0; } } diff --git a/builtin_set_color.cpp b/builtin_set_color.cpp index e8775a57..549ea8cf 100644 --- a/builtin_set_color.cpp +++ b/builtin_set_color.cpp @@ -153,21 +153,21 @@ static int builtin_set_color(parser_t &parser, wchar_t **argv) const rgb_color_t fg = rgb_color_t(fgcolor ? fgcolor : L""); if (fgcolor && fg.is_none()) { - append_format(stderr_buffer, _("%s: Unknown color '%s'\n"), argv[0], fgcolor); + append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], fgcolor); return STATUS_BUILTIN_ERROR; } const rgb_color_t bg = rgb_color_t(bgcolor ? bgcolor : L""); if (bgcolor && bg.is_none()) { - append_format(stderr_buffer, _("%s: Unknown color '%s'\n"), argv[0], bgcolor); + append_format(stderr_buffer, _(L"%ls: Unknown color '%ls'\n"), argv[0], bgcolor); return STATUS_BUILTIN_ERROR; } /* Make sure that the term exists */ if (cur_term == NULL && setupterm(0, STDOUT_FILENO, 0) == ERR) { - append_format(stderr_buffer, _("%s: Could not set up terminal\n"), argv[0]); + append_format(stderr_buffer, _(L"%ls: Could not set up terminal\n"), argv[0]); return STATUS_BUILTIN_ERROR; } @@ -182,7 +182,7 @@ extern const wchar_t *program_name; /** Shorthand for wgettext call */ -#define _(wstr) wgettext((const wchar_t *)wstr) +#define _(wstr) wgettext(wstr) /** Noop, used to tell xgettext that a string should be translated, |