Moved variables to the top of function.
authorDaniel Carl <danielcarl@gmx.de>
Fri, 29 Mar 2013 22:54:55 +0000 (23:54 +0100)
committerDaniel Carl <danielcarl@gmx.de>
Fri, 29 Mar 2013 22:54:55 +0000 (23:54 +0100)
src/command.c
src/completion.c
src/dom.c
src/hints.c
src/history.c
src/keybind.c
src/main.c
src/setting.c
src/util.c

index 1591369..d46e6ea 100644 (file)
@@ -225,7 +225,7 @@ gboolean command_scroll(const Arg *arg)
 {
     GtkAdjustment *adjust = (arg->i & VB_SCROLL_AXIS_H) ? vb.gui.adjust_h : vb.gui.adjust_v;
 
-    int direction  = (arg->i & (1 << 2)) ? 1 : -1;
+    int direction = (arg->i & (1 << 2)) ? 1 : -1;
 
     /* type scroll */
     if (arg->i & VB_SCROLL_TYPE_SCROLL) {
@@ -281,8 +281,7 @@ gboolean command_unmap(const Arg *arg)
 gboolean command_set(const Arg *arg)
 {
     gboolean success;
-    char *line = NULL;
-    char *param;
+    char *param = NULL, *line = NULL;
 
     if (!arg->s || !strlen(arg->s)) {
         return FALSE;
index 2db1e4e..32fd67b 100644 (file)
@@ -127,10 +127,8 @@ void completion_clean()
 static GList *completion_init_completion(GList *target, GList *source,
     Comp_Func func, const char *input, const char *prefix)
 {
-    char *command = NULL;
-    char *data = NULL;
+    char *command = NULL, *data = NULL, **token = NULL;
     gboolean match;
-    char **token = NULL;
 
     /* remove counts before command and save it to print it later in inputbox */
     vb.comps.count  = g_ascii_strtoll(input, &command, 10);
index c372423..2c4dcc8 100644 (file)
--- a/src/dom.c
+++ b/src/dom.c
@@ -65,12 +65,14 @@ void dom_clear_focus(void)
 gboolean dom_is_editable(Element *element)
 {
     gboolean result = FALSE;
+    char *tagname, *type;
+
     if (!element) {
         return result;
     }
 
-    char *tagname = webkit_dom_element_get_tag_name(element);
-    char *type = webkit_dom_element_get_attribute(element, "type");
+    tagname = webkit_dom_element_get_tag_name(element);
+    type    = webkit_dom_element_get_attribute(element, "type");
     if (!g_ascii_strcasecmp(tagname, "textarea")) {
         result = TRUE;
     } else if (!g_ascii_strcasecmp(tagname, "input")
index 161033e..bba07a2 100644 (file)
@@ -45,10 +45,11 @@ void hints_init(WebKitWebFrame *frame)
 
 void hints_clear()
 {
+    char *js, *value = NULL;
+
     hints_observe_input(FALSE);
     if (CLEAN_MODE(vb.state.mode) == VB_MODE_HINTING) {
-        char *js = g_strdup_printf("%s.clear();", HINT_VAR);
-        char *value = NULL;
+        js = g_strdup_printf("%s.clear();", HINT_VAR);
         vb_eval_script(webkit_web_view_get_main_frame(vb.gui.webview), js, HINT_FILE, &value);
         g_free(value);
         g_free(js);
index aa016bf..8c9aeec 100644 (file)
@@ -47,8 +47,9 @@ static void history_write_to_file(GList *list, const char *file);
  */
 void history_cleanup(void)
 {
+    const char *file;
     for (HistoryType i = HISTORY_FIRST; i < HISTORY_LAST; i++) {
-        const char *file = history_get_file_by_type(i);
+        file = history_get_file_by_type(i);
         history_write_to_file(history_load(file), file);
     }
 }
@@ -58,8 +59,9 @@ void history_cleanup(void)
  */
 void history_add(HistoryType type, const char *value)
 {
-    const char *file = history_get_file_by_type(type);
     FILE *f;
+    const char *file = history_get_file_by_type(type);
+
     if ((f = fopen(file, "a+"))) {
         file_lock_set(fileno(f), F_WRLCK);
 
index 712153f..269e543 100644 (file)
@@ -51,12 +51,13 @@ void keybind_cleanup(void)
 
 gboolean keybind_add_from_string(char *keys, const char *command, const Mode mode)
 {
+    char **token = NULL;
     if (keys == NULL || *keys == '\0') {
         return FALSE;
     }
 
     /* split the input string into command and parameter part */
-    char **token = g_strsplit(command, " ", 2);
+    token = g_strsplit(command, " ", 2);
     if (!token[0] || !command_exists(token[0])) {
         g_strfreev(token);
         return FALSE;
index eb13bf0..53d0d55 100644 (file)
@@ -127,8 +127,7 @@ gboolean vb_eval_script(WebKitWebFrame *frame, char *script, char *file, char **
 
 gboolean vb_load_uri(const Arg *arg)
 {
-    char *uri;
-    char *path = arg->s;
+    char *uri, *rp, *path = arg->s;
     struct stat st;
 
     if (!path) {
@@ -142,12 +141,10 @@ gboolean vb_load_uri(const Arg *arg)
 
     /* check if the path is a file path */
     if (stat(path, &st) == 0) {
-        char *rp = realpath(path, NULL);
+        rp  = realpath(path, NULL);
         uri = g_strdup_printf("file://%s", rp);
     } else if (!strchr(path, '.')) {
-        char *part  = NULL;
-        char *tmpl  = NULL;
-        char *query = NULL;
+        char *part  = NULL, *tmpl  = NULL, *query = NULL;
 
         /* look up for a searchengine with handle */
         if ((part = strchr(path, ' '))) {
@@ -174,8 +171,7 @@ gboolean vb_load_uri(const Arg *arg)
 
     if (arg->i == VB_TARGET_NEW) {
         guint i = 0;
-        char *cmd[5];
-        char xid[64];
+        char *cmd[5], xid[64];
 
         cmd[i++] = *args;
         if (vb.embed) {
@@ -287,6 +283,7 @@ void vb_set_widget_font(GtkWidget *widget, const VbColor *fg, const VbColor *bg,
 
 void vb_update_statusbar()
 {
+    int max, val, num;
     GString *status = g_string_new("");
 
     /* show current count */
@@ -298,7 +295,7 @@ void vb_update_statusbar()
 
     /* show the active downloads */
     if (vb.state.downloads) {
-        int num = g_list_length(vb.state.downloads);
+        num = g_list_length(vb.state.downloads);
         g_string_append_printf(status, " %d %s", num, num == 1 ? "download" : "downloads");
     }
 
@@ -308,8 +305,8 @@ void vb_update_statusbar()
     }
 
     /* show the scroll status */
-    int max = gtk_adjustment_get_upper(vb.gui.adjust_v) - gtk_adjustment_get_page_size(vb.gui.adjust_v);
-    int val = (int)(gtk_adjustment_get_value(vb.gui.adjust_v) / max * 100);
+    max = gtk_adjustment_get_upper(vb.gui.adjust_v) - gtk_adjustment_get_page_size(vb.gui.adjust_v);
+    val = (int)(gtk_adjustment_get_value(vb.gui.adjust_v) / max * 100);
 
     if (max == 0) {
         g_string_append(status, " All");
@@ -511,8 +508,7 @@ static void vb_new_request_cb(SoupSession *session, SoupMessage *message)
 
 static void vb_gotheaders_cb(SoupMessage *message)
 {
-    GSList *list = NULL;
-    GSList *p = NULL;
+    GSList *list = NULL, *p = NULL;
 
     for(p = list = soup_cookies_from_response(message); p; p = g_slist_next(p)) {
         vb_set_cookie((SoupCookie*)p->data);
@@ -576,8 +572,7 @@ static void vb_inspector_finished(WebKitWebInspector *inspector)
 static gboolean vb_process_input(const char *input)
 {
     gboolean success;
-    char *command = NULL;
-    char **token;
+    char *command = NULL, **token;
 
     if (!input || !strlen(input)) {
         return FALSE;
@@ -656,13 +651,12 @@ void vb_inputbox_print(gboolean force, const MessageType type, gboolean hide, co
 
 static void vb_run_user_script(WebKitWebFrame *frame)
 {
-    char *js      = NULL;
+    char *js = NULL, *value = NULL;
     GError *error = NULL;
 
     if (g_file_test(vb.files[FILES_SCRIPT], G_FILE_TEST_IS_REGULAR)
         && g_file_get_contents(vb.files[FILES_SCRIPT], &js, NULL, &error)
     ) {
-        char *value = NULL;
         gboolean success = vb_eval_script(frame, js, vb.files[FILES_SCRIPT], &value);
         if (!success) {
             fprintf(stderr, "%s", value);
@@ -776,6 +770,8 @@ static void vb_init_core(void)
 
 static void vb_read_config(void)
 {
+    char *line, **lines;
+
     /* load default config */
     for (guint i = 0; default_config[i].command != NULL; i++) {
         if (!vb_process_input(default_config[i].command)) {
@@ -784,8 +780,7 @@ static void vb_read_config(void)
     }
 
     /* read config from config files */
-    char **lines = util_get_lines(vb.files[FILES_CONFIG]);
-    char *line;
+    lines = util_get_lines(vb.files[FILES_CONFIG]);
 
     if (lines) {
         int length = g_strv_length(lines) - 1;
@@ -920,8 +915,9 @@ static gboolean vb_new_window_policy_cb(
 
 static void vb_hover_link_cb(WebKitWebView *webview, const char *title, const char *link)
 {
+    char *message;
     if (link) {
-        char *message = g_strdup_printf("Link: %s", link);
+        message = g_strdup_printf("Link: %s", link);
         gtk_label_set_text(GTK_LABEL(vb.gui.statusbar.left), message);
         g_free(message);
     } else {
@@ -1052,8 +1048,7 @@ static void vb_destroy_client()
 int main(int argc, char *argv[])
 {
     static char *winid = NULL;
-    static gboolean ver = false;
-    static gboolean dump = false;
+    static gboolean ver = false, dump = false;
     static GError *err;
     static GOptionEntry opts[] = {
         {"version", 'v', 0, G_OPTION_ARG_NONE, &ver, "Print version", NULL},
index a2d8aac..ddf25cc 100644 (file)
@@ -125,9 +125,8 @@ void setting_cleanup(void)
 
 gboolean setting_run(char *name, const char *param)
 {
-    Arg *a          = NULL;
-    gboolean result = FALSE;
-    gboolean get    = FALSE;
+    Arg *a = NULL;
+    gboolean result = FALSE, get = FALSE;
     SettingType type = SETTING_SET;
 
     /* determine the type to names last char and param */
@@ -548,8 +547,8 @@ static gboolean setting_strict_ssl(const Setting *s, const SettingType type)
 
 static gboolean setting_ca_bundle(const Setting *s, const SettingType type)
 {
+    char *value;
     if (type == SETTING_GET) {
-        char *value = NULL;
         g_object_get(vb.soup_session, "ssl-ca-file", &value, NULL);
         setting_print_value(s, value);
         g_free(value);
@@ -596,6 +595,7 @@ static gboolean setting_download_path(const Setting *s, const SettingType type)
 static gboolean setting_proxy(const Setting *s, const SettingType type)
 {
     gboolean enabled;
+    char *proxy, *proxy_new;
     SoupURI *proxy_uri = NULL;
 
     /* get the current status */
@@ -619,9 +619,9 @@ static gboolean setting_proxy(const Setting *s, const SettingType type)
     }
 
     if (enabled) {
-        char *proxy = (char *)g_getenv("http_proxy");
+        proxy = (char *)g_getenv("http_proxy");
         if (proxy != NULL && strlen(proxy)) {
-            char *proxy_new = g_strrstr(proxy, "http://")
+            proxy_new = g_strrstr(proxy, "http://")
                 ? g_strdup(proxy)
                 : g_strdup_printf("http://%s", proxy);
             proxy_uri = soup_uri_new(proxy_new);
index d984791..ca09c9a 100644 (file)
@@ -100,15 +100,15 @@ char **util_get_lines(const char *filename)
 
 char *util_strcasestr(const char *haystack, const char *needle)
 {
+    unsigned char c1, c2;
+    int i, j;
     int nlen = strlen(needle);
     int hlen = strlen(haystack) - nlen + 1;
-    int i;
 
     for (i = 0; i < hlen; i++) {
-        int j;
         for (j = 0; j < nlen; j++) {
-            unsigned char c1 = haystack[i + j];
-            unsigned char c2 = needle[j];
+            c1 = haystack[i + j];
+            c2 = needle[j];
             if (toupper(c1) != toupper(c2)) {
                 goto next;
             }