annotate liboctave/util/pathsearch.cc @ 23743:e919cc8d9d92

don't use singleton pattern in pathsearch class; treat pathsep as constant * dirfns.cc (Fpathsep): Don't allow pathsep to be changed. * pathsearch.h, pathsearch.cc (directory_path::static_members): Eliminate singleton class. (directory_path::path_sep_char (char)): Delete. Don't allow path separator character to be changed.
author John W. Eaton <jwe@octave.org>
date Fri, 07 Jul 2017 07:21:20 -0400
parents 08036a7f3660
children 194eb4bd202b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
1 /*
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
2
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 1996-2017 John W. Eaton
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
4
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
6
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
10 (at your option) any later version.
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22402
diff changeset
15 GNU General Public License for more details.
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
16
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5777
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5777
diff changeset
19 <http://www.gnu.org/licenses/>.
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
20
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
21 */
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
22
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21301
diff changeset
23 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21202
diff changeset
24 # include "config.h"
2021
aa68db31dc34 [project @ 1996-03-23 05:53:57 by jwe]
jwe
parents: 2006
diff changeset
25 #endif
aa68db31dc34 [project @ 1996-03-23 05:53:57 by jwe]
jwe
parents: 2006
diff changeset
26
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
27 #include <cstdlib>
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
28
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
29 #include <string>
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
30
21883
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
31 #include "kpse.h"
02add2f597a1 compile kpse.cc separately from pathsearch.cc
John W. Eaton <jwe@octave.org>
parents: 21882
diff changeset
32 #include "lo-error.h"
3024
95e8b5c4824a [project @ 1997-06-04 05:06:26 by jwe]
jwe
parents: 2847
diff changeset
33 #include "lo-utils.h"
3833
f3278ec3ccb7 [project @ 2001-05-17 12:31:52 by jwe]
jwe
parents: 3505
diff changeset
34 #include "oct-env.h"
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
35 #include "pathsearch.h"
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
36
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
37 namespace octave
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
38 {
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
39 directory_path::directory_path (const std::string& s, const std::string& d)
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
40 : m_orig_path (s), m_default_path (d), m_initialized (false),
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
41 m_expanded_path (), m_path_elements ()
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
42 {
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
43 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
44 init ();
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
45 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
46
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
47 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
48 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
49 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
50 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
51
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
52 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
53 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
54 std::list<std::string> retval;
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
55
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
56 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
57 {
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
58 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
59 {
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
60 std::string elt_dir = kpse_element_dir (elt);
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
61
21873
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
62 if (! elt_dir.empty ())
40195d04b17c still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents: 21871
diff changeset
63 retval.push_back (elt_dir);
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
64 }
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
65 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
66
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
67 return retval;
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
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
70 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
71 {
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
72 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
73 }
4242
4d3994172bd5 [project @ 2002-12-26 22:06:10 by jwe]
jwe
parents: 4126
diff changeset
74
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
75 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
76 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
77 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
78 ? 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
79 : std::list<std::string> ());
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
80 }
4242
4d3994172bd5 [project @ 2002-12-26 22:06:10 by jwe]
jwe
parents: 4126
diff changeset
81
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
82 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
83 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
84 {
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
85 return (m_initialized
21884
e8a8cb1a7258 eliminate unused parameter in kpse functions
John W. Eaton <jwe@octave.org>
parents: 21883
diff changeset
86 ? 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
87 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
88
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
89 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
90 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
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 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
93 ? 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
94 : std::list<std::string> ());
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
95 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
96
23743
e919cc8d9d92 don't use singleton pattern in pathsearch class; treat pathsep as constant
John W. Eaton <jwe@octave.org>
parents: 23696
diff changeset
97 void directory_path::init (void)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
98 {
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
99 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
100
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
101 if (! octave_kpse_initialized)
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
102 {
23696
08036a7f3660 remove octave:: namespace tag from symbols used inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 23457
diff changeset
103 std::string val = sys::env::getenv ("KPATHSEA_DEBUG");
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
104
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
105 if (! val.empty ())
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
106 kpse_debug |= atoi (val.c_str ());
3174
390d5e396682 [project @ 1998-05-04 16:36:17 by jwe]
jwe
parents: 3024
diff changeset
107
21882
d8104206e8a9 additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents: 21873
diff changeset
108 octave_kpse_initialized = true;
21745
bf1121302404 use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents: 21732
diff changeset
109 }
1786
b9e8c73e154e [project @ 1996-01-24 20:36:22 by jwe]
jwe
parents:
diff changeset
110
21867
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
111 m_expanded_path
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
112 = kpse_path_expand (m_default_path.empty ()
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
113 ? m_orig_path
0cdfd6d230e6 use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents: 21745
diff changeset
114 : kpse_expand_default (m_orig_path, m_default_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 }