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 ();
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
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>
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 ())
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) 724 home = home.substr (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]))
885 while (elt.length () > 3
890 elt = elt.substr (1);
896 while (elt.length () > 1
898 elt = elt.substr (1);
905 size_t dirlen = dir.length ();
936 #define brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n') 952 static std::list<std::string>
954 const std::list<std::string>& arr2)
956 std::list<std::string>
result;
960 else if (arr2.empty ())
964 for (
const auto& elt_2 : arr2)
965 for (
const auto& elt_1 : arr1)
966 result.push_back (elt_1 + elt_2);
976 static std::list<std::string>
985 std::list<std::string>
result (1, preamble);
996 (*current_liboctave_warning_with_id_handler)
997 (
"Octave:pathsearch-syntax",
998 "%s: Unmatched {",
text.c_str ());
1022 static std::list<std::string>
1025 std::list<std::string>
result;
1027 size_t text_len =
text.length ();
1038 i = (i0 < i1 ? i0 : i1);
1065 size_t text_len =
text.length ();
1069 for (;
i < text_len;
i++)
1081 if (
c ==
'\\' && (quoted == 0 || quoted ==
'"' || quoted ==
'`'))
1094 if (
c ==
'"' ||
c ==
'\'' ||
c ==
'`')
1100 if (
c == satisfy && ! level && ! quoted)
1112 if ((
c !=
'{') ||
i == 0 || (
text[
i-1] !=
'$'))
1118 else if (
c ==
'}' && level)
1140 size_t path_len = path.length ();
1143 expansion = fallback;
1148 expansion = (path_len == 1 ? fallback : fallback + path);
1157 expansion = path + fallback;
1165 for (
size_t i = 0;
i < path_len;
i++)
1167 if (
i + 1 < path_len
1174 expansion = path.substr (0,
i+1) + fallback + path.substr (
i+1);
1215 char last_char = ret.back ();
1257 (*current_liboctave_warning_with_id_handler)
1258 (
"Octave:pathsearch-syntax",
1259 "pathsearch: variable '%s' references itself (eventually)",
1267 if (!
value.empty ())
1281 #if ! defined (IS_VAR_START) 1282 # define IS_VAR_START(c) ((c) == '$') 1286 #if ! defined (IS_VAR_CHAR) 1287 # define IS_VAR_CHAR(c) (isalnum (c) || (c) == '_') 1291 #if ! defined (IS_VAR_BEGIN_DELIMITER) 1292 # define IS_VAR_BEGIN_DELIMITER(c) ((c) == '{') 1295 #if ! defined (IS_VAR_END_DELIMITER) 1296 # define IS_VAR_END_DELIMITER(c) ((c) == '}') 1307 size_t src_len = src.length ();
1310 for (
size_t i = 0;
i < src_len;
i++)
1329 expand (expansion, src.substr (
i, var_end -
i + 1));
1336 size_t var_end = ++
i;
1341 if (var_end == src_len)
1343 (*current_liboctave_warning_with_id_handler)
1344 (
"Octave:pathsearch-syntax",
1345 "%s: No matching } for ${", src.c_str ());
1350 expand (expansion, src.substr (
i, var_end -
i));
1357 (*current_liboctave_warning_with_id_handler)
1358 (
"Octave:pathsearch-syntax",
1359 "%s: Unrecognized variable construct '$%c'",
1360 src.c_str (), src[
i]);
1366 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)
is already an absolute the name is checked against the file system instead of Octave s loadpath In this if otherwise an empty string is returned If the first argument is a cell array of 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
static bool dir_p(const std::string &fn)
static bool is_path_sep(char c)
static int brace_gobbler(const std::string &, int &, int)
static void expand(std::string &expansion, const std::string &var)
static std::list< std::string > expand_amble(const std::string &)
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
nd example oindent opens the file binary numeric values will be read assuming they are stored in IEEE format with the least significant bit and then converted to the native representation Opening a file that is already open simply opens it again and returns a separate file id It is not an error to open a file several though writing to the same file through several different file ids may produce unexpected results The possible values of text mode reading and writing automatically converts linefeeds to the appropriate line end character for the you may append a you must also open the file in binary mode The parameter conversions are currently only supported for and permissions will be set to and then everything is written in a single operation This is very efficient and improves performance c
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)
std::string kpse_path_find_first_of(const std::string &path, const std::list< std::string > &names)
nd deftypefn *std::string name
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)
time_t unix_time(void) const
#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)
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
nd group nd example For each display the value
#define IS_DEVICE_SEP(ch)
static unsigned int max_name_length(void)
static void expanding(const std::string &var, bool xp)
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 const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE * x
static bool kpse_absolute_p(const std::string &filename, int relative_ok)