From 59af2a8499160a369aceed1bd5cb32109fb5e77c Mon Sep 17 00:00:00 2001 From: koral Date: Thu, 10 Feb 2011 15:20:19 +0100 Subject: Moves additionnal utility functions to util.c. --- src/io.c | 2 ++ src/util.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- src/util.h | 4 ++++ src/uzbl-core.c | 68 ----------------------------------------------------- 4 files changed, 76 insertions(+), 70 deletions(-) diff --git a/src/io.c b/src/io.c index 80dd666..1c463db 100644 --- a/src/io.c +++ b/src/io.c @@ -1,3 +1,5 @@ +#define _POSIX_SOURCE + #include #include "events.h" diff --git a/src/util.c b/src/util.c index 2da484f..3cf6416 100644 --- a/src/util.c +++ b/src/util.c @@ -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