summaryrefslogtreecommitdiff
path: root/src/bin/e_path.c
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2004-11-25 03:37:45 +0000
committerCarsten Haitzler <raster@rasterman.com>2004-11-25 03:37:45 +0000
commit5e2388c886b15923f2b1350191524f40b0e9050a (patch)
treeeeb93c0db03cb87075ed74cc31367f669e5f2e72 /src/bin/e_path.c
parentf2b45ed47126d12986591cb02a6fcfc5908255fe (diff)
_ _ _ _ _____ ___
| | | | ___| | | | ___| __ ___ ___ _______ ___ / _ \__ _____ _ __ | |_| |/ _ \ | | | |_ | '__/ _ \/ _ \_ / _ \/ __| | | | \ \ / / _ \ '__| | _ | __/ | | | _|| | | __/ __// / __/\__ \ | |_| |\ V / __/ | |_| |_|\___|_|_| |_| |_| \___|\___/___\___||___/ \___/ \_/ \___|_| I put E17's wm code into cvs. Hell is freezing over. Duke Nukem Forever will be out next week. Snowballls take up residence in Hell. The Fat Lady sings. The End is nigh... :) SVN revision: 12247
Diffstat (limited to 'src/bin/e_path.c')
-rw-r--r--src/bin/e_path.c232
1 files changed, 232 insertions, 0 deletions
diff --git a/src/bin/e_path.c b/src/bin/e_path.c
new file mode 100644
index 0000000..c303743
--- /dev/null
+++ b/src/bin/e_path.c
@@ -0,0 +1,232 @@
1#include "e.h"
2
3/* local subsystem functions */
4static void _e_path_free(E_Path *ep);
5static void _e_path_cache_free(E_Path *ep);
6static Evas_Bool _e_path_cache_free_cb(Evas_Hash *hash, const char *key, void *data, void *fdata);
7
8/* local subsystem globals */
9static char _e_path_buf[PATH_MAX] = "";
10
11/* externally accessible functions */
12E_Path *
13e_path_new(void)
14{
15 E_Path *ep;
16
17 ep = E_OBJECT_ALLOC(E_Path, _e_path_free);
18 return ep;
19}
20
21void
22e_path_path_append(E_Path *ep, const char *path)
23{
24 E_OBJECT_CHECK(ep);
25 if (!path) return;
26 if (path[0] == '~')
27 {
28 char *new_path;
29 char *home_dir;
30 int len1, len2;
31
32 home_dir = e_user_homedir_get();
33 if (!home_dir) return;
34 len1 = strlen(home_dir);
35 len2 = strlen(path);
36 new_path = malloc(len1 + len2 + 1);
37 if (!new_path)
38 {
39 free(home_dir);
40 return;
41 }
42 strcpy(new_path, home_dir);
43 strcat(new_path, path + 1);
44 free(home_dir);
45 ep->dir_list = evas_list_append(ep->dir_list, new_path);
46 }
47 else
48 ep->dir_list = evas_list_append(ep->dir_list, strdup(path));
49 _e_path_cache_free(ep);
50}
51
52void
53e_path_path_prepend(E_Path *ep, const char *path)
54{
55 E_OBJECT_CHECK(ep);
56 if (!path) return;
57 if (path[0] == '~')
58 {
59 char *new_path;
60 char *home_dir;
61 int len1, len2;
62
63 home_dir = e_user_homedir_get();
64 if (!home_dir) return;
65 len1 = strlen(home_dir);
66 len2 = strlen(path);
67 new_path = malloc(len1 + len2 + 1);
68 if (!new_path)
69 {
70 free(home_dir);
71 return;
72 }
73 strcpy(new_path, home_dir);
74 strcat(new_path, path + 1);
75 free(home_dir);
76 ep->dir_list = evas_list_prepend(ep->dir_list, new_path);
77 }
78 else
79 ep->dir_list = evas_list_prepend(ep->dir_list, strdup(path));
80 _e_path_cache_free(ep);
81}
82
83void
84e_path_path_remove(E_Path *ep, const char *path)
85{
86 Evas_List *l;
87
88 E_OBJECT_CHECK(ep);
89 if (!path) return;
90 if (path[0] == '~')
91 {
92 char *new_path;
93 char *home_dir;
94 int len1, len2;
95
96 home_dir = e_user_homedir_get();
97 if (!home_dir) return;
98 len1 = strlen(home_dir);
99 len2 = strlen(path);
100 new_path = malloc(len1 + len2 + 1);
101 if (!new_path)
102 {
103 free(home_dir);
104 return;
105 }
106 strcpy(new_path, home_dir);
107 strcat(new_path, path + 1);
108 free(home_dir);
109 for (l = ep->dir_list; l; l = l->next)
110 {
111 char *p;
112
113 p = l->data;
114 if (p)
115 {
116 if (!strcmp(p, new_path))
117 {
118 ep->dir_list = evas_list_prepend(ep->dir_list, l->data);
119 free(new_path);
120 _e_path_cache_free(ep);
121 return;
122 }
123 }
124 }
125 free(new_path);
126 }
127 else
128 {
129 for (l = ep->dir_list; l; l = l->next)
130 {
131 char *p;
132
133 p = l->data;
134 if (p)
135 {
136 if (!strcmp(p, path))
137 {
138 ep->dir_list = evas_list_prepend(ep->dir_list, l->data);
139 _e_path_cache_free(ep);
140 return;
141 }
142 }
143 }
144 }
145}
146
147const char *
148e_path_find(E_Path *ep, const char *file)
149{
150 Evas_List *l;
151 char *str;
152
153 E_OBJECT_CHECK_RETURN(ep, NULL);
154 if (!file) return NULL;
155 _e_path_buf[0] = 0;
156 str = evas_hash_find(ep->hash, file);
157 if (str)
158 {
159 strcpy(_e_path_buf, str);
160 return _e_path_buf;
161 }
162 for (l = ep->dir_list; l; l = l->next)
163 {
164 char *p, *rp;
165
166 p = l->data;
167 if (p)
168 {
169 snprintf(_e_path_buf, sizeof(_e_path_buf), "%s/%s", p, file);
170 rp = e_file_realpath(_e_path_buf);
171 if ((rp) && (rp[0] != 0))
172 {
173 strcpy(_e_path_buf, rp);
174 free(rp);
175 if (evas_hash_size(ep->hash) >= 512)
176 _e_path_cache_free(ep);
177 ep->hash = evas_hash_add(ep->hash, file, strdup(_e_path_buf));
178 return _e_path_buf;
179 }
180 if (rp) free(rp);
181 }
182 }
183 return _e_path_buf;
184}
185
186void
187e_path_evas_append(E_Path *ep, Evas *evas)
188{
189 Evas_List *l;
190
191 E_OBJECT_CHECK(ep);
192 if (!evas) return;
193 for (l = ep->dir_list; l; l = l->next)
194 {
195 char *p, *rp;
196
197 p = l->data;
198 if (p) evas_font_path_append(evas, p);
199 }
200}
201
202/* local subsystem functions */
203static void
204_e_path_free(E_Path *ep)
205{
206 _e_path_cache_free(ep);
207 while (ep->dir_list)
208 {
209 free(ep->dir_list->data);
210 ep->dir_list = evas_list_remove(ep->dir_list, ep->dir_list->data);
211 }
212 free(ep);
213}
214
215static void
216_e_path_cache_free(E_Path *ep)
217{
218 if (!ep->hash) return;
219 while (evas_hash_size(ep->hash) > 0)
220 evas_hash_foreach(ep->hash, _e_path_cache_free_cb, ep);
221}
222
223static Evas_Bool
224_e_path_cache_free_cb(Evas_Hash *hash, const char *key, void *data, void *fdata)
225{
226 E_Path *ep;
227
228 ep = fdata;
229 free(data);
230 ep->hash = evas_hash_del(ep->hash, key, data);
231 return 0;
232}