commit 17b0b6b0c43b75a3f1ad3941182a7e98184bad4a
Author: Pavel Sanda <[email protected]>
Date: Mon Oct 5 21:18:00 2026 +0200
Drop the cygdrive probe
At startup LyX asked an installed Cygwin where it maps the Windows
drives, by running its mount.exe through the command interpreter. The
answer is only ever used when writing posix style paths into LaTeX
files, i.e. when a native Windows LyX drives a Cygwin TeX.
Cygwin has exposed the prefix as the symlink /proc/cygdrive since
1.7.33 (November 2014), so the question does not need asking at all.
Using that path keeps working for whatever the user set with
mount --change-cygdrive-prefix, and nothing gets spawned.
Drops runComspec() (previous runCommand() which moved here just for
this caller).
Reviewed by Enrico.
Tier 01 DiD / argv 09: one COMSPEC caller less on Windows
https://www.mail-archive.com/[email protected]/msg226967.html
Assisted-by: Claude Opus 5
---
src/support/os_win32.cpp | 148 ++---------------------------------------------
1 file changed, 6 insertions(+), 142 deletions(-)
diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp
index bacb905b52..4ea4855005 100644
--- a/src/support/os_win32.cpp
+++ b/src/support/os_win32.cpp
@@ -32,21 +32,17 @@
#include "support/lassert.h"
-#include <cstdio>
#include <cstdlib>
-#include <cstring> // memset
#include <iostream>
#include <vector>
#include <QString>
#include <io.h>
-#include <fcntl.h> // _O_RDONLY
#include <direct.h> // _getdrive
#include <fileapi.h> // GetFinalPathNameByHandle
#include <shlobj.h> // SHGetFolderPath
#include <windef.h>
-#include <windows.h>
#include <shellapi.h>
#include <shlwapi.h>
@@ -91,102 +87,14 @@ wchar_t ** argv_ = 0;
bool windows_style_tex_paths_ = true;
-string cygdrive = "/cygdrive";
+// The prefix a Cygwin installation maps the Windows drives under, used
+// when writing posix style paths into LaTeX files for a Cygwin TeX.
+// Cygwin keeps /proc/cygdrive as a symlink to the prefix actually in
+// use, so there is nothing to ask it about: this covers whatever the
+// user set with mount --change-cygdrive-prefix.
+string const cygdrive = "/proc/cygdrive";
-// Run cmd through COMSPEC and return its standard output in result,
-// the return value tells whether the command exited successfully.
-//
-// Relic of the former cross-platform support::runCommand() and it spawns
-// a shell, so you need be extra careful about safety of the arguments.
-// Preferably do not add new callers of this function - we have generic
-// Systemcall and this is used only in init() before QCoreApplication
-// kicks in.
-bool runComspec(string const & cmd, string & result)
-{
- result.clear();
-
- if (verbose)
- lyxerr << "\nRunning: " << cmd << endl;
- else
- LYXERR(Debug::INFO,"Running: " << cmd);
-
- STARTUPINFO startup;
- PROCESS_INFORMATION process;
- SECURITY_ATTRIBUTES security;
- HANDLE in, out;
- FILE * inf = 0;
- bool err2out = false;
- string command;
- string const infile = trim(split(cmd, command, '<'), " \"");
- command = rtrim(command);
- if (suffixIs(command, "2>&1")) {
- command = rtrim(command, "2>&1");
- err2out = true;
- }
- string const cmdarg = "/d /c \"" + command + "\"";
- string const comspec = getEnv("COMSPEC");
-
- security.nLength = sizeof(SECURITY_ATTRIBUTES);
- security.bInheritHandle = TRUE;
- security.lpSecurityDescriptor = NULL;
-
- if (CreatePipe(&in, &out, &security, 0)) {
- memset(&startup, 0, sizeof(STARTUPINFO));
- memset(&process, 0, sizeof(PROCESS_INFORMATION));
-
- startup.cb = sizeof(STARTUPINFO);
- startup.dwFlags = STARTF_USESTDHANDLES;
-
- startup.hStdError = err2out ? out :
GetStdHandle(STD_ERROR_HANDLE);
- startup.hStdInput = infile.empty()
- ? GetStdHandle(STD_INPUT_HANDLE)
- : CreateFile(infile.c_str(), GENERIC_READ,
- FILE_SHARE_READ, &security, OPEN_EXISTING,
- FILE_ATTRIBUTE_NORMAL, NULL);
- startup.hStdOutput = out;
-
- if (startup.hStdInput != INVALID_HANDLE_VALUE &&
- CreateProcess(comspec.c_str(), (LPTSTR)cmdarg.c_str(),
- &security, &security, TRUE, CREATE_NO_WINDOW,
- 0, 0, &startup, &process)) {
-
- CloseHandle(process.hThread);
- int fno = _open_osfhandle((intptr_t)in, _O_RDONLY);
- CloseHandle(out);
- inf = _fdopen(fno, "r");
- }
- }
-
- if (!inf) {
- lyxerr << "RunCommand: could not start child process" << endl;
- return false;
- }
-
- int c = fgetc(inf);
- while (c != EOF) {
- result += static_cast<char>(c);
- c = fgetc(inf);
- }
-
- WaitForSingleObject(process.hProcess, INFINITE);
- DWORD pret;
- BOOL success = GetExitCodeProcess(process.hProcess, &pret);
- bool valid = (pret == 0) && success;
- if (!success)
- pret = -1;
- if (!infile.empty())
- CloseHandle(startup.hStdInput);
- CloseHandle(process.hProcess);
- if (fclose(inf) != 0)
- pret = -1;
-
- if (pret == -1)
- perror("RunCommand: could not terminate child process");
-
- return valid;
-}
-
BOOL terminate_handler(DWORD event)
{
if (event == CTRL_CLOSE_EVENT
@@ -290,50 +198,6 @@ void init(int argc, char ** argv[])
#endif
LATTEST(argc == argc_);
- // If Cygwin is detected, query the cygdrive prefix.
- // The cygdrive prefix is needed for translating windows style paths
- // to posix style paths in LaTeX files when the Cygwin teTeX is used.
- int i;
- HKEY hkey;
- char buf[MAX_PATH];
- DWORD bufsize = sizeof(buf);
- LONG retval = ERROR_FILE_NOT_FOUND;
- HKEY const mainkey[2] = { HKEY_LOCAL_MACHINE, HKEY_CURRENT_USER };
- char const * const subkey[2] = {
- "Software\\Cygwin\\setup", // Cygwin 1.7
- "Software\\Cygnus Solutions\\Cygwin\\mounts v2\\/" // Prev. ver.
- };
- char const * const valuename[2] = {
- "rootdir", // Cygwin 1.7 or later
- "native" // Previous versions
- };
- // Check for newer Cygwin versions first, then older ones
- for (i = 0; i < 2 && retval != ERROR_SUCCESS; ++i) {
- for (int k = 0; k < 2 && retval != ERROR_SUCCESS; ++k)
- retval = RegOpenKey(mainkey[k], subkey[i], &hkey);
- }
- if (retval == ERROR_SUCCESS) {
- // Query the Cygwin root directory
- retval = RegQueryValueEx(hkey, valuename[i - 1],
- NULL, NULL, (LPBYTE) buf, &bufsize);
- RegCloseKey(hkey);
- string const mount = string(buf) + "\\bin\\mount.exe";
- if (retval == ERROR_SUCCESS && FileName(mount).exists()) {
- string result;
- bool const valid = runComspec(
- mount + " --show-cygdrive-prefix", result);
- // The output of the mount command is as follows:
- // Prefix Type Flags
- // /cygdrive system binmode
- // So, we use the inner split to pass the second line
- // to the outer split which sets cygdrive with its
- // contents until the first blank, discarding the
- // unneeded return value.
- if (valid && prefixIs(result, "Prefix"))
- split(split(result, '\n'), cygdrive, ' ');
- }
- }
-
// Catch shutdown events.
SetConsoleCtrlHandler((PHANDLER_ROUTINE)terminate_handler, TRUE);
}
--
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs