summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorportix <portix@gmx.net>2010-12-14 11:43:41 +0100
committerportix <portix@gmx.net>2010-12-14 11:43:41 +0100
commitd0c36a391331d321e26983887ee4910485a118ed (patch)
treee8b0ec7266ee7f645d61154e40e5da7d440aacc1
parent37599008e5da021e24d26c9e3dd01030f2c78dfc (diff)
downloaddwb-d0c36a391331d321e26983887ee4910485a118ed.zip
remove dwb_free in most cases, clear status bar
-rw-r--r--src/commands.c22
-rw-r--r--src/completion.c10
-rw-r--r--src/download.c31
-rw-r--r--src/dwb.c91
-rw-r--r--src/dwb.h2
-rw-r--r--src/session.c11
-rw-r--r--src/util.c49
-rw-r--r--src/util.h2
-rw-r--r--src/view.c18
9 files changed, 124 insertions, 112 deletions
diff --git a/src/commands.c b/src/commands.c
index 36084dd9..200437f7 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -94,7 +94,7 @@ dwb_com_focus_input(Arg *a) {
if (value && !strcmp(value, "_dwb_no_input_")) {
ret = false;
}
- dwb_free(value);
+ FREE(value);
return ret;
}/*}}}*/
@@ -113,7 +113,7 @@ dwb_com_add_search_field(Arg *a) {
dwb.state.mode = SearchFieldMode;
dwb_set_normal_message(dwb.state.fview, false, "Enter a Keyword for marked search:");
dwb_focus_entry();
- dwb_free(value);
+ FREE(value);
return ret;
}/*}}}*/
@@ -148,7 +148,7 @@ dwb_com_find(Arg *arg) {
dwb.state.mode = FindMode;
dwb.state.forward_search = arg->b;
if (v->status->search_string) {
- dwb_free(v->status->search_string);
+ free(v->status->search_string);
v->status->search_string = NULL;
}
dwb_focus_entry();
@@ -537,8 +537,8 @@ dwb_com_remove_view(Arg *arg) {
/* clean up */
dwb_source_remove(gl);
- dwb_free(v->status);
- dwb_free(v);
+ FREE(v->status);
+ FREE(v);
dwb.state.views = g_list_delete_link(dwb.state.views, gl);
@@ -727,7 +727,7 @@ dwb_com_yank(Arg *arg) {
dwb_set_normal_message(dwb.state.fview, true, "Yanked: %s", message);
ret = true;
}
- dwb_free(text);
+ free(text);
}
return ret;
}/*}}}*/
@@ -744,7 +744,7 @@ dwb_com_paste(Arg *arg) {
dwb.state.nv = arg->n;
Arg a = { .p = text };
dwb_load_uri(&a);
- dwb_free(text);
+ free(text);
return true;
}
return false;
@@ -761,7 +761,7 @@ dwb_com_entry_delete_word(Arg *a) {
dwb_util_cut_text(text, new, position);
gtk_entry_set_text(GTK_ENTRY(dwb.gui.entry), text);
gtk_editable_set_position(GTK_EDITABLE(dwb.gui.entry), new);
- dwb_free(text);
+ FREE(text);
}
return true;
}/*}}}*/
@@ -776,7 +776,7 @@ dwb_com_entry_delete_letter(Arg *a) {
dwb_util_cut_text(text, position-1, position);
gtk_entry_set_text(GTK_ENTRY(dwb.gui.entry), text);
gtk_editable_set_position(GTK_EDITABLE(dwb.gui.entry), position-1);
- dwb_free(text);
+ FREE(text);
}
return true;
}/*}}}*/
@@ -788,7 +788,7 @@ dwb_com_entry_delete_line(Arg *a) {
char *text = gtk_editable_get_chars(GTK_EDITABLE(dwb.gui.entry), 0, -1);
gtk_entry_set_text(GTK_ENTRY(dwb.gui.entry), &text[position]);
- dwb_free(text);
+ FREE(text);
return true;
}/*}}}*/
@@ -834,7 +834,7 @@ dwb_com_entry_history_back(Arg *a) {
n = dwb.state.last_com_history->data;
char *text = gtk_editable_get_chars(GTK_EDITABLE(dwb.gui.entry), 0, -1);
dwb_prepend_navigation_with_argument(&dwb.fc.commands, text, NULL);
- dwb_free(text);
+ FREE(text);
}
}
else if ( dwb.state.last_com_history && dwb.state.last_com_history->prev ) {
diff --git a/src/completion.c b/src/completion.c
index b25d58db..d4355d36 100644
--- a/src/completion.c
+++ b/src/completion.c
@@ -149,7 +149,7 @@ dwb_comp_update_completion(GtkWidget *box, GList *comps, GList *active, int max,
void
dwb_comp_clean_completion() {
for (GList *l = dwb.comps.completions; l; l=l->next) {
- dwb_free(l->data);
+ FREE(l->data);
}
g_list_free(dwb.comps.completions);
gtk_widget_destroy(CURRENT_VIEW()->compbox);
@@ -247,7 +247,7 @@ dwb_comp_get_key_completion(gboolean entry) {
Completion *c = dwb_comp_get_completion_item(&n, m, value);
gtk_box_pack_start(GTK_BOX(CURRENT_VIEW()->compbox), c->event, false, false, 0);
list = g_list_append(list, c);
- dwb_free(value);
+ FREE(value);
}
}
return list;
@@ -302,7 +302,7 @@ dwb_comp_set_autcompletion(GList *l, WebSettings *s) {
void
dwb_comp_clean_autocompletion() {
for (GList *l = dwb.comps.auto_c; l; l=l->next) {
- dwb_free(l->data);
+ FREE(l->data);
}
g_list_free(dwb.comps.auto_c);
gtk_widget_destroy(CURRENT_VIEW()->autocompletion);
@@ -372,7 +372,7 @@ void
dwb_comp_clean_path_completion() {
if (dwb.comps.path_completion) {
for (GList *l = dwb.comps.path_completion; l; l=l->next) {
- dwb_free(l->data);
+ FREE(l->data);
}
g_list_free(dwb.comps.path_completion);
dwb.comps.path_completion = dwb.comps.active_path = NULL;
@@ -426,7 +426,7 @@ dwb_comp_get_path(GList *list, char *text) {
char *newpath = g_build_filename(path, filename, NULL);
char *store = g_strconcat(newpath, g_file_test(newpath, G_FILE_TEST_IS_DIR) ? "/" : "", NULL);
list = g_list_prepend(list, store);
- dwb_free(newpath);
+ FREE(newpath);
}
}
g_dir_close(dir);
diff --git a/src/download.c b/src/download.c
index 286eaf54..21f00069 100644
--- a/src/download.c
+++ b/src/download.c
@@ -38,19 +38,19 @@ dwb_get_download_command(const char *uri, const char *output) {
char *newcommand = NULL;
if ( (newcommand = dwb_util_string_replace(command, "dwb_uri", uri)) ) {
- dwb_free(command);
+ FREE(command);
command = newcommand;
}
if ( (newcommand = dwb_util_string_replace(command, "dwb_cookies", dwb.files.cookies)) ) {
- dwb_free(command);
+ FREE(command);
command = newcommand;
}
if ( (newcommand = dwb_util_string_replace(command, "dwb_output", output)) ) {
- dwb_free(command);
+ FREE(command);
command = newcommand;
}
if ( GET_BOOL("use-fifo") && (newcommand = dwb_util_string_replace(command, "dwb_fifo", dwb.files.fifo)) ) {
- dwb_free(command);
+ FREE(command);
command = newcommand;
}
return command;
@@ -83,7 +83,7 @@ dwb_dl_progress_cb(WebKitDownload *download) {
guint remaining = (guint)(elapsed / progress - elapsed);
char *message = g_strdup_printf("[%d:%02d][%d%%][%.3f/%.3f]", remaining/60, remaining%60, (int)(progress*100), current_size, total_size);
gtk_label_set_text(GTK_LABEL(label->rlabel), message);
- dwb_free(message);
+ FREE(message);
guint blue = ((1 - progress) * 0xaa);
guint green = progress * 0xaa;
@@ -92,7 +92,7 @@ dwb_dl_progress_cb(WebKitDownload *download) {
GdkColor color;
gdk_color_parse(colorstring, &color);
gtk_widget_modify_bg(label->event, GTK_STATE_NORMAL, &color);
- dwb_free(colorstring);
+ FREE(colorstring);
}/*}}}*/
/* dwb_dl_set_mimetype(const char *) {{{*/
@@ -102,7 +102,7 @@ dwb_dl_set_mimetype(const char *command) {
for (GList *l = dwb.fc.mimetypes; l; l=l->next) {
Navigation *n = l->data;
if (!strcmp(dwb.state.mimetype_request, n->first)) {
- dwb_free(n->second);
+ FREE(n->second);
n->second = g_strdup(command);
return;
}
@@ -125,7 +125,7 @@ dwb_dl_spawn(DwbDownload *dl) {
g_clear_error(&error);
}
dwb_dl_set_mimetype(dl->path);
- dwb_free(command);
+ FREE(command);
g_strfreev(argv);
}/*}}}*/
@@ -142,13 +142,16 @@ dwb_dl_status_cb(WebKitDownload *download) {
dwb_dl_spawn(label);
}
gtk_widget_destroy(label->event);
- dwb_free(label->path);
+ FREE(label->path);
downloads = g_list_delete_link(downloads, list);
}
if (!downloads) {
gtk_widget_hide(dwb.gui.downloadbar);
}
- dwb_free(dwb.state.mimetype_request);
+ if (dwb.state.mimetype_request) {
+ free(dwb.state.mimetype_request);
+ dwb.state.mimetype_request = NULL;
+ }
}
}/*}}}*/
@@ -248,14 +251,14 @@ dwb_dl_start() {
g_signal_connect(dwb.state.download, "notify::status", G_CALLBACK(dwb_dl_status_cb), NULL);
webkit_download_start(dwb.state.download);
}
- dwb_free(lastdir);
+ FREE(lastdir);
if (dwb.state.dl_action != Execute) {
lastdir = g_strdup(path);
}
dwb_normal_mode(true);
dwb.state.download = NULL;
- dwb_free(fullpath);
+ FREE(fullpath);
}/*}}}*/
/* dwb_dl_entry_set_directory() {{{*/
@@ -267,8 +270,8 @@ dwb_dl_entry_set_directory() {
dwb_entry_set_text(newdir);
- dwb_free(current_dir);
- dwb_free(newdir);
+ FREE(current_dir);
+ FREE(newdir);
}/*}}}*/
/* dwb_dl_entry_set_spawn_command{{{*/
diff --git a/src/dwb.c b/src/dwb.c
index 06e0aba5..c16c3e98 100644
--- a/src/dwb.c
+++ b/src/dwb.c
@@ -465,7 +465,7 @@ dwb_key_press_cb(GtkWidget *w, GdkEventKey *e, View *v) {
}
ret = dwb_eval_key(e);
}
- dwb_free(key);
+ FREE(key);
return ret;
}/*}}}*/
@@ -497,8 +497,10 @@ dwb_set_status_bar_text(GtkWidget *label, const char *text, GdkColor *fg, Pango
if (text) {
char *escaped = g_markup_escape_text(text, -1);
gtk_label_set_markup(GTK_LABEL(label), escaped);
- dwb_free(escaped);
+ FREE(escaped);
}
+ else
+ gtk_label_set_text(GTK_LABEL(label), NULL);
if (fg) {
gtk_widget_modify_fg(label, GTK_STATE_NORMAL, fg);
@@ -574,7 +576,7 @@ dwb_update_status_text(GList *gl, GtkAdjustment *a) {
if (v->status->block) {
char *js_items = v->status->block_current ? g_strdup_printf(" [%d]", v->status->items_blocked) : g_strdup(" [a]");
g_string_append(string, js_items);
- dwb_free(js_items);
+ FREE(js_items);
}
gboolean back = webkit_web_view_can_go_back(WEBKIT_WEB_VIEW(v->web));
@@ -592,7 +594,7 @@ dwb_update_status_text(GList *gl, GtkAdjustment *a) {
value == upper ? g_strdup(" [bot]") :
g_strdup_printf(" [%02d%%]", (int)(value * 100/upper));
g_string_append(string, position);
- dwb_free(position);
+ FREE(position);
}
dwb_set_status_bar_text(VIEW(gl)->rstatus, string->str, NULL, NULL);
@@ -606,8 +608,10 @@ dwb_update_status_text(GList *gl, GtkAdjustment *a) {
void
dwb_clean_load_end(GList *gl) {
View *v = gl->data;
- dwb_free(v->status->mimetype);
- v->status->mimetype = NULL;
+ if (v->status->mimetype) {
+ free(v->status->mimetype);
+ v->status->mimetype = NULL;
+ }
}/*}}}*/
/* dwb_navigation_from_webkit_history_item(WebKitWebHistoryItem *) return: (alloc) Navigation* {{{*/
@@ -770,7 +774,7 @@ dwb_clean_buffer(GList *gl) {
/* dwb_reload_scripts(GList *, WebSettings *s) {{{*/
static void
dwb_reload_scripts(GList *gl, WebSettings *s) {
- dwb_free(dwb.misc.scripts);
+ FREE(dwb.misc.scripts);
dwb_init_scripts();
dwb_com_reload(NULL);
}/*}}}*/
@@ -829,7 +833,7 @@ dwb_submit_searchengine(void) {
if (value) {
dwb.state.form_name = value;
}
- dwb_free(com);
+ FREE(com);
}/*}}}*/
/* dwb_save_searchengine {{{*/
@@ -841,12 +845,15 @@ dwb_save_searchengine(void) {
if (text && strlen(text) > 0) {
dwb_append_navigation_with_argument(&dwb.fc.searchengines, text, dwb.state.search_engine);
dwb_set_normal_message(dwb.state.fview, true, "Search saved");
- dwb_free(dwb.state.search_engine);
+ if (dwb.state.search_engine) {
+ free(dwb.state.search_engine);
+ dwb.state.search_engine = NULL;
+ }
}
else {
dwb_set_error_message(dwb.state.fview, "No keyword specified, aborting.");
}
- dwb_free(text);
+ free(text);
}
dwb_normal_mode(false);
@@ -923,7 +930,7 @@ dwb_update_hints(GdkEventKey *e) {
dwb_set_status_bar_text(VIEW(dwb.state.fview)->lstatus, text, &dwb.color.active_fg, dwb.font.fd_normal);
com = g_strdup_printf("dwb_update_hints(\"%d\")", dwb.state.nummod);
- dwb_free(text);
+ FREE(text);
}
else if (DWB_TAB_KEY(e)) {
if (e->state & GDK_SHIFT_MASK) {
@@ -938,7 +945,7 @@ dwb_update_hints(GdkEventKey *e) {
}
if (com) {
buffer = dwb_execute_script(com, true);
- dwb_free(com);
+ free(com);
}
if (buffer) {
if (!strcmp("_dwb_no_hints_", buffer)) {
@@ -959,7 +966,7 @@ dwb_update_hints(GdkEventKey *e) {
dwb_normal_mode(true);
}
}
- dwb_free(buffer);
+ FREE(buffer);
return true;
}/*}}}*/
@@ -1094,7 +1101,7 @@ dwb_tab_label_set_text(GList *gl, const char *text) {
char *escaped = g_markup_printf_escaped("%d : %s", g_list_position(dwb.state.views, gl), uri ? uri : "about:blank");
gtk_label_set_text(GTK_LABEL(v->tablabel), escaped);
- dwb_free(escaped);
+ FREE(escaped);
}/*}}}*/
@@ -1120,8 +1127,7 @@ dwb_update_status(GList *gl) {
dwb_tab_label_set_text(gl, title);
dwb_update_status_text(gl, NULL);
- if (filename)
- dwb_free(filename);
+ FREE(filename);
}/*}}}*/
/* dwb_update_tab_label {{{*/
@@ -1212,8 +1218,8 @@ dwb_load_uri(Arg *arg) {
fprintf(stderr, "Cannot open %s: %s", (char*)arg->p, error->message);
g_clear_error(&error);
}
- dwb_free(tmp);
- dwb_free(path);
+ FREE(tmp);
+ FREE(path);
}
}
}
@@ -1225,7 +1231,7 @@ dwb_load_uri(Arg *arg) {
/* load uri */
webkit_web_view_load_uri(CURRENT_WEBVIEW(), uri);
- dwb_free(uri);
+ FREE(uri);
}/*}}}*/
/* dwb_update_layout() {{{*/
@@ -1277,7 +1283,7 @@ dwb_eval_editing_key(GdkEventKey *e) {
}
}
}
- dwb_free(key);
+ FREE(key);
return ret;
}/*}}}*/
@@ -1372,7 +1378,7 @@ dwb_eval_key(GdkEventKey *e) {
if (tmp) {
dwb_com_simple_command(tmp);
}
- dwb_free(key);
+ FREE(key);
return ret;
}/*}}}*/
@@ -1443,10 +1449,8 @@ dwb_update_search(gboolean forward) {
const char *text = GET_TEXT();
int matches;
if (strlen(text) > 0) {
- if (v->status->search_string) {
- dwb_free(v->status->search_string);
- }
- v->status->search_string = g_strdup(GET_TEXT());
+ FREE(v->status->search_string);
+ v->status->search_string = g_strdup(text);
}
if (!v->status->search_string) {
return false;
@@ -1489,7 +1493,7 @@ dwb_user_script_cb(GIOChannel *channel, GIOCondition condition, char *filename)
while (g_io_channel_read_line(channel, &line, NULL, NULL, &error) == G_IO_STATUS_NORMAL) {
dwb_parse_command_line(g_strchomp(line));
- dwb_free(line);
+ FREE(line);
}
if (error) {
fprintf(stderr, "Cannot read from std_out: %s\n", error->message);
@@ -1551,7 +1555,7 @@ dwb_get_scripts() {
}
i++;
}
- dwb_free(content);
+ FREE(content);
}
}
@@ -1588,7 +1592,7 @@ gboolean
dwb_clean_up() {
for (GList *l = dwb.keymap; l; l=l->next) {
KeyMap *m = l->data;
- dwb_free(m);
+ FREE(m);
}
g_list_free(dwb.keymap);
g_hash_table_remove_all(dwb.settings);
@@ -1650,11 +1654,11 @@ dwb_save_keys() {
KeyMap *map = l->data;
char *sc = g_strdup_printf("%s %s", dwb_modmask_to_string(map->mod), map->key ? map->key : "");
g_key_file_set_value(keyfile, dwb.misc.profile, map->map->n.first, sc);
- dwb_free(sc);
+ FREE(sc);
}
if ( (content = g_key_file_to_data(keyfile, &size, &error)) ) {
g_file_set_contents(dwb.files.keys, content, size, &error);
- dwb_free(content);
+ free(content);
}
if (error) {
fprintf(stderr, "Couldn't save keyfile: %s", error->message);
@@ -1680,11 +1684,11 @@ dwb_save_settings() {
char *value = dwb_util_arg_to_char(&s->arg, s->type);
g_key_file_set_value(keyfile, dwb.misc.profile, s->n.first, value ? value : "" );
- dwb_free(value);
+ FREE(value);
}
if ( (content = g_key_file_to_data(keyfile, &size, &error)) ) {
g_file_set_contents(dwb.files.settings, content, size, &error);
- dwb_free(content);
+ free(content);
}
if (error) {
fprintf(stderr, "Couldn't save settingsfile: %s\n", error->message);
@@ -1901,7 +1905,7 @@ dwb_read_settings() {
g_hash_table_insert(dwb.settings, key, s);
set = true;
}
- dwb_free(value);
+ FREE(value);
}
if (!set) {
g_hash_table_insert(dwb.settings, key, &DWB_SETTINGS[j]);
@@ -2070,13 +2074,14 @@ dwb_init_gui() {
GList *
dwb_init_file_content(GList *gl, const char *filename, Content_Func func) {
char *content = dwb_util_get_file_content(filename);
+
if (content) {
char **token = g_strsplit(content, "\n", 0);
int length = MAX(g_strv_length(token) - 1, 0);
for (int i=0; i < length; i++) {
gl = g_list_append(gl, func(token[i]));
}
- dwb_free(content);
+ free(content);
g_strfreev(token);
}
return gl;
@@ -2089,7 +2094,7 @@ dwb_get_search_completion(const char *text) {
char *uri = n->second;
n->second = dwb_util_domain_from_uri(uri);
- dwb_free(uri);
+ FREE(uri);
return n;
}
@@ -2139,8 +2144,8 @@ dwb_init_files() {
dwb.fc.cookies_allow = dwb_init_file_content(dwb.fc.cookies_allow, dwb.files.cookies_allow, (Content_Func)dwb_return);
dwb.fc.content_block_allow = dwb_init_file_content(dwb.fc.content_block_allow, dwb.files.content_block_allow, (Content_Func)dwb_return);
- dwb_free(path);
- dwb_free(profile_path);
+ FREE(path);
+ FREE(profile_path);
}/*}}}*/
/* signals {{{*/
@@ -2184,7 +2189,7 @@ dwb_init_proxy() {
newproxy = g_strrstr(proxy, "http://") ? g_strdup(proxy) : g_strdup_printf("http://%s", proxy);
dwb.misc.proxyuri = soup_uri_new(newproxy);
g_object_set(G_OBJECT(dwb.misc.soupsession), "proxy-uri", use_proxy ? dwb.misc.proxyuri : NULL, NULL);
- dwb_free(newproxy);
+ FREE(newproxy);
}
}/*}}}*/
@@ -2286,7 +2291,7 @@ dwb_handle_channel(GIOChannel *c, GIOCondition condition, void *data) {
g_strstrip(line);
dwb_parse_command_line(line);
g_io_channel_flush(c, NULL);
- dwb_free(line);
+ free(line);
}
return true;
}/*}}}*/
@@ -2320,8 +2325,8 @@ dwb_init_fifo(int single) {
fprintf(ff, "add_view %s\n", path);
- dwb_free(curr_dir);
- dwb_free(path);
+ FREE(curr_dir);
+ FREE(path);
}
else {
fprintf(ff, "add_view %s\n", dwb.misc.argv[i]);
@@ -2342,7 +2347,7 @@ dwb_init_fifo(int single) {
if (GET_BOOL("use-fifo")) {
char *filename = g_strdup_printf("%s-%d.fifo", dwb.misc.name, getpid());
dwb.files.fifo = g_build_filename(path, filename, NULL);
- dwb_free(filename);
+ FREE(filename);
if (!g_file_test(dwb.files.fifo, G_FILE_TEST_EXISTS)) {
mkfifo(dwb.files.fifo, 0600);
@@ -2350,7 +2355,7 @@ dwb_init_fifo(int single) {
dwb_open_channel(dwb.files.fifo);
}
- dwb_free(path);
+ FREE(path);
}/*}}}*/
/*}}}*/
diff --git a/src/dwb.h b/src/dwb.h
index 2e56d7cd..4cbe923b 100644
--- a/src/dwb.h
+++ b/src/dwb.h
@@ -2,6 +2,7 @@
#define DWB_H
#include <gtk/gtk.h>
#include <webkit/webkit.h>
+#include <stdlib.h>
#define NAME "dwb"
/* SETTINGS MAKROS {{{*/
@@ -64,6 +65,7 @@ function get_value(e) { value = e.value ? e.id + \" \" + e.value : e.id; console
#define WEBVIEW_FROM_ARG(arg) (WEBKIT_WEB_VIEW(((View*)(arg && arg->p ? ((GSList*)arg->p)->data : dwb.state.fview->data))->web))
#define CLEAR_COMMAND_TEXT(X) dwb_set_status_bar_text(VIEW(X)->lstatus, NULL, NULL, NULL)
+#define FREE(X) if ((X)) free((X))
#define DIGIT(X) (X->keyval >= GDK_0 && X->keyval <= GDK_9)
#define ALPHA(X) ((X->keyval >= GDK_A && X->keyval <= GDK_Z) || (X->keyval >= GDK_a && X->keyval <= GDK_z) || X->keyval == GDK_space)
diff --git a/src/session.c b/src/session.c
index 816d2337..4017f1fd 100644
--- a/src/session.c
+++ b/src/session.c
@@ -13,7 +13,7 @@ dwb_session_get_groups() {
char *content = dwb_util_get_file_content(dwb.files.session);
if (content) {
groups = g_regex_split_simple("^g:", content, G_REGEX_MULTILINE, G_REGEX_MATCH_NOTEMPTY);
- dwb_free(content);
+ free(content);
}
return groups;
}/*}}}*/
@@ -34,7 +34,7 @@ dwb_session_get_group(const char *name) {
i++;
}
g_strfreev(groups);
- dwb_free(group);
+ FREE(group);
}
return content;
}/*}}}*/
@@ -65,7 +65,8 @@ dwb_session_list() {
g_strfreev(group);
}
g_strfreev(content);
- dwb_free(path);
+ FREE(path);
+
exit(EXIT_SUCCESS);
}/*}}}*/
@@ -99,7 +100,7 @@ dwb_session_restore(const char *name) {
WebKitWebHistoryItem *item = webkit_web_history_item_new_with_data(line[1], line[2]);
webkit_web_back_forward_list_add_item(bf_list, item);
last = current;
- dwb_free(uri);
+ FREE(uri);
uri = g_strdup(line[1]);
}
if (i == length && lastweb)
@@ -154,7 +155,7 @@ dwb_session_save(const char *name) {
}
i++;
}
- dwb_free(group);
+ FREE(group);
g_strfreev(groups);
}
dwb_util_set_file_content(dwb.files.session, buffer->str);
diff --git a/src/util.c b/src/util.c
index b62b5818..ba8141c1 100644
--- a/src/util.c
+++ b/src/util.c
@@ -33,10 +33,11 @@ dwb_util_cut_text(char *text, int start, int end) {
/* dwb_util_is_hex(const char *string) {{{*/
gboolean
dwb_util_is_hex(const char *string) {
- char *dup = g_strdup(string);
+ char *dup, *loc;
+ dup = loc = g_strdup(string);
gboolean ret = !strtok(dup, "1234567890abcdefABCDEF");
- dwb_free(dup);
+ FREE(loc);
return ret;
}/*}}}*/
/* dwb_util_test_connect(const char *uri) return: int {{{*/
@@ -104,7 +105,7 @@ dwb_util_keyval_to_char(guint keyval) {
return key;
}
else {
- dwb_free(key);
+ FREE(key);
return NULL;
}
}/*}}}*/
@@ -233,7 +234,7 @@ dwb_util_get_directory_entries(const char *path, const char *text) {
char *newpath = g_build_filename(path, filename, NULL);
if (g_file_test(newpath, G_FILE_TEST_IS_DIR)) {
store = g_strconcat(newpath, "/", NULL);
- dwb_free(newpath);
+ FREE(newpath);
}
else {
store = newpath;
@@ -264,8 +265,8 @@ dwb_util_get_directory_content(GString **buffer, const char *dirname) {
fprintf(stderr, "Cannot read %s: %s\n", filename, error->message);
g_clear_error(&error);
}
- dwb_free(filepath);
- dwb_free(content);
+ FREE(filepath);
+ FREE(content);
}
}
g_dir_close (dir);
@@ -315,7 +316,7 @@ dwb_util_get_data_dir(const char *dir) {
if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
return path;
}
- dwb_free(path);
+ FREE(path);
}
return path;
}/*}}}*/
@@ -340,7 +341,7 @@ dwb_navigation_new_from_line(const char *text) {
if (text) {
line = g_strsplit(text, " ", 2);
nv = dwb_navigation_new(line[0], line[1]);
- dwb_free(line);
+ FREE(line);
}
return nv;
}/*}}}*/
@@ -348,9 +349,9 @@ dwb_navigation_new_from_line(const char *text) {
/* dwb_navigation_free(Navigation *n){{{*/
void
dwb_navigation_free(Navigation *n) {
- dwb_free(n->first);
- dwb_free(n->second);
- dwb_free(n);
+ FREE(n->first);
+ FREE(n->second);
+ FREE(n);
}/*}}}*/
/*}}}*/
@@ -381,9 +382,9 @@ dwb_quickmark_new_from_line(const char *line) {
/* dwb_quickmark_free(Quickmark *q) {{{*/
void
dwb_quickmark_free(Quickmark *q) {
- dwb_free(q->key);
+ FREE(q->key);
dwb_navigation_free(q->nav);
- dwb_free(q);
+ FREE(q);
}/*}}}*/
/*}}}*/
@@ -391,9 +392,9 @@ dwb_quickmark_free(Quickmark *q) {
void
dwb_web_settings_free(WebSettings *s) {
if (s->type == Char || s->type == ColorChar) {
- dwb_free(s->arg.p);
+ FREE(s->arg.p);
}
- dwb_free(s);
+ FREE(s);
}
/* dwb_true, dwb_false {{{*/
@@ -406,12 +407,14 @@ gboolean
dwb_true() {
return true;
}/*}}}*/
+
/* dwb_return(const char *) return char * (alloc) {{{*/
char *
dwb_return(const char *ret) {
return g_strdup(ret);
}/*}}}*/
+/* dwb_malloc(size_t size) return: void* {{{*/
void *
dwb_malloc(size_t size) {
void *r;
@@ -421,17 +424,15 @@ dwb_malloc(size_t size) {
exit(EXIT_SUCCESS);
}
return r;
-}
-gboolean
+}/*}}}*/
+
+void
dwb_free(void *p) {
- if (p) {
- g_free(p);
- p = NULL;
- return true;
- }
- return false;
+ if (p)
+ free(p);
}
+/* dwb_util_domain_from_uri (char *uri) return: char* (alloc){{{*/
char *
dwb_util_domain_from_uri(char *uri) {
if (!uri)
@@ -449,4 +450,4 @@ dwb_util_domain_from_uri(char *uri) {
}
char *ret = domain[0] ? g_strdup(domain) : g_strdup(uri_p);
return ret;
-}
+}/*}}}*/
diff --git a/src/util.h b/src/util.h
index b8208def..b7030d92 100644
--- a/src/util.h
+++ b/src/util.h
@@ -49,7 +49,7 @@ gboolean dwb_false(void);
char * dwb_return(const char *);
void * dwb_malloc(size_t);
-gboolean dwb_free(void *);
+void dwb_free(void *);
char * dwb_util_domain_from_uri(char *);
#endif
diff --git a/src/view.c b/src/view.c
index 03e524fb..dc95112b 100644
--- a/src/view.c
+++ b/src/view.c
@@ -53,7 +53,7 @@ dwb_web_view_button_press_cb(WebKitWebView *web, GdkEventButton *e, GList *gl) {
dwb_add_view(&a);
ret = true;
}
- dwb_free(clipboard);
+ FREE(clipboard);
}
else if (e->button == 1 && e->type == GDK_BUTTON_PRESS) {
dwb_focus(gl);
@@ -337,7 +337,7 @@ dwb_web_view_load_status_cb(WebKitWebView *web, GParamSpec *pspec, GList *gl) {
text = g_strdup_printf("loading [%d%%]", (int)(progress * 100));
dwb_set_status_bar_text(VIEW(gl)->rstatus, text, NULL, NULL);
gtk_window_set_title(GTK_WINDOW(dwb.gui.window), text);
- dwb_free(text);
+ FREE(text);
break;
}
}/*}}}*/
@@ -422,7 +422,6 @@ dwb_view_entry_keypress_cb(GtkWidget* entry, GdkEventKey *e) {
/* dwb_entry_activate_cb (GtkWidget *entry) {{{*/
static gboolean
dwb_view_entry_activate_cb(GtkEntry* entry) {
- char *text = g_strdup(gtk_entry_get_text(entry));
gboolean ret = false;
Mode mode = dwb.state.mode;
@@ -443,7 +442,7 @@ dwb_view_entry_activate_cb(GtkEntry* entry) {
dwb_parse_key_setting(GET_TEXT());
}
else if (mode == CommandMode) {
- dwb_parse_command_line(text);
+ dwb_parse_command_line(GET_TEXT());
}
else if (mode == DownloadGetPath) {
dwb_dl_start();
@@ -453,12 +452,11 @@ dwb_view_entry_activate_cb(GtkEntry* entry) {
dwb_end();
}
else {
- Arg a = { .n = 0, .p = text };
+ Arg a = { .n = 0, .p = (char*)GET_TEXT() };
dwb_load_uri(&a);
- dwb_prepend_navigation_with_argument(&dwb.fc.commands, text, NULL);
+ dwb_prepend_navigation_with_argument(&dwb.fc.commands, a.p, NULL);
dwb_normal_mode(true);
}
- dwb_free(text);
return true;
}/*}}}*/
@@ -565,8 +563,10 @@ dwb_view_clean_vars(GList *gl) {
View *v = gl->data;
v->status->items_blocked = 0;
- if (v->status->current_host)
- dwb_free(v->status->current_host);
+ if (v->status->current_host) {
+ free(v->status->current_host);
+ v->status->current_host = NULL;
+ }
}/*}}}*/
/* dwb_view_create_web_view(View *v) return: GList * {{{*/