From 7976aa42f9b254712011bd331b96c31a47dcdd8b Mon Sep 17 00:00:00 2001 From: Klaus Alexander Seistrup Date: Mon, 26 Feb 2024 04:24:40 +0100 Subject: [PATCH] Move setlocale() from rline() to the top of main() --- src/kuroko.c | 22 ++++++++++++++++++++++ src/vendor/rline.c | 8 -------- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/kuroko.c b/src/kuroko.c index 2a798bc..655643a 100644 --- a/src/kuroko.c +++ b/src/kuroko.c @@ -5,6 +5,7 @@ * or executes scripts from the argument list. */ #define _DEFAULT_SOURCE +#include #include #include #include @@ -759,6 +760,26 @@ static int compileFile(char * argv[], int flags, char * fileName) { return func == NULL; } +void initializeLocale(void) { + char *myLocale; +#ifndef _WIN32 + myLocale = setlocale(LC_ALL, ""); + if (myLocale != NULL) { + struct lconv *lc = localeconv(); + char *decimalPoint = lc->decimal_point; + if (decimalPoint) { + if (strcmp(decimalPoint, ".") != 0) { + myLocale = setlocale(LC_ALL, "C.UTF-8"); + } + } + } else { + myLocale = setlocale(LC_ALL, "C.UTF-8"); + } +#else + myLocale = setlocale(LC_ALL, "C.UTF-8"); +#endif +} + int main(int argc, char * argv[]) { #ifdef _WIN32 SetConsoleOutputCP(65001); @@ -770,6 +791,7 @@ int main(int argc, char * argv[]) { int inspectAfter = 0; int opt; int maxDepth = -1; + initializeLocale(); while ((opt = getopt(argc, argv, "+:c:C:dgGim:rR:tTMSV-:")) != -1) { switch (opt) { case 'c': diff --git a/src/vendor/rline.c b/src/vendor/rline.c index 1246735..8bfb1da 100644 --- a/src/vendor/rline.c +++ b/src/vendor/rline.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #ifndef _WIN32 #include @@ -2429,13 +2428,6 @@ static int read_line(void) { * Read a line of text with interactive editing. */ int rline(char * buffer, int buf_size) { -#ifndef _WIN32 - setlocale(LC_ALL, ""); - /* If the requested locale doesn't use . as a radix point, fall back to C to not break float parsing. */ - if (strtod("0.5",NULL) != 0.5) setlocale(LC_ALL, "C.UTF-8"); -#else - setlocale(LC_ALL, "C.UTF-8"); -#endif get_initial_termios(); set_unbuffered(); get_size();