26 #if defined (HAVE_CONFIG_H)
78 const std::string& warn_for,
bool warn)
82 if (! fcn_name.empty ())
95 error (
"%s: the symbol '%s' is not valid as a function",
96 warn_for.c_str (), fcn_name.c_str ());
103 const std::string& warn_for,
bool warn)
107 std::string fcn_name;
117 error (
"%s: argument must be a string containing function name",
125 const std::string& fname,
const std::string& header,
126 const std::string& trailer)
132 std::string s = arg.
xstring_value (
"%s: argument must be a string",
135 std::string cmd = header;
137 cmd.append (trailer);
146 if (parse_status != 0)
147 error (
"%s: '%s' is not valid as a function",
148 warn_for.c_str (), fname.c_str ());
153 error (
"%s: '%s' is not valid as a function",
154 warn_for.c_str (), fname.c_str ());
156 warning (
"%s: passing function body as a string is obsolete; please use anonymous functions",
180 if (args.length () != 1)
183 std::string
name = args(0).xstring_value (
"isglobal: NAME must be a string");
185 return ovl (interp.isglobal (
name));
201 const std::string&
type =
"any")
206 bool search_any =
type ==
"any";
207 bool search_var =
type ==
"var";
208 bool search_dir =
type ==
"dir";
209 bool search_file =
type ==
"file";
210 bool search_builtin =
type ==
"builtin";
211 bool search_class =
type ==
"class";
213 if (! (search_any || search_var || search_dir || search_file
214 || search_builtin || search_class))
215 error (R
"(exist: unrecognized type argument "%s")", type.c_str ());
219 if (search_any || search_var)
236 if (search_any || search_file || search_dir)
238 bool have_fcn_ext =
false;
240 std::string xname =
name;
243 size_t pos =
name.rfind (
'.');
245 if (pos != std::string::npos)
247 ext =
name.substr (pos+1);
249 if (ext ==
"m" || ext ==
"oct" || ext ==
"mex")
251 xname =
name.substr (0, pos);
256 std::string file_name;
258 if (search_any || search_file)
265 if (have_fcn_ext && ! file_name.empty ())
267 pos = file_name.rfind (
'.');
269 if (pos != std::string::npos)
271 std::string fext = file_name.substr (pos+1);
278 if (search_any && file_name.empty ())
289 if (! have_fcn_ext && file_name.empty ())
298 if (file_name.empty ())
302 size_t len = file_name.length ();
306 if (search_any || search_file)
308 if (
len > 4 && (file_name.substr (
len-4) ==
".oct"
309 || file_name.substr (
len-4) ==
".mex"))
318 if (file_name.empty ())
329 if (search_any || search_file)
334 len = file_name.length ();
336 if (
len > 4 && (file_name.substr (
len-4) ==
".oct"
337 || file_name.substr (
len-4) ==
".mex"))
342 else if (search_dir && fs.
is_dir ())
346 if (search_file || search_dir)
350 if ((search_any || search_builtin)
366 #define GET_IDX(LEN) \
367 static_cast<int> (((LEN)-1) * static_cast<double> (rand ()) / RAND_MAX)
372 static const std::string alpha
373 =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
375 static size_t len = alpha.length ();
379 size_t pos = nm.length ();
381 if (nm.substr (0, 2) ==
"__")
467 int nargin = args.length ();
469 if (nargin < 1 || nargin > 2)
472 std::string
name = args(0).xstring_value (
"exist: NAME must be a string");
476 std::string
type = args(1).xstring_value (
"exist: TYPE must be a string");
479 warning (R
"(exist: "class" type argument is not implemented)");
573 if (! args(1).is_string () || args(1).string_value () !=
"local")
592 template <
typename T>
609 int nargout,
const char *nm)
613 int nargin = args.
length ();
615 if (nargout > 0 || nargin == 0)
621 warning (R
"("local" has no effect outside a function)");
629 bool bval = args(0).xbool_value (
"%s: argument must be a logical value", nm);
639 int nargout,
const char *nm)
643 int nargin = args.
length ();
645 if (nargout > 0 || nargin == 0)
651 warning (R
"("local" has no effect outside a function)");
659 std::string sval = args(0).xstring_value (
"%s: argument must be a single character", nm);
661 switch (sval.length ())
672 error (
"%s: argument must be a single character", nm);
682 int nargout,
const char *nm,
683 int minval,
int maxval)
687 int nargin = args.
length ();
689 if (nargout > 0 || nargin == 0)
695 warning (R
"("local" has no effect outside a function)");
703 int ival = args(0).xint_value (
"%s: argument must be an integer value", nm);
706 error (
"%s: arg must be greater than %d", nm, minval);
708 error (
"%s: arg must be less than or equal to %d", nm, maxval);
718 int nargout,
const char *nm,
719 double minval,
double maxval)
723 int nargin = args.
length ();
725 if (nargout > 0 || nargin == 0)
731 warning (R
"("local" has no effect outside a function)");
739 double dval = args(0).xscalar_value (
"%s: argument must be a scalar value", nm);
742 error (
"%s: argument must be greater than %g", nm, minval);
744 error (
"%s: argument must be less than or equal to %g", nm, maxval);
754 int nargout,
const char *nm,
bool empty_ok)
758 int nargin = args.
length ();
760 if (nargout > 0 || nargin == 0)
766 warning (R
"("local" has no effect outside a function)");
774 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
776 if (! empty_ok && sval.empty ())
777 error (
"%s: value must not be empty", nm);
787 int nargout,
const char *nm,
const char **choices)
791 while (choices[nchoices] !=
nullptr)
794 int nargin = args.
length ();
796 assert (var < nchoices);
798 if (nargout > 0 || nargin == 0)
804 warning (R
"("local" has no effect outside a function)");
812 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
815 for (; i < nchoices; i++)
817 if (sval == choices[i])
824 error (R
"(%s: value not allowed ("%s"))", nm, sval.c_str ());
832 int nargout,
const char *nm,
const char **choices)
836 while (choices[nchoices] !=
nullptr)
839 int nargin = args.
length ();
841 if (nargout > 0 || nargin == 0)
847 warning (R
"("local" has no effect outside a function)");
855 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
858 for (; i < nchoices; i++)
860 if (sval == choices[i])
867 error (R
"(%s: value not allowed ("%s"))", nm, sval.c_str ());
890 if (args.length () != 0)
909 int nargin = args.length ();
917 = args(0).xstring_value (
"munlock: FCN must be a string");
919 interp.munlock (
name);
922 interp.munlock (
true);
937 int nargin = args.length ();
945 = args(0).xstring_value (
"mislocked: FCN must be a string");
947 return ovl (interp.mislocked (
name));
950 return ovl (interp.mislocked (
true));
957 int argc,
int idx,
bool have_regexp =
false)
961 for (
int k = idx; k < argc; k++)
963 std::string patstr = argv[k];
964 if (! patstr.empty ())
978 if (pattern.
match (nm))
994 warning (
"clear: ignoring --exclusive option");
1000 bool exclusive =
false)
1010 for (
const auto&
name : fcns)
1027 bool exclusive =
false)
1033 for (
const auto&
name : gvars)
1045 for (
const auto&
name : gvars)
1058 std::string pattern = argv[idx++];
1070 bool exclusive =
false,
bool have_regexp =
false)
1080 for (
const auto&
name : lvars)
1102 bool exclusive =
false)
1134 for (; idx < argc; idx++)
1140 else if (argv[idx] ==
"functions"
1145 else if (argv[idx] ==
"global"
1150 else if (argv[idx] ==
"variables"
1155 else if (argv[idx] ==
"classes"
1259 int argc = args.length () + 1;
1275 bool clear_all =
false;
1276 bool clear_functions =
false;
1277 bool clear_globals =
false;
1278 bool clear_variables =
false;
1279 bool clear_objects =
false;
1280 bool exclusive =
false;
1281 bool have_regexp =
false;
1282 bool have_dash_option =
false;
1284 while (++idx < argc)
1286 if (argv[idx] ==
"-all" || argv[idx] ==
"-a")
1288 if (have_dash_option)
1291 have_dash_option =
true;
1294 else if (argv[idx] ==
"-exclusive" || argv[idx] ==
"-x")
1298 else if (argv[idx] ==
"-functions" || argv[idx] ==
"-f")
1300 if (have_dash_option)
1303 have_dash_option =
true;
1304 clear_functions =
true;
1306 else if (argv[idx] ==
"-global" || argv[idx] ==
"-g")
1308 if (have_dash_option)
1311 have_dash_option =
true;
1312 clear_globals =
true;
1314 else if (argv[idx] ==
"-variables" || argv[idx] ==
"-v")
1316 if (have_dash_option)
1319 have_dash_option =
true;
1320 clear_variables =
true;
1322 else if (argv[idx] ==
"-classes" || argv[idx] ==
"-c")
1324 if (have_dash_option)
1327 have_dash_option =
true;
1328 clear_objects =
true;
1330 else if (argv[idx] ==
"-regexp" || argv[idx] ==
"-r")
1332 if (have_dash_option)
1335 have_dash_option =
true;
1344 if (! have_dash_option && ! exclusive)
1353 warning (
"clear: ignoring extra arguments after -all");
1355 interp.clear_all ();
1357 else if (have_regexp)
1361 else if (clear_functions)
1365 else if (clear_globals)
1369 else if (clear_variables)
1373 else if (clear_objects)
1375 interp.clear_objects ();
1377 interp.clear_all ();
1415 DEFUN (missing_function_hook, args, nargout,
1459 if (tmp.
length () == 1 && tmp(0).is_string ())
1460 return tmp(0).string_value ();
1472 if (args.length () != 1)
1475 std::string
name = args(0).xstring_value (
"__varval__: first argument must be a variable name");
1477 std::string nm = args(0).string_value ();
1488 return interp.varval (nm);
1493 DEFUN (missing_component_hook, args, nargout,
1535 while ((pos =
text.find (
'.', pos)) != std::string::npos)
1547 for (
int i = 0; i <
n; i++)
1551 if (
len != std::string::npos)
1556 if (
len != std::string::npos)
bool match(const std::string &str) const
Provides threadsafe access to octave.
void clear_workspace(void)
octave_value varval(const std::string &name) const
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
void clear_variables(void)
std::list< std::string > user_function_names(void)
std::list< std::string > variable_names(void)
void clear_function(const std::string &name)
bool is_local_variable(const std::string &name) const
void clear_function_pattern(const std::string &pat)
void clear_global_variable(const std::string &name)
void clear_global_variable_pattern(const std::string &pattern)
void clear_functions(bool force=false)
void clear_variable_pattern(const std::string &pattern)
load_path & get_load_path(void)
void clear_variable(const std::string &name)
symbol_table & get_symbol_table(void)
void clear_all(bool force=false)
void clear_variable_regexp(const std::string &pattern)
void clear_symbol_pattern(const std::string &pat)
std::list< std::string > global_variable_names(void)
tree_evaluator & get_evaluator(void)
std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
std::string find_fcn(const std::string &fcn, std::string &dir_name, const std::string &pack_name="")
bool is_match(const std::string &buffer)
octave_value find_cmdline_function(const std::string &name)
bool is_built_in_function_name(const std::string &name)
octave_value find_function(const std::string &name, const symbol_scope &search_scope=symbol_scope())
octave_value get_auto_fcn_var(stack_frame::auto_var_type avt) const
std::string lookup_autoload(const std::string &nm) const
unwind_protect * curr_fcn_unwind_protect_frame(void)
static void clear_exemplar_map(void)
octave_idx_type length(void) const
bool is_constant(void) const
bool is_string(void) const
bool is_defined(void) const
bool is_function_handle(void) const
octave_function * function_value(bool silent=false) const
std::string string_value(bool force=false) const
bool is_anonymous_function(void) const
bool isobject(void) const
std::string xstring_value(const char *fmt,...) const
bool is_inline_function(void) const
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void warning(const char *fmt,...)
void error_with_cfn(const char *fmt,...)
void error(const char *fmt,...)
static std::string basename(const std::string &s, bool strip_path=false)
bool drive_or_unc_share(const std::string &name)
interpreter & __get_interpreter__(const std::string &who)
bool iskeyword(const std::string &s)
tree_evaluator & __get_evaluator__(const std::string &who)
octave_value_list feval(const char *name, const octave_value_list &args, int nargout)
Evaluate an Octave function (built-in or interpreted) and return the list of result values.
std::string file_in_path(const std::string &name, const std::string &suffix)
symbol_table & __get_symbol_table__(const std::string &who)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
static void do_matlab_compatible_clear(octave::interpreter &interp, const string_vector &argv, int argc, int idx)
static void do_clear_globals(octave::interpreter &interp, const string_vector &argv, int argc, int idx, bool exclusive=false)
static bool try_local_protect(T &var)
static bool name_matches_any_pattern(const std::string &nm, const string_vector &argv, int argc, int idx, bool have_regexp=false)
static void do_clear_functions(octave::interpreter &interp, const string_vector &argv, int argc, int idx, bool exclusive=false)
static void do_clear_symbols(octave::interpreter &interp, const string_vector &argv, int argc, int idx, bool exclusive=false)
octave_function * extract_function(const octave_value &arg, const std::string &warn_for, const std::string &fname, const std::string &header, const std::string &trailer)
static octave::unwind_protect * curr_fcn_unwind_protect_frame(void)
string_vector get_struct_elts(const std::string &text)
std::string maybe_missing_function_hook(const std::string &name)
octave_function * is_valid_function(const std::string &fcn_name, const std::string &warn_for, bool warn)
std::string unique_symbol_name(const std::string &basename)
static void do_clear_variables(octave::interpreter &interp, const string_vector &argv, int argc, int idx, bool exclusive=false, bool have_regexp=false)
static bool wants_local_change(const octave_value_list &args, int &nargin)
static int symbol_exist(octave::interpreter &interp, const std::string &name, const std::string &type="any")
static std::string Vmissing_function_hook
static void maybe_warn_exclusive(bool exclusive)
static std::string Vmissing_component_hook
#define SET_INTERNAL_VARIABLE(NM)