mirror of
https://github.com/yann64/haikuports.git
synced 2026-03-19 01:46:00 +01:00
lite_xl: add recipe (#13752)
This commit is contained in:
BIN
app-editors/lite-xl/additional-files/icon.iom
Normal file
BIN
app-editors/lite-xl/additional-files/icon.iom
Normal file
Binary file not shown.
23
app-editors/lite-xl/additional-files/lite-xl.rdef.in
Normal file
23
app-editors/lite-xl/additional-files/lite-xl.rdef.in
Normal file
@@ -0,0 +1,23 @@
|
||||
resource app_flags B_MULTIPLE_LAUNCH;
|
||||
|
||||
resource app_version {
|
||||
major = @MAJOR@,
|
||||
middle = @MIDDLE@,
|
||||
minor = @MINOR@,
|
||||
|
||||
variety = B_APPV_FINAL,
|
||||
internal = 0,
|
||||
|
||||
short_info = "@APP_NAME@",
|
||||
long_info = "@LONG_INFO@"
|
||||
};
|
||||
|
||||
resource app_signature "@APP_SIGNATURE@";
|
||||
|
||||
resource vector_icon {
|
||||
$"6E63696607032E2E3203E1E1E60393DDFA03FF000001FFA800C105180418B907"
|
||||
$"0A033334555A5F430807302D302B332A50355337535750590A04302C304C5058"
|
||||
$"50380A0636353647BC88C2EC4A4F4A4B4A3A0A0736353647BC88C2EC4A4F4A4A"
|
||||
$"3A443A370A043E413E3B473D47440A033C384947493B070A060100201D200A05"
|
||||
$"0101000A000102000A0300000A010104000A020105000A04010600"
|
||||
};
|
||||
19
app-editors/lite-xl/additional-files/lua/LICENSE.build
Normal file
19
app-editors/lite-xl/additional-files/lua/LICENSE.build
Normal file
@@ -0,0 +1,19 @@
|
||||
Copyright (c) 2021 The Meson development team
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
106
app-editors/lite-xl/lite_xl-2.1.8.recipe
Normal file
106
app-editors/lite-xl/lite_xl-2.1.8.recipe
Normal file
@@ -0,0 +1,106 @@
|
||||
SUMMARY="A lightweight text editor written in Lua"
|
||||
DESCRIPTION="Lite XL is derived from lite. It is a lightweight text editor written mostly in Lua \
|
||||
It aims to provide something practical, pretty, small and fast easy to modify and extend, \
|
||||
or to use without doing either.
|
||||
|
||||
The aim of Lite XL compared to lite is to be more user friendly, improve the quality of font \
|
||||
rendering, and reduce CPU usage."
|
||||
HOMEPAGE="https://lite-xl.com/"
|
||||
COPYRIGHT="2022-present Lite XL Team
|
||||
2020-2022 Francesco Abbate
|
||||
2020 rxi
|
||||
"
|
||||
LICENSE="MIT"
|
||||
REVISION="1"
|
||||
# Lite-XL
|
||||
SOURCE_URI="https://github.com/lite-xl/lite-xl/archive/refs/tags/v$portVersion.tar.gz"
|
||||
CHECKSUM_SHA256="fcaffb946bc60583369cb040d533a4ac18075a6d474d49a2a5ff4bf87e2e9a10"
|
||||
SOURCE_DIR="lite-xl-$portVersion"
|
||||
SOURCE_FILENAME="lite-xl-$portVersion.tar.gz"
|
||||
# Lua 5.4
|
||||
luaver="5.4.6"
|
||||
SOURCE_URI_2="https://www.lua.org/ftp/lua-$luaver.tar.gz"
|
||||
CHECKSUM_SHA256_2="7d5ea1b9cb6aa0b59ca3dde1c6adcb57ef83a1ba8e5432c0ecd06bf439b3ad88"
|
||||
SOURCE_FILENAME_2="lua-$luaver.tar.gz"
|
||||
SOURCE_DIR_2="lua-$luaver"
|
||||
PATCHES_2="
|
||||
buildfiles.patch
|
||||
lua-unicode.diff
|
||||
"
|
||||
# deps end
|
||||
PATCHES="lite_xl-$portVersion.patch"
|
||||
ADDITIONAL_FILES="lite-xl.rdef.in"
|
||||
|
||||
ARCHITECTURES="all ?x86_gcc2"
|
||||
|
||||
PROVIDES="
|
||||
lite_xl = $portVersion
|
||||
app:lite_xl = $portVersion
|
||||
"
|
||||
REQUIRES="
|
||||
haiku
|
||||
lib:libedit
|
||||
lib:libfreetype
|
||||
lib:libpcre2_8
|
||||
lib:libreadline
|
||||
lib:libsdl3
|
||||
"
|
||||
|
||||
BUILD_REQUIRES="
|
||||
haiku_devel
|
||||
devel:libedit
|
||||
devel:libfreetype
|
||||
devel:libpcre2_8
|
||||
devel:libreadline
|
||||
devel:libsdl3
|
||||
"
|
||||
BUILD_PREREQUIRES="
|
||||
cmd:cmake
|
||||
cmd:gcc
|
||||
cmd:install
|
||||
cmd:meson
|
||||
cmd:pkg_config
|
||||
"
|
||||
|
||||
BUILD()
|
||||
{
|
||||
ln -sf $sourceDir2 $sourceDir/subprojects/lua
|
||||
rm $sourceDir/subprojects/lua.wrap
|
||||
|
||||
meson setup --buildtype=release \
|
||||
--prefix=$prefix \
|
||||
--datadir=$dataDir \
|
||||
--bindir=$appsDir \
|
||||
--reconfigure \
|
||||
build
|
||||
meson compile -C build
|
||||
}
|
||||
|
||||
INSTALL()
|
||||
{
|
||||
mkdir -p $appsDir $dataDir $binDir $docDir
|
||||
meson install --skip-subprojects -C build
|
||||
install -m 0755 $binDir/lite-xl "$appsDir/Lite XL"
|
||||
rm $binDir/lite-xl
|
||||
rmdir $binDir
|
||||
rm -rf $docDir # doc only contains the MIT license as of writing
|
||||
|
||||
local MAJOR="`echo "$portVersion" | cut -d. -f1`"
|
||||
local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
|
||||
local MINOR="`echo "$portVersion" | cut -d. -f3`"
|
||||
local APP_NAME="Lite XL"
|
||||
local LONG_INFO="$SUMMARY"
|
||||
local APP_SIGNATURE="application/x-vnd.lite-xl"
|
||||
sed \
|
||||
-e "s|@MAJOR@|$MAJOR|" \
|
||||
-e "s|@MIDDLE@|$MIDDLE|" \
|
||||
-e "s|@MINOR@|$MINOR|" \
|
||||
-e "s|@LONG_INFO@|$LONG_INFO|" \
|
||||
-e "s|@APP_NAME@|$APP_NAME|" \
|
||||
-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
|
||||
$portDir/additional-files/lite-xl.rdef.in > lite-xl.rdef
|
||||
|
||||
addResourcesToBinaries lite-xl.rdef "$appsDir/Lite XL"
|
||||
|
||||
addAppDeskbarSymlink "$appsDir/Lite XL"
|
||||
}
|
||||
141
app-editors/lite-xl/patches/buildfiles.patch
Normal file
141
app-editors/lite-xl/patches/buildfiles.patch
Normal file
@@ -0,0 +1,141 @@
|
||||
# check additional-files/lua/LICENSE.build
|
||||
diff --git a/meson.build b/meson.build
|
||||
new file mode 100644
|
||||
index 0000000..ffd115c
|
||||
--- /dev/null
|
||||
+++ b/meson.build
|
||||
@@ -0,0 +1,116 @@
|
||||
+project(
|
||||
+ 'lua-5.4',
|
||||
+ 'c',
|
||||
+ license: 'MIT',
|
||||
+ meson_version: '>=0.49.2',
|
||||
+ version: '5.4.6',
|
||||
+ default_options: ['c_std=c99', 'warning_level=2'],
|
||||
+)
|
||||
+
|
||||
+lua_versions = meson.project_version().split('.')
|
||||
+cc = meson.get_compiler('c')
|
||||
+
|
||||
+# Skip bogus warning.
|
||||
+add_project_arguments(cc.get_supported_arguments('-Wno-string-plus-int', '-Wno-stringop-overflow'), language: 'c')
|
||||
+
|
||||
+# Platform-specific defines.
|
||||
+is_posix = host_machine.system() in ['cygwin', 'darwin', 'dragonfly', 'freebsd', 'gnu', 'haiku', 'linux', 'netbsd', 'openbsd', 'sunos']
|
||||
+if is_posix
|
||||
+ add_project_arguments('-DLUA_USE_POSIX', language: 'c')
|
||||
+elif get_option('default_library') != 'static' and host_machine.system() == 'windows'
|
||||
+ add_project_arguments('-DLUA_BUILD_AS_DLL', language: 'c')
|
||||
+endif
|
||||
+
|
||||
+# Library dependencies.
|
||||
+lua_lib_deps = [cc.find_library('m', required: false)]
|
||||
+
|
||||
+if meson.version().version_compare('>= 0.62')
|
||||
+ dl_dep = dependency('dl', required: get_option('loadlib'))
|
||||
+else
|
||||
+ dl_dep = cc.find_library('dl', required: get_option('loadlib'))
|
||||
+endif
|
||||
+
|
||||
+if dl_dep.found()
|
||||
+ lua_lib_deps += dl_dep
|
||||
+ add_project_arguments('-DLUA_USE_DLOPEN', language: 'c')
|
||||
+endif
|
||||
+
|
||||
+# Interpreter dependencies.
|
||||
+lua_exe_deps = []
|
||||
+lua_exe_args = []
|
||||
+
|
||||
+readline_dep = dependency('readline', required: get_option('line_editing'))
|
||||
+if readline_dep.found()
|
||||
+ lua_exe_deps += readline_dep
|
||||
+ lua_exe_args += '-DLUA_USE_READLINE'
|
||||
+else
|
||||
+ readline_dep = dependency('libedit', required: get_option('line_editing'))
|
||||
+endif
|
||||
+
|
||||
+# Targets.
|
||||
+lua_lib = library(
|
||||
+ 'lua',
|
||||
+ 'src/lapi.c',
|
||||
+ 'src/lauxlib.c',
|
||||
+ 'src/lbaselib.c',
|
||||
+ 'src/lcode.c',
|
||||
+ 'src/lcorolib.c',
|
||||
+ 'src/lctype.c',
|
||||
+ 'src/ldblib.c',
|
||||
+ 'src/ldebug.c',
|
||||
+ 'src/ldo.c',
|
||||
+ 'src/ldump.c',
|
||||
+ 'src/lfunc.c',
|
||||
+ 'src/lgc.c',
|
||||
+ 'src/linit.c',
|
||||
+ 'src/liolib.c',
|
||||
+ 'src/llex.c',
|
||||
+ 'src/lmathlib.c',
|
||||
+ 'src/lmem.c',
|
||||
+ 'src/loadlib.c',
|
||||
+ 'src/lobject.c',
|
||||
+ 'src/lopcodes.c',
|
||||
+ 'src/loslib.c',
|
||||
+ 'src/lparser.c',
|
||||
+ 'src/lstate.c',
|
||||
+ 'src/lstring.c',
|
||||
+ 'src/lstrlib.c',
|
||||
+ 'src/ltable.c',
|
||||
+ 'src/ltablib.c',
|
||||
+ 'src/ltm.c',
|
||||
+ 'src/lundump.c',
|
||||
+ 'src/lutf8lib.c',
|
||||
+ 'src/lvm.c',
|
||||
+ 'src/lzio.c',
|
||||
+ dependencies: lua_lib_deps,
|
||||
+ version: meson.project_version(),
|
||||
+ soversion: lua_versions[0] + '.' + lua_versions[1],
|
||||
+ implicit_include_directories: false,
|
||||
+ install: true,
|
||||
+)
|
||||
+
|
||||
+inc = include_directories('src')
|
||||
+lua_dep = declare_dependency(
|
||||
+ link_with: lua_lib,
|
||||
+ include_directories: inc,
|
||||
+)
|
||||
+
|
||||
+if get_option('interpreter')
|
||||
+ lua_exe = executable(
|
||||
+ 'lua',
|
||||
+ 'src/lua.c',
|
||||
+ c_args: lua_exe_args,
|
||||
+ dependencies: [lua_dep, lua_exe_deps],
|
||||
+ export_dynamic: dl_dep.found(),
|
||||
+ implicit_include_directories: false,
|
||||
+ )
|
||||
+
|
||||
+ if get_option('default_library') == 'static'
|
||||
+ luac_exe = executable(
|
||||
+ 'luac',
|
||||
+ 'src/luac.c',
|
||||
+ dependencies: lua_dep,
|
||||
+ implicit_include_directories: false,
|
||||
+ )
|
||||
+ endif
|
||||
+endif
|
||||
diff --git a/meson_options.txt b/meson_options.txt
|
||||
new file mode 100644
|
||||
index 0000000..3db9320
|
||||
--- /dev/null
|
||||
+++ b/meson_options.txt
|
||||
@@ -0,0 +1,12 @@
|
||||
+option(
|
||||
+ 'loadlib', type: 'feature',
|
||||
+ description: 'Allow Lua to "require" C extension modules'
|
||||
+)
|
||||
+option(
|
||||
+ 'line_editing', type: 'boolean', value: false,
|
||||
+ description: 'Link with GNU readline (or libedit) to add history to the Lua interpreter.'
|
||||
+)
|
||||
+option(
|
||||
+ 'interpreter', type: 'boolean', value: true,
|
||||
+ description: 'Build the Lua interpreter.'
|
||||
+)
|
||||
26
app-editors/lite-xl/patches/lite_xl-2.1.8.patch
Normal file
26
app-editors/lite-xl/patches/lite_xl-2.1.8.patch
Normal file
@@ -0,0 +1,26 @@
|
||||
diff --git a/data/core/start.lua b/data/core/start.lua
|
||||
index 46f3cbe..32956f5 100644
|
||||
--- a/data/core/start.lua
|
||||
+++ b/data/core/start.lua
|
||||
@@ -10,7 +10,7 @@ if MACOS_RESOURCES then
|
||||
DATADIR = MACOS_RESOURCES
|
||||
else
|
||||
local prefix = EXEDIR:match("^(.+)[/\\]bin$")
|
||||
- DATADIR = prefix and (prefix .. PATHSEP .. 'share' .. PATHSEP .. 'lite-xl') or (EXEDIR .. PATHSEP .. 'data')
|
||||
+ DATADIR = os.getenv('XDG_DATA_DIRS'):match('^.-:(.-)$') .. '/lite-xl'
|
||||
end
|
||||
USERDIR = (system.get_file_info(EXEDIR .. PATHSEP .. 'user') and (EXEDIR .. PATHSEP .. 'user'))
|
||||
or os.getenv("LITE_USERDIR")
|
||||
diff --git a/src/main.c b/src/main.c
|
||||
index 4642a85..6433370 100644
|
||||
--- a/src/main.c
|
||||
+++ b/src/main.c
|
||||
@@ -214,7 +214,7 @@ init_lua:
|
||||
" HOME = os.getenv('" LITE_OS_HOME "')\n"
|
||||
" local exedir = match(EXEFILE, '^(.*)" LITE_PATHSEP_PATTERN LITE_NONPATHSEP_PATTERN "$')\n"
|
||||
" local prefix = match(exedir, '^(.*)" LITE_PATHSEP_PATTERN "bin$')\n"
|
||||
- " dofile((MACOS_RESOURCES or (prefix and prefix .. '/share/lite-xl' or exedir .. '/data')) .. '/core/start.lua')\n"
|
||||
+ " dofile(os.getenv('XDG_DATA_DIRS'):match('^.-:(.-)$') .. '/lite-xl/core/start.lua')\n"
|
||||
" core = require(os.getenv('LITE_XL_RUNTIME') or 'core')\n"
|
||||
" core.init()\n"
|
||||
" core.run()\n"
|
||||
251
app-editors/lite-xl/patches/lua-unicode.diff
Normal file
251
app-editors/lite-xl/patches/lua-unicode.diff
Normal file
@@ -0,0 +1,251 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Jan200101 <sentrycraft123@gmail.com>
|
||||
Date: Fri, 29 Nov 2024 08:19:27 +0100
|
||||
Subject: [PATCH] add utf8 wrapper
|
||||
|
||||
Signed-off-by: Jan200101 <sentrycraft123@gmail.com>
|
||||
---
|
||||
meson.build | 1 +
|
||||
src/Makefile | 2 +-
|
||||
src/luaconf.h | 10 ++++
|
||||
src/utf8_wrappers.c | 129 ++++++++++++++++++++++++++++++++++++++++++++
|
||||
src/utf8_wrappers.h | 46 ++++++++++++++++
|
||||
5 files changed, 187 insertions(+), 1 deletion(-)
|
||||
create mode 100644 src/utf8_wrappers.c
|
||||
create mode 100644 src/utf8_wrappers.h
|
||||
|
||||
diff --git a/meson.build b/meson.build
|
||||
index ffd115c..31efb31 100644
|
||||
--- a/meson.build
|
||||
+++ b/meson.build
|
||||
@@ -82,6 +82,7 @@ lua_lib = library(
|
||||
'src/lutf8lib.c',
|
||||
'src/lvm.c',
|
||||
'src/lzio.c',
|
||||
+ 'src/utf8_wrappers.c',
|
||||
dependencies: lua_lib_deps,
|
||||
version: meson.project_version(),
|
||||
soversion: lua_versions[0] + '.' + lua_versions[1],
|
||||
diff --git a/src/Makefile b/src/Makefile
|
||||
index b771196..6d3ff24 100644
|
||||
--- a/src/Makefile
|
||||
+++ b/src/Makefile
|
||||
@@ -33,7 +33,7 @@ CMCFLAGS=
|
||||
PLATS= guess aix bsd c89 freebsd generic ios linux linux-readline macosx mingw posix solaris
|
||||
|
||||
LUA_A= liblua.a
|
||||
-CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o
|
||||
+CORE_O= lapi.o lcode.o lctype.o ldebug.o ldo.o ldump.o lfunc.o lgc.o llex.o lmem.o lobject.o lopcodes.o lparser.o lstate.o lstring.o ltable.o ltm.o lundump.o lvm.o lzio.o utf8_wrappers.o
|
||||
LIB_O= lauxlib.o lbaselib.o lcorolib.o ldblib.o liolib.o lmathlib.o loadlib.o loslib.o lstrlib.o ltablib.o lutf8lib.o linit.o
|
||||
BASE_O= $(CORE_O) $(LIB_O) $(MYOBJS)
|
||||
|
||||
diff --git a/src/luaconf.h b/src/luaconf.h
|
||||
index 137103e..3cd0d53 100644
|
||||
--- a/src/luaconf.h
|
||||
+++ b/src/luaconf.h
|
||||
@@ -789,5 +789,15 @@
|
||||
|
||||
|
||||
|
||||
+#if defined(lua_c) || defined(luac_c) || (defined(LUA_LIB) && \
|
||||
+ (defined(lauxlib_c) || defined(liolib_c) || \
|
||||
+ defined(loadlib_c) || defined(loslib_c)))
|
||||
+#include "utf8_wrappers.h"
|
||||
+#endif
|
||||
+
|
||||
+
|
||||
+
|
||||
+
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/utf8_wrappers.c b/src/utf8_wrappers.c
|
||||
new file mode 100644
|
||||
index 0000000..5b9b1f6
|
||||
--- /dev/null
|
||||
+++ b/src/utf8_wrappers.c
|
||||
@@ -0,0 +1,129 @@
|
||||
+/**
|
||||
+ * Wrappers to provide Unicode (UTF-8) support on Windows.
|
||||
+ *
|
||||
+ * Copyright (c) 2018 Peter Wu <peter@lekensteyn.nl>
|
||||
+ * SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
|
||||
+ */
|
||||
+
|
||||
+#ifdef _WIN32
|
||||
+#include <windows.h> /* for MultiByteToWideChar */
|
||||
+#include <wchar.h> /* for _wrename */
|
||||
+#include <stdio.h>
|
||||
+#include <stdlib.h>
|
||||
+#include <errno.h>
|
||||
+
|
||||
+// A environment variable has the maximum length of 32767 characters
|
||||
+// including the terminator.
|
||||
+#define MAX_ENV_SIZE 32767
|
||||
+// Set a high limit in case long paths are enabled.
|
||||
+#define MAX_PATH_SIZE 4096
|
||||
+#define MAX_MODE_SIZE 128
|
||||
+// cmd.exe argument length is reportedly limited to 8192.
|
||||
+#define MAX_CMD_SIZE 8192
|
||||
+
|
||||
+static char env_value[MAX_ENV_SIZE];
|
||||
+
|
||||
+FILE *fopen_utf8(const char *pathname, const char *mode) {
|
||||
+ wchar_t pathname_w[MAX_PATH_SIZE];
|
||||
+ wchar_t mode_w[MAX_MODE_SIZE];
|
||||
+ if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, pathname, -1, pathname_w, MAX_PATH_SIZE) ||
|
||||
+ !MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, mode_w, MAX_MODE_SIZE)) {
|
||||
+ errno = EINVAL;
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ return _wfopen(pathname_w, mode_w);
|
||||
+}
|
||||
+
|
||||
+FILE *freopen_utf8(const char *pathname, const char *mode, FILE *stream) {
|
||||
+ wchar_t pathname_w[MAX_PATH_SIZE];
|
||||
+ wchar_t mode_w[MAX_MODE_SIZE];
|
||||
+ if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, pathname, -1, pathname_w, MAX_PATH_SIZE) ||
|
||||
+ !MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, mode_w, MAX_MODE_SIZE)) {
|
||||
+ // Close stream as documented for the error case.
|
||||
+ fclose(stream);
|
||||
+ errno = EINVAL;
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ return _wfreopen(pathname_w, mode_w, stream);
|
||||
+}
|
||||
+
|
||||
+int remove_utf8(const char *pathname) {
|
||||
+ wchar_t pathname_w[MAX_PATH_SIZE];
|
||||
+ if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, pathname, -1, pathname_w, MAX_PATH_SIZE)) {
|
||||
+ errno = EINVAL;
|
||||
+ return -1;
|
||||
+ }
|
||||
+ return _wremove(pathname_w);
|
||||
+}
|
||||
+
|
||||
+int rename_utf8(const char *oldpath, const char *newpath) {
|
||||
+ wchar_t oldpath_w[MAX_PATH_SIZE];
|
||||
+ wchar_t newpath_w[MAX_PATH_SIZE];
|
||||
+ if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, oldpath, -1, oldpath_w, MAX_PATH_SIZE) ||
|
||||
+ !MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, newpath, -1, newpath_w, MAX_PATH_SIZE)) {
|
||||
+ errno = EINVAL;
|
||||
+ return -1;
|
||||
+ }
|
||||
+ return _wrename(oldpath_w, newpath_w);
|
||||
+}
|
||||
+
|
||||
+FILE *popen_utf8(const char *command, const char *mode) {
|
||||
+ wchar_t command_w[MAX_CMD_SIZE];
|
||||
+ wchar_t mode_w[MAX_MODE_SIZE];
|
||||
+ if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, command, -1, command_w, MAX_CMD_SIZE) ||
|
||||
+ !MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, mode, -1, mode_w, MAX_MODE_SIZE)) {
|
||||
+ errno = EINVAL;
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ return _wpopen(command_w, mode_w);
|
||||
+}
|
||||
+
|
||||
+int system_utf8(const char *command) {
|
||||
+ wchar_t command_w[MAX_CMD_SIZE];
|
||||
+ if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, command, -1, command_w, MAX_CMD_SIZE)) {
|
||||
+ errno = EINVAL;
|
||||
+ return -1;
|
||||
+ }
|
||||
+ return _wsystem(command_w);
|
||||
+}
|
||||
+
|
||||
+DWORD GetModuleFileNameA_utf8(HMODULE hModule, LPSTR lpFilename, DWORD nSize) {
|
||||
+ wchar_t filename_w[MAX_PATH + 1];
|
||||
+ if (!GetModuleFileNameW(hModule, filename_w, MAX_PATH + 1)) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+ return WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, filename_w, -1, lpFilename, nSize, NULL, NULL);
|
||||
+}
|
||||
+
|
||||
+HMODULE LoadLibraryExA_utf8(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags) {
|
||||
+ wchar_t pathname_w[MAX_PATH_SIZE];
|
||||
+ if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, lpLibFileName, -1, pathname_w, MAX_PATH_SIZE)) {
|
||||
+ SetLastError(ERROR_INVALID_NAME);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+ return LoadLibraryExW(pathname_w, hFile, dwFlags);
|
||||
+}
|
||||
+
|
||||
+char* getenv_utf8(const char *varname) {
|
||||
+ /** This implementation is not thread safe.
|
||||
+ * The string is only valid until the next call to getenv.
|
||||
+ * This behavior is allowed per POSIX.1-2017 where it was said that:
|
||||
+ * > The returned string pointer might be invalidated or the string content might be overwritten by a subsequent call to getenv(), setenv(), unsetenv(), or (if supported) putenv() but they shall not be affected by a call to any other function in this volume of POSIX.1-2017.
|
||||
+ * > The returned string pointer might also be invalidated if the calling thread is terminated.
|
||||
+ * > The getenv() function need not be thread-safe.
|
||||
+ */
|
||||
+ wchar_t *value_w;
|
||||
+ wchar_t varname_w[MAX_ENV_SIZE];
|
||||
+
|
||||
+ if (!MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, varname, -1, varname_w, MAX_ENV_SIZE))
|
||||
+ return NULL;
|
||||
+ value_w = _wgetenv((const wchar_t *) varname_w);
|
||||
+ if (!value_w)
|
||||
+ return NULL;
|
||||
+
|
||||
+ if (!WideCharToMultiByte(CP_UTF8, WC_ERR_INVALID_CHARS, value_w, -1, env_value, MAX_ENV_SIZE, NULL, NULL))
|
||||
+ return NULL;
|
||||
+
|
||||
+ return env_value;
|
||||
+}
|
||||
+#endif
|
||||
diff --git a/src/utf8_wrappers.h b/src/utf8_wrappers.h
|
||||
new file mode 100644
|
||||
index 0000000..22e853f
|
||||
--- /dev/null
|
||||
+++ b/src/utf8_wrappers.h
|
||||
@@ -0,0 +1,46 @@
|
||||
+/**
|
||||
+ * Wrappers to provide Unicode (UTF-8) support on Windows.
|
||||
+ *
|
||||
+ * Copyright (c) 2018 Peter Wu <peter@lekensteyn.nl>
|
||||
+ * SPDX-License-Identifier: (GPL-2.0-or-later OR MIT)
|
||||
+ */
|
||||
+
|
||||
+#ifdef _WIN32
|
||||
+
|
||||
+#if defined(loadlib_c) || defined(lauxlib_c) || defined(liolib_c) || defined(luac_c)
|
||||
+#include <stdio.h> /* for loadlib_c */
|
||||
+FILE *fopen_utf8(const char *pathname, const char *mode);
|
||||
+#define fopen fopen_utf8
|
||||
+#endif
|
||||
+
|
||||
+#ifdef lauxlib_c
|
||||
+#include <stdio.h>
|
||||
+FILE *freopen_utf8(const char *pathname, const char *mode, FILE *stream);
|
||||
+#define freopen freopen_utf8
|
||||
+#endif
|
||||
+
|
||||
+#ifdef liolib_c
|
||||
+FILE *popen_utf8(const char *command, const char *mode);
|
||||
+#define _popen popen_utf8
|
||||
+#endif
|
||||
+
|
||||
+#ifdef loslib_c
|
||||
+#include <stdio.h>
|
||||
+int remove_utf8(const char *pathname);
|
||||
+int rename_utf8(const char *oldpath, const char *newpath);
|
||||
+int system_utf8(const char *command);
|
||||
+char *getenv_utf8(const char *varname);
|
||||
+#define remove remove_utf8
|
||||
+#define rename rename_utf8
|
||||
+#define system system_utf8
|
||||
+#define getenv getenv_utf8
|
||||
+#endif
|
||||
+
|
||||
+#ifdef loadlib_c
|
||||
+#include <windows.h>
|
||||
+DWORD GetModuleFileNameA_utf8(HMODULE hModule, LPSTR lpFilename, DWORD nSize);
|
||||
+HMODULE LoadLibraryExA_utf8(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags);
|
||||
+#define GetModuleFileNameA GetModuleFileNameA_utf8
|
||||
+#define LoadLibraryExA LoadLibraryExA_utf8
|
||||
+#endif
|
||||
+#endif
|
||||
--
|
||||
2.47.0
|
||||
|
||||
Reference in New Issue
Block a user