Author Topic: How to get the pathname of foo.e when it is loaded?  (Read 1976 times)

IanG

  • Community Member
  • Posts: 18
  • Hero Points: 0
How to get the pathname of foo.e when it is loaded?
« on: March 15, 2014, 03:38:40 am »
I'm working on a language parser which needs a bunch of supporting files like the lexer (.vlx) and so on. As such, I don't want to put my test code into the directory corresponding to _config_path(), in fact I don't think that's the place to put any development code.

Let's say my macro is in /home/me/dev/slick/foo.e and requires foo.vlx in the same folder. When I use the "Macro" -> "Load Module" menu item, how can I get this to work properly? (i.e., what is _macro_path_or_something() ):

_str my_vlx = _macro_path_or_something() :+ FILESEP :+ LEXER_NAME :+ ".vlx";

I've grepped through the macros folder looking at *_path and path_* but nothing stood out.

Thanks in advance.  -- Ian

Graeme

  • Senior Community Member
  • Posts: 2345
  • Hero Points: 307
Re: How to get the pathname of foo.e when it is loaded?
« Reply #1 on: March 15, 2014, 06:42:43 am »
If you mean what I think you mean then it's not particularly easy.  I wanted to know how to do this for my xretrace macro so that I could open the xretrace.e module in the editor when the user pressed f1 for help after the module was loaded.  In the end I gave up and forced my code to be within a known folder in the config folder.  One possible benefit (or confusion) from that is that when you upgrade to a new version of slickedit but still want to run older versions (like I do) you can have separate .ex files for each version.

Anyway, there's a call_list thing for _on_load_module  - this means that a function that starts with _on_load_module_abc gets called when module abc gets loaded, just before loading.  The problem is, the very first time the module is loaded, the function _on_load_module_abc doesn't yet exist.  To get round that you would need to have another module that gets loaded before abc
e.g. module abc1.e
_str my_abc_module_path;

void _on_load_module_abc(_str module_name)
{
   my_abc_module_path = module_name;
}

////////////////////////////////////////////////////
and in module abc
#import abc1.e
definit()
{
   say(my_abc_module_path);
}

and you can use strip_filename(my_abc_module_path, "N");
to get the path.  And you have to ensure that abc1.e is loaded before abc.e.

The above is mostly untested.

Another way you might consider is that #include somefile looks first in the folder containing the file being loaded, so could arrange to have another file in the same folder that contains a text string specifying the path  e.g.
file abc_path.txt could have
#define MYPATH c:/temp/mymacros
which would be generated by an installer  - or it could be generated by a batch file in the same folder using %0 and was run by the user upon installation.


IanG

  • Community Member
  • Posts: 18
  • Hero Points: 0
Re: How to get the pathname of foo.e when it is loaded?
« Reply #2 on: March 17, 2014, 02:39:07 am »
Grame, thanks for the excellent advice. Your suggestions planted the necessary seeds in my mind.

Since this is a one-time thing and will be user driven, I opted to use a slightly different approach which avoids hardcoding anything but just asks the user to find the file manually if it isn't there. I did run into some problems but they're OT and I will start a new thread.

Regards,  Ian.