From cdd90a08046bdc9c466271fb0eb674c7bfbe9645 Mon Sep 17 00:00:00 2001 From: m32 Date: Wed, 25 Sep 2024 22:20:59 +0200 Subject: [PATCH 01/10] first we import from the user directory, not from plugins directory --- python/configs/plug/far2l/pluginmanager.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/configs/plug/far2l/pluginmanager.py b/python/configs/plug/far2l/pluginmanager.py index cb8ed7a43..7de4385fc 100644 --- a/python/configs/plug/far2l/pluginmanager.py +++ b/python/configs/plug/far2l/pluginmanager.py @@ -13,7 +13,7 @@ def setup(): if os.path.isdir(USERHOME): - sys.path.insert(3, USERHOME) + sys.path.insert(1, USERHOME) fname = os.path.join(USERHOME, "logger.ini") if os.path.isfile(fname): with open(fname, "rt") as fp: From 0a0d41af6b042642b5006dea8e40892fcc5cc14e Mon Sep 17 00:00:00 2001 From: m32 Date: Tue, 1 Oct 2024 21:27:32 +0200 Subject: [PATCH 02/10] Virtualenv not required to build python plugin --- CMakeLists.txt | 40 +++++----------------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 629c8226b..d695b461c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -461,7 +461,7 @@ else() " COMPONENT system) endif() -if (DEFINED VIRTUAL_PYTHON) +if (DEFINED PYTHON AND PYTHON) message(STATUS "PYTHON plugin with interpreter from virtualenv enabled") add_subdirectory (python) # Copy this explicitly cuz generic copier command excludes 'far2l' @@ -470,40 +470,10 @@ if (DEFINED VIRTUAL_PYTHON) COMPONENT base FILES_MATCHING PATTERN "*") else() - if (DEFINED PYTHON AND PYTHON) - find_package(Python3 COMPONENTS Interpreter Development) - - if(Python3_FOUND AND Python3_Development_FOUND) - message(STATUS "PYTHON plugin enabled") - add_subdirectory (python) - install(CODE " - execute_process(COMMAND echo Python: preparing virtual environment) - " COMPONENT system) - install(CODE " - execute_process(COMMAND ${Python3_EXECUTABLE} -m venv --system-site-packages ${CMAKE_INSTALL_PREFIX}/lib/far2l/Plugins/python/plug/python) - " COMPONENT system) - install(CODE " - execute_process(COMMAND echo Python: installing packages) - " COMPONENT system) - install(CODE " - execute_process(COMMAND ${CMAKE_INSTALL_PREFIX}/lib/far2l/Plugins/python/plug/python/bin/python -m pip install cffi debugpy) - " COMPONENT system) - - # Copy this explicitly cuz generic copier command excludes 'far2l' - install(DIRECTORY "${INSTALL_DIR}/Plugins/python/plug/far2l" - DESTINATION "lib/far2l/Plugins/python/plug/" USE_SOURCE_PERMISSIONS - COMPONENT base FILES_MATCHING - PATTERN "*") - else() - message(WARNING "${ColorRed}PYTHON plugin disabled due to missing python3 environment${ColorNormal}") - endif () - - else() - message(STATUS "${ColorRed}PYTHON plugin disabled, use -DPYTHON=yes if you need it${ColorNormal}") - install(CODE " - execute_process(COMMAND rm -f ${CMAKE_INSTALL_PREFIX}/lib/far2l/Plugins/python/plug/python.far-plug-wide) - " COMPONENT system) - endif() + message(STATUS "${ColorRed}PYTHON plugin disabled, use -DPYTHON=yes if you need it${ColorNormal}") + install(CODE " + execute_process(COMMAND rm -f ${CMAKE_INSTALL_PREFIX}/lib/far2l/Plugins/python/plug/python.far-plug-wide) + " COMPONENT system) endif() if (NOT DEFINED SIMPLEINDENT OR SIMPLEINDENT) From 7125921794d11631adf63bb7c4e68038fb2bbe86 Mon Sep 17 00:00:00 2001 From: m32 Date: Tue, 1 Oct 2024 21:27:42 +0200 Subject: [PATCH 03/10] Virtualenv not required to build python plugin --- python/CMakeLists.txt | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 2f0a1b4c0..9fbfc9ec1 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -6,13 +6,6 @@ src/python.cpp ${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py ) -if (DEFINED VIRTUAL_PYTHON) - message(STATUS "VIRTUAL env interpreter=${VIRTUAL_PYTHON}") - message(STATUS "VIRTUAL env interpreter version=${VIRTUAL_PYTHON_VERSION}") - # for finding adequate python package - set(Python3_EXECUTABLE ${VIRTUAL_PYTHON}) -endif() - find_package(Python3 COMPONENTS Interpreter Development) # find Python interpreter and library message(STATUS "Python3_VERSION = ${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}") message(STATUS "Python3_EXECUTABLE = ${Python3_EXECUTABLE}") @@ -34,18 +27,7 @@ target_compile_definitions(python PRIVATE -DFAR_USE_INTERNALS -DPROCPLUGINMACROFUNC -DPYTHON_LIBRARY="${Python3_LIBRARIES}" - -DPYTHON_VERSION="${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR}" ) -if (DEFINED VIRTUAL_PYTHON) - target_compile_definitions(python PRIVATE - -DVIRTUAL_PYTHON="${VIRTUAL_PYTHON}" - ) - set(Python_EXECUTABLE ${VIRTUAL_PYTHON}) -else() - set(VIRTUAL_PYTHON_VERSION 0) - set(Python_EXECUTABLE ${Python3_EXECUTABLE}) -endif() - target_include_directories(python PRIVATE .) target_include_directories(python PRIVATE ../WinPort) @@ -64,13 +46,6 @@ add_custom_command(TARGET python POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/configs" "${INSTALL_DIR}/Plugins/python" COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py" "${INSTALL_DIR}/Plugins/python/plug/far2l" ) -if (NOT DEFINED VIRTUAL_PYTHON) - add_custom_command(TARGET python POST_BUILD - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/configs - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/far2lcffi.py - COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_BINARY_DIR}/python" "${INSTALL_DIR}/Plugins/python/plug/python" - ) -endif() add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/pythongen.py @@ -80,5 +55,5 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py DEPENDS ../WinPort/windows.h DEPENDS ../WinPort/WinCompat.h DEPENDS ../WinPort/WinPort.h - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/prebuild.sh "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" "${VIRTUAL_PYTHON_VERSION}" "${Python_EXECUTABLE}" "${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS}" + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/prebuild.sh "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" "${Python3_EXECUTABLE}" "${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS}" ) From ba68bb85c89a98d63efbcf5c19f07ce147ee091f Mon Sep 17 00:00:00 2001 From: m32 Date: Tue, 1 Oct 2024 21:27:45 +0200 Subject: [PATCH 04/10] Virtualenv not required to build python plugin --- python/src/prebuild.sh | 34 ++++++--------------- python/src/python.cpp | 67 +++++------------------------------------ python/src/pythongen.py | 1 - 3 files changed, 18 insertions(+), 84 deletions(-) diff --git a/python/src/prebuild.sh b/python/src/prebuild.sh index 49c26983e..c48bcf9ad 100755 --- a/python/src/prebuild.sh +++ b/python/src/prebuild.sh @@ -4,28 +4,18 @@ echo "XBUILD=$*" SRC="$1" DST="$2" -VIRTUAL_PYTHON="$3" -PYTHON="$4" -PREPROCESSOR="$5 -E -P -xc" +PYTHON="$3" +PREPROCESSOR="$4 -E -P -xc" mkdir -p "$DST/incpy" -if [ "$VIRTUAL_PYTHON" == "0" ]; then - if [ ! -f "$DST/python/.prepared" ]; then - echo "Preparing python virtual env at $DST/python using $PYTHON" - mkdir -p "$DST/python" - $PYTHON -m venv --system-site-packages "$DST/python" - "$DST/python/bin/python" -m pip install --upgrade pip || true - "$DST/python/bin/python" -m pip install --ignore-installed debugpy pcpp adbutils - "$DST/python/bin/python" -m pip install --force-reinstall --no-binary :all: cffi - $PREPROCESSOR "$SRC/python/src/consts.gen" | sh > "${DST}/incpy/consts.h" - echo "1" > "$DST/python/.prepared" - fi -else - if [ ! -f "$DST/.prepared" ]; then - $PREPROCESSOR "$SRC/python/src/consts.gen" | sh > "${DST}/incpy/consts.h" - echo "1" > "$DST/.prepared" - fi +if [ ! -f "$DST/python/.prepared" ]; then + echo "Preparing python virtual env at $DST/python using $PYTHON" + mkdir -p "$DST/python" + $PYTHON -m venv --system-site-packages "$DST/python" + "$DST/python/bin/python" -m pip install pcpp + $PREPROCESSOR "$SRC/python/src/consts.gen" | sh > "${DST}/incpy/consts.h" + echo "1" > "$DST/python/.prepared" fi ################### @@ -34,8 +24,4 @@ cp -f -R \ "$SRC/python/configs/plug/far2l/"* \ "$DST/incpy/" -if [ "$VIRTUAL_PYTHON" == "0" ]; then - "$DST/python/bin/python" "$SRC/python/src/pythongen.py" "${SRC}" "${DST}/incpy" -else - "$PYTHON" "$SRC/python/src/pythongen.py" "${SRC}" "${DST}/incpy" -fi +"$DST/python/bin/python" "$SRC/python/src/pythongen.py" "${SRC}" "${DST}/incpy" diff --git a/python/src/python.cpp b/python/src/python.cpp index 9417f07b8..50f3a4201 100644 --- a/python/src/python.cpp +++ b/python/src/python.cpp @@ -17,16 +17,11 @@ #include #include #include +#include "../far2l/src/console/savescr.hpp" static struct PluginStartupInfo Info; static FARSTANDARDFUNCTIONS FSF; -// #define PYPLUGIN_DEBUGLOG "/tmp/far2.py.log" - #define PYPLUGIN_DEBUGLOG "" /* to stderr */ -// #define PYPLUGIN_THREADED -// #define PYPLUGIN_MEASURE_STARTUP - -#ifdef PYPLUGIN_DEBUGLOG static void python_log(const char *function, unsigned int line, const char *format, ...) { va_list args; @@ -34,29 +29,12 @@ static void python_log(const char *function, unsigned int line, const char *form sprintf(xformat, "[PYTHON %lu]: %s@%u%s%s", (unsigned long)GetProcessUptimeMSec(), function, line, (*format != '\n') ? " - " : "", format); - FILE *stream = nullptr; - if (PYPLUGIN_DEBUGLOG[0]) { - stream = fopen(PYPLUGIN_DEBUGLOG, "at"); - } - if (!stream) { - stream = stderr; - } - va_start(args, format); - vfprintf(stream, xformat, args); + vfprintf(stderr, xformat, args); va_end(args); - - if (stream != stderr) { - fclose(stream); - } else { - fflush(stderr); - } } #define PYTHON_LOG(args...) python_log(__FUNCTION__, __LINE__, args) -#else -#define PYTHON_LOG(args...) -#endif static PyObject * far2l_CheckForInput(PyObject *self, PyObject *args) @@ -83,8 +61,8 @@ far2l_CheckForEscape(PyObject *self, PyObject *args) } static PyMethodDef Far2lcMethods[] = { - {"CheckForInput", far2l_CheckForInput, METH_VARARGS, "CheckForInput"}, - {"CheckForEscape", far2l_CheckForEscape, METH_VARARGS, "CheckForEscape"}, + {"CheckForInput", far2l_CheckForInput, METH_VARARGS, "CheckForInput"}, + {"CheckForEscape", far2l_CheckForEscape, METH_VARARGS, "CheckForEscape"}, {NULL, NULL, 0, NULL} /* Sentinel */ }; @@ -110,9 +88,8 @@ PYTHON_LOG("status exception\n"); \ goto done; \ } -bool init_python(std::string program_name) +static bool init_python() { -#if 1 PyStatus status; PyConfig config; @@ -126,43 +103,22 @@ bool init_python(std::string program_name) (decode byte string from the locale encoding). Implicitly preinitialize Python. */ - status = PyConfig_SetBytesString(&config, &config.program_name, program_name.c_str()); - FAIL_IF_STATUS_EXCEPTION(status); /* Read all configuration at once */ -PYTHON_LOG("call PyConfig_Read\n"); status = PyConfig_Read(&config); FAIL_IF_STATUS_EXCEPTION(status); PyImport_AppendInittab("far2lc", PyInit_far2lc); -PYTHON_LOG("call Py_InitializeFromConfig\n"); status = Py_InitializeFromConfig(&config); FAIL_IF_STATUS_EXCEPTION(status); -#if 0 -{ - PyObject *sys_path = PySys_GetObject("path"); -// PyList_Insert(sys_path, 0, PyUnicode_FromString("/devel/bin/python3/lib/python3.11/site-packages")); - PyList_Insert(sys_path, 0, PyUnicode_FromString("/path/to/mode/modules2")); - PySys_SetObject("path", sys_path); -} -#endif - PyConfig_Clear(&config); return true; done: PyConfig_Clear(&config); return false; -#else - PyImport_AppendInittab("far2lc", PyInit_far2lc); - Py_SetProgramName((wchar_t *)program_name.c_str()); - - Py_Initialize(); - - return true; -#endif } #ifdef PYPLUGIN_THREADED @@ -183,8 +139,8 @@ class PythonHolder { std::string syspath = "import sys"; syspath += "\nsys.path.insert(1, '" + pluginPath + "')"; - syspath += "\nsys.path.insert(1, '" + pluginPath + "/plugins')"; +PYTHON_LOG("initial sys.path=%s\n", syspath.c_str()); PyRun_SimpleString(syspath.c_str()); PyObject *pName; @@ -219,14 +175,7 @@ class PythonHolder pluginPath.resize(pos); } -#ifdef VIRTUAL_PYTHON - std::string progname = VIRTUAL_PYTHON; -#else - std::string progname = pluginPath; - progname += "/python/bin/python"; -#endif - - PYTHON_LOG("pluginpath: %s, python library used:%s, progname: %s\n", pluginPath.c_str(), PYTHON_LIBRARY, progname.c_str()); + PYTHON_LOG("pluginpath: %s, python library used:%s\n", pluginPath.c_str(), PYTHON_LIBRARY); soPythonInterpreter = dlopen(PYTHON_LIBRARY, RTLD_NOW | RTLD_GLOBAL); if( !soPythonInterpreter ){ PYTHON_LOG("error %u from dlopen('%s')\n", errno, PYTHON_LIBRARY); @@ -234,7 +183,7 @@ class PythonHolder return; } - initok = init_python(progname); + initok = init_python(); if( initok ) { #ifdef PYPLUGIN_THREADED diff --git a/python/src/pythongen.py b/python/src/pythongen.py index c044661d2..3802228e5 100755 --- a/python/src/pythongen.py +++ b/python/src/pythongen.py @@ -4,7 +4,6 @@ import re import pcpp import io -import cffi source = sys.argv[1] target = os.path.join(sys.argv[2], "far2lcffi.py") From ee5b077077fed8965e2e0f8b99acdcb18cafd530 Mon Sep 17 00:00:00 2001 From: m32 Date: Tue, 1 Oct 2024 23:12:57 +0200 Subject: [PATCH 05/10] wrong number of parameters --- python/configs/plug/far2l/farprogress.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/python/configs/plug/far2l/farprogress.py b/python/configs/plug/far2l/farprogress.py index a94ce0d7b..56a5a4d65 100644 --- a/python/configs/plug/far2l/farprogress.py +++ b/python/configs/plug/far2l/farprogress.py @@ -30,7 +30,8 @@ def adv(self, cmd, par): self.info.AdvControl( self.info.ModuleNumber, cmd, - self.ffi.cast("void *", par) + self.ffi.cast("void *", par), + self.ffi.NULL ) def show(self): @@ -67,7 +68,7 @@ def setbar(self, value): percent = value * 100 // self.maxvalue pv = self.ffi.new('struct PROGRESSVALUE *', (percent, 100)) - self.info.AdvControl(self.info.ModuleNumber, self.ffic.ACTL_SETPROGRESSVALUE, pv) + self.adv(self.ffic.ACTL_SETPROGRESSVALUE, pv) nb = int(percent*PROGRESS_WIDTH // 100) self.bar = '\u2588'*nb + '\u2591'*(PROGRESS_WIDTH-nb) From fd9fc2d2c48e39f9f1a72ccb19d83d7be36224e8 Mon Sep 17 00:00:00 2001 From: m32 Date: Tue, 1 Oct 2024 23:15:19 +0200 Subject: [PATCH 06/10] using dialogbuilder for configuration editing and progress dialog while waiting for debugger --- python/configs/plug/plugins/udebug.py | 233 ++++++++------------------ 1 file changed, 66 insertions(+), 167 deletions(-) diff --git a/python/configs/plug/plugins/udebug.py b/python/configs/plug/plugins/udebug.py index b4ef4f267..26a1c4690 100644 --- a/python/configs/plug/plugins/udebug.py +++ b/python/configs/plug/plugins/udebug.py @@ -1,6 +1,17 @@ import logging import debugpy from far2l.plugin import PluginBase +from far2l.farprogress import ProgressMessage +from far2l.fardialogbuilder import ( + TEXT, + EDIT, + BUTTON, + MASKED, + HLine, + HSizer, + VSizer, + DialogBuilder, +) log = logging.getLogger(__name__) @@ -19,10 +30,12 @@ class Plugin(PluginBase): def debug(self): if Config.configured: - log.debug("udebug can be configured only once") + self.parent.Message(("udebug can be configured only once.",)) return - if not Config.configured: + t = ProgressMessage(self, self.label, "Waiting for VSCode", 100) + t.show() + try: Config.configured = True debugpy.log_to(Config.logto) # in vs code debuger select attach, port = 5678 @@ -32,8 +45,12 @@ def debug(self): # import debugpy # debugpy.breakpoint() debugpy.listen((Config.host, Config.port)) - debugpy.wait_for_client() - # debugpy.breakpoint() + debugpy.wait_for_client() + # debugpy.breakpoint() + except: + log.exception() + finally: + t.close() def breakpoint(self): debugpy.breakpoint() @@ -46,174 +63,56 @@ def CommandLine(self, line): getattr(self, line)() def Configure(self): + if Config.configured: + self.parent.Message(("udebug can be configured only once.",)) + return + @self.ffi.callback("FARWINDOWPROC") - def KeyDialogProc(hDlg, Msg, Param1, Param2): - # if Msg == self.ffic.DN_KEY: - # if Param2 == 27: - # return 0 + def DialogProc(hDlg, Msg, Param1, Param2): + if Msg == self.ffic.DN_INITDIALOG: + try: + dlg.SetText(dlg.ID_logpath, Config.logto) + dlg.SetText(dlg.ID_ipaddress, Config.host) + dlg.SetText(dlg.ID_port, str(Config.port)) + except: + log.exception("bang") return self.info.DefDlgProc(hDlg, Msg, Param1, Param2) - fdis = [ - ( - self.ffic.DI_DOUBLEBOX, - 2, - 1, - 32, - 7, - 0, - {"Selected": 0}, - 0, - 0, - self.s2f("Python Debug Config"), - 0, - ), - ( - self.ffic.DI_TEXT, - 4, - 2, - 11, - 0, - 0, - {"Selected": 0}, - 0, - 0, - self.s2f("Log path"), - 0, - ), - ( - self.ffic.DI_EDIT, - 13, - 2, - 30, - 0, - 0, - {"Selected": 0}, - 0, - 0, - self.s2f(Config.logto), - 32, - ), - ( - self.ffic.DI_TEXT, - 4, - 3, - 8, - 0, - 0, - {"Selected": 0}, - 0, - 0, - self.s2f("Host"), - 0, - ), - ( - self.ffic.DI_EDIT, - 13, - 3, - 30, - 0, - 0, - {"Selected": 0}, - 0, - 0, - self.s2f(Config.host), - 32, - ), - ( - self.ffic.DI_TEXT, - 4, - 4, - 8, - 0, - 0, - {"Selected": 0}, - 0, - 0, - self.s2f("Port"), - 0, - ), - ( - self.ffic.DI_EDIT, - 13, - 4, - 30, - 0, - 0, - {"Selected": 0}, - 0, - 0, - self.s2f(str(Config.port)), - 5, - ), - ( - self.ffic.DI_TEXT, - 2, - 5, - 0, - 0, - 0, - {"Selected": 0}, - self.ffic.DIF_SEPARATOR, - 0, - self.ffi.NULL, - 0, - ), - ( - self.ffic.DI_BUTTON, - 6, - 6, - 0, - 0, - 0, - {"Selected": 0}, - 0, - self.ffic.DIF_DEFAULT, - self.s2f("OK"), - 0, - ), - ( - self.ffic.DI_BUTTON, - 19, - 6, - 0, - 0, - 0, - {"Selected": 0}, - 0, - 0, - self.s2f("Cancel"), - 0, - ), - ] - fdi = self.ffi.new("struct FarDialogItem []", fdis) - hDlg = self.info.DialogInit( - self.info.ModuleNumber, - -1, - -1, - fdis[0][3] + 3, - fdis[0][4] + 2, - self.s2f("Debug Config"), - fdi, - len(fdi), - 0, - 0, - KeyDialogProc, + b = DialogBuilder( + self, + DialogProc, + "debugpy config", + "helptopic", 0, + VSizer( + HSizer( + TEXT(None, "log path:"), + EDIT("logpath", 33, maxlength=80), + ), + HSizer( + TEXT(None, "ip address:"), + EDIT("ipaddress", 20), + ), + HSizer( + TEXT(None, "ip port:"), + MASKED("port", "99999"), + ), + HLine(), + HSizer( + BUTTON("vok", "OK", default=True, flags=self.ffic.DIF_CENTERGROUP), + BUTTON("vcancel", "Cancel", flags=self.ffic.DIF_CENTERGROUP), + ), + ), ) - res = self.info.DialogRun(hDlg) - log.debug("dialog result: {0}".format(res)) - if res == 8: - result = [] - for i in (2, 4, 6): - sptr = self.info.SendDlgMessage( - hDlg, self.ffic.DM_GETCONSTTEXTPTR, i, 0 - ) - result.append(self.f2s(sptr)) - log.debug("result: {0}".format(result)) - Config.logto = result[0] - Config.host = result[1] - Config.port = int(result[2]) - self.info.DialogFree(hDlg) + # debugpy.breakpoint() + dlg = b.build(-1, -1) + + res = self.info.DialogRun(dlg.hDlg) + if res == dlg.ID_vok: + Config.logto = dlg.GetText(dlg.ID_logpath) + Config.host = dlg.GetText(dlg.ID_ipaddress) + Config.port = int(dlg.GetText(dlg.ID_port), 10) + self.info.DialogFree(dlg.hDlg) log.debug("end dialog") def OpenPlugin(self, OpenFrom): From 31f3edc90a78a3b37e312acd558356971d58cce6 Mon Sep 17 00:00:00 2001 From: m32 Date: Thu, 3 Oct 2024 04:54:20 +0200 Subject: [PATCH 07/10] Python compatible changes, for exporting as modules --- WinPort/WinPort.h | 259 +++++------------------------------------- WinPort/WinPortDecl.h | 224 ++++++++++++++++++++++++++++++++++++ 2 files changed, 252 insertions(+), 231 deletions(-) create mode 100644 WinPort/WinPortDecl.h diff --git a/WinPort/WinPort.h b/WinPort/WinPort.h index 47fa2a01b..5493f3650 100644 --- a/WinPort/WinPort.h +++ b/WinPort/WinPort.h @@ -10,82 +10,17 @@ # include # include #endif +#endif /* FAR_PYTHON_GEN */ -#define WINPORT_DECL(NAME, RV, ARGS) SHAREDSYMBOL RV WINPORT_##NAME ARGS -#define WINPORT(NAME) WINPORT_##NAME - -#ifdef __cplusplus -extern "C" { -#endif - int WinPortMain(const char *full_exe_path, int argc, char **argv, int (*AppMain)(int argc, char **argv)); - void WinPortHelp(); - const wchar_t *WinPortBackend(); - - // true means far2l runs under smoke testing and code must - // not skip events from input queue that sometimes used to make UX smoother - BOOL WinPortTesting(); - - ///console API - WINPORT_DECL(ForkConsole,HANDLE,()); - WINPORT_DECL(JoinConsole,VOID,(HANDLE hConsole)); - - WINPORT_DECL(GetLargestConsoleWindowSize,COORD,(HANDLE hConsoleOutput)); - WINPORT_DECL(SetConsoleWindowInfo,BOOL,(HANDLE hConsoleOutput, BOOL bAbsolute, const SMALL_RECT *lpConsoleWindow)); - WINPORT_DECL(SetConsoleTitle,BOOL,(HANDLE hConsoleOutput, const WCHAR *title)); - WINPORT_DECL(GetConsoleTitle,DWORD,(HANDLE hConsoleOutput, WCHAR *title, DWORD max_size)); - WINPORT_DECL(SetConsoleScreenBufferSize,BOOL,(HANDLE hConsoleOutput,COORD dwSize)); - WINPORT_DECL(GetConsoleScreenBufferInfo,BOOL,(HANDLE hConsoleOutput,CONSOLE_SCREEN_BUFFER_INFO *lpConsoleScreenBufferInfo)); - WINPORT_DECL(SetConsoleCursorPosition,BOOL,(HANDLE hConsoleOutput,COORD dwCursorPosition)); - WINPORT_DECL(SetConsoleCursorInfo,BOOL,(HANDLE hConsoleOutput,const CONSOLE_CURSOR_INFO *lpConsoleCursorInfon)); - WINPORT_DECL(GetConsoleCursorInfo,BOOL,(HANDLE hConsoleOutput,CONSOLE_CURSOR_INFO *lpConsoleCursorInfon)); - WINPORT_DECL(GetConsoleMode,BOOL,(HANDLE hConsoleHandle,LPDWORD lpMode)); - WINPORT_DECL(SetConsoleMode,BOOL,(HANDLE hConsoleHandle, DWORD dwMode)); - WINPORT_DECL(ScrollConsoleScreenBuffer,BOOL,(HANDLE hConsoleOutput, const SMALL_RECT *lpScrollRectangle, const SMALL_RECT *lpClipRectangle, COORD dwDestinationOrigin, const CHAR_INFO *lpFill)); - WINPORT_DECL(SetConsoleTextAttribute,BOOL,(HANDLE hConsoleOutput, DWORD64 qAttributes)); - WINPORT_DECL(CompositeCharRegister,COMP_CHAR,(const WCHAR *lpSequence)); - WINPORT_DECL(CompositeCharLookup,const WCHAR *,(COMP_CHAR CompositeChar)); - WINPORT_DECL(WriteConsole,BOOL,(HANDLE hConsoleOutput, const WCHAR *lpBuffer, DWORD nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)); - WINPORT_DECL(WriteConsoleOutput,BOOL,(HANDLE hConsoleOutput,const CHAR_INFO *lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpScreenRegion)); - WINPORT_DECL(WriteConsoleOutputCharacter,BOOL,(HANDLE hConsoleOutput, const WCHAR *lpCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten)); - WINPORT_DECL(WaitConsoleInput, BOOL,(HANDLE hConsoleInput, DWORD dwTimeout)); - WINPORT_DECL(ReadConsoleOutput, BOOL, (HANDLE hConsoleOutput, CHAR_INFO *lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpScreenRegion)); - WINPORT_DECL(FillConsoleOutputAttribute, BOOL, (HANDLE hConsoleOutput, DWORD64 qAttributes, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfAttrsWritten)); - WINPORT_DECL(FillConsoleOutputCharacter, BOOL, (HANDLE hConsoleOutput, WCHAR cCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten)); - WINPORT_DECL(SetConsoleActiveScreenBuffer, BOOL,(HANDLE hConsoleOutput)); - WINPORT_DECL(SetConsoleCursorBlinkTime,VOID,(HANDLE hConsoleOutput, DWORD dwMilliseconds )); - - WINPORT_DECL(FlushConsoleInputBuffer,BOOL,(HANDLE hConsoleInput)); - WINPORT_DECL(GetNumberOfConsoleInputEvents,BOOL,(HANDLE hConsoleInput, LPDWORD lpcNumberOfEvents)); - WINPORT_DECL(PeekConsoleInput,BOOL,(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead)); - WINPORT_DECL(ReadConsoleInput,BOOL,(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead)); - WINPORT_DECL(WriteConsoleInput,BOOL,(HANDLE hConsoleInput, const INPUT_RECORD *lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsWritten)); - - // Checks if any of specified keys pressed - // Optionally preserves specified classes of input events - // return one plus array index of pressed key or zero if no one of specified keys is pressed +// CheckForKeyPress Checks if any of specified keys pressed +// Optionally preserves specified classes of input events +// return one plus array index of pressed key or zero if no one of specified keys is pressed #define CFKP_KEEP_MATCHED_KEY_EVENTS 0x001 #define CFKP_KEEP_UNMATCHED_KEY_EVENTS 0x002 #define CFKP_KEEP_MOUSE_EVENTS 0x004 #define CFKP_KEEP_OTHER_EVENTS 0x100 - WINPORT_DECL(CheckForKeyPress,DWORD,(HANDLE hConsoleInput, const WORD *KeyCodes, DWORD KeyCodesCount, DWORD Flags)); - - WINPORT_DECL(SetConsoleDisplayMode,BOOL,(DWORD ModeFlags)); - WINPORT_DECL(GetConsoleDisplayMode,BOOL,(LPDWORD lpModeFlags)); - WINPORT_DECL(SetConsoleWindowMaximized,VOID,(BOOL Maximized)); - WINPORT_DECL(GetConsoleColorPalette,BYTE,(HANDLE hConsoleOutput)); // Returns current color resolution: 4, 8, 24 - WINPORT_DECL(GetConsoleBasePalette,VOID,(HANDLE hConsoleOutput, void *p)); - WINPORT_DECL(SetConsoleBasePalette,BOOL,(HANDLE hConsoleOutput, void *p)); - - WINPORT_DECL(GenerateConsoleCtrlEvent, BOOL, (DWORD dwCtrlEvent, DWORD dwProcessGroupId )); - WINPORT_DECL(SetConsoleCtrlHandler, BOOL, (PHANDLER_ROUTINE HandlerRoutine, BOOL Add )); - - WINPORT_DECL(SetConsoleScrollRegion, VOID, (HANDLE hConsoleOutput, SHORT top, SHORT bottom)); - WINPORT_DECL(GetConsoleScrollRegion, VOID, (HANDLE hConsoleOutput, SHORT *top, SHORT *bottom)); - - WINPORT_DECL(SetConsoleScrollCallback, VOID, (HANDLE hConsoleOutput, PCONSOLE_SCROLL_CALLBACK pCallback, PVOID pContext)); - WINPORT_DECL(BeginConsoleAdhocQuickEdit, BOOL, ()); - WINPORT_DECL(SetConsoleTweaks, DWORD64, (DWORD64 tweaks)); +// SetConsoleTweaks #define EXCLUSIVE_CTRL_LEFT 0x00000001 #define EXCLUSIVE_CTRL_RIGHT 0x00000002 #define EXCLUSIVE_ALT_LEFT 0x00000004 @@ -105,95 +40,7 @@ extern "C" { #define TWEAK_STATUS_SUPPORT_TTY_PALETTE 0x10 #define TWEAK_STATUS_SUPPORT_BLINK_RATE 0x20 - WINPORT_DECL(SaveConsoleWindowState,VOID,()); - WINPORT_DECL(ConsoleChangeFont, VOID, ()); - WINPORT_DECL(IsConsoleActive, BOOL, ()); - WINPORT_DECL(ConsoleDisplayNotification, VOID, (const WCHAR *title, const WCHAR *text)); - WINPORT_DECL(ConsoleBackgroundMode, BOOL, (BOOL TryEnterBackgroundMode)); - WINPORT_DECL(SetConsoleFKeyTitles, BOOL, (HANDLE hConsoleOutput, const CHAR **titles)); - - // Query/Change or only Query palette color with specified index: - // if Index set to (DWORD)-1 then operates on currently chosen color (not using pallette) - // if initial *ColorFG or *ColorBK was set to (DWORD)-1 - it will change to default color - // if initial *ColorFG or *ColorBK was set to (DWORD)-2 - this color will not be changed (Query-only operation) - WINPORT_DECL(OverrideConsoleColor, VOID, (HANDLE hConsoleOutput, DWORD Index, DWORD *ColorFG, DWORD *ColorBK)); - - WINPORT_DECL(SetConsoleRepaintsDefer, VOID, (HANDLE hConsoleOutput, BOOL Deferring)); - -#ifdef WINPORT_REGISTRY - ///registry API - WINPORT_DECL(RegOpenKeyEx, LONG, (HKEY hKey,LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)); - WINPORT_DECL(RegCreateKeyEx, LONG, (HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions, - REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)); - WINPORT_DECL(RegCloseKey, LONG, (HKEY hKey)); - WINPORT_DECL(RegDeleteKey, LONG, (HKEY hKey, LPCWSTR lpSubKey)); - WINPORT_DECL(RegDeleteValue, LONG, (HKEY hKey, LPCWSTR lpValueName)); - WINPORT_DECL(RegSetValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, - DWORD dwType, const BYTE *lpData, DWORD cbData)); - WINPORT_DECL(RegEnumKeyEx, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpName, LPDWORD lpcName, - LPDWORD lpReserved, LPWSTR lpClass,LPDWORD lpcClass, PFILETIME lpftLastWriteTime)); - WINPORT_DECL(RegEnumKey, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD cchName)); - WINPORT_DECL(RegEnumValue, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpValueName, LPDWORD lpcchValueName, - LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)); - WINPORT_DECL(RegQueryValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName, - LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)); - WINPORT_DECL(RegSetValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName, - DWORD lpReserved, DWORD lpType, CONST BYTE * lpData, DWORD cbData)); - WINPORT_DECL(RegQueryInfoKey, LONG, (HKEY hKey, LPTSTR lpClass, LPDWORD lpcClass, - LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, - LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, - LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)); - - WINPORT_DECL(RegWipeBegin, VOID, ()); - WINPORT_DECL(RegWipeEnd, VOID, ()); -#endif - -//other - WINPORT_DECL(GetLastError, DWORD, ()); - WINPORT_DECL(SetLastError, VOID, (DWORD code)); - WINPORT_DECL(GetCurrentProcessId, DWORD, ()); - WINPORT_DECL(GetDoubleClickTime, DWORD, ()); - -//files - WINPORT_DECL(CreateDirectory, BOOL, (LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes )); - WINPORT_DECL(RemoveDirectory, BOOL, ( LPCWSTR lpDirName)); - WINPORT_DECL(DeleteFile, BOOL, ( LPCWSTR lpFileName)); - WINPORT_DECL(CreateFile, HANDLE, ( LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, - const DWORD *UnixMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)); - WINPORT_DECL(GetFileDescriptor, int, (HANDLE hFile)); - WINPORT_DECL(CloseHandle, BOOL, (HANDLE hObject)); - WINPORT_DECL(MoveFile, BOOL, (LPCWSTR ExistingFileName, LPCWSTR NewFileName )); - WINPORT_DECL(MoveFileEx, BOOL, (LPCWSTR ExistingFileName, LPCWSTR NewFileName,DWORD dwFlags)); - WINPORT_DECL(GetCurrentDirectory, DWORD, (DWORD nBufferLength, LPWSTR lpBuffer)); - WINPORT_DECL(SetCurrentDirectory, BOOL, (LPCWSTR lpPathName)); - WINPORT_DECL(GetFileSizeEx, BOOL, ( HANDLE hFile, PLARGE_INTEGER lpFileSize)); - WINPORT_DECL(GetFileSize, DWORD, ( HANDLE hFile, LPDWORD lpFileSizeHigh)); - WINPORT_DECL(GetFileSize64, DWORD64, ( HANDLE hFile)); - WINPORT_DECL(ReadFile, BOOL, ( HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, - LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)); - WINPORT_DECL(WriteFile, BOOL, ( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, - LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)); - WINPORT_DECL(SetFilePointerEx, BOOL, ( HANDLE hFile, LARGE_INTEGER liDistanceToMove, - PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)); - - // hints that file will soon grow up to specified size, doesnt change actual size of file - WINPORT_DECL(FileAllocationHint, VOID, (HANDLE hFile, DWORD64 HintFileSize)); - // grows file to specified size if it was smaller, ensuring that disk space is actually allocated - WINPORT_DECL(FileAllocationRequire, BOOL, (HANDLE hFile, DWORD64 RequireFileSize)); - - WINPORT_DECL(SetFilePointer, DWORD, ( HANDLE hFile, - LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)); - WINPORT_DECL(GetFileTime, BOOL, ( HANDLE hFile, LPFILETIME lpCreationTime, - LPFILETIME lpLastAccessTime, LPFILETIME lpLastWriteTime)); - WINPORT_DECL(SetFileTime, BOOL, ( HANDLE hFile, const FILETIME *lpCreationTime, - const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)); - WINPORT_DECL(SetEndOfFile, BOOL, ( HANDLE hFile)); - WINPORT_DECL(FlushFileBuffers, BOOL, ( HANDLE hFile)); - WINPORT_DECL(GetFileType, DWORD, ( HANDLE hFile)); - - WINPORT_DECL(GetFileAttributes, DWORD, (LPCWSTR lpFileName)); - WINPORT_DECL(SetFileAttributes, DWORD, (LPCWSTR lpFileName, DWORD dwAttributes)); - +// FindFirstFileWithFlags #define FIND_FILE_FLAG_NO_DIRS 0x01 #define FIND_FILE_FLAG_NO_FILES 0x02 #define FIND_FILE_FLAG_NO_LINKS 0x04 @@ -202,83 +49,32 @@ extern "C" { #define FIND_FILE_FLAG_CASE_INSENSITIVE 0x1000 //currently affects only english characters #define FIND_FILE_FLAG_NOT_ANNOYING 0x2000 //avoid sudo prompt if can't query some not very important information without it - WINPORT_DECL(FindFirstFileWithFlags, HANDLE, (LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags)); - WINPORT_DECL(FindFirstFile, HANDLE, (LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)); - WINPORT_DECL(FindNextFile, BOOL, (HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData)); - WINPORT_DECL(FindClose, BOOL, (HANDLE hFindFile)); +#ifdef __cplusplus +extern "C" { +#endif +#ifndef FAR_PYTHON_GEN + int WinPortMain(const char *full_exe_path, int argc, char **argv, int (*AppMain)(int argc, char **argv)); + void WinPortHelp(); + const wchar_t *WinPortBackend(); - WINPORT_DECL(GetDriveType, UINT, (LPCWSTR lpRootPathName)); - WINPORT_DECL(GetTempFileName, UINT,( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer )); - WINPORT_DECL(GetFullPathName, DWORD, (LPCTSTR lpFileName, DWORD nBufferLength, LPTSTR lpBuffer, LPTSTR *lpFilePart)); + // true means far2l runs under smoke testing and code must + // not skip events from input queue that sometimes used to make UX smoother + BOOL WinPortTesting(); +#endif /* FAR_PYTHON_GEN */ - WINPORT_DECL(EvaluateAttributes, DWORD,( uint32_t unix_mode, const WCHAR *name )); - WINPORT_DECL(EvaluateAttributesA, DWORD,( uint32_t unix_mode, const char *name )); +#ifndef FAR_PYTHON_GEN +#define WINPORT_DECL_DEF(NAME, RV, ARGS) SHAREDSYMBOL RV WINPORT_##NAME ARGS; +#define WINPORT_DECL(NAME, RV, ARGS) SHAREDSYMBOL RV WINPORT_##NAME ARGS +#define WINPORT(NAME) WINPORT_##NAME +#include "WinPortDecl.h" +#endif /* FAR_PYTHON_GEN */ +#ifndef FAR_PYTHON_GEN //time/date SHAREDSYMBOL clock_t GetProcessUptimeMSec();//use instead of Windows's clock() - WINPORT_DECL(Sleep, VOID, (DWORD dwMilliseconds)); - WINPORT_DECL(GetTickCount, DWORD, ()); - WINPORT_DECL(GetLocalTime, VOID, (LPSYSTEMTIME lpSystemTime)); - WINPORT_DECL(GetSystemTime, VOID, (LPSYSTEMTIME lpSystemTime)); - WINPORT_DECL(SystemTimeToFileTime, BOOL, (const SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime)); - WINPORT_DECL(LocalFileTimeToFileTime, BOOL, (const FILETIME *lpLocalFileTime, LPFILETIME lpFileTime)); - WINPORT_DECL(CompareFileTime, LONG, (const FILETIME *lpFileTime1, const FILETIME *lpFileTime2)); - WINPORT_DECL(FileTimeToLocalFileTime, BOOL, (const FILETIME *lpFileTime, LPFILETIME lpLocalFileTime)); - WINPORT_DECL(FileTimeToSystemTime, BOOL, (const FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime)); - WINPORT_DECL(GetSystemTimeAsFileTime, VOID, (FILETIME *lpFileTime)); - WINPORT_DECL(FileTimeToDosDateTime, BOOL, (const FILETIME *lpFileTime, LPWORD lpFatDate, LPWORD lpFatTime)); - WINPORT_DECL(DosDateTimeToFileTime, BOOL, ( WORD fatdate, WORD fattime, LPFILETIME ft)); - WINPORT_DECL(FileTime_UnixToWin32, VOID, (struct timespec ts, FILETIME *lpFileTime)); - WINPORT_DECL(FileTime_Win32ToUnix, VOID, (const FILETIME *lpFileTime, struct timespec *ts)); - - //string - WINPORT_DECL(LCMapString, INT, (LCID lcid, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)); - WINPORT_DECL(CharUpperBuff, DWORD, (LPWSTR lpsz, DWORD cchLength)); - WINPORT_DECL(CharLowerBuff, DWORD, (LPWSTR lpsz, DWORD cchLength)); - WINPORT_DECL(IsCharLower, BOOL, (WCHAR ch)); - WINPORT_DECL(IsCharUpper, BOOL, (WCHAR ch)); - WINPORT_DECL(IsCharAlpha, BOOL, (WCHAR ch)); - WINPORT_DECL(IsCharAlphaNumeric, BOOL, (WCHAR ch)); - WINPORT_DECL(CompareString, int, ( LCID Locale, DWORD dwCmpFlags, LPCWSTR lpString1, int cchCount1, LPCWSTR lpString2, int cchCount2)); - WINPORT_DECL(CompareStringA, int, ( LCID Locale, DWORD dwCmpFlags, LPCSTR lpString1, int cchCount1, LPCSTR lpString2, int cchCount2)); - WINPORT_DECL(WideCharToMultiByte, int, ( UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, - int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar)); - WINPORT_DECL(MultiByteToWideChar, int, ( UINT CodePage, DWORD dwFlags, - LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar)); - WINPORT_DECL(CharUpper, LPWSTR, (LPWSTR lpsz)); - WINPORT_DECL(CharLower, LPWSTR, (LPWSTR lpsz)); - WINPORT_DECL(GetOEMCP, UINT, ()); - WINPORT_DECL(GetACP, UINT, ()); - WINPORT_DECL(GetCPInfo, BOOL, (UINT CodePage, LPCPINFO lpCPInfo)); - WINPORT_DECL(GetCPInfoEx, BOOL, (UINT codepage, DWORD dwFlags, LPCPINFOEX cpinfo)); - WINPORT_DECL(EnumSystemCodePages, BOOL, (CODEPAGE_ENUMPROCW lpfnCodePageEnum, DWORD flags)); + WINPORT_DECL_DEF(FileTime_UnixToWin32, VOID, (struct timespec ts, FILETIME *lpFileTime)) + WINPORT_DECL_DEF(FileTime_Win32ToUnix, VOID, (const FILETIME *lpFileTime, struct timespec *ts)) - //clipboard - WINPORT_DECL(RegisterClipboardFormat, UINT, (LPCWSTR lpszFormat)); - WINPORT_DECL(OpenClipboard, BOOL, (PVOID Reserved)); - WINPORT_DECL(CloseClipboard, BOOL, ()); - WINPORT_DECL(EmptyClipboard, BOOL, ()); - WINPORT_DECL(IsClipboardFormatAvailable, BOOL, (UINT format)); - - // use Clipboard-Alloc/-Free/-Size to operate data pointers - WINPORT_DECL(GetClipboardData, PVOID, (UINT format)); - WINPORT_DECL(SetClipboardData, PVOID, (UINT format, HANDLE mem)); - - // these are simplified analogs for Win32's Global* APIs, that dedicated to reference clipboard data - WINPORT_DECL(ClipboardAlloc, PVOID, (SIZE_T len)); // allocates zero-initialized memory - WINPORT_DECL(ClipboardSize, SIZE_T, (PVOID mem)); // return _exact_ allocation size - - // note that like in win32, clipboard data is mostly owned by clipboard so ClipboardFree actually useful - // only in case of SetClipboardData's failure. - WINPORT_DECL(ClipboardFree, VOID, (PVOID mem)); - - //keyboard - WINPORT_DECL(GetKeyboardLayoutList, int, (int nBuff, HKL *lpList)); - WINPORT_DECL(MapVirtualKey, UINT, (UINT uCode, UINT uMapType)); - WINPORT_DECL(VkKeyScan, SHORT, (WCHAR ch)); - WINPORT_DECL(ToUnicodeEx, int, (UINT wVirtKey, UINT wScanCode, CONST BYTE *lpKeyState, - LPWSTR pwszBuff, int cchBuff, UINT wFlags, HKL dwhkl)); - //%s -> %ls, %ws -> %ls SHAREDSYMBOL int vswprintf_ws2ls(wchar_t * ws, size_t len, const wchar_t * format, va_list arg ); SHAREDSYMBOL int swprintf_ws2ls (wchar_t* ws, size_t len, const wchar_t* format, ...); @@ -287,6 +83,8 @@ extern "C" { SHAREDSYMBOL const wchar_t *GetPathTranslationPrefix(); SHAREDSYMBOL const char *GetPathTranslationPrefixA(); +#endif + #ifdef __cplusplus } @@ -353,4 +151,3 @@ struct ConsoleRepaintsDeferScope }; #endif -#endif /* FAR_PYTHON_GEN */ diff --git a/WinPort/WinPortDecl.h b/WinPort/WinPortDecl.h new file mode 100644 index 000000000..116eef3d4 --- /dev/null +++ b/WinPort/WinPortDecl.h @@ -0,0 +1,224 @@ + ///console API + WINPORT_DECL_DEF(ForkConsole,HANDLE,()) + WINPORT_DECL_DEF(JoinConsole,VOID,(HANDLE hConsole)) + + WINPORT_DECL_DEF(GetLargestConsoleWindowSize,COORD,(HANDLE hConsoleOutput)) + WINPORT_DECL_DEF(SetConsoleWindowInfo,BOOL,(HANDLE hConsoleOutput, BOOL bAbsolute, const SMALL_RECT *lpConsoleWindow)) + WINPORT_DECL_DEF(SetConsoleTitle,BOOL,(HANDLE hConsoleOutput, const WCHAR *title)) + WINPORT_DECL_DEF(GetConsoleTitle,DWORD,(HANDLE hConsoleOutput, WCHAR *title, DWORD max_size)) + WINPORT_DECL_DEF(SetConsoleScreenBufferSize,BOOL,(HANDLE hConsoleOutput,COORD dwSize)) + WINPORT_DECL_DEF(GetConsoleScreenBufferInfo,BOOL,(HANDLE hConsoleOutput,CONSOLE_SCREEN_BUFFER_INFO *lpConsoleScreenBufferInfo)) + WINPORT_DECL_DEF(SetConsoleCursorPosition,BOOL,(HANDLE hConsoleOutput,COORD dwCursorPosition)) + WINPORT_DECL_DEF(SetConsoleCursorInfo,BOOL,(HANDLE hConsoleOutput,const CONSOLE_CURSOR_INFO *lpConsoleCursorInfon)) + WINPORT_DECL_DEF(GetConsoleCursorInfo,BOOL,(HANDLE hConsoleOutput,CONSOLE_CURSOR_INFO *lpConsoleCursorInfon)) + WINPORT_DECL_DEF(GetConsoleMode,BOOL,(HANDLE hConsoleHandle,LPDWORD lpMode)) + WINPORT_DECL_DEF(SetConsoleMode,BOOL,(HANDLE hConsoleHandle, DWORD dwMode)) + WINPORT_DECL_DEF(ScrollConsoleScreenBuffer,BOOL,(HANDLE hConsoleOutput, const SMALL_RECT *lpScrollRectangle, const SMALL_RECT *lpClipRectangle, COORD dwDestinationOrigin, const CHAR_INFO *lpFill)) + WINPORT_DECL_DEF(SetConsoleTextAttribute,BOOL,(HANDLE hConsoleOutput, DWORD64 qAttributes)) + WINPORT_DECL_DEF(CompositeCharRegister,COMP_CHAR,(const WCHAR *lpSequence)) + WINPORT_DECL_DEF(CompositeCharLookup,const WCHAR *,(COMP_CHAR CompositeChar)) + WINPORT_DECL_DEF(WriteConsole,BOOL,(HANDLE hConsoleOutput, const WCHAR *lpBuffer, DWORD nNumberOfCharsToWrite, LPDWORD lpNumberOfCharsWritten, LPVOID lpReserved)) + WINPORT_DECL_DEF(WriteConsoleOutput,BOOL,(HANDLE hConsoleOutput,const CHAR_INFO *lpBuffer,COORD dwBufferSize,COORD dwBufferCoord,PSMALL_RECT lpScreenRegion)) + WINPORT_DECL_DEF(WriteConsoleOutputCharacter,BOOL,(HANDLE hConsoleOutput, const WCHAR *lpCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten)) + WINPORT_DECL_DEF(WaitConsoleInput, BOOL,(HANDLE hConsoleInput, DWORD dwTimeout)) + WINPORT_DECL_DEF(ReadConsoleOutput, BOOL, (HANDLE hConsoleOutput, CHAR_INFO *lpBuffer, COORD dwBufferSize, COORD dwBufferCoord, PSMALL_RECT lpScreenRegion)) + WINPORT_DECL_DEF(FillConsoleOutputAttribute, BOOL, (HANDLE hConsoleOutput, DWORD64 qAttributes, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfAttrsWritten)) + WINPORT_DECL_DEF(FillConsoleOutputCharacter, BOOL, (HANDLE hConsoleOutput, WCHAR cCharacter, DWORD nLength, COORD dwWriteCoord, LPDWORD lpNumberOfCharsWritten)) + WINPORT_DECL_DEF(SetConsoleActiveScreenBuffer, BOOL,(HANDLE hConsoleOutput)) + WINPORT_DECL_DEF(SetConsoleCursorBlinkTime,VOID,(HANDLE hConsoleOutput, DWORD dwMilliseconds )) + + WINPORT_DECL_DEF(FlushConsoleInputBuffer,BOOL,(HANDLE hConsoleInput)) + WINPORT_DECL_DEF(GetNumberOfConsoleInputEvents,BOOL,(HANDLE hConsoleInput, LPDWORD lpcNumberOfEvents)) + WINPORT_DECL_DEF(PeekConsoleInput,BOOL,(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead)) + WINPORT_DECL_DEF(ReadConsoleInput,BOOL,(HANDLE hConsoleInput, PINPUT_RECORD lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsRead)) + WINPORT_DECL_DEF(WriteConsoleInput,BOOL,(HANDLE hConsoleInput, const INPUT_RECORD *lpBuffer, DWORD nLength, LPDWORD lpNumberOfEventsWritten)) + + WINPORT_DECL_DEF(CheckForKeyPress,DWORD,(HANDLE hConsoleInput, const WORD *KeyCodes, DWORD KeyCodesCount, DWORD Flags)) + + WINPORT_DECL_DEF(SetConsoleDisplayMode,BOOL,(DWORD ModeFlags)) + WINPORT_DECL_DEF(GetConsoleDisplayMode,BOOL,(LPDWORD lpModeFlags)) + WINPORT_DECL_DEF(SetConsoleWindowMaximized,VOID,(BOOL Maximized)) + WINPORT_DECL_DEF(GetConsoleColorPalette,BYTE,(HANDLE hConsoleOutput)) // Returns current color resolution: 4, 8, 24 + + WINPORT_DECL_DEF(GetConsoleBasePalette,VOID,(HANDLE hConsoleOutput, void *p)) + WINPORT_DECL_DEF(SetConsoleBasePalette,BOOL,(HANDLE hConsoleOutput, void *p)) + + WINPORT_DECL_DEF(GenerateConsoleCtrlEvent, BOOL, (DWORD dwCtrlEvent, DWORD dwProcessGroupId )) + WINPORT_DECL_DEF(SetConsoleCtrlHandler, BOOL, (PHANDLER_ROUTINE HandlerRoutine, BOOL Add )) + + WINPORT_DECL_DEF(SetConsoleScrollRegion, VOID, (HANDLE hConsoleOutput, SHORT top, SHORT bottom)) + WINPORT_DECL_DEF(GetConsoleScrollRegion, VOID, (HANDLE hConsoleOutput, SHORT *top, SHORT *bottom)) + + WINPORT_DECL_DEF(SetConsoleScrollCallback, VOID, (HANDLE hConsoleOutput, PCONSOLE_SCROLL_CALLBACK pCallback, PVOID pContext)) + WINPORT_DECL_DEF(BeginConsoleAdhocQuickEdit, BOOL, ()) + WINPORT_DECL_DEF(SetConsoleTweaks, DWORD64, (DWORD64 tweaks)) + + WINPORT_DECL_DEF(SaveConsoleWindowState,VOID,()) + WINPORT_DECL_DEF(ConsoleChangeFont, VOID, ()) + WINPORT_DECL_DEF(IsConsoleActive, BOOL, ()) + WINPORT_DECL_DEF(ConsoleDisplayNotification, VOID, (const WCHAR *title, const WCHAR *text)) + WINPORT_DECL_DEF(ConsoleBackgroundMode, BOOL, (BOOL TryEnterBackgroundMode)) + WINPORT_DECL_DEF(SetConsoleFKeyTitles, BOOL, (HANDLE hConsoleOutput, const CHAR **titles)) + + // Query/Change or only Query palette color with specified index: + // if Index set to (DWORD)-1 then operates on currently chosen color (not using pallette) + // if initial *ColorFG or *ColorBK was set to (DWORD)-1 - it will change to default color + // if initial *ColorFG or *ColorBK was set to (DWORD)-2 - this color will not be changed (Query-only operation) + WINPORT_DECL_DEF(OverrideConsoleColor, VOID, (HANDLE hConsoleOutput, DWORD Index, DWORD *ColorFG, DWORD *ColorBK)) + + WINPORT_DECL_DEF(SetConsoleRepaintsDefer, VOID, (HANDLE hConsoleOutput, BOOL Deferring)) + +#ifdef WINPORT_REGISTRY + ///registry API + WINPORT_DECL_DEF(RegOpenKeyEx, LONG, (HKEY hKey,LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)) + WINPORT_DECL_DEF(RegCreateKeyEx, LONG, (HKEY hKey, LPCWSTR lpSubKey, DWORD Reserved, LPWSTR lpClass, DWORD dwOptions, + REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition)) + WINPORT_DECL_DEF(RegCloseKey, LONG, (HKEY hKey)) + WINPORT_DECL_DEF(RegDeleteKey, LONG, (HKEY hKey, LPCWSTR lpSubKey)) + WINPORT_DECL_DEF(RegDeleteValue, LONG, (HKEY hKey, LPCWSTR lpValueName)) + WINPORT_DECL_DEF(RegSetValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName, DWORD Reserved, + DWORD dwType, const BYTE *lpData, DWORD cbData)) + WINPORT_DECL_DEF(RegEnumKeyEx, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpName, LPDWORD lpcName, + LPDWORD lpReserved, LPWSTR lpClass,LPDWORD lpcClass, PFILETIME lpftLastWriteTime)) + WINPORT_DECL_DEF(RegEnumKey, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpName, DWORD cchName)) + WINPORT_DECL_DEF(RegEnumValue, LONG, (HKEY hKey, DWORD dwIndex, LPWSTR lpValueName, LPDWORD lpcchValueName, + LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)) + WINPORT_DECL_DEF(RegQueryValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName, + LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData)) +#if 0 +// duplicated definition + WINPORT_DECL_DEF(RegSetValueEx, LONG, (HKEY hKey, LPCWSTR lpValueName, + DWORD lpReserved, DWORD lpType, CONST BYTE * lpData, DWORD cbData)) +#endif + WINPORT_DECL_DEF(RegQueryInfoKey, LONG, (HKEY hKey, LPTSTR lpClass, LPDWORD lpcClass, + LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, + LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, + LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)) + + WINPORT_DECL_DEF(RegWipeBegin, VOID, ()) + WINPORT_DECL_DEF(RegWipeEnd, VOID, ()) +#endif + +//other + WINPORT_DECL_DEF(GetLastError, DWORD, ()) + WINPORT_DECL_DEF(SetLastError, VOID, (DWORD code)) + WINPORT_DECL_DEF(GetCurrentProcessId, DWORD, ()) + WINPORT_DECL_DEF(GetDoubleClickTime, DWORD, ()) + +//files + WINPORT_DECL_DEF(CreateDirectory, BOOL, (LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes )) + WINPORT_DECL_DEF(RemoveDirectory, BOOL, ( LPCWSTR lpDirName)) + WINPORT_DECL_DEF(DeleteFile, BOOL, ( LPCWSTR lpFileName)) + WINPORT_DECL_DEF(CreateFile, HANDLE, ( LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, + const DWORD *UnixMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)) + WINPORT_DECL_DEF(GetFileDescriptor, int, (HANDLE hFile)) + WINPORT_DECL_DEF(CloseHandle, BOOL, (HANDLE hObject)) + WINPORT_DECL_DEF(MoveFile, BOOL, (LPCWSTR ExistingFileName, LPCWSTR NewFileName )) + WINPORT_DECL_DEF(MoveFileEx, BOOL, (LPCWSTR ExistingFileName, LPCWSTR NewFileName,DWORD dwFlags)) + WINPORT_DECL_DEF(GetCurrentDirectory, DWORD, (DWORD nBufferLength, LPWSTR lpBuffer)) + WINPORT_DECL_DEF(SetCurrentDirectory, BOOL, (LPCWSTR lpPathName)) + WINPORT_DECL_DEF(GetFileSizeEx, BOOL, ( HANDLE hFile, PLARGE_INTEGER lpFileSize)) + WINPORT_DECL_DEF(GetFileSize, DWORD, ( HANDLE hFile, LPDWORD lpFileSizeHigh)) + WINPORT_DECL_DEF(GetFileSize64, DWORD64, ( HANDLE hFile)) + WINPORT_DECL_DEF(ReadFile, BOOL, ( HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, + LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped)) + WINPORT_DECL_DEF(WriteFile, BOOL, ( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, + LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped)) + WINPORT_DECL_DEF(SetFilePointerEx, BOOL, ( HANDLE hFile, LARGE_INTEGER liDistanceToMove, + PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)) + + // hints that file will soon grow up to specified size, doesnt change actual size of file + WINPORT_DECL_DEF(FileAllocationHint, VOID, (HANDLE hFile, DWORD64 HintFileSize)) + // grows file to specified size if it was smaller, ensuring that disk space is actually allocated + WINPORT_DECL_DEF(FileAllocationRequire, BOOL, (HANDLE hFile, DWORD64 RequireFileSize)) + + WINPORT_DECL_DEF(SetFilePointer, DWORD, ( HANDLE hFile, + LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)) + WINPORT_DECL_DEF(GetFileTime, BOOL, ( HANDLE hFile, LPFILETIME lpCreationTime, + LPFILETIME lpLastAccessTime, LPFILETIME lpLastWriteTime)) + WINPORT_DECL_DEF(SetFileTime, BOOL, ( HANDLE hFile, const FILETIME *lpCreationTime, + const FILETIME *lpLastAccessTime, const FILETIME *lpLastWriteTime)) + WINPORT_DECL_DEF(SetEndOfFile, BOOL, ( HANDLE hFile)) + WINPORT_DECL_DEF(FlushFileBuffers, BOOL, ( HANDLE hFile)) + WINPORT_DECL_DEF(GetFileType, DWORD, ( HANDLE hFile)) + + WINPORT_DECL_DEF(GetFileAttributes, DWORD, (LPCWSTR lpFileName)) + WINPORT_DECL_DEF(SetFileAttributes, DWORD, (LPCWSTR lpFileName, DWORD dwAttributes)) + + WINPORT_DECL_DEF(FindFirstFileWithFlags, HANDLE, (LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData, DWORD dwFlags)) + WINPORT_DECL_DEF(FindFirstFile, HANDLE, (LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData)) + WINPORT_DECL_DEF(FindNextFile, BOOL, (HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData)) + WINPORT_DECL_DEF(FindClose, BOOL, (HANDLE hFindFile)) + +#if 0 +// not implemented + WINPORT_DECL_DEF(GetDriveType, UINT, (LPCWSTR lpRootPathName)) +#endif + WINPORT_DECL_DEF(GetTempFileName, UINT,( LPCWSTR path, LPCWSTR prefix, UINT unique, LPWSTR buffer )) + WINPORT_DECL_DEF(GetFullPathName, DWORD, (LPCTSTR lpFileName, DWORD nBufferLength, LPTSTR lpBuffer, LPTSTR *lpFilePart)) + + WINPORT_DECL_DEF(EvaluateAttributes, DWORD,( uint32_t unix_mode, const WCHAR *name )) + WINPORT_DECL_DEF(EvaluateAttributesA, DWORD,( uint32_t unix_mode, const char *name )) + +//time/date + WINPORT_DECL_DEF(Sleep, VOID, (DWORD dwMilliseconds)) + WINPORT_DECL_DEF(GetTickCount, DWORD, ()) + WINPORT_DECL_DEF(GetLocalTime, VOID, (LPSYSTEMTIME lpSystemTime)) + WINPORT_DECL_DEF(GetSystemTime, VOID, (LPSYSTEMTIME lpSystemTime)) + WINPORT_DECL_DEF(SystemTimeToFileTime, BOOL, (const SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime)) + WINPORT_DECL_DEF(LocalFileTimeToFileTime, BOOL, (const FILETIME *lpLocalFileTime, LPFILETIME lpFileTime)) + WINPORT_DECL_DEF(CompareFileTime, LONG, (const FILETIME *lpFileTime1, const FILETIME *lpFileTime2)) + WINPORT_DECL_DEF(FileTimeToLocalFileTime, BOOL, (const FILETIME *lpFileTime, LPFILETIME lpLocalFileTime)) + WINPORT_DECL_DEF(FileTimeToSystemTime, BOOL, (const FILETIME *lpFileTime, LPSYSTEMTIME lpSystemTime)) + WINPORT_DECL_DEF(GetSystemTimeAsFileTime, VOID, (FILETIME *lpFileTime)) + WINPORT_DECL_DEF(FileTimeToDosDateTime, BOOL, (const FILETIME *lpFileTime, LPWORD lpFatDate, LPWORD lpFatTime)) + WINPORT_DECL_DEF(DosDateTimeToFileTime, BOOL, ( WORD fatdate, WORD fattime, LPFILETIME ft)) + + //string + WINPORT_DECL_DEF(LCMapString, INT, (LCID lcid, DWORD flags, LPCWSTR src, INT srclen, LPWSTR dst, INT dstlen)) + WINPORT_DECL_DEF(CharUpperBuff, DWORD, (LPWSTR lpsz, DWORD cchLength)) + WINPORT_DECL_DEF(CharLowerBuff, DWORD, (LPWSTR lpsz, DWORD cchLength)) + WINPORT_DECL_DEF(IsCharLower, BOOL, (WCHAR ch)) + WINPORT_DECL_DEF(IsCharUpper, BOOL, (WCHAR ch)) + WINPORT_DECL_DEF(IsCharAlpha, BOOL, (WCHAR ch)) + WINPORT_DECL_DEF(IsCharAlphaNumeric, BOOL, (WCHAR ch)) + WINPORT_DECL_DEF(CompareString, int, ( LCID Locale, DWORD dwCmpFlags, LPCWSTR lpString1, int cchCount1, LPCWSTR lpString2, int cchCount2)) + WINPORT_DECL_DEF(CompareStringA, int, ( LCID Locale, DWORD dwCmpFlags, LPCSTR lpString1, int cchCount1, LPCSTR lpString2, int cchCount2)) + WINPORT_DECL_DEF(WideCharToMultiByte, int, ( UINT CodePage, DWORD dwFlags, LPCWSTR lpWideCharStr, + int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCSTR lpDefaultChar, LPBOOL lpUsedDefaultChar)) + WINPORT_DECL_DEF(MultiByteToWideChar, int, ( UINT CodePage, DWORD dwFlags, + LPCSTR lpMultiByteStr, int cbMultiByte, LPWSTR lpWideCharStr, int cchWideChar)) + WINPORT_DECL_DEF(CharUpper, LPWSTR, (LPWSTR lpsz)) + WINPORT_DECL_DEF(CharLower, LPWSTR, (LPWSTR lpsz)) + WINPORT_DECL_DEF(GetOEMCP, UINT, ()) + WINPORT_DECL_DEF(GetACP, UINT, ()) + WINPORT_DECL_DEF(GetCPInfo, BOOL, (UINT CodePage, LPCPINFO lpCPInfo)) + WINPORT_DECL_DEF(GetCPInfoEx, BOOL, (UINT codepage, DWORD dwFlags, LPCPINFOEX cpinfo)) + WINPORT_DECL_DEF(EnumSystemCodePages, BOOL, (CODEPAGE_ENUMPROCW lpfnCodePageEnum, DWORD flags)) + + //clipboard + WINPORT_DECL_DEF(RegisterClipboardFormat, UINT, (LPCWSTR lpszFormat)) + WINPORT_DECL_DEF(OpenClipboard, BOOL, (PVOID Reserved)) + WINPORT_DECL_DEF(CloseClipboard, BOOL, ()) + WINPORT_DECL_DEF(EmptyClipboard, BOOL, ()) + WINPORT_DECL_DEF(IsClipboardFormatAvailable, BOOL, (UINT format)) + + // use Clipboard-Alloc/-Free/-Size to operate data pointers + WINPORT_DECL_DEF(GetClipboardData, PVOID, (UINT format)) + WINPORT_DECL_DEF(SetClipboardData, PVOID, (UINT format, HANDLE mem)) + + // these are simplified analogs for Win32's Global* APIs, that dedicated to reference clipboard data + WINPORT_DECL_DEF(ClipboardAlloc, PVOID, (SIZE_T len)) // allocates zero-initialized memory + WINPORT_DECL_DEF(ClipboardSize, SIZE_T, (PVOID mem)) // return _exact_ allocation size + + // note that like in win32, clipboard data is mostly owned by clipboard so ClipboardFree actually useful + // only in case of SetClipboardData's failure. + WINPORT_DECL_DEF(ClipboardFree, VOID, (PVOID mem)) + + //keyboard + WINPORT_DECL_DEF(GetKeyboardLayoutList, int, (int nBuff, HKL *lpList)) + WINPORT_DECL_DEF(MapVirtualKey, UINT, (UINT uCode, UINT uMapType)) + WINPORT_DECL_DEF(VkKeyScan, SHORT, (WCHAR ch)) + WINPORT_DECL_DEF(ToUnicodeEx, int, (UINT wVirtKey, UINT wScanCode, CONST BYTE *lpKeyState, + LPWSTR pwszBuff, int cchBuff, UINT wFlags, HKL dwhkl)) + From 143b730343c50883d9537f304bb67784e0d63582 Mon Sep 17 00:00:00 2001 From: m32 Date: Thu, 3 Oct 2024 04:55:58 +0200 Subject: [PATCH 08/10] remove python3-venv dependency, avoid using python3-venv and use only system preprocessor --- python/CMakeLists.txt | 19 +- python/src/consts.gen | 20 --- python/src/prebuild.sh | 25 +-- python/src/python.cpp | 27 ++- python/src/pythongen.py | 386 ---------------------------------------- 5 files changed, 39 insertions(+), 438 deletions(-) delete mode 100644 python/src/consts.gen delete mode 100755 python/src/pythongen.py diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 9fbfc9ec1..7dde5c107 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -3,7 +3,7 @@ project(python) set(SOURCES src/python.cpp -${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py +"${INSTALL_DIR}/Plugins/python/plug/far2l/far2lcffi.h" ) find_package(Python3 COMPONENTS Interpreter Development) # find Python interpreter and library @@ -40,20 +40,19 @@ set_target_properties(python PROPERTIES SUFFIX ".far-plug-wide" ) -add_custom_command(TARGET python POST_BUILD +add_custom_command( + #TARGET python POST_BUILD + OUTPUT "${INSTALL_DIR}/Plugins/python/plug/far2l/far2lcffi.h" DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/configs - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/far2lcffi.py - COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/configs" "${INSTALL_DIR}/Plugins/python" - COMMAND ${CMAKE_COMMAND} -E copy "${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py" "${INSTALL_DIR}/Plugins/python/plug/far2l" -) - -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/incpy/far2lcffi.py - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/pythongen.py + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/far2lcffi.h + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/far2lcffidefs.h DEPENDS ../far2l/far2sdk/farplug-wide.h DEPENDS ../far2l/far2sdk/farcolor.h DEPENDS ../far2l/far2sdk/farkeys.h DEPENDS ../WinPort/windows.h DEPENDS ../WinPort/WinCompat.h DEPENDS ../WinPort/WinPort.h - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/prebuild.sh "${CMAKE_SOURCE_DIR}" "${CMAKE_CURRENT_BINARY_DIR}" "${Python3_EXECUTABLE}" "${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS}" + DEPENDS ../WinPort/WinPortDecl.h + COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/configs" "${INSTALL_DIR}/Plugins/python" + COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/src/prebuild.sh "${CMAKE_SOURCE_DIR}" "${INSTALL_DIR}/Plugins/python/plug/far2l/far2lcffi.h" "${CMAKE_C_COMPILER} ${CMAKE_C_FLAGS}" ) diff --git a/python/src/consts.gen b/python/src/consts.gen deleted file mode 100644 index 859603a06..000000000 --- a/python/src/consts.gen +++ /dev/null @@ -1,20 +0,0 @@ -#include -#ifdef __linux__ -# include -#endif - -#ifdef PATH_MAX -echo "#define PATH_MAX" PATH_MAX -#else -echo "#define PATH_MAX" 0x1000 -#endif - -#ifdef NAME_MAX -echo "#define NAME_MAX" NAME_MAX -#else -echo "#define NAME_MAX" 0xff -#endif - -#if defined(__LP64__) || defined(_LP64) -echo "#define __LP64__" -#endif diff --git a/python/src/prebuild.sh b/python/src/prebuild.sh index c48bcf9ad..a38dfc2fb 100755 --- a/python/src/prebuild.sh +++ b/python/src/prebuild.sh @@ -1,27 +1,10 @@ #!/bin/bash set -e -echo "XBUILD=$*" SRC="$1" DST="$2" -PYTHON="$3" -PREPROCESSOR="$4 -E -P -xc" +PREPROCESSOR="$3 -E -P -xc" -mkdir -p "$DST/incpy" - -if [ ! -f "$DST/python/.prepared" ]; then - echo "Preparing python virtual env at $DST/python using $PYTHON" - mkdir -p "$DST/python" - $PYTHON -m venv --system-site-packages "$DST/python" - "$DST/python/bin/python" -m pip install pcpp - $PREPROCESSOR "$SRC/python/src/consts.gen" | sh > "${DST}/incpy/consts.h" - echo "1" > "$DST/python/.prepared" -fi - -################### - -cp -f -R \ - "$SRC/python/configs/plug/far2l/"* \ - "$DST/incpy/" - -"$DST/python/bin/python" "$SRC/python/src/pythongen.py" "${SRC}" "${DST}/incpy" +echo XXX $PREPROCESSOR -I"$SRC/far2l/far2sdk" -I"$SRC/WinPort" "$SRC/python/src/far2lcffi.h" "$DST" +$PREPROCESSOR -I"$SRC/far2l/far2sdk" -I"$SRC/WinPort" "$SRC/python/src/far2lcffi.h" > "$DST" +cat "$SRC/python/src/far2lcffidefs.h" >> "$DST" diff --git a/python/src/python.cpp b/python/src/python.cpp index 50f3a4201..79ab9a127 100644 --- a/python/src/python.cpp +++ b/python/src/python.cpp @@ -17,10 +17,24 @@ #include #include #include -#include "../far2l/src/console/savescr.hpp" static struct PluginStartupInfo Info; static FARSTANDARDFUNCTIONS FSF; +extern "C" { +#undef WINPORT_DECL_DEF +#define WINPORT_DECL_DEF(NAME, RV, ARGS) typedef RV (*ptrWINPORT_##NAME) ARGS; +#include "WinPortDecl.h" +#undef WINPORT_DECL_DEF +#define WINPORT_DECL_DEF(NAME, RV, ARGS) ptrWINPORT_##NAME v##NAME; +typedef struct _WINPORTDECL{ +#include "WinPortDecl.h" +} WINPORTDECL; +static WINPORTDECL winportvar = { +#undef WINPORT_DECL_DEF +#define WINPORT_DECL_DEF(NAME, RV, ARGS) &WINPORT_##NAME, +#include "WinPortDecl.h" +}; +} static void python_log(const char *function, unsigned int line, const char *format, ...) { @@ -60,9 +74,20 @@ far2l_CheckForEscape(PyObject *self, PyObject *args) Py_RETURN_FALSE; } +static PyObject * +far2l_WINPORT(PyObject *self, PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + + PyObject *pValue = PyLong_FromLong((long int)&winportvar); + return pValue; +} + static PyMethodDef Far2lcMethods[] = { {"CheckForInput", far2l_CheckForInput, METH_VARARGS, "CheckForInput"}, {"CheckForEscape", far2l_CheckForEscape, METH_VARARGS, "CheckForEscape"}, + {"WINPORT", far2l_WINPORT, METH_VARARGS, "WINPORT"}, {NULL, NULL, 0, NULL} /* Sentinel */ }; diff --git a/python/src/pythongen.py b/python/src/pythongen.py deleted file mode 100755 index 3802228e5..000000000 --- a/python/src/pythongen.py +++ /dev/null @@ -1,386 +0,0 @@ -#!/usr/bin/env vpython3 -import sys -import os -import re -import pcpp -import io - -source = sys.argv[1] -target = os.path.join(sys.argv[2], "far2lcffi.py") - -cpp = pcpp.Preprocessor() -cpp.add_path(source) -cpp.add_path(os.path.join(source, "far2l", "far2sdk")) -cpp.add_path(sys.argv[2]) # to find consts.h -cpp.define("FAR_USE_INTERNALS 1") -# cpp.define('WINPORT_DIRECT') -cpp.define("WINPORT_REGISTRY") -cpp.define("UNICODE") -cpp.define("PROCPLUGINMACROFUNC") -cpp.define("__GNUC__") -cpp.define("_FAR_NO_NAMELESS_UNIONS") -cpp.define("_FILE_OFFSET_BITS 64") -cpp.define("FAR_PYTHON_GEN 1") -data = """\ -#define uid_t uint32_t -#define gid_t uint32_t -#include "consts.h" -#include "farplug-wide.h" -#include "farcolor.h" -#include "farkeys.h" -""" - -cpp.parse(data) -fp = io.StringIO() -cpp.write(fp) - -data = fp.getvalue() -for s in re.findall("'.+'", data): - t = str(ord(s[-2].encode("ascii"))) - data = data.replace(s, t) -data = data.replace("#line", "//#line") -data = data.replace("#pragma", "//#pragma") - -with open(target, 'wt') as fp: - fp.write('''\ -data = """\\ -''') - fp.write('''\ -#define RIGHT_ALT_PRESSED 0x0001 // the right alt key is pressed. -#define LEFT_ALT_PRESSED 0x0002 // the left alt key is pressed. -#define RIGHT_CTRL_PRESSED 0x0004 // the right ctrl key is pressed. -#define LEFT_CTRL_PRESSED 0x0008 // the left ctrl key is pressed. -#define SHIFT_PRESSED 0x0010 // the shift key is pressed. -#define NUMLOCK_ON 0x0020 // the numlock light is on. -#define SCROLLLOCK_ON 0x0040 // the scrolllock light is on. -#define CAPSLOCK_ON 0x0080 // the capslock light is on. -#define ENHANCED_KEY 0x0100 // the key is enhanced. - -#define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 -#define RIGHTMOST_BUTTON_PRESSED 0x0002 -#define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004 -#define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008 -#define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010 - -#define MOUSE_MOVED 0x0001 -#define DOUBLE_CLICK 0x0002 -#define MOUSE_WHEELED 0x0004 -#define MOUSE_HWHEELED 0x0008 - -#define KEY_EVENT 0x0001 // Event contains key event record -#define MOUSE_EVENT 0x0002 // Event contains mouse event record -#define WINDOW_BUFFER_SIZE_EVENT 0x0004 // Event contains window change event record -#define MENU_EVENT 0x0008 // Event contains menu event record -#define FOCUS_EVENT 0x0010 // event contains focus change -#define BRACKETED_PASTE_EVENT 0x0020 // event contains bracketed paste state change -#define CALLBACK_EVENT 0x0040 // callback to be invoked when its record dequeued, its translated into NOOP_EVENT when invoked -#define NOOP_EVENT 0x0080 // nothing interesting, typically injected to kick events dispatcher - -/* - * Virtual Keys, Standard Set - */ -#define VK_LBUTTON 0x01 -#define VK_RBUTTON 0x02 -#define VK_CANCEL 0x03 -#define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */ - -#define VK_XBUTTON1 0x05 /* NOT contiguous with L & RBUTTON */ -#define VK_XBUTTON2 0x06 /* NOT contiguous with L & RBUTTON */ - -/* - * 0x07 : unassigned - */ - -#define VK_BACK 0x08 -#define VK_TAB 0x09 - -/* - * 0x0A - 0x0B : reserved - */ - -#define VK_CLEAR 0x0C -#define VK_RETURN 0x0D - -#define VK_SHIFT 0x10 -#define VK_CONTROL 0x11 -#define VK_MENU 0x12 -#define VK_PAUSE 0x13 -#define VK_CAPITAL 0x14 - -#define VK_KANA 0x15 -#define VK_HANGEUL 0x15 /* old name - should be here for compatibility */ -#define VK_HANGUL 0x15 -#define VK_JUNJA 0x17 -#define VK_FINAL 0x18 -#define VK_HANJA 0x19 -#define VK_KANJI 0x19 - -#define VK_ESCAPE 0x1B - -#define VK_CONVERT 0x1C -#define VK_NONCONVERT 0x1D -#define VK_ACCEPT 0x1E -#define VK_MODECHANGE 0x1F - -#define VK_SPACE 0x20 -#define VK_PRIOR 0x21 -#define VK_NEXT 0x22 -#define VK_END 0x23 -#define VK_HOME 0x24 -#define VK_LEFT 0x25 -#define VK_UP 0x26 -#define VK_RIGHT 0x27 -#define VK_DOWN 0x28 -#define VK_SELECT 0x29 -#define VK_PRINT 0x2A -#define VK_EXECUTE 0x2B -#define VK_SNAPSHOT 0x2C -#define VK_INSERT 0x2D -#define VK_DELETE 0x2E -#define VK_HELP 0x2F - -/* - * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39) - * 0x40 : unassigned - * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A) - */ - -#define VK_LWIN 0x5B -#define VK_RWIN 0x5C -#define VK_APPS 0x5D - -/* - * 0x5E : reserved - */ - -#define VK_SLEEP 0x5F - -#define VK_NUMPAD0 0x60 -#define VK_NUMPAD1 0x61 -#define VK_NUMPAD2 0x62 -#define VK_NUMPAD3 0x63 -#define VK_NUMPAD4 0x64 -#define VK_NUMPAD5 0x65 -#define VK_NUMPAD6 0x66 -#define VK_NUMPAD7 0x67 -#define VK_NUMPAD8 0x68 -#define VK_NUMPAD9 0x69 -#define VK_MULTIPLY 0x6A -#define VK_ADD 0x6B -#define VK_SEPARATOR 0x6C -#define VK_SUBTRACT 0x6D -#define VK_DECIMAL 0x6E -#define VK_DIVIDE 0x6F -#define VK_F1 0x70 -#define VK_F2 0x71 -#define VK_F3 0x72 -#define VK_F4 0x73 -#define VK_F5 0x74 -#define VK_F6 0x75 -#define VK_F7 0x76 -#define VK_F8 0x77 -#define VK_F9 0x78 -#define VK_F10 0x79 -#define VK_F11 0x7A -#define VK_F12 0x7B -#define VK_F13 0x7C -#define VK_F14 0x7D -#define VK_F15 0x7E -#define VK_F16 0x7F -#define VK_F17 0x80 -#define VK_F18 0x81 -#define VK_F19 0x82 -#define VK_F20 0x83 -#define VK_F21 0x84 -#define VK_F22 0x85 -#define VK_F23 0x86 -#define VK_F24 0x87 - -/* - * 0x88 - 0x8F : unassigned - */ - -#define VK_NUMLOCK 0x90 -#define VK_SCROLL 0x91 - -/* - * NEC PC-9800 kbd definitions - */ -#define VK_OEM_NEC_EQUAL 0x92 // '=' key on numpad - -/* - * Fujitsu/OASYS kbd definitions - */ -#define VK_OEM_FJ_JISHO 0x92 // 'Dictionary' key -#define VK_OEM_FJ_MASSHOU 0x93 // 'Unregister word' key -#define VK_OEM_FJ_TOUROKU 0x94 // 'Register word' key -#define VK_OEM_FJ_LOYA 0x95 // 'Left OYAYUBI' key -#define VK_OEM_FJ_ROYA 0x96 // 'Right OYAYUBI' key - -/* - * 0x97 - 0x9F : unassigned - */ - -/* - * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. - * Used only as parameters to GetAsyncKeyState() and GetKeyState(). - * No other API or message will distinguish left and right keys in this way. - */ -#define VK_LSHIFT 0xA0 -#define VK_RSHIFT 0xA1 -#define VK_LCONTROL 0xA2 -#define VK_RCONTROL 0xA3 -#define VK_LMENU 0xA4 -#define VK_RMENU 0xA5 - -#define VK_BROWSER_BACK 0xA6 -#define VK_BROWSER_FORWARD 0xA7 -#define VK_BROWSER_REFRESH 0xA8 -#define VK_BROWSER_STOP 0xA9 -#define VK_BROWSER_SEARCH 0xAA -#define VK_BROWSER_FAVORITES 0xAB -#define VK_BROWSER_HOME 0xAC - -#define VK_VOLUME_MUTE 0xAD -#define VK_VOLUME_DOWN 0xAE -#define VK_VOLUME_UP 0xAF -#define VK_MEDIA_NEXT_TRACK 0xB0 -#define VK_MEDIA_PREV_TRACK 0xB1 -#define VK_MEDIA_STOP 0xB2 -#define VK_MEDIA_PLAY_PAUSE 0xB3 -#define VK_LAUNCH_MAIL 0xB4 -#define VK_LAUNCH_MEDIA_SELECT 0xB5 -#define VK_LAUNCH_APP1 0xB6 -#define VK_LAUNCH_APP2 0xB7 - -/* - * 0xB8 - 0xB9 : reserved - */ - -#define VK_OEM_1 0xBA // ';:' for US -#define VK_OEM_PLUS 0xBB // '+' any country -#define VK_OEM_COMMA 0xBC // ',' any country -#define VK_OEM_MINUS 0xBD // '-' any country -#define VK_OEM_PERIOD 0xBE // '.' any country -#define VK_OEM_2 0xBF // '/?' for US -#define VK_OEM_3 0xC0 // '`~' for US - -/* - * 0xC1 - 0xD7 : reserved - */ - -/* - * 0xD8 - 0xDA : unassigned - */ - -#define VK_OEM_4 0xDB // '[{' for US -#define VK_OEM_5 0xDC // '\|' for US -#define VK_OEM_6 0xDD // ']}' for US -#define VK_OEM_7 0xDE // ''"' for US -#define VK_OEM_8 0xDF - -/* - * 0xE0 : reserved - */ - -/* - * Various extended or enhanced keyboards - */ -#define VK_OEM_AX 0xE1 // 'AX' key on Japanese AX kbd -#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd. -#define VK_ICO_HELP 0xE3 // Help key on ICO -#define VK_ICO_00 0xE4 // 00 key on ICO - -#define VK_PROCESSKEY 0xE5 - -#define VK_ICO_CLEAR 0xE6 - - -#define VK_PACKET 0xE7 - -#define VK_UNASSIGNED 0xE8 - -/* - * 0xE8 : unassigned - */ - -/* - * Nokia/Ericsson definitions - */ -#define VK_OEM_RESET 0xE9 -#define VK_OEM_JUMP 0xEA -#define VK_OEM_PA1 0xEB -#define VK_OEM_PA2 0xEC -#define VK_OEM_PA3 0xED -#define VK_OEM_WSCTRL 0xEE -#define VK_OEM_CUSEL 0xEF -#define VK_OEM_ATTN 0xF0 -#define VK_OEM_FINISH 0xF1 -#define VK_OEM_COPY 0xF2 -#define VK_OEM_AUTO 0xF3 -#define VK_OEM_ENLW 0xF4 -#define VK_OEM_BACKTAB 0xF5 - -#define VK_ATTN 0xF6 -#define VK_CRSEL 0xF7 -#define VK_EXSEL 0xF8 -#define VK_EREOF 0xF9 -#define VK_PLAY 0xFA -#define VK_ZOOM 0xFB -#define VK_NONAME 0xFC -#define VK_PA1 0xFD -#define VK_OEM_CLEAR 0xFE - -#define KEYEVENTF_EXTENDEDKEY 0x0001 -#define KEYEVENTF_KEYUP 0x0002 -#define KEYEVENTF_UNICODE 0x0004 -#define KEYEVENTF_SCANCODE 0x0008 - -#define TICKS_PER_SECOND 10000000 -#define EPOCH_DIFFERENCE 11644473600 - -#define FILE_ATTRIBUTE_READONLY 0x00000001 -#define FILE_ATTRIBUTE_HIDDEN 0x00000002 -#define FILE_ATTRIBUTE_SYSTEM 0x00000004 -#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 -#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 -#define FILE_ATTRIBUTE_DEVICE 0x00000040 -#define FILE_ATTRIBUTE_NORMAL 0x00000080 -#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 -#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 -#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 -#define FILE_ATTRIBUTE_COMPRESSED 0x00000800 -#define FILE_ATTRIBUTE_OFFLINE 0x00001000 -#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 -#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 -#define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000 -#define FILE_ATTRIBUTE_VIRTUAL 0x00010000 -#define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000 -#define FILE_ATTRIBUTE_BROKEN 0x00200000 -#define FILE_ATTRIBUTE_EXECUTABLE 0x00400000 -''') - fp.write(data) - fp.write('''\ -""" -''') - fp.write('''\ -import cffi -ffi = cffi.FFI() -pack = None -while True: - i = data.find('//#pragma pack') - if i < 0: - ffi.cdef(data, pack=pack) - break - ndata = data[:i] - ffi.cdef(ndata, pack=pack) - data = data[i:] - i = data.find(')') - s = data[:i+1] - if s.find('()') > 0: - pack = None - else: - pack = 2 - data = data[i+1:] -del pack, data, i, ndata, s -''') From 4ac2f42bd3c74479371afb3000b7d4d7b3207180 Mon Sep 17 00:00:00 2001 From: m32 Date: Thu, 3 Oct 2024 04:58:58 +0200 Subject: [PATCH 09/10] move declarations to far2lcffi.h --- python/configs/plug/far2l/far2lcffi.py | 34 ++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 python/configs/plug/far2l/far2lcffi.py diff --git a/python/configs/plug/far2l/far2lcffi.py b/python/configs/plug/far2l/far2lcffi.py new file mode 100644 index 000000000..d5c5097b2 --- /dev/null +++ b/python/configs/plug/far2l/far2lcffi.py @@ -0,0 +1,34 @@ +import os +import re + +import cffi +ffi = cffi.FFI() + +__all__ = ["ffi"] + +def convert(): + with open(os.path.join(os.path.dirname(__file__), 'far2lcffi.h'), 'rt') as fp: + data = fp.read() + + for s in re.findall("'.+'", data): + i = str(ord(s[-2].encode("ascii"))) + data = data.replace(s, i) + + pack = None + while True: + i = data.find('#pragma pack') + if i < 0: + ffi.cdef(data, pack=pack) + break + ndata = data[:i] + ffi.cdef(ndata, pack=pack) + data = data[i:] + i = data.find(')') + s = data[:i+1] + if s.find('()') > 0: + pack = None + else: + pack = 2 + data = data[i+1:] + +convert() From 249096b6f76a5d6491c849ade0163927bc9d2421 Mon Sep 17 00:00:00 2001 From: m32 Date: Thu, 3 Oct 2024 05:00:18 +0200 Subject: [PATCH 10/10] use only system preprocessor --- python/src/far2lcffi.h | 40 +++++ python/src/far2lcffidefs.h | 351 +++++++++++++++++++++++++++++++++++++ 2 files changed, 391 insertions(+) create mode 100644 python/src/far2lcffi.h create mode 100644 python/src/far2lcffidefs.h diff --git a/python/src/far2lcffi.h b/python/src/far2lcffi.h new file mode 100644 index 000000000..302105ffb --- /dev/null +++ b/python/src/far2lcffi.h @@ -0,0 +1,40 @@ +#include +#ifdef __linux__ +# include +#endif + +#ifndef PATH_MAX +#define PATH_MAX 0x1000 +#endif + +#ifndef NAME_MAX +#define NAME_MAX 0xff +#endif + +#if !defined(__LP64__) && defined(_LP64) +#define __LP64__ +#endif + +#define FAR_USE_INTERNALS +#define PROCPLUGINMACROFUNC +#define UNICODE +//#define WINPORT_DIRECT +//#define WINPORT_REGISTRY +#define _FAR_NO_NAMELESS_UNIONS +#define FAR_PYTHON_GEN + +#define uid_t uint32_t +#define gid_t uint32_t +#include "farplug-wide.h" +#include "farcolor.h" +#include "farkeys.h" + +// create typedef +#define WINPORT_DECL_DEF(NAME, RV, ARGS) typedef RV (*WINPORT_##NAME) ARGS; +#include "WinPortDecl.h" +// create structure +#undef WINPORT_DECL_DEF +#define WINPORT_DECL_DEF(NAME, RV, ARGS) WINPORT_##NAME NAME; +struct WINPORTDECL{ +#include "WinPortDecl.h" +}; diff --git a/python/src/far2lcffidefs.h b/python/src/far2lcffidefs.h new file mode 100644 index 000000000..f77797c76 --- /dev/null +++ b/python/src/far2lcffidefs.h @@ -0,0 +1,351 @@ +// WinCompat.h + +#define CONSOLE_FULLSCREEN_MODE 1 +#define CONSOLE_WINDOWED_MODE 2 + +// +// ControlKeyState flags +// + +#define RIGHT_ALT_PRESSED 0x0001 // the right alt key is pressed. +#define LEFT_ALT_PRESSED 0x0002 // the left alt key is pressed. +#define RIGHT_CTRL_PRESSED 0x0004 // the right ctrl key is pressed. +#define LEFT_CTRL_PRESSED 0x0008 // the left ctrl key is pressed. +#define SHIFT_PRESSED 0x0010 // the shift key is pressed. +#define NUMLOCK_ON 0x0020 // the numlock light is on. +#define SCROLLLOCK_ON 0x0040 // the scrolllock light is on. +#define CAPSLOCK_ON 0x0080 // the capslock light is on. +#define ENHANCED_KEY 0x0100 // the key is enhanced. + +#define FROM_LEFT_1ST_BUTTON_PRESSED 0x0001 +#define RIGHTMOST_BUTTON_PRESSED 0x0002 +#define FROM_LEFT_2ND_BUTTON_PRESSED 0x0004 +#define FROM_LEFT_3RD_BUTTON_PRESSED 0x0008 +#define FROM_LEFT_4TH_BUTTON_PRESSED 0x0010 + +#define MOUSE_MOVED 0x0001 +#define DOUBLE_CLICK 0x0002 +#define MOUSE_WHEELED 0x0004 +#define MOUSE_HWHEELED 0x0008 + +#define KEY_EVENT 0x0001 // Event contains key event record +#define MOUSE_EVENT 0x0002 // Event contains mouse event record +#define WINDOW_BUFFER_SIZE_EVENT 0x0004 // Event contains window change event record +#define MENU_EVENT 0x0008 // Event contains menu event record +#define FOCUS_EVENT 0x0010 // event contains focus change +#define BRACKETED_PASTE_EVENT 0x0020 // event contains bracketed paste state change +#define CALLBACK_EVENT 0x0040 // callback to be invoked when its record dequeued, its translated into NOOP_EVENT when invoked +#define NOOP_EVENT 0x0080 // nothing interesting, typically injected to kick events dispatcher + +/* + * Virtual Keys, Standard Set + */ +#define VK_LBUTTON 0x01 +#define VK_RBUTTON 0x02 +#define VK_CANCEL 0x03 +#define VK_MBUTTON 0x04 /* NOT contiguous with L & RBUTTON */ + +#define VK_XBUTTON1 0x05 /* NOT contiguous with L & RBUTTON */ +#define VK_XBUTTON2 0x06 /* NOT contiguous with L & RBUTTON */ + +/* + * 0x07 : unassigned + */ + +#define VK_BACK 0x08 +#define VK_TAB 0x09 + +/* + * 0x0A - 0x0B : reserved + */ + +#define VK_CLEAR 0x0C +#define VK_RETURN 0x0D + +#define VK_SHIFT 0x10 +#define VK_CONTROL 0x11 +#define VK_MENU 0x12 +#define VK_PAUSE 0x13 +#define VK_CAPITAL 0x14 + +#define VK_KANA 0x15 +#define VK_HANGEUL 0x15 /* old name - should be here for compatibility */ +#define VK_HANGUL 0x15 +#define VK_JUNJA 0x17 +#define VK_FINAL 0x18 +#define VK_HANJA 0x19 +#define VK_KANJI 0x19 + +#define VK_ESCAPE 0x1B + +#define VK_CONVERT 0x1C +#define VK_NONCONVERT 0x1D +#define VK_ACCEPT 0x1E +#define VK_MODECHANGE 0x1F + +#define VK_SPACE 0x20 +#define VK_PRIOR 0x21 +#define VK_NEXT 0x22 +#define VK_END 0x23 +#define VK_HOME 0x24 +#define VK_LEFT 0x25 +#define VK_UP 0x26 +#define VK_RIGHT 0x27 +#define VK_DOWN 0x28 +#define VK_SELECT 0x29 +#define VK_PRINT 0x2A +#define VK_EXECUTE 0x2B +#define VK_SNAPSHOT 0x2C +#define VK_INSERT 0x2D +#define VK_DELETE 0x2E +#define VK_HELP 0x2F + +/* + * VK_0 - VK_9 are the same as ASCII '0' - '9' (0x30 - 0x39) + * 0x40 : unassigned + * VK_A - VK_Z are the same as ASCII 'A' - 'Z' (0x41 - 0x5A) + */ + +#define VK_LWIN 0x5B +#define VK_RWIN 0x5C +#define VK_APPS 0x5D + +/* + * 0x5E : reserved + */ + +#define VK_SLEEP 0x5F + +#define VK_NUMPAD0 0x60 +#define VK_NUMPAD1 0x61 +#define VK_NUMPAD2 0x62 +#define VK_NUMPAD3 0x63 +#define VK_NUMPAD4 0x64 +#define VK_NUMPAD5 0x65 +#define VK_NUMPAD6 0x66 +#define VK_NUMPAD7 0x67 +#define VK_NUMPAD8 0x68 +#define VK_NUMPAD9 0x69 +#define VK_MULTIPLY 0x6A +#define VK_ADD 0x6B +#define VK_SEPARATOR 0x6C +#define VK_SUBTRACT 0x6D +#define VK_DECIMAL 0x6E +#define VK_DIVIDE 0x6F +#define VK_F1 0x70 +#define VK_F2 0x71 +#define VK_F3 0x72 +#define VK_F4 0x73 +#define VK_F5 0x74 +#define VK_F6 0x75 +#define VK_F7 0x76 +#define VK_F8 0x77 +#define VK_F9 0x78 +#define VK_F10 0x79 +#define VK_F11 0x7A +#define VK_F12 0x7B +#define VK_F13 0x7C +#define VK_F14 0x7D +#define VK_F15 0x7E +#define VK_F16 0x7F +#define VK_F17 0x80 +#define VK_F18 0x81 +#define VK_F19 0x82 +#define VK_F20 0x83 +#define VK_F21 0x84 +#define VK_F22 0x85 +#define VK_F23 0x86 +#define VK_F24 0x87 + +/* + * 0x88 - 0x8F : unassigned + */ + +#define VK_NUMLOCK 0x90 +#define VK_SCROLL 0x91 + +/* + * NEC PC-9800 kbd definitions + */ +#define VK_OEM_NEC_EQUAL 0x92 // '=' key on numpad + +/* + * Fujitsu/OASYS kbd definitions + */ +#define VK_OEM_FJ_JISHO 0x92 // 'Dictionary' key +#define VK_OEM_FJ_MASSHOU 0x93 // 'Unregister word' key +#define VK_OEM_FJ_TOUROKU 0x94 // 'Register word' key +#define VK_OEM_FJ_LOYA 0x95 // 'Left OYAYUBI' key +#define VK_OEM_FJ_ROYA 0x96 // 'Right OYAYUBI' key + +/* + * 0x97 - 0x9F : unassigned + */ + +/* + * VK_L* & VK_R* - left and right Alt, Ctrl and Shift virtual keys. + * Used only as parameters to GetAsyncKeyState() and GetKeyState(). + * No other API or message will distinguish left and right keys in this way. + */ +#define VK_LSHIFT 0xA0 +#define VK_RSHIFT 0xA1 +#define VK_LCONTROL 0xA2 +#define VK_RCONTROL 0xA3 +#define VK_LMENU 0xA4 +#define VK_RMENU 0xA5 + +#define VK_BROWSER_BACK 0xA6 +#define VK_BROWSER_FORWARD 0xA7 +#define VK_BROWSER_REFRESH 0xA8 +#define VK_BROWSER_STOP 0xA9 +#define VK_BROWSER_SEARCH 0xAA +#define VK_BROWSER_FAVORITES 0xAB +#define VK_BROWSER_HOME 0xAC + +#define VK_VOLUME_MUTE 0xAD +#define VK_VOLUME_DOWN 0xAE +#define VK_VOLUME_UP 0xAF +#define VK_MEDIA_NEXT_TRACK 0xB0 +#define VK_MEDIA_PREV_TRACK 0xB1 +#define VK_MEDIA_STOP 0xB2 +#define VK_MEDIA_PLAY_PAUSE 0xB3 +#define VK_LAUNCH_MAIL 0xB4 +#define VK_LAUNCH_MEDIA_SELECT 0xB5 +#define VK_LAUNCH_APP1 0xB6 +#define VK_LAUNCH_APP2 0xB7 + +/* + * 0xB8 - 0xB9 : reserved + */ + +#define VK_OEM_1 0xBA // ';:' for US +#define VK_OEM_PLUS 0xBB // '+' any country +#define VK_OEM_COMMA 0xBC // ',' any country +#define VK_OEM_MINUS 0xBD // '-' any country +#define VK_OEM_PERIOD 0xBE // '.' any country +#define VK_OEM_2 0xBF // '/?' for US +#define VK_OEM_3 0xC0 // '`~' for US + +/* + * 0xC1 - 0xD7 : reserved + */ + +/* + * 0xD8 - 0xDA : unassigned + */ + +#define VK_OEM_4 0xDB // '[{' for US +#define VK_OEM_5 0xDC // '\|' for US +#define VK_OEM_6 0xDD // ']}' for US +#define VK_OEM_7 0xDE // ''"' for US +#define VK_OEM_8 0xDF + +/* + * 0xE0 : reserved + */ + +/* + * Various extended or enhanced keyboards + */ +#define VK_OEM_AX 0xE1 // 'AX' key on Japanese AX kbd +#define VK_OEM_102 0xE2 // "<>" or "\|" on RT 102-key kbd. +#define VK_ICO_HELP 0xE3 // Help key on ICO +#define VK_ICO_00 0xE4 // 00 key on ICO + +#define VK_PROCESSKEY 0xE5 + +#define VK_ICO_CLEAR 0xE6 + + +#define VK_PACKET 0xE7 + +#define VK_UNASSIGNED 0xE8 + +/* + * 0xE8 : unassigned + */ + +/* + * Nokia/Ericsson definitions + */ +#define VK_OEM_RESET 0xE9 +#define VK_OEM_JUMP 0xEA +#define VK_OEM_PA1 0xEB +#define VK_OEM_PA2 0xEC +#define VK_OEM_PA3 0xED +#define VK_OEM_WSCTRL 0xEE +#define VK_OEM_CUSEL 0xEF +#define VK_OEM_ATTN 0xF0 +#define VK_OEM_FINISH 0xF1 +#define VK_OEM_COPY 0xF2 +#define VK_OEM_AUTO 0xF3 +#define VK_OEM_ENLW 0xF4 +#define VK_OEM_BACKTAB 0xF5 + +#define VK_ATTN 0xF6 +#define VK_CRSEL 0xF7 +#define VK_EXSEL 0xF8 +#define VK_EREOF 0xF9 +#define VK_PLAY 0xFA +#define VK_ZOOM 0xFB +#define VK_NONAME 0xFC +#define VK_PA1 0xFD +#define VK_OEM_CLEAR 0xFE + +#define KEYEVENTF_EXTENDEDKEY 0x0001 +#define KEYEVENTF_KEYUP 0x0002 +#define KEYEVENTF_UNICODE 0x0004 +#define KEYEVENTF_SCANCODE 0x0008 + +#define TICKS_PER_SECOND 10000000 +#define EPOCH_DIFFERENCE 11644473600 + +#define FILE_ATTRIBUTE_READONLY 0x00000001 +#define FILE_ATTRIBUTE_HIDDEN 0x00000002 +#define FILE_ATTRIBUTE_SYSTEM 0x00000004 +#define FILE_ATTRIBUTE_DIRECTORY 0x00000010 +#define FILE_ATTRIBUTE_ARCHIVE 0x00000020 +#define FILE_ATTRIBUTE_DEVICE 0x00000040 +#define FILE_ATTRIBUTE_NORMAL 0x00000080 +#define FILE_ATTRIBUTE_TEMPORARY 0x00000100 +#define FILE_ATTRIBUTE_SPARSE_FILE 0x00000200 +#define FILE_ATTRIBUTE_REPARSE_POINT 0x00000400 +#define FILE_ATTRIBUTE_COMPRESSED 0x00000800 +#define FILE_ATTRIBUTE_OFFLINE 0x00001000 +#define FILE_ATTRIBUTE_NOT_CONTENT_INDEXED 0x00002000 +#define FILE_ATTRIBUTE_ENCRYPTED 0x00004000 +#define FILE_ATTRIBUTE_INTEGRITY_STREAM 0x00008000 +#define FILE_ATTRIBUTE_VIRTUAL 0x00010000 +#define FILE_ATTRIBUTE_NO_SCRUB_DATA 0x00020000 +#define FILE_ATTRIBUTE_BROKEN 0x00200000 +#define FILE_ATTRIBUTE_EXECUTABLE 0x00400000 +#define FILE_ATTRIBUTE_DEVICE_CHAR 0x00800000 +#define FILE_ATTRIBUTE_DEVICE_FIFO 0x01000000 +#define FILE_ATTRIBUTE_DEVICE_SOCK 0x02000000 +#define FILE_ATTRIBUTE_HARDLINKS 0x08000000 + +// WinPort.h + +#define CFKP_KEEP_MATCHED_KEY_EVENTS 0x001 +#define CFKP_KEEP_UNMATCHED_KEY_EVENTS 0x002 +#define CFKP_KEEP_MOUSE_EVENTS 0x004 +#define CFKP_KEEP_OTHER_EVENTS 0x100 + +#define EXCLUSIVE_CTRL_LEFT 0x00000001 +#define EXCLUSIVE_CTRL_RIGHT 0x00000002 +#define EXCLUSIVE_ALT_LEFT 0x00000004 +#define EXCLUSIVE_ALT_RIGHT 0x00000008 +#define EXCLUSIVE_WIN_LEFT 0x00000010 +#define EXCLUSIVE_WIN_RIGHT 0x00000020 + +#define CONSOLE_PAINT_SHARP 0x00010000 +#define CONSOLE_OSC52CLIP_SET 0x00020000 + +#define CONSOLE_TTY_PALETTE_OVERRIDE 0x00040000 + +#define TWEAK_STATUS_SUPPORT_EXCLUSIVE_KEYS 0x01 +#define TWEAK_STATUS_SUPPORT_PAINT_SHARP 0x02 +#define TWEAK_STATUS_SUPPORT_OSC52CLIP_SET 0x04 +#define TWEAK_STATUS_SUPPORT_CHANGE_FONT 0x08 +#define TWEAK_STATUS_SUPPORT_TTY_PALETTE 0x10 +#define TWEAK_STATUS_SUPPORT_BLINK_RATE 0x20