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++)
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 ();
190 retval = fs && ! fs.
is_dir ();
213#if defined (ENAMETOOLONG)
215 else if (errno == ENAMETOOLONG)
236 perror (
name.c_str ());
268 for (
const auto& filename : filenames)
271 std::cerr << now.
unix_time () <<
' ' << filename << std::endl;
286static std::list<std::string>
290 std::list<std::string> ret;
292 std::string potential = dir +
name;
298 ret.push_back (potential);
310static std::list<std::string>
313 std::list<std::string> ret_list;
318 ret_list.push_back (found);
326static std::list<std::string>
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)
413 if (expansion.empty ())
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)
454 std::string user =
name.substr (1, c-1);
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);
477 expansion = (
name.length () > c ? home : home +
name.substr (c));
494static std::list<std::string>
495search (
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;
560 return ret_list.empty () ?
"" : ret_list.front ();
566std::list<std::string>
576std::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 ());
650static std::list<std::string>
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)
736 return ret_list.empty () ?
"" : ret_list.front ();
746std::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')
843static 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);
864static std::list<std::string>
expand_amble (
const std::string&);
867static 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);
913static 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;
1026 return (fs && fs.
is_dir ());
1049 char last_char = ret.back ();
const std::string & m_path
static bool is_path_sep(char c)
static unsigned int max_name_length(void)
static bool rooted_relative_pathname(const std::string &s)
static std::string get_home_directory(void)
static bool absolute_pathname(const std::string &s)
std::string dir(void) const
static password getpwnam(const std::string &nm)
OCTAVE_TIME_T unix_time(void) const
std::string kpse_path_find_first_of(const std::string &path, const std::list< std::string > &names)
#define NAME_BEGINS_WITH_DEVICE(name)
static void log_search(const std::list< std::string > &filenames)
static std::list< std::string > brace_expand(const std::string &text)
#define KPSE_DEBUG_SEARCH
static std::list< std::string > absolute_search(const std::string &name)
static std::string kpse_tilde_expand(const std::string &name)
std::string kpse_element_dir(const std::string &elt)
static std::list< std::string > find_first_of(const std::string &path, const std::list< std::string > &names, bool all)
static int brace_arg_separator
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)
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::string kpse_readable_file(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_find_first_of(const std::string &path, const std::list< std::string > &names)
std::list< std::string > kpse_all_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)
#define KPSE_DEBUG_P(bit)
#define brace_whitespace(c)
std::list< std::string > path_find_first_of(const std::string &path, const std::list< std::string > &names, bool all)
static bool dir_p(const std::string &fn)
#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 > dir_search(const std::string &dir, const std::string &name, bool search_all)
std::string kpse_path_search(const std::string &path, const std::string &name)
std::wstring u8_to_wstring(const std::string &utf8_string)
int octave_access_r_ok(void)
int octave_access_wrapper(const char *nm, int mode)