GNU Octave 11.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 
Loading...
Searching...
No Matches
pathsearch.cc
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////////
2//
3// Copyright (C) 1996-2026 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-utils.h"
36#include "oct-env.h"
37#include "oct-error.h"
38#include "pathsearch.h"
39
41
42directory_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
50std::list<std::string>
52{
53 return m_initialized ? m_path_elements : std::list<std::string> ();
54}
55
56std::list<std::string>
58{
59 std::list<std::string> retval;
60
61 if (m_initialized)
62 {
63 for (const auto& elt : m_path_elements)
64 {
65 std::string elt_dir = kpse_element_dir (elt);
66
67 if (! elt_dir.empty ())
68 retval.push_back (elt_dir);
69 }
70 }
71
72 return retval;
73}
74
75std::string
76directory_path::find_first (const std::string& nm)
77{
78 return m_initialized ? kpse_path_search (m_expanded_path, nm) : "";
79}
80
81std::list<std::string>
82directory_path::find_all (const std::string& nm)
83{
84 return (m_initialized
85 ? kpse_all_path_search (m_expanded_path, nm)
86 : std::list<std::string> ());
87}
88
89std::string
90directory_path::find_first_of (const std::list<std::string>& names)
91{
92 return (m_initialized
93 ? kpse_path_find_first_of (m_expanded_path, names) : "");
94}
95
96std::list<std::string>
97directory_path::find_all_first_of (const std::list<std::string>& names)
98{
99 return (m_initialized
100 ? kpse_all_path_find_first_of (m_expanded_path, names)
101 : std::list<std::string> ());
102}
103
104void
105directory_path::init ()
106{
107 m_expanded_path = kpse_path_expand (m_orig_path);
108
109 for (kpse_path_iterator pi (m_expanded_path); pi != std::string::npos; pi++)
110 m_path_elements.push_back (*pi);
111
112 m_initialized = true;
113}
114
115char
117{
118 return SEPCHAR;
119}
120
121std::string
123{
124 return SEPCHAR_STR;
125}
126
127OCTAVE_END_NAMESPACE(octave)
std::list< std::string > find_all(const std::string &)
Definition pathsearch.cc:82
std::list< std::string > all_directories()
Definition pathsearch.cc:57
std::string find_first_of(const std::list< std::string > &names)
Definition pathsearch.cc:90
std::string find_first(const std::string &)
Definition pathsearch.cc:76
std::list< std::string > find_all_first_of(const std::list< std::string > &names)
Definition pathsearch.cc:97
static std::string path_sep_str()
static char path_sep_char()
std::list< std::string > elements()
Definition pathsearch.cc:51
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:684
std::string kpse_element_dir(const std::string &elt)
Definition kpse.cc:977
std::string kpse_path_expand(const std::string &path)
Definition kpse.cc:711
std::list< std::string > kpse_all_path_find_first_of(const std::string &path, const std::list< std::string > &names)
Definition kpse.cc:700
std::list< std::string > kpse_all_path_search(const std::string &path, const std::string &name)
Definition kpse.cc:531
std::string kpse_path_search(const std::string &path, const std::string &name)
Definition kpse.cc:520