Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Sat, 25 Jun 2016 14:15:08 UTC Commit: 65988f51f0634d29d4454602f367f03f925fc6d2 https://github.com/geany/geany/commit/65988f51f0634d29d4454602f367f03f925fc6...
Log Message: ----------- style: Reduce scope of several variables
No behavioral changes.
Modified Paths: -------------- src/callbacks.c src/document.c src/editor.c src/encodings.c src/keyfile.c src/msgwindow.c src/prefs.c src/search.c src/sidebar.c src/socket.c src/symbols.c src/templates.c src/toolbar.c src/tools.c src/ui_utils.c src/vte.c
Modified: src/callbacks.c 10 lines changed, 4 insertions(+), 6 deletions(-) =================================================================== @@ -127,13 +127,14 @@ void on_save_as1_activate(GtkMenuItem *menuitem, gpointer user_data) void on_save_all1_activate(GtkMenuItem *menuitem, gpointer user_data) { guint i, max = (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); - GeanyDocument *doc, *cur_doc = document_get_current(); + GeanyDocument *cur_doc = document_get_current(); guint count = 0;
/* iterate over documents in tabs order */ for (i = 0; i < max; i++) { - doc = document_get_from_page(i); + GeanyDocument *doc = document_get_from_page(i); + if (! doc->changed) continue;
@@ -552,7 +553,6 @@ void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); ScintillaObject *sci; - gchar *text; gboolean keep_sel = TRUE;
g_return_if_fail(doc != NULL); @@ -570,8 +570,7 @@ void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data) gchar *result = NULL; gint cmd = SCI_LOWERCASE; gboolean rectsel = (gboolean) scintilla_send_message(sci, SCI_SELECTIONISRECTANGLE, 0, 0); - - text = sci_get_selection_contents(sci); + gchar *text = sci_get_selection_contents(sci);
if (utils_str_has_upper(text)) { @@ -599,7 +598,6 @@ void on_toggle_case1_activate(GtkMenuItem *menuitem, gpointer user_data) sci_send_command(sci, cmd);
g_free(text); - } }
Modified: src/document.c 26 lines changed, 12 insertions(+), 14 deletions(-) =================================================================== @@ -1518,7 +1518,6 @@ GeanyDocument *document_open_file_full(GeanyDocument *doc, const gchar *filename void document_open_file_list(const gchar *data, gsize length) { guint i; - gchar *filename; gchar **list;
g_return_if_fail(data != NULL); @@ -1528,7 +1527,8 @@ void document_open_file_list(const gchar *data, gsize length) /* stop at the end or first empty item, because last item is empty but not null */ for (i = 0; list[i] != NULL && list[i][0] != '\0'; i++) { - filename = utils_get_path_from_uri(list[i]); + gchar *filename = utils_get_path_from_uri(list[i]); + if (filename == NULL) continue; document_open_file(filename, FALSE, NULL, NULL); @@ -2695,7 +2695,6 @@ void document_update_tags(GeanyDocument *doc) void document_highlight_tags(GeanyDocument *doc) { GString *keywords_str; - gchar *keywords; gint keyword_idx;
/* some filetypes support type keywords (such as struct names), but not @@ -2732,10 +2731,9 @@ void document_highlight_tags(GeanyDocument *doc) keywords_str = symbols_find_typenames_as_string(doc->file_type->lang, FALSE); if (keywords_str) { - guint hash; + gchar *keywords = g_string_free(keywords_str, FALSE); + guint hash = g_str_hash(keywords);
- keywords = g_string_free(keywords_str, FALSE); - hash = g_str_hash(keywords); if (hash != doc->priv->keyword_hash) { sci_set_keywords(doc->editor->sci, keyword_idx, keywords); @@ -2893,11 +2891,10 @@ void document_set_encoding(GeanyDocument *doc, const gchar *new_encoding) /* Clears an Undo or Redo buffer. */ void document_undo_clear_stack(GTrashStack **stack) { - undo_action *a; - while (g_trash_stack_height(stack) > 0) { - a = g_trash_stack_pop(stack); + undo_action *a = g_trash_stack_pop(stack); + if (G_LIKELY(a != NULL)) { switch (a->type) @@ -3459,7 +3456,7 @@ static GtkWidget* document_show_message(GeanyDocument *doc, GtkMessageType msgty { va_list args; gchar *text, *markup; - GtkWidget *hbox, *vbox, *icon, *label, *extra_label, *content_area; + GtkWidget *hbox, *icon, *label, *content_area; GtkWidget *info_widget, *parent; parent = document_get_notebook_child(doc);
@@ -3518,8 +3515,9 @@ static GtkWidget* document_show_message(GeanyDocument *doc, GtkMessageType msgty
if (extra_text) { - vbox = gtk_vbox_new(FALSE, 6); - extra_label = geany_wrap_label_new(extra_text); + GtkWidget *vbox = gtk_vbox_new(FALSE, 6); + GtkWidget *extra_label = geany_wrap_label_new(extra_text); + gtk_box_pack_start(GTK_BOX(vbox), label, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(vbox), extra_label, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), vbox, TRUE, TRUE, 0); @@ -3689,7 +3687,6 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force) { gboolean ret = FALSE; gboolean use_gio_filemon; - time_t cur_time = 0; time_t mtime; gchar *locale_filename; FileDiskStatus old_status; @@ -3710,7 +3707,8 @@ gboolean document_check_disk_status(GeanyDocument *doc, gboolean force) } else { - cur_time = time(NULL); + time_t cur_time = time(NULL); + if (! force && doc->priv->last_check > (cur_time - file_prefs.disk_check_timeout)) return FALSE;
Modified: src/editor.c 17 lines changed, 9 insertions(+), 8 deletions(-) =================================================================== @@ -195,15 +195,15 @@ static void on_snippet_keybinding_activate(gchar *key) { GeanyDocument *doc = document_get_current(); const gchar *s; - GHashTable *specials;
if (!doc || !gtk_widget_has_focus(GTK_WIDGET(doc->editor->sci))) return;
s = snippets_find_completion_by_name(doc->file_type->name, key); if (!s) /* allow user to specify keybindings for "special" snippets */ { - specials = g_hash_table_lookup(snippet_hash, "Special"); + GHashTable *specials = g_hash_table_lookup(snippet_hash, "Special"); + if (G_LIKELY(specials != NULL)) s = g_hash_table_lookup(specials, key); } @@ -1616,7 +1616,7 @@ static void close_block(GeanyEditor *editor, gint pos) const GeanyIndentPrefs *iprefs = editor_get_indent_prefs(editor); gint x = 0, cnt = 0; gint line, line_len; - gchar *text, *line_buf; + gchar *line_buf; ScintillaObject *sci; gint line_indent, last_indent;
@@ -1656,8 +1656,8 @@ static void close_block(GeanyEditor *editor, gint pos) gint brace_line = sci_get_line_from_position(sci, start_brace); gint size = sci_get_line_indentation(sci, brace_line); gchar *ind = get_whitespace(iprefs, size); + gchar *text = g_strconcat(ind, "}", NULL);
- text = g_strconcat(ind, "}", NULL); line_start = sci_get_position_from_line(sci, line); sci_set_anchor(sci, line_start); sci_replace_sel(sci, text); @@ -4382,16 +4382,12 @@ void editor_fold_all(GeanyEditor *editor)
void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection) { - gint search_pos, pos_in_line, current_tab_true_length; gint anchor_pos, caret_pos; - gint tab_len; - gchar *tab_str; struct Sci_TextToFind ttf;
g_return_if_fail(editor != NULL);
sci_start_undo_action(editor->sci); - tab_len = sci_get_tab_width(editor->sci); if (sci_has_selection(editor->sci) && !ignore_selection) { ttf.chrg.cpMin = sci_get_selection_start(editor->sci); @@ -4408,10 +4404,15 @@ void editor_replace_tabs(GeanyEditor *editor, gboolean ignore_selection) caret_pos = sci_get_current_position(editor->sci); while (TRUE) { + gint search_pos, pos_in_line, current_tab_true_length; + gint tab_len; + gchar *tab_str; + search_pos = sci_find_text(editor->sci, SCFIND_MATCHCASE, &ttf); if (search_pos == -1) break;
+ tab_len = sci_get_tab_width(editor->sci); pos_in_line = sci_get_col_from_position(editor->sci, search_pos); current_tab_true_length = tab_len - (pos_in_line % tab_len); tab_str = g_strnfill(current_tab_true_length, ' ');
Modified: src/encodings.c 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -521,7 +521,6 @@ GtkTreeStore *encodings_encoding_store_new(gboolean has_detect) GtkTreeIter iter_current, iter_westeuro, iter_easteuro, iter_eastasian, iter_asian, iter_utf8, iter_middleeast; GtkTreeIter *iter_parent; - gchar *encoding_string; gint i;
store = gtk_tree_store_new(2, G_TYPE_INT, G_TYPE_STRING); @@ -547,6 +546,8 @@ GtkTreeStore *encodings_encoding_store_new(gboolean has_detect)
for (i = 0; i < GEANY_ENCODINGS_MAX; i++) { + gchar *encoding_string; + switch (encodings[i].group) { case WESTEUROPEAN: iter_parent = &iter_westeuro; break;
Modified: src/keyfile.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -370,7 +370,6 @@ void configuration_save_session_files(GKeyFile *config) gint npage; gchar entry[16]; guint i = 0, j = 0, max; - GeanyDocument *doc;
npage = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook)); g_key_file_set_integer(config, "files", "current_page", npage); @@ -382,7 +381,8 @@ void configuration_save_session_files(GKeyFile *config) max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); for (i = 0; i < max; i++) { - doc = document_get_from_page(i); + GeanyDocument *doc = document_get_from_page(i); + if (doc != NULL && doc->real_path != NULL) { gchar *fname;
Modified: src/msgwindow.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -304,7 +304,6 @@ void msgwin_compiler_add(gint msg_color, const gchar *format, ...) void msgwin_compiler_add_string(gint msg_color, const gchar *msg) { GtkTreeIter iter; - GtkTreePath *path; const GdkColor *color = get_color(msg_color); gchar *utf8_msg;
@@ -319,8 +318,9 @@ void msgwin_compiler_add_string(gint msg_color, const gchar *msg)
if (ui_prefs.msgwindow_visible && interface_prefs.compiler_tab_autoscroll) { - path = gtk_tree_model_get_path( + GtkTreePath *path = gtk_tree_model_get_path( gtk_tree_view_get_model(GTK_TREE_VIEW(msgwindow.tree_compiler)), &iter); + gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(msgwindow.tree_compiler), path, NULL, TRUE, 0.5, 0.5); gtk_tree_path_free(path); }
Modified: src/prefs.c 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -214,13 +214,14 @@ static void kb_tree_view_change_button_clicked_cb(GtkWidget *button, KbData *kbd
static void kb_show_popup_menu(KbData *kbdata, GtkWidget *widget, GdkEventButton *event) { - GtkWidget *item; static GtkWidget *menu = NULL; guint button; guint32 event_time;
if (menu == NULL) { + GtkWidget *item; + menu = gtk_menu_new();
item = ui_image_menu_item_new(GTK_STOCK_ADD, _("_Expand All"));
Modified: src/search.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -302,7 +302,7 @@ static void on_widget_toggled_set_insensitive(
static GtkWidget *add_find_checkboxes(GtkDialog *dialog) { - GtkWidget *checkbox1, *checkbox2, *check_regexp, *check_back, *checkbox5, + GtkWidget *checkbox1, *checkbox2, *check_regexp, *checkbox5, *checkbox7, *check_multiline, *hbox, *fbox, *mbox;
check_regexp = gtk_check_button_new_with_mnemonic(_("_Use regular expressions")); @@ -338,7 +338,7 @@ static GtkWidget *add_find_checkboxes(GtkDialog *dialog)
if (dialog != GTK_DIALOG(find_dlg.dialog)) { - check_back = gtk_check_button_new_with_mnemonic(_("Search _backwards")); + GtkWidget *check_back = gtk_check_button_new_with_mnemonic(_("Search _backwards")); ui_hookup_widget(dialog, check_back, "check_back"); gtk_button_set_focus_on_click(GTK_BUTTON(check_back), FALSE); gtk_container_add(GTK_CONTAINER(fbox), check_back);
Modified: src/sidebar.c 3 lines changed, 1 insertions(+), 2 deletions(-) =================================================================== @@ -768,11 +768,10 @@ static void create_openfiles_popup_menu(void) static void unfold_parent(GtkTreeIter *iter) { GtkTreeIter parent; - GtkTreePath *path;
if (gtk_tree_model_iter_parent(GTK_TREE_MODEL(store_openfiles), &parent, iter)) { - path = gtk_tree_model_get_path(GTK_TREE_MODEL(store_openfiles), &parent); + GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(store_openfiles), &parent); gtk_tree_view_expand_row(GTK_TREE_VIEW(tv.tree_openfiles), path, TRUE); gtk_tree_path_free(path); }
Modified: src/socket.c 3 lines changed, 1 insertions(+), 2 deletions(-) =================================================================== @@ -128,7 +128,6 @@ static gint socket_fd_close (gint sock); static void send_open_command(gint sock, gint argc, gchar **argv) { gint i; - gchar *filename;
g_return_if_fail(argc > 1); geany_debug("using running instance of Geany"); @@ -158,7 +157,7 @@ static void send_open_command(gint sock, gint argc, gchar **argv)
for (i = 1; i < argc && argv[i] != NULL; i++) { - filename = main_get_argv_filename(argv[i]); + gchar *filename = main_get_argv_filename(argv[i]);
/* if the filename is valid or if a new file should be opened is check on the other side */ if (filename != NULL)
Modified: src/symbols.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -301,7 +301,6 @@ static gint compare_symbol_lines(gconstpointer a, gconstpointer b) static GList *get_tag_list(GeanyDocument *doc, TMTagType tag_types) { GList *tag_names = NULL; - TMTag *tag; guint i;
g_return_val_if_fail(doc, NULL); @@ -311,7 +310,8 @@ static GList *get_tag_list(GeanyDocument *doc, TMTagType tag_types)
for (i = 0; i < doc->tm_file->tags_array->len; ++i) { - tag = TM_TAG(doc->tm_file->tags_array->pdata[i]); + TMTag *tag = TM_TAG(doc->tm_file->tags_array->pdata[i]); + if (G_UNLIKELY(tag == NULL)) return NULL;
Modified: src/templates.c 14 lines changed, 6 insertions(+), 8 deletions(-) =================================================================== @@ -175,15 +175,13 @@ static gchar *get_template_from_file(const gchar *locale_fname, const gchar *doc GeanyFiletype *ft) { gchar *content; - GString *template = NULL;
content = read_file(locale_fname);
if (content != NULL) { gchar *file_header; - - template = g_string_new(content); + GString *template = g_string_new(content);
file_header = get_template_fileheader(ft); templates_replace_valist(template, @@ -630,16 +628,16 @@ static gchar *run_command(const gchar *command, const gchar *file_name, static void templates_replace_command(GString *text, const gchar *file_name, const gchar *file_type, const gchar *func_name) { - gchar *match = NULL; - gchar *wildcard = NULL; - gchar *cmd; - gchar *result; + gchar *match;
g_return_if_fail(text != NULL);
while ((match = strstr(text->str, "{command:")) != NULL) { - cmd = match; + gchar *wildcard; + gchar *cmd = match; + gchar *result; + while (*match != '}' && *match != '\0') match++;
Modified: src/toolbar.c 12 lines changed, 8 insertions(+), 4 deletions(-) =================================================================== @@ -418,7 +418,6 @@ void toolbar_update_ui(void) { static GtkWidget *hbox_menubar = NULL; static GtkWidget *menubar = NULL; - GtkWidget *menubar_toolbar_separator = NULL; GtkWidget *parent; GtkToolItem *first_item;
@@ -438,6 +437,8 @@ void toolbar_update_ui(void)
if (toolbar_prefs.append_to_menu) { + GtkWidget *menubar_toolbar_separator; + if (parent != NULL) { if (parent != hbox_menubar) @@ -1064,10 +1065,8 @@ static TBEditorWidget *tb_editor_create_dialog(GtkWindow *parent) void toolbar_configure(GtkWindow *parent) { gchar *markup; - const gchar *name; GSList *sl, *used_items; GList *l, *all_items; - GtkTreeIter iter; GtkTreePath *path; TBEditorWidget *tbw;
@@ -1089,15 +1088,20 @@ void toolbar_configure(GtkWindow *parent) -1); foreach_list(l, all_items) { - name = gtk_action_get_name(l->data); + const gchar *name = gtk_action_get_name(l->data); + if (g_slist_find_custom(used_items, name, (GCompareFunc) strcmp) == NULL) { + GtkTreeIter iter; + gtk_list_store_append(tbw->store_available, &iter); tb_editor_set_item_values(name, tbw->store_available, &iter); } } foreach_slist(sl, used_items) { + GtkTreeIter iter; + gtk_list_store_append(tbw->store_used, &iter); tb_editor_set_item_values(sl->data, tbw->store_used, &iter); }
Modified: src/tools.c 4 lines changed, 2 insertions(+), 2 deletions(-) =================================================================== @@ -547,7 +547,6 @@ static void cc_insert_custom_command_items(GtkMenu *me, const gchar *label, cons { GtkWidget *item; gint key_idx = -1; - GeanyKeyBinding *kb = NULL;
switch (idx) { @@ -566,7 +565,8 @@ static void cc_insert_custom_command_items(GtkMenu *me, const gchar *label, cons gtk_widget_set_tooltip_text(item, tooltip); if (key_idx != -1) { - kb = keybindings_lookup_item(GEANY_KEY_GROUP_FORMAT, key_idx); + GeanyKeyBinding *kb = keybindings_lookup_item(GEANY_KEY_GROUP_FORMAT, key_idx); + if (kb->key > 0) { gtk_widget_add_accelerator(item, "activate", gtk_accel_group_new(),
Modified: src/ui_utils.c 14 lines changed, 6 insertions(+), 8 deletions(-) =================================================================== @@ -608,8 +608,6 @@ static void on_menu_insert_include_activate(GtkMenuItem *menuitem, gpointer user static void insert_include_items(GtkMenu *me, GtkMenu *mp, gchar **includes, gchar *label) { guint i = 0; - GtkWidget *tmp_menu; - GtkWidget *tmp_popup; GtkWidget *edit_menu, *edit_menu_item; GtkWidget *popup_menu, *popup_menu_item;
@@ -622,8 +620,9 @@ static void insert_include_items(GtkMenu *me, GtkMenu *mp, gchar **includes, gch
while (includes[i] != NULL) { - tmp_menu = gtk_menu_item_new_with_label(includes[i]); - tmp_popup = gtk_menu_item_new_with_label(includes[i]); + GtkWidget *tmp_menu = gtk_menu_item_new_with_label(includes[i]); + GtkWidget *tmp_popup = gtk_menu_item_new_with_label(includes[i]); + gtk_container_add(GTK_CONTAINER(edit_menu), tmp_menu); gtk_container_add(GTK_CONTAINER(popup_menu), tmp_popup); g_signal_connect(tmp_menu, "activate", @@ -1106,16 +1105,15 @@ void ui_set_search_entry_background(GtkWidget *widget, gboolean success)
static void recent_create_menu(GeanyRecentFiles *grf) { - GtkWidget *tmp; guint i, len; - gchar *filename;
len = MIN(file_prefs.mru_length, g_queue_get_length(grf->recent_queue)); for (i = 0; i < len; i++) { - filename = g_queue_peek_nth(grf->recent_queue, i); /* create menu item for the recent files menu in the menu bar */ - tmp = gtk_menu_item_new_with_label(filename); + const gchar *filename = g_queue_peek_nth(grf->recent_queue, i); + GtkWidget *tmp = gtk_menu_item_new_with_label(filename); + gtk_widget_show(tmp); gtk_container_add(GTK_CONTAINER(grf->menubar), tmp); g_signal_connect(tmp, "activate", G_CALLBACK(grf->activate_cb), NULL);
Modified: src/vte.c 21 lines changed, 8 insertions(+), 13 deletions(-) =================================================================== @@ -417,15 +417,13 @@ static void vte_commit_cb(VteTerminal *vte, gchar *arg1, guint arg2, gpointer us
static void vte_start(GtkWidget *widget) { - gchar **env; - gchar **argv; - /* split the shell command line, so arguments will work too */ - argv = g_strsplit(vc->shell, " ", -1); + gchar **argv = g_strsplit(vc->shell, " ", -1);
if (argv != NULL) { - env = vte_get_child_environment(); + gchar **env = vte_get_child_environment(); + pid = vf->vte_terminal_fork_command(VTE_TERMINAL(widget), argv[0], argv, env, vte_info.dir, TRUE, TRUE, TRUE); g_strfreev(env); @@ -693,15 +691,11 @@ gboolean vte_send_cmd(const gchar *cmd) * directory in vte_info.dir. Note: vte_info.dir contains the real path. */ const gchar *vte_get_working_directory(void) { - gchar buffer[4096 + 1]; - gchar *file; - gchar *cwd; - gint length; - if (pid > 0) { - file = g_strdup_printf("/proc/%d/cwd", pid); - length = readlink(file, buffer, sizeof(buffer)); + gchar buffer[4096 + 1]; + gchar *file = g_strdup_printf("/proc/%d/cwd", pid); + gint length = readlink(file, buffer, sizeof(buffer));
if (length > 0 && *buffer == '/') { @@ -711,7 +705,8 @@ const gchar *vte_get_working_directory(void) } else if (length == 0) { - cwd = g_get_current_dir(); + gchar *cwd = g_get_current_dir(); + if (cwd != NULL) { if (chdir(file) == 0)
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).