diff --git a/manual/luatex-tex.tex b/manual/luatex-tex.tex index 73e141f4d8ac8fa4a2f6e9ff35c820ecf4fccd74..ee458bf2d4115765c0669c91ef5ceea26e04e68c 100644 --- a/manual/luatex-tex.tex +++ b/manual/luatex-tex.tex @@ -167,6 +167,11 @@ The current list is: \NC total_pages \NC number of written pages \NC \NR \NC var_mem_max \NC number of allocated words for nodes \NC \NR \NC var_used \NC variable (one|-|word) memory in use \NC \NR +\NC lc_collate \NC the value of \type {LC_COLLATE} at startup time (becomes \type {C} at startup) \NC \NR +\NC lc_ctype \NC the value of \type {LC_CTYPE} at startup time (becomes \type {C} at startup) \NC \NR +%NC lc_monetary \NC the value of \type {LC_MONETARY} at startup time \NC \NR +\NC lc_numeric \NC the value of \type {LC_NUMERIC} at startup time \NC \NR +%NC lc_time \NC the value of \type {LC_TIME} at startup time (becomes \type {C} at startup) \NC \NR \stoptabulate The error and warning messages can be wiped with the \type {resetmessages} diff --git a/manual/luatex.pdf b/manual/luatex.pdf index fc22a9e5eaa51d678b303616830d1bf24c671d62..23ccd7cb17b7b40b02f320aa8b52cbc8144fdc85 100644 Binary files a/manual/luatex.pdf and b/manual/luatex.pdf differ diff --git a/source/texk/web2c/luatexdir/lua/lstatslib.c b/source/texk/web2c/luatexdir/lua/lstatslib.c index 7473ca214a4da8c29904c468cdab7fb77379dee1..c6ed9d3b5a93031757ed69c04d42ae38362c7880 100644 --- a/source/texk/web2c/luatexdir/lua/lstatslib.c +++ b/source/texk/web2c/luatexdir/lua/lstatslib.c @@ -121,6 +121,21 @@ static const char *getenginename(void) return engine_name; } +static const char * get_lc_ctype(void) +{ + return lc_ctype; +} + +static const char * get_lc_collate(void) +{ + return lc_collate; +} + +static const char * get_lc_numeric(void) +{ + return lc_numeric; +} + static lua_Number get_luatexhashchars(void) @@ -310,8 +325,13 @@ static struct statistic stats[] = { {"luabytecode_bytes", 'g', &luabytecode_bytes}, {"luastate_bytes", 'g', &luastate_bytes}, {"callbacks", 'g', &callback_count}, + {"indirect_callbacks", 'g', &saved_callback_count}, + {"lc_ctype", 'S', &get_lc_ctype}, + {"lc_collate", 'S', &get_lc_collate}, + {"lc_numeric",'S', &get_lc_numeric}, + {NULL, 0, 0} }; diff --git a/source/texk/web2c/luatexdir/lua/luainit.w b/source/texk/web2c/luatexdir/lua/luainit.w index 1c8b23b2d70c96a866d6169158b7566b986acc80..c7bcbf47b4a0ae1b850a0bf0df3c75018e4ca5d3 100644 --- a/source/texk/web2c/luatexdir/lua/luainit.w +++ b/source/texk/web2c/luatexdir/lua/luainit.w @@ -25,6 +25,8 @@ #include "lua/luatex-api.h" +#include <locale.h> + /* internalized strings: see luatex-api.h */ set_make_keys; @@ -106,6 +108,13 @@ const_string LUATEX_IHELP[] = { NULL }; +@ Later we will put on environment |LC_CTYPE|, |LC_COLLATE| and +|LC_NUMERIC| set to |C|, so we need a place where to store the old values. +@c +const char *lc_ctype; +const char *lc_collate; +const char *lc_numeric; + /* " --8bit ignored, input is assumed to be in UTF-8 encoding", " --default-translate-file=FILE ignored, input is assumed to be in UTF-8 encoding", @@ -309,12 +318,25 @@ static void parse_options(int ac, char **av) if ((strstr(argv[0], "luajittexlua") != NULL) || (strstr(argv[0], "texluajit") != NULL)) { #else - if ((strstr(argv[0], "luatexlua") != NULL) || + if ((strstr(argv[0], "luatexlua") != NULL) || (strstr(argv[0], "texlua") != NULL)) { #endif lua_only = 1; luainit = 1; } +/* More fun for all: we keep the env. locale. */ +#ifdef LuajitTeX + if ((strstr(argv[0], "luajittexluakl") != NULL) || + (strstr(argv[0], "texluajitkl") != NULL)) { +#else + if ((strstr(argv[0], "luatexluakl") != NULL) || + (strstr(argv[0], "texluakl") != NULL)) { +#endif + lua_only = 1; + luainit = 1; + keep_locale =1 ; + } + for (;;) { g = getopt_long_only(ac, av, "+", long_options, &option_index); if (g == -1) /* End of arguments, exit the loop. */ @@ -866,6 +888,9 @@ void lua_initialize(int ac, char **av) static char LC_COLLATE_C[] = "LC_COLLATE=C"; static char LC_NUMERIC_C[] = "LC_NUMERIC=C"; static char engine_luatex[] = "engine=" my_name; + char *old_locale = NULL; + char *env_locale = NULL; + char *tmp = NULL; /* Save to pass along to topenin. */ const char *fmt = "This is " MyName ", Version %s" WEB2CVERSION; argc = ac; @@ -917,10 +942,49 @@ void lua_initialize(int ac, char **av) if (lua_only) shellenabledp = true; + /* Get the current locale (it should be C ) */ + /* and save LC_CTYPE, LC_COLLATE and LC_NUMERIC. */ + /* Later luainterpreter() will consciously use them. */ + old_locale = setlocale (LC_ALL, NULL); + lc_ctype = NULL; + lc_collate = NULL; + lc_numeric = NULL; + if (old_locale) { + /* If setlocale fails here, then the state */ + /* could be compromised, and we exit. */ + env_locale = setlocale (LC_ALL, ""); + if (!env_locale) { + fprintf(stderr,"Unable to read environment locale:exit now.\n"); + exit(1); + } + tmp = setlocale (LC_CTYPE, NULL); + if (tmp) { + lc_ctype = xstrdup(tmp); + } + tmp = setlocale (LC_COLLATE, NULL); + if (tmp){ + lc_collate = xstrdup(tmp); + } + tmp = setlocale (LC_NUMERIC, NULL); + if (tmp){ + lc_numeric = xstrdup(tmp); + } + /* Back to the previous locale if possible, */ + /* otherwise it's a serious error and we exit:*/ + /* we can't ensure a 'sane' locale for lua. */ + env_locale = setlocale (LC_ALL, old_locale); + if (!env_locale) { + fprintf(stderr,"Unable to restore original locale:exit now.\n"); + exit(1); + } + } else { + fprintf(stderr,"Unable to store environment locale.\n"); + } + /* make sure that the locale is 'sane' (for lua) */ /* but the user can choose to keep the locale, */ /* as in the standard Lua. */ - if (!(lua_only && keep_locale)) { + if (!(lua_only && keep_locale)) { putenv(LC_CTYPE_C); putenv(LC_COLLATE_C); putenv(LC_NUMERIC_C); @@ -931,6 +995,13 @@ void lua_initialize(int ac, char **av) putenv(engine_luatex); luainterpreter(); +/* +now, here we should put +LC_CTYPE, LC_COLLATE, LC_NUMERIC +into status.list table + +*/ + /* init internalized strings */ set_init_keys; diff --git a/source/texk/web2c/luatexdir/lua/luatex-api.h b/source/texk/web2c/luatexdir/lua/luatex-api.h index 150dc91a7603c02ee2f94f6d26626efeaaad71b0..41935354e1a24542497099fd35de1d9b97655759 100644 --- a/source/texk/web2c/luatexdir/lua/luatex-api.h +++ b/source/texk/web2c/luatexdir/lua/luatex-api.h @@ -155,6 +155,12 @@ extern void undump_luac_registers(void); extern int lua_only; extern int keep_locale; +extern const char *lc_ctype; +extern const char *lc_collate; +extern const char *lc_numeric; + + + #ifdef LuajitTeX extern int luajiton; extern char *jithash_hashname ;