Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/emc/ini/emcIniFile.hh
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ public:
return(IniFile::Find(result,
tag, section, num));
}
const char * Find(const char *tag, const char *section=NULL,
std::optional<std::string> Find(const char *tag, const char *section=NULL,
int num = 1){
return(IniFile::Find(tag, section, num)
.value_or(nullptr));
return(IniFile::Find(tag, section, num));
}

private:
Expand Down
6 changes: 3 additions & 3 deletions src/emc/ini/inijoint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ extern value_inihal_data old_inihal_data;
static int loadJoint(int joint, EmcIniFile *jointIniFile)
{
char jointString[16];
const char *inistring;
EmcJointType jointType;
double units;
double backlash;
Expand Down Expand Up @@ -234,8 +233,9 @@ static int loadJoint(int joint, EmcIniFile *jointIniFile)

comp_file_type = 0; // default
jointIniFile->Find(&comp_file_type, "COMP_FILE_TYPE", jointString);
if (NULL != (inistring = jointIniFile->Find("COMP_FILE", jointString))) {
if (0 != emcJointLoadComp(joint, inistring, comp_file_type)) {
auto comp_file = jointIniFile->Find("COMP_FILE", jointString);
if (comp_file) {
if (0 != emcJointLoadComp(joint, comp_file->c_str(), comp_file_type)) {
return -1;
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/emc/ini/initraj.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,33 @@ static int loadTraj(EmcIniFile *trajInifile)

try{
int axismask = 0;
const char *coord = trajInifile->Find("COORDINATES", "TRAJ");
auto coord = trajInifile->Find("COORDINATES", "TRAJ");
if(coord) {
if(strchr(coord, 'x') || strchr(coord, 'X')) {
if(coord->find_first_of("xX") != std::string::npos) {
axismask |= 1;
}
if(strchr(coord, 'y') || strchr(coord, 'Y')) {
if(coord->find_first_of("yY") != std::string::npos) {
axismask |= 2;
}
if(strchr(coord, 'z') || strchr(coord, 'Z')) {
if(coord->find_first_of("zZ") != std::string::npos) {
axismask |= 4;
}
if(strchr(coord, 'a') || strchr(coord, 'A')) {
if(coord->find_first_of("aA") != std::string::npos) {
axismask |= 8;
}
if(strchr(coord, 'b') || strchr(coord, 'B')) {
if(coord->find_first_of("bB") != std::string::npos) {
axismask |= 16;
}
if(strchr(coord, 'c') || strchr(coord, 'C')) {
if(coord->find_first_of("cC") != std::string::npos) {
axismask |= 32;
}
if(strchr(coord, 'u') || strchr(coord, 'U')) {
if(coord->find_first_of("uU") != std::string::npos) {
axismask |= 64;
}
if(strchr(coord, 'v') || strchr(coord, 'V')) {
if(coord->find_first_of("vV") != std::string::npos) {
axismask |= 128;
}
if(strchr(coord, 'w') || strchr(coord, 'W')) {
if(coord->find_first_of("wW") != std::string::npos) {
axismask |= 256;
}
} else {
Expand Down Expand Up @@ -295,22 +295,22 @@ static int loadTraj(EmcIniFile *trajInifile)
return -1;
}
try{
const char *inistring;
unsigned char coordinateMark[6] = { 1, 1, 1, 0, 0, 0 };
int t;
int len;
char homes[LINELEN];
char home[LINELEN];
EmcPose homePose = { {0.0, 0.0, 0.0}, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
double d;
if (NULL != (inistring = trajInifile->Find("HOME", "TRAJ"))) {
auto inistring = trajInifile->Find("HOME", "TRAJ");
if (inistring) {
// [TRAJ]HOME is important for genhexkins.c kinetmaticsForward()
// and probably other non-identity kins that solve the forward
// kinematics with an iterative algorithm when the homePose
// is not all zeros

// found it, now interpret it according to coordinateMark[]
rtapi_strxcpy(homes, inistring);
rtapi_strxcpy(homes, inistring->c_str());
len = 0;
for (t = 0; t < 6; t++) {
if (!coordinateMark[t]) {
Expand Down Expand Up @@ -354,7 +354,7 @@ static int loadTraj(EmcIniFile *trajInifile)
} else {
// badly formatted entry
rcs_print("invalid INI file value for [TRAJ] HOME: %s\n",
inistring);
inistring->c_str());
return -1;
}
} // end of for-loop on coordinateMark[]
Expand Down
25 changes: 12 additions & 13 deletions src/emc/pythonplugin/python_plugin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ int PythonPlugin::configure(const char *iniFilename,
const char *section)
{
IniFile inifile;
std::optional<const char*> inistring;

if (section == NULL) {
logPP(1, "no section");
Expand All @@ -360,16 +359,16 @@ int PythonPlugin::configure(const char *iniFilename,

char real_path[PATH_MAX];
char expandinistring[PATH_MAX];
if ((inistring = inifile.Find("TOPLEVEL", section))) {
if (inifile.TildeExpansion(*inistring,expandinistring,sizeof(expandinistring))) {
if (auto inistring = inifile.Find("TOPLEVEL", section)) {
if (inifile.TildeExpansion(inistring->c_str(),expandinistring,sizeof(expandinistring))) {
logPP(-1, "TildeExpansion failed '%s'", toplevel);
status = PLUGIN_BAD_PATH;
return status;
}
toplevel = strstore(expandinistring);

if ((inistring = inifile.Find("RELOAD_ON_CHANGE", section)))
reload_on_change = (atoi(*inistring) > 0);
if (auto reload_str = inifile.Find("RELOAD_ON_CHANGE", section))
reload_on_change = (atoi(reload_str->c_str()) > 0);

if (realpath(toplevel, real_path) == NULL) {
logPP(-1, "can\'t resolve path to '%s'", toplevel);
Expand All @@ -394,16 +393,16 @@ int PythonPlugin::configure(const char *iniFilename,
abs_path = strstore(real_path);
}

if ((inistring = inifile.Find("LOG_LEVEL", section)))
log_level = atoi(*inistring);
if (auto inistring = inifile.Find("LOG_LEVEL", section))
log_level = atoi(inistring->c_str());
else log_level = 0;

char pycmd[PATH_MAX + 64];
int n = 1;
int lineno;
while ((inistring = inifile.Find("PATH_PREPEND", "PYTHON",
n, &lineno))) {
if (inifile.TildeExpansion(*inistring,expandinistring,sizeof(expandinistring))) {
while (auto inistring = inifile.Find("PATH_PREPEND", "PYTHON",
n, &lineno)) {
if (inifile.TildeExpansion(inistring->c_str(),expandinistring,sizeof(expandinistring))) {
logPP(-1, "TildeExpansion failed '%s'", toplevel);
status = PLUGIN_EXCEPTION_DURING_PATH_PREPEND;
return status;
Expand All @@ -420,9 +419,9 @@ int PythonPlugin::configure(const char *iniFilename,
n++;
}
n = 1;
while ((inistring = inifile.Find("PATH_APPEND", "PYTHON",
n, &lineno))) {
if (inifile.TildeExpansion(*inistring,expandinistring,sizeof(expandinistring))) {
while (auto inistring = inifile.Find("PATH_APPEND", "PYTHON",
n, &lineno)) {
if (inifile.TildeExpansion(inistring->c_str(),expandinistring,sizeof(expandinistring))) {
logPP(-1, "TildeExpansion failed '%s'", toplevel);
status = PLUGIN_EXCEPTION_DURING_PATH_APPEND;
return status;
Expand Down
5 changes: 2 additions & 3 deletions src/emc/rs274ngc/interp_namedparams.cc
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,6 @@ double Interp::inicheck()
{
IniFile inifile;
const char *filename;
std::optional<const char*> inistring;
double result = -1.0;

if ((filename = getenv("INI_FILE_NAME")) == NULL) {
Expand All @@ -976,8 +975,8 @@ double Interp::inicheck()
return -1.0;
}

if ((inistring = inifile.Find("LINEAR_UNITS", "TRAJ"))) {
if (!strcmp(*inistring, "inch")) {
if (auto inistring = inifile.Find("LINEAR_UNITS", "TRAJ")) {
if (*inistring == "inch") {
result = 0.0;
} else {
result = 1.0;
Expand Down
65 changes: 32 additions & 33 deletions src/emc/rs274ngc/rs274ngc_pre.cc
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,6 @@ int Interp::init()
fprintf(stderr,"Unable to open inifile:%s:\n", iniFileName);
} else {
bool opt;
std::optional<const char*> inistring;

inifile.Find(&_setup.tool_change_at_g30, "TOOL_CHANGE_AT_G30", "EMCIO");
inifile.Find(&_setup.tool_change_quill_up, "TOOL_CHANGE_QUILL_UP", "EMCIO");
Expand Down Expand Up @@ -920,14 +919,14 @@ int Interp::init()
inifile.Find(&opt, "OWORD_WARNONLY", "RS274NGC");
if (opt) _setup.feature_set |= FEATURE_OWORD_WARNONLY;

if ((inistring =inifile.Find("LOCKING_INDEXER_JOINT", "AXIS_A"))) {
_setup.a_indexer_jnum = atol(*inistring);
if (auto inistring = inifile.Find("LOCKING_INDEXER_JOINT", "AXIS_A")) {
_setup.a_indexer_jnum = atol(inistring->c_str());
}
if ((inistring =inifile.Find("LOCKING_INDEXER_JOINT", "AXIS_B"))) {
_setup.b_indexer_jnum = atol(*inistring);
if (auto inistring = inifile.Find("LOCKING_INDEXER_JOINT", "AXIS_B")) {
_setup.b_indexer_jnum = atol(inistring->c_str());
}
if ((inistring =inifile.Find("LOCKING_INDEXER_JOINT", "AXIS_C"))) {
_setup.c_indexer_jnum = atol(*inistring);
if (auto inistring = inifile.Find("LOCKING_INDEXER_JOINT", "AXIS_C")) {
_setup.c_indexer_jnum = atol(inistring->c_str());
}
inifile.Find(&_setup.orient_offset, "ORIENT_OFFSET", "RS274NGC");
inifile.Find(&_setup.parameter_g73_peck_clearance, "G73_PECK_CLEARANCE", "RS274NGC");
Expand All @@ -937,18 +936,18 @@ int Interp::init()

_setup.debugmask |= EMC_DEBUG_UNCONDITIONAL;

if((inistring = inifile.Find("LOG_LEVEL", "RS274NGC")))
if(auto inistring = inifile.Find("LOG_LEVEL", "RS274NGC"))
{
_setup.loggingLevel = atol(*inistring);
_setup.loggingLevel = atol(inistring->c_str());
}

// default the log_file to stderr.
if((inistring = inifile.Find("LOG_FILE", "RS274NGC")))
if(auto inistring = inifile.Find("LOG_FILE", "RS274NGC"))
{
if ((log_file = fopen(*inistring, "a")) == NULL) {
if ((log_file = fopen(inistring->c_str(), "a")) == NULL) {
log_file = stderr;
logDebug( "(%d): Unable to open log file:%s, using stderr",
getpid(), *inistring);
getpid(), inistring->c_str());
}
} else {
log_file = stderr;
Expand All @@ -957,38 +956,38 @@ int Interp::init()
_setup.use_lazy_close = 1;

_setup.wizard_root[0] = 0;
if((inistring = inifile.Find("WIZARD_ROOT", "WIZARD")))
if(auto inistring = inifile.Find("WIZARD_ROOT", "WIZARD"))
{
logDebug("[WIZARD]WIZARD_ROOT:%s", *inistring);
if (realpath(*inistring, _setup.wizard_root) == NULL) {
logDebug("[WIZARD]WIZARD_ROOT:%s", inistring->c_str());
if (realpath(inistring->c_str(), _setup.wizard_root) == NULL) {
//realpath didn't find the file
logDebug("realpath failed to find wizard_root:%s:", *inistring);
logDebug("realpath failed to find wizard_root:%s:", inistring->c_str());
}
}
logDebug("_setup.wizard_root:%s:", _setup.wizard_root);

_setup.program_prefix[0] = 0;
if((inistring = inifile.Find("PROGRAM_PREFIX", "DISPLAY")))
if(auto inistring = inifile.Find("PROGRAM_PREFIX", "DISPLAY"))
{
// found it
char expandinistring[LINELEN];
if (inifile.TildeExpansion(*inistring,expandinistring,sizeof(expandinistring))) {
logDebug("TildeExpansion failed for: %s",*inistring);
if (inifile.TildeExpansion(inistring->c_str(),expandinistring,sizeof(expandinistring))) {
logDebug("TildeExpansion failed for: %s",inistring->c_str());
}
if (realpath(expandinistring, _setup.program_prefix) == NULL){
//realpath didn't find the file
logDebug("realpath failed to find program_prefix:%s:", *inistring);
logDebug("realpath failed to find program_prefix:%s:", inistring->c_str());
}
logDebug("program prefix:%s: prefix:%s:",
*inistring, _setup.program_prefix);
inistring->c_str(), _setup.program_prefix);
}
else
{
logDebug("PROGRAM_PREFIX not found");
}
logDebug("_setup.program_prefix:%s:", _setup.program_prefix);

if((inistring = inifile.Find("SUBROUTINE_PATH", "RS274NGC")))
if(auto inistring = inifile.Find("SUBROUTINE_PATH", "RS274NGC"))
{
// found it
int dct;
Expand All @@ -999,7 +998,7 @@ int Interp::init()
_setup.subroutines[dct] = NULL;
}

rtapi_strxcpy(tmpdirs,*inistring);
rtapi_strxcpy(tmpdirs,inistring->c_str());
nextdir = strtok(tmpdirs,":"); // first token
dct = 0;
while (1) {
Expand Down Expand Up @@ -1031,15 +1030,15 @@ int Interp::init()
}
// subroutine to execute on aborts - for instance to retract
// toolchange HAL pins
if ((inistring = inifile.Find("ON_ABORT_COMMAND", "RS274NGC"))) {
_setup.on_abort_command = strstore(*inistring);
if (auto inistring = inifile.Find("ON_ABORT_COMMAND", "RS274NGC")) {
_setup.on_abort_command = strstore(inistring->c_str());
logDebug("_setup.on_abort_command=%s", _setup.on_abort_command);
} else {
_setup.on_abort_command = NULL;
}

// initialize the Python plugin singleton
if ((inistring = inifile.Find("TOPLEVEL", "PYTHON"))) {
if (inifile.Find("TOPLEVEL", "PYTHON")) {
int status = python_plugin->configure(iniFileName,"PYTHON");
if (status != PLUGIN_OK) {
Error("Python plugin configure() failed, status = %d", status);
Expand All @@ -1051,10 +1050,10 @@ int Interp::init()
_setup.g_remapped.clear();
_setup.m_remapped.clear();
_setup.remaps.clear();
while ((inistring = inifile.Find("REMAP", "RS274NGC",
n, &lineno))) {
while (auto inistring = inifile.Find("REMAP", "RS274NGC",
n, &lineno)) {

CHP(parse_remap( *inistring, lineno));
CHP(parse_remap( inistring->c_str(), lineno));
n++;
}

Expand Down Expand Up @@ -2513,7 +2512,6 @@ VARIABLE_FILE = rs274ngc.var
int Interp::ini_load(const char *filename)
{
IniFile inifile;
std::optional<const char*> inistring;

// open it
if (inifile.Open(filename) == false) {
Expand All @@ -2525,12 +2523,13 @@ int Interp::ini_load(const char *filename)


char parameter_file_name[LINELEN]={};
if ((inistring = inifile.Find("PARAMETER_FILE", "RS274NGC"))) {
if (strlen(*inistring) >= sizeof(parameter_file_name)) {
if (auto inistring = inifile.Find("PARAMETER_FILE", "RS274NGC")) {
if (inistring->length() >= sizeof(parameter_file_name)) {
logDebug("%s:[RS274NGC]PARAMETER_FILE is too long (max len %zu)",
filename, sizeof(parameter_file_name)-1);
} else {
strncpy(parameter_file_name, *inistring, sizeof(parameter_file_name));
strncpy(parameter_file_name, inistring->c_str(), sizeof(parameter_file_name)-1);
parameter_file_name[sizeof(parameter_file_name)-1] = '\0';
logDebug("found PARAMETER_FILE:%s:", parameter_file_name);
}
} else {
Expand Down
5 changes: 2 additions & 3 deletions src/emc/sai/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -675,16 +675,15 @@ int main (int argc, char ** argv)
}
_sai._external_length_units = 0.03937007874016;
if (inifile!= 0) {
std::optional<const char*> inistring;
IniFile ini;
// open it
if (ini.Open(inifile) == false) {
fprintf(stderr, "could not open supplied INI file %s\n", inifile);
exit(1);
}

if ((inistring = ini.Find("LINEAR_UNITS", "TRAJ"))) {
if (!strcmp(*inistring, "mm")) {
if (auto inistring = ini.Find("LINEAR_UNITS", "TRAJ")) {
if (*inistring == "mm") {
_sai._external_length_units = 1.0;
}
}
Expand Down
Loading
Loading