GNU Octave  3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
Classes | Macros | Typedefs | Functions | Variables
kpse.cc File Reference
#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 <cerrno>
#include <cassert>
#include <sys/types.h>
#include <unistd.h>
#include "sysdir.h"
#include "statdefs.h"
#include <cctype>
#include <ctime>
Include dependency graph for kpse.cc:
This graph shows which files directly or indirectly include this file:

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

Macros

#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 IS_VAR_BEGIN_DELIMITER(c)   ((c) == '{')
#define IS_VAR_CHAR(c)   (isalnum (c) || (c) == '_')
#define IS_VAR_END_DELIMITER(c)   ((c) == '}')
#define IS_VAR_START(c)   ((c) == '$')
#define KPATHSEA   32
#define KPSE_DEBUG
#define KPSE_DEBUG_EXPAND   4 /* path element expansion */
#define KPSE_DEBUG_FOPEN   2 /* fopen/fclose calls */
#define KPSE_DEBUG_HASH   1 /* hash lookups */
#define KPSE_DEBUG_P(bit)   (kpathsea_debug & (1 << (bit)))
#define KPSE_DEBUG_PATHS   3 /* search path initializations */
#define KPSE_DEBUG_SEARCH   5 /* searches */
#define KPSE_DEBUG_STAT   0 /* stat calls */
#define KPSE_DEBUG_VARS   6 /* variable values */
#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_eltstr_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_typecached (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 void expand (std::string &expansion, const std::string &var)
static string_vector expand_amble (const std::string &)
static void expand_elt (str_llist_type *, const std::string &, unsigned)
static void expanding (const std::string &var, bool xp)
static bool expanding_p (const std::string &var)
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_typekpse_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 std::map< std::string,
bool
expansions
static bool first_search = true
static unsigned int kpathsea_debug = 0
static kpse_format_info_type kpse_format_info
static cache_entrythe_cache = 0

Macro Definition Documentation

#define _POSIX_NAME_MAX   255

Definition at line 152 of file kpse.cc.

#define _POSIX_PATH_MAX   255

Definition at line 187 of file kpse.cc.

#define brace_whitespace (   c)    (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n')

Definition at line 1487 of file kpse.cc.

Referenced by brace_gobbler().

#define DEBUGF (   str)    DEBUGF_START (); gnulib::fputs (str, stderr); DEBUGF_END ()

Definition at line 220 of file kpse.cc.

#define DEBUGF1 (   str,
  e1 
)    DEBUGF_START (); gnulib::fprintf (stderr, str, e1); DEBUGF_END ()

Definition at line 222 of file kpse.cc.

Referenced by hash_lookup(), kpse_element_dirs(), and search().

#define DEBUGF2 (   str,
  e1,
  e2 
)    DEBUGF_START (); gnulib::fprintf (stderr, str, e1, e2); DEBUGF_END ()

Definition at line 224 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 226 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 ()

Definition at line 228 of file kpse.cc.

Referenced by search().

#define DEBUGF_END ( )    gnulib::fflush (stderr); } while (0)

Definition at line 218 of file kpse.cc.

#define DEBUGF_START ( )    do { gnulib::fputs ("kdebug:", stderr)

Definition at line 217 of file kpse.cc.

#define DIR_SEP   '/'

Definition at line 110 of file kpse.cc.

#define DIR_SEP_STRING   "/"

Definition at line 111 of file kpse.cc.

Referenced by dir_list_add(), do_subdir(), and kpse_expand_kpse_dot().

#define ENV_SEP   ':'

Definition at line 170 of file kpse.cc.

Referenced by expand_amble(), and kpse_path_expand().

#define ENV_SEP_STRING   ":"
#define EXPAND_DEFAULT (   try_path,
  source_string 
)
Value:
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)

Definition at line 1711 of file kpse.cc.

#define FATAL (   str)
Value:
do \
{ \
gnulib::fputs ("pathsearch: fatal: ", stderr); \
gnulib::fputs (str, stderr); \
gnulib::fputs (".\n", stderr); \
exit (1); \
} \
while (0)

Definition at line 293 of file kpse.cc.

Referenced by xclosedir().

#define FATAL_PERROR (   str)
Value:
do \
{ \
gnulib::fputs ("pathsearch: ", stderr); \
perror (str); exit (EXIT_FAILURE); \
} \
while (0)

Definition at line 285 of file kpse.cc.

Referenced by xfopen().

#define IS_DEVICE_SEP (   ch)    0

Definition at line 119 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)
#define IS_ENV_SEP (   ch)    ((ch) == ENV_SEP)

Definition at line 176 of file kpse.cc.

Referenced by kpse_expand_default(), and kpse_is_env_sep().

#define IS_VAR_BEGIN_DELIMITER (   c)    ((c) == '{')

Definition at line 2573 of file kpse.cc.

Referenced by kpse_var_expand().

#define IS_VAR_CHAR (   c)    (isalnum (c) || (c) == '_')

Definition at line 2570 of file kpse.cc.

