Mercurial > octave
comparison libinterp/parse-tree/oct-parse.yy @ 27015:4d9e1a832a55
move core of mfilename function to evaluator
* pt-eval.h, pt-eval.cc (tree_evaluator::mfilename): Move innter
workings of mfilename function here from oct-parse.yy.
* interpreter.h, interpreter.cc (interpreter::mfilename): New function.
* oct-parse.yy (Fmfilename): Extract arguments and call
interpreter::mfilename.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 31 Mar 2019 20:50:10 +0000 |
parents | daab1b311a98 |
children | 9b261300a001 |
comparison
equal
deleted
inserted
replaced
27014:daab1b311a98 | 27015:4d9e1a832a55 |
---|---|
5061 | 5061 |
5062 code->call (tw, 0, octave_value_list ()); | 5062 code->call (tw, 0, octave_value_list ()); |
5063 | 5063 |
5064 if (verbose) | 5064 if (verbose) |
5065 octave_stdout << "done." << std::endl; | 5065 octave_stdout << "done." << std::endl; |
5066 } | 5066 } |
5067 } | 5067 } |
5068 | 5068 |
5069 DEFMETHOD (mfilename, interp, args, , | 5069 DEFMETHOD (mfilename, interp, args, , |
5070 doc: /* -*- texinfo -*- | 5070 doc: /* -*- texinfo -*- |
5071 @deftypefn {} {} mfilename () | 5071 @deftypefn {} {} mfilename () |
5083 Given the argument @qcode{"fullpathext"}, include the directory part of | 5083 Given the argument @qcode{"fullpathext"}, include the directory part of |
5084 the filename and the extension. | 5084 the filename and the extension. |
5085 @seealso{inputname, dbstack} | 5085 @seealso{inputname, dbstack} |
5086 @end deftypefn */) | 5086 @end deftypefn */) |
5087 { | 5087 { |
5088 octave_value retval; | |
5089 | |
5090 int nargin = args.length (); | 5088 int nargin = args.length (); |
5091 | 5089 |
5092 if (nargin > 1) | 5090 if (nargin > 1) |
5093 print_usage (); | 5091 print_usage (); |
5094 | 5092 |
5095 std::string arg; | 5093 std::string opt; |
5096 | 5094 |
5097 if (nargin == 1) | 5095 if (nargin == 1) |
5098 arg = args(0).xstring_value ("mfilename: argument must be a string"); | 5096 opt = args(0).xstring_value ("mfilename: option argument must be a string"); |
5099 | 5097 |
5100 std::string fname; | 5098 return octave_value (interp.mfilename (opt)); |
5101 | |
5102 octave::call_stack& cs = interp.get_call_stack (); | |
5103 | |
5104 octave_user_code *fcn = cs.caller_user_code (); | |
5105 | |
5106 if (fcn) | |
5107 { | |
5108 fname = fcn->fcn_file_name (); | |
5109 | |
5110 if (fname.empty ()) | |
5111 fname = fcn->name (); | |
5112 } | |
5113 | |
5114 if (arg == "fullpathext") | |
5115 retval = fname; | |
5116 else | |
5117 { | |
5118 size_t dpos = fname.rfind (octave::sys::file_ops::dir_sep_char ()); | |
5119 size_t epos = fname.rfind ('.'); | |
5120 | |
5121 if (epos <= dpos+1) | |
5122 epos = std::string::npos; | |
5123 | |
5124 fname = (epos != std::string::npos) ? fname.substr (0, epos) : fname; | |
5125 | |
5126 if (arg == "fullpath") | |
5127 retval = fname; | |
5128 else | |
5129 retval = (dpos != std::string::npos) ? fname.substr (dpos+1) : fname; | |
5130 } | |
5131 | |
5132 return retval; | |
5133 } | 5099 } |
5134 | 5100 |
5135 DEFUN (source, args, , | 5101 DEFUN (source, args, , |
5136 doc: /* -*- texinfo -*- | 5102 doc: /* -*- texinfo -*- |
5137 @deftypefn {} {} source (@var{file}) | 5103 @deftypefn {} {} source (@var{file}) |