Mercurial > octave
annotate liboctave/util/pathsearch.cc @ 21882:d8104206e8a9
additional cleanups for kpse.cc
* kpse.cc: Use kpse instead of kpathsea consistently.
Define file and path macros using Octave functions.
Style fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 12 Jun 2016 11:18:55 -0400 |
parents | 40195d04b17c |
children | 02add2f597a1 |
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 { |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21871
diff
changeset
|
80 std::string elt_dir = kpse_element_dir (elt); |
1786 | 81 |
21873
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21871
diff
changeset
|
82 if (! elt_dir.empty ()) |
40195d04b17c
still more simplification of pathsearch
John W. Eaton <jwe@octave.org>
parents:
21871
diff
changeset
|
83 retval.push_back (elt_dir); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
84 } |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
85 } |
1786 | 86 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
87 return retval; |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
88 } |
1786 | 89 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
90 std::string |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
91 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
|
92 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
93 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
|
94 } |
4242 | 95 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
96 std::list<std::string> |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
97 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
|
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 |
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
100 ? 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
|
101 : std::list<std::string> ()); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
102 } |
4242 | 103 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
104 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
|
105 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
|
106 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
107 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
|
108 ? 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
|
109 } |
1786 | 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 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
|
112 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
|
113 { |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
114 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
|
115 ? 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
|
116 : std::list<std::string> ()); |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
117 } |
1786 | 118 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
119 void |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
120 directory_path::init (void) |
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
121 { |
21882
d8104206e8a9
additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents:
21873
diff
changeset
|
122 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
|
123 |
21882
d8104206e8a9
additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents:
21873
diff
changeset
|
124 if (! octave_kpse_initialized) |
21745
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 std::string val = octave::sys::env::getenv ("KPATHSEA_DEBUG"); |
1786 | 127 |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
128 if (! val.empty ()) |
21882
d8104206e8a9
additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents:
21873
diff
changeset
|
129 kpse_debug |= atoi (val.c_str ()); |
3174 | 130 |
21882
d8104206e8a9
additional cleanups for kpse.cc
John W. Eaton <jwe@octave.org>
parents:
21873
diff
changeset
|
131 octave_kpse_initialized = true; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
132 } |
1786 | 133 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
134 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
|
135 = 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
|
136 ? 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
|
137 : kpse_expand_default (m_orig_path, m_default_path)); |
1786 | 138 |
21867
0cdfd6d230e6
use std::list<std::string> instead of string_vector in pathsearch functions
John W. Eaton <jwe@octave.org>
parents:
21745
diff
changeset
|
139 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
|
140 m_path_elements.push_back (*pi); |
1786 | 141 |
21867
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_initialized = true; |
21745
bf1121302404
use namespace for dir_path class
John W. Eaton <jwe@octave.org>
parents:
21732
diff
changeset
|
143 } |
1786 | 144 } |