diff options
author | koral <koral@mailoo.org> | 2011-02-10 15:20:19 +0100 |
---|---|---|
committer | koral <koral@mailoo.org> | 2011-02-10 15:20:19 +0100 |
commit | 59af2a8499160a369aceed1bd5cb32109fb5e77c (patch) | |
tree | 8ca62aa594b1ee548566236bf73998dc0f1b720d /src/util.c | |
parent | ece7f8a0bc6f4b45e931ce2634f79fe6c84a18c9 (diff) |
Moves additionnal utility functions to util.c.
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 72 |
1 files changed, 70 insertions, 2 deletions
@@ -6,8 +6,7 @@ #include "util.h" -const XDG_Var XDG[] = -{ +const XDG_Var XDG[] = { { "XDG_CONFIG_HOME", "~/.config" }, { "XDG_DATA_HOME", "~/.local/share" }, { "XDG_CACHE_HOME", "~/.cache" }, @@ -110,6 +109,75 @@ for_each_line_in_file(const gchar *path, void (*callback)(const gchar *l, void * } +enum exp_type +get_exp_type(const gchar *s) { + /* variables */ + if(*(s+1) == '(') + return EXP_EXPR; + else if(*(s+1) == '{') + return EXP_BRACED_VAR; + else if(*(s+1) == '<') + return EXP_JS; + else if(*(s+1) == '[') + return EXP_ESCAPE; + else + return EXP_SIMPLE_VAR; + + /*@notreached@*/ +return EXP_ERR; +} + + +/* search a PATH style string for an existing file+path combination */ +gchar* +find_existing_file(gchar* path_list) { + int i=0; + int cnt; + gchar **split; + gchar *tmp = NULL; + gchar *executable; + + if(!path_list) + return NULL; + + split = g_strsplit(path_list, ":", 0); + while(split[i]) + i++; + + if(i<=1) { + tmp = g_strdup(split[0]); + g_strfreev(split); + return tmp; + } + else + cnt = i-1; + + i=0; + tmp = g_strdup(split[cnt]); + g_strstrip(tmp); + if(tmp[0] == '/') + executable = g_strdup_printf("%s", tmp+1); + else + executable = g_strdup(tmp); + g_free(tmp); + + while(i<cnt) { + tmp = g_strconcat(g_strstrip(split[i]), "/", executable, NULL); + if(g_file_test(tmp, G_FILE_TEST_EXISTS)) { + g_strfreev(split); + return tmp; + } + else + g_free(tmp); + i++; + } + +g_free(executable); + g_strfreev(split); + return NULL; +} + + char* itos(int val) { char tmp[20]; |