@@ -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- # include < wordexp.h >
101+
102102#include " units.h"
103103
104104#include < unordered_set>
@@ -2651,59 +2651,32 @@ 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
26602654FILE *Interp::find_ngc_file (setup_pointer settings,const char *basename, char *foundhere )
26612655{
26622656 FILE *newFP = NULL ;
26632657 char tmpFileName[PATH_MAX+1 ];
26642658 char newFileName[PATH_MAX+1 ];
26652659 char foundPlace[PATH_MAX+1 ];
26662660 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- }
26832661
2684- // #2 then look in the program_prefix place
2685- if (!newFP) {
2662+ // look for a new file
2663+ snprintf (tmpFileName, sizeof (tmpFileName), " %s.ngc " , basename);
26862664
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);
2665+ // find subroutine by search: program_prefix, subroutines, wizard_root
2666+ // use first file found
26902667
2691- // found a file we can open?
2668+ // first look in the program_prefix place
2669+ size_t chk = snprintf (newFileName, sizeof (newFileName), " %s/%s" , settings->program_prefix , tmpFileName);
26922670 if (chk < sizeof (newFileName)){
26932671 newFP = fopen (newFileName, " r" );
26942672 }
26952673
2696- // #3 then look in the list of subroutines prefixes
2674+ // then look in the subroutines place
26972675 if (!newFP) {
26982676 for (dct = 0 ; dct < MAX_SUB_DIRS; dct++) {
26992677 if (!settings->subroutines [dct])
27002678 continue ;
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?
2679+ chk = snprintf (newFileName, sizeof (newFileName), " %s/%s" , settings->subroutines [dct], tmpFileName);
27072680 if (chk < sizeof (newFileName)){
27082681 newFP = fopen (newFileName, " r" );
27092682 if (newFP) {
@@ -2713,31 +2686,20 @@ FILE *Interp::find_ngc_file(setup_pointer settings,const char *basename, char *f
27132686 }
27142687 }
27152688 }
2716-
2717- // #4 if still not found, search the wizard tree
2689+ // if not found, search the wizard tree
27182690 if (!newFP) {
27192691 int ret;
2720- // expand '~' into user path
2721- wordexp (settings->wizard_root , &exp_result, 0 );
2722- ret = findFile (exp_result.we_wordv [0 ], tmpFileName, foundPlace);
2692+ ret = findFile (settings->wizard_root , tmpFileName, foundPlace);
27232693
27242694 if (INTERP_OK == ret) {
27252695 // create the long name
27262696 chk = snprintf (newFileName, sizeof (newFileName), " %s/%s" ,
27272697 foundPlace, tmpFileName);
2728-
2729- // found a file we can open?
2730- if (chk < sizeof (newFileName)){
2731- newFP = fopen (newFileName, " r" );
2732- }
2698+ if (chk < sizeof (newFileName)) newFP = fopen (newFileName, " r" );
27332699 }
27342700 }
2735- }
27362701 if (foundhere && (newFP != NULL ))
27372702 strcpy (foundhere, newFileName);
2738-
2739- // Not sure this is needed but the internet told me
2740- wordfree (&exp_result);
27412703 return newFP;
27422704}
27432705
0 commit comments