29 #if defined (HAVE_CONFIG_H)
52 #if defined (OCTAVE_USE_WINDOWS_API)
53 # define WIN32_LEAN_AND_MEAN 1
60 #define IS_DEVICE_SEP(ch) octave::sys::file_ops::is_dev_sep (ch)
61 #define NAME_BEGINS_WITH_DEVICE(name) \
62 (name.length () > 0 && IS_DEVICE_SEP ((name)[1]))
64 #define DIR_SEP_STRING octave::sys::file_ops::dir_sep_str ()
65 #define IS_DIR_SEP(ch) octave::sys::file_ops::is_dir_sep (ch)
67 #define ENV_SEP octave::directory_path::path_sep_char ()
68 #define ENV_SEP_STRING octave::directory_path::path_sep_str ()
69 #define IS_ENV_SEP(ch) octave::directory_path::is_path_sep (ch)
72 #if ! defined (NO_DEBUG)
78 # define KPSE_DEBUG_P(bit) (kpse_debug & (1 << (bit)))
80 # define KPSE_DEBUG_STAT 0 // stat calls
81 # define KPSE_DEBUG_EXPAND 1 // path element expansion
82 # define KPSE_DEBUG_SEARCH 2 // searches
83 # define KPSE_DEBUG_VARS 3 // variable values
84 # define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
102 b =
e = std::string::npos;
123 b =
e = std::string::npos;
135 unsigned ret_len = 0;
139 size_t len = name.
length ();
141 for (
size_t i = 0;
i < len;
i++)
155 ret[ret_len++] = name[
i];
159 ret.resize (ret_len);
169 #if defined (OCTAVE_USE_WINDOWS_API)
173 const char *
t = fn.c_str ();
174 return (GetFileAttributes (t) != 0xFFFFFFFF
175 && ! (GetFileAttributes (t) & FILE_ATTRIBUTE_DIRECTORY));
183 const char *t = fn.c_str ();
189 retval = fs && ! fs.
is_dir ();
211 #if defined (ENAMETOOLONG)
213 else if (errno == ENAMETOOLONG)
234 perror (name.c_str ());
266 for (
const auto &
filename : filenames)
284 static std::list<std::string>
288 std::list<std::string> ret;
296 ret.push_back (potential);
308 static std::list<std::string>
311 std::list<std::string> ret_list;
316 ret_list.push_back (found);
324 static std::list<std::string>
327 std::list<std::string> ret_list;
334 std::list<std::string>
found;
339 while (elt.length () > 3
344 elt = elt.substr (1);
350 while (elt.length () > 1
352 elt = elt.substr (1);
358 found = std::list<std::string> ();
371 if (! found.empty ())
374 ret_list.splice (ret_list.end (),
found);
377 ret_list.push_back (found.front ());
394 static std::list<std::string>
398 std::list<std::string> ret_list;
409 std::cerr <<
"kdebug: start search (file=" << name
410 <<
", find_all=" << all <<
", path=" << path <<
")."
414 ret_list = (absolute_p
422 first_search =
false;
430 std::cerr <<
"kdebug: search (" << original_name <<
") =>";
435 std::cerr << std::endl;
458 std::list<std::string> ret_list =
search (path, name,
false);
460 return ret_list.empty () ?
"" : ret_list.front ();
466 std::list<std::string>
469 return search (path, name,
true);
476 std::list<std::string>
478 const std::list<std::string>& names,
bool all)
480 std::list<std::string> ret_list;
488 std::list<std::string>
found;
494 while (elt.length () > 3
499 elt = elt.substr (1);
505 while (elt.length () > 1
507 elt = elt.substr (1);
515 for (
auto it = names.cbegin (); it != names.cend () && !
done; it++)
522 found = std::list<std::string> ();
530 if (! found.empty ())
533 ret_list.splice (ret_list.end (),
found);
536 ret_list.push_back (found.front ());
547 static std::list<std::string>
551 std::list<std::string> ret_list;
555 std::cerr <<
"kdebug: start find_first_of (";
557 for (
auto p = names.cbegin ();
p != names.cend ();
p++)
559 if (
p == names.cbegin ())
562 std::cerr <<
", " << *
p;
565 std::cerr <<
"), path=" << path <<
"." << std::endl;
568 for (
const auto &
name : names)
578 if (! ret_list.empty ())
590 first_search =
false;
599 std::cerr <<
"kdebug: find_first_of (";
601 for (
auto p = names.cbegin ();
p != names.cend ();
p++)
603 if (
p == names.cbegin ())
606 std::cerr <<
", " << *
p;
615 std::cerr << std::endl;
629 const std::list<std::string>& names)
631 std::list<std::string> ret_list =
find_first_of (path, names,
false);
633 return ret_list.empty () ?
"" : ret_list.front ();
643 std::list<std::string>
645 const std::list<std::string>& names)
660 if (name.empty () || name[0] !=
'~')
668 else if (name.length () == 1)
672 if (expansion.empty ())
686 size_t home_len = home.length ();
690 home = home.substr (1);
696 expansion = home + name.substr (c);
702 #if defined (HAVE_PWD_H)
707 while (name.length () > c && !
IS_DIR_SEP (name[c]))
724 home = home.substr (1);
727 if (name.length () > c &&
IS_DIR_SEP (home[home.length () - 1]))
730 expansion = name.length () > c ? home : home + name.substr (c);
764 if (kpse_dot.empty ())
773 size_t elt_len = elt.length ();
777 else if (elt_len == 1 && elt[0] ==
'.')
779 else if (elt_len > 1 && elt[0] ==
'.' &&
IS_DIR_SEP (elt[1]))
785 int len = ret.length ();
804 for (
const auto &expanded_elt : expansions)
821 ret.resize (ret.length () - 1);
852 size_t len = ret.length ();
887 while (elt.length () > 3
892 elt = elt.substr (1);
898 while (elt.length () > 1
900 elt = elt.substr (1);
907 size_t dirlen = dir.length ();
938 #define brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n')
954 static std::list<std::string>
956 const std::list<std::string>& arr2)
958 std::list<std::string>
result;
962 else if (arr2.empty ())
966 for (
const auto &elt_2 : arr2)
967 for (
const auto &elt_1 : arr1)
968 result.push_back (elt_1 + elt_2);
978 static std::list<std::string>
987 std::list<std::string>
result (1, preamble);
998 (*current_liboctave_warning_with_id_handler)
999 (
"Octave:pathsearch-syntax",
1000 "%s: Unmatched {", text.c_str ());
1002 result = std::list<std::string> (1,
text);
1024 static std::list<std::string>
1027 std::list<std::string>
result;
1029 size_t text_len = text.length ();
1033 for (start = 0, i = 0, c = 1; c && start < text_len; start = ++
i)
1040 i = (i0 < i1 ? i0 : i1);
1046 if (result.empty ())
1049 result.splice (result.end (), partial);
1067 size_t text_len = text.length ();
1071 for (; i < text_len; i++)
1083 if (c ==
'\\' && (quoted == 0 || quoted ==
'"' || quoted ==
'`'))
1096 if (c ==
'"' || c ==
'\'' || c ==
'`')
1102 if (c == satisfy && ! level && ! quoted)
1114 if ((c !=
'{') || i == 0 || (text[i-1] !=
'$'))
1120 else if (c ==
'}' && level)
1142 size_t path_len = path.length ();
1145 expansion = fallback;
1150 expansion = path_len == 1 ? fallback : fallback + path;
1159 expansion = path + fallback;
1167 for (
size_t i = 0;
i < path_len;
i++)
1169 if (
i + 1 < path_len
1176 expansion = path.substr (0, i+1) + fallback + path.substr (i+1);
1194 return (fs && fs.
is_dir ());
1217 char last_char = ret[ret.length () - 1];
1239 expansions[
var] = xp;
1247 return (expansions.find (var) != expansions.end ()) ? expansions[var] :
false;
1259 (*current_liboctave_warning_with_id_handler)
1260 (
"Octave:pathsearch-syntax",
1261 "pathsearch: variable '%s' references itself (eventually)",
1269 if (! value.empty ())
1283 #if ! defined (IS_VAR_START)
1284 # define IS_VAR_START(c) ((c) == '$')
1288 #if ! defined (IS_VAR_CHAR)
1289 # define IS_VAR_CHAR(c) (isalnum (c) || (c) == '_')
1293 #if ! defined (IS_VAR_BEGIN_DELIMITER)
1294 # define IS_VAR_BEGIN_DELIMITER(c) ((c) == '{')
1297 #if ! defined (IS_VAR_END_DELIMITER)
1298 # define IS_VAR_END_DELIMITER(c) ((c) == '}')
1309 size_t src_len = src.length ();
1312 for (
size_t i = 0;
i < src_len;
i++)
1331 expand (expansion, src.substr (i, var_end - i + 1));
1338 size_t var_end = ++
i;
1343 if (var_end == src_len)
1345 (*current_liboctave_warning_with_id_handler)
1346 (
"Octave:pathsearch-syntax",
1347 "%s: No matching } for ${", src.c_str ());
1352 expand (expansion, src.substr (i, var_end - i));
1359 (*current_liboctave_warning_with_id_handler)
1360 (
"Octave:pathsearch-syntax",
1361 "%s: Unrecognized variable construct '$%c'",
1362 src.c_str (), src[
i]);
1368 expansion += src[
i];
static password getpwnam(const std::string &nm)
#define IS_VAR_BEGIN_DELIMITER(c)
std::list< std::string > kpse_all_path_find_first_of(const std::string &path, const std::list< std::string > &names)
time_t unix_time(void) const
static bool dir_p(const std::string &fn)
static bool is_path_sep(char c)
static int brace_gobbler(const std::string &, int &, int)
in that an updated permutation matrix is returned Note that if var
static void expand(std::string &expansion, const std::string &var)
static std::list< std::string > expand_amble(const std::string &)
octave_idx_type length(void) const
static std::string kpse_brace_expand_element(const std::string &elt)
#define brace_whitespace(c)
static bool expanding_p(const std::string &var)
static std::string kpse_readable_file(const std::string &name)
static std::list< std::string > absolute_search(const std::string &name)
std::string kpse_path_expand(const std::string &path)
static bool rooted_relative_pathname(const std::string &s)
#define KPSE_DEBUG_SEARCH
OCTAVE_EXPORT octave_value_list return the number of command line arguments passed to Octave If called with the optional argument the function t
static std::map< std::string, bool > expansions
std::list< std::string > path_find_first_of(const std::string &path, const std::list< std::string > &names, bool all)
static void log_search(const std::list< std::string > &filenames)
int octave_access_wrapper(const char *nm, int mode)
std::string kpse_path_search(const std::string &path, const std::string &name)
static std::list< std::string > array_concat(const std::list< std::string > &arr1, const std::list< std::string > &arr2)
static std::string getenv(const std::string &name)
static std::list< std::string > brace_expand(const std::string &)
int octave_access_r_ok(void)
OCTAVE_EXPORT octave_value_list search each directory of the loadpath for element of the cell array and return the first that matches If the second optional argument return a cell array containing the list of all files that have the same name in the path If no files are found
std::string kpse_path_find_first_of(const std::string &path, const std::list< std::string > &names)
std::string dir(void) const
static std::string get_home_directory(void)
static bool absolute_pathname(const std::string &s)
std::string kpse_expand_default(const std::string &path, const std::string &fallback)
static std::string kpse_expand(const std::string &s)
static std::string kpse_tilde_expand(const std::string &name)
static std::list< std::string > search(const std::string &path, const std::string &original_name, bool all)
std::list< std::string > kpse_all_path_search(const std::string &path, const std::string &name)
static std::list< std::string > find_first_of(const std::string &path, const std::list< std::string > &names, bool all)
the sparsity preserving column transformation such that that defines the pivoting threshold can be given in which case it defines the c
#define KPSE_DEBUG_P(bit)
With real return the complex result
OCTAVE_EXPORT octave_value_list the first data row corresponds to an index of zero The a spreadsheet style form such as the file is read until end of file is reached The such as text
#define NAME_BEGINS_WITH_DEVICE(name)
static std::list< std::string > path_search(const std::string &path, const std::string &name, bool all)
=val(i)}if ode{val(i)}occurs in table i
OCTAVE_EXPORT octave_value_list or N dimensional array whose elements are all equal to the IEEE symbol zero divided by nd tex zero divided by nd ifnottex and any operation involving another NaN value(5+NaN).Note that NaN always compares not equal to NaN(NaN!
static int brace_arg_separator
static std::string kpse_var_expand(const std::string &src)
static std::list< std::string > dir_search(const std::string &dir, const std::string &name, bool search_all)
octave::sys::file_stat fs(filename)
static std::string kpse_brace_expand(const std::string &path)
static std::string kpse_truncate_filename(const std::string &name)
#define IS_VAR_END_DELIMITER(c)
static bool READABLE(const std::string &fn)
std::string kpse_element_dir(const std::string &elt)
static std::string kpse_expand_kpse_dot(const std::string &path)
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
#define IS_DEVICE_SEP(ch)
static unsigned int max_name_length(void)
static void expanding(const std::string &var, bool xp)
F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &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 F77_REAL &F77_RET_T F77_DBLE &F77_RET_T F77_DBLE &F77_RET_T F77_REAL &F77_RET_T F77_REAL &F77_RET_T F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T F77_REAL F77_REAL &F77_RET_T F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE * x
static bool kpse_absolute_p(const std::string &filename, int relative_ok)