diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/io.c | 2 | ||||
-rw-r--r-- | src/util.c | 72 | ||||
-rw-r--r-- | src/util.h | 4 | ||||
-rw-r--r-- | src/uzbl-core.c | 68 |
4 files changed, 76 insertions, 70 deletions
@@ -1,3 +1,5 @@ +#define _POSIX_SOURCE + #include <stdio.h> #include "events.h" @@ -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]; @@ -6,12 +6,16 @@ typedef struct { gchar* default_value; } XDG_Var; +enum exp_type {EXP_ERR, EXP_SIMPLE_VAR, EXP_BRACED_VAR, EXP_EXPR, EXP_JS, EXP_ESCAPE}; + gchar* get_xdg_var(XDG_Var xdg); gchar* find_xdg_file(int xdg_type, const char* filename); gboolean file_exists(const char* filename); char* str_replace(const char* search, const char* replace, const char* string); gboolean for_each_line_in_file(const gchar *path, void (*callback)(const gchar *l, void *c), void *user_data); +enum exp_type get_exp_type(const gchar*); +gchar* find_existing_file(gchar*); char* itos(int val); gchar* strfree(gchar *str); gchar* argv_idx(const GArray*, const guint); diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 8cc20bb..4ee0129 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -165,24 +165,6 @@ create_var_to_name_hash() { /* --- UTILITY FUNCTIONS --- */ -enum exp_type {EXP_ERR, EXP_SIMPLE_VAR, EXP_BRACED_VAR, EXP_EXPR, EXP_JS, EXP_ESCAPE}; -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; -} /* * recurse == 1: don't expand '@(command)@' @@ -353,56 +335,6 @@ expand(const char* s, guint recurse) { } -/* 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; -} - - void clean_up(void) { if (uzbl.info.pid_str) { |