aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar koral <koral@mailoo.org>2011-02-10 15:20:19 +0100
committerGravatar koral <koral@mailoo.org>2011-02-10 15:20:19 +0100
commit59af2a8499160a369aceed1bd5cb32109fb5e77c (patch)
tree8ca62aa594b1ee548566236bf73998dc0f1b720d
parentece7f8a0bc6f4b45e931ce2634f79fe6c84a18c9 (diff)
Moves additionnal utility functions to util.c.
-rw-r--r--src/io.c2
-rw-r--r--src/util.c72
-rw-r--r--src/util.h4
-rw-r--r--src/uzbl-core.c68
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 <stdio.h>
#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<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];
diff --git a/src/util.h b/src/util.h
index e2ecf73..a0efe85 100644
--- a/src/util.h
+++ b/src/util.h
@@ -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) {