按提示词结论补 INI 命名参数桥
This commit is contained in:
@@ -82,6 +82,37 @@ bool file_mode_enabled() {
|
||||
return std::getenv("CNC_SIM_RS274_FILE_MODE") != nullptr;
|
||||
}
|
||||
|
||||
class ScopedEnvironmentVariable {
|
||||
public:
|
||||
ScopedEnvironmentVariable(const char *name, const std::string &value) : name_(name), active_(!value.empty()) {
|
||||
if (!active_) {
|
||||
return;
|
||||
}
|
||||
if (const char *old = std::getenv(name_)) {
|
||||
had_old_ = true;
|
||||
old_ = old;
|
||||
}
|
||||
setenv(name_, value.c_str(), 1);
|
||||
}
|
||||
|
||||
~ScopedEnvironmentVariable() {
|
||||
if (!active_) {
|
||||
return;
|
||||
}
|
||||
if (had_old_) {
|
||||
setenv(name_, old_.c_str(), 1);
|
||||
} else {
|
||||
unsetenv(name_);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
const char *name_;
|
||||
bool active_;
|
||||
bool had_old_ = false;
|
||||
std::string old_;
|
||||
};
|
||||
|
||||
#ifndef CNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE
|
||||
bool write_temp_program(const char *program,
|
||||
size_t program_len,
|
||||
@@ -197,6 +228,9 @@ int parse_linuxcnc_rs274_backend(CanonEventSink &sink,
|
||||
sink.clear_callback_status();
|
||||
cnc_sim_linuxcnc_set_canon_sink(&sink);
|
||||
|
||||
// LinuxCNC source basis: rs274ngc_pre.cc and interp_namedparams.cc read
|
||||
// INI_FILE_NAME for startup and #<_ini[section]key> named parameters.
|
||||
ScopedEnvironmentVariable ini_file_env("INI_FILE_NAME", options.ini_file_name);
|
||||
InterpBase *interp = makeInterp();
|
||||
if (!options.ini_file_name.empty()) {
|
||||
// LinuxCNC source basis: emctask.cc calls Interp::ini_load() before
|
||||
|
||||
Reference in New Issue
Block a user