GNU Octave  4.2.1
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
pathsearch.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2017 John W. Eaton
4 
5 This file is part of Octave.
6 
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
20 
21 */
22 
23 #if defined (HAVE_CONFIG_H)
24 # include "config.h"
25 #endif
26 
27 #include <cstdlib>
28 
29 #include <string>
30 
31 #include "kpse.h"
32 #include "lo-error.h"
33 #include "lo-utils.h"
34 #include "oct-env.h"
35 #include "pathsearch.h"
36 #include "singleton-cleanup.h"
37 
38 namespace octave
39 {
40  directory_path::static_members *directory_path::static_members::instance = 0;
41 
43  : xpath_sep_char (SEPCHAR), xpath_sep_str (SEPCHAR_STR) { }
44 
45  bool
47  {
48  bool retval = true;
49 
50  if (! instance)
51  {
52  instance = new static_members ();
53 
54  if (instance)
55  singleton_cleanup_list::add (cleanup_instance);
56  }
57 
58  if (! instance)
59  (*current_liboctave_error_handler)
60  ("unable to create directory_path::static_members object!");
61 
62  return retval;
63  }
64 
65  std::list<std::string>
67  {
68  return m_initialized ? m_path_elements : std::list<std::string> ();
69  }
70 
71  std::list<std::string>
73  {
74  std::list<std::string> retval;
75 
76  if (m_initialized)
77  {
78  for (const auto& elt : m_path_elements)
79  {
80  std::string elt_dir = kpse_element_dir (elt);
81 
82  if (! elt_dir.empty ())
83  retval.push_back (elt_dir);
84  }
85  }
86 
87  return retval;
88  }
89 
92  {
94  }
95 
96  std::list<std::string>
98  {
99  return (m_initialized
101  : std::list<std::string> ());
102  }
103 
105  directory_path::find_first_of (const std::list<std::string>& names)
106  {
107  return (m_initialized
108  ? kpse_path_find_first_of (m_expanded_path, names) : "");
109  }
110 
111  std::list<std::string>
112  directory_path::find_all_first_of (const std::list<std::string>& names)
113  {
114  return (m_initialized
116  : std::list<std::string> ());
117  }
118 
119  void
121  {
122  static bool octave_kpse_initialized = false;
123 
124  if (! octave_kpse_initialized)
125  {
126  std::string val = octave::sys::env::getenv ("KPATHSEA_DEBUG");
127 
128  if (! val.empty ())
129  kpse_debug |= atoi (val.c_str ());
130 
131  octave_kpse_initialized = true;
132  }
133 
135  = kpse_path_expand (m_default_path.empty ()
136  ? m_orig_path
138 
139  for (kpse_path_iterator pi (m_expanded_path); pi != std::string::npos; pi++)
140  m_path_elements.push_back (*pi);
141 
142  m_initialized = true;
143  }
144 }
std::string find_first(const std::string &)
Definition: pathsearch.cc:91
std::list< std::string > kpse_all_path_find_first_of(const std::string &path, const std::list< std::string > &names)
Definition: kpse.cc:644
std::list< std::string > find_all(const std::string &)
Definition: pathsearch.cc:97
Octave interface to the compression and uncompression libraries.
Definition: aepbalance.cc:47
std::string find_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:105
std::string m_expanded_path
Definition: pathsearch.h:130
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:5068
static static_members * instance
Definition: pathsearch.h:168
std::string m_orig_path
Definition: pathsearch.h:119
std::string kpse_path_expand(const std::string &path)
Definition: kpse.cc:867
std::string kpse_path_search(const std::string &path, const std::string &name)
Definition: kpse.cc:456
static std::string getenv(const std::string &name)
Definition: oct-env.cc:235
std::string kpse_path_find_first_of(const std::string &path, const std::list< std::string > &names)
Definition: kpse.cc:628
OCTAVE_EXPORT octave_value_list isdir nd deftypefn *std::string nm
Definition: utils.cc:941
static void add(fptr f)
std::list< std::string > elements(void)
Definition: pathsearch.cc:66
std::string kpse_expand_default(const std::string &path, const std::string &fallback)
Definition: kpse.cc:1138
std::string m_default_path
Definition: pathsearch.h:123
octave_value retval
Definition: data.cc:6294
unsigned int kpse_debug
Definition: kpse.cc:88
std::list< std::string > find_all_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:112
std::list< std::string > kpse_all_path_search(const std::string &path, const std::string &name)
Definition: kpse.cc:467
std::list< std::string > m_path_elements
Definition: pathsearch.h:133
std::list< std::string > all_directories(void)
Definition: pathsearch.cc:72
std::string kpse_element_dir(const std::string &elt)
Definition: kpse.cc:1205
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
Definition: utils.cc:854
static const double pi
Definition: lo-specfun.cc:3610