GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
kpse.cc File Reference
#include <cctype>
#include <cerrno>
#include <cstdlib>
#include <map>
#include <fstream>
#include <iostream>
#include <string>
#include "dir-ops.h"
#include "file-ops.h"
#include "file-stat.h"
#include "kpse.h"
#include "oct-env.h"
#include "oct-passwd.h"
#include "oct-time.h"
#include "pathsearch.h"
#include "unistd-wrappers.h"
Include dependency graph for kpse.cc:

Go to the source code of this file.

Macros

#define brace_whitespace(c)   (! (c) || (c) == ' ' || (c) == '\t' || (c) == '\n')
 
#define DIR_SEP_STRING   octave::sys::file_ops::dir_sep_str ()
 
#define ENV_SEP   octave::directory_path::path_sep_char ()
 
#define ENV_SEP_STRING   octave::directory_path::path_sep_str ()
 
#define IS_DEVICE_SEP(ch)   octave::sys::file_ops::is_dev_sep (ch)
 
#define IS_DIR_SEP(ch)   octave::sys::file_ops::is_dir_sep (ch)
 
#define IS_ENV_SEP(ch)   octave::directory_path::is_path_sep (ch)
 
#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 KPSE_DEBUG
 
#define KPSE_DEBUG_EXPAND   1
 
#define KPSE_DEBUG_P(bit)   (kpse_debug & (1 << (bit)))
 
#define KPSE_DEBUG_SEARCH   2
 
#define KPSE_DEBUG_STAT   0
 
#define KPSE_DEBUG_VARS   3
 
#define KPSE_LAST_DEBUG   KPSE_DEBUG_VARS
 
#define NAME_BEGINS_WITH_DEVICE(name)   (name.length () > 0 && IS_DEVICE_SEP ((name)[1]))
 

Functions

static std::list< std::stringabsolute_search (const std::string &name)
 
static std::list< std::stringarray_concat (const std::list< std::string > &arr1, const std::list< std::string > &arr2)
 
static std::list< std::stringbrace_expand (const std::string &)
 
static int brace_gobbler (const std::string &, int &, int)
 
static bool dir_p (const std::string &fn)
 
static std::list< std::stringdir_search (const std::string &dir, const std::string &name, bool search_all)
 
static void expand (std::string &expansion, const std::string &var)
 
static std::list< std::stringexpand_amble (const std::string &)
 
static void expanding (const std::string &var, bool xp)
 
static bool expanding_p (const std::string &var)
 
static std::list< std::stringfind_first_of (const std::string &path, const std::list< std::string > &names, bool all)
 
static bool kpse_absolute_p (const std::string &filename, int relative_ok)
 
std::list< std::stringkpse_all_path_find_first_of (const std::string &path, const std::list< std::string > &names)
 
std::list< std::stringkpse_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)
 
std::string kpse_element_dir (const std::string &elt)
 
static std::string kpse_expand (const std::string &s)
 
std::string kpse_expand_default (const std::string &path, const std::string &fallback)
 
static std::string kpse_expand_kpse_dot (const std::string &path)
 
std::string kpse_path_expand (const std::string &path)
 
std::string kpse_path_find_first_of (const std::string &path, const std::list< std::string > &names)
 
std::string kpse_path_search (const std::string &path, const std::string &name)
 
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 void log_search (const std::list< std::string > &filenames)
 
std::list< std::stringpath_find_first_of (const std::string &path, const std::list< std::string > &names, bool all)
 
static std::list< std::stringpath_search (const std::string &path, const std::string &name, bool all)
 
static bool READABLE (const std::string &fn)
 
static std::list< std::stringsearch (const std::string &path, const std::string &original_name, bool all)
 

Variables

static int brace_arg_separator = ','
 
static std::map< std::string, boolexpansions
 
static bool first_search = true
 
unsigned int kpse_debug = 0
 

Macro Definition Documentation

◆ brace_whitespace

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

Definition at line 936 of file kpse.cc.

Referenced by brace_gobbler().

◆ DIR_SEP_STRING

#define DIR_SEP_STRING   octave::sys::file_ops::dir_sep_str ()

Definition at line 64 of file kpse.cc.

Referenced by kpse_element_dir(), and kpse_expand_kpse_dot().

◆ ENV_SEP

#define ENV_SEP   octave::directory_path::path_sep_char ()

Definition at line 67 of file kpse.cc.

Referenced by expand_amble(), and kpse_path_expand().

◆ ENV_SEP_STRING

