Mercurial > octave
annotate liboctave/util/pathsearch.cc @ 21745:bf1121302404
use namespace for dir_path class
* pathsearch.h, pathsearch.cc: Put dir_path class in octave namespace
and rename to directory_path. Change all uses.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 19 May 2016 13:59:28 -0400 |
parents | 6a1eded90355 |
children | 0cdfd6d230e6 |
rev | line source |
---|---|
1786 | 1 /* |
2 | |
19697
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
1786 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
1786 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
1786 | 20 |
21 */ | |
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 | 25 #endif |
26 | |
1786 | 27 #include <cstdlib> |
28 | |
29 #include <string> | |
30 | |
3024 | 31 #include "lo-utils.h" |
3833 | 32 #include "oct-env.h" |
1786 | 33 #include "pathsearch.h" |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
34 #include "singleton-cleanup.h" |
3024 | 35 #include "str-vec.h" |
1786 | 36 |
4399 | 37 #include "kpse.cc" |
4378 | 38 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
39 namespace octave |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
40 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
41 directory_path::static_members *directory_path::static_members::instance = 0; |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
42 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
43 directory_path::static_members::static_members (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
44 : xpath_sep_char (SEPCHAR), xpath_sep_str (SEPCHAR_STR) { } |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
45 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
46 bool |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
47 directory_path::static_members::instance_ok (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
48 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
49 bool retval = true; |
5777 | 50 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
51 if (! instance) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
52 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
53 instance = new static_members (); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
54 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
55 if (instance) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
56 singleton_cleanup_list::add (cleanup_instance); |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
57 } |
5777 | 58 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
59 if (! instance) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
60 (*current_liboctave_error_handler) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
61 ("unable to create directory_path::static_members object!"); |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
62 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
63 return retval; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
64 } |
1786 | 65 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
66 string_vector |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
67 directory_path::elements (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
68 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
69 return initialized ? pv : string_vector (); |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
70 } |
1786 | 71 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
72 string_vector |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
73 directory_path::all_directories (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
74 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
75 int count = 0; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
76 string_vector retval; |
1786 | 77 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
78 if (initialized) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
79 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
80 int len = pv.numel (); |
1786 | 81 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
82 int nmax = len > 32 ? len : 32; |
1786 | 83 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
84 retval.resize (len); |
1786 | 85 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
86 for (int i = 0; i < len; i++) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
87 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
88 str_llist_type *elt_dirs = kpse_element_dirs (pv[i]); |
1786 | 89 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
90 if (elt_dirs) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
91 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
92 str_llist_elt_type *dir; |
1786 | 93 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
94 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
95 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
96 const std::string elt_dir = STR_LLIST (*dir); |
1786 | 97 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
98 if (! elt_dir.empty ()) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
99 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
100 if (count == nmax) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
101 nmax *= 2; |
1786 | 102 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
103 retval.resize (nmax); |
3415 | 104 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
105 retval[count++] = elt_dir; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
106 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
107 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
108 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
109 } |
1786 | 110 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
111 retval.resize (count); |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
112 } |
1786 | 113 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
114 return retval; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
115 } |
1786 | 116 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
117 std::string |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
118 directory_path::find_first (const std::string& nm) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
119 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
120 return initialized ? kpse_path_search (p, nm, true) : ""; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
121 } |
4242 | 122 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
123 string_vector |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
124 directory_path::find_all (const std::string& nm) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
125 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
126 return initialized ? kpse_all_path_search (p, nm) : string_vector (); |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
127 } |
4242 | 128 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
129 std::string |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
130 directory_path::find_first_of (const string_vector& names) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
131 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
132 return initialized |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
133 ? kpse_path_find_first_of (p, names, true) : ""; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
134 } |
1786 | 135 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
136 string_vector |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
137 directory_path::find_all_first_of (const string_vector& names) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
138 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
139 return initialized |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
140 ? kpse_all_path_find_first_of (p, names) : string_vector (); |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
141 } |
1786 | 142 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
143 void |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
144 directory_path::init (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
145 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
146 static bool octave_kpathsea_initialized = false; |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
147 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
148 if (! octave_kpathsea_initialized) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
149 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
150 std::string val = octave::sys::env::getenv ("KPATHSEA_DEBUG"); |
1786 | 151 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
152 if (! val.empty ()) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
153 kpathsea_debug |= atoi (val.c_str ()); |
3174 | 154 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
155 octave_kpathsea_initialized = true; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
156 } |
1786 | 157 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
158 p = kpse_path_expand (p_default.empty () |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
159 ? p_orig : kpse_expand_default (p_orig, p_default)); |
3196 | 160 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
161 int count = 0; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
162 for (kpse_path_iterator pi (p); pi != std::string::npos; pi++) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
163 count++; |
1786 | 164 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
165 pv.resize (count); |
1786 | 166 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
167 kpse_path_iterator pi (p); |
1786 | 168 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
169 for (int i = 0; i < count; i++) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
170 pv[i] = *pi++; |
1786 | 171 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
172 initialized = true; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
173 } |
1786 | 174 } |