26#if defined (HAVE_CONFIG_H)
78 const std::string& warn_for,
bool warn)
82 if (! fcn_name.empty ())
84 octave::symbol_table& symtab
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",
123OCTAVE_NAMESPACE_BEGIN
142 if (args.length () != 1)
145 std::string
name = args(0).xstring_value (
"isglobal: NAME must be a string");
147 return ovl (interp.isglobal (
name));
163 const std::string& type =
"any")
168 bool search_any = type ==
"any";
169 bool search_var = type ==
"var";
170 bool search_dir = type ==
"dir";
171 bool search_file = type ==
"file";
172 bool search_builtin = type ==
"builtin";
173 bool search_class = type ==
"class";
175 if (! (search_any || search_var || search_dir || search_file
176 || search_builtin || search_class))
177 error (R
"(exist: unrecognized type argument "%s")", type.c_str ());
179 if (search_any || search_var)
198 if (search_any || search_file || search_dir || search_class)
200 bool have_fcn_ext =
false;
202 std::string xname =
name;
205 std::size_t pos =
name.rfind (
'.');
207 if (pos != std::string::npos)
209 ext =
name.substr (pos+1);
211 if (ext ==
"m" || ext ==
"oct" || ext ==
"mex")
213 xname =
name.substr (0, pos);
218 std::string file_name;
220 if (search_any || search_file || search_class)
227 if (have_fcn_ext && ! file_name.empty ())
230 pos = file_name.rfind (
'.');
232 if (pos != std::string::npos)
234 std::string fext = file_name.substr (pos+1);
241 if (search_any && file_name.empty ())
251 if (! have_fcn_ext && file_name.empty ())
259 if (file_name.empty ())
263 std::size_t
len = file_name.length ();
265 if (
len > 0 && (search_any || search_file || search_class))
267 if (search_any || search_file)
269 if (
len > 4 && (file_name.substr (
len-4) ==
".oct"
270 || file_name.substr (
len-4) ==
".mex"))
289 if (file_name.empty ())
296 sys::file_stat fs (file_name);
300 if (search_any || search_file)
305 len = file_name.length ();
307 if (
len > 4 && (file_name.substr (
len-4) ==
".oct"
308 || file_name.substr (
len-4) ==
".mex"))
313 else if (search_dir && fs.is_dir ())
317 if (search_file || search_dir)
321 if ((search_any || search_builtin)
337#define GET_IDX(LEN) \
338 static_cast<int> (((LEN)-1) * static_cast<double> (rand ()) / RAND_MAX)
343 static const std::string alpha
344 =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
346 static std::size_t
len = alpha.length ();
350 std::size_t pos = nm.length ();
352 if (nm.substr (0, 2) ==
"__")
355 octave::interpreter& interp
437 int nargin = args.length ();
439 if (nargin < 1 || nargin > 2)
444 if (args(0).builtin_type () !=
btyp_unknown && args(0).isempty ())
449 if (nargin == 2 && args(1).builtin_type () !=
btyp_unknown
450 && args(1).isempty ())
453 std::string
name = args(0).xstring_value (
"exist: NAME must be a string");
458 = args(1).xstring_value (
"exist: TYPE must be a string");
552 if (! args(1).is_string () || args(1).string_value () !=
"local")
565 octave::tree_evaluator& tw
568 return tw.curr_fcn_unwind_protect_frame ();
588 int nargout,
const char *nm)
592 int nargin = args.
length ();
594 if (nargout > 0 || nargin == 0)
600 warning (R
"("local" has no effect outside a function)");
608 bool bval = args(0).xbool_value (
"%s: argument must be a logical value", nm);
618 int nargout,
const char *nm)
622 int nargin = args.
length ();
624 if (nargout > 0 || nargin == 0)
630 warning (R
"("local" has no effect outside a function)");
638 std::string sval = args(0).xstring_value (
"%s: argument must be a single character", nm);
640 switch (sval.length ())
651 error (
"%s: argument must be a single character", nm);
661 int nargout,
const char *nm,
662 int minval,
int maxval)
666 int nargin = args.
length ();
668 if (nargout > 0 || nargin == 0)
674 warning (R
"("local" has no effect outside a function)");
682 int ival = args(0).xint_value (
"%s: argument must be an integer value", nm);
685 error (
"%s: arg must be greater than %d", nm, minval);
687 error (
"%s: arg must be less than or equal to %d", nm, maxval);
697 int nargout,
const char *nm,
698 double minval,
double maxval)
702 int nargin = args.
length ();
704 if (nargout > 0 || nargin == 0)
710 warning (R
"("local" has no effect outside a function)");
718 double dval = args(0).xscalar_value (
"%s: argument must be a scalar value", nm);
721 error (
"%s: argument must be greater than %g", nm, minval);
723 error (
"%s: argument must be less than or equal to %g", nm, maxval);
733 int nargout,
const char *nm,
bool empty_ok)
737 int nargin = args.
length ();
739 if (nargout > 0 || nargin == 0)
745 warning (R
"("local" has no effect outside a function)");
753 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
755 if (! empty_ok && sval.empty ())
756 error (
"%s: value must not be empty", nm);
766 int nargout,
const char *nm,
const char **choices)
770 while (choices[nchoices] !=
nullptr)
773 int nargin = args.
length ();
775 assert (var < nchoices);
777 if (nargout > 0 || nargin == 0)
778 retval = choices[var];
783 warning (R
"("local" has no effect outside a function)");
791 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
794 for (; i < nchoices; i++)
796 if (sval == choices[i])
803 error (R
"(%s: value not allowed ("%s"))", nm, sval.c_str ());
811 int nargout,
const char *nm,
const char **choices)
815 while (choices[nchoices] !=
nullptr)
818 int nargin = args.
length ();
820 if (nargout > 0 || nargin == 0)
826 warning (R
"("local" has no effect outside a function)");
834 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
837 for (; i < nchoices; i++)
839 if (sval == choices[i])
846 error (R
"(%s: value not allowed ("%s"))", nm, sval.c_str ());
869 if (args.length () != 0)
888 int nargin = args.length ();
896 = args(0).xstring_value (
"munlock: FCN must be a string");
898 interp.munlock (
name);
901 interp.munlock (
true);
916 int nargin = args.length ();
924 = args(0).xstring_value (
"mislocked: FCN must be a string");
926 return ovl (interp.mislocked (
name));
929 return ovl (interp.mislocked (
true));
936 int argc,
int idx,
bool have_regexp =
false)
940 for (
int k = idx; k < argc; k++)
942 std::string patstr = argv[k];
943 if (! patstr.empty ())
947 if (regexp::is_match (patstr, nm))
957 if (pattern.
match (nm))
973 warning (
"clear: ignoring --exclusive option");
979 bool exclusive =
false)
989 for (
const auto&
name : fcns)
1006 bool exclusive =
false)
1012 for (
const auto&
name : gvars)
1024 for (
const auto&
name : gvars)
1037 std::string pattern = argv[idx++];
1049 bool exclusive =
false,
bool have_regexp =
false)
1059 for (
const auto&
name : lvars)
1081 bool exclusive =
false)
1113 for (; idx < argc; idx++)
1119 else if (argv[idx] ==
"functions"
1124 else if (argv[idx] ==
"global"
1129 else if (argv[idx] ==
"variables"
1134 else if (argv[idx] ==
"classes"
1238 int argc = args.length () + 1;
1254 bool clear_all =
false;
1255 bool clear_functions =
false;
1256 bool clear_globals =
false;
1257 bool clear_variables =
false;
1258 bool clear_objects =
false;
1259 bool exclusive =
false;
1260 bool have_regexp =
false;
1261 bool have_dash_option =
false;
1263 while (++idx < argc)
1265 if (argv[idx] ==
"-all" || argv[idx] ==
"-a")
1267 if (have_dash_option)
1270 have_dash_option =
true;
1273 else if (argv[idx] ==
"-exclusive" || argv[idx] ==
"-x")
1277 else if (argv[idx] ==
"-functions" || argv[idx] ==
"-f")
1279 if (have_dash_option)
1282 have_dash_option =
true;
1283 clear_functions =
true;
1285 else if (argv[idx] ==
"-global" || argv[idx] ==
"-g")
1287 if (have_dash_option)
1290 have_dash_option =
true;
1291 clear_globals =
true;
1293 else if (argv[idx] ==
"-variables" || argv[idx] ==
"-v")
1295 if (have_dash_option)
1298 have_dash_option =
true;
1299 clear_variables =
true;
1301 else if (argv[idx] ==
"-classes" || argv[idx] ==
"-c")
1303 if (have_dash_option)
1306 have_dash_option =
true;
1307 clear_objects =
true;
1309 else if (argv[idx] ==
"-regexp" || argv[idx] ==
"-r")
1311 if (have_dash_option)
1314 have_dash_option =
true;
1323 if (! have_dash_option && ! exclusive)
1332 warning (
"clear: ignoring extra arguments after -all");
1334 interp.clear_all ();
1336 else if (have_regexp)
1340 else if (clear_functions)
1344 else if (clear_globals)
1348 else if (clear_variables)
1352 else if (clear_objects)
1354 interp.clear_objects ();
1356 interp.clear_all ();
1394DEFUN (missing_function_hook, args, nargout,
1409 "missing_function_hook");
1415 octave::interpreter& interp
1422 octave::symbol_table& symtab = interp.get_symbol_table ();
1439 if (tmp.
length () == 1 && tmp(0).is_string ())
1440 return tmp(0).string_value ();
1477 if (args.length () != 1)
1480 std::string
name = args(0).xstring_value (
"__varval__: NAME must be a string");
1483 if (
name ==
".argn.")
1490 return interp.varval (
name);
1495DEFUN (missing_component_hook, args, nargout,
1524 "missing_component_hook");
1533 const std::string& fname,
const std::string& header,
1534 const std::string& trailer)
1540 std::string s = arg.
xstring_value (
"%s: argument must be a string",
1543 std::string cmd = header;
1545 cmd.append (trailer);
1549 octave::interpreter& interp
1552 interp.eval_string (cmd,
true, parse_status, 0);
1554 if (parse_status != 0)
1555 error (
"%s: '%s' is not valid as a function",
1556 warn_for.c_str (), fname.c_str ());
1561 error (
"%s: '%s' is not valid as a function",
1562 warn_for.c_str (), fname.c_str ());
1564 warning (
"%s: passing function body as a string is obsolete; please use anonymous functions",
Provides threadsafe access to octave.
void clear_workspace(void)
bool match(const std::string &str) const
octave_value varval(const std::string &name) const
void clear_variable(const std::string &name)
void clear_variables(void)
load_path & get_load_path(void)
tree_evaluator & get_evaluator(void)
void clear_symbol_pattern(const std::string &pat)
void clear_global_variable(const std::string &name)
void clear_global_variable_pattern(const std::string &pattern)
symbol_table & get_symbol_table(void)
std::list< std::string > global_variable_names(void)
void clear_variable_regexp(const std::string &pattern)
void clear_variable_pattern(const std::string &pattern)
void clear_function_pattern(const std::string &pat)
bool is_local_variable(const std::string &name) const
std::list< std::string > variable_names(void)
void clear_function(const std::string &name)
std::list< std::string > user_function_names(void)
void clear_all(bool force=false)
void clear_functions(bool force=false)
std::string find_fcn(const std::string &fcn, std::string &dir_name, const std::string &pack_name="")
std::string find_method(const std::string &class_name, const std::string &meth, std::string &dir_name, const std::string &pack_name="")
static OCTINTERP_API void clear_exemplar_map(void)
octave_idx_type length(void) const
OCTINTERP_API std::string xstring_value(const char *fmt,...) const
OCTINTERP_API octave_function * function_value(bool silent=false) const
bool is_constant(void) const
bool is_string(void) const
bool is_defined(void) const
bool is_function_handle(void) const
bool is_classdef_meta(void) const
std::string string_value(bool force=false) const
bool is_anonymous_function(void) const
bool isobject(void) const
bool is_inline_function(void) const
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 find_cmdline_function(const std::string &name)
octave_value get_auto_fcn_var(stack_frame::auto_var_type avt) const
std::string lookup_autoload(const std::string &nm) 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,...)
OCTAVE_NAMESPACE_BEGIN bool iskeyword(const std::string &s)
static std::string basename(const std::string &s, bool strip_path=false)
OCTINTERP_API octave_value_list feval(const char *name, const octave_value_list &args=octave_value_list(), int nargout=0)
interpreter & __get_interpreter__(const std::string &who)
tree_evaluator & __get_evaluator__(const std::string &who)
symbol_table & __get_symbol_table__(const std::string &who)
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
bool drive_or_unc_share(const std::string &name)
std::string file_in_path(const std::string &name, const std::string &suffix)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
OCTAVE_NAMESPACE_END 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 void do_clear_symbols(interpreter &interp, const string_vector &argv, int argc, int idx, bool exclusive=false)
static void do_clear_functions(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_variables(interpreter &interp, const string_vector &argv, int argc, int idx, bool exclusive=false, bool have_regexp=false)
static octave::unwind_protect * curr_fcn_unwind_protect_frame(void)
static void do_clear_globals(interpreter &interp, const string_vector &argv, int argc, int idx, bool exclusive=false)
octave_function * is_valid_function(const std::string &fcn_name, const std::string &warn_for, bool warn)
static int symbol_exist(interpreter &interp, const std::string &name, const std::string &type="any")
static void do_matlab_compatible_clear(interpreter &interp, const string_vector &argv, int argc, int idx)
std::string maybe_missing_function_hook(const std::string &name)
std::string unique_symbol_name(const std::string &basename)
static bool wants_local_change(const octave_value_list &args, int &nargin)
static std::string Vmissing_function_hook
static void maybe_warn_exclusive(bool exclusive)
static std::string Vmissing_component_hook