Mercurial > hg > octave-nkf
annotate liboctave/pathsearch.cc @ 12283:0664a7ddd944 release-3-4-x
README.MacOS: Spelling corrections.
author | Ben Abbott <bpabbott@mac.com> |
---|---|
date | Fri, 28 Jan 2011 22:27:17 -0500 |
parents | fd0a3ac60b0e |
children | 7dd7cccf0757 |
rev | line source |
---|---|
1786 | 1 /* |
2 | |
11523 | 3 Copyright (C) 1996-2011 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 | |
2021 | 23 #ifdef HAVE_CONFIG_H |
24 #include <config.h> | |
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" |
34 #include "str-vec.h" | |
3024 | 35 #include "str-vec.h" |
1786 | 36 |
4399 | 37 #include "kpse.cc" |
4378 | 38 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
39 dir_path::static_members *dir_path::static_members::instance = 0; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
40 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
41 dir_path::static_members::static_members (void) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
42 : xpath_sep_char (SEPCHAR), xpath_sep_str (SEPCHAR_STR) { } |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
43 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
44 bool |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
45 dir_path::static_members::instance_ok (void) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
46 { |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
47 bool retval = true; |
5777 | 48 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
49 if (! instance) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
50 instance = new static_members (); |
5777 | 51 |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
52 if (! instance) |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
53 { |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
54 (*current_liboctave_error_handler) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
55 ("unable to create dir_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
|
56 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
57 retval = false; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
58 } |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
59 |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
60 return retval; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
61 } |
1786 | 62 |
63 string_vector | |
64 dir_path::elements (void) | |
65 { | |
66 return initialized ? pv : string_vector (); | |
67 } | |
68 | |
69 string_vector | |
70 dir_path::all_directories (void) | |
71 { | |
72 int count = 0; | |
73 string_vector retval; | |
74 | |
75 if (initialized) | |
76 { | |
77 int len = pv.length (); | |
78 | |
79 int nmax = len > 32 ? len : 32; | |
80 | |
81 retval.resize (len); | |
82 | |
83 for (int i = 0; i < len; i++) | |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
84 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
85 str_llist_type *elt_dirs = kpse_element_dirs (pv[i]); |
1786 | 86 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
87 if (elt_dirs) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
88 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
89 str_llist_elt_type *dir; |
1786 | 90 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
91 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
92 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
93 const std::string elt_dir = STR_LLIST (*dir); |
1786 | 94 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
95 if (! elt_dir.empty ()) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
96 { |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
97 if (count == nmax) |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
98 nmax *= 2; |
1786 | 99 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
100 retval.resize (nmax); |
3415 | 101 |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
102 retval[count++] = elt_dir; |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
103 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
104 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
105 } |
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
106 } |
1786 | 107 |
108 retval.resize (count); | |
109 } | |
110 | |
111 return retval; | |
112 } | |
113 | |
3504 | 114 std::string |
115 dir_path::find_first (const std::string& nm) | |
1786 | 116 { |
4390 | 117 return initialized ? kpse_path_search (p, nm, true) : std::string (); |
4242 | 118 } |
119 | |
120 string_vector | |
121 dir_path::find_all (const std::string& nm) | |
122 { | |
4390 | 123 return initialized ? kpse_all_path_search (p, nm) : string_vector (); |
4242 | 124 } |
125 | |
126 std::string | |
127 dir_path::find_first_of (const string_vector& names) | |
128 { | |
4390 | 129 return initialized |
130 ? kpse_path_find_first_of (p, names, true) : std::string (); | |
1786 | 131 } |
132 | |
133 string_vector | |
4242 | 134 dir_path::find_all_first_of (const string_vector& names) |
1786 | 135 { |
4390 | 136 return initialized |
137 ? kpse_all_path_find_first_of (p, names) : string_vector (); | |
1786 | 138 } |
139 | |
140 void | |
141 dir_path::init (void) | |
142 { | |
8008
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
143 static bool octave_kpathsea_initialized = false; |
4d13a7a2f6ab
dir_path: use singleton class for static data members
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
144 |
3174 | 145 if (! octave_kpathsea_initialized) |
1786 | 146 { |
4394 | 147 std::string val = octave_env::getenv ("KPATHSEA_DEBUG"); |
1786 | 148 |
4394 | 149 if (! val.empty ()) |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
150 kpathsea_debug |= atoi (val.c_str ()); |
3174 | 151 |
152 octave_kpathsea_initialized = true; | |
1786 | 153 } |
154 | |
4395 | 155 p = kpse_path_expand (p_default.empty () |
10314
07ebe522dac2
untabify liboctave C++ sources
John W. Eaton <jwe@octave.org>
parents:
10158
diff
changeset
|
156 ? p_orig : kpse_expand_default (p_orig, p_default)); |
3196 | 157 |
1786 | 158 int count = 0; |
8021 | 159 for (kpse_path_iterator pi (p); pi != std::string::npos; pi++) |
4394 | 160 count++; |
1786 | 161 |
162 pv.resize (count); | |
163 | |
4394 | 164 kpse_path_iterator pi (p); |
1786 | 165 |
166 for (int i = 0; i < count; i++) | |
4398 | 167 pv[i] = *pi++; |
1786 | 168 |
169 initialized = true; | |
170 } |