From e0acf99635e715b088eee33f83e4524ed3c7f734 Mon Sep 17 00:00:00 2001 From: Brendan Taylor Date: Tue, 2 Nov 2010 21:14:48 -0600 Subject: moved for_each_line_in_file into util.c --- src/util.c | 19 +++++++++++++++++++ src/util.h | 3 +++ src/uzbl-core.c | 37 +++++++++++++------------------------ 3 files changed, 35 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/util.c b/src/util.c index 54d1d02..c9c728e 100644 --- a/src/util.c +++ b/src/util.c @@ -89,3 +89,22 @@ str_replace (const char* search, const char* replace, const char* string) { return ret; } +gboolean +for_each_line_in_file(const gchar *path, void (*callback)(const gchar *l, void *c), void *user_data) { + gchar *line = NULL; + gsize len; + + GIOChannel *chan = g_io_channel_new_file(path, "r", NULL); + + if (chan) { + while (g_io_channel_read_line(chan, &line, &len, NULL, NULL) == G_IO_STATUS_NORMAL) { + callback(line, user_data); + g_free(line); + } + g_io_channel_unref (chan); + + return TRUE; + } + + return FALSE; +} diff --git a/src/util.h b/src/util.h index 2a00b8a..f03f13e 100644 --- a/src/util.h +++ b/src/util.h @@ -13,3 +13,6 @@ 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); diff --git a/src/uzbl-core.c b/src/uzbl-core.c index 8b2dba5..4125514 100644 --- a/src/uzbl-core.c +++ b/src/uzbl-core.c @@ -364,26 +364,6 @@ strfree(gchar *str) { gchar* argv_idx(const GArray *a, const guint idx) { return g_array_index(a, gchar*, idx); } -void -for_each_line_in_file(gchar *path, void (*callback)(const gchar *l, void *c), void *user_data) { \ - gchar *line = NULL; - gsize len; - - GIOChannel *chan = g_io_channel_new_file(path, "r", NULL); - - if (chan) { - while (g_io_channel_read_line(chan, &line, &len, NULL, NULL) == G_IO_STATUS_NORMAL) { - callback(line, user_data); - g_free(line); - } - g_io_channel_unref (chan); - } else { - gchar *tmp = g_strdup_printf("File %s can not be read.", path); - send_event(COMMAND_ERROR, tmp, NULL); - g_free(tmp); - } -} - /* search a PATH style string for an existing file+path combination */ gchar* find_existing_file(gchar* path_list) { @@ -953,7 +933,12 @@ include(WebKitWebView *page, GArray *argv, GString *result) { pe = parseenv(argv_idx(argv, 0)); if((path = find_existing_file(pe))) { - for_each_line_in_file(path, parse_cmd_line_cb, NULL); + if(!for_each_line_in_file(path, parse_cmd_line_cb, NULL)) { + gchar *tmp = g_strdup_printf("File %s can not be read.", path); + send_event(COMMAND_ERROR, tmp, NULL); + g_free(tmp); + } + send_event(FILE_INCLUDED, path, NULL); g_free(path); } @@ -2079,9 +2064,13 @@ settings_init () { s->config_file = find_xdg_file (0, "/uzbl/config"); } - if (s->config_file) - for_each_line_in_file(s->config_file, parse_cmd_line_cb, NULL); - else if (uzbl.state.verbose) + if (s->config_file) { + if(!for_each_line_in_file(s->config_file, parse_cmd_line_cb, NULL)) { + gchar *tmp = g_strdup_printf("File %s can not be read.", s->config_file); + send_event(COMMAND_ERROR, tmp, NULL); + g_free(tmp); + } + } else if (uzbl.state.verbose) printf ("No configuration file loaded.\n"); if(s->connect_socket_names) -- cgit v1.2.3