68 =
" %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\n";
100 const std::string& warn_for,
bool warn)
104 if (! fcn_name.empty ())
113 error (
"%s: the symbol '%s' is not valid as a function",
114 warn_for.c_str (), fcn_name.c_str ());
121 const std::string& warn_for,
bool warn)
125 std::string fcn_name;
134 error (
"%s: expecting function name as argument", warn_for.c_str ());
141 const std::string& fname,
const std::string& header,
142 const std::string& trailer)
154 std::string cmd = header;
156 cmd.append (trailer);
162 if (parse_status == 0)
168 error (
"%s: '%s' is not valid as a function",
169 warn_for.c_str (), fname.c_str ());
173 warning (
"%s: passing function body as a string is obsolete; please use anonymous functions",
177 error (
"%s: '%s' is not valid as a function",
178 warn_for.c_str (), fname.c_str ());
181 error (
"%s: expecting first argument to be a string",
195 size_t len = text.
length ();
197 while ((pos = text.find (
'.', pos)) != std::string::npos)
209 for (
int i = 0; i < n; i++)
211 len = text.find (
'.', pos);
213 if (len != std::string::npos)
216 retval[i] = text.substr (pos, len);
218 if (len != std::string::npos)
242 std::string& prefix, std::string& hint)
246 size_t pos = text.rfind (
'.');
248 if (pos != std::string::npos)
250 if (pos == text.length ())
253 hint = text.substr (pos+1);
255 prefix = text.substr (0, pos);
257 std::string base_name = prefix;
259 pos = base_name.find_first_of (
"{(.");
261 if (pos != std::string::npos)
262 base_name = base_name.substr (0, pos);
297 bool retval = (! text.empty ()
300 && text.find (
"..") == std::string::npos
301 && text.rfind (
'.') != std::string::npos);
304 symbol_record *sr = curr_sym_tab->lookup (text);
306 if (sr && ! sr->is_function ())
333 int nargin = args.
length ();
341 if (! args(0).is_string ())
343 error (
"isglobal: NAME must be a string");
347 std::string name = args(0).string_value ();
352 DEFUN (isglobal, args, ,
354 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\
355 Return true if @var{name} is a globally visible variable.\n\
366 @seealso{isvarname, exist}\n\
393 bool search_any = type ==
"any";
394 bool search_var = type ==
"var";
395 bool search_dir = type ==
"dir";
396 bool search_file = type ==
"file";
397 bool search_builtin = type ==
"builtin";
399 if (search_any || search_var)
418 if (search_any || search_builtin)
433 if (search_any || search_file || search_dir)
437 if (file_name.empty ())
440 size_t len = file_name.length ();
444 if (search_any || search_file)
446 if (len > 4 && (file_name.substr (len-4) ==
".oct"
447 || file_name.substr (len-4) ==
".mex"))
456 if (file_name.empty ())
463 if (search_any || search_file)
468 len = file_name.length ();
470 if (len > 4 && (file_name.substr (len-4) ==
".oct"
471 || file_name.substr (len-4) ==
".mex"))
476 else if (search_dir && fs.
is_dir ())
480 if (search_file || search_dir)
491 #define GET_IDX(LEN) \
492 static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX)
497 static const std::string alpha
498 =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
500 static size_t len = alpha.length ();
502 std::string nm = basename + alpha[
GET_IDX (len)];
504 size_t pos = nm.length ();
506 if (nm.substr (0, 2) ==
"__")
510 nm.insert (pos++, 1, alpha[
GET_IDX (len)]);
515 DEFUN (exist, args, ,
517 @deftypefn {Built-in Function} {@var{c} =} exist (@var{name})\n\
518 @deftypefnx {Built-in Function} {@var{c} =} exist (@var{name}, @var{type})\n\
519 Check for the existence of @var{name} as a variable, function, file,\n\
520 directory, or class.\n\
522 The return code @var{c} is one of\n\
526 @var{name} is a variable.\n\
529 @var{name} is an absolute file name, an ordinary file in Octave's\n\
530 @code{path}, or (after appending @samp{.m}) a function file in Octave's\n\
534 @var{name} is a @samp{.oct} or @samp{.mex} file in Octave's @code{path}.\n\
537 @var{name} is a built-in function.\n\
540 @var{name} is a directory.\n\
543 @var{name} is a function not associated with a file (entered on the command\n\
547 @var{name} does not exist.\n\
550 If the optional argument @var{type} is supplied, check only for symbols of\n\
551 the specified type. Valid types are\n\
554 @item @qcode{\"var\"}\n\
555 Check only for variables.\n\
557 @item @qcode{\"builtin\"}\n\
558 Check only for built-in functions.\n\
560 @item @qcode{\"dir\"}\n\
561 Check only for directories.\n\
563 @item @qcode{\"file\"}\n\
564 Check only for files and directories.\n\
566 @item @qcode{\"class\"}\n\
567 Check only for classes. (Note: This option is accepted, but not currently\n\
571 If no type is given, and there are multiple possible matches for name,\n\
572 @code{exist} will return a code according to the following priority list:\n\
573 variable, built-in function, oct-file, directory, file, class.\n\
575 @code{exist} returns 2 if a regular file called @var{name} is present in\n\
576 Octave's search path. If you want information about other types of files\n\
577 not on the search path you should use some combination of the functions\n\
578 @code{file_in_path} and @code{stat} instead.\n\
580 @seealso{file_in_loadpath, file_in_path, dir_in_loadpath, stat}\n\
585 int nargin = args.
length ();
587 if (nargin == 1 || nargin == 2)
589 if (args(0).is_string ())
591 std::string name = args(0).string_value ();
595 if (args(1).is_string ())
597 std::string
type = args(1).string_value ();
600 warning (
"exist: \"class\" type argument is not implemented");
605 error (
"exist: TYPE must be a string");
611 error (
"exist: NAME must be a string");
702 error (
"get_global_value: undefined symbol '%s'", nm.c_str ());
719 error (
"get_top_level_value: undefined symbol '%s'", nm.c_str ());
739 if (args(1).is_string () && args(1).string_value () ==
"local")
760 curr_usr_fcn = dynamic_cast<octave_user_function *> (curr_usr_code);
770 int nargout,
const char *nm)
774 int nargin = args.
length ();
776 if (nargout > 0 || nargin == 0)
782 warning (
"\"local\" has no effect outside a function");
787 bool bval = args(0).bool_value ();
792 error (
"%s: expecting arg to be a logical value", nm);
802 int nargout,
const char *nm)
806 int nargin = args.
length ();
808 if (nargout > 0 || nargin == 0)
814 warning (
"\"local\" has no effect outside a function");
819 std::string sval = args(0).string_value ();
823 switch (sval.length ())
834 error (
"%s: argument must be a single character", nm);
839 error (
"%s: argument must be a single character", nm);
849 int nargout,
const char *nm,
850 int minval,
int maxval)
854 int nargin = args.
length ();
856 if (nargout > 0 || nargin == 0)
862 warning (
"\"local\" has no effect outside a function");
867 int ival = args(0).int_value ();
872 error (
"%s: expecting arg to be greater than %d", nm, minval);
873 else if (ival > maxval)
874 error (
"%s: expecting arg to be less than or equal to %d",
880 error (
"%s: expecting arg to be an integer value", nm);
890 int nargout,
const char *nm,
891 double minval,
double maxval)
895 int nargin = args.
length ();
897 if (nargout > 0 || nargin == 0)
903 warning (
"\"local\" has no effect outside a function");
908 double dval = args(0).scalar_value ();
913 error (
"%s: expecting arg to be greater than %g", minval);
914 else if (dval > maxval)
915 error (
"%s: expecting arg to be less than or equal to %g", maxval);
920 error (
"%s: expecting arg to be a scalar value", nm);
930 int nargout,
const char *nm,
bool empty_ok)
934 int nargin = args.
length ();
936 if (nargout > 0 || nargin == 0)
942 warning (
"\"local\" has no effect outside a function");
947 if (args(0).is_string ())
949 std::string sval = args(0).string_value ();
951 if (empty_ok || ! sval.empty ())
954 error (
"%s: value must not be empty", nm);
957 error (
"%s: first argument must be a string", nm);
967 int nargout,
const char *nm,
const char **choices)
971 while (choices[nchoices] != 0)
974 int nargin = args.
length ();
975 assert (var < nchoices);
977 if (nargout > 0 || nargin == 0)
978 retval = choices[var];
983 warning (
"\"local\" has no effect outside a function");
988 if (args(0).is_string ())
990 std::string sval = args(0).string_value ();
993 for (; i < nchoices; i++)
995 if (sval == choices[i])
1002 error (
"%s: value not allowed (\"%s\")", nm, sval.c_str ());
1005 error (
"%s: first argument must be a string", nm);
1007 else if (nargin > 1)
1029 std::list<whos_parameter>::iterator i = params.begin ();
1030 std::ostringstream param_buf;
1034 while (i != params.end ())
1051 os << std::setiosflags (std::ios::right)
1053 param_buf << std::setiosflags (std::ios::right)
1081 a = (a < 0 ? 0 : a);
1083 b = (b < 0 ? 0 : b);
1087 << std::setw (b) <<
""
1094 << std::setw (b) <<
""
1101 param_buf << param.
line;
1104 << std::resetiosflags (std::ios::right);
1106 << std::resetiosflags (std::ios::right);
1112 param_buf << param.
line;
1117 os << param_buf.str ();
1148 const std::string& expr_str = std::string (),
1150 : name (expr_str.empty () ? sr.name () : expr_str),
1151 varval (expr_val.is_undefined () ? sr.varval () : expr_val),
1152 is_automatic (sr.is_automatic ()),
1153 is_complex (varval.is_complex_type ()),
1154 is_formal (sr.is_formal ()),
1155 is_global (sr.is_global ()),
1156 is_persistent (sr.is_persistent ())
1160 const std::list<whos_parameter>& params)
const
1164 std::list<whos_parameter>::const_iterator i = params.begin ();
1168 while (i != params.end ())
1184 os << std::setiosflags (std::ios::right)
1192 - dims_str.find (
'x');
1194 - dims_str.length ()
1196 front = (front > 0) ? front : 0;
1197 back = (back > 0) ? back : 0;
1200 << std::setw (front)
1217 error (
"whos_line_format: modifier '%c' unknown",
1220 os << std::setiosflags (std::ios::right)
1230 tmp[0] = (is_automatic ?
'a' :
' ');
1231 tmp[1] = (is_complex ?
'c' :
' ');
1232 tmp[2] = (is_formal ?
'f' :
' ');
1233 tmp[3] = (is_global ?
'g' :
' ');
1234 tmp[4] = (is_persistent ?
'p' :
' ');
1242 os << varval.byte_size ();
1246 os << varval.class_name ();
1250 os << varval.capacity ();
1263 os << varval.type_name ();
1267 error (
"whos_line_format: command '%c' unknown",
1272 << std::resetiosflags (std::ios::right);
1313 const std::string& expr_str,
1316 lst.push_back (
symbol_info (sr, expr_str, expr_val));
1319 size_t size (
void)
const {
return lst.size (); }
1321 bool empty (
void)
const {
return lst.empty (); }
1324 map_value (
const std::string& caller_function_name,
int nesting_level)
const
1326 size_t len = lst.size ();
1328 Cell name_info (len, 1);
1329 Cell size_info (len, 1);
1330 Cell bytes_info (len, 1);
1331 Cell class_info (len, 1);
1332 Cell global_info (len, 1);
1333 Cell sparse_info (len, 1);
1334 Cell complex_info (len, 1);
1335 Cell nesting_info (len, 1);
1336 Cell persistent_info (len, 1);
1338 std::list<symbol_info>::const_iterator p = lst.begin ();
1340 for (
size_t j = 0; j < len; j++)
1346 ni.
assign (
"function", caller_function_name);
1347 ni.
assign (
"level", nesting_level);
1349 name_info(j) = si.
name;
1355 size_info(j) = val.
size ();
1360 nesting_info(j) = ni;
1365 info.
assign (
"name", name_info);
1366 info.
assign (
"size", size_info);
1367 info.
assign (
"bytes", bytes_info);
1368 info.
assign (
"class", class_info);
1369 info.
assign (
"global", global_info);
1370 info.
assign (
"sparse", sparse_info);
1371 info.
assign (
"complex", complex_info);
1372 info.
assign (
"nesting", nesting_info);
1373 info.
assign (
"persistent", persistent_info);
1383 size_t elements = 0;
1385 std::list<whos_parameter> params = parse_whos_line_format ();
1391 for (std::list<symbol_info>::const_iterator p = lst.begin ();
1392 p != lst.end (); p++)
1394 p->display_line (os, params);
1402 os <<
"\nTotal is " << elements
1403 << (elements == 1 ?
" element" :
" elements")
1404 <<
" using " << bytes << (bytes == 1 ?
" byte" :
" bytes")
1417 std::list<whos_parameter> params;
1422 std::string param_string =
"abcenst";
1425 size_t pos_a, pos_b, pos_c, pos_e, pos_n, pos_s, pos_t;
1427 pos_a = param_string.find (
'a');
1428 pos_b = param_string.find (
'b');
1429 pos_c = param_string.find (
'c');
1430 pos_e = param_string.find (
'e');
1431 pos_n = param_string.find (
'n');
1432 pos_s = param_string.find (
's');
1433 pos_t = param_string.find (
't');
1435 param_names(pos_a) =
"Attr";
1436 param_names(pos_b) =
"Bytes";
1437 param_names(pos_c) =
"Class";
1438 param_names(pos_e) =
"Elements";
1439 param_names(pos_n) =
"Name";
1440 param_names(pos_s) =
"Size";
1441 param_names(pos_t) =
"Type";
1443 for (
size_t i = 0; i < param_string.length (); i++)
1444 param_length(i) = param_names(i).
length ();
1447 param_length(pos_a) = 5;
1452 for (std::list<symbol_info>::const_iterator p = lst.begin ();
1453 p != lst.end (); p++)
1455 std::stringstream ss1, ss2;
1459 param_length(pos_n) = ((str.length ()
1460 >
static_cast<size_t> (param_length(pos_n)))
1461 ? str.length () : param_length(pos_n));
1466 param_length(pos_t) = ((str.length ()
1467 >
static_cast<size_t> (param_length(pos_t)))
1468 ? str.length () : param_length(pos_t));
1473 param_length(pos_e) = ((str.length ()
1474 >
static_cast<size_t> (param_length(pos_e)))
1475 ? str.length () : param_length(pos_e));
1480 param_length(pos_b) = ((str.length ()
1481 >
static_cast<size_t> (param_length(pos_b)))
1482 ? str.length () : param_length (pos_b));
1486 while (static_cast<size_t> (idx) < format_len)
1493 bool error_encountered =
false;
1506 pos = cmd.find (
';');
1507 if (pos != std::string::npos)
1508 cmd = cmd.substr (0, pos+1);
1510 error (
"parameter without ; in whos_line_format");
1512 idx += cmd.length ();
1516 if (cmd.find_first_of (
"crl") != 1)
1517 items = sscanf (cmd.c_str (),
"%c%c:%d:%d:%d;",
1518 &garbage, ¶m.
command, &a, &b, &balance);
1520 items = sscanf (cmd.c_str (),
"%c%c%c:%d:%d:%d;",
1522 &a, &b, &balance) - 1;
1526 error (
"whos_line_format: parameter structure without command in whos_line_format");
1527 error_encountered =
true;
1532 pos = param_string.find (param.
command);
1533 if (pos != std::string::npos)
1536 param.
text = param_names(pos);
1537 param.
line.assign (param_names(pos).
length (),
'=');
1546 error (
"whos_line_format: '%c' is not a command",
1548 error_encountered =
true;
1563 for (std::list<symbol_info>::const_iterator p = lst.begin ();
1564 p != lst.end (); p++)
1568 int first1 = dims_str.find (
'x');
1569 int total1 = dims_str.length ();
1570 int rest1 = total1 - first1;
1571 rest = (rest1 > rest ? rest1 : rest);
1572 first = (first1 > first ? first1 : first);
1573 total = (total1 > total ? total1 : total);
1578 if (first < balance)
1579 first += balance - first;
1595 error (
"whos_line_format: modifier 'c' not available for command '%c'",
1597 error_encountered =
true;
1608 < param_length(pos_s)
1609 ? param_length(pos_s)
1613 if (! error_encountered)
1614 params.push_back (param);
1622 pos = text.find (
'%');
1623 if (pos != std::string::npos)
1624 text = text.substr (0, pos);
1627 idx += text.length ();
1629 param.
line.assign (text.length (),
' ');
1630 params.push_back (param);
1644 bool verbose =
false, std::string msg = std::string ())
1648 std::string my_name = argv[0];
1650 bool global_only =
false;
1651 bool have_regexp =
false;
1654 for (i = 1; i < argc; i++)
1656 if (argv[i] ==
"-file")
1665 error (
"whos: -file argument must be followed by a file name");
1668 std::string nm = argv[i + 1];
1688 std::string newmsg = std::string (
"Variables in the file ") +
1691 retval =
do_who (i, argv, return_list, verbose, newmsg);
1697 else if (argv[i] ==
"-regexp")
1699 else if (argv[i] ==
"global")
1701 else if (argv[i][0] ==
'-')
1702 warning (
"%s: unrecognized option '%s'", my_name.c_str (),
1708 int npats = argc - i;
1713 for (
int j = 0; j < npats; j++)
1714 pats[j] = argv[i+j];
1723 std::list<std::string> symbol_names;
1725 for (
int j = 0; j < npats; j++)
1727 std::string pat = pats[j];
1731 std::list<symbol_table::symbol_record> tmp = global_only
1735 for (std::list<symbol_table::symbol_record>::const_iterator
1736 p = tmp.begin (); p != tmp.end (); p++)
1738 if (p->is_variable ())
1741 symbol_stats.
append (*p);
1743 symbol_names.push_back (p->name ());
1749 size_t pos = pat.find_first_of (
".({");
1751 if (pos != std::string::npos && pos > 0)
1762 std::string base_name = pat.substr (0, pos);
1777 symbol_stats.
append (sr, pat, expr_val);
1786 std::list<symbol_table::symbol_record> tmp = global_only
1790 for (std::list<symbol_table::symbol_record>::const_iterator
1791 p = tmp.begin (); p != tmp.end (); p++)
1793 if (p->is_variable ())
1796 symbol_stats.
append (*p);
1798 symbol_names.push_back (p->name ());
1809 std::string caller_function_name;
1812 caller_function_name = caller->
name ();
1814 retval = symbol_stats.
map_value (caller_function_name, 1);
1819 else if (! (symbol_stats.
empty () && symbol_names.empty ()))
1821 if (msg.length () == 0)
1844 DEFUN (who, args, nargout,
1846 @deftypefn {Command} {} who\n\
1847 @deftypefnx {Command} {} who pattern @dots{}\n\
1848 @deftypefnx {Command} {} who option pattern @dots{}\n\
1849 @deftypefnx {Command} {C =} who (\"pattern\", @dots{})\n\
1850 List currently defined variables matching the given patterns.\n\
1852 Valid pattern syntax is the same as described for the @code{clear} command.\n\
1853 If no patterns are supplied, all variables are listed.\n\
1855 By default, only variables visible in the local scope are displayed.\n\
1857 The following are valid options, but may not be combined.\n\
1861 List variables in the global scope rather than the current scope.\n\
1864 The patterns are considered to be regular expressions when matching the\n\
1865 variables to display. The same pattern syntax accepted by the @code{regexp}\n\
1866 function is used.\n\
1869 The next argument is treated as a filename. All variables found within the\n\
1870 specified file are listed. No patterns are accepted when reading variables\n\
1874 If called as a function, return a cell array of defined variable names\n\
1875 matching the given patterns.\n\
1876 @seealso{whos, isglobal, isvarname, exist, regexp}\n\
1883 int argc = args.length () + 1;
1888 retval =
do_who (argc, argv, nargout == 1);
1896 DEFUN (whos, args, nargout,
1898 @deftypefn {Command} {} whos\n\
1899 @deftypefnx {Command} {} whos pattern @dots{}\n\
1900 @deftypefnx {Command} {} whos option pattern @dots{}\n\
1901 @deftypefnx {Built-in Function} {S =} whos (\"pattern\", @dots{})\n\
1902 Provide detailed information on currently defined variables matching the\n\
1905 Options and pattern syntax are the same as for the @code{who} command.\n\
1907 Extended information about each variable is summarized in a table with the\n\
1908 following default entries.\n\
1912 Attributes of the listed variable. Possible attributes are:\n\
1916 Variable in local scope\n\
1919 Automatic variable. An automatic variable is one created by the\n\
1920 interpreter, for example @code{argn}.\n\
1923 Variable of complex type.\n\
1926 Formal parameter (function argument).\n\
1929 Variable with global scope.\n\
1932 Persistent variable.\n\
1936 The name of the variable.\n\
1939 The logical size of the variable. A scalar is 1x1, a vector is\n\
1940 @nospell{1xN} or @nospell{Nx1}, a 2-D matrix is @nospell{MxN}.\n\
1943 The amount of memory currently used to store the variable.\n\
1946 The class of the variable. Examples include double, single, char, uint16,\n\
1947 cell, and struct.\n\
1950 The table can be customized to display more or less information through\n\
1951 the function @code{whos_line_format}.\n\
1953 If @code{whos} is called as a function, return a struct array of defined\n\
1954 variable names matching the given patterns. Fields in the structure\n\
1955 describing each variable are: name, size, bytes, class, global, sparse,\n\
1956 complex, nesting, persistent.\n\
1957 @seealso{who, whos_line_format}\n\
1964 int argc = args.length () + 1;
1969 retval =
do_who (argc, argv, nargout == 1,
true);
1982 static std::string ans =
"ans";
2010 feval (fname, args, 0);
2021 error (
"mlock: invalid use outside a function");
2041 bool retval =
false;
2058 @deftypefn {Built-in Function} {} mlock ()\n\
2059 Lock the current function into memory so that it can't be cleared.\n\
2060 @seealso{munlock, mislocked, persistent}\n\
2065 if (args.length () == 0)
2072 error (
"mlock: invalid use outside a function");
2082 @deftypefn {Built-in Function} {} munlock ()\n\
2083 @deftypefnx {Built-in Function} {} munlock (@var{fcn})\n\
2084 Unlock the named function @var{fcn}.\n\
2086 If no function is named then unlock the current function.\n\
2087 @seealso{mlock, mislocked, persistent}\n\
2092 if (args.length () == 1)
2094 if (args(0).is_string ())
2096 std::string name = args(0).string_value ();
2100 error (
"munlock: FCN must be a string");
2102 else if (args.length () == 0)
2109 error (
"munlock: invalid use outside a function");
2120 @deftypefn {Built-in Function} {} mislocked ()\n\
2121 @deftypefnx {Built-in Function} {} mislocked (@var{fcn})\n\
2122 Return true if the named function @var{fcn} is locked.\n\
2124 If no function is named then return true if the current function is locked.\n\
2125 @seealso{mlock, munlock, persistent}\n\
2130 if (args.length () == 1)
2132 if (args(0).is_string ())
2138 error (
"mislocked: FCN must be a string");
2140 else if (args.length () == 0)
2147 error (
"mislocked: invalid use outside a function");
2159 int argc,
int idx,
bool have_regexp =
false)
2161 bool retval =
false;
2163 for (
int k = idx; k < argc; k++)
2165 std::string patstr = argv[k];
2166 if (! patstr.empty ())
2180 if (pattern.
match (nm))
2196 warning (
"clear: ignoring --exclusive option");
2201 bool exclusive =
false)
2211 int fcount = fcns.
length ();
2213 for (
int i = 0; i < fcount; i++)
2215 std::string nm = fcns[i];
2231 bool exclusive =
false)
2237 int gcount = gvars.
length ();
2239 for (
int i = 0; i < gcount; i++)
2248 int gcount = gvars.
length ();
2250 for (
int i = 0; i < gcount; i++)
2252 std::string nm = gvars[i];
2268 bool exclusive =
false,
bool have_regexp =
false)
2278 int lcount = lvars.
length ();
2280 for (
int i = 0; i < lcount; i++)
2282 std::string nm = lvars[i];
2302 bool exclusive =
false)
2331 for (; idx < argc; idx++)
2333 if (argv[idx] ==
"all"
2338 else if (argv[idx] ==
"functions"
2343 else if (argv[idx] ==
"global"
2348 else if (argv[idx] ==
"variables"
2353 else if (argv[idx] ==
"classes"
2367 #define CLEAR_OPTION_ERROR(cond) \
2380 @deftypefn {Command} {} clear [options] pattern @dots{}\n\
2381 Delete the names matching the given patterns from the symbol table.\n\
2383 The pattern may contain the following special characters:\n\
2387 Match any single character.\n\
2390 Match zero or more characters.\n\
2392 @item [ @var{list} ]\n\
2393 Match the list of characters specified by @var{list}. If the first\n\
2394 character is @code{!} or @code{^}, match all characters except those\n\
2395 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\
2396 match all lowercase and uppercase alphabetic characters.\n\
2399 For example, the command\n\
2406 clears the name @code{foo} and all names that begin with the letter\n\
2407 @code{b} and end with the letter @code{r}.\n\
2409 If @code{clear} is called without any arguments, all user-defined\n\
2410 variables (local and global) are cleared from the symbol table.\n\
2412 If @code{clear} is called with at least one argument, only the visible\n\
2413 names matching the arguments are cleared. For example, suppose you have\n\
2414 defined a function @code{foo}, and then hidden it by performing the\n\
2415 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\
2416 will clear the variable definition and restore the definition of\n\
2417 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\
2418 clear the function definition.\n\
2420 The following options are available in both long and short form\n\
2424 Clear all local and global user-defined variables and all functions from the\n\
2427 @item -exclusive, -x\n\
2428 Clear the variables that don't match the following pattern.\n\
2430 @item -functions, -f\n\
2431 Clear the function names and the built-in symbols names.\n\
2433 @item -global, -g\n\
2434 Clear global symbol names.\n\
2436 @item -variables, -v\n\
2437 Clear local variable names.\n\
2439 @item -classes, -c\n\
2440 Clears the class structure table and clears all objects.\n\
2442 @item -regexp, -r\n\
2443 The arguments are treated as regular expressions as any variables that\n\
2444 match will be cleared.\n\
2447 With the exception of @code{exclusive}, all long options can be used\n\
2448 without the dash as well.\n\
2449 @seealso{who, whos, exist}\n\
2454 int argc = args.length () + 1;
2471 bool clear_all =
false;
2472 bool clear_functions =
false;
2473 bool clear_globals =
false;
2474 bool clear_variables =
false;
2475 bool clear_objects =
false;
2476 bool exclusive =
false;
2477 bool have_regexp =
false;
2478 bool have_dash_option =
false;
2480 while (++idx < argc)
2482 if (argv[idx] ==
"-all" || argv[idx] ==
"-a")
2486 have_dash_option =
true;
2489 else if (argv[idx] ==
"-exclusive" || argv[idx] ==
"-x")
2491 have_dash_option =
true;
2494 else if (argv[idx] ==
"-functions" || argv[idx] ==
"-f")
2498 have_dash_option =
true;
2499 clear_functions =
true;
2501 else if (argv[idx] ==
"-global" || argv[idx] ==
"-g")
2505 have_dash_option =
true;
2506 clear_globals =
true;
2508 else if (argv[idx] ==
"-variables" || argv[idx] ==
"-v")
2512 have_dash_option =
true;
2513 clear_variables =
true;
2515 else if (argv[idx] ==
"-classes" || argv[idx] ==
"-c")
2519 have_dash_option =
true;
2520 clear_objects =
true;
2522 else if (argv[idx] ==
"-regexp" || argv[idx] ==
"-r")
2526 have_dash_option =
true;
2535 if (! have_dash_option)
2547 (
"clear: ignoring extra arguments after -all");
2551 else if (have_regexp)
2555 else if (clear_functions)
2559 else if (clear_globals)
2563 else if (clear_variables)
2567 else if (clear_objects)
2587 DEFUN (whos_line_format, args, nargout,
2589 @deftypefn {Built-in Function} {@var{val} =} whos_line_format ()\n\
2590 @deftypefnx {Built-in Function} {@var{old_val} =} whos_line_format (@var{new_val})\n\
2591 @deftypefnx {Built-in Function} {} whos_line_format (@var{new_val}, \"local\")\n\
2592 Query or set the format string used by the command @code{whos}.\n\
2594 A full format string is:\n\
2595 @c Set example in small font to prevent overfull line\n\
2598 %[modifier]<command>[:width[:left-min[:balance]]];\n\
2599 @end smallexample\n\
2601 The following command sequences are available:\n\
2605 Prints attributes of variables (g=global, p=persistent, f=formal parameter,\n\
2606 a=automatic variable).\n\
2609 Prints number of bytes occupied by variables.\n\
2612 Prints class names of variables.\n\
2615 Prints elements held by variables.\n\
2618 Prints variable names.\n\
2621 Prints dimensions of variables.\n\
2624 Prints type names of variables.\n\
2627 Every command may also have an alignment modifier:\n\
2634 Right alignment (default).\n\
2637 Column-aligned (only applicable to command %s).\n\
2640 The @code{width} parameter is a positive integer specifying the minimum\n\
2641 number of columns used for printing. No maximum is needed as the field will\n\
2642 auto-expand as required.\n\
2644 The parameters @code{left-min} and @code{balance} are only available when the\n\
2645 column-aligned modifier is used with the command @samp{%s}.\n\
2646 @code{balance} specifies the column number within the field width which will\n\
2647 be aligned between entries. Numbering starts from 0 which indicates the\n\
2648 leftmost column. @code{left-min} specifies the minimum field width to the\n\
2649 left of the specified balance column.\n\
2651 The default format is:\n\
2653 @qcode{\" %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;@xbackslashchar{}n\"}\n\
2655 When called from inside a function with the @qcode{\"local\"} option, the\n\
2656 variable is changed locally for the function and any subroutines it calls.\n\
2657 The original variable value is restored when exiting the function.\n\
2666 DEFUN (missing_function_hook, args, nargout,
2668 @deftypefn {Built-in Function} {@var{val} =} missing_function_hook ()\n\
2669 @deftypefnx {Built-in Function} {@var{old_val} =} missing_function_hook (@var{new_val})\n\
2670 @deftypefnx {Built-in Function} {} missing_function_hook (@var{new_val}, \"local\")\n\
2671 Query or set the internal variable that specifies the function to call when\n\
2672 an unknown identifier is requested.\n\
2674 When called from inside a function with the @qcode{\"local\"} option, the\n\
2675 variable is changed locally for the function and any subroutines it calls.\n\
2676 The original variable value is restored when exiting the function.\n\
2677 @seealso{missing_component_hook}\n\
2698 Vmissing_function_hook.clear ();
2706 DEFUN (__varval__, args, ,
2708 @deftypefn {Built-in Function} {} __varval__ (@var{name})\n\
2709 Undocumented internal function.\n\
2714 if (args.length () == 1)
2721 error (
"__varval__: expecting argument to be variable name");
2731 DEFUN (missing_component_hook, args, nargout,
2733 @deftypefn {Built-in Function} {@var{val} =} missing_component_hook ()\n\
2734 @deftypefnx {Built-in Function} {@var{old_val} =} missing_component_hook (@var{new_val})\n\
2735 @deftypefnx {Built-in Function} {} missing_component_hook (@var{new_val}, \"local\")\n\
2736 Query or set the internal variable that specifies the function to call when\n\
2737 a component of Octave is missing.\n\
2739 This can be useful for packagers that may split the Octave installation into\n\
2740 multiple sub-packages, for example, to provide a hint to users for how to\n\
2741 install the missing components.\n\
2743 When called from inside a function with the @qcode{\"local\"} option, the\n\
2744 variable is changed locally for the function and any subroutines it calls.\n\
2745 The original variable value is restored when exiting the function.\n\
2747 The hook function is expected to be of the form\n\
2750 @var{fcn} (@var{component})\n\
2753 Octave will call @var{fcn} with the name of the function that requires the\n\
2754 component and a string describing the missing component. The hook function\n\
2755 should return an error message to be displayed.\n\
2756 @seealso{missing_function_hook}\n\
static void clear_objects(scope_id scope=xcurrent_scope)
bool is_builtin_function(void) const
static void clear_global_pattern(const std::string &pat)
bool is_object(void) const
static void clear(octave_shlib &oct_file)
symbol_info(const symbol_table::symbol_record &sr, const std::string &expr_str=std::string(), const octave_value &expr_val=octave_value())
octave_idx_type capacity(void) const
bool try_local_protect(T &var)
void display_line(std::ostream &os, const std::list< whos_parameter > ¶ms) const
static void clear_workspace(void)
std::string str(char sep= 'x') const
static void clear_functions(bool force=false)
static void clear_variable_pattern(const std::string &pat)
std::string get_dims_str(const octave_value &val)
void assign(const std::string &k, const Cell &val)
#define CLEAR_OPTION_ERROR(cond)
static void clear_global(const std::string &name)
OCTINTERP_API void print_usage(void)
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type length(void) const
bool is_regexp_match(const std::string &pat, const std::string &buffer, const regexp::opts &opt=regexp::opts(), const std::string &who="regexp")
static std::string find_fcn(const std::string &fcn, std::string &dir_name, const std::string &pack_name=std::string())
bool is_defined(void) const
static void set_scope(scope_id scope)
bool local_protect(T &variable)
std::ostream & list_in_columns(std::ostream &, int width=0, const std::string &prefix=std::string()) const
static void do_matlab_compatible_clear(const string_vector &argv, int argc, int idx)
static void clear_variable(const std::string &name)
#define DEFUN(name, args_name, nargout_name, doc)
static std::list< symbol_record > glob_variables(const std::string &pattern)
void error(const char *fmt,...)
static void print_descriptor(std::ostream &os, std::list< whos_parameter > params)
std::string name(void) const
#define SET_INTERNAL_VARIABLE(NM)
octave_value_list feval(const std::string &name, const octave_value_list &args, int nargout)
static string_vector names(const map_type &lst)
static octave_function * current(void)
void set_top_level_value(const std::string &nm, const octave_value &val)
int first_parameter_length
static scope_id alloc_scope(void)
void interpreter_try(unwind_protect &frame)
static void clear_mex_functions(void)
octave_value_list eval_string(const std::string &eval_str, bool silent, int &parse_status, int nargout)
static std::string Vwhos_line_format
void bind_ans(const octave_value &val, bool print)
static bool is_variable(const std::string &name)
octave_value set_internal_variable(bool &var, const octave_value_list &args, int nargout, const char *nm)
std::string file_in_path(const std::string &name, const std::string &suffix)
bool is_keyword(const std::string &s)
static octave_value find_function(const std::string &name, const octave_value_list &args=octave_value_list(), bool local_funcs=true)
static octave_value varval(const std::string &name, scope_id scope=xcurrent_scope, context_id context=xdefault_context)
static void do_clear_variables(const string_vector &argv, int argc, int idx, bool exclusive=false, bool have_regexp=false)
static void clear_variables(void)
bool is_function_handle(void) const
static void do_clear_functions(const string_vector &argv, int argc, int idx, bool exclusive=false)
void set_global_value(const std::string &nm, const octave_value &val)
static std::string Vmissing_function_hook
std::string unique_symbol_name(const std::string &basename)
void bind_internal_variable(const std::string &fname, const octave_value &val)
static symbol_record find_symbol(const std::string &name, scope_id scope=xcurrent_scope)
void clear_function(const std::string &nm)
static octave_value global_varval(const std::string &name)
static bool wants_local_change(const octave_value_list &args, int &nargin)
static std::list< std::string > global_variable_names(void)
static void clear_symbol(const std::string &name)
int buffer_error_messages
static octave_user_code * caller_user_code(size_t nskip=0)
static octave_value safe_symbol_lookup(const std::string &symbol_name)
static std::string basename(const std::string &s, bool strip_path=false)
std::list< symbol_info > lst
static octave_function * caller(void)
void add_fcn(void(*fcn)(void))
void clear_variable(const std::string &nm)
bool is_sparse_type(void) const
static std::list< symbol_record > regexp_global_variables(const std::string &pattern)
std::string string_value(bool force=false) const
bool is_global(void) const
void error_with_cfn(const char *fmt,...)
void resize(octave_idx_type n, const std::string &rfv=std::string())
static void set_workspace(void)
octave_value lookup_function_handle(const std::string &nm)
static bool is_global(const std::string &name)
bool is_string(void) const
static std::list< symbol_record > regexp_variables(const std::string &pattern)
string_vector get_struct_elts(const std::string &text)
static void force_assign(const std::string &name, const octave_value &value=octave_value(), scope_id scope=xcurrent_scope, context_id context=xdefault_context)
string_vector generate_struct_completions(const std::string &text, std::string &prefix, std::string &hint)
static void global_assign(const std::string &name, const octave_value &value=octave_value())
bool is_inline_function(void) const
bool is_complex_type(void) const
static bool is_variable(const std::string &name)
bool match(const std::string &str) const
static void push(octave_function *f, symbol_table::scope_id scope=symbol_table::current_scope(), symbol_table::context_id context=symbol_table::current_context())
octave_idx_type length(void) const
string_vector map_keys(void) const
virtual bool is_user_function(void) const
void maybe_missing_function_hook(const std::string &name)
std::list< whos_parameter > parse_whos_line_format(void)
static dim_vector alloc(int n)
bool is_classdef_object(void) const
octave_map map_value(const std::string &caller_function_name, int nesting_level) const
static std::string Vmissing_component_hook
octave_function * function_value(bool silent=false) const
static std::list< std::string > variable_names(void)
void warning(const char *fmt,...)
bool looks_like_struct(const std::string &text)
static void clear_all(bool force=false)
static std::list< std::string > user_function_names(void)
static std::string dir_sep_chars(void)
std::string type_name(void) const
octave_idx_type length(void) const
Number of elements in the array.
static void clear_exemplar_map(void)
static bool is_local_variable(const std::string &name)
octave_value get_global_value(const std::string &nm, bool silent)
bool mislocked(const std::string &nm)
octave_value get_top_level_value(const std::string &nm, bool silent)
void assign(const std::string &k, const octave_value &val)
bool is_cs_list(void) const
static std::list< symbol_record > glob_global_variables(const std::string &pattern)
symbol_info_list(const symbol_info_list &sil)
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)
void print_with_name(std::ostream &os, const std::string &name) const
bool is_anonymous_function(void) const
static bool name_matches_any_pattern(const std::string &nm, const string_vector &argv, int argc, int idx, bool have_regexp=false)
std::string class_name(void) const
static void maybe_warn_exclusive(bool exclusive)
bool is_constant(void) const
bool is_user_function(void) const
bool is_undefined(void) const
void append(const symbol_table::symbol_record &sr)
void clear_symbol(const std::string &nm)
static void do_clear_symbols(const string_vector &argv, int argc, int idx, bool exclusive=false)
void display(std::ostream &os)
octave_value_list list_value(void) const
static void clear_symbol_pattern(const std::string &pat)
static octave_value do_isglobal(const octave_value_list &args)
static void clear_variable_regexp(const std::string &pat)
std::string lookup_autoload(const std::string &nm)
static octave_value do_who(int argc, const string_vector &argv, bool return_list, bool verbose=false, std::string msg=std::string())
void clear_mex_functions(void)
octave_function * is_valid_function(const std::string &fcn_name, const std::string &warn_for, bool warn)
bool discard_warning_messages
bool discard_error_messages
static void clear_function(const std::string &name)
static void clear_function_pattern(const std::string &pat)
void append(const symbol_table::symbol_record &sr, const std::string &expr_str, const octave_value &expr_val)
void munlock(const std::string &nm)
bool islocked(void) const
return octave_value(v1.char_array_value().concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string())? '\'': '"'))
int symbol_exist(const std::string &name, const std::string &type)
static void erase_scope(scope_id scope)
static void top_level_assign(const std::string &name, const octave_value &value=octave_value())
size_t byte_size(void) const
static octave_value top_level_varval(const std::string &name)
static void do_clear_globals(const string_vector &argv, int argc, int idx, bool exclusive=false)
static octave_value find(const std::string &name, const octave_value_list &args=octave_value_list(), bool skip_variables=false, bool local_funcs=true)