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 size_t m_len =
name.length ();
141 for (
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 ();
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;
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>
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);
352 while (elt.length () > 1
354 elt = elt.substr (1);
360 found = std::list<std::string> ();
373 if (! found.empty ())
376 ret_list.splice (ret_list.end (), found);
379 ret_list.push_back (found.front ());
395 std::string expansion;
398 if (
name.empty () ||
name[0] !=
'~')
406 else if (
name.length () == 1)
410 if (expansion.empty ())
424 size_t home_len = home.length ();
428 home = home.substr (1);
434 expansion = home +
name.substr (c);
440 #if defined (HAVE_PWD_H)
448 std::string user =
name.substr (1, c-1);
455 std::string home = (p ? p.
dir () :
".");
462 home = home.substr (1);
468 expansion = (
name.length () > c ? home : home +
name.substr (c));
485 static std::list<std::string>
486 search (
const std::string&
path,
const std::string& original_name,
489 std::list<std::string> ret_list;
500 std::cerr <<
"kdebug: start search (file=" <<
name
501 <<
", find_all=" << all <<
", path=" <<
path <<
")."
505 ret_list = (absolute_p
521 std::cerr <<
"kdebug: search (" << original_name <<
") =>";
526 std::cerr << std::endl;
551 return ret_list.empty () ?
"" : ret_list.front ();
557 std::list<std::string>
567 std::list<std::string>
569 const std::list<std::string>& names,
bool all)
571 std::list<std::string> ret_list;
576 std::string elt = *
pi;
579 std::list<std::string> found;
585 while (elt.length () > 3
590 elt = elt.substr (1);
596 while (elt.length () > 1
598 elt = elt.substr (1);
606 for (
auto it = names.cbegin (); it != names.cend () && ! done; it++)
608 std::string
name = *it;
613 found = std::list<std::string> ();
621 if (! found.empty ())
624 ret_list.splice (ret_list.end (), found);
627 ret_list.push_back (found.front ());
638 static std::list<std::string>
642 std::list<std::string> ret_list;
646 std::cerr <<
"kdebug: start find_first_of (";
648 for (
auto p = names.cbegin (); p != names.cend (); p++)
650 if (p == names.cbegin ())
653 std::cerr <<
", " << *p;
656 std::cerr <<
"), path=" <<
path <<
'.' << std::endl;
659 for (
const auto&
name : names)
669 if (! ret_list.empty ())
690 std::cerr <<
"kdebug: find_first_of (";
692 for (
auto p = names.cbegin (); p != names.cend (); p++)
694 if (p == names.cbegin ())
697 std::cerr <<
", " << *p;
706 std::cerr << std::endl;
720 const std::list<std::string>& names)
724 return ret_list.empty () ?
"" : ret_list.front ();
734 std::list<std::string>
736 const std::list<std::string>& names)
761 while (elt.length () > 3
766 elt = elt.substr (1);
772 while (elt.length () > 1
774 elt = elt.substr (1);
781 size_t dirlen = dir.length ();
812 #define brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n')
828 static std::list<std::string>
830 const std::list<std::string>& arr2)
832 std::list<std::string> result;
836 else if (arr2.empty ())
840 for (
const auto& elt_2 : arr2)
841 for (
const auto& elt_1 : arr1)
842 result.push_back (elt_1 + elt_2);
849 static std::list<std::string>
expand_amble (
const std::string&);
852 static std::list<std::string>
859 std::string preamble =
text.substr (0, i);
861 std::list<std::string> result (1, preamble);
872 (*current_liboctave_warning_with_id_handler)
873 (
"Octave:pathsearch-syntax",
874 "%s: Unmatched {",
text.c_str ());
876 result = std::list<std::string> (1,
text);
880 std::string amble =
text.substr (start, i-start);
883 std::string postamble =
text.substr (i+1);
898 static std::list<std::string>
901 std::list<std::string> result;
903 size_t text_len =
text.length ();
907 for (start = 0, i = 0, c = 1; c && start < text_len; start = ++i)
914 i = (i0 < i1 ? i0 : i1);
916 std::string tem =
text.substr (start, i-start);
923 result.splice (result.end (), partial);
941 size_t text_len =
text.length ();
945 for (; i < text_len; i++)
957 if (c ==
'\\' && (quoted == 0 || quoted ==
'"' || quoted ==
'`'))
970 if (c ==
'"' || c ==
'\'' || c ==
'`')
976 if (c == satisfy && ! level && ! quoted)
988 if ((c !=
'{') || i == 0 || (
text[i-1] !=
'$'))
994 else if (c ==
'}' && level)
999 c = (c == satisfy) ? c : 0;
1011 return (fs && fs.
is_dir ());
1034 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)
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 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)
octave_value::octave_value(const Array< char > &chm, char type) return retval
int octave_access_r_ok(void)
int octave_access_wrapper(const char *nm, int mode)