Referenced by kpse_var_expand().

#define IS_VAR_END_DELIMITER (   c)    ((c) == '}')

Definition at line 2576 of file kpse.cc.

Referenced by kpse_var_expand().

#define IS_VAR_START (   c)    ((c) == '$')

Definition at line 2567 of file kpse.cc.

Referenced by kpse_var_expand().

#define KPATHSEA   32

Definition at line 71 of file kpse.cc.

#define KPSE_DEBUG

Definition at line 202 of file kpse.cc.

#define KPSE_DEBUG_EXPAND   4 /* path element expansion */

Definition at line 211 of file kpse.cc.

Referenced by kpse_element_dirs().

#define KPSE_DEBUG_FOPEN   2 /* fopen/fclose calls */

Definition at line 209 of file kpse.cc.

Referenced by xfopen().

#define KPSE_DEBUG_HASH   1 /* hash lookups */

Definition at line 208 of file kpse.cc.

Referenced by hash_lookup().

#define KPSE_DEBUG_P (   bit)    (kpathsea_debug & (1 << (bit)))
#define KPSE_DEBUG_PATHS   3 /* search path initializations */

Definition at line 210 of file kpse.cc.

#define KPSE_DEBUG_SEARCH   5 /* searches */

Definition at line 212 of file kpse.cc.

Referenced by find_first_of(), kpse_db_search(), log_search(), and search().

#define KPSE_DEBUG_STAT   0 /* stat calls */

Definition at line 207 of file kpse.cc.

Referenced by dir_links().

#define KPSE_DEBUG_VARS   6 /* variable values */

Definition at line 213 of file kpse.cc.

Referenced by kpse_var_value().

#define KPSE_LAST_DEBUG   KPSE_DEBUG_VARS

Definition at line 214 of file kpse.cc.

#define NAME_BEGINS_WITH_DEVICE (   name)    0

Definition at line 122 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 156 of file kpse.cc.

Referenced by kpse_truncate_filename().

#define PATH_MAX   _POSIX_PATH_MAX

Definition at line 194 of file kpse.cc.

Referenced by octave_canonicalize_file_name(), and KPty::open().

#define ST_NLINK_TRICK

Definition at line 85 of file kpse.cc.

#define STR_LLIST (   sl)    ((sl).str)
#define STR_LLIST_MOVED (   sl)    ((sl).moved)

Definition at line 327 of file kpse.cc.

Referenced by str_llist_add(), and str_llist_float().

#define STR_LLIST_NEXT (   sl)    ((sl).next)

Typedef Documentation

Definition at line 323 of file kpse.cc.

Definition at line 324 of file kpse.cc.

Function Documentation

static string_vector absolute_search ( const std::string &  name)
static

Definition at line 770 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 1504 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 1533 of file kpse.cc.

References array_concat(), brace_gobbler(), and expand_amble().

Referenced by expand_amble(), and kpse_brace_expand_element().

static int brace_gobbler ( const std::string &  text,
int indx,
int  satisfy 
)
static

Definition at line 1613 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 2101 of file kpse.cc.

References cache_length, cache_entry::key, the_cache, and cache_entry::value.

Referenced by kpse_element_dirs().

static str_llist_type* cached ( const std::string &  key)
static

Definition at line 2124 of file kpse.cc.

References cache_length, and cache_entry::value.

Referenced by kpse_element_dirs().

static void checked_dir_list_add ( str_llist_type l,
const std::string &  dir 
)
static

Definition at line 2069 of file kpse.cc.

References dir_list_add(), and dir_p().

Referenced by expand_elt().

static int dir_links ( const std::string &  fn)
static

Definition at line 2159 of file kpse.cc.

References DEBUGF2, KPSE_DEBUG_P, KPSE_DEBUG_STAT, and stat().

Referenced by do_subdir().

static void dir_list_add ( str_llist_type l,
const std::string &  dir 
)
static

Definition at line 2039 of file kpse.cc.

References DIR_SEP_STRING, 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
static bool dir_p ( const std::string &  fn)
static

Definition at line 2055 of file kpse.cc.

References stat().

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 2188 of file kpse.cc.

References dir_links(), dir_list_add(), DIR_SEP_STRING, dirent, expand_elt(), IS_DEVICE_SEP, IS_DIR_SEP, and xclosedir().

Referenced by expand_elt().

static bool elt_in_db ( const std::string &  db_dir,
const std::string &  path_elt 
)
static

Definition at line 1815 of file kpse.cc.

Referenced by kpse_db_search().

static void expand ( std::string &  expansion,
const std::string &  var 
)
static

Definition at line 2541 of file kpse.cc.

References expanding(), expanding_p(), octave_env::getenv(), and kpse_var_expand().

Referenced by kpse_var_expand().

static string_vector expand_amble ( const std::string &  text)
static
static void expand_elt ( str_llist_type str_list_ptr,
const std::string &  elt,
unsigned   
)
static

Definition at line 2332 of file kpse.cc.

References checked_dir_list_add(), do_subdir(), and IS_DIR_SEP.

