comparison liboctave/pathsearch.cc @ 3505:5a2c5361dbf1

[project @ 2000-02-01 11:04:15 by jwe]
author jwe
date Tue, 01 Feb 2000 11:05:08 +0000
parents 5eef8a2294bd
children f3278ec3ccb7
comparison
equal deleted inserted replaced
3504:5eef8a2294bd 3505:5a2c5361dbf1
27 #include <cstdlib> 27 #include <cstdlib>
28 28
29 #include <string> 29 #include <string>
30 30
31 #include "lo-utils.h" 31 #include "lo-utils.h"
32 #include "oct-kpse.h"
32 #include "pathsearch.h" 33 #include "pathsearch.h"
33 #include "str-vec.h" 34 #include "str-vec.h"
34 #include "str-vec.h" 35 #include "str-vec.h"
35 36
36 extern "C"
37 {
38 // Have to redefine these because they conflict with new C++ keywords
39 // or otherwise cause trouble...
40 #define string kpse_string
41
42 #include <kpathsea/default.h>
43 #include <kpathsea/expand.h>
44 #include <kpathsea/pathsearch.h>
45 #include <kpathsea/progname.h>
46
47 extern unsigned int kpathsea_debug;
48
49 #undef string
50 }
51
52 static bool octave_kpathsea_initialized = false; 37 static bool octave_kpathsea_initialized = false;
53 38
54 string_vector 39 string_vector
55 dir_path::elements (void) 40 dir_path::elements (void)
56 { 41 {
71 56
72 retval.resize (len); 57 retval.resize (len);
73 58
74 for (int i = 0; i < len; i++) 59 for (int i = 0; i < len; i++)
75 { 60 {
76 str_llist_type *elt_dirs = kpse_element_dirs (pv[i].c_str ()); 61 str_llist_type *elt_dirs
62 = ::octave_kpse_element_dirs (pv[i].c_str ());
77 63
78 if (elt_dirs) 64 if (elt_dirs)
79 { 65 {
80 str_llist_elt_type *dir; 66 str_llist_elt_type *dir;
81 67
107 { 93 {
108 std::string retval; 94 std::string retval;
109 95
110 if (initialized) 96 if (initialized)
111 { 97 {
112 char *tmp = kpse_path_search (p.c_str (), nm.c_str (), true); 98 char *tmp = ::octave_kpse_path_search (p.c_str (), nm.c_str (), true);
113 if (tmp) 99 if (tmp)
114 { 100 {
115 retval = tmp; 101 retval = tmp;
116 free (tmp); 102 free (tmp);
117 } 103 }
125 { 111 {
126 string_vector retval; 112 string_vector retval;
127 113
128 if (initialized) 114 if (initialized)
129 { 115 {
130 kpse_string *tmp = kpse_all_path_search (p.c_str (), nm.c_str ()); 116 char **tmp = ::octave_kpse_all_path_search (p.c_str (), nm.c_str ());
131 117
132 if (tmp) 118 if (tmp)
133 { 119 {
134 int count = 0; 120 int count = 0;
135 kpse_string *ptr = tmp; 121 char **ptr = tmp;
136 while (*ptr++) 122 while (*ptr++)
137 count++; 123 count++;
138 124
139 retval.resize (count); 125 retval.resize (count);
140 126
147 } 133 }
148 134
149 void 135 void
150 dir_path::set_program_name (const std::string& nm) 136 dir_path::set_program_name (const std::string& nm)
151 { 137 {
152 kpse_set_progname (nm.c_str ()); 138 ::octave_kpse_set_progname (nm.c_str ());
153 } 139 }
154 140
155 void 141 void
156 dir_path::init (void) 142 dir_path::init (void)
157 { 143 {
163 kpathsea_debug |= atoi (s); 149 kpathsea_debug |= atoi (s);
164 150
165 octave_kpathsea_initialized = true; 151 octave_kpathsea_initialized = true;
166 } 152 }
167 153
168 kpse_clear_dir_cache (); 154 ::octave_kpse_clear_dir_cache ();
169 155
170 char *t1 = 0; 156 char *t1 = 0;
171 157
172 if (p_default.empty ()) 158 if (p_default.empty ())
173 t1 = kpse_path_expand (p_orig.c_str ()); 159 t1 = ::octave_kpse_path_expand (p_orig.c_str ());
174 else 160 else
175 { 161 {
176 char *t2 = kpse_expand_default (p_orig.c_str (), p_default.c_str ()); 162 char *t2
177 163 = ::octave_kpse_expand_default (p_orig.c_str (), p_default.c_str ());
178 t1 = kpse_path_expand (t2); 164
165 t1 = ::octave_kpse_path_expand (t2);
179 166
180 if (t2) 167 if (t2)
181 free (t2); 168 free (t2);
182 } 169 }
183 170
188 } 175 }
189 else 176 else
190 p = std::string (); 177 p = std::string ();
191 178
192 int count = 0; 179 int count = 0;
193 char *path_elt = kpse_path_element (p.c_str ()); 180 char *path_elt = ::octave_kpse_path_element (p.c_str ());
194 while (path_elt) 181 while (path_elt)
195 { 182 {
196 path_elt = kpse_path_element (0); 183 path_elt = ::octave_kpse_path_element (0);
197 count++; 184 count++;
198 } 185 }
199 186
200 pv.resize (count); 187 pv.resize (count);
201 188
202 path_elt = kpse_path_element (p.c_str ()); 189 path_elt = ::octave_kpse_path_element (p.c_str ());
203 190
204 for (int i = 0; i < count; i++) 191 for (int i = 0; i < count; i++)
205 { 192 {
206 pv[i] = path_elt; 193 pv[i] = path_elt;
207 path_elt = kpse_path_element (0); 194 path_elt = ::octave_kpse_path_element (0);
208 } 195 }
209 196
210 initialized = true; 197 initialized = true;
211 } 198 }
212 199