26 #if defined (HAVE_CONFIG_H)
79 if (! s || ! (isalpha (*s) || *s ==
'_'))
83 if (! (isalnum (*s) || *s ==
'_'))
95 DEFUN (isvarname, args, ,
105 if (args.length () != 1)
110 if (args(0).is_string ())
112 std::string varname = args(0).string_value ();
144 DEFUN (is_same_file, args, ,
169 if (args.length () != 2)
174 bool s1_string = args(0).is_string ();
175 bool s1_cellstr = args(0).iscellstr ();
176 bool s2_string = args(1).is_string ();
177 bool s2_cellstr = args(1).iscellstr ();
179 if (s1_string && s2_string)
181 std::string file1 = args(0).string_value ();
182 std::string file2 = args(1).string_value ();
186 else if ((s1_string && s2_cellstr) || (s1_cellstr && s2_string))
193 cellstr_arg = args(1);
198 cellstr_arg = args(0);
211 else if (s1_cellstr && s2_cellstr)
220 error (
"is_same_file: cellstr arrays FILEPATH1 and FILEPATH2 must be the same size");
230 error (
"is_same_file: FILEPATH1 and FILEPATH2 must be strings or cell arrays of strings");
258 int min_match_len,
int case_sens)
260 int stdlen = std.length ();
261 int slen = s.length ();
263 return (slen <= stdlen
264 && slen >= min_match_len
266 ? (
strncmp (std.c_str (), s.c_str (), slen) == 0)
273 const std::string& s,
274 int min_toks_to_match,
int max_toks)
278 int toks_matched = 0;
280 if (s.empty () || max_toks < 1)
283 char *kw =
strsave (s.c_str ());
300 const char **to_match =
new const char * [max_toks + 1];
301 const char *
const *s1 = std;
302 const char **s2 = to_match;
309 while ((end = strchr (beg,
' ')) !=
nullptr)
321 if (tok_count >= max_toks)
326 s2[tok_count+1] =
nullptr;
332 if (!
almost_match (*s1, *s2, min_len[toks_matched], 0))
342 status = (toks_matched >= min_toks_to_match);
398 DEFMETHOD (file_in_loadpath, interp, args, ,
421 int nargin = args.length ();
423 if (nargin < 1 || nargin > 2)
426 string_vector names = args(0).xstring_vector_value (
"file_in_loadpath: FILE argument must be a string");
429 error (
"file_in_loadpath: FILE argument must not be empty");
437 std::string opt = args(1).xstring_value (
"file_in_loadpath: optional second argument must be a string");
440 error (R
"(file_in_loadpath: "all" is only valid second argument)");
492 int nargin = args.length ();
494 if (nargin < 2 || nargin > 3)
497 std::string
path = args(0).xstring_value (
"file_in_path: PATH must be a string");
499 string_vector names = args(1).xstring_vector_value (
"file_in_path: FILE argument must be a string");
502 error (
"file_in_path: FILE argument must not be empty");
508 std::string opt = args(2).xstring_value (
"file_in_path: optional third argument must be a string");
511 error (R
"(file_in_path: "all" is only valid third argument)");
543 std::string nm =
name;
545 if (! suffix.empty ())
554 const std::string& file,
555 bool require_regular_file)
557 std::string fname = file;
568 = fs.
exists () && (fs.
is_reg () || ! require_regular_file);
615 std::string fname =
name;
616 size_t pos =
name.find_first_of (
'>');
617 if (pos != std::string::npos)
618 fname =
name.substr (0, pos);
640 std::string tcontents
660 size_t len = s.length ();
666 if (s[j] ==
'\\' && j+1 <
len)
720 int tmpi = s[j] -
'0';
723 int digit = s[k] -
'0';
724 if (digit < 0 || digit > 7)
740 if (! isxdigit (s[k]))
746 tmpi += digit -
'a' + 10;
747 else if (digit >=
'A')
748 tmpi += digit -
'A' + 10;
754 warning (R
"(malformed hex escape sequence '\x' -- converting to '\0')");
762 warning (R
"(unrecognized escape sequence '\%c' -- converting to '%c')", s[j], s[j]);
791 if (args.length () != 1)
794 std::string str = args(0).xstring_value (
"do_string_escapes: STRING argument must be of type string");
877 static char retval[2] {
'\0',
'\0'};
889 for (
size_t i = 0; i < s.length (); i++)
927 if (args.length () != 1)
930 std::string str = args(0).xstring_value (
"undo_string_escapes: S argument must be a string");
957 DEFUN (is_absolute_filename, args, ,
964 if (args.length () != 1)
967 return ovl (args(0).is_string ()
978 DEFUN (is_rooted_relative_filename, args, ,
985 if (args.length () != 1)
988 return ovl (args(0).is_string ()
999 DEFUN (make_absolute_filename, args, ,
1010 if (args.length () != 1)
1013 std::string nm = args(0).xstring_value (
"make_absolute_filename: FILE argument must be a filename");
1025 DEFMETHOD (dir_in_loadpath, interp, args, ,
1048 int nargin = args.length ();
1050 if (nargin < 1 || nargin > 2)
1055 dir = args(0).xstring_value (
"dir_in_loadpath: DIR must be a directory name");
1102 int nargin = args.length ();
1111 if (args(0).is_string ())
1113 std::string nm = args(0).string_value ();
1119 int val = args(0).xint_value (
"errno: argument must be string or integer");
1145 DEFUN (errno_list, args, ,
1152 if (args.length () != 0)
1167 const char *warnfor)
1169 if (nr < 0 || nc < 0)
1172 "%s: converting negative dimension to zero", warnfor);
1174 nr = (nr < 0) ? 0 : nr;
1175 nc = (nc < 0) ? 0 : nc;
1183 for (
int i = 0; i < dim.
ndims (); i++)
1194 "%s: converting negative dimension to zero", warnfor);
1204 error (
"%s (A): use %s (size (A)) instead", warn_for, warn_for);
1239 if ((nr != 1 || nc != 2) && (nr != 2 || nc != 1))
1240 error (
"%s (A): use %s (size (A)) instead", warn_for, warn_for);
1290 error (
"dims_to_numel: invalid index %s", e.what ());
1303 if (nr > 0 && nc > 0)
1318 if (nr > 0 && nc > 0)
1329 size_t format (std::ostream& os,
const char *fmt, ...)
1334 va_start (args, fmt);
1343 size_t vformat (std::ostream& os,
const char *fmt, va_list args)
1352 size_t format (std::ostream& os,
const std::string& enc,
const char *fmt, ...)
1357 va_start (args, fmt);
1366 size_t vformat (std::ostream& os,
const std::string& enc,
const char *fmt,
1371 if (enc.compare (
"utf-8"))
1401 va_start (args, fmt);
1415 void sleep (
double seconds,
bool do_graphics_events)
1425 if (do_graphics_events)
1434 struct timespec one_tenth = { 0, 100000000 };
1442 if (do_graphics_events)
1452 double remaining_time = seconds;
1456 struct timespec nano_laps = { 0, 100000000 };
1458 while (remaining_time > 0.1)
1462 if (do_graphics_events)
1469 if (remaining_time < 0.1)
1479 if (remaining_time > 0.0)
1481 nano_laps = { 0,
static_cast<int> (remaining_time * 1e9) };
1506 int nargin = args.length ();
1508 if (nargin < 1 || nargin > 2)
1513 n = args(1).idx_type_value ();
1519 idx_vector idx = args(0).index_vector (
true);
1526 catch (
const octave::execution_exception&)
1528 interp.recover_from_exception ();
1555 int nargin = args.
length ();
1560 const Cell *ccells = cells;
1565 for (
int i = 0; i < nargin; i++)
1568 iscell[i] = arg.
iscell ();
1576 new_args(i) = ccells[i](0);
1578 else if (
numel == 1)
1581 dims = ccells[i].
dims ();
1583 else if (dims != ccells[i].dims ())
1584 error (
"%s: cell arguments must have matching sizes", fun_name);
1588 for (
int i = 0; i < nargout; i++)
1589 rcells[i].clear (dims);
1593 for (
int i = 0; i < nargin; i++)
1595 new_args(i) = ccells[i](j);
1601 if (tmp.
length () < nargout)
1602 error (
"%s: do_simple_cellfun: internal error", fun_name);
1604 for (
int i = 0; i < nargout; i++)
1605 rcells[i](j) = tmp(i);
1610 for (
int i = 0; i < nargout; i++)
1631 DEFUN (isstudent, args, ,
1640 if (args.length () != 0)
1682 int min_match_len,
int case_sens)
1689 const std::string& s,
int min_toks_to_match,
1716 bool require_regular_file)
charNDArray min(char d, const charNDArray &m)
void resize(const dim_vector &dv, const T &rfv)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
const dim_vector & dims(void) const
Return a const-reference so that dims ()(i) works efficiently.
Vector representing the dimensions (size) of an Array.
octave_idx_type numel(int n=0) const
Number of elements that a matrix with this dimensions would have.
void resize(int n, int fill_value=0)
bool isvector(void) const
octave_idx_type ndims(void) const
Number of dimensions.
dim_vector redim(int n) const
Force certain dimensionality, preserving numel ().
int process_events(bool force=false)
octave_idx_type length(octave_idx_type n=0) const
octave_idx_type extent(octave_idx_type n) const
std::string find_first_of(const std::list< std::string > &names)
std::list< std::string > find_all_first_of(const std::list< std::string > &names)
std::string find_first_of(const string_vector &files) const
std::string find_fcn_file(const std::string &fcn, const std::string &pack_name="")
string_vector find_all_first_of(const string_vector &files) const
string_vector find_matching_dirs(const std::string &dir) const
std::string find_dir(const std::string &dir) const
std::string find_file(const std::string &file) const
static bool rooted_relative_pathname(const std::string &s)
static bool absolute_pathname(const std::string &s)
static std::string make_absolute(const std::string &s, const std::string &dot_path=get_current_directory())
double double_value(void) const
static int lookup(const std::string &name)
static octave_scalar_map list(void)
octave_idx_type length(void) const
octave_idx_type rows(void) const
bool isnumeric(void) const
octave_idx_type numel(void) const
octave_idx_type idx_type_value(bool req_int=false, bool frc_str_conv=false) const
bool is_scalar_type(void) const
Cell cell_value(void) const
octave_idx_type columns(void) const
Array< octave_idx_type > octave_idx_type_vector_value(bool req_int=false, bool frc_str_conv=false, bool frc_vec_conv=false) const
std::string string_value(bool force=false) const
idx_vector index_vector(bool require_integers=false) const
Array< std::string > cellstr_value(void) const
bool is_magic_colon(void) const
dim_vector dims(void) const
octave_idx_type numel(void) const
std::list< std::string > std_list(void) const
OCTINTERP_API void print_usage(void)
#define DEFMETHOD(name, interp_name, args_name, nargout_name, doc)
Macro to define a builtin method.
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
#define DEFUNX(name, fname, args_name, nargout_name, doc)
Macro to define a builtin function with certain internal name.
void warning(const char *fmt,...)
void warning_with_id(const char *id, const char *fmt,...)
void error(const char *fmt,...)
void warn_data_file_in_path(const std::string &fcn, const std::string &file)
OCTAVE_API int octave_strncasecmp(const char *s1, const char *s2, size_t n)
F77_RET_T const F77_DBLE const F77_DBLE * f
static char * strsave(const char *s)
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.
OCTAVE_API std::string u8_to_encoding(const std::string &who, const std::string &u8_string, const std::string &encoding)
std::string concat(const std::string &dir, const std::string &file)
gh_manager & __get_gh_manager__(const std::string &who)
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
int almost_match(const std::string &std, const std::string &s, int min_match_len, int case_sens)
std::string vasprintf(const char *fmt, va_list args)
std::string contents_file_in_path(const std::string &dir)
bool valid_identifier(const char *s)
static void check_dimensions(octave_idx_type &nr, octave_idx_type &nc, const char *warnfor)
static double f(double k, double l_nu, double c_pm)
std::string do_string_escapes(const std::string &s)
bool same_file_internal(const std::string &file1, const std::string &file2)
bool iskeyword(const std::string &s)
string_vector search_path_for_all_files(const std::string &path, const string_vector &names)
const char * undo_string_escape(char c)
std::string asprintf(const char *fmt,...)
void sleep(double seconds, bool do_graphics_events)
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)
Matrix identity_matrix(octave_idx_type nr, octave_idx_type nc)
std::string fcn_file_in_path(const std::string &name)
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
size_t vformat(std::ostream &os, const char *fmt, va_list args)
std::string file_in_path(const std::string &name, const std::string &suffix)
std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file)
size_t format(std::ostream &os, const char *fmt,...)
FloatMatrix float_identity_matrix(octave_idx_type nr, octave_idx_type nc)
bool same_file(const std::string &f, const std::string &g)
std::string search_path_for_file(const std::string &path, const string_vector &names)
std::string undo_string_escapes(const std::string &s)
octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx_arg)
load_path & __get_load_path__(const std::string &who)
static string_vector make_absolute(const string_vector &sv)
int octave_nanosleep_wrapper(const struct timespec *requested, struct timespec *remaining)
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
T::size_type numel(const T &str)
octave_value::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.
std::string do_string_escapes(const std::string &s)
std::string find_data_file_in_load_path(const std::string &fcn, const std::string &file, bool require_regular_file)
octave_idx_type dims_to_numel(const dim_vector &dims, const octave_value_list &idx)
std::string undo_string_escapes(const std::string &s)
int almost_match(const std::string &std, const std::string &s, int min_match_len, int case_sens)
int keyword_almost_match(const char *const *std, int *min_len, const std::string &s, int min_toks_to_match, int max_toks)
Matrix identity_matrix(octave_idx_type nr, octave_idx_type nc)
std::string file_in_path(const std::string &name, const std::string &suffix)
void get_dimensions(const octave_value &a, const char *warn_for, dim_vector &dim)
bool valid_identifier(const char *s)
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)
FloatMatrix float_identity_matrix(octave_idx_type nr, octave_idx_type nc)
void octave_sleep(double seconds)
OCTAVE_EXPORT octave_value_list Ferrno(const octave_value_list &args, int)
string_vector search_path_for_all_files(const std::string &path, const string_vector &names)
std::string contents_file_in_path(const std::string &s)
size_t octave_vformat(std::ostream &os, const char *fmt, va_list args)
std::string fcn_file_in_path(const std::string &s)
const char * undo_string_escape(char c)
std::string search_path_for_file(const std::string &path, const string_vector &names)
void check_dimensions(dim_vector &dim, const char *warnfor)
bool same_file(const std::string &f, const std::string &g)
std::string octave_vasprintf(const char *fmt, va_list args)
int octave_vasprintf_wrapper(char **buf, const char *fmt, va_list args)