GNU Octave  8.1.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-2023 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 
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 
128 {
129  return SEPCHAR_STR;
130 }
131 
OCTAVE_END_NAMESPACE(octave)
std::list< std::string > find_all(const std::string &)
Definition: pathsearch.cc:78
std::string m_expanded_path
Definition: pathsearch.h:96
std::list< std::string > all_directories(void)
Definition: pathsearch.cc:55
std::string find_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:86
std::string find_first(const std::string &)
Definition: pathsearch.cc:73
std::list< std::string > find_all_first_of(const std::list< std::string > &names)
Definition: pathsearch.cc:93
std::list< std::string > elements(void)
Definition: pathsearch.cc:50
std::list< std::string > m_path_elements
Definition: pathsearch.h:99
void init(void)
Definition: pathsearch.cc:100
bool m_initialized
Definition: pathsearch.h:92
static std::string path_sep_str(void)
Definition: pathsearch.cc:127
std::string m_orig_path
Definition: pathsearch.h:89
static char path_sep_char(void)
Definition: pathsearch.cc:122
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
std::string kpse_path_find_first_of(const std::string &path, const std::list< std::string > &names)
Definition: kpse.cc:731
std::string kpse_element_dir(const std::string &elt)
Definition: kpse.cc:1037
std::string kpse_path_expand(const std::string &path)
Definition: kpse.cc:758
std::list< std::string > kpse_all_path_find_first_of(const std::string &path, const std::list< std::string > &names)
Definition: kpse.cc:747
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:567
std::string kpse_path_search(const std::string &path, const std::string &name)
Definition: kpse.cc:556
static const double pi
Definition: lo-specfun.cc:1944