summaryrefslogtreecommitdiff
path: root/legacy/efreet
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2012-07-02 00:01:16 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-07-02 00:01:16 +0000
commit7c8d0f697d815aa5a5ce7c592abb7a7ab690e2b5 (patch)
tree67300c208ccbba8ea0bad1feef6eda0db4a71bc2 /legacy/efreet
parent65d1ef4715af9af7a394d2c0e41670a170bf14f7 (diff)
with user-dirs - expand env vars. i suspect we have to deal with
escapes too. SVN revision: 73115
Diffstat (limited to 'legacy/efreet')
-rw-r--r--legacy/efreet/src/lib/efreet_base.c47
1 files changed, 46 insertions, 1 deletions
diff --git a/legacy/efreet/src/lib/efreet_base.c b/legacy/efreet/src/lib/efreet_base.c
index 4cea7f31ae..8d57deda80 100644
--- a/legacy/efreet/src/lib/efreet_base.c
+++ b/legacy/efreet/src/lib/efreet_base.c
@@ -279,6 +279,51 @@ efreet_dirs_get(const char *key, const char *fallback)
279 return dirs; 279 return dirs;
280} 280}
281 281
282static const char *
283efreet_env_expand(const char *in)
284{
285 Eina_Strbuf *sb;
286 const char *ret, *p, *e1 = NULL, *e2 = NULL, *val;
287 char *env;
288
289 if (!in) return NULL;
290 sb = eina_strbuf_new();
291 if (!sb) return NULL;
292
293 /* maximum length of any env var is the input string */
294 env = alloca(strlen(in) + 1);
295 for (p = in; *p; p++)
296 {
297 if (!e1)
298 {
299 if (*p == '$') e1 = p + 1;
300 else eina_strbuf_append_char(sb, *p);
301 }
302 else if (!(((*p >= 'a') && (*p <= 'z')) ||
303 ((*p >= 'A') && (*p <= 'Z')) ||
304 ((*p >= '0') && (*p <= '9')) ||
305 (*p == '_')))
306 {
307 size_t len;
308
309 e2 = p;
310 len = (size_t)(e2 - e1);
311 if (len > 0)
312 {
313 memcpy(env, e1, len);
314 env[len] = 0;
315 val = getenv(env);
316 if (val) eina_strbuf_append(sb, val);
317 }
318 e1 = NULL;
319 eina_strbuf_append_char(sb, *p);
320 }
321 }
322 ret = eina_stringshare_add(eina_strbuf_string_get(sb));
323 eina_strbuf_free(sb);
324 return ret;
325}
326
282/** 327/**
283 * @internal 328 * @internal
284 * @param key The user-dirs key to lookup 329 * @param key The user-dirs key to lookup
@@ -334,5 +379,5 @@ fallback:
334 ret = alloca(strlen(home) + strlen(fallback) + 2); 379 ret = alloca(strlen(home) + strlen(fallback) + 2);
335 sprintf(ret, "%s/%s", home, fallback); 380 sprintf(ret, "%s/%s", home, fallback);
336 } 381 }
337 return eina_stringshare_add(ret); 382 return efreet_env_expand(ret);
338} 383}