Skip to content

Commit f036526

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 edb91db commit f036526

3 files changed

Lines changed: 62 additions & 20 deletions

File tree

src/emc/rs274ngc/interp_o_word.cc

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -546,9 +546,11 @@ int Interp::control_back_to( block_pointer block, // pointer to block
546546
offset_map_iterator it;
547547
offset_pointer op;
548548

549-
logOword("Entered:%s %s", name,block->o_name);
549+
logOword("Entered:%s %s", name,basename(block->o_name));
550550

551-
it = settings->offset_map.find(block->o_name);
551+
it = settings->offset_map.find(basename(block->o_name));
552+
553+
// #1 already defined
552554
if (it != settings->offset_map.end()) {
553555
op = &it->second;
554556
if ((settings->filename[0] != 0) &
@@ -585,6 +587,8 @@ int Interp::control_back_to( block_pointer block, // pointer to block
585587
settings->sequence_number = op->sequence_number;
586588
return INTERP_OK;
587589
}
590+
591+
// #2 open the File
588592
newFP = find_ngc_file(settings, block->o_name, newFileName);
589593

590594
if (newFP) {
@@ -607,8 +611,8 @@ int Interp::control_back_to( block_pointer block, // pointer to block
607611
free(dirname);
608612
}
609613

610-
settings->skipping_o = block->o_name; // start skipping
611-
settings->skipping_to_sub = block->o_name; // start skipping
614+
settings->skipping_o = basename(block->o_name); // start skipping
615+
settings->skipping_to_sub = basename(block->o_name); // start skipping
612616
settings->skipping_start = settings->sequence_number;
613617
return INTERP_OK;
614618
}

src/emc/rs274ngc/interp_remap.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,13 @@ int Interp::parse_remap(const char *inistring, int lineno)
446446
errored = true;
447447
continue;
448448
}
449-
FILE *fp = find_ngc_file(&_setup,arg);
449+
FILE *fp = find_ngc_file(&_setup, arg);
450450
if (fp) {
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+
fprintf(stderr,"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+
fprintf(stderr,"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: 50 additions & 12 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,32 +2651,59 @@ 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
2670+
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]);
2675+
2676+
// copy to newFileName - in case this is the one...
2677+
size_t chk = snprintf(newFileName, sizeof(newFileName), "%s", tmpFileName);
2678+
2679+
// found a file we can open?
2680+
if (chk < sizeof(newFileName)){
2681+
newFP = fopen(newFileName, "r");
2682+
}
26612683

2662-
// look for a new file
2663-
snprintf(tmpFileName, sizeof(tmpFileName), "%s.ngc", basename);
2684+
// #2 then look in the program_prefix place
2685+
if (!newFP) {
26642686

2665-
// find subroutine by search: program_prefix, subroutines, wizard_root
2666-
// use first file found
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);
26672690

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

2674-
// then look in the subroutines place
2696+
// #3 then look in the list of subroutines prefixes
26752697
if (!newFP) {
26762698
for (dct = 0; dct < MAX_SUB_DIRS; dct++) {
26772699
if (!settings->subroutines[dct])
26782700
continue;
2679-
chk = snprintf(newFileName, sizeof(newFileName), "%s/%s", settings->subroutines[dct], tmpFileName);
2701+
2702+
// expand '~' into user path
2703+
wordexp(settings->subroutines[dct], &exp_result, 0);
2704+
chk = snprintf(newFileName, sizeof(newFileName), "%s/%s", exp_result.we_wordv[0], tmpFileName);
2705+
2706+
// found a file we can open?
26802707
if (chk < sizeof(newFileName)){
26812708
newFP = fopen(newFileName, "r");
26822709
if (newFP) {
@@ -2686,20 +2713,31 @@ FILE *Interp::find_ngc_file(setup_pointer settings,const char *basename, char *f
26862713
}
26872714
}
26882715
}
2689-
// if not found, search the wizard tree
2716+
2717+
// #4 if still not found, search the wizard tree
26902718
if (!newFP) {
26912719
int ret;
2692-
ret = findFile(settings->wizard_root, tmpFileName, foundPlace);
2720+
// expand '~' into user path
2721+
wordexp(settings->wizard_root, &exp_result, 0);
2722+
ret = findFile(exp_result.we_wordv[0], tmpFileName, foundPlace);
26932723

26942724
if (INTERP_OK == ret) {
26952725
// create the long name
26962726
chk = snprintf(newFileName, sizeof(newFileName), "%s/%s",
26972727
foundPlace, tmpFileName);
2698-
if (chk < sizeof(newFileName)) newFP = fopen(newFileName, "r");
2728+
2729+
// found a file we can open?
2730+
if (chk < sizeof(newFileName)){
2731+
newFP = fopen(newFileName, "r");
2732+
}
26992733
}
27002734
}
2735+
}
27012736
if (foundhere && (newFP != NULL))
27022737
strcpy(foundhere, newFileName);
2738+
2739+
// Not sure this is needed but the internet told me
2740+
wordfree(&exp_result);
27032741
return newFP;
27042742
}
27052743

0 commit comments

Comments
 (0)