Referenced by do_subdir(), and kpse_element_dirs().

static void expanding ( const std::string &  var,
bool  xp 
)
static

Definition at line 2523 of file kpse.cc.

Referenced by expand().

static bool expanding_p ( const std::string &  var)
static

Definition at line 2531 of file kpse.cc.

Referenced by expand().

static string_vector find_first_of ( const std::string &  path,
const string_vector names,
bool  must_exist,
bool  all 
)
static
static string_vector hash_lookup ( hash_table_type  table,
const std::string &  key 
)
static
static bool kpse_absolute_p ( const std::string &  filename,
int  relative_ok 
)
static

Definition at line 645 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 1173 of file kpse.cc.

References find_first_of().

Referenced by dir_path::find_all_first_of().

static string_vector kpse_all_path_search ( const std::string &  path,
const std::string &  name 
)
static

Definition at line 952 of file kpse.cc.

References search().

Referenced by dir_path::find_all().

static std::string kpse_brace_expand ( const std::string &  path)
static
static std::string kpse_brace_expand_element ( const std::string &  elt)
static

Definition at line 1334 of file kpse.cc.

References brace_expand(), ENV_SEP_STRING, expansions, 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
static str_llist_type * kpse_element_dirs ( const std::string &  elt)
static
static std::string kpse_expand ( const std::string &  s)
static

Definition at line 1280 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 1981 of file kpse.cc.

References IS_ENV_SEP.

Referenced by dir_path::init().

static std::string kpse_expand_kpse_dot ( const std::string &  path)
static

Definition at line 1293 of file kpse.cc.

References DIR_SEP_STRING, ENV_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 394 of file kpse.cc.

References hash_table_type::size.

Referenced by hash_lookup().

static bool kpse_is_env_sep ( char  c)
static

Definition at line 349 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
static std::string kpse_path_find_first_of ( const std::string &  path,
const string_vector names,
bool  must_exist 
)
static

Definition at line 1157 of file kpse.cc.

References string_vector::empty(), and find_first_of().

Referenced by dir_path::find_first_of().

static std::string kpse_path_search ( const std::string &  path,
const std::string &  name,
bool  must_exist 
)
static

Definition at line 937 of file kpse.cc.

References string_vector::empty(), and search().

Referenced by dir_path::find_first().

static std::string kpse_readable_file ( const std::string &  name)
static

Definition at line 600 of file kpse.cc.

References kpse_truncate_filename(), READABLE(), and stat().

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 1189 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 538 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
static std::string kpse_var_value ( const std::string &  var)
static

Definition at line 516 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
static bool match ( const std::string &  filename_arg,
const std::string &  path_elt_arg 
)
static
static string_vector path_find_first_of ( const std::string &  path,
const string_vector names,
bool  ,
bool  all 
)
static
static string_vector path_search ( const std::string &  path,
const std::string &  name,
bool  ,
bool  all 
)
static
static bool READABLE ( const std::string &  fn,
struct stat st 
)
inlinestatic

Definition at line 585 of file kpse.cc.

References stat().

Referenced by kpse_readable_file().

static string_vector search ( const std::string &  path,
const std::string &  original_name,
bool  must_exist,
bool  all 
)
static
static void str_llist_add ( str_llist_type l,
const std::string &  str 
)
static

Definition at line 2442 of file kpse.cc.

References STR_LLIST, STR_LLIST_MOVED, and STR_LLIST_NEXT.

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

Definition at line 2468 of file kpse.cc.

References STR_LLIST_MOVED, and STR_LLIST_NEXT.

Referenced by dir_list_search().

void xclosedir ( DIR *  d)
static

Definition at line 2428 of file kpse.cc.

References FATAL.

Referenced by do_subdir().

static FILE* xfopen ( const std::string &  filename,
const char mode 
)
static

Definition at line 358 of file kpse.cc.

References DEBUGF3, f, FATAL_PERROR, KPSE_DEBUG_FOPEN, and KPSE_DEBUG_P.

Referenced by log_search().

Variable Documentation

hash_table_type alias_db
static

Definition at line 1725 of file kpse.cc.

int brace_arg_separator = ','
static

Definition at line 1571 of file kpse.cc.

unsigned cache_length = 0
static

Definition at line 2092 of file kpse.cc.

Referenced by cache(), and cached().

hash_table_type db
static

Definition at line 1723 of file kpse.cc.

string_vector db_dir_list
static

Definition at line 1727 of file kpse.cc.

std::map<std::string, bool> expansions
static

Definition at line 2520 of file kpse.cc.

Referenced by kpse_brace_expand_element().

bool first_search = true
static

Definition at line 676 of file kpse.cc.

unsigned int kpathsea_debug = 0
static

Definition at line 234 of file kpse.cc.

Referenced by dir_path::init().

kpse_format_info_type kpse_format_info
static

Definition at line 1707 of file kpse.cc.

cache_entry* the_cache = 0
static

Definition at line 2091 of file kpse.cc.

Referenced by cache().