From 313b70a0c22d25e4c06db3e4975e5ef81d069506 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 17 Feb 2021 09:06:42 +0100 Subject: [PATCH] math: Set LC_NUMERIC to C again e94f86e6d27a6d382199f8094842c5883b28ef80 removed it in favor of using fish_wcstod, but this broke the *output* - math currently prints numbers with "," and then can't read them. So we partially revert it until we come up with something better. Maybe set $LC_NUMERIC globally inside fish? --- src/builtin_math.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/builtin_math.cpp b/src/builtin_math.cpp index 9c8f4c8ae..310d2e554 100644 --- a/src/builtin_math.cpp +++ b/src/builtin_math.cpp @@ -228,6 +228,15 @@ static int evaluate_expression(const wchar_t *cmd, const parser_t &parser, io_st int retval = STATUS_CMD_OK; te_error_t error; + // Switch locale while computing stuff. + // This means that the "." is always the radix character, + // so numbers work the same across locales. + // + // TODO: Technically this is only needed for *output* currently, + // because we already use wcstod_l while computing, + // but we can't have math print numbers that it won't then also read. + char *saved_locale = strdup(setlocale(LC_NUMERIC, nullptr)); + setlocale(LC_NUMERIC, "C"); double v = te_interp(expression.c_str(), &error); if (error.position == 0) { @@ -257,6 +266,8 @@ static int evaluate_expression(const wchar_t *cmd, const parser_t &parser, io_st streams.err.append_format(L"%*ls%ls\n", error.position - 1, L" ", L"^"); retval = STATUS_CMD_ERROR; } + setlocale(LC_NUMERIC, saved_locale); + free(saved_locale); return retval; }