#define ENV_SEP_STRING   octave::directory_path::path_sep_str ()

◆ IS_DEVICE_SEP

#define IS_DEVICE_SEP (   ch)    octave::sys::file_ops::is_dev_sep (ch)

Definition at line 60 of file kpse.cc.

Referenced by kpse_element_dir(), and kpse_truncate_filename().

◆ IS_DIR_SEP

◆ IS_ENV_SEP

#define IS_ENV_SEP (   ch)    octave::directory_path::is_path_sep (ch)

Definition at line 69 of file kpse.cc.

Referenced by kpse_expand_default().

◆ IS_VAR_BEGIN_DELIMITER

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

Definition at line 1292 of file kpse.cc.

Referenced by kpse_var_expand().

◆ IS_VAR_CHAR

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

Definition at line 1287 of file kpse.cc.

Referenced by kpse_var_expand().

◆ IS_VAR_END_DELIMITER

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

Definition at line 1296 of file kpse.cc.

Referenced by kpse_var_expand().

◆ IS_VAR_START

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

Definition at line 1282 of file kpse.cc.

Referenced by kpse_var_expand().

◆ KPSE_DEBUG

#define KPSE_DEBUG

Definition at line 75 of file kpse.cc.

◆ KPSE_DEBUG_EXPAND

#define KPSE_DEBUG_EXPAND   1

Definition at line 81 of file kpse.cc.

◆ KPSE_DEBUG_P

#define KPSE_DEBUG_P (   bit)    (kpse_debug & (1 << (bit)))

Definition at line 78 of file kpse.cc.

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

◆ KPSE_DEBUG_SEARCH

#define KPSE_DEBUG_SEARCH   2

Definition at line 82 of file kpse.cc.

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

◆ KPSE_DEBUG_STAT

#define KPSE_DEBUG_STAT   0

Definition at line 80 of file kpse.cc.

◆ KPSE_DEBUG_VARS

#define KPSE_DEBUG_VARS   3

Definition at line 83 of file kpse.cc.

◆ KPSE_LAST_DEBUG

#define KPSE_LAST_DEBUG   KPSE_DEBUG_VARS

Definition at line 84 of file kpse.cc.

◆ NAME_BEGINS_WITH_DEVICE

#define NAME_BEGINS_WITH_DEVICE (   name)    (name.length () > 0 && IS_DEVICE_SEP ((name)[1]))

Definition at line 61 of file kpse.cc.

Referenced by kpse_path_expand(), path_find_first_of(), and path_search().

Function Documentation

◆ absolute_search()

static std::list<std::string> absolute_search ( const std::string name)
static

Definition at line 309 of file kpse.cc.

References found, kpse_readable_file(), name, and string.

Referenced by find_first_of(), and search().

◆ array_concat()

static std::list<std::string> array_concat ( const std::list< std::string > &  arr1,
const std::list< std::string > &  arr2 
)
static

Definition at line 953 of file kpse.cc.

References result.

Referenced by brace_expand().

◆ brace_expand()

static std::list< std::string > brace_expand ( const std::string text)
static

Definition at line 977 of file kpse.cc.

References array_concat(), brace_gobbler(), c, expand_amble(), i, result, start, string, and text.

Referenced by expand_amble(), and kpse_brace_expand_element().

◆ brace_gobbler()

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

Definition at line 1058 of file kpse.cc.

References brace_whitespace, c, and i.

Referenced by brace_expand(), and expand_amble().

◆ dir_p()

static bool dir_p ( const std::string fn)
static

Definition at line 1188 of file kpse.cc.

References fs, and octave::sys::base_file_stat::is_dir().

Referenced by kpse_element_dir().

◆ dir_search()

static std::list<std::string> dir_search ( const std::string dir,
const std::string name,
bool  search_all 
)
static

Definition at line 285 of file kpse.cc.

References kpse_readable_file(), name, string, and tmp.

Referenced by path_find_first_of(), and path_search().

◆ expand()

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

Definition at line 1253 of file kpse.cc.

References expanding(), expanding_p(), octave::sys::env::getenv(), kpse_var_expand(), string, tmp, value, and var.

Referenced by kpse_var_expand().

◆ expand_amble()

static std::list< std::string > expand_amble ( const std::string text)
static

Definition at line 1023 of file kpse.cc.

References brace_arg_separator, brace_expand(), brace_gobbler(), c, ENV_SEP, i, result, start, and string.

Referenced by brace_expand().

◆ expanding()

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

