summaryrefslogtreecommitdiff
path: root/source/luametatex
diff options
context:
space:
mode:
Diffstat (limited to 'source/luametatex')
-rw-r--r--source/luametatex/build.sh9
-rw-r--r--source/luametatex/cmake/luametatex.cmake10
-rw-r--r--source/luametatex/cmake/mingw-64-ucrt.cmake14
-rw-r--r--source/luametatex/source/lua/lmtenginelib.c35
-rw-r--r--source/luametatex/source/luametatex.h6
-rw-r--r--source/luametatex/source/luarest/lmtfilelib.c83
-rw-r--r--source/luametatex/source/utilities/auxfile.c53
-rw-r--r--source/luametatex/source/utilities/auxfile.h2
8 files changed, 127 insertions, 85 deletions
diff --git a/source/luametatex/build.sh b/source/luametatex/build.sh
index 60e7d13d5..56ed63497 100644
--- a/source/luametatex/build.sh
+++ b/source/luametatex/build.sh
@@ -33,6 +33,15 @@ then
cd build/mingw-32
cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=./cmake/mingw-32.cmake ../..
+elif [ "$1" = "mingw-64-ucrt" ] || [ "$1" = "mingw64ucrt" ] || [ "$1" = "--mingw64ucrt" ] || [ "$1" = "ucrt" ] || [ "$1" = "--ucrt" ]
+then
+
+ PLATFORM="win64"
+ SUFFIX=".exe"
+ mkdir -p build/mingw-64-ucrt
+ cd build/mingw-64-ucrt
+ cmake -G Ninja -DCMAKE_TOOLCHAIN_FILE=./cmake/mingw-64-ucrt.cmake ../..
+
else
PLATFORM="native"
diff --git a/source/luametatex/cmake/luametatex.cmake b/source/luametatex/cmake/luametatex.cmake
index 396b33d5a..eabef915b 100644
--- a/source/luametatex/cmake/luametatex.cmake
+++ b/source/luametatex/cmake/luametatex.cmake
@@ -25,9 +25,13 @@ target_link_libraries(luametatex
miniz
)
-target_link_libraries(luametatex
- ${CMAKE_DL_LIBS}
-)
+if (LUAMETATEX_NOLDL)
+ # mingw ucrt
+else()
+ target_link_libraries(luametatex
+ ${CMAKE_DL_LIBS}
+ )
+endif()
install(TARGETS luametatex
EXPORT luametatex
diff --git a/source/luametatex/cmake/mingw-64-ucrt.cmake b/source/luametatex/cmake/mingw-64-ucrt.cmake
new file mode 100644
index 000000000..c5f3915ff
--- /dev/null
+++ b/source/luametatex/cmake/mingw-64-ucrt.cmake
@@ -0,0 +1,14 @@
+# if (NOT __MINGW64_TOOLCHAIN_)
+# add_compile_options(-DLUASOCKET_INET_PTON)
+# endif()
+
+set(CMAKE_SYSTEM_NAME Windows)
+set(TOOLCHAIN_PREFIX x86_64-w64-mingw32ucrt)
+set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc)
+
+add_compile_options(-mtune=nocona)
+
+set(LUAMETATEX_MINGW 64)
+set(LUAMETATEX_NOLDL 1)
+
+# set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc")
diff --git a/source/luametatex/source/lua/lmtenginelib.c b/source/luametatex/source/lua/lmtenginelib.c
index fef2ed819..8e99aa29a 100644
--- a/source/luametatex/source/lua/lmtenginelib.c
+++ b/source/luametatex/source/lua/lmtenginelib.c
@@ -32,8 +32,10 @@ typedef struct environment_state_info {
char *ownbase;
char *ownname;
char *owncore;
+ char *ownlink;
char *input_name;
int luatex_lua_offset;
+ int padding;
} environment_state_info;
static environment_state_info lmt_environment_state = {
@@ -47,8 +49,10 @@ static environment_state_info lmt_environment_state = {
.ownbase = NULL,
.ownname = NULL,
.owncore = NULL,
+ .ownlink = NULL,
.input_name = NULL,
.luatex_lua_offset = 0,
+ .padding = 0,
};
/*tex todo: make helpers in loslibext which has similar code */
@@ -57,18 +61,21 @@ static void enginelib_splitnames(void)
{
char *p = lmt_memory_strdup(lmt_environment_state.ownpath); /*tex We need to make copies! */
/*
- printf("ownpath = %s\n",environment_state.ownpath);
- printf("ownbase = %s\n",environment_state.ownbase);
- printf("ownname = %s\n",environment_state.ownname);
- printf("owncore = %s\n",environment_state.owncore);
+ We loose some here but not enough to worry about. Maybe eventually we will use our own
+ |basename| and |dirname| anyway. I need to check if all are set to something we can
+ indeed free.
*/
/*
- We loose some here but not enough to worry about. Maybe eventually we will use our own
- |basename| and |dirname| anyway.
+ if (lmt_environment_state.ownbase) { lmt_memory_free(lmt_environment_state.ownbase); }
+ if (lmt_environment_state.ownname) { lmt_memory_free(lmt_environment_state.ownbase); }
+ if (lmt_environment_state.ownpath) { lmt_memory_free(lmt_environment_state.ownbase); }
+ if (lmt_environment_state.ownlink) { lmt_memory_free(lmt_environment_state.ownlink); }
*/
+ /* */
lmt_environment_state.ownbase = aux_basename(lmt_memory_strdup(p));
lmt_environment_state.ownname = aux_basename(lmt_memory_strdup(p));
lmt_environment_state.ownpath = aux_dirname(lmt_memory_strdup(p)); /* We could use p and not free later, but this is cleaner. */
+ lmt_environment_state.ownlink = aux_utf8_readlink(lmt_environment_state.ownpath);
/* */
for (size_t i = 0; i < strlen(lmt_environment_state.ownname); i++) {
if (lmt_environment_state.ownname[i] == '.') {
@@ -77,12 +84,6 @@ static void enginelib_splitnames(void)
}
}
lmt_environment_state.owncore = lmt_memory_strdup(lmt_environment_state.ownname);
- /*
- printf("ownpath = %s\n",environment_state.ownpath);
- printf("ownbase = %s\n",environment_state.ownbase);
- printf("ownname = %s\n",environment_state.ownname);
- printf("owncore = %s\n",environment_state.owncore);
- */
lmt_memory_free(p);
}
@@ -221,7 +222,7 @@ static void enginelib_show_version_info(void)
"\n"
"Functionality : level " LMT_TOSTRING(luametatex_development_id) "\n"
"Support : " luametatex_support_address "\n"
- "Copyright : The Lua(Meta)TeX Team(s) (2005-2022+)\n"
+ "Copyright : The Lua(Meta)TeX Team(s) (2005-2023+)\n"
"\n"
"The LuaMetaTeX project is related to ConTeXt development. This macro package\n"
"tightly integrates TeX and MetaPost in close cooperation with Lua. Updates will\n"
@@ -333,6 +334,11 @@ static void enginelib_show_credits(void)
"compiler : " LMT_COMPILER_USED "\n"
# endif
);
+ printf("own path : %s\n", lmt_environment_state.ownpath);
+ printf("own base : %s\n", lmt_environment_state.ownbase);
+ printf("own name : %s\n", lmt_environment_state.ownname);
+ printf("own core : %s\n", lmt_environment_state.owncore);
+ printf("own link : %s\n", lmt_environment_state.ownlink ? lmt_environment_state.ownlink : "<no link>");
exit(EXIT_SUCCESS);
}
@@ -357,7 +363,7 @@ static void enginelib_prepare_cmdline(int zero_offset)
lua_set_string_by_key(L, "selfbin", lmt_environment_state.argv[0]);
lua_set_string_by_key(L, "selfpath", lmt_environment_state.ownpath);
lua_set_string_by_key(L, "selfdir", lmt_environment_state.ownpath); /* for old times sake */
- lua_set_string_by_key(L, "selfbase", lmt_environment_state.ownbase);
+ lua_set_string_by_key(L, "selflink", lmt_environment_state.ownlink);
lua_set_string_by_key(L, "selfname", lmt_environment_state.ownname);
lua_set_string_by_key(L, "selfcore", lmt_environment_state.owncore);
lua_createtable(L, lmt_environment_state.argc, 0);
@@ -613,6 +619,7 @@ void tex_engine_initialize(int ac, char **av)
lmt_engine_state.luatex_banner = lmt_memory_strdup(lmt_version_state.banner);
/* preparations */
lmt_environment_state.ownpath = aux_utf8_getownpath(lmt_environment_state.argv[0]);
+ lmt_environment_state.ownlink = aux_utf8_readlink(lmt_environment_state.ownpath);
enginelib_splitnames();
aux_set_run_time();
/*tex
diff --git a/source/luametatex/source/luametatex.h b/source/luametatex/source/luametatex.h
index 410d4dd68..4d79c6cf2 100644
--- a/source/luametatex/source/luametatex.h
+++ b/source/luametatex/source/luametatex.h
@@ -90,9 +90,9 @@
# include "tex/textypes.h"
# define luametatex_version 210
-# define luametatex_revision 06
-# define luametatex_version_string "2.10.06"
-# define luametatex_development_id 20230224
+# define luametatex_revision 07
+# define luametatex_version_string "2.10.07"
+# define luametatex_development_id 20230306
# define luametatex_name_camelcase "LuaMetaTeX"
# define luametatex_name_lowercase "luametatex"
diff --git a/source/luametatex/source/luarest/lmtfilelib.c b/source/luametatex/source/luarest/lmtfilelib.c
index 8a814d713..f78c05e64 100644
--- a/source/luametatex/source/luarest/lmtfilelib.c
+++ b/source/luametatex/source/luarest/lmtfilelib.c
@@ -37,6 +37,7 @@
# include "../lua/lmtinterface.h"
# include "../utilities/auxmemory.h"
+# include "../utilities/auxfile.h"
# ifndef R_OK
# define F_OK 0x0
@@ -107,8 +108,6 @@
# ifdef _WIN32
- # include "../utilities/auxfile.h"
-
# ifndef S_ISDIR
# define S_ISDIR(mode) (mode & _S_IFDIR)
# endif
@@ -173,11 +172,15 @@
return r;
}
+ // # if defined(__MINGW64__) || defined(__MINGW32__)
+ // extern int CreateSymbolicLinkW(LPCWSTR lpSymlinkFileName, LPCWSTR lpTargetFileName, DWORD dwFlags);
+ // # endif
+
static int mk_symlink(const char *t, const char *f)
{
LPWSTR wt = aux_utf8_to_wide(t);
LPWSTR wf = aux_utf8_to_wide(f);
- int r = (CreateSymbolicLinkA(t, f, 0x2) != 0);
+ int r = CreateSymbolicLinkW((LPCWSTR) t, (LPCWSTR) f, 0x2) != 0;
lmt_memory_free(wt);
lmt_memory_free(wf);
return r;
@@ -187,7 +190,7 @@
{
LPWSTR wt = aux_utf8_to_wide(t);
LPWSTR wf = aux_utf8_to_wide(f);
- int r = (CreateSymbolicLinkA(t, f, 0x3) != 0);
+ int r = CreateSymbolicLinkW((LPCWSTR) t, (LPCWSTR) f, 0x3) != 0;
lmt_memory_free(wt);
lmt_memory_free(wf);
return r;
@@ -290,7 +293,7 @@ static int filelib_chdir(lua_State *L) {
lua_pushboolean(L, 0);
break;
} else if (_wgetcwd(wpath, size)) {
- char * path = aux_utf8_from_wide(wpath);
+ char *path = aux_utf8_from_wide(wpath);
lua_pushstring(L, path);
lmt_memory_free(path);
break;
@@ -787,64 +790,16 @@ static int filelib_setexecutable(lua_State *L)
link("name","target") : targetname
*/
-// # ifdef _WIN32
-//
-// static int filelib_symlinkattributes(lua_State *L)
-// {
-// lua_pushnil(L);
-// return 1;
-// }
-//
-// # else
-//
-// static int push_link_target(lua_State *L)
-// {
-// const char *file = luaL_checkstring(L, 1);
-// char *target = NULL;
-// int tsize, size = 256; /* size = initial buffer capacity */
-// while (1) {
-// target = lmt_memory_realloc(target, size);
-// if (! target) {
-// return 0;
-// }
-// tsize = readlink(file, target, size);
-// if (tsize < 0) {
-// /* error */
-// lmt_memory_free(target);
-// return 0;
-// }
-// if (tsize < size) {
-// break;
-// }
-// /* possibly truncated readlink() result, double size and retry */
-// size *= 2;
-// }
-// target[tsize] = '\0';
-// lua_pushlstring(L, target, tsize);
-// lmt_memory_free(target);
-// return 1;
-// }
-//
-// static int filelib_symlinkattributes(lua_State *L)
-// {
-// if (lua_isstring(L, 2) && (strcmp(lua_tostring(L, 2), "target") == 0)) {
-// if (! push_link_target(L)) {
-// lua_pushnil(L);
-// }
-// } else {
-// int ret = filelib_attributes(L);
-// if (ret == 1 && lua_type(L, -1) == LUA_TTABLE) {
-// if (push_link_target(L)) {
-// lua_setfield(L, -2, "target");
-// }
-// } else {
-// lua_pushnil(L);
-// }
-// }
-// return 1;
-// }
-//
-// # endif
+static int filelib_symlinktarget(lua_State *L)
+{
+ const char *file = aux_utf8_readlink(luaL_checkstring(L, 1));
+ if (file) {
+ lua_pushstring(L, file);
+ } else {
+ lua_pushnil(L);
+ }
+ return 1;
+}
static const struct luaL_Reg filelib_function_list[] = {
{ "attributes", filelib_attributes },
@@ -858,7 +813,7 @@ static const struct luaL_Reg filelib_function_list[] = {
{ "link", filelib_link },
{ "symlink", filelib_symlink },
{ "setexecutable", filelib_setexecutable },
- /* { "symlinkattributes", filelib_symlinkattributes }, */
+ { "symlinktarget", filelib_symlinktarget },
/* */
{ "isdir", filelib_isdir },
{ "isfile", filelib_isfile },
diff --git a/source/luametatex/source/utilities/auxfile.c b/source/luametatex/source/utilities/auxfile.c
index 0021cb229..c4a03d605 100644
--- a/source/luametatex/source/utilities/auxfile.c
+++ b/source/luametatex/source/utilities/auxfile.c
@@ -14,6 +14,7 @@
# include <ctype.h>
# include <io.h>
# include <shellapi.h>
+ # include <fileapi.h>
LPWSTR aux_utf8_to_wide(const char *utf8str) {
if (utf8str) {
@@ -123,7 +124,7 @@
if (file) {
char *path = NULL;
char buffer[MAX_PATH];
- GetModuleFileName(NULL,buffer,sizeof(buffer));
+ GetModuleFileName(NULL, buffer, sizeof(buffer));
path = lmt_memory_strdup(buffer);
if (strlen(path) > 0) {
for (size_t i = 0; i < strlen(path); i++) {
@@ -137,6 +138,31 @@
return lmt_memory_strdup(".");
}
+ /*tex We alwways return a copy so that we're consistent with windows/unix. */
+
+ // # if defined(__MINGW64__) || defined(__MINGW32__)
+ // extern DWORD GetFinalPathNameByHandleW(HANDLE hFile, LPWSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags);
+ // # endif
+
+ char *aux_utf8_readlink(const char *file)
+ {
+ LPWSTR wide = aux_utf8_to_wide(file);
+ HANDLE handle = CreateFileW(wide, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+ char *link = NULL;
+ if (handle == INVALID_HANDLE_VALUE) {
+ LPWSTR path = (LPWSTR) lmt_memory_malloc((MAX_PATH+1) * sizeof(WCHAR));
+ DWORD size = GetFinalPathNameByHandleW(handle, path, MAX_PATH, VOLUME_NAME_NT);
+ if (size > 0 && size < MAX_PATH) {
+ path[size] = '\0';
+ link = aux_utf8_from_wide(path);
+ }
+ lmt_memory_free(path);
+ }
+ CloseHandle(handle);
+ lmt_memory_free(wide);
+ return link ? link : lmt_memory_strdup(file);
+ }
+
# else
# include <string.h>
@@ -209,6 +235,31 @@
}
}
+ /*tex We alwways return a copy so that we're consistent with windows/unix. */
+
+ char *aux_utf8_readlink(const char *file)
+ {
+ int size = 256;
+ while (1) {
+ char *target = lmt_memory_malloc(size);
+ if (! target) {
+ break;
+ } else {
+ int tsize = readlink(file, target, size);
+ if (tsize <= 0) {
+ lmt_memory_free(target);
+ break;
+ } else if (tsize < size) {
+ target[tsize] = '\0';
+ return target;
+ } else {
+ size *= 2;
+ }
+ }
+ }
+ return lmt_memory_strdup(file);
+ }
+
# endif
# ifndef S_ISREG
diff --git a/source/luametatex/source/utilities/auxfile.h b/source/luametatex/source/utilities/auxfile.h
index 19a4815c2..8ed4dee40 100644
--- a/source/luametatex/source/utilities/auxfile.h
+++ b/source/luametatex/source/utilities/auxfile.h
@@ -107,6 +107,7 @@
extern int aux_utf8_rename (const char *oldname, const char *newname);
extern int aux_utf8_setargv (char * **av, char **argv, int argc);
extern char *aux_utf8_getownpath (const char *file);
+ extern char *aux_utf8_readlink (const char *file);
# else
@@ -118,6 +119,7 @@
extern int aux_utf8_setargv (char * **av, char **argv, int argc);
extern char *aux_utf8_getownpath (const char *file);
+ extern char *aux_utf8_readlink (const char *file);
# include <libgen.h>