From bug-request at octave dot org Wed Apr 5 02:58:12 2006 Subject: Re: autoload From: David Bateman To: "John W. Eaton" CC: Paul Kienzle , "\"\"mailing.list\" \"\"@il06exr03.mot.com" Date: Wed, 05 Apr 2006 09:53:39 +0200 John, I recently wrote an mfilename function in octave-forge that also uses curr_caller_function, though the details are a bit different. I issue I have with this function is that its suppose to identify the "m-file" from which it is caller. Therefore, also for compatiability when you use keyboard or debug_on_error, mfilename is suppose to identify the m-file in which the error or keyboard occurred, not the function error or keyboard, as both yours and my implementation will do. To me is vastly limits the usefullness, as mfilenames primary use is in debugging... D. John W. Eaton wrote: >On 31-Mar-2006, Paul Kienzle wrote: > >| Okay, I agree that 'which' is not an ideal solution. I'm still >| unhappy with the hardcoded full path to the function though. It >| means that I can't move the directories around and have it just work. >| When we eventually put octave into an OS X octave.app, we will >| not be able to rely on a fixed path to the file. >| >| Could we instead rely on the relative path between the script >| containing the autoload command and the oct file we are loading >| from? For example, assuming we had a function 'thisfile' which >| returns the path to the currently running script: >| >| autoload('min', fullfile(fileparts(thisfile()),'max.oct') ) > >OK, how about the following function (which also has the "advantage" >of being needed for compatibility)? With it, you can write the above, >but instead of > > thisfile () > >use > > mfilename ("fullpath") > > >So the only assumption is that the PKG_ADD file that contains the >autoload command and the file named in the autoload command must be >located in the same directory. > >I also fixed the construction of the PKG_ADD files for Octave so that >they use this new method so we can generate the PKG_ADD files just >once, when Octave is compiled. > >| It would be easier to use if the path transformation were >| implicit, and autoload would add the correct path if the given >| path were not anchored at the root: >| >| autoload('min', 'max.oct') > >OK, I suppose you could also make this work given the implementation >of mfilename. Exercise left to the reader. :-) > >jwe > > >src/ChangeLog: > >2006-04-05 John W. Eaton > > * parse.y (Fmfilename): New function. > > >Index: src/parse.y >=================================================================== >RCS file: /cvs/octave/src/parse.y,v >retrieving revision 1.247 >diff -u -r1.247 parse.y >--- src/parse.y 15 Mar 2006 02:51:40 -0000 1.247 >+++ src/parse.y 5 Apr 2006 06:50:12 -0000 > at @ -3584,6 +3584,68 @@ > unwind_protect::run_frame ("source_file"); > } > >+DEFUN (mfilename, args, , >+ "-*- texinfo -*-\n\ >+ at deftypefn {Built-in Function} {} mfilename ()\n\ >+ at deftypefnx {Built-in Function} {} mfilename (@code{\"fullpath\"})\n\ >+ at deftypefnx {Built-in Function} {} mfilename (@code{\"fullpathext\"})\n\ >+Return the name of the currently executing file. At the top-level,\n\ >+return the empty string. Given the argument at code{\"fullpath\"},\n\ >+include the directory part of the file name, but not the extension.\n\ >+Given the argument at code{\"fullpathext\"}, include the directory part\n\ >+of the file name and the extension.\n\ >+ at end deftypfn") >+{ >+ octave_value retval; >+ >+ int nargin = args.length (); >+ >+ if (nargin > 1) >+ { >+ print_usage ("mfilename"); >+ return retval; >+ } >+ >+ std::string arg; >+ >+ if (nargin == 1) >+ { >+ arg = args(0).string_value (); >+ >+ if (error_state) >+ { >+ error ("mfilename: expecting argument to be a character string"); >+ return retval; >+ } >+ } >+ >+ std::string fname; >+ >+ if (curr_caller_function) >+ fname = curr_caller_function->fcn_file_name (); >+ >+ if (arg == "fullpathext") >+ retval = fname; >+ else >+ { >+ size_t pos = fname.rfind ('.'); >+ >+ fname = (pos != NPOS) ? fname.substr (0, pos) : fname; >+ >+ if (arg == "fullpath") >+ retval = fname; >+ else >+ { >+ pos = fname.rfind (file_ops::dir_sep_char); >+ >+ retval = (pos != NPOS) ? fname.substr (pos+1) : fname; >+ } >+ } >+ >+ return retval; >+} >+ >+ > DEFUN (source, args, , > "-*- texinfo -*-\n\ > at deftypefn {Built-in Function} {} source (@var{file})\n\ > > > >------------------------------------------------------------- >Octave is freely available under the terms of the GNU GPL. > >Octave's home on the web: http://www.octave.org >How to fund new projects: http://www.octave.org/funding.html >Subscription information: http://www.octave.org/archive.html >------------------------------------------------------------- > > > > -- David Bateman David dot Bateman at motorola dot com Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 6 72 01 06 33 (Mob) 91193 Gif-Sur-Yvette FRANCE +33 1 69 35 77 01 (Fax) The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------