26 #if defined (HAVE_CONFIG_H)
78 const std::string& warn_for,
bool warn)
82 if (! fcn_name.empty ())
94 error (
"%s: the symbol '%s' is not valid as a function",
95 warn_for.c_str (), fcn_name.c_str ());
102 const std::string& warn_for,
bool warn)
106 std::string fcn_name;
116 error (
"%s: argument must be a string containing function name",
141 if (args.length () != 1)
144 std::string name = args(0).xstring_value (
"isglobal: NAME must be a string");
146 return ovl (interp.isglobal (name));
162 const std::string& type =
"any")
167 bool search_any = type ==
"any";
168 bool search_var = type ==
"var";
169 bool search_dir = type ==
"dir";
170 bool search_file = type ==
"file";
171 bool search_builtin = type ==
"builtin";
172 bool search_class = type ==
"class";
174 if (! (search_any || search_var || search_dir || search_file
175 || search_builtin || search_class))
176 error (R
"(exist: unrecognized type argument "%s")", type.c_str ());
178 if (search_any || search_var)
197 if (search_any || search_file || search_dir || search_class)
199 bool have_fcn_ext =
false;
201 std::string xname = name;
204 std::size_t pos = name.rfind (
'.');
206 if (pos != std::string::npos)
208 ext = name.substr (pos+1);
210 if (ext ==
"m" || ext ==
"oct" || ext ==
"mex")
212 xname = name.substr (0, pos);
217 std::string file_name;
219 if (search_any || search_file || search_class)
226 if (have_fcn_ext && ! file_name.empty ())
229 pos = file_name.rfind (
'.');
231 if (pos != std::string::npos)
233 std::string fext = file_name.substr (pos+1);
240 if (search_any && file_name.empty ())
250 if (! have_fcn_ext && file_name.empty ())
258 if (file_name.empty ())
262 std::size_t
len = file_name.length ();
264 if (
len > 0 && (search_any || search_file || search_class))
266 if (search_any || search_file)
268 if (
len > 4 && (file_name.substr (
len-4) ==
".oct"
269 || file_name.substr (
len-4) ==
".mex"))
288 if (file_name.empty ())
295 sys::file_stat fs (file_name);
299 if (search_any || search_file)
304 len = file_name.length ();
306 if (
len > 4 && (file_name.substr (
len-4) ==
".oct"
307 || file_name.substr (
len-4) ==
".mex"))
312 else if (search_dir && fs.is_dir ())
316 if (search_file || search_dir)
320 if ((search_any || search_builtin)
336 #define GET_IDX(LEN) \
337 static_cast<int> (((LEN)-1) * static_cast<double> (rand ()) / RAND_MAX)
342 static const std::string alpha
343 =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
345 static std::size_t
len = alpha.length ();
349 std::size_t pos = nm.length ();
351 if (nm.substr (0, 2) ==
"__")
435 int nargin = args.length ();
437 if (nargin < 1 || nargin > 2)
442 if (args(0).builtin_type () !=
btyp_unknown && args(0).isempty ())
447 if (nargin == 2 && args(1).builtin_type () !=
btyp_unknown
448 && args(1).isempty ())
451 std::string name = args(0).xstring_value (
"exist: NAME must be a string");
456 = args(1).xstring_value (
"exist: TYPE must be a string");
550 if (! args(1).is_string () || args(1).string_value () !=
"local")
560 static octave::unwind_protect *
565 return tw.curr_fcn_unwind_protect_frame ();
568 template <
typename T>
576 frame->protect_var (var);
585 int nargout,
const char *nm)
589 int nargin = args.
length ();
591 if (nargout > 0 || nargin == 0)
597 warning (R
"("local" has no effect outside a function)");
605 bool bval = args(0).xbool_value (
"%s: argument must be a logical value", nm);
615 int nargout,
const char *nm)
619 int nargin = args.
length ();
621 if (nargout > 0 || nargin == 0)
627 warning (R
"("local" has no effect outside a function)");
635 std::string sval = args(0).xstring_value (
"%s: argument must be a single character", nm);
637 switch (sval.length ())
648 error (
"%s: argument must be a single character", nm);
658 int nargout,
const char *nm,
659 int minval,
int maxval)
663 int nargin = args.
length ();
665 if (nargout > 0 || nargin == 0)
671 warning (R
"("local" has no effect outside a function)");
679 int ival = args(0).xint_value (
"%s: argument must be an integer value", nm);
682 error (
"%s: arg must be greater than %d", nm, minval);
684 error (
"%s: arg must be less than or equal to %d", nm, maxval);
694 int nargout,
const char *nm,
695 double minval,
double maxval)
699 int nargin = args.
length ();
701 if (nargout > 0 || nargin == 0)
707 warning (R
"("local" has no effect outside a function)");
715 double dval = args(0).xscalar_value (
"%s: argument must be a scalar value", nm);
718 error (
"%s: argument must be greater than %g", nm, minval);
720 error (
"%s: argument must be less than or equal to %g", nm, maxval);
730 int nargout,
const char *nm,
bool empty_ok)
734 int nargin = args.
length ();
736 if (nargout > 0 || nargin == 0)
742 warning (R
"("local" has no effect outside a function)");
750 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
752 if (! empty_ok && sval.empty ())
753 error (
"%s: value must not be empty", nm);
763 int nargout,
const char *nm,
const char **choices)
767 while (choices[nchoices] !=
nullptr)
770 int nargin = args.
length ();
774 if (nargout > 0 || nargin == 0)
775 retval = choices[var];
780 warning (R
"("local" has no effect outside a function)");
788 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
791 for (; i < nchoices; i++)
793 if (sval == choices[i])
800 error (R
"(%s: value not allowed ("%s"))", nm, sval.c_str ());
808 int nargout,
const char *nm,
const char **choices)
812 while (choices[nchoices] !=
nullptr)
815 int nargin = args.
length ();
817 if (nargout > 0 || nargin == 0)
823 warning (R
"("local" has no effect outside a function)");
831 std::string sval = args(0).xstring_value (
"%s: first argument must be a string", nm);
834 for (; i < nchoices; i++)
836 if (sval == choices[i])
843 error (R
"(%s: value not allowed ("%s"))", nm, sval.c_str ());
866 if (args.length () != 0)
885 int nargin = args.length ();
893 = args(0).xstring_value (
"munlock: FCN must be a string");
895 interp.munlock (name);
898 interp.munlock (
true);
913 int nargin = args.length ();
921 = args(0).xstring_value (
"mislocked: FCN must be a string");
923 return ovl (interp.mislocked (name));
926 return ovl (interp.mislocked (
true));
933 int argc,
int idx,
bool have_regexp =
false)
937 for (
int k = idx; k < argc; k++)
939 std::string patstr = argv[k];
940 if (! patstr.empty ())
954 if (pattern.
match (nm))
970 warning (
"clear: ignoring --exclusive option");
976 bool exclusive =
false)
986 for (
const auto& name : fcns)
1003 bool exclusive =
false)
1009 for (
const auto& name : gvars)
1021 for (
const auto& name : gvars)
1034 std::string pattern = argv[idx++];
1046 bool exclusive =
false,
bool have_regexp =
false)
1056 for (
const auto& name : lvars)
1078 bool exclusive =
false)
1110 for (; idx < argc; idx++)
1116 else if (argv[idx] ==
"functions"
1121 else if (argv[idx] ==
"global"
1126 else if (argv[idx] ==
"variables"
1131 else if (argv[idx] ==
"classes"
1235 int argc = args.length () + 1;
1251 bool clear_all =
false;
1252 bool clear_functions =
false;
1253 bool clear_globals =
false;
1254 bool clear_variables =
false;
1255 bool clear_objects =
false;
1256 bool exclusive =
false;
1257 bool have_regexp =
false;
1258 bool have_dash_option =
false;
1260 while (++idx < argc)
1262 if (argv[idx] ==
"-all" || argv[idx] ==
"-a")
1264 if (have_dash_option)
1267 have_dash_option =
true;
1270 else if (argv[idx] ==
"-exclusive" || argv[idx] ==
"-x")
1274 else if (argv[idx] ==
"-functions" || argv[idx] ==
"-f")
1276 if (have_dash_option)
1279 have_dash_option =
true;
1280 clear_functions =
true;
1282 else if (argv[idx] ==
"-global" || argv[idx] ==
"-g")
1284 if (have_dash_option)
1287 have_dash_option =
true;
1288 clear_globals =
true;
1290 else if (argv[idx] ==
"-variables" || argv[idx] ==
"-v")
1292 if (have_dash_option)
1295 have_dash_option =
true;
1296 clear_variables =
true;
1298 else if (argv[idx] ==
"-classes" || argv[idx] ==
"-c")
1300 if (have_dash_option)
1303 have_dash_option =
true;
1304 clear_objects =
true;
1306 else if (argv[idx] ==
"-regexp" || argv[idx] ==
"-r")
1308 if (have_dash_option)
1311 have_dash_option =
true;
1320 if (! have_dash_option && ! exclusive)
1329 warning (
"clear: ignoring extra arguments after -all");
1331 interp.clear_all ();
1333 else if (have_regexp)
1337 else if (clear_functions)
1341 else if (clear_globals)
1345 else if (clear_variables)
1349 else if (clear_objects)
1351 interp.clear_objects ();
1353 interp.clear_all ();
1391 DEFUN (missing_function_hook, args, nargout,
1406 "missing_function_hook");
1418 octave::symbol_table& symtab = interp.get_symbol_table ();
1425 octave::unwind_protect_var<std::string>
1435 if (tmp.
length () == 1 && tmp(0).is_string ())
1436 return tmp(0).string_value ();
1473 if (args.length () != 1)
1476 std::string name = args(0).xstring_value (
"__varval__: NAME must be a string");
1479 if (name ==
".argn.")
1486 return interp.varval (name);
1491 DEFUN (missing_component_hook, args, nargout,
1520 "missing_component_hook");
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)
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)
std::list< std::string > global_variable_names(void)
void clear_variable_regexp(const std::string &pattern)
symbol_table & get_symbol_table(void)
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)
load_path & get_load_path(void)
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 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_match(const std::string &buffer) 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
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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,...)
void error_unless(bool cond)
interpreter & __get_interpreter__(void)
symbol_table & __get_symbol_table__(void)
tree_evaluator & __get_evaluator__(void)
bool iskeyword(const std::string &s)
static std::string basename(const std::string &s, bool strip_path=false)
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.
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)
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)
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)
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 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