Last active
January 13, 2023 19:45
-
-
Save fabriceleal/ae8a3a592a7e18f10eb85b75d34d0143 to your computer and use it in GitHub Desktop.
testing swipl-devel/issues/1093
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SWI-Prolog.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <locale.h> | |
// https://github.com/SWI-Prolog/swipl-devel/issues/1093 | |
int ac = 0; | |
char *av[10]; | |
void setLocale() { | |
setlocale(LC_ALL, "C"); | |
setlocale(LC_NUMERIC, "C"); | |
// setlocale(LC_ALL, "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=en_US.UTF-8;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=en_US.UTF-8;LC_ADDRESS=en_US.UTF-8;LC_TELEPHONE=en_US.UTF-8;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=en_US.UTF-8"); | |
// setlocale(LC_NUMERIC, "en_US.UTF-8"); | |
} | |
void checkLocale() { | |
printf("LC_ALL: %s\n", setlocale(LC_ALL, NULL)); | |
printf("LC_NUMERIC: %s\n", setlocale(LC_NUMERIC, NULL)); | |
} | |
void test() { | |
checkLocale(); | |
float actual = atof("7654.321"); | |
printf("expected %.5f\n", 7654.321f); | |
printf("actual %.5f\n", actual); | |
struct lconv *c = localeconv(); | |
printf("decimal_point: %s\n\n\n", c->decimal_point); | |
} | |
int main(int argc, char** argv) | |
{ | |
av[ac++] = argv[0]; | |
av[ac++] = "-q"; | |
av[ac] = NULL; | |
printf("startup\n"); | |
checkLocale(); | |
// setLocale(); | |
// printf("\n\nafter setLocale()\n"); | |
// checkLocale(); | |
printf("\n\nTEST before PL_initialise()\n"); | |
test(); | |
if (!PL_initialise(ac, av)) | |
{ | |
PL_halt(1); | |
} | |
printf("TEST after PL_initialise()\n"); | |
test(); | |
printf("TEST after 2nd setLocale()\n"); | |
setLocale(); | |
test(); | |
PL_halt(0); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment