31 #if defined (HAVE_CONFIG_H)
54 #if defined (OCTAVE_USE_WINDOWS_API)
55 # define WIN32_LEAN_AND_MEAN 1
64 #define IS_DEVICE_SEP(ch) octave::sys::file_ops::is_dev_sep (ch)
65 #define NAME_BEGINS_WITH_DEVICE(name) \
66 (name.length () > 0 && IS_DEVICE_SEP ((name)[1]))
68 #define DIR_SEP_STRING octave::sys::file_ops::dir_sep_str ()
69 #define IS_DIR_SEP(ch) octave::sys::file_ops::is_dir_sep (ch)
71 #define ENV_SEP octave::directory_path::path_sep_char ()
72 #define ENV_SEP_STRING octave::directory_path::path_sep_str ()
73 #define IS_ENV_SEP(ch) octave::directory_path::is_path_sep (ch)
76 #if ! defined (NO_DEBUG)
82 # define KPSE_DEBUG_P(bit) (kpse_debug & (1 << (bit)))
84 # define KPSE_DEBUG_STAT 0
85 # define KPSE_DEBUG_EXPAND 1
86 # define KPSE_DEBUG_SEARCH 2
87 # define KPSE_DEBUG_VARS 3
88 # define KPSE_LAST_DEBUG KPSE_DEBUG_VARS
102 m_b =
m_e = std::string::npos;
123 m_b =
m_e = std::string::npos;
135 unsigned ret_len = 0;
137 std::string ret = name;
139 std::size_t m_len = name.length ();
141 for (std::size_t i = 0; i < m_len; i++)
148 else if (c_len > octave::sys::dir_entry::max_name_length ())
155 ret[ret_len++] = name[i];
159 ret.resize (ret_len);
172 #if defined (OCTAVE_USE_WINDOWS_API)
176 DWORD f_attr = GetFileAttributesW (w_fn.c_str ());
178 return (f_attr != 0xFFFFFFFF && ! (f_attr & FILE_ATTRIBUTE_DIRECTORY));
184 const char *t = fn.c_str ();
188 octave::sys::file_stat fs (fn);
190 retval = fs && ! fs.is_dir ();
213 #if defined (ENAMETOOLONG)
215 else if (errno == ENAMETOOLONG)
236 perror (name.c_str ());
250 && octave::sys::env::rooted_relative_pathname (filename)));
268 for (
const auto& filename : filenames)
270 octave::sys::time now;
271 std::cerr << now.unix_time () <<
' ' << filename << std::endl;
286 static std::list<std::string>
290 std::list<std::string> ret;
292 std::string potential = dir + name;
298 ret.push_back (potential);
310 static std::list<std::string>
313 std::list<std::string> ret_list;
318 ret_list.push_back (found);
326 static std::list<std::string>
327 path_search (
const std::string& path,
const std::string& name,
bool all)
329 std::list<std::string> ret_list;
334 std::string elt = *
pi;
336 std::list<std::string> found;
341 while (elt.length () > 3
346 elt = elt.substr (1);
349 #if (! defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
350 && ! defined (DOUBLE_SLASH_IS_DISTINCT_ROOT))
354 while (elt.length () > 1
356 elt = elt.substr (1);
363 found = std::list<std::string> ();
376 if (! found.empty ())
379 ret_list.splice (ret_list.end (), found);
382 ret_list.push_back (found.front ());
398 std::string expansion;
401 if (name.empty () || name[0] !=
'~')
409 else if (name.length () == 1)
411 expansion = octave::sys::env::get_home_directory ();
413 if (expansion.empty ())
422 std::string home = octave::sys::env::get_home_directory ();
427 std::size_t home_len = home.length ();
429 #if (! defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
430 && ! defined (DOUBLE_SLASH_IS_DISTINCT_ROOT))
433 home = home.substr (1);
440 expansion = home + name.substr (c);
446 #if defined (HAVE_PWD_H)
451 while (name.length () > c && !
IS_DIR_SEP (name[c]))
454 std::string user = name.substr (1, c-1);
458 octave::sys::password p = octave::sys::password::getpwnam (user);
461 std::string home = (p ? p.dir () :
".");
466 # if (! defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
467 && ! defined (DOUBLE_SLASH_IS_DISTINCT_ROOT))
470 home = home.substr (1);
474 if (name.length () > c &&
IS_DIR_SEP (home.back ()))
477 expansion = (name.length () > c ? home : home + name.substr (c));
494 static std::list<std::string>
495 search (
const std::string& path,
const std::string& original_name,
498 std::list<std::string> ret_list;
509 std::cerr <<
"kdebug: start search (file=" << name
510 <<
", find_all=" << all <<
", path=" << path <<
")."
514 ret_list = (absolute_p
530 std::cerr <<
"kdebug: search (" << original_name <<
") =>";
535 std::cerr << std::endl;
558 std::list<std::string> ret_list =
search (path, name,
false);
560 return ret_list.empty () ?
"" : ret_list.front ();
566 std::list<std::string>
569 return search (path, name,
true);
576 std::list<std::string>
578 const std::list<std::string>& names,
bool all)
580 std::list<std::string> ret_list;
585 std::string elt = *
pi;
588 std::list<std::string> found;
594 while (elt.length () > 3
599 elt = elt.substr (1);
602 #if (! defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
603 && ! defined (DOUBLE_SLASH_IS_DISTINCT_ROOT))
607 while (elt.length () > 1
609 elt = elt.substr (1);
618 for (
auto it = names.cbegin (); it != names.cend () && ! done; it++)
620 std::string name = *it;
625 found = std::list<std::string> ();
633 if (! found.empty ())
636 ret_list.splice (ret_list.end (), found);
639 ret_list.push_back (found.front ());
650 static std::list<std::string>
651 find_first_of (
const std::string& path,
const std::list<std::string>& names,
654 std::list<std::string> ret_list;
658 std::cerr <<
"kdebug: start find_first_of (";
660 for (
auto p = names.cbegin (); p != names.cend (); p++)
662 if (p == names.cbegin ())
665 std::cerr <<
", " << *p;
668 std::cerr <<
"), path=" << path <<
'.' << std::endl;
671 for (
const auto& name : names)
681 if (! ret_list.empty ())
702 std::cerr <<
"kdebug: find_first_of (";
704 for (
auto p = names.cbegin (); p != names.cend (); p++)
706 if (p == names.cbegin ())
709 std::cerr <<
", " << *p;
718 std::cerr << std::endl;
732 const std::list<std::string>& names)
734 std::list<std::string> ret_list =
find_first_of (path, names,
false);
736 return ret_list.empty () ?
"" : ret_list.front ();
746 std::list<std::string>
748 const std::list<std::string>& names)
773 while (elt.length () > 3
778 elt = elt.substr (1);
781 #if (! defined (OCTAVE_HAVE_WINDOWS_FILESYSTEM) \
782 && ! defined (DOUBLE_SLASH_IS_DISTINCT_ROOT))
786 while (elt.length () > 1
788 elt = elt.substr (1);
796 std::size_t dirlen = dir.length ();
827 #define brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n')
843 static std::list<std::string>
845 const std::list<std::string>& arr2)
847 std::list<std::string> result;
851 else if (arr2.empty ())
855 for (
const auto& elt_2 : arr2)
856 for (
const auto& elt_1 : arr1)
857 result.push_back (elt_1 + elt_2);
864 static std::list<std::string>
expand_amble (
const std::string&);
867 static std::list<std::string>
874 std::string preamble = text.substr (0, i);
876 std::list<std::string> result (1, preamble);
887 (*current_liboctave_warning_with_id_handler)
888 (
"Octave:pathsearch-syntax",
889 "%s: Unmatched {", text.c_str ());
891 result = std::list<std::string> (1, text);
895 std::string amble = text.substr (start, i-start);
898 std::string postamble = text.substr (i+1);
913 static std::list<std::string>
916 std::list<std::string> result;
918 std::size_t text_len = text.length ();
922 for (start = 0, i = 0, c = 1; c && start < text_len; start = ++i)
929 i = (i0 < i1 ? i0 : i1);
931 std::string tem = text.substr (start, i-start);
938 result.splice (result.end (), partial);
956 std::size_t text_len = text.length ();
958 std::size_t i = indx;
960 for (; i < text_len; i++)
972 if (c ==
'\\' && (quoted == 0 || quoted ==
'"' || quoted ==
'`'))
985 if (c ==
'"' || c ==
'\'' || c ==
'`')
991 if (c == satisfy && ! level && ! quoted)
1003 if ((c !=
'{') || i == 0 || (text[i-1] !=
'$'))
1009 else if (c ==
'}' && level)
1014 c = (c == satisfy) ? c : 0;
1024 octave::sys::file_stat fs (fn);
1026 return (fs && fs.is_dir ());
1049 char last_char = ret.back ();
const std::string & m_path
std::string kpse_path_find_first_of(const std::string &path, const std::list< std::string > &names)
#define NAME_BEGINS_WITH_DEVICE(name)
static std::list< std::string > brace_expand(const std::string &text)
static void log_search(const std::list< std::string > &filenames)
#define KPSE_DEBUG_SEARCH
static std::string kpse_tilde_expand(const std::string &name)
std::string kpse_element_dir(const std::string &elt)
static std::list< std::string > dir_search(const std::string &dir, const std::string &name, bool search_all)
static int brace_arg_separator
static std::list< std::string > absolute_search(const std::string &name)
static std::list< std::string > expand_amble(const std::string &)
static int brace_gobbler(const std::string &, int &, int)
std::string kpse_path_expand(const std::string &path)
std::list< std::string > kpse_all_path_find_first_of(const std::string &path, const std::list< std::string > &names)
static bool kpse_absolute_p(const std::string &filename, int relative_ok)
static std::list< std::string > path_search(const std::string &path, const std::string &name, bool all)
static std::list< std::string > find_first_of(const std::string &path, const std::list< std::string > &names, bool all)
static std::string kpse_readable_file(const std::string &name)
std::list< std::string > kpse_all_path_search(const std::string &path, const std::string &name)
#define KPSE_DEBUG_P(bit)
#define brace_whitespace(c)
static bool dir_p(const std::string &fn)
std::list< std::string > path_find_first_of(const std::string &path, const std::list< std::string > &names, bool all)
#define IS_DEVICE_SEP(ch)
static std::string kpse_truncate_filename(const std::string &name)
static bool READABLE(const std::string &fn)
static std::list< std::string > search(const std::string &path, const std::string &original_name, bool all)
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)
std::wstring u8_to_wstring(const std::string &utf8_string)
static bool absolute_pathname(const std::string &s)
int octave_access_r_ok(void)
int octave_access_wrapper(const char *nm, int mode)