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 ());
137 error (
"%s: expecting function name as argument", warn_for.c_str ());
144 const std::string& fname,
const std::string& header,
145 const std::string& trailer)
155 std::string cmd = header;
157 cmd.append (trailer);
165 if (parse_status == 0)
171 error (
"%s: '%s' is not valid as a function",
172 warn_for.c_str (), fname.c_str ());
176 warning (
"%s: passing function body as a string is obsolete; please use anonymous functions",
180 error (
"%s: '%s' is not valid as a function",
181 warn_for.c_str (), fname.c_str ());
184 error (
"%s: expecting first argument to be a string",
198 size_t len = text.
length ();
200 while ((pos = text.find (
'.', pos)) != std::string::npos)
212 for (
int i = 0; i < n; i++)
214 len = text.find (
'.', pos);
216 if (len != std::string::npos)
219 retval[i] = text.substr (pos, len);
221 if (len != std::string::npos)
245 std::string& prefix, std::string& hint)
249 size_t pos = text.rfind (
'.');
251 if (pos != std::string::npos)
253 if (pos == text.length ())
256 hint = text.substr (pos+1);
258 prefix = text.substr (0, pos);
260 std::string base_name = prefix;
262 pos = base_name.find_first_of (
"{(.");
264 if (pos != std::string::npos)
265 base_name = base_name.substr (0, pos);
299 bool retval = (! text.empty ()
302 && text.find (
"..") == std::string::npos
303 && text.rfind (
'.') != std::string::npos);
306 symbol_record *sr = curr_sym_tab->lookup (text);
308 if (sr && ! sr->is_function ())
335 int nargin = args.
length ();
343 std::string name = args(0).string_value ();
347 error (
"isglobal: NAME must be a string");
354 DEFUN (isglobal, args, ,
356 @deftypefn {Built-in Function} {} isglobal (@var{name})\n\
357 Return true if @var{name} is a globally visible variable.\n\
367 @seealso{isvarname, exist}\n\
391 std::string struct_elts;
392 std::string symbol_name = name;
394 size_t pos = name.find (
'.');
396 if (pos != std::string::npos && pos > 0)
398 struct_elts = name.substr (pos+1);
399 symbol_name = name.substr (0, pos);
404 bool search_any = type ==
"any";
405 bool search_var = type ==
"var";
406 bool search_dir = type ==
"dir";
407 bool search_file = type ==
"file";
408 bool search_builtin = type ==
"builtin";
410 if (search_any || search_var)
412 bool not_a_struct = struct_elts.empty ();
413 bool var_ok = not_a_struct;
427 if (search_any || search_file || search_dir)
431 if (file_name.empty ())
434 size_t len = file_name.length ();
438 if (search_any || search_file)
440 if (len > 4 && (file_name.substr (len-4) ==
".oct"
441 || file_name.substr (len-4) ==
".mex"))
450 if (file_name.empty ())
457 if (search_any || search_file)
458 return fs.
is_dir () ? 7 : 2;
459 else if (search_dir && fs.
is_dir ())
463 if (search_file || search_dir)
473 if (val.
is_defined () && struct_elts.empty ())
475 if ((search_any || search_builtin)
479 if ((search_any || search_file)
492 #define GET_IDX(LEN) \
493 static_cast<int> ((LEN-1) * static_cast<double> (rand ()) / RAND_MAX)
498 static const std::string alpha
499 =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
501 static size_t len = alpha.length ();
503 std::string nm = basename + alpha[
GET_IDX (len)];
505 size_t pos = nm.length ();
507 if (nm.substr (0, 2) ==
"__")
511 nm.insert (pos++, 1, alpha[
GET_IDX (len)]);
516 DEFUN (exist, args, ,
518 @deftypefn {Built-in Function} {} exist (@var{name}, @var{type})\n\
519 Return 1 if the name exists as a variable, 2 if the name is an\n\
520 absolute file name, an ordinary file in Octave's @code{path}, or (after\n\
521 appending @samp{.m}) a function file in Octave's @code{path}, 3 if the\n\
522 name is a @samp{.oct} or @samp{.mex} file in Octave's @code{path},\n\
523 5 if the name is a built-in function, 7 if the name is a directory, or 103\n\
524 if the name is a function not associated with a file (entered on\n\
525 the command line).\n\
527 Otherwise, return 0.\n\
529 This function also returns 2 if a regular file called @var{name}\n\
530 exists in Octave's search path. If you want information about\n\
531 other types of files, you should use some combination of the functions\n\
532 @code{file_in_path} and @code{stat} instead.\n\
534 If the optional argument @var{type} is supplied, check only for\n\
535 symbols of the specified type. Valid types are\n\
538 @item @qcode{\"var\"}\n\
539 Check only for variables.\n\
541 @item @qcode{\"builtin\"}\n\
542 Check only for built-in functions.\n\
544 @item @qcode{\"file\"}\n\
545 Check only for files and directories.\n\
547 @item @qcode{\"dir\"}\n\
548 Check only for directories.\n\
551 @seealso{file_in_loadpath, file_in_path, find_dir_in_path, stat}\n\
556 int nargin = args.
length ();
558 if (nargin == 1 || nargin == 2)
560 std::string name = args(0).string_value ();
566 std::string
type = args(1).string_value ();
571 error (
"exist: TYPE must be a string");
577 error (
"exist: NAME must be a string");
614 error (
"get_global_value: undefined symbol '%s'", nm.c_str ());
631 error (
"get_top_level_value: undefined symbol '%s'", nm.c_str ());
651 if (args(1).is_string () && args(1).string_value () ==
"local")
672 curr_usr_fcn = dynamic_cast<octave_user_function *> (curr_usr_code);
682 int nargout,
const char *nm)
686 int nargin = args.
length ();
688 if (nargout > 0 || nargin == 0)
694 warning (
"\"local\" has no effect outside a function");
699 bool bval = args(0).bool_value ();
704 error (
"%s: expecting arg to be a logical value", nm);
714 int nargout,
const char *nm)
718 int nargin = args.
length ();
720 if (nargout > 0 || nargin == 0)
726 warning (
"\"local\" has no effect outside a function");
731 std::string sval = args(0).string_value ();
735 switch (sval.length ())
746 error (
"%s: argument must be a single character", nm);
751 error (
"%s: argument must be a single character", nm);
761 int nargout,
const char *nm,
762 int minval,
int maxval)
766 int nargin = args.
length ();
768 if (nargout > 0 || nargin == 0)
774 warning (
"\"local\" has no effect outside a function");
779 int ival = args(0).int_value ();
784 error (
"%s: expecting arg to be greater than %d", nm, minval);
785 else if (ival > maxval)
786 error (
"%s: expecting arg to be less than or equal to %d",
792 error (
"%s: expecting arg to be an integer value", nm);
802 int nargout,
const char *nm,
803 double minval,
double maxval)
807 int nargin = args.
length ();
809 if (nargout > 0 || nargin == 0)
815 warning (
"\"local\" has no effect outside a function");
820 double dval = args(0).scalar_value ();
825 error (
"%s: expecting arg to be greater than %g", minval);
826 else if (dval > maxval)
827 error (
"%s: expecting arg to be less than or equal to %g", maxval);
832 error (
"%s: expecting arg to be a scalar value", nm);
842 int nargout,
const char *nm,
bool empty_ok)
846 int nargin = args.
length ();
848 if (nargout > 0 || nargin == 0)
854 warning (
"\"local\" has no effect outside a function");
859 std::string sval = args(0).string_value ();
863 if (empty_ok || ! sval.empty ())
866 error (
"%s: value must not be empty", nm);
869 error (
"%s: expecting arg to be a character string", nm);
879 int nargout,
const char *nm,
const char **choices)
883 while (choices[nchoices] != 0)
886 int nargin = args.
length ();
887 assert (var < nchoices);
889 if (nargout > 0 || nargin == 0)
890 retval = choices[var];
895 warning (
"\"local\" has no effect outside a function");
900 std::string sval = args(0).string_value ();
905 for (; i < nchoices; i++)
907 if (sval == choices[i])
914 error (
"%s: value not allowed (\"%s\")", nm, sval.c_str ());
917 error (
"%s: expecting arg to be a character string", nm);
941 std::list<whos_parameter>::iterator i = params.begin ();
942 std::ostringstream param_buf;
946 while (i != params.end ())
963 os << std::setiosflags (std::ios::right)
965 param_buf << std::setiosflags (std::ios::right)
999 << std::setw (b) <<
""
1006 << std::setw (b) <<
""
1013 param_buf << param.
line;
1016 << std::resetiosflags (std::ios::right);
1018 << std::resetiosflags (std::ios::right);
1024 param_buf << param.
line;
1029 os << param_buf.str ();
1059 const std::string& expr_str = std::string (),
1061 : name (expr_str.empty () ? sr.name () : expr_str),
1062 varval (expr_val.is_undefined () ? sr.varval () : expr_val),
1063 is_automatic (sr.is_automatic ()),
1064 is_complex (varval.is_complex_type ()),
1065 is_formal (sr.is_formal ()),
1066 is_global (sr.is_global ()),
1067 is_persistent (sr.is_persistent ())
1070 void display_line (std::ostream& os,
1071 const std::list<whos_parameter>& params)
const
1075 std::list<whos_parameter>::const_iterator i = params.begin ();
1079 while (i != params.end ())
1095 os << std::setiosflags (std::ios::right)
1103 - dims_str.find (
'x');
1105 - dims_str.length ()
1107 front = (front > 0) ? front : 0;
1108 back = (back > 0) ? back : 0;
1111 << std::setw (front)
1128 error (
"whos_line_format: modifier '%c' unknown",
1131 os << std::setiosflags (std::ios::right)
1141 tmp[0] = (is_automatic ?
'a' :
' ');
1142 tmp[1] = (is_complex ?
'c' :
' ');
1143 tmp[2] = (is_formal ?
'f' :
' ');
1144 tmp[3] = (is_global ?
'g' :
' ');
1145 tmp[4] = (is_persistent ?
'p' :
' ');
1153 os << varval.byte_size ();
1157 os << varval.class_name ();
1161 os << varval.capacity ();
1174 os << varval.type_name ();
1178 error (
"whos_line_format: command '%c' unknown",
1183 << std::resetiosflags (std::ios::right);
1224 const std::string& expr_str,
1227 lst.push_back (
symbol_info (sr, expr_str, expr_val));
1230 size_t size (
void)
const {
return lst.size (); }
1232 bool empty (
void)
const {
return lst.empty (); }
1235 map_value (
const std::string& caller_function_name,
int nesting_level)
const
1237 size_t len = lst.size ();
1239 Cell name_info (len, 1);
1240 Cell size_info (len, 1);
1241 Cell bytes_info (len, 1);
1242 Cell class_info (len, 1);
1243 Cell global_info (len, 1);
1244 Cell sparse_info (len, 1);
1245 Cell complex_info (len, 1);
1246 Cell nesting_info (len, 1);
1247 Cell persistent_info (len, 1);
1249 std::list<symbol_info>::const_iterator p = lst.begin ();
1251 for (
size_t j = 0; j < len; j++)
1257 ni.
assign (
"function", caller_function_name);
1258 ni.
assign (
"level", nesting_level);
1260 name_info(j) = si.
name;
1266 size_info(j) = val.
size ();
1271 nesting_info(j) = ni;
1276 info.
assign (
"name", name_info);
1277 info.
assign (
"size", size_info);
1278 info.
assign (
"bytes", bytes_info);
1279 info.
assign (
"class", class_info);
1280 info.
assign (
"global", global_info);
1281 info.
assign (
"sparse", sparse_info);
1282 info.
assign (
"complex", complex_info);
1283 info.
assign (
"nesting", nesting_info);
1284 info.
assign (
"persistent", persistent_info);
1289 void display (std::ostream& os)
1294 size_t elements = 0;
1296 std::list<whos_parameter> params = parse_whos_line_format ();
1302 for (std::list<symbol_info>::const_iterator p = lst.begin ();
1303 p != lst.end (); p++)
1305 p->display_line (os, params);
1313 os <<
"\nTotal is " << elements
1314 << (elements == 1 ?
" element" :
" elements")
1315 <<
" using " << bytes << (bytes == 1 ?
" byte" :
" bytes")
1323 std::list<whos_parameter> parse_whos_line_format (
void)
1328 std::list<whos_parameter> params;
1333 std::string param_string =
"abcenst";
1336 size_t pos_a, pos_b, pos_c, pos_e, pos_n, pos_s, pos_t;
1338 pos_a = param_string.find (
'a');
1339 pos_b = param_string.find (
'b');
1340 pos_c = param_string.find (
'c');
1341 pos_e = param_string.find (
'e');
1342 pos_n = param_string.find (
'n');
1343 pos_s = param_string.find (
's');
1344 pos_t = param_string.find (
't');
1346 param_names(pos_a) =
"Attr";
1347 param_names(pos_b) =
"Bytes";
1348 param_names(pos_c) =
"Class";
1349 param_names(pos_e) =
"Elements";
1350 param_names(pos_n) =
"Name";
1351 param_names(pos_s) =
"Size";
1352 param_names(pos_t) =
"Type";
1354 for (
size_t i = 0; i < param_string.length (); i++)
1355 param_length(i) = param_names(i).
length ();
1358 param_length(pos_a) = 5;
1363 for (std::list<symbol_info>::const_iterator p = lst.begin ();
1364 p != lst.end (); p++)
1366 std::stringstream ss1, ss2;
1370 param_length(pos_n) = ((str.length ()
1371 >
static_cast<size_t> (param_length(pos_n)))
1372 ? str.length () : param_length(pos_n));
1377 param_length(pos_t) = ((str.length ()
1378 >
static_cast<size_t> (param_length(pos_t)))
1379 ? str.length () : param_length(pos_t));
1384 param_length(pos_e) = ((str.length ()
1385 >
static_cast<size_t> (param_length(pos_e)))
1386 ? str.length () : param_length(pos_e));
1391 param_length(pos_b) = ((str.length ()
1392 >
static_cast<size_t> (param_length(pos_b)))
1393 ? str.length () : param_length (pos_b));
1397 while (static_cast<size_t> (idx) < format_len)
1404 bool error_encountered =
false;
1408 int a = 0, b = -1, balance = 1;
1415 pos = cmd.find (
';');
1416 if (pos != std::string::npos)
1417 cmd = cmd.substr (0, pos+1);
1419 error (
"parameter without ; in whos_line_format");
1421 idx += cmd.length ();
1425 if (cmd.find_first_of (
"crl") != 1)
1426 items = sscanf (cmd.c_str (),
"%c%c:%d:%d:%d;",
1427 &garbage, ¶m.
command, &a, &b, &balance);
1429 items = sscanf (cmd.c_str (),
"%c%c%c:%d:%d:%d;",
1431 &a, &b, &balance) - 1;
1435 error (
"whos_line_format: parameter structure without command in whos_line_format");
1436 error_encountered =
true;
1441 pos = param_string.find (param.
command);
1442 if (pos != std::string::npos)
1445 param.
text = param_names(pos);
1446 param.
line.assign (param_names(pos).
length (),
'=');
1455 error (
"whos_line_format: '%c' is not a command",
1457 error_encountered =
true;
1472 for (std::list<symbol_info>::const_iterator p = lst.begin ();
1473 p != lst.end (); p++)
1477 int first1 = dims_str.find (
'x');
1478 int total1 = dims_str.length ();
1479 int rest1 = total1 - first1;
1480 rest = (rest1 > rest ? rest1 : rest);
1481 first = (first1 > first ? first1 : first);
1482 total = (total1 > total ? total1 : total);
1487 if (first < balance)
1488 first += balance - first;
1504 error (
"whos_line_format: modifier 'c' not available for command '%c'",
1506 error_encountered =
true;
1517 < param_length(pos_s)
1518 ? param_length(pos_s)
1522 if (! error_encountered)
1523 params.push_back (param);
1531 pos = text.find (
'%');
1532 if (pos != std::string::npos)
1533 text = text.substr (0, pos);
1536 idx += text.length ();
1538 param.
line.assign (text.length (),
' ');
1539 params.push_back (param);
1553 bool verbose =
false, std::string msg = std::string ())
1557 std::string my_name = argv[0];
1559 bool global_only =
false;
1560 bool have_regexp =
false;
1563 for (i = 1; i < argc; i++)
1565 if (argv[i] ==
"-file")
1574 error (
"whos: -file argument must be followed by a file name");
1577 std::string nm = argv[i + 1];
1597 std::string newmsg = std::string (
"Variables in the file ") +
1600 retval =
do_who (i, argv, return_list, verbose, newmsg);
1606 else if (argv[i] ==
"-regexp")
1608 else if (argv[i] ==
"global")
1610 else if (argv[i][0] ==
'-')
1611 warning (
"%s: unrecognized option '%s'", my_name.c_str (),
1617 int npats = argc - i;
1622 for (
int j = 0; j < npats; j++)
1623 pats[j] = argv[i+j];
1632 std::list<std::string> symbol_names;
1634 for (
int j = 0; j < npats; j++)
1636 std::string pat = pats[j];
1640 std::list<symbol_table::symbol_record> tmp = global_only
1644 for (std::list<symbol_table::symbol_record>::const_iterator
1645 p = tmp.begin (); p != tmp.end (); p++)
1647 if (p->is_variable ())
1650 symbol_stats.
append (*p);
1652 symbol_names.push_back (p->name ());
1658 size_t pos = pat.find_first_of (
".({");
1660 if (pos != std::string::npos && pos > 0)
1671 std::string base_name = pat.substr (0, pos);
1686 symbol_stats.
append (sr, pat, expr_val);
1695 std::list<symbol_table::symbol_record> tmp = global_only
1699 for (std::list<symbol_table::symbol_record>::const_iterator
1700 p = tmp.begin (); p != tmp.end (); p++)
1702 if (p->is_variable ())
1705 symbol_stats.
append (*p);
1707 symbol_names.push_back (p->name ());
1718 std::string caller_function_name;
1721 caller_function_name = caller->
name ();
1723 retval = symbol_stats.
map_value (caller_function_name, 1);
1728 else if (! (symbol_stats.
empty () && symbol_names.empty ()))
1730 if (msg.length () == 0)
1753 DEFUN (who, args, nargout,
1755 @deftypefn {Command} {} who\n\
1756 @deftypefnx {Command} {} who pattern @dots{}\n\
1757 @deftypefnx {Command} {} who option pattern @dots{}\n\
1758 @deftypefnx {Command} {C =} who (\"pattern\", @dots{})\n\
1759 List currently defined variables matching the given patterns. Valid\n\
1760 pattern syntax is the same as described for the @code{clear} command.\n\
1761 If no patterns are supplied, all variables are listed.\n\
1762 By default, only variables visible in the local scope are displayed.\n\
1764 The following are valid options but may not be combined.\n\
1768 List variables in the global scope rather than the current scope.\n\
1771 The patterns are considered to be regular expressions when matching the\n\
1772 variables to display. The same pattern syntax accepted by\n\
1773 the @code{regexp} function is used.\n\
1776 The next argument is treated as a filename. All variables found within the\n\
1777 specified file are listed. No patterns are accepted when reading variables\n\
1781 If called as a function, return a cell array of defined variable names\n\
1782 matching the given patterns.\n\
1783 @seealso{whos, isglobal, isvarname, exist, regexp}\n\
1790 int argc = args.length () + 1;
1795 retval =
do_who (argc, argv, nargout == 1);
1803 DEFUN (whos, args, nargout,
1805 @deftypefn {Command} {} whos\n\
1806 @deftypefnx {Command} {} whos pattern @dots{}\n\
1807 @deftypefnx {Command} {} whos option pattern @dots{}\n\
1808 @deftypefnx {Command} {S =} whos (\"pattern\", @dots{})\n\
1809 Provide detailed information on currently defined variables matching the\n\
1810 given patterns. Options and pattern syntax are the same as for the\n\
1811 @code{who} command. Extended information about each variable is\n\
1812 summarized in a table with the following default entries.\n\
1816 Attributes of the listed variable. Possible attributes are:\n\
1820 Variable in local scope\n\
1823 Automatic variable. An automatic variable is one created by the\n\
1824 interpreter, for example @code{argn}.\n\
1827 Variable of complex type.\n\
1830 Formal parameter (function argument).\n\
1833 Variable with global scope.\n\
1836 Persistent variable.\n\
1840 The name of the variable.\n\
1843 The logical size of the variable. A scalar is 1x1, a vector is\n\
1844 @nospell{1xN} or @nospell{Nx1}, a 2-D matrix is @nospell{MxN}.\n\
1847 The amount of memory currently used to store the variable.\n\
1850 The class of the variable. Examples include double, single, char, uint16,\n\
1851 cell, and struct.\n\
1854 The table can be customized to display more or less information through\n\
1855 the function @code{whos_line_format}.\n\
1857 If @code{whos} is called as a function, return a struct array of defined\n\
1858 variable names matching the given patterns. Fields in the structure\n\
1859 describing each variable are: name, size, bytes, class, global, sparse,\n\
1860 complex, nesting, persistent.\n\
1861 @seealso{who, whos_line_format}\n\
1868 int argc = args.length () + 1;
1873 retval =
do_who (argc, argv, nargout == 1,
true);
1886 static std::string ans =
"ans";
1914 feval (fname, args, 0);
1925 error (
"mlock: invalid use outside a function");
1945 bool retval =
false;
1962 @deftypefn {Built-in Function} {} mlock ()\n\
1963 Lock the current function into memory so that it can't be cleared.\n\
1964 @seealso{munlock, mislocked, persistent}\n\
1969 if (args.length () == 0)
1976 error (
"mlock: invalid use outside a function");
1986 @deftypefn {Built-in Function} {} munlock ()\n\
1987 @deftypefnx {Built-in Function} {} munlock (@var{fcn})\n\
1988 Unlock the named function @var{fcn}. If no function is named\n\
1989 then unlock the current function.\n\
1990 @seealso{mlock, mislocked, persistent}\n\
1995 if (args.length () == 1)
1997 std::string name = args(0).string_value ();
2002 error (
"munlock: FCN must be a string");
2004 else if (args.length () == 0)
2011 error (
"munlock: invalid use outside a function");
2022 @deftypefn {Built-in Function} {} mislocked ()\n\
2023 @deftypefnx {Built-in Function} {} mislocked (@var{fcn})\n\
2024 Return true if the named function @var{fcn} is locked. If no function is\n\
2025 named then return true if the current function is locked.\n\
2026 @seealso{mlock, munlock, persistent}\n\
2031 if (args.length () == 1)
2038 error (
"mislocked: FCN must be a string");
2040 else if (args.length () == 0)
2047 error (
"mislocked: invalid use outside a function");
2059 int argc,
int idx,
bool have_regexp =
false)
2061 bool retval =
false;
2063 for (
int k = idx; k < argc; k++)
2065 std::string patstr = argv[k];
2066 if (! patstr.empty ())
2080 if (pattern.
match (nm))
2096 warning (
"clear: ignoring --exclusive option");
2101 bool exclusive =
false)
2111 int fcount = fcns.
length ();
2113 for (
int i = 0; i < fcount; i++)
2115 std::string nm = fcns[i];
2131 bool exclusive =
false)
2137 int gcount = gvars.
length ();
2139 for (
int i = 0; i < gcount; i++)
2148 int gcount = gvars.
length ();
2150 for (
int i = 0; i < gcount; i++)
2152 std::string nm = gvars[i];
2168 bool exclusive =
false,
bool have_regexp =
false)
2178 int lcount = lvars.
length ();
2180 for (
int i = 0; i < lcount; i++)
2182 std::string nm = lvars[i];
2202 bool exclusive =
false)
2231 for (; idx < argc; idx++)
2233 if (argv[idx] ==
"all"
2238 else if (argv[idx] ==
"functions"
2243 else if (argv[idx] ==
"global"
2248 else if (argv[idx] ==
"variables"
2253 else if (argv[idx] ==
"classes"
2266 #define CLEAR_OPTION_ERROR(cond) \
2279 @deftypefn {Command} {} clear [options] pattern @dots{}\n\
2280 Delete the names matching the given patterns from the symbol table. The\n\
2281 pattern may contain the following special characters:\n\
2285 Match any single character.\n\
2288 Match zero or more characters.\n\
2290 @item [ @var{list} ]\n\
2291 Match the list of characters specified by @var{list}. If the first\n\
2292 character is @code{!} or @code{^}, match all characters except those\n\
2293 specified by @var{list}. For example, the pattern @samp{[a-zA-Z]} will\n\
2294 match all lowercase and uppercase alphabetic characters.\n\
2297 For example, the command\n\
2304 clears the name @code{foo} and all names that begin with the letter\n\
2305 @code{b} and end with the letter @code{r}.\n\
2307 If @code{clear} is called without any arguments, all user-defined\n\
2308 variables (local and global) are cleared from the symbol table. If\n\
2309 @code{clear} is called with at least one argument, only the visible\n\
2310 names matching the arguments are cleared. For example, suppose you have\n\
2311 defined a function @code{foo}, and then hidden it by performing the\n\
2312 assignment @code{foo = 2}. Executing the command @kbd{clear foo} once\n\
2313 will clear the variable definition and restore the definition of\n\
2314 @code{foo} as a function. Executing @kbd{clear foo} a second time will\n\
2315 clear the function definition.\n\
2317 The following options are available in both long and short form\n\
2321 Clears all local and global user-defined variables and all functions\n\
2322 from the symbol table.\n\
2324 @item -exclusive, -x\n\
2325 Clears the variables that don't match the following pattern.\n\
2327 @item -functions, -f\n\
2328 Clears the function names and the built-in symbols names.\n\
2330 @item -global, -g\n\
2331 Clears the global symbol names.\n\
2333 @item -variables, -v\n\
2334 Clears the local variable names.\n\
2336 @item -classes, -c\n\
2337 Clears the class structure table and clears all objects.\n\
2339 @item -regexp, -r\n\
2340 The arguments are treated as regular expressions as any variables that\n\
2341 match will be cleared.\n\
2344 With the exception of @code{exclusive}, all long options can be used\n\
2345 without the dash as well.\n\
2350 int argc = args.length () + 1;
2367 bool clear_all =
false;
2368 bool clear_functions =
false;
2369 bool clear_globals =
false;
2370 bool clear_variables =
false;
2371 bool clear_objects =
false;
2372 bool exclusive =
false;
2373 bool have_regexp =
false;
2374 bool have_dash_option =
false;
2376 while (++idx < argc)
2378 if (argv[idx] ==
"-all" || argv[idx] ==
"-a")
2382 have_dash_option =
true;
2385 else if (argv[idx] ==
"-exclusive" || argv[idx] ==
"-x")
2387 have_dash_option =
true;
2390 else if (argv[idx] ==
"-functions" || argv[idx] ==
"-f")
2394 have_dash_option =
true;
2395 clear_functions =
true;
2397 else if (argv[idx] ==
"-global" || argv[idx] ==
"-g")
2401 have_dash_option =
true;
2402 clear_globals =
true;
2404 else if (argv[idx] ==
"-variables" || argv[idx] ==
"-v")
2408 have_dash_option =
true;
2409 clear_variables =
true;
2411 else if (argv[idx] ==
"-classes" || argv[idx] ==
"-c")
2415 have_dash_option =
true;
2416 clear_objects =
true;
2418 else if (argv[idx] ==
"-regexp" || argv[idx] ==
"-r")
2422 have_dash_option =
true;
2431 if (! have_dash_option)
2443 (
"clear: ignoring extra arguments after -all");
2447 else if (have_regexp)
2451 else if (clear_functions)
2455 else if (clear_globals)
2459 else if (clear_variables)
2463 else if (clear_objects)
2482 DEFUN (whos_line_format, args, nargout,
2484 @deftypefn {Built-in Function} {@var{val} =} whos_line_format ()\n\
2485 @deftypefnx {Built-in Function} {@var{old_val} =} whos_line_format (@var{new_val})\n\
2486 @deftypefnx {Built-in Function} {} whos_line_format (@var{new_val}, \"local\")\n\
2487 Query or set the format string used by the command @code{whos}.\n\
2489 A full format string is:\n\
2490 @c Set example in small font to prevent overfull line\n\
2493 %[modifier]<command>[:width[:left-min[:balance]]];\n\
2494 @end smallexample\n\
2496 The following command sequences are available:\n\
2500 Prints attributes of variables (g=global, p=persistent,\n\
2501 f=formal parameter, a=automatic variable).\n\
2504 Prints number of bytes occupied by variables.\n\
2507 Prints class names of variables.\n\
2510 Prints elements held by variables.\n\
2513 Prints variable names.\n\
2516 Prints dimensions of variables.\n\
2519 Prints type names of variables.\n\
2522 Every command may also have an alignment modifier:\n\
2529 Right alignment (default).\n\
2532 Column-aligned (only applicable to command %s).\n\
2535 The @code{width} parameter is a positive integer specifying the minimum\n\
2536 number of columns used for printing. No maximum is needed as the field will\n\
2537 auto-expand as required.\n\
2539 The parameters @code{left-min} and @code{balance} are only available when the\n\
2540 column-aligned modifier is used with the command @samp{%s}.\n\
2541 @code{balance} specifies the column number within the field width which will\n\
2542 be aligned between entries. Numbering starts from 0 which indicates the\n\
2543 leftmost column. @code{left-min} specifies the minimum field width to the\n\
2544 left of the specified balance column.\n\
2546 The default format is\n\
2547 @qcode{\" %a:4; %ln:6; %cs:16:6:1; %rb:12; %lc:-1;\\n\"}.\n\
2549 When called from inside a function with the @qcode{\"local\"} option, the\n\
2550 variable is changed locally for the function and any subroutines it calls. \n\
2551 The original variable value is restored when exiting the function.\n\
2560 DEFUN (missing_function_hook, args, nargout,
2562 @deftypefn {Built-in Function} {@var{val} =} missing_function_hook ()\n\
2563 @deftypefnx {Built-in Function} {@var{old_val} =} missing_function_hook (@var{new_val})\n\
2564 @deftypefnx {Built-in Function} {} missing_function_hook (@var{new_val}, \"local\")\n\
2565 Query or set the internal variable that specifies the function to call when\n\
2566 an unknown identifier is requested.\n\
2568 When called from inside a function with the @qcode{\"local\"} option, the\n\
2569 variable is changed locally for the function and any subroutines it calls. \n\
2570 The original variable value is restored when exiting the function.\n\
2571 @seealso{missing_component_hook}\n\
2592 Vmissing_function_hook.clear ();
2600 DEFUN (__varval__, args, ,
2602 @deftypefn {Built-in Function} {} __varval__ (@var{name})\n\
2603 Undocumented internal function.\n\
2608 if (args.length () == 1)
2615 error (
"__varval__: expecting argument to be variable name");
2625 DEFUN (missing_component_hook, args, nargout,
2627 @deftypefn {Built-in Function} {@var{val} =} missing_component_hook ()\n\
2628 @deftypefnx {Built-in Function} {@var{old_val} =} missing_component_hook (@var{new_val})\n\
2629 @deftypefnx {Built-in Function} {} missing_component_hook (@var{new_val}, \"local\")\n\
2630 Query or set the internal variable that specifies the function to call when\n\
2631 a component of Octave is missing. This can be useful for packagers that\n\
2632 may split the Octave installation into multiple sub-packages, for example,\n\
2633 to provide a hint to users for how to install the missing components.\n\
2635 When called from inside a function with the @qcode{\"local\"} option, the\n\
2636 variable is changed locally for the function and any subroutines it calls. \n\
2637 The original variable value is restored when exiting the function.\n\
2639 The hook function is expected to be of the form\n\
2642 @var{fcn} (@var{component})\n\
2645 Octave will call @var{fcn} with the name of the function that requires the\n\
2646 component and a string describing the missing component. The hook function\n\
2647 should return an error message to be displayed.\n\
2648 @seealso{missing_function_hook}\n\