math: Set LC_NUMERIC to C again

e94f86e6d2 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?
This commit is contained in:
Fabian Homborg
2021-02-17 09:06:42 +01:00
parent c0af8dae20
commit 313b70a0c2

View File

@@ -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;
}