![]() |
The platform layers | ![]() |
The portable code never calls the C library or the operating system directly for files, directories, environment variables and processes. It calls a small set of functions with the prefix texmacs_, which are declared and implemented once per platform:
Plugins/Unix/unix_system.hpp
Used on Linux, macOS and the other Unix systems.
Plugins/Windows64/windows64_system.hpp
Used for 64-bit Windows builds (OS_MINGW64).
Plugins/Windows/windows32_system.hpp
Used for the older 32-bit Windows builds.
Plugins/Android/android_system.hpp
Used on Android.
System/Files/file.cpp
and
System/Misc/sys_utils.hpp
include the right header with preprocessor tests.
texmacs_fopen (name, mode, lock), texmacs_fread, texmacs_fwrite, texmacs_fsize, texmacs_fclose (f, unlock), texmacs_lock_file, texmacs_unlock_file. Names are UTF-8 strings.
texmacs_opendir, texmacs_readdir (which returns a texmacs_dirent with a validity flag and the name), texmacs_closedir, texmacs_stat, texmacs_mkdir, texmacs_rmdir, texmacs_rename, texmacs_chmod, texmacs_remove.
texmacs_reset_last_error, texmacs_get_last_error, texmacs_get_last_error_str.
texmacs_getenv, texmacs_setenv.
get_default_theme (light or dark, following the system with Qt 6.5 and later, and light with the other ports, whose own themes come from the preference gui theme in Vue and from the appearance of the application in Cocoa), texmacs_get_application_directory, texmacs_init_guile_hooks.
Processes are run by
unix_sys_utils.cpp
on Unix, by windows_system and mingw_system on 64-bit Windows, and by Qt (qt_system) on 32-bit Windows and Android; see programs, web requests, messages and timing.
The Unix layer maps the interface directly to the C library: names are passed unchanged, locks are flock locks (LOCK_EX), and texmacs_stat is stat. texmacs_get_application_directory uses /proc/self/exe on Linux and _NSGetExecutablePath on macOS.
unix_entrypoint.cpp
contains main: it installs the Scheme hooks, finds TEXMACS_PATH (paths, directories and settings), adds the usr/bin directories of an AppImage to PATH, forces the X11 platform of Qt 5 when no Wayland display is present, and calls texmacs_entrypoint. The file also contains a disabled experiment (EXPERIMENTAL_REEXEC_DETACHED) which re-executes the program detached from the terminal. Stack traces use backtrace, and the server log uses syslog on Linux and os_log on macOS.
Plugins/MacOS/ adds services which only exist on macOS; it is compiled with every port on macOS (MACOSX_EXTENSIONS), unless --disable-macosx-extensions is given, which the Cocoa port refuses:
mac_utilities.mm
mac_alternate_startup (is the Alt key held during startup, in which case the settings and caches are reset), the event filter which repairs Ctrl+Tab in some Qt versions, the support for Apple remote controls, mac_begin_server and mac_end_server, which declare a background activity so that the system does not put a running TeXmacs server to sleep (App Nap), and the unified title bar of the windows.
mac_spellservice.mm
Spell checking with the system dictionaries.
mac_images.mm
Image sizes and conversions with Cocoa.
mac_app.mm
The NSApplication delegate of the X11 front end on macOS (MACOSX_EXTENSIONS). The native Cocoa port has its own, in
Plugins/NS
.
The 64-bit layer converts all names and environment variables between UTF-8 and the wide character APIs of Windows (
windows64_encoding.cpp
), opens files in binary mode, and locks them with LockFileEx. texmacs_init_guile_hooks installs wide character versions of the file functions used by Guile (stat, open, readdir, getenv, …), so that Scheme code also works with non-ASCII names.
windows64_entrypoint.cpp
defines main, WinMain and wWinMain, which all:
attach to the console of the parent process if there is one, so that messages are visible when TeXmacs is started from a terminal (except under MSYS);
set TEXMACS_DISPLAYNAME to the full name of the user if it is not set;
find TEXMACS_PATH next to the executable;
convert the command line, obtained in wide characters from the system, to UTF-8 and call texmacs_entrypoint.
The 32-bit layer (
Plugins/Windows/
) uses the nowide library for the conversion of arguments and file names. Both layers have their own stack trace and server log implementations.
The Android layer implements texmacs_fopen with a QFile (the returned FILE* is really a QFile*) and does no locking. URLs with the root content denote documents provided by other applications; resolution only tests them for the requested type, their suffix is derived from their MIME type (android_suffix_from_mime), and resolve_in_path looks for programs in $TEXMACS_PATH/bin. The application directory is the home directory.
android.cpp
starts a background service and exports the JNI function callScheme, by which the Java side can run a Scheme command in the main thread.
The behaviour of locks differs: advisory flock locks on Unix, mandatory LockFileEx locks on Windows (which block other programs as long as TeXmacs holds the file), none on Android.
See also the pitfalls of texmacs_get_application_directory and texmacs_stat in paths, directories and settings and files and caches.