GNU Octave  6.2.0
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-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if defined (HAVE_CONFIG_H)
27 # include "config.h"
28 #endif
29 
30 #include <cstdlib>
31 
32 #include <string>
33 
34 #include "kpse.h"
35 #include "lo-error.h"
36 #include "lo-utils.h"
37 #include "oct-env.h"
38 #include "pathsearch.h"
39 
40 namespace octave
41 {
42  directory_path::directory_path (const std::string& s)
43  : m_orig_path (s), m_initialized (false), m_expanded_path (),
44  m_path_elements ()
45  {
46  if (! m_orig_path.empty ())
47  init ();
48  }
49 
50  std::list<std::string> directory_path::elements (void)
51  {
52  return m_initialized ? m_path_elements : std::list<std::string> ();
53  }
54 
55  std::list<std::string> directory_path::all_directories (void)
56  {
57  std::list<std::string> retval;
58 
59  if (m_initialized)
60  {
61  for (const auto& elt : m_path_elements)
62  {
63  std::string elt_dir = kpse_element_dir (elt);
64 
65  if (! elt_dir.empty ())
66  retval.push_back (elt_dir);
67  }
68  }
69 
70  return retval;
71  }
72 
73  std::string directory_path::find_first (const std::string& nm)
74  {
76  }
77 
78  std::list<std::string> directory_path::find_all (const std::string& nm)
79  {
80  return (m_initialized
82  : std::list<std::string> ());
83  }
84 
85  std::string
86  directory_path::find_first_of (const std::list<std::string>& names)
87  {
88  return (m_initialized
90  }
91 
92  std::list<std::string>
93  directory_path::find_all_first_of (const std::list<std::string>& names)
94  {
95  return (m_initialized
97  : std::list<std::string> ());
98  }
99 
101  {
102  static bool octave_kpse_initialized = false;
103 
104  if (! octave_kpse_initialized)
105  {
106  std::string val = sys::env::getenv ("KPATHSEA_DEBUG");
107 
108  if (! val.empty ())
109  kpse_debug |= atoi (val.c_str ());
110 
111  octave_kpse_initialized = true;
112  }
113 
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 
127  std::string directory_path::path_sep_str (void)
128  {
129  return SEPCHAR_STR;
130  }
131 }
std::string find_first(const std::string &)
Definition: pathsearch.cc:73
std::list< std::string > m_path_elements
Definition: pathsearch.h:99
std::list< std::string > elements(void)
Definition: pathsearch.cc:50
std::string m_expanded_path
Definition: pathsearch.h:96
static char path_sep_char(void)
Definition: pathsearch.cc:122
directory_path(const std::string &s="")
Definition: pathsearch.cc:42
std::string find_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:86
std::string m_orig_path
Definition: pathsearch.h:89
std::list< std::string > find_all_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:93
std::list< std::string > all_directories(void)
Definition: pathsearch.cc:55
std::list< std::string > find_all(const std::string &)
Definition: pathsearch.cc:78
static std::string path_sep_str(void)
Definition: pathsearch.cc:127
static std::string getenv(const std::string &name)
Definition: oct-env.cc:271
std::string kpse_path_find_first_of(const std::string &path, const std::list< std::string > &names)
Definition: kpse.cc:719
std::string kpse_element_dir(const std::string &elt)
Definition: kpse.cc:1022
std::string kpse_path_expand(const std::string &path)
Definition: kpse.cc:746
std::list< std::string > kpse_all_path_find_first_of(const std::string &path, const std::list< std::string > &names)
Definition: kpse.cc:735
unsigned int kpse_debug
Definition: kpse.cc:92
std::list< std::string > kpse_all_path_search(const std::string &path, const std::string &name)
Definition: kpse.cc:558
std::string kpse_path_search(const std::string &path, const std::string &name)
Definition: kpse.cc:547
static const double pi
Definition: lo-specfun.cc:1995
octave_value::octave_value(const Array< char > &chm, char type) return retval
Definition: ov.cc:811