Classes | Defines | 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 <climits>
#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

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_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 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_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 bool first_search = true
static unsigned int kpathsea_debug = 0
static kpse_format_info_type kpse_format_info
static cache_entrythe_cache = 0

Define Documentation

#define _POSIX_NAME_MAX   255

Definition at line 149 of file kpse.cc.

#define _POSIX_PATH_MAX   255

Definition at line 184 of file kpse.cc.

#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 ()

Definition at line 217 of file kpse.cc.

#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 ()

Definition at line 225 of file kpse.cc.

Referenced by search().

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

Definition at line 215 of file kpse.cc.

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

Definition at line 214 of file kpse.cc.

#define DIR_SEP   '/'

Definition at line 106 of file kpse.cc.

#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 ENV_SEP_STRING   ":"

Definition at line 168 of file kpse.cc.

#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 1724 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 290 of file kpse.cc.

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

Definition at line 282 of file kpse.cc.

Referenced by xfopen().

#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)
#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 KPATHSEA   32

Definition at line 67 of file kpse.cc.

#define KPSE_DEBUG

Definition at line 199 of file kpse.cc.

#define KPSE_DEBUG_EXPAND   4

Definition at line 208 of file kpse.cc.

#define KPSE_DEBUG_FOPEN   2

Definition at line 206 of file kpse.cc.

Referenced by xfopen().

#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)))
#define KPSE_DEBUG_PATHS   3

Definition at line 207 of file kpse.cc.

#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 KPSE_LAST_DEBUG   KPSE_DEBUG_VARS

Definition at line 211 of file kpse.cc.

#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 ST_NLINK_TRICK

Definition at line 81 of file kpse.cc.

#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_MOVED (   sl  )     ((sl).moved)

Definition at line 324 of file kpse.cc.

#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 Documentation

Definition at line 320 of file kpse.cc.

Definition at line 321 of file kpse.cc.


Function Documentation

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().

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

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]
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]
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]
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 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]

Definition at line 950 of file kpse.cc.

References search().

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]
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 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().

static bool kpse_is_env_sep ( char  c  )  [static]

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]
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]
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]
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 
) [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]
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().


Variable Documentation

Definition at line 1738 of file kpse.cc.

int brace_arg_separator = ',' [static]

Definition at line 1584 of file kpse.cc.

unsigned cache_length = 0 [static]

Definition at line 2104 of file kpse.cc.

hash_table_type db [static]

Definition at line 1736 of file kpse.cc.

Definition at line 1740 of file kpse.cc.

bool first_search = true [static]

Definition at line 673 of file kpse.cc.

unsigned int kpathsea_debug = 0 [static]

Definition at line 231 of file kpse.cc.

Definition at line 1720 of file kpse.cc.

cache_entry* the_cache = 0 [static]

Definition at line 2103 of file kpse.cc.

 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines