Mercurial > octave
annotate liboctave/util/pathsearch.cc @ 21871:cab605836305
use std::list instead of custom list type in pathsearch code
* kpse.cc, pathsearch.cc: Use std::list<std::string> instead of
custom list type.
(str_llist_elt): Delete struct type.
(str_llist_elt_type, str_llist_type): Delete typedefs.
(STR_LLIST, STR_LLIST_NEXT): Delete macros.
(str_llist_add): Delete functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 11 Jun 2016 18:56:14 -0400 |
parents | 0cdfd6d230e6 |
children | 40195d04b17c |
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" |
1786 | 35 |
4399 | 36 #include "kpse.cc" |
4378 | 37 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
38 namespace octave |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
39 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
40 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
|
41 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
42 directory_path::static_members::static_members (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
43 : 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
|
44 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
45 bool |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
46 directory_path::static_members::instance_ok (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
47 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
48 bool retval = true; |
5777 | 49 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
50 if (! instance) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
51 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
52 instance = new static_members (); |
13983
7dd7cccf0757
clean up memory allocated for singletons before exit
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
53 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
54 if (instance) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
55 singleton_cleanup_list::add (cleanup_instance); |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
56 } |
5777 | 57 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
58 if (! instance) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
59 (*current_liboctave_error_handler) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
60 ("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
|
61 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
62 return retval; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
63 } |
1786 | 64 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
65 std::list<std::string> |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
66 directory_path::elements (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
67 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
68 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
|
69 } |
1786 | 70 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
71 std::list<std::string> |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
72 directory_path::all_directories (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
73 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
74 std::list<std::string> retval; |
1786 | 75 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
76 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
|
77 { |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
78 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
|
79 { |
21871
cab605836305
use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
80 std::list<std::string> elt_dirs = kpse_element_dirs (elt); |
1786 | 81 |
21871
cab605836305
use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
82 if (! elt_dirs.empty ()) |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
83 { |
21871
cab605836305
use std::list instead of custom list type in pathsearch code
John W. Eaton <jwe@octave.org>
parents:
21867
diff
changeset
|
84 for (const auto &elt_dir : elt_dirs) |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
85 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
86 if (! elt_dir.empty ()) |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
87 retval.push_back (elt_dir); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
88 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
89 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
90 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
91 } |
1786 | 92 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
93 return retval; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
94 } |
1786 | 95 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
96 std::string |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
97 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
|
98 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
99 return m_initialized ? kpse_path_search (m_expanded_path, nm, true) : ""; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
100 } |
4242 | 101 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
102 std::list<std::string> |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
103 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
|
104 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
105 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
|
106 ? 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
|
107 : std::list<std::string> ()); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
108 } |
4242 | 109 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
110 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
|
111 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
|
112 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
113 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
|
114 ? kpse_path_find_first_of (m_expanded_path, names, true) : ""); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
115 } |
1786 | 116 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
117 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
|
118 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
|
119 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
120 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
|
121 ? 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
|
122 : std::list<std::string> ()); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
123 } |
1786 | 124 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
125 void |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
126 directory_path::init (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
127 { |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
128 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
|
129 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
130 if (! octave_kpathsea_initialized) |
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 std::string val = octave::sys::env::getenv ("KPATHSEA_DEBUG"); |
1786 | 133 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
134 if (! val.empty ()) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
135 kpathsea_debug |= atoi (val.c_str ()); |
3174 | 136 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
137 octave_kpathsea_initialized = true; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
138 } |
1786 | 139 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
140 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
|
141 = 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
|
142 ? 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
|
143 : kpse_expand_default (m_orig_path, m_default_path)); |
1786 | 144 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
145 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
|
146 m_path_elements.push_back (*pi); |
1786 | 147 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
148 m_initialized = true; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
149 } |
1786 | 150 } |