# HG changeset patch # User John W. Eaton # Date 1377715562 14400 # Node ID 091e4df179de26eebea846d52914af051141fae7 # Parent f4772605aec383b3b1125455c66111f3d1693920 new function to help with debugging by parsing .m files without executing them * oct-parse.in.yy (F__parse_file__): New function. diff -r f4772605aec3 -r 091e4df179de libinterp/parse-tree/oct-parse.in.yy --- a/libinterp/parse-tree/oct-parse.in.yy Wed Aug 28 11:07:03 2013 -0700 +++ b/libinterp/parse-tree/oct-parse.in.yy Wed Aug 28 14:46:02 2013 -0400 @@ -4435,3 +4435,54 @@ return retval; } + +DEFUN (__parse_file__, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} __parse_file__ (@var{file}, @var{verbose})\n\ +Undocumented internal function.\n\ +@end deftypefn") +{ + octave_value retval; + + int nargin = args.length (); + + if (nargin == 1 || nargin == 2) + { + std::string file = args(0).string_value (); + + std::string full_file = octave_env::make_absolute (file); + + size_t file_len = file.length (); + + if ((file_len > 4 && file.substr (file_len-4) == ".oct") + || (file_len > 4 && file.substr (file_len-4) == ".mex") + || (file_len > 2 && file.substr (file_len-2) == ".m")) + { + file = octave_env::base_pathname (file); + file = file.substr (0, file.find_last_of ('.')); + + size_t pos = file.find_last_of (file_ops::dir_sep_str ()); + if (pos != std::string::npos) + file = file.substr (pos+1); + } + + if (! error_state) + { + if (nargin == 2) + octave_stdout << "parsing " << full_file << std::endl; + + octave_function *fcn = parse_fcn_file (full_file, file, "", + true, false, false, + false, "__parse_file__"); + + if (fcn) + delete fcn; + } + else + error ("__parse_file__: expecting file name as argument"); + } + else + print_usage (); + + return retval; +}