1786
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
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 |
4378
|
37 #include "kpse.h" |
|
38 |
3174
|
39 static bool octave_kpathsea_initialized = false; |
1786
|
40 |
|
41 string_vector |
|
42 dir_path::elements (void) |
|
43 { |
|
44 return initialized ? pv : string_vector (); |
|
45 } |
|
46 |
|
47 string_vector |
|
48 dir_path::all_directories (void) |
|
49 { |
|
50 int count = 0; |
|
51 string_vector retval; |
|
52 |
|
53 if (initialized) |
|
54 { |
|
55 int len = pv.length (); |
|
56 |
|
57 int nmax = len > 32 ? len : 32; |
|
58 |
|
59 retval.resize (len); |
|
60 |
|
61 for (int i = 0; i < len; i++) |
|
62 { |
4394
|
63 str_llist_type *elt_dirs = kpse_element_dirs (pv[i]); |
1786
|
64 |
3415
|
65 if (elt_dirs) |
1786
|
66 { |
3415
|
67 str_llist_elt_type *dir; |
1786
|
68 |
3415
|
69 for (dir = *elt_dirs; dir; dir = STR_LLIST_NEXT (*dir)) |
1786
|
70 { |
4390
|
71 const std::string elt_dir = STR_LLIST (*dir); |
1786
|
72 |
4390
|
73 if (! elt_dir.empty ()) |
3415
|
74 { |
|
75 if (count == nmax) |
|
76 nmax *= 2; |
1786
|
77 |
3415
|
78 retval.resize (nmax); |
|
79 |
|
80 retval[count++] = elt_dir; |
|
81 } |
1786
|
82 } |
|
83 } |
|
84 } |
|
85 |
|
86 retval.resize (count); |
|
87 } |
|
88 |
|
89 return retval; |
|
90 } |
|
91 |
3504
|
92 std::string |
|
93 dir_path::find_first (const std::string& nm) |
1786
|
94 { |
4390
|
95 return initialized ? kpse_path_search (p, nm, true) : std::string (); |
4242
|
96 } |
|
97 |
|
98 string_vector |
|
99 dir_path::find_all (const std::string& nm) |
|
100 { |
4390
|
101 return initialized ? kpse_all_path_search (p, nm) : string_vector (); |
4242
|
102 } |
|
103 |
|
104 std::string |
|
105 dir_path::find_first_of (const string_vector& names) |
|
106 { |
4390
|
107 return initialized |
|
108 ? kpse_path_find_first_of (p, names, true) : std::string (); |
1786
|
109 } |
|
110 |
|
111 string_vector |
4242
|
112 dir_path::find_all_first_of (const string_vector& names) |
1786
|
113 { |
4390
|
114 return initialized |
|
115 ? kpse_all_path_find_first_of (p, names) : string_vector (); |
1786
|
116 } |
|
117 |
|
118 void |
|
119 dir_path::init (void) |
|
120 { |
3174
|
121 if (! octave_kpathsea_initialized) |
1786
|
122 { |
4394
|
123 std::string val = octave_env::getenv ("KPATHSEA_DEBUG"); |
1786
|
124 |
4394
|
125 if (! val.empty ()) |
|
126 kpathsea_debug |= atoi (val.c_str ()); |
3174
|
127 |
|
128 octave_kpathsea_initialized = true; |
1786
|
129 } |
|
130 |
4395
|
131 p = kpse_path_expand (p_default.empty () |
|
132 ? p_orig : kpse_expand_default (p_orig, p_default)); |
3196
|
133 |
1786
|
134 int count = 0; |
4394
|
135 for (kpse_path_iterator pi (p); pi != NPOS; pi++) |
|
136 count++; |
1786
|
137 |
|
138 pv.resize (count); |
|
139 |
4394
|
140 kpse_path_iterator pi (p); |
1786
|
141 |
|
142 for (int i = 0; i < count; i++) |
4395
|
143 pv[i] = *pi++; |
1786
|
144 |
|
145 initialized = true; |
|
146 } |
|
147 |
|
148 /* |
|
149 ;;; Local Variables: *** |
|
150 ;;; mode: C++ *** |
|
151 ;;; End: *** |
|
152 */ |