summaryrefslogtreecommitdiff
path: root/src/bin/e_path.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2005-05-20 03:09:44 +0000
committerCarsten Haitzler <raster@rasterman.com>2005-05-20 03:09:44 +0000
commit242e7b4744ba3c5254d0d68e567a06fbae031a81 (patch)
treefcd39db716258f0f3d00f542001e5fbe6c8b1e2c /src/bin/e_path.c
parentfc0105416156c25ea36bc7bc941b58fe0014bf91 (diff)
shorne's patch
SVN revision: 14861
Diffstat (limited to 'src/bin/e_path.c')
-rw-r--r--src/bin/e_path.c242
1 files changed, 210 insertions, 32 deletions
diff --git a/src/bin/e_path.c b/src/bin/e_path.c
index 96f1b6f..dabcaf5 100644
--- a/src/bin/e_path.c
+++ b/src/bin/e_path.c
@@ -22,13 +22,14 @@ e_path_new(void)
22} 22}
23 23
24void 24void
25e_path_path_append(E_Path *ep, const char *path) 25e_path_default_path_append(E_Path *ep, const char *path)
26{ 26{
27 E_OBJECT_CHECK(ep); 27 E_OBJECT_CHECK(ep);
28 E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE); 28 E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
29 if (!path) return; 29 if (!path) return;
30 if (path[0] == '~') 30 if (path[0] == '~')
31 { 31 {
32 E_Path_Dir *epd;
32 char *new_path; 33 char *new_path;
33 char *home_dir; 34 char *home_dir;
34 int len1, len2; 35 int len1, len2;
@@ -43,24 +44,52 @@ e_path_path_append(E_Path *ep, const char *path)
43 free(home_dir); 44 free(home_dir);
44 return; 45 return;
45 } 46 }
47 epd = malloc(sizeof(E_Path_Dir));
48 if (!epd)
49 {
50 free(home_dir);
51 free(new_path);
52 return;
53 }
54
55 epd->dir = new_path;
46 strcpy(new_path, home_dir); 56 strcpy(new_path, home_dir);
47 strcat(new_path, path + 1); 57 strcat(new_path, path + 1);
48 free(home_dir); 58 free(home_dir);
49 ep->dir_list = evas_list_append(ep->dir_list, new_path); 59 ep->default_dir_list = evas_list_append(ep->default_dir_list, epd);
50 } 60 }
51 else 61 else
52 ep->dir_list = evas_list_append(ep->dir_list, strdup(path)); 62 {
63 E_Path_Dir *epd;
64 epd = malloc(sizeof(E_Path_Dir));
65 if (!epd)
66 return;
67 epd->dir = strdup(path);
68 ep->default_dir_list = evas_list_append(ep->default_dir_list, epd);
69 }
53 _e_path_cache_free(ep); 70 _e_path_cache_free(ep);
54} 71}
55 72
56void 73void
57e_path_path_prepend(E_Path *ep, const char *path) 74e_path_user_path_set(E_Path *ep, Evas_List **user_dir_list)
75{
76
77 E_OBJECT_CHECK(ep);
78 E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
79
80 ep->user_dir_list = user_dir_list;
81 _e_path_cache_free(ep);
82}
83
84void
85e_path_user_path_append(E_Path *ep, const char *path)
58{ 86{
59 E_OBJECT_CHECK(ep); 87 E_OBJECT_CHECK(ep);
60 E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE); 88 E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
61 if (!path) return; 89 if (!path) return;
62 if (path[0] == '~') 90 if (path[0] == '~')
63 { 91 {
92 E_Path_Dir *epd;
64 char *new_path; 93 char *new_path;
65 char *home_dir; 94 char *home_dir;
66 int len1, len2; 95 int len1, len2;
@@ -75,18 +104,83 @@ e_path_path_prepend(E_Path *ep, const char *path)
75 free(home_dir); 104 free(home_dir);
76 return; 105 return;
77 } 106 }
107 epd = malloc(sizeof(E_Path_Dir));
108 if (!epd)
109 {
110 free(home_dir);
111 free(new_path);
112 return;
113 }
114
115 epd->dir = new_path;
78 strcpy(new_path, home_dir); 116 strcpy(new_path, home_dir);
79 strcat(new_path, path + 1); 117 strcat(new_path, path + 1);
80 free(home_dir); 118 free(home_dir);
81 ep->dir_list = evas_list_prepend(ep->dir_list, new_path); 119 *(ep->user_dir_list) = evas_list_append(*(ep->user_dir_list), epd);
82 } 120 }
83 else 121 else
84 ep->dir_list = evas_list_prepend(ep->dir_list, strdup(path)); 122 {
123 E_Path_Dir *epd;
124 epd = malloc(sizeof(E_Path_Dir));
125 if (!epd)
126 return;
127 epd->dir = strdup(path);
128 *(ep->user_dir_list) = evas_list_append(*(ep->user_dir_list), epd);
129 }
85 _e_path_cache_free(ep); 130 _e_path_cache_free(ep);
86} 131}
87 132
88void 133void
89e_path_path_remove(E_Path *ep, const char *path) 134e_path_user_path_prepend(E_Path *ep, const char *path)
135{
136 E_OBJECT_CHECK(ep);
137 E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
138 if (!path) return;
139 if (path[0] == '~')
140 {
141 E_Path_Dir *epd;
142 char *new_path;
143 char *home_dir;
144 int len1, len2;
145
146 home_dir = e_user_homedir_get();
147 if (!home_dir) return;
148 len1 = strlen(home_dir);
149 len2 = strlen(path);
150 new_path = malloc(len1 + len2 + 1);
151 if (!new_path)
152 {
153 free(home_dir);
154 return;
155 }
156 epd = malloc(sizeof(E_Path_Dir));
157 if (!epd)
158 {
159 free(home_dir);
160 free(new_path);
161 return;
162 }
163
164 epd->dir = new_path;
165 strcpy(new_path, home_dir);
166 strcat(new_path, path + 1);
167 free(home_dir);
168 *(ep->user_dir_list) = evas_list_prepend(*(ep->user_dir_list), epd);
169 }
170 else
171 {
172 E_Path_Dir *epd;
173 epd = malloc(sizeof(E_Path_Dir));
174 if (!epd)
175 return;
176 epd->dir = strdup(path);
177 *(ep->user_dir_list) = evas_list_prepend(*(ep->user_dir_list), epd);
178 }
179 _e_path_cache_free(ep);
180}
181
182void
183e_path_user_path_remove(E_Path *ep, const char *path)
90{ 184{
91 Evas_List *l; 185 Evas_List *l;
92 186
@@ -112,16 +206,19 @@ e_path_path_remove(E_Path *ep, const char *path)
112 strcpy(new_path, home_dir); 206 strcpy(new_path, home_dir);
113 strcat(new_path, path + 1); 207 strcat(new_path, path + 1);
114 free(home_dir); 208 free(home_dir);
115 for (l = ep->dir_list; l; l = l->next) 209 for (l = *(ep->user_dir_list); l; l = l->next)
116 { 210 {
117 char *p; 211 E_Path_Dir *epd;
118 212
119 p = l->data; 213 epd = l->data;
120 if (p) 214 if (epd->dir)
121 { 215 {
122 if (!strcmp(p, new_path)) 216 if (!strcmp(epd->dir, new_path))
123 { 217 {
124 ep->dir_list = evas_list_prepend(ep->dir_list, l->data); 218 *(ep->user_dir_list) = evas_list_remove_list(
219 *(ep->user_dir_list), l);
220 free(epd->dir);
221 free(epd);
125 free(new_path); 222 free(new_path);
126 _e_path_cache_free(ep); 223 _e_path_cache_free(ep);
127 return; 224 return;
@@ -132,16 +229,18 @@ e_path_path_remove(E_Path *ep, const char *path)
132 } 229 }
133 else 230 else
134 { 231 {
135 for (l = ep->dir_list; l; l = l->next) 232 for (l = *(ep->user_dir_list); l; l = l->next)
136 { 233 {
137 char *p; 234 E_Path_Dir *epd;
138 235 epd = l->data;
139 p = l->data; 236 if (epd->dir)
140 if (p)
141 { 237 {
142 if (!strcmp(p, path)) 238 if (!strcmp(epd->dir, path))
143 { 239 {
144 ep->dir_list = evas_list_prepend(ep->dir_list, l->data); 240 *(ep->user_dir_list) = evas_list_remove_list(
241 *(ep->user_dir_list), l);
242 free(epd->dir);
243 free(epd);
145 _e_path_cache_free(ep); 244 _e_path_cache_free(ep);
146 return; 245 return;
147 } 246 }
@@ -158,6 +257,7 @@ e_path_find(E_Path *ep, const char *file)
158 257
159 E_OBJECT_CHECK_RETURN(ep, NULL); 258 E_OBJECT_CHECK_RETURN(ep, NULL);
160 E_OBJECT_TYPE_CHECK_RETURN(ep, E_PATH_TYPE, NULL); 259 E_OBJECT_TYPE_CHECK_RETURN(ep, E_PATH_TYPE, NULL);
260
161 if (!file) return NULL; 261 if (!file) return NULL;
162 _e_path_buf[0] = 0; 262 _e_path_buf[0] = 0;
163 str = evas_hash_find(ep->hash, file); 263 str = evas_hash_find(ep->hash, file);
@@ -166,14 +266,40 @@ e_path_find(E_Path *ep, const char *file)
166 strcpy(_e_path_buf, str); 266 strcpy(_e_path_buf, str);
167 return _e_path_buf; 267 return _e_path_buf;
168 } 268 }
169 for (l = ep->dir_list; l; l = l->next) 269 /* Look in the default dir list */
270 for (l = ep->default_dir_list; l; l = l->next)
271 {
272 E_Path_Dir *epd;
273 char *rp;
274
275 epd = l->data;
276 if (epd->dir)
277 {
278 snprintf(_e_path_buf, sizeof(_e_path_buf), "%s/%s", epd->dir, file);
279 rp = ecore_file_realpath(_e_path_buf);
280 if ((rp) && (rp[0] != 0))
281 {
282 strncpy(_e_path_buf, rp, sizeof(_e_path_buf) - 1);
283 _e_path_buf[sizeof(_e_path_buf) - 1] = 0;
284 free(rp);
285 if (evas_hash_size(ep->hash) >= 512)
286 _e_path_cache_free(ep);
287 ep->hash = evas_hash_add(ep->hash, file, strdup(_e_path_buf));
288 return _e_path_buf;
289 }
290 if (rp) free(rp);
291 }
292 }
293 /* Look in the users dir list */
294 for (l = *(ep->user_dir_list); l; l = l->next)
170 { 295 {
171 char *p, *rp; 296 E_Path_Dir *epd;
297 char *rp;
172 298
173 p = l->data; 299 epd = l->data;
174 if (p) 300 if (epd->dir)
175 { 301 {
176 snprintf(_e_path_buf, sizeof(_e_path_buf), "%s/%s", p, file); 302 snprintf(_e_path_buf, sizeof(_e_path_buf), "%s/%s", epd->dir, file);
177 rp = ecore_file_realpath(_e_path_buf); 303 rp = ecore_file_realpath(_e_path_buf);
178 if ((rp) && (rp[0] != 0)) 304 if ((rp) && (rp[0] != 0))
179 { 305 {
@@ -195,16 +321,63 @@ void
195e_path_evas_append(E_Path *ep, Evas *evas) 321e_path_evas_append(E_Path *ep, Evas *evas)
196{ 322{
197 Evas_List *l; 323 Evas_List *l;
324 Evas_List *dir_list;
198 325
199 E_OBJECT_CHECK(ep); 326 E_OBJECT_CHECK(ep);
200 E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE); 327 E_OBJECT_TYPE_CHECK(ep, E_PATH_TYPE);
201 if (!evas) return; 328 if (!evas) return;
202 for (l = ep->dir_list; l; l = l->next) 329
330 dir_list = e_path_dir_list_get(ep);
331
332 for (l = dir_list; l; l = l->next)
203 { 333 {
204 char *p; 334 E_Path_Dir *epd;
205 335
206 p = l->data; 336 epd = l->data;
207 if (p) evas_font_path_append(evas, p); 337 if (epd->dir) evas_font_path_append(evas, epd->dir);
338 }
339}
340
341/* compine default_list and and user_list int and easy to use list */
342Evas_List *
343e_path_dir_list_get(E_Path *ep)
344{
345 Evas_List *dir_list;
346 Evas_List *l;
347 E_Path_Dir *new_epd;
348 E_Path_Dir *epd;
349
350 dir_list = NULL;
351
352 for (l = ep->default_dir_list; l; l = l->next)
353 {
354 epd = l->data;
355 new_epd = malloc(sizeof(E_Path_Dir));
356 new_epd->dir = strdup(epd->dir);
357 dir_list = evas_list_append(dir_list, new_epd);
358 }
359 for (l = *(ep->user_dir_list); l; l = l->next)
360 {
361 epd = l->data;
362 new_epd = malloc(sizeof(E_Path_Dir));
363 new_epd->dir = strdup(epd->dir);
364 dir_list = evas_list_append(dir_list, new_epd);
365 }
366
367 return dir_list;
368}
369
370void
371e_path_dir_list_free(Evas_List *dir_list)
372{
373 E_Path_Dir *epd;
374
375 while (dir_list)
376 {
377 epd = dir_list->data;
378 dir_list = evas_list_remove_list(dir_list, dir_list);
379 free(epd->dir);
380 free(epd);
208 } 381 }
209} 382}
210 383
@@ -213,10 +386,14 @@ static void
213_e_path_free(E_Path *ep) 386_e_path_free(E_Path *ep)
214{ 387{
215 _e_path_cache_free(ep); 388 _e_path_cache_free(ep);
216 while (ep->dir_list) 389 while (ep->default_dir_list)
217 { 390 {
218 free(ep->dir_list->data); 391 E_Path_Dir *epd;
219 ep->dir_list = evas_list_remove_list(ep->dir_list, ep->dir_list); 392 epd = ep->default_dir_list->data;
393 free(epd->dir);
394 free(epd);
395 ep->default_dir_list = evas_list_remove_list(ep->default_dir_list,
396 ep->default_dir_list);
220 } 397 }
221 free(ep); 398 free(ep);
222} 399}
@@ -227,6 +404,7 @@ _e_path_cache_free(E_Path *ep)
227 if (!ep->hash) return; 404 if (!ep->hash) return;
228 evas_hash_foreach(ep->hash, _e_path_cache_free_cb, NULL); 405 evas_hash_foreach(ep->hash, _e_path_cache_free_cb, NULL);
229 evas_hash_free(ep->hash); 406 evas_hash_free(ep->hash);
407 ep->hash = NULL;
230} 408}
231 409
232static Evas_Bool 410static Evas_Bool