Definition at line 1235 of file kpse.cc.

References expansions, and var.

Referenced by expand().

◆ expanding_p()

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

Definition at line 1243 of file kpse.cc.

References expansions, and var.

Referenced by expand().

◆ find_first_of()

static std::list<std::string> find_first_of ( const std::string path,
const std::list< std::string > &  names,
bool  all 
)
static

◆ kpse_absolute_p()

static bool kpse_absolute_p ( const std::string filename,
int  relative_ok 
)
static

◆ kpse_all_path_find_first_of()

std::list<std::string> kpse_all_path_find_first_of ( const std::string path,
const std::list< std::string > &  names 
)

Definition at line 644 of file kpse.cc.

References find_first_of().

Referenced by octave::directory_path::find_all_first_of().

◆ kpse_all_path_search()

std::list< std::string > kpse_all_path_search ( const std::string path,
const std::string name 
)

Definition at line 467 of file kpse.cc.

References name, and search().

Referenced by octave::directory_path::find_all().

◆ kpse_brace_expand()

static std::string kpse_brace_expand ( const std::string path)
static

◆ kpse_brace_expand_element()

static std::string kpse_brace_expand_element ( const std::string elt)
static

Definition at line 797 of file kpse.cc.

References brace_expand(), ENV_SEP_STRING, expansions, kpse_expand(), string, and x.

Referenced by kpse_brace_expand().

◆ kpse_element_dir()

std::string kpse_element_dir ( const std::string elt)

◆ kpse_expand()

static std::string kpse_expand ( const std::string s)
static

Definition at line 746 of file kpse.cc.

References kpse_tilde_expand(), kpse_var_expand(), s, and string.

Referenced by kpse_brace_expand_element(), and search().

◆ kpse_expand_default()

std::string kpse_expand_default ( const std::string path,
const std::string fallback 
)

Definition at line 1136 of file kpse.cc.

References i, IS_ENV_SEP, and string.

Referenced by octave::directory_path::init().

◆ kpse_expand_kpse_dot()

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

◆ kpse_path_expand()

◆ kpse_path_find_first_of()

std::string kpse_path_find_first_of ( const std::string path,
const std::list< std::string > &  names 
)

Definition at line 628 of file kpse.cc.

References find_first_of().

Referenced by octave::directory_path::find_first_of().

◆ kpse_path_search()

std::string kpse_path_search ( const std::string path,
const std::string name 
)

Definition at line 456 of file kpse.cc.

References name, and search().

Referenced by octave::directory_path::find_first().

◆ kpse_readable_file()

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

Definition at line 203 of file kpse.cc.

References kpse_truncate_filename(), name, READABLE(), and string.

Referenced by absolute_search(), and dir_search().

◆ kpse_tilde_expand()

static std::string kpse_tilde_expand ( const std::string name)
static

◆ kpse_truncate_filename()

static std::string kpse_truncate_filename ( const std::string name)
static

Definition at line 132 of file kpse.cc.

References i, IS_DEVICE_SEP, IS_DIR_SEP, octave::sys::dir_entry::max_name_length(), name, and string.

Referenced by kpse_readable_file().

◆ kpse_var_expand()

static std::string kpse_var_expand ( const std::string src)
static

◆ log_search()

static void log_search ( const std::list< std::string > &  filenames)
static

Definition at line 262 of file kpse.cc.

References filename, KPSE_DEBUG_P, KPSE_DEBUG_SEARCH, now, and octave::sys::time::unix_time().

Referenced by find_first_of(), and search().

◆ path_find_first_of()

std::list<std::string> path_find_first_of ( const std::string path,
const std::list< std::string > &  names,
bool  all 
)

◆ path_search()

static std::list<std::string> path_search ( const std::string path,
const std::string name,
bool  all 
)
static

◆ READABLE()

static bool READABLE ( const std::string fn)
inlinestatic

◆ search()

Variable Documentation

◆ brace_arg_separator

int brace_arg_separator = ','
static

Definition at line 1016 of file kpse.cc.

Referenced by expand_amble().

◆ expansions

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

Definition at line 1232 of file kpse.cc.

Referenced by expanding(), expanding_p(), and kpse_brace_expand_element().

◆ first_search

bool first_search = true
static

Definition at line 257 of file kpse.cc.

Referenced by find_first_of(), path_find_first_of(), path_search(), and search().

◆ kpse_debug

unsigned int kpse_debug = 0

Definition at line 88 of file kpse.cc.

Referenced by octave::directory_path::init().