Skip to content

Commit b0c39e3

Browse files
committed
interpeter: allow full paths with o words and remaps
You can use the full path including having '~' expanded to the user path. This should be useful with GUI code writing, we can search paths easier, and just specify the path directly when calling the Oword. Might also help new users to get a fully functioning cample config. When switching from RIP to installed the paths usually get jumbled. This means we could really use a link in USER/linuxcnc/ to all the sample code. One remaining problem is if you give an incorrect path in MDI, it is not caught and hangs milltask. I'm not sure of the MDI command process yet.
1 parent 81e9385 commit b0c39e3

3 files changed

Lines changed: 80 additions & 37 deletions

File tree

src/emc/rs274ngc/interp_o_word.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,10 +545,10 @@ int Interp::control_back_to( block_pointer block, // pointer to block
545545
FILE *newFP;
546546
offset_map_iterator it;
547547
offset_pointer op;
548+
logOword("Entered:%s %s", name,basename(block->o_name));
549+
it = settings->offset_map.find(basename(block->o_name));
548550

549-
logOword("Entered:%s %s", name,block->o_name);
550-
551-
it = settings->offset_map.find(block->o_name);
551+
// #1 already defined
552552
if (it != settings->offset_map.end()) {
553553
op = &it->second;
554554
if ((settings->filename[0] != 0) &
@@ -585,6 +585,8 @@ int Interp::control_back_to( block_pointer block, // pointer to block
585585
settings->sequence_number = op->sequence_number;
586586
return INTERP_OK;
587587
}
588+
589+
// #2 open the File
588590
newFP = find_ngc_file(settings, block->o_name, newFileName);
589591

590592
if (newFP) {
@@ -607,8 +609,8 @@ int Interp::control_back_to( block_pointer block, // pointer to block
607609
free(dirname);
608610
}
609611

610-
settings->skipping_o = block->o_name; // start skipping
611-
settings->skipping_to_sub = block->o_name; // start skipping
612+
settings->skipping_o = basename(block->o_name); // start skipping
613+
settings->skipping_to_sub = basename(block->o_name); // start skipping
612614
settings->skipping_start = settings->sequence_number;
613615
return INTERP_OK;
614616
}

src/emc/rs274ngc/interp_remap.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,8 @@ int Interp::parse_remap(const char *inistring, int lineno)
451451
r.remap_ngc = strstore(arg);
452452
fclose(fp);
453453
} else {
454-
Error("NGC file not found: ngc=%s - %d:REMAP = %s",
455-
arg, lineno,inistring);
454+
Error("INTERP_REMAP: NGC file not found: ngc=%s\nREMAP INI Line:%d = %s\n",
455+
arg, lineno, inistring);
456456
errored = true;
457457
}
458458
continue;
@@ -465,7 +465,7 @@ int Interp::parse_remap(const char *inistring, int lineno)
465465
continue;
466466
}
467467
if (!PYUSABLE) {
468-
Error("Python plugin required for python=, but not available: %d:REMAP = %s",
468+
Error("iNTERP_REMAP: Python plugin required for python=, but not available:\nREMAP INI line:%d = %s\n",
469469
lineno,inistring);
470470
errored = true;
471471
continue;

src/emc/rs274ngc/rs274ngc_pre.cc

Lines changed: 70 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ include an option for suppressing superfluous commands.
9898
#include "interp_internal.hh" // interpreter private definitions
9999
#include "interp_queue.hh"
100100
#include "rs274ngc_interp.hh"
101-
101+
#include <wordexp.h>
102102
#include "units.h"
103103

104104
#include <unordered_set>
@@ -2651,55 +2651,96 @@ int Interp::on_abort(int reason, const char *message)
26512651

26522652
// spun out from interp_o_word so we can use it to test ngc file accessibility during
26532653
// config file parsing (REMAP... ngc=<basename>)
2654+
// Will expand ~ to user's home path
2655+
// searchs this sequence until it finds a match:
2656+
// 1) checks if path is already the full path
2657+
// 2) tries adding the INI defined program prefix to path
2658+
// 3) tries adding the INI defined subroutine prefix to path
2659+
// 4) tries adding the INI defined whizard prefix to path
26542660
FILE *Interp::find_ngc_file(setup_pointer settings,const char *basename, char *foundhere )
26552661
{
26562662
FILE *newFP = NULL;
26572663
char tmpFileName[PATH_MAX+1];
26582664
char newFileName[PATH_MAX+1];
26592665
char foundPlace[PATH_MAX+1];
26602666
int dct;
2667+
wordexp_t exp_result;
2668+
2669+
// #1 check if this is the full path already
26612670

2662-
// look for a new file
2663-
snprintf(tmpFileName, sizeof(tmpFileName), "%s.ngc", basename);
2671+
// expand user path
2672+
wordexp(basename, &exp_result, 0);
2673+
// add .ngc to expanded path
2674+
snprintf(tmpFileName, sizeof(tmpFileName), "%s.ngc", exp_result.we_wordv[0]);
26642675

2665-
// find subroutine by search: program_prefix, subroutines, wizard_root
2666-
// use first file found
2676+
// copy to newFileName - in case this is the one...
2677+
size_t chk = snprintf(newFileName, sizeof(newFileName), "%s", tmpFileName);
26672678

2668-
// first look in the program_prefix place
2669-
size_t chk = snprintf(newFileName, sizeof(newFileName), "%s/%s", settings->program_prefix, tmpFileName);
2679+
// found a file we can open?
26702680
if (chk < sizeof(newFileName)){
26712681
newFP = fopen(newFileName, "r");
26722682
}
26732683

2674-
// then look in the subroutines place
2684+
// #2 then look in the program_prefix place
26752685
if (!newFP) {
2676-
for (dct = 0; dct < MAX_SUB_DIRS; dct++) {
2677-
if (!settings->subroutines[dct])
2678-
continue;
2679-
chk = snprintf(newFileName, sizeof(newFileName), "%s/%s", settings->subroutines[dct], tmpFileName);
2680-
if (chk < sizeof(newFileName)){
2686+
2687+
// expand '~' into user path
2688+
wordexp(settings->program_prefix, &exp_result, 0);
2689+
chk = snprintf(newFileName, sizeof(newFileName), "%s/%s", exp_result.we_wordv[0], tmpFileName);
2690+
2691+
// found a file we can open?
2692+
if (chk < sizeof(newFileName)){
26812693
newFP = fopen(newFileName, "r");
2682-
if (newFP) {
2683-
// logOword("fopen: |%s|", newFileName);
2684-
break; // use first occurrence in dir search
2694+
}
2695+
}
2696+
2697+
// #3 then look in the list of subroutines prefixes
2698+
if (!newFP) {
2699+
for (dct = 0; dct < MAX_SUB_DIRS; dct++) {
2700+
if (!settings->subroutines[dct])
2701+
continue;
2702+
2703+
// expand '~' into user path
2704+
wordexp(settings->subroutines[dct], &exp_result, 0);
2705+
chk = snprintf(newFileName, sizeof(newFileName), "%s/%s", exp_result.we_wordv[0], tmpFileName);
2706+
2707+
// found a file we can open?
2708+
if (chk < sizeof(newFileName)){
2709+
newFP = fopen(newFileName, "r");
2710+
if (newFP) {
2711+
// logOword("fopen: |%s|", newFileName);
2712+
break; // use first occurrence in dir search
2713+
}
26852714
}
2686-
}
2687-
}
2715+
}
26882716
}
2689-
// if not found, search the wizard tree
2717+
2718+
// #4 if still not found, search the wizard tree
2719+
// Wiz directory already expands the '~' to user path
26902720
if (!newFP) {
2691-
int ret;
2692-
ret = findFile(settings->wizard_root, tmpFileName, foundPlace);
2693-
2694-
if (INTERP_OK == ret) {
2695-
// create the long name
2696-
chk = snprintf(newFileName, sizeof(newFileName), "%s/%s",
2697-
foundPlace, tmpFileName);
2698-
if (chk < sizeof(newFileName)) newFP = fopen(newFileName, "r");
2699-
}
2721+
int ret;
2722+
2723+
// walks the directory hierarchy ?
2724+
ret = findFile(settings->wizard_root, tmpFileName, foundPlace);
2725+
2726+
if (INTERP_OK == ret) {
2727+
// create the long name
2728+
chk = snprintf(newFileName, sizeof(newFileName), "%s/%s",
2729+
foundPlace, tmpFileName);
2730+
2731+
// found a file we can open?
2732+
if (chk < sizeof(newFileName)){
2733+
newFP = fopen(newFileName, "r");
2734+
}
2735+
}
27002736
}
2737+
2738+
// pass what we found
27012739
if (foundhere && (newFP != NULL))
2702-
strcpy(foundhere, newFileName);
2740+
strcpy(foundhere, newFileName);
2741+
2742+
// Not sure this is needed but the internet told me
2743+
wordfree(&exp_result);
27032744
return newFP;
27042745
}
27052746

0 commit comments

Comments
 (0)