GNU Octave  4.4.1
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
pathsearch.cc
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 1996-2018 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
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
11 
12 Octave is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License 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 <https://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 
37 namespace octave
38 {
40  : m_orig_path (s), m_default_path (d), m_initialized (false),
41  m_expanded_path (), m_path_elements ()
42  {
43  if (! m_orig_path.empty ())
44  init ();
45  }
46 
47  std::list<std::string> directory_path::elements (void)
48  {
49  return m_initialized ? m_path_elements : std::list<std::string> ();
50  }
51 
52  std::list<std::string> directory_path::all_directories (void)
53  {
54  std::list<std::string> retval;
55 
56  if (m_initialized)
57  {
58  for (const auto& elt : m_path_elements)
59  {
60  std::string elt_dir = kpse_element_dir (elt);
61 
62  if (! elt_dir.empty ())
63  retval.push_back (elt_dir);
64  }
65  }
66 
67  return retval;
68  }
69 
71  {
73  }
74 
75  std::list<std::string> directory_path::find_all (const std::string& nm)
76  {
77  return (m_initialized
79  : std::list<std::string> ());
80  }
81 
83  directory_path::find_first_of (const std::list<std::string>& names)
84  {
85  return (m_initialized
87  }
88 
89  std::list<std::string>
90  directory_path::find_all_first_of (const std::list<std::string>& names)
91  {
92  return (m_initialized
94  : std::list<std::string> ());
95  }
96 
98  {
99  static bool octave_kpse_initialized = false;
100 
101  if (! octave_kpse_initialized)
102  {
103  std::string val = sys::env::getenv ("KPATHSEA_DEBUG");
104 
105  if (! val.empty ())
106  kpse_debug |= atoi (val.c_str ());
107 
108  octave_kpse_initialized = true;
109  }
110 
112  = kpse_path_expand (m_default_path.empty ()
113  ? m_orig_path
115 
116  for (kpse_path_iterator pi (m_expanded_path); pi != std::string::npos; pi++)
117  m_path_elements.push_back (*pi);
118 
119  m_initialized = true;
120  }
121 
123  {
124  return SEPCHAR;
125  }
126 
128  {
129  return SEPCHAR_STR;
130  }
131 }
static char path_sep_char(void)
Definition: pathsearch.cc:122
std::string find_first(const std::string &)
Definition: pathsearch.cc:70
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:75
std::string find_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:83
std::string m_expanded_path
Definition: pathsearch.h:97
identity matrix If supplied two scalar respectively For allows like xample val
Definition: data.cc:4986
static std::string path_sep_str(void)
Definition: pathsearch.cc:127
std::string m_orig_path
Definition: pathsearch.h:86
std::string kpse_path_expand(const std::string &path)
Definition: kpse.cc:865
s
Definition: file-io.cc:2729
std::string kpse_path_search(const std::string &path, const std::string &name)
Definition: kpse.cc:456
F77_RET_T const F77_REAL const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE &F77_RET_T const F77_DBLE F77_DBLE &F77_RET_T const F77_REAL F77_REAL &F77_RET_T const F77_DBLE const F77_DBLE F77_DBLE * d
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:975
std::list< std::string > elements(void)
Definition: pathsearch.cc:47
std::string kpse_expand_default(const std::string &path, const std::string &fallback)
Definition: kpse.cc:1136
std::string m_default_path
Definition: pathsearch.h:90
is false
Definition: cellfun.cc:400
octave_value retval
Definition: data.cc:6246
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:90
std::list< std::string > kpse_all_path_search(const std::string &path, const std::string &name)
Definition: kpse.cc:467
directory_path(const std::string &s="", const std::string &d="")
Definition: pathsearch.cc:39
std::list< std::string > m_path_elements
Definition: pathsearch.h:100
std::list< std::string > all_directories(void)
Definition: pathsearch.cc:52
std::string kpse_element_dir(const std::string &elt)
Definition: kpse.cc:1203
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:888
static const double pi
Definition: lo-specfun.cc:1996