Klammertext runs natively on Windows; a Windows source-install guide; the bundled sh for @eval :shell
Assembled from klammertext-dev f344a37d772c. The commands, the library,
the Standard Klammer Set, the reflection klammerset and the Python
binding build and run natively on Windows (MSYS2 UCRT64 gcc, python.org
Python), and both test tiers pass there. doc/install/windows_source_install.md
is the fifth install guide: a source install parallel to the Linux and
macOS ones, verified by following it on a pristine Windows 11.
Behaviour on every system: paths Klammertext prints use forward slashes;
output is LF; the command line is UTF-8 on Windows; @eval :shell is a
POSIX shell command everywhere -- on Windows it runs the sh Klammertext
ships, BusyBox for Windows (win/busybox/, GPLv2, with its licence and the
source pointer). KLAMMERTEXT_FONTS and KLAMMERTEXT_KLAMMERSETS are lists in
the system's PATH convention (';' on Windows). On Linux and macOS nothing
observable changes.
This commit is contained in:
1 parent
f9af1ff869
commit
830b19394d
55 files changed
+1182
-153
No files matched your search
+46
-1
@@ -1,3 +1,8 @@
|
||||
#include <unistd.h>
|
||||
#include <fstream>
|
||||
#include "error.h"
|
||||
#include "file.h"
|
||||
#include "locator.h"
|
||||
#include <stdlib.h>
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
@@ -621,11 +626,51 @@ std::string freplace(const std::string& src, const std::regex& pattern,
|
||||
return result;
|
||||
}
|
||||
|
||||
// Shell_command -- see util.h. On Windows the script goes to a file under
|
||||
// the temp directory (mkstemp, so concurrent runs do not collide), and the
|
||||
// line is ""<busybox>" sh "<script>"" -- the outer pair of quotes because
|
||||
// cmd /c strips the FIRST and LAST quote of a line holding more than two.
|
||||
Shell_command::Shell_command(const std::string& sh_command, [[maybe_unused]] const Locator& loc)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
fs::path busybox = fs::path(get_env_var("KLAMMERTEXT_HOME")) / "win" / "busybox" / "busybox64u.exe";
|
||||
if (!fs::exists(busybox)) {
|
||||
throw Environment_error(
|
||||
"The shell Klammertext runs sh commands with on Windows is missing: "
|
||||
+ busybox.generic_string(), loc);
|
||||
}
|
||||
std::string path = (fs::temp_directory_path() / "ktext_sh_XXXXXX").string();
|
||||
std::vector<char> tmpl(path.begin(), path.end());
|
||||
tmpl.push_back('\0');
|
||||
int fd = mkstemp(tmpl.data());
|
||||
if (fd == -1) {
|
||||
throw Environment_error("Could not create a temporary file for a shell command", loc);
|
||||
}
|
||||
close(fd);
|
||||
m_script = tmpl.data();
|
||||
std::ofstream out(m_script, std::ios::binary);
|
||||
out << sh_command << "\n";
|
||||
out.close();
|
||||
m_line = "\"\"" + busybox.string() + "\" sh \"" + m_script + "\"\"";
|
||||
#else
|
||||
m_line = sh_command;
|
||||
#endif
|
||||
}
|
||||
|
||||
Shell_command::~Shell_command()
|
||||
{
|
||||
if (!m_script.empty()) {
|
||||
std::error_code ec {};
|
||||
fs::remove(m_script, ec);
|
||||
}
|
||||
}
|
||||
|
||||
std::string exec(const char* cmd)
|
||||
{
|
||||
std::array<char, 128> buffer;
|
||||
std::string result;
|
||||
FILE* pipe = popen(cmd, "r");
|
||||
Shell_command sh_cmd(cmd, Locator::none());
|
||||
FILE* pipe = popen(sh_cmd.line().c_str(), "r");
|
||||
if (!pipe) throw std::runtime_error("popen() failed");
|
||||
while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) {
|
||||
result += buffer.data();
|
||||
|
||||
Reference in new issue
Block a user