annotate liboctave/util/pathsearch.cc @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 0a5b15007766
children e88a07dec498
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
3 // Copyright (C) 1996-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
27 # include "config.h"
2021
aa68db31dc34 [project @ 1996-03-23 05:53:57 by jwe]
jwe
parents: 2006
diff changeset
28 #endif
aa68db31dc34 [project @ 1996-03-23 05:53:57 by jwe]
jwe
parents: 2006
diff changeset
29
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
30 #include <cstdlib>
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
31
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
32 #include <string>
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
33
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
34 #include "kpse.h"
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
35 #include "lo-error.h"
3024
95e8b5c4824a [project @ 1997-06-04 05:06:26 by jwe]
jwe
parents: 2847
diff changeset
36 #include "lo-utils.h"
3833
f3278ec3ccb7 [project @ 2001-05-17 12:31:52 by jwe]
jwe
parents: 3505
diff changeset
37 #include "oct-env.h"
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
38 #include "pathsearch.h"
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
39
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
40 namespace octave
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
41 {
26174
94fc8648f0fe eliminate some unused and unnecessary path expansion code
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
42 directory_path::directory_path (const std::string& s)
94fc8648f0fe eliminate some unused and unnecessary path expansion code
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
43 : m_orig_path (s), m_initialized (false), m_expanded_path (),
94fc8648f0fe eliminate some unused and unnecessary path expansion code
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
44 m_path_elements ()
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
45 {
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
46 if (! m_orig_path.empty ())
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
47 init ();
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
48 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
49
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
50 std::list<std::string> directory_path::elements (void)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
51 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
52 return m_initialized ? m_path_elements : std::list<std::string> ();
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
53 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
54
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
55 std::list<std::string> directory_path::all_directories (void)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
56 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
57 std::list<std::string> retval;
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
58
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
59 if (m_initialized)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
60 {
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
61 for (const auto& elt : m_path_elements)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
62 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
63 std::string elt_dir = kpse_element_dir (elt);
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
64
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
65 if (! elt_dir.empty ())
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
66 retval.push_back (elt_dir);
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
67 }
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
68 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
69
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
70 return retval;
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
71 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
72
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
73 std::string directory_path::find_first (const std::string& nm)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
74 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
75 return m_initialized ? kpse_path_search (m_expanded_path, nm) : "";
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
76 }
4242
4d3994172bd5 [project @ 2002-12-26 22:06:10 by jwe]
jwe
parents: 4126
diff changeset
77
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
78 std::list<std::string> directory_path::find_all (const std::string& nm)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
79 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
80 return (m_initialized
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
81 ? kpse_all_path_search (m_expanded_path, nm)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
82 : std::list<std::string> ());
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
83 }
4242
4d3994172bd5 [project @ 2002-12-26 22:06:10 by jwe]
jwe
parents: 4126
diff changeset
84
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
85 std::string
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
86 directory_path::find_first_of (const std::list<std::string>& names)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
87 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
88 return (m_initialized
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
89 ? kpse_path_find_first_of (m_expanded_path, names) : "");
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
90 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
91
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
92 std::list<std::string>
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
93 directory_path::find_all_first_of (const std::list<std::string>& names)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
94 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
95 return (m_initialized
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
96 ? kpse_all_path_find_first_of (m_expanded_path, names)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
97 : std::list<std::string> ());
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
98 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
99
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
100 void directory_path::init (void)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
101 {
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
102 static bool octave_kpse_initialized = false;
8008
4d13a7a2f6ab dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents: 7017
diff changeset
103
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
104 if (! octave_kpse_initialized)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
105 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
106 std::string val = sys::env::getenv ("KPATHSEA_DEBUG");
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
107
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
108 if (! val.empty ())
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
109 kpse_debug |= atoi (val.c_str ());
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3024
diff changeset
110
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
111 octave_kpse_initialized = true;
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
112 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
113
26174
94fc8648f0fe eliminate some unused and unnecessary path expansion code
John W. Eaton <jwe@octave.org>
parents: 25054
diff changeset
114 m_expanded_path = kpse_path_expand (m_orig_path);
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
115
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
116 for (kpse_path_iterator pi (m_expanded_path); pi != std::string::npos; pi++)
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
117 m_path_elements.push_back (*pi);
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
118
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
119 m_initialized = true;
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
120 }
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
121
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
122 char directory_path::path_sep_char (void)
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
123 {
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
124 return SEPCHAR;
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
125 }
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
126
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
127 std::string directory_path::path_sep_str (void)
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
128 {
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
129 return SEPCHAR_STR;
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
130 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
131 }