#include <map>
#include <string>
#include "lo-error.h"
#include "oct-env.h"
#include "oct-passwd.h"
#include "str-vec.h"
#include <cstdio>
#include <cstdarg>
#include <cstdlib>
#include <climits>
#include <cerrno>
#include <cassert>
#include <sys/types.h>
#include <unistd.h>
#include "sysdir.h"
#include "statdefs.h"
#include <cctype>
#include <ctime>
Go to the source code of this file.
Classes | |
struct | cache_entry |
struct | hash_element_type |
struct | hash_table_type |
struct | kpse_format_info_type |
class | kpse_path_iterator |
struct | str_llist_elt |
Defines | |
#define | _POSIX_NAME_MAX 255 |
#define | _POSIX_PATH_MAX 255 |
#define | brace_whitespace(c) (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n') |
#define | DEBUGF(str) DEBUGF_START (); gnulib::fputs (str, stderr); DEBUGF_END () |
#define | DEBUGF1(str, e1) DEBUGF_START (); gnulib::fprintf (stderr, str, e1); DEBUGF_END () |
#define | DEBUGF2(str, e1, e2) DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2); DEBUGF_END () |
#define | DEBUGF3(str, e1, e2, e3) DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3); DEBUGF_END () |
#define | DEBUGF4(str, e1, e2, e3, e4) DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END () |
#define | DEBUGF_END() gnulib::fflush (stderr); } while (0) |
#define | DEBUGF_START() do { gnulib::fputs ("kdebug:", stderr) |
#define | DIR_SEP '/' |
#define | DIR_SEP_STRING "/" |
#define | ENV_SEP ':' |
#define | ENV_SEP_STRING ":" |
#define | EXPAND_DEFAULT(try_path, source_string) |
#define | FATAL(str) |
#define | FATAL_PERROR(str) |
#define | IS_DEVICE_SEP(ch) 0 |
#define | IS_DIR_SEP(ch) ((ch) == DIR_SEP) |
#define | IS_ENV_SEP(ch) ((ch) == ENV_SEP) |
#define | KPATHSEA 32 |
#define | KPSE_DEBUG |
#define | KPSE_DEBUG_EXPAND 4 |
#define | KPSE_DEBUG_FOPEN 2 |
#define | KPSE_DEBUG_HASH 1 |
#define | KPSE_DEBUG_P(bit) (kpathsea_debug & (1 << (bit))) |
#define | KPSE_DEBUG_PATHS 3 |
#define | KPSE_DEBUG_SEARCH 5 |
#define | KPSE_DEBUG_STAT 0 |
#define | KPSE_DEBUG_VARS 6 |
#define | KPSE_LAST_DEBUG KPSE_DEBUG_VARS |
#define | NAME_BEGINS_WITH_DEVICE(name) 0 |
#define | NAME_MAX _POSIX_NAME_MAX |
#define | PATH_MAX _POSIX_PATH_MAX |
#define | ST_NLINK_TRICK |
#define | STR_LLIST(sl) ((sl).str) |
#define | STR_LLIST_MOVED(sl) ((sl).moved) |
#define | STR_LLIST_NEXT(sl) ((sl).next) |
Typedefs | |
typedef str_llist_elt | str_llist_elt_type |
typedef str_llist_elt * | str_llist_type |
Functions | |
static string_vector | absolute_search (const std::string &name) |
static string_vector | array_concat (const string_vector &arr1, const string_vector &arr2) |
static string_vector | brace_expand (const std::string &) |
static int | brace_gobbler (const std::string &, int &, int) |
static void | cache (const std::string key, str_llist_type *value) |
static str_llist_type * | cached (const std::string &key) |
static void | checked_dir_list_add (str_llist_type *l, const std::string &dir) |
static int | dir_links (const std::string &fn) |
static void | dir_list_add (str_llist_type *l, const std::string &dir) |
static string_vector | dir_list_search (str_llist_type *dirs, const std::string &name, bool search_all) |
static bool | dir_p (const std::string &fn) |
static void | do_subdir (str_llist_type *str_list_ptr, const std::string &elt, unsigned elt_length, const std::string &post) |
static bool | elt_in_db (const std::string &db_dir, const std::string &path_elt) |
static string_vector | expand_amble (const std::string &) |
static void | expand_elt (str_llist_type *, const std::string &, unsigned) |
static string_vector | find_first_of (const std::string &path, const string_vector &names, bool must_exist, bool all) |
static string_vector | hash_lookup (hash_table_type table, const std::string &key) |
static bool | kpse_absolute_p (const std::string &filename, int relative_ok) |
static string_vector | kpse_all_path_find_first_of (const std::string &path, const string_vector &names) |
static string_vector | kpse_all_path_search (const std::string &path, const std::string &name) |
static std::string | kpse_brace_expand (const std::string &path) |
static std::string | kpse_brace_expand_element (const std::string &elt) |
static string_vector | kpse_db_search (const std::string &name, const std::string &path_elt, bool all) |
static str_llist_type * | kpse_element_dirs (const std::string &elt) |
static std::string | kpse_expand (const std::string &s) |
static std::string | kpse_expand_default (const std::string &path, const std::string &dflt) |
static std::string | kpse_expand_kpse_dot (const std::string &path) |
static unsigned | kpse_hash (hash_table_type table, const std::string &key) |
static bool | kpse_is_env_sep (char c) |
static std::string | kpse_path_expand (const std::string &path) |
static std::string | kpse_path_find_first_of (const std::string &path, const string_vector &names, bool must_exist) |
static std::string | kpse_path_search (const std::string &path, const std::string &name, bool must_exist) |
static std::string | kpse_readable_file (const std::string &name) |
static std::string | kpse_tilde_expand (const std::string &name) |
static std::string | kpse_truncate_filename (const std::string &name) |
static std::string | kpse_var_expand (const std::string &src) |
static std::string | kpse_var_value (const std::string &var) |
static void | log_search (const string_vector &filenames) |
static bool | match (const std::string &filename_arg, const std::string &path_elt_arg) |
static string_vector | path_find_first_of (const std::string &path, const string_vector &names, bool, bool all) |
static string_vector | path_search (const std::string &path, const std::string &name, bool, bool all) |
static bool | READABLE (const std::string &fn, struct stat &st) |
static string_vector | search (const std::string &path, const std::string &original_name, bool must_exist, bool all) |
static void | str_llist_add (str_llist_type *l, const std::string &str) |
static void | str_llist_float (str_llist_type *l, str_llist_elt_type *mover) |
static void | xclosedir (DIR *d) |
static FILE * | xfopen (const std::string &filename, const char *mode) |
Variables | |
static hash_table_type | alias_db |
static int | brace_arg_separator = ',' |
static unsigned | cache_length = 0 |
static hash_table_type | db |
static string_vector | db_dir_list |
static bool | first_search = true |
static unsigned int | kpathsea_debug = 0 |
static kpse_format_info_type | kpse_format_info |
static cache_entry * | the_cache = 0 |
#define brace_whitespace | ( | c | ) | (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n') |
Definition at line 1500 of file kpse.cc.
Referenced by brace_gobbler().
#define DEBUGF | ( | str | ) | DEBUGF_START (); gnulib::fputs (str, stderr); DEBUGF_END () |
#define DEBUGF1 | ( | str, | ||
e1 | ||||
) | DEBUGF_START (); gnulib::fprintf (stderr, str, e1); DEBUGF_END () |
Definition at line 219 of file kpse.cc.
Referenced by hash_lookup(), and search().
#define DEBUGF2 | ( | str, | ||
e1, | ||||
e2 | ||||
) | DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2); DEBUGF_END () |
Definition at line 221 of file kpse.cc.
Referenced by dir_links(), and kpse_var_value().
#define DEBUGF3 | ( | str, | ||
e1, | ||||
e2, | ||||
e3 | ||||
) | DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3); DEBUGF_END () |
Definition at line 223 of file kpse.cc.
Referenced by kpse_db_search(), and xfopen().
#define DEBUGF4 | ( | str, | ||
e1, | ||||
e2, | ||||
e3, | ||||
e4 | ||||
) | DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2, e3, e4); DEBUGF_END () |
#define DEBUGF_START | ( | ) | do { gnulib::fputs ("kdebug:", stderr) |
#define DIR_SEP_STRING "/" |
Definition at line 107 of file kpse.cc.
Referenced by kpse_expand_kpse_dot().
#define ENV_SEP ':' |
Definition at line 167 of file kpse.cc.
Referenced by expand_amble().
#define EXPAND_DEFAULT | ( | try_path, | ||
source_string | ||||
) |
do \ { \ if (! try_path.empty ()) \ { \ info.raw_path = try_path; \ info.path = kpse_expand_default (try_path, info.path); \ info.path_source = source_string; \ } \ } \ while (0)
#define FATAL | ( | str | ) |
#define FATAL_PERROR | ( | str | ) |
#define IS_DEVICE_SEP | ( | ch | ) | 0 |
Definition at line 115 of file kpse.cc.
Referenced by dir_list_add(), do_subdir(), kpse_absolute_p(), and kpse_truncate_filename().
#define IS_DIR_SEP | ( | ch | ) | ((ch) == DIR_SEP) |
Definition at line 112 of file kpse.cc.
Referenced by dir_list_add(), do_subdir(), kpse_absolute_p(), kpse_expand_kpse_dot(), kpse_path_expand(), kpse_tilde_expand(), kpse_truncate_filename(), match(), path_find_first_of(), and path_search().
#define IS_ENV_SEP | ( | ch | ) | ((ch) == ENV_SEP) |
Definition at line 173 of file kpse.cc.
Referenced by kpse_expand_default(), and kpse_is_env_sep().
#define KPSE_DEBUG_HASH 1 |
Definition at line 205 of file kpse.cc.
Referenced by hash_lookup().
#define KPSE_DEBUG_P | ( | bit | ) | (kpathsea_debug & (1 << (bit))) |
Definition at line 202 of file kpse.cc.
Referenced by dir_links(), find_first_of(), hash_lookup(), kpse_db_search(), kpse_var_value(), log_search(), search(), and xfopen().
#define KPSE_DEBUG_SEARCH 5 |
Definition at line 209 of file kpse.cc.
Referenced by find_first_of(), kpse_db_search(), log_search(), and search().
#define KPSE_DEBUG_STAT 0 |
Definition at line 204 of file kpse.cc.
Referenced by dir_links().
#define KPSE_DEBUG_VARS 6 |
Definition at line 210 of file kpse.cc.
Referenced by kpse_var_value().
#define NAME_BEGINS_WITH_DEVICE | ( | name | ) | 0 |
Definition at line 118 of file kpse.cc.
Referenced by kpse_path_expand(), path_find_first_of(), and path_search().
#define NAME_MAX _POSIX_NAME_MAX |
Definition at line 153 of file kpse.cc.
Referenced by kpse_truncate_filename().
#define PATH_MAX _POSIX_PATH_MAX |
Definition at line 191 of file kpse.cc.
Referenced by octave_canonicalize_file_name().
#define STR_LLIST | ( | sl | ) | ((sl).str) |
Definition at line 323 of file kpse.cc.
Referenced by dir_list_search(), kpse_path_expand(), and path_find_first_of().
#define STR_LLIST_NEXT | ( | sl | ) | ((sl).next) |
Definition at line 325 of file kpse.cc.
Referenced by dir_list_search(), kpse_path_expand(), and path_find_first_of().
typedef str_llist_elt str_llist_elt_type |
typedef str_llist_elt* str_llist_type |
static string_vector absolute_search | ( | const std::string & | name | ) | [static] |
Definition at line 767 of file kpse.cc.
References string_vector::append(), and kpse_readable_file().
Referenced by find_first_of(), and search().
static string_vector array_concat | ( | const string_vector & | arr1, | |
const string_vector & | arr2 | |||
) | [static] |
Definition at line 1517 of file kpse.cc.
References string_vector::empty(), and Array< T >::length().
Referenced by brace_expand().
static string_vector brace_expand | ( | const std::string & | text | ) | [static] |
Definition at line 1546 of file kpse.cc.
References array_concat(), brace_gobbler(), and expand_amble().
Referenced by expand_amble(), and kpse_brace_expand_element().
Definition at line 1626 of file kpse.cc.
References brace_whitespace.
Referenced by brace_expand(), and expand_amble().
static void cache | ( | const std::string | key, | |
str_llist_type * | value | |||
) | [static] |
Definition at line 2113 of file kpse.cc.
References cache_entry::key, and cache_entry::value.
static str_llist_type* cached | ( | const std::string & | key | ) | [static] |
Definition at line 2136 of file kpse.cc.
References cache_entry::value.
static void checked_dir_list_add | ( | str_llist_type * | l, | |
const std::string & | dir | |||
) | [static] |
Definition at line 2081 of file kpse.cc.
References dir_list_add(), and dir_p().
static int dir_links | ( | const std::string & | fn | ) | [static] |
Definition at line 2171 of file kpse.cc.
References DEBUGF2, KPSE_DEBUG_P, and KPSE_DEBUG_STAT.
Referenced by do_subdir().
static void dir_list_add | ( | str_llist_type * | l, | |
const std::string & | dir | |||
) | [static] |
Definition at line 2051 of file kpse.cc.
References IS_DEVICE_SEP, IS_DIR_SEP, and str_llist_add().
Referenced by checked_dir_list_add(), and do_subdir().
static string_vector dir_list_search | ( | str_llist_type * | dirs, | |
const std::string & | name, | |||
bool | search_all | |||
) | [static] |
Definition at line 734 of file kpse.cc.
References string_vector::append(), kpse_readable_file(), STR_LLIST, str_llist_float(), and STR_LLIST_NEXT.
Referenced by path_find_first_of(), and path_search().
static bool dir_p | ( | const std::string & | fn | ) | [static] |
Definition at line 2067 of file kpse.cc.
Referenced by checked_dir_list_add().
static void do_subdir | ( | str_llist_type * | str_list_ptr, | |
const std::string & | elt, | |||
unsigned | elt_length, | |||
const std::string & | post | |||
) | [static] |
Definition at line 2200 of file kpse.cc.
References dir_links(), dir_list_add(), dirent, expand_elt(), IS_DEVICE_SEP, IS_DIR_SEP, and xclosedir().
static bool elt_in_db | ( | const std::string & | db_dir, | |
const std::string & | path_elt | |||
) | [static] |
Definition at line 1828 of file kpse.cc.
Referenced by kpse_db_search().
static string_vector expand_amble | ( | const std::string & | text | ) | [static] |
Definition at line 1591 of file kpse.cc.
References string_vector::append(), brace_expand(), brace_gobbler(), c1, string_vector::empty(), ENV_SEP, and Array< T >::length().
Referenced by brace_expand().
static void expand_elt | ( | str_llist_type * | , | |
const std::string & | , | |||
unsigned | ||||
) | [static] |
Referenced by do_subdir().
static string_vector find_first_of | ( | const std::string & | path, | |
const string_vector & | names, | |||
bool | must_exist, | |||
bool | all | |||
) | [static] |
Definition at line 1068 of file kpse.cc.
References absolute_search(), string_vector::empty(), kpse_absolute_p(), KPSE_DEBUG_P, KPSE_DEBUG_SEARCH, Array< T >::length(), log_search(), and path_find_first_of().
Referenced by kpse_all_path_find_first_of(), and kpse_path_find_first_of().
static string_vector hash_lookup | ( | hash_table_type | table, | |
const std::string & | key | |||
) | [static] |
Definition at line 408 of file kpse.cc.
References string_vector::append(), hash_table_type::buckets, DEBUGF1, string_vector::empty(), hash_element_type::key, KPSE_DEBUG_HASH, KPSE_DEBUG_P, kpse_hash(), Array< T >::length(), hash_element_type::next, and hash_element_type::value.
Referenced by kpse_db_search().
Definition at line 642 of file kpse.cc.
References IS_DEVICE_SEP, and IS_DIR_SEP.
Referenced by find_first_of(), kpse_expand_kpse_dot(), log_search(), and search().
static string_vector kpse_all_path_find_first_of | ( | const std::string & | path, | |
const string_vector & | names | |||
) | [static] |
Definition at line 1171 of file kpse.cc.
References find_first_of().
static string_vector kpse_all_path_search | ( | const std::string & | path, | |
const std::string & | name | |||
) | [static] |
static std::string kpse_brace_expand | ( | const std::string & | path | ) | [static] |
Definition at line 1367 of file kpse.cc.
References kpse_brace_expand_element(), kpse_expand_kpse_dot(), and kpse_var_expand().
Referenced by kpse_path_expand().
static std::string kpse_brace_expand_element | ( | const std::string & | elt | ) | [static] |
Definition at line 1332 of file kpse.cc.
References brace_expand(), kpse_expand(), Array< T >::length(), and x.
Referenced by kpse_brace_expand().
static string_vector kpse_db_search | ( | const std::string & | name, | |
const std::string & | path_elt, | |||
bool | all | |||
) | [static] |
Definition at line 1862 of file kpse.cc.
References string_vector::append(), hash_table_type::buckets, DEBUGF3, elt_in_db(), hash_lookup(), KPSE_DEBUG_P, KPSE_DEBUG_SEARCH, kpse_readable_file(), Array< T >::length(), match(), and string_vector::resize().
Referenced by path_find_first_of(), and path_search().
static str_llist_type* kpse_element_dirs | ( | const std::string & | elt | ) | [static] |
Referenced by kpse_path_expand(), path_find_first_of(), and path_search().
static std::string kpse_expand | ( | const std::string & | s | ) | [static] |
Definition at line 1278 of file kpse.cc.
References kpse_tilde_expand(), and kpse_var_expand().
Referenced by kpse_brace_expand_element(), and search().
static std::string kpse_expand_default | ( | const std::string & | path, | |
const std::string & | dflt | |||
) | [static] |
Definition at line 1993 of file kpse.cc.
References IS_ENV_SEP.
static std::string kpse_expand_kpse_dot | ( | const std::string & | path | ) | [static] |
Definition at line 1291 of file kpse.cc.
References DIR_SEP_STRING, octave_env::getenv(), IS_DIR_SEP, and kpse_absolute_p().
Referenced by kpse_brace_expand().
static unsigned kpse_hash | ( | hash_table_type | table, | |
const std::string & | key | |||
) | [static] |
Definition at line 391 of file kpse.cc.
References hash_table_type::size.
Referenced by hash_lookup().
Definition at line 346 of file kpse.cc.
References IS_ENV_SEP.
Referenced by kpse_path_iterator::next(), and kpse_path_iterator::set_end().
static std::string kpse_path_expand | ( | const std::string & | path | ) | [static] |
Definition at line 1404 of file kpse.cc.
References IS_DIR_SEP, kpse_brace_expand(), kpse_element_dirs(), NAME_BEGINS_WITH_DEVICE, STR_LLIST, and STR_LLIST_NEXT.
static std::string kpse_path_find_first_of | ( | const std::string & | path, | |
const string_vector & | names, | |||
bool | must_exist | |||
) | [static] |
Definition at line 1155 of file kpse.cc.
References string_vector::empty(), and find_first_of().
static std::string kpse_path_search | ( | const std::string & | path, | |
const std::string & | name, | |||
bool | must_exist | |||
) | [static] |
Definition at line 935 of file kpse.cc.
References string_vector::empty(), and search().
static std::string kpse_readable_file | ( | const std::string & | name | ) | [static] |
Definition at line 597 of file kpse.cc.
References kpse_truncate_filename(), and READABLE().
Referenced by absolute_search(), dir_list_search(), and kpse_db_search().
static std::string kpse_tilde_expand | ( | const std::string & | name | ) | [static] |
Definition at line 1187 of file kpse.cc.
References octave_passwd::dir(), octave_env::getenv(), octave_passwd::getpwnam(), and IS_DIR_SEP.
Referenced by kpse_expand().
static std::string kpse_truncate_filename | ( | const std::string & | name | ) | [static] |
Definition at line 535 of file kpse.cc.
References IS_DEVICE_SEP, IS_DIR_SEP, and NAME_MAX.
Referenced by kpse_readable_file().
static std::string kpse_var_expand | ( | const std::string & | src | ) | [static] |
Referenced by kpse_brace_expand(), kpse_expand(), and kpse_var_value().
static std::string kpse_var_value | ( | const std::string & | var | ) | [static] |
Definition at line 513 of file kpse.cc.
References DEBUGF2, octave_env::getenv(), KPSE_DEBUG_P, KPSE_DEBUG_VARS, and kpse_var_expand().
Referenced by log_search().
static void log_search | ( | const string_vector & | filenames | ) | [static] |
Definition at line 680 of file kpse.cc.
References string_vector::empty(), kpse_absolute_p(), KPSE_DEBUG_P, KPSE_DEBUG_SEARCH, kpse_var_value(), Array< T >::length(), and xfopen().
Referenced by find_first_of(), and search().
static bool match | ( | const std::string & | filename_arg, | |
const std::string & | path_elt_arg | |||
) | [static] |
Definition at line 1747 of file kpse.cc.
References IS_DIR_SEP.
Referenced by Array< T >::assign(), dim_vector::concat(), DEFUN_DLD(), do_numeric_lookup(), extract_keyword(), kpse_db_search(), tree_switch_case::label_matches(), and glob_match::match().
static string_vector path_find_first_of | ( | const std::string & | path, | |
const string_vector & | names, | |||
bool | , | |||
bool | all | |||
) | [static] |
Definition at line 960 of file kpse.cc.
References string_vector::append(), dir_list_search(), string_vector::empty(), IS_DIR_SEP, kpse_db_search(), kpse_element_dirs(), Array< T >::length(), NAME_BEGINS_WITH_DEVICE, STR_LLIST, str_llist_add(), and STR_LLIST_NEXT.
Referenced by find_first_of().
static string_vector path_search | ( | const std::string & | path, | |
const std::string & | name, | |||
bool | , | |||
bool | all | |||
) | [static] |
Definition at line 783 of file kpse.cc.
References string_vector::append(), dir_list_search(), string_vector::empty(), IS_DIR_SEP, kpse_db_search(), kpse_element_dirs(), and NAME_BEGINS_WITH_DEVICE.
Referenced by search().
static bool READABLE | ( | const std::string & | fn, | |
struct stat & | st | |||
) | [inline, static] |
Definition at line 582 of file kpse.cc.
Referenced by kpse_readable_file().
static string_vector search | ( | const std::string & | path, | |
const std::string & | original_name, | |||
bool | must_exist, | |||
bool | all | |||
) | [static] |
Definition at line 870 of file kpse.cc.
References absolute_search(), DEBUGF1, DEBUGF4, kpse_absolute_p(), KPSE_DEBUG_P, KPSE_DEBUG_SEARCH, kpse_expand(), log_search(), and path_search().
Referenced by kpse_all_path_search(), and kpse_path_search().
static void str_llist_add | ( | str_llist_type * | l, | |
const std::string & | str | |||
) | [static] |
Referenced by dir_list_add(), and path_find_first_of().
static void str_llist_float | ( | str_llist_type * | l, | |
str_llist_elt_type * | mover | |||
) | [static] |
Referenced by dir_list_search().
static void xclosedir | ( | DIR * | d | ) | [static] |
Referenced by do_subdir().
static FILE* xfopen | ( | const std::string & | filename, | |
const char * | mode | |||
) | [static] |
Definition at line 355 of file kpse.cc.
References DEBUGF3, f, FATAL_PERROR, KPSE_DEBUG_FOPEN, and KPSE_DEBUG_P.
Referenced by log_search().
hash_table_type alias_db [static] |
int brace_arg_separator = ',' [static] |
unsigned cache_length = 0 [static] |
hash_table_type db [static] |
string_vector db_dir_list [static] |
bool first_search = true [static] |
unsigned int kpathsea_debug = 0 [static] |
kpse_format_info_type kpse_format_info [static] |
cache_entry* the_cache = 0 [static] |