24 #if defined (HAVE_CONFIG_H) 76 if (!
s || ! (isalpha (*
s) || *
s ==
'_' || *
s ==
'$'))
80 if (! (isalnum (*
s) || *
s ==
'_' || *
s ==
'$'))
92 DEFUN (isvarname, args, ,
99 if (args.length () != 1)
104 if (args(0).is_string ())
139 int stdlen =
std.length ();
140 int slen =
s.length ();
142 return (slen <= stdlen
143 && slen >= min_match_len
154 int min_toks_to_match,
int max_toks)
158 int toks_matched = 0;
160 if (
s.empty () || max_toks < 1)
180 const char **to_match =
new const char * [max_toks + 1];
181 const char *
const *s1 =
std;
182 const char **
s2 = to_match;
189 while ((end = strchr (beg,
' ')) !=
nullptr)
201 if (tok_count >= max_toks)
206 s2[tok_count+1] =
nullptr;
222 status = (toks_matched >= min_toks_to_match);
241 return (nr == 0 || nc == 0);
284 DEFMETHOD (file_in_loadpath, interp, args, ,
307 int nargin = args.length ();
312 string_vector names = args(0).xstring_vector_value (
"file_in_loadpath: FILE argument must be a string");
315 error (
"file_in_loadpath: FILE argument must not be empty");
323 std::string opt = args(1).xstring_value (
"file_in_loadpath: optional second argument must be a string");
326 error (R
"(file_in_loadpath: "all" is only valid second argument)"); 378 int nargin = args.length ();
383 std::string path = args(0).xstring_value (
"file_in_path: PATH must be a string");
385 string_vector names = args(1).xstring_vector_value (
"file_in_path: FILE argument must be a string");
388 error (
"file_in_path: FILE argument must not be empty");
394 std::string opt = args(2).xstring_value (
"file_in_path: optional third argument must be a string");
397 error (R
"(file_in_path: "all" is only valid third argument)"); 430 if (! suffix.empty ())
441 bool require_regular_file)
485 int len =
name.length ();
496 else if (len > 2 &&
name[len - 2] ==
'.' &&
name[len - 1] ==
'm')
505 size_t pos =
name.find_first_of (
'>');
506 if (pos != std::string::npos)
551 int len =
name.length ();
562 else if (len > 4 &&
name.find (
".oct", len-5))
588 int len =
name.length ();
599 else if (len > 4 &&
name.find (
".mex", len-5))
625 size_t len =
s.length ();
631 if (
s[j] ==
'\\' && j+1 < len)
685 int tmpi =
s[j] -
'0';
688 int digit =
s[
k] -
'0';
689 if (digit < 0 || digit > 7)
705 if (! isxdigit (
s[
k]))
711 tmpi += digit -
'a' + 10;
712 else if (digit >=
'A')
713 tmpi += digit -
'A' + 10;
719 warning (R
"(malformed hex escape sequence '\x' -- converting to '\0')"); 727 warning (R
"(unrecognized escape sequence '\%c' -- converting to '%c')", s[j], s[j]); 755 if (args.length () != 1)
758 std::string str = args(0).xstring_value (
"do_string_escapes: STRING argument must be of type string");
840 static char retval[2] {
'\0',
'\0'};
853 for (
size_t i = 0;
i <
s.length ();
i++)
890 if (args.length () != 1)
893 std::string str = args(0).xstring_value (
"undo_string_escapes: S argument must be a string");
920 DEFUN (is_absolute_filename, args, ,
927 if (args.length () != 1)
930 return ovl (args(0).is_string ()
948 if (args.length () != 1)
951 return ovl (args(0).is_string ()
962 DEFUN (make_absolute_filename, args, ,
972 if (args.length () != 1)
975 std::string nm = args(0).xstring_value (
"make_absolute_filename: FILE argument must be a filename");
987 DEFMETHOD (dir_in_loadpath, interp, args, ,
1010 int nargin = args.length ();
1017 dir = args(0).xstring_value (
"dir_in_loadpath: DIR must be a directory name");
1045 DEFUNX (
"errno", Ferrno, args, ,
1064 int nargin = args.length ();
1073 if (args(0).is_string ())
1081 int val = args(0).xint_value (
"errno: argument must be string or integer");
1107 DEFUN (errno_list, args, ,
1114 if (args.length () != 0)
1129 if (nr < 0 || nc < 0)
1132 "%s: converting negative dimension to zero", warnfor);
1134 nr = (nr < 0) ? 0 : nr;
1135 nc = (nc < 0) ? 0 : nc;
1144 for (
int i = 0;
i < dim.
ndims ();
i++)
1155 "%s: converting negative dimension to zero", warnfor);
1165 if (!
a.dims ().isvector ())
1166 error (
"%s (A): use %s (size (A)) instead", warn_for, warn_for);
1193 if (
a.is_scalar_type ())
1195 nr = nc =
a.idx_type_value ();
1202 if ((nr != 1 || nc != 2) && (nr != 2 || nc != 1))
1203 error (
"%s (A): use %s (size (A)) instead", warn_for, warn_for);
1218 ? 0 :
a.idx_type_value (
"%s: row dimension must be a scalar", warn_for);
1220 ? 0 :
b.idx_type_value (
"%s: column dimension must be a scalar", warn_for);
1258 error (
"dims_to_numel: Invalid IDX %s. %s",
1259 idx.c_str (), msg.c_str ());
1273 if (nr > 0 && nc > 0)
1289 if (nr > 0 && nc > 0)
1306 va_start (args, fmt);
1349 va_start (args, fmt);
1372 double fraction = std::modf (seconds, &seconds);
1378 fraction = std::modf (fraction * 10, &tenths) / 10;
1379 fraction =
std::round (fraction * 1000000000);
1383 struct timespec hundredths_delay = { 0,
static_cast<long> (fraction) };
1390 struct timespec one_tenth = { 0, 100000000 };
1392 for (
int i = 0; i < static_cast<int> (tenths);
i++)
1404 :
static_cast<time_t
> (seconds));
1406 for (time_t
s = 0;
s < sec;
s++)
1408 for (
int i = 0;
i < 10;
i++)
1417 DEFUN (isindex, args, ,
1435 int nargin = args.length ();
1442 n = args(1).idx_type_value ();
1453 idx_vector idx = args(0).index_vector (
true);
1460 catch (
const octave::execution_exception&)
1492 const Cell *ccells = cells;
1508 new_args(
i) = ccells[
i](0);
1510 else if (
numel == 1)
1516 error (
"%s: cell arguments must have matching sizes", fun_name);
1521 rcells[
i].clear (
dims);
1527 new_args(
i) = ccells[
i](j);
1534 error (
"%s: do_simple_cellfun: internal error", fun_name);
1537 rcells[
i](j) =
tmp(
i);
1556 if (
tmp.length () > 0)
1562 DEFUN (isstudent, args, ,
void warning_with_id(const char *id, const char *fmt,...)
std::string find_first_of(const string_vector &files) const
OCTINTERP_API void octave_sleep(double seconds)
For example cd octave end example noindent changes the current working directory to file
bool same_file(const std::string &f, const std::string &g)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
OCTINTERP_API std::string oct_file_in_path(const std::string &)
static void recover_from_exception(void)
octave_idx_type extent(octave_idx_type n) const
OCTAVE_EXPORT octave_value_list who nd deftypefn *octave_value retval
OCTINTERP_API void print_usage(void)
idx_vector index_vector(bool require_integers=false) const
OCTINTERP_API size_t octave_vformat(std::ostream &os, const char *fmt, va_list args)
identity matrix If supplied two scalar respectively For allows like xample val
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE * f
OCTINTERP_API std::string undo_string_escapes(const std::string &s)
OCTINTERP_API std::string fcn_file_in_path(const std::string &)
octave_value_list & append(const octave_value &val)
string_vector find_all_first_of(const string_vector &files) const
static string_vector make_absolute(const string_vector &sv)
void resize(int n, int fill_value=0)
is already an absolute name
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
OCTINTERP_API octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx)
std::string find_oct_file(const std::string &fcn, const std::string &pack_name="")
void error(const char *fmt,...)
bool is_magic_colon(void) const
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
int empty_arg(const char *, octave_idx_type nr, octave_idx_type nc)
OCTINTERP_API std::string file_in_path(const std::string &, const std::string &)
static bool rooted_relative_pathname(const std::string &s)
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
std::string find_mex_file(const std::string &fcn, const std::string &pack_name="")
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
std::string find_dir(const std::string &dir) const
OCTAVE_API int octave_strncasecmp(const char *s1, const char *s2, size_t n)
std::string find_fcn_file(const std::string &fcn, const std::string &pack_name="")
calling an anonymous function involves an overhead quite comparable to the overhead of an m file function Passing a handle to a built in function is because the interpreter is not involved in the internal loop For a
int almost_match(const std::string &std, const std::string &s, int min_match_len, int case_sens)
int octave_vasprintf_wrapper(char **buf, const char *fmt, va_list args)
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
std::string concat(const std::string &dir, const std::string &file)
OCTINTERP_API std::string contents_file_in_path(const std::string &)
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function xample nargout(@histc)
void warn_data_file_in_path(const std::string &fcn, const std::string &file)
OCTINTERP_API std::string octave_asprintf(const char *fmt,...)
bool valid_identifier(const char *s)
octave_idx_type numel(const octave_value_list &idx)
bool same_file_internal(const std::string &file1, const std::string &file2)
OCTINTERP_API std::string octave_vasprintf(const char *fmt, va_list args)
std::string find_file(const std::string &file) const
static bool absolute_pathname(const std::string &s)
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
octave_idx_type length(octave_idx_type n=0) const
OCTAVE_EXPORT octave_value_list is_rooted_relative_filename
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
bool is_keyword(const std::string &s)
OCTINTERP_API size_t octave_format(std::ostream &os, const char *fmt,...)
the exceeded dimensions are set to if fewer subscripts than dimensions are the exceeding dimensions are merged into the final requested dimension For consider the following dims
return ovl(undo_string_escapes(str))
load_path & __get_load_path__(const std::string &who)
With real return the complex result
std::string search_path_for_file(const std::string &path, const string_vector &names)
OCTINTERP_API void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
OCTINTERP_API FloatMatrix float_identity_matrix(octave_idx_type nr, octave_idx_type nc)
void warning(const char *fmt,...)
octave::unwind_protect frame
charNDArray max(char d, const charNDArray &m)
T::size_type numel(const T &str)
static char * strsave(const char *s)
OCTINTERP_API std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file=false)
OCTINTERP_API const char * undo_string_escape(char c)
OCTINTERP_API std::string do_string_escapes(const std::string &s)
static int lookup(const std::string &name)
OCTINTERP_API Matrix identity_matrix(octave_idx_type nr, octave_idx_type nc)
OCTINTERP_API octave_value_list do_simple_cellfun(octave_value_list(*fun)(const octave_value_list &, int), const char *fun_name, const octave_value_list &args, int nargout)
octave_idx_type length(void) const
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
OCTINTERP_API std::string mex_file_in_path(const std::string &)
octave::sys::file_stat fs(filename)
void resize(octave_idx_type n, const octave_value &rfv=octave_value())
static octave_scalar_map list(void)
octave_idx_type ndims(void) const
Number of dimensions.
string_vector search_path_for_all_files(const std::string &path, const string_vector &names)
bool strncmp(const T &str_a, const T &str_b, const typename T::size_type n)
True if the first N characters are the same.
std::list< std::string > std_list(void) const
octave_idx_type numel(void) const
Number of elements in the array.
Vector representing the dimensions (size) of an Array.
bool discard_error_messages
int octave_nanosleep_wrapper(const struct timespec *requested, struct timespec *remaining)
OCTINTERP_API void check_dimensions(dim_vector &dim, const char *warnfor)
If this string is the system will ring the terminal sometimes it is useful to be able to print the original representation of the string
Cell cell_value(void) const
bool isnumeric(void) const
string_vector find_matching_dirs(const std::string &dir) const
charNDArray min(char d, const charNDArray &m)