gchar *get_file_relative_path(const gchar *origin_dir, const gchar *dest_file) { gchar *dest_dir, *ret; dest_dir = g_path_get_dirname(dest_file); ret = relpath(origin_dir, dest_dir); if (ret) { gchar *dest_basename; dest_basename = g_path_get_basename(dest_file); if (g_strcmp0(ret, "./") != 0) { SETPTR(ret, g_build_filename(ret, dest_basename, NULL)); } else { SETPTR(ret, g_strdup(dest_basename)); } g_free(dest_basename); } g_free(dest_dir); return ret; }
static void deletefree(void *currblock) { int listcounter = 0; size_t size = GETSIZE(HEADER(currblock)); for (;(listcounter < LISTS - 1) && (size > 1); listcounter++) { size >>= 1; } if (PREVFREE(currblock) != NULL) { if (NEXTFREE(currblock) != NULL) { SETPTR(NEXTPTR(PREVFREE(currblock)), NEXTFREE(currblock)); SETPTR(PREVPTR(NEXTFREE(currblock)), PREVFREE(currblock)); } else { SETPTR(NEXTPTR(PREVFREE(currblock)), NULL); free_lists[listcounter] = PREVFREE(currblock); } } else { if (NEXTFREE(currblock) != NULL) { SETPTR(PREVPTR(NEXTFREE(currblock)), NULL); } else { free_lists[listcounter] = NULL; } } return; }
/* store text, clear search flags so we can use Search->Find Next/Previous */ static void setup_find(const gchar *text, gboolean backwards) { SETPTR(search_data.text, g_strdup(text)); SETPTR(search_data.original_text, g_strdup(text)); search_data.flags = 0; search_data.backwards = backwards; search_data.search_bar = TRUE; }
static gboolean goto_compiler_file_line(const gchar *filename, gint line, gboolean focus_editor) { if (!filename || line <= -1) return FALSE; /* If the path doesn't exist, try the current document. * This happens when we receive build messages in the wrong order - after the * 'Leaving directory' messages */ if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { gchar *cur_dir = utils_get_current_file_dir_utf8(); gchar *name; if (cur_dir) { /* we let the user know we couldn't find the parsed filename from the message window */ SETPTR(cur_dir, utils_get_locale_from_utf8(cur_dir)); name = g_path_get_basename(filename); SETPTR(name, g_build_path(G_DIR_SEPARATOR_S, cur_dir, name, NULL)); g_free(cur_dir); if (g_file_test(name, G_FILE_TEST_EXISTS)) { ui_set_statusbar(FALSE, _("Could not find file '%s' - trying the current document path."), filename); filename = name; } else g_free(name); } } { gchar *utf8_filename = utils_get_utf8_from_locale(filename); GeanyDocument *doc = document_find_by_filename(utf8_filename); GeanyDocument *old_doc = document_get_current(); g_free(utf8_filename); if (doc == NULL) /* file not already open */ doc = document_open_file(filename, FALSE, NULL, NULL); if (doc != NULL) { gboolean ret; if (! doc->changed && editor_prefs.use_indicators) /* if modified, line may be wrong */ editor_indicator_set_on_line(doc->editor, GEANY_INDICATOR_ERROR, line - 1); ret = navqueue_goto_line(old_doc, doc, line); if (ret && focus_editor) gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci)); return ret; } } return FALSE; }
static void remove_foreach_project_filetype(gpointer data, gpointer user_data) { GeanyFiletype *ft = data; if (ft != NULL) { SETPTR(ft->projfilecmds, NULL); SETPTR(ft->projexeccmds, NULL); SETPTR(ft->projerror_regex_string, NULL); ft->project_list_entry = -1; } }
static void instantsave_document_new_cb(GObject *obj, GeanyDocument *doc, gpointer user_data) { if (enable_instantsave && doc->file_name == NULL) { gchar *new_filename; gint fd; GeanyFiletype *ft = doc->file_type; fd = g_file_open_tmp("gis_XXXXXX", &new_filename, NULL); if (fd != -1) close(fd); /* close the returned file descriptor as we only need the filename */ if (ft == NULL || ft->id == GEANY_FILETYPES_NONE) /* ft is NULL when a new file without template was opened, so use the * configured default file type */ ft = filetypes_lookup_by_name(instantsave_default_ft); if (ft != NULL) /* add the filetype's default extension to the new filename */ SETPTR(new_filename, g_strconcat(new_filename, ".", ft->extension, NULL)); doc->file_name = new_filename; if (doc->file_type->id == GEANY_FILETYPES_NONE) document_set_filetype(doc, filetypes_lookup_by_name(instantsave_default_ft)); /* force saving the file to enable all the related actions(tab name, filetype, etc.) */ document_save_file(doc, TRUE); } }
static void find_file(GtkTreeIter *iter) { gchar *pattern_str = NULL; gboolean case_sensitive, full_path; gchar *path; path = build_path(iter); if (show_dialog_find_file(iter ? path : NULL, &pattern_str, &case_sensitive, &full_path) == GTK_RESPONSE_ACCEPT) { GPatternSpec *pattern; if (!case_sensitive) SETPTR(pattern_str, g_utf8_strdown(pattern_str, -1)); pattern = g_pattern_spec_new(pattern_str); msgwin_clear_tab(MSG_MESSAGE); msgwin_set_messages_dir(get_project_base_path()); find_file_recursive(iter, case_sensitive, full_path, pattern); msgwin_switch_tab(MSG_MESSAGE, TRUE); } g_free(pattern_str); g_free(path); }
/* Update project-related preferences after using the Preferences dialog. */ void project_apply_prefs(void) { GtkWidget *path_entry = ui_lookup_widget(ui_widgets.prefs_dialog, "project_file_path_entry"); const gchar *str; str = gtk_entry_get_text(GTK_ENTRY(path_entry)); SETPTR(local_prefs.project_file_path, g_strdup(str)); }
static gchar *generate_find_string(GeanyProject *prj) { gchar *ret; ret = g_strdup("find -L . -not -path '*/\\.*'"); if (!EMPTY(prj->file_patterns)) { guint i; SETPTR(ret, g_strconcat(ret, " \\( -name \"", prj->file_patterns[0], "\"", NULL)); for (i = 1; prj->file_patterns[i]; i++) SETPTR(ret, g_strconcat(ret, " -o -name \"", prj->file_patterns[i], "\"", NULL)); SETPTR(ret, g_strconcat(ret, " \\)", NULL)); } return ret; }
static void tmpStr(naRef* out, struct naStr* str, const char* key) { str->type = T_STR; str->hashcode = str->emblen = 0; str->data.ref.ptr = (unsigned char*)key; str->data.ref.len = strlen(key); SETPTR(*out, str); }
static void on_term_font_set(GtkFontButton *widget, gpointer user_data) { const gchar *fontbtn = gtk_font_button_get_font_name(widget); if (! utils_str_equal(fontbtn, vc->font)) { SETPTR(vc->font, g_strdup(gtk_font_button_get_font_name(widget))); vte_apply_user_settings(); } }
static gchar *relpath(const gchar *origin_dir, const gchar *dest_dir) { gchar *origin, *dest; gchar **originv, **destv; gchar *ret = NULL; guint i, j; origin = tm_get_real_path(origin_dir); dest = tm_get_real_path(dest_dir); if (EMPTY(origin) || EMPTY(dest) || origin[0] != dest[0]) { g_free(origin); g_free(dest); return NULL; } originv = g_strsplit_set(g_path_skip_root(origin), "/\\", -1); destv = g_strsplit_set(g_path_skip_root(dest), "/\\", -1); for (i = 0; originv[i] != NULL && destv[i] != NULL; i++) if (g_strcmp0(originv[i], destv[i]) != 0) break; ret = g_strdup(""); for (j = i; originv[j] != NULL; j++) SETPTR(ret, g_build_filename(ret, "..", NULL)); for (j = i; destv[j] != NULL; j++) SETPTR(ret, g_build_filename(ret, destv[j], NULL)); if (strlen(ret) == 0) SETPTR(ret, g_strdup("./")); g_free(origin); g_free(dest); g_strfreev(originv); g_strfreev(destv); return ret; }
static void find_file_recursive(GtkTreeIter *iter, gboolean case_sensitive, gboolean full_path, GPatternSpec *pattern) { GtkTreeModel *model = GTK_TREE_MODEL(s_file_store); GtkTreeIter child; gboolean iterate; iterate = gtk_tree_model_iter_children(model, &child, iter); if (iterate) { while (iterate) { find_file_recursive(&child, case_sensitive, full_path, pattern); iterate = gtk_tree_model_iter_next(model, &child); } } else { gchar *utf8_name; if (iter == NULL) return; if (full_path) { gchar *utf8_path, *utf8_base_path; utf8_path = build_path(iter); utf8_base_path = get_project_base_path(); utf8_name = get_relative_path(utf8_base_path, utf8_path); g_free(utf8_path); g_free(utf8_base_path); } else gtk_tree_model_get(GTK_TREE_MODEL(model), iter, FILEVIEW_COLUMN_NAME, &utf8_name, -1); if (!case_sensitive) SETPTR(utf8_name, g_utf8_strdown(utf8_name, -1)); if (g_pattern_match_string(pattern, utf8_name)) { gchar *utf8_base_path = get_project_base_path(); gchar *utf8_path, *rel_path; utf8_path = build_path(iter); rel_path = get_relative_path(utf8_base_path, utf8_path); msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s", rel_path ? rel_path : utf8_path); g_free(utf8_path); g_free(rel_path); g_free(utf8_base_path); } g_free(utf8_name); } }
static gchar *get_tags_filename(void) { gchar *ret = NULL; if (geany_data->app->project) { ret = utils_remove_ext_from_filename(geany_data->app->project->file_name); SETPTR(ret, g_strconcat(ret, ".tags", NULL)); } return ret; }
/* utf8 */ static gchar *build_path(GtkTreeIter *iter) { GtkTreeIter node; GtkTreeIter parent; gchar *path = NULL; GtkTreeModel *model; gchar *name; if (!iter) return get_project_base_path(); node = *iter; model = GTK_TREE_MODEL(s_file_store); while (gtk_tree_model_iter_parent(model, &parent, &node)) { gtk_tree_model_get(model, &node, FILEVIEW_COLUMN_NAME, &name, -1); if (path == NULL) path = g_strdup(name); else SETPTR(path, g_build_filename(name, path, NULL)); g_free(name); node = parent; } if (topmost_selected(model, &node, TRUE)) { gchar *utf8_base_path = get_project_base_path(); SETPTR(path, g_build_filename(utf8_base_path, path, NULL)); g_free(utf8_base_path); } else { gtk_tree_model_get(model, &node, FILEVIEW_COLUMN_NAME, &name, -1); SETPTR(path, g_build_filename(name, path, NULL)); g_free(name); } return path; }
static void setup_config_file_menus(void) { gchar *f; f = g_build_filename(app->configdir, "filetype_extensions.conf", NULL); ui_add_config_file_menu_item(f, NULL, NULL); SETPTR(f, g_build_filename(app->configdir, GEANY_FILEDEFS_SUBDIR, "filetypes.common", NULL)); ui_add_config_file_menu_item(f, NULL, NULL); g_free(f); g_signal_connect(geany_object, "document-save", G_CALLBACK(on_document_save), NULL); }
/* name argument (ie filetype name) must not be translated as it is used for * filetype lookup. Use filetypes_get_display_name() instead.*/ static void ft_init(filetype_id ft_id, int lang, const char *name, const char *title_name, enum TitleType title_type, const char *mime_type, GeanyFiletypeGroupID group_id) { GeanyFiletype *ft = filetypes[ft_id]; ft->lang = lang; ft->name = g_strdup(name); ft->title = filetype_make_title((title_name != NULL) ? title_name : ft->name, title_type); if (mime_type != NULL) SETPTR(ft->mime_type, g_strdup(mime_type)); ft->group = group_id; }
static void read_template(const gchar *name, gint id) { gchar *fname = g_build_path(G_DIR_SEPARATOR_S, app->configdir, GEANY_TEMPLATES_SUBDIR, name, NULL); /* try system if user template doesn't exist */ if (!g_file_test(fname, G_FILE_TEST_EXISTS)) SETPTR(fname, g_build_path(G_DIR_SEPARATOR_S, app->datadir, GEANY_TEMPLATES_SUBDIR, name, NULL)); templates[id] = read_file(fname); g_free(fname); }
static void show_entry(tagEntry *entry) { const gchar *kind; const gchar *signature; const gchar *scope; const gchar *file; const gchar *name; gchar *scope_str; gchar *kind_str; file = entry->file; if (!file) file = ""; name = entry->name; if (!name) name = ""; signature = tagsField(entry, "signature"); if (!signature) signature = ""; scope = tagsField(entry, "class"); if (!scope) scope = tagsField(entry, "struct"); if (!scope) scope = tagsField(entry, "union"); if (!scope) scope = tagsField(entry, "enum"); if (scope) scope_str = g_strconcat(scope, "::", NULL); else scope_str = g_strdup(""); kind = entry->kind; if (kind) { kind_str = g_strconcat(kind, ": ", NULL); SETPTR(kind_str, g_strdup_printf("%-14s", kind_str)); } else kind_str = g_strdup(""); msgwin_msg_add(COLOR_BLACK, -1, NULL, "%s:%lu:\n %s%s%s%s", file, entry->address.lineNumber, kind_str, scope_str, name, signature); g_free(scope_str); g_free(kind_str); }
void vte_send_selection_to_vte(void) { GeanyDocument *doc; gchar *text; gsize len; doc = document_get_current(); g_return_if_fail(doc != NULL); if (sci_has_selection(doc->editor->sci)) { text = g_malloc0(sci_get_selected_text_length(doc->editor->sci) + 1); sci_get_selected_text(doc->editor->sci, text); } else { /* Get the current line */ gint line_num = sci_get_current_line(doc->editor->sci); text = sci_get_line(doc->editor->sci, line_num); } len = strlen(text); if (vc->send_selection_unsafe) { /* Explicitly append a trailing newline character to get the command executed, this is disabled by default as it could cause all sorts of damage. */ if (text[len-1] != '\n' && text[len-1] != '\r') { SETPTR(text, g_strconcat(text, "\n", NULL)); len++; } } else { /* Make sure there is no newline character at the end to prevent unwanted execution */ while (text[len-1] == '\n' || text[len-1] == '\r') { text[len-1] = '\0'; len--; } } vf->vte_terminal_feed_child(VTE_TERMINAL(vc->vte), text, len); /* show the VTE */ gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_VTE); gtk_widget_grab_focus(vc->vte); msgwin_show_hide(TRUE); g_free(text); }
static void make_absolute(gchar **filename, const gchar *dir) { guint skip_dot_slash = 0; /* number of characters to skip at the beginning of the filename */ if (*filename == NULL) return; /* skip some characters at the beginning of the filename, at the moment only "./" * can be extended if other "trash" is known */ if (strncmp(*filename, "./", 2) == 0) skip_dot_slash = 2; /* add directory */ if (! utils_is_absolute_path(*filename)) SETPTR(*filename, g_build_filename(dir, *filename + skip_dot_slash, NULL)); }
static void on_configure_response(GtkDialog * dialog, gint response, gpointer * user_data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) { if(g_strcmp0(gtk_entry_get_text(GTK_ENTRY(widgets.author_entry)), "") == 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("The author name field is empty!")); } else { website_selected = gtk_combo_box_get_active(GTK_COMBO_BOX(widgets.combo)); check_button_is_checked = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets.check_button)); SETPTR(author_name, g_strdup(gtk_entry_get_text(GTK_ENTRY(widgets.author_entry)))); save_settings(); } } }
/* Tries to parse strings of the file:line style, allowing line field to be missing * * filename is filled with the filename, should be freed * * line is filled with the line number or -1 */ static void msgwin_parse_generic_line(const gchar *string, gchar **filename, gint *line) { gchar **fields; gboolean incertain = TRUE; /* whether we're reasonably certain of the result */ *filename = NULL; *line = -1; fields = g_strsplit(string, ":", 2); /* extract the filename */ if (fields[0] != NULL) { *filename = utils_get_locale_from_utf8(fields[0]); if (msgwindow.messages_dir != NULL) make_absolute(filename, msgwindow.messages_dir); /* now the line */ if (fields[1] != NULL) { gchar *end; *line = strtol(fields[1], &end, 10); if (end == fields[1]) *line = -1; else if (*end == ':' || g_ascii_isspace(*end)) { /* if we have a blank or a separator right after the number, assume we really got a * filename (it's a grep-like syntax) */ incertain = FALSE; } } /* if we aren't sure we got a supposedly correct filename, check it */ if (incertain && ! g_file_test(*filename, G_FILE_TEST_EXISTS)) { SETPTR(*filename, NULL); *line = -1; } } g_strfreev(fields); }
/* Ensures utf8_dir exists and is writable and * set backup_dir to the locale encoded form of utf8_dir */ static gboolean backupcopy_set_backup_dir(const gchar *utf8_dir) { gchar *tmp; if (G_UNLIKELY(EMPTY(utf8_dir))) return FALSE; tmp = utils_get_locale_from_utf8(utf8_dir); if (! g_path_is_absolute(tmp) || ! g_file_test(tmp, G_FILE_TEST_EXISTS) || ! g_file_test(tmp, G_FILE_TEST_IS_DIR)) { g_free(tmp); return FALSE; } /** TODO add utils_is_file_writeable() to the plugin API and make use of it **/ SETPTR(backupcopy_backup_dir, tmp); return TRUE; }
/* Verifies data for New & Properties dialogs. * Returns: FALSE if the user needs to change any data. */ static gboolean update_config(const PropertyDialogElements *e, gboolean new_project) { const gchar *name, *file_name, *base_path; gchar *locale_filename; gsize name_len; gint err_code = 0; GeanyProject *p; g_return_val_if_fail(e != NULL, TRUE); name = gtk_entry_get_text(GTK_ENTRY(e->name)); name_len = strlen(name); if (name_len == 0) { SHOW_ERR(_("The specified project name is too short.")); gtk_widget_grab_focus(e->name); return FALSE; } else if (name_len > MAX_NAME_LEN) { SHOW_ERR1(_("The specified project name is too long (max. %d characters)."), MAX_NAME_LEN); gtk_widget_grab_focus(e->name); return FALSE; } if (new_project) file_name = gtk_entry_get_text(GTK_ENTRY(e->file_name)); else file_name = gtk_label_get_text(GTK_LABEL(e->file_name)); if (G_UNLIKELY(! NZV(file_name))) { SHOW_ERR(_("You have specified an invalid project filename.")); gtk_widget_grab_focus(e->file_name); return FALSE; } locale_filename = utils_get_locale_from_utf8(file_name); base_path = gtk_entry_get_text(GTK_ENTRY(e->base_path)); if (NZV(base_path)) { /* check whether the given directory actually exists */ gchar *locale_path = utils_get_locale_from_utf8(base_path); if (! g_path_is_absolute(locale_path)) { /* relative base path, so add base dir of project file name */ gchar *dir = g_path_get_dirname(locale_filename); SETPTR(locale_path, g_strconcat(dir, G_DIR_SEPARATOR_S, locale_path, NULL)); g_free(dir); } if (! g_file_test(locale_path, G_FILE_TEST_IS_DIR)) { gboolean create_dir; create_dir = dialogs_show_question_full(NULL, GTK_STOCK_OK, GTK_STOCK_CANCEL, _("Create the project's base path directory?"), _("The path \"%s\" does not exist."), base_path); if (create_dir) err_code = utils_mkdir(locale_path, TRUE); if (! create_dir || err_code != 0) { if (err_code != 0) SHOW_ERR1(_("Project base directory could not be created (%s)."), g_strerror(err_code)); gtk_widget_grab_focus(e->base_path); utils_free_pointers(2, locale_path, locale_filename, NULL); return FALSE; } } g_free(locale_path); } /* finally test whether the given project file can be written */ if ((err_code = utils_is_file_writable(locale_filename)) != 0 || (err_code = g_file_test(locale_filename, G_FILE_TEST_IS_DIR) ? EISDIR : 0) != 0) { SHOW_ERR1(_("Project file could not be written (%s)."), g_strerror(err_code)); gtk_widget_grab_focus(e->file_name); g_free(locale_filename); return FALSE; } g_free(locale_filename); if (app->project == NULL) { create_project(); new_project = TRUE; } p = app->project; SETPTR(p->name, g_strdup(name)); SETPTR(p->file_name, g_strdup(file_name)); /* use "." if base_path is empty */ SETPTR(p->base_path, g_strdup(NZV(base_path) ? base_path : "./")); if (! new_project) /* save properties specific fields */ { GtkTextIter start, end; GtkTextBuffer *buffer; GeanyDocument *doc = document_get_current(); GeanyBuildCommand *oldvalue; GeanyFiletype *ft = doc ? doc->file_type : NULL; GtkWidget *widget; gchar *tmp; GString *str; GSList *node; /* get and set the project description */ buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e->description)); gtk_text_buffer_get_start_iter(buffer, &start); gtk_text_buffer_get_end_iter(buffer, &end); SETPTR(p->description, g_strdup(gtk_text_buffer_get_text(buffer, &start, &end, FALSE))); foreach_slist(node, stash_groups) stash_group_update(node->data, e->dialog); /* read the project build menu */ oldvalue = ft ? ft->projfilecmds : NULL; build_read_project(ft, e->build_properties); if (ft != NULL && ft->projfilecmds != oldvalue && ft->project_list_entry < 0) { if (p->build_filetypes_list == NULL) p->build_filetypes_list = g_ptr_array_new(); ft->project_list_entry = p->build_filetypes_list->len; g_ptr_array_add(p->build_filetypes_list, ft); } build_menu_update(doc); widget = ui_lookup_widget(e->dialog, "radio_long_line_disabled_project"); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) p->long_line_behaviour = 0; else { widget = ui_lookup_widget(e->dialog, "radio_long_line_default_project"); if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) p->long_line_behaviour = 1; else /* "Custom" radio button must be checked */ p->long_line_behaviour = 2; } widget = ui_lookup_widget(e->dialog, "spin_long_line_project"); p->long_line_column = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); apply_editor_prefs(); /* get and set the project file patterns */ tmp = g_strdup(gtk_entry_get_text(GTK_ENTRY(e->patterns))); g_strfreev(p->file_patterns); g_strstrip(tmp); str = g_string_new(tmp); do {} while (utils_string_replace_all(str, " ", " ")); p->file_patterns = g_strsplit(str->str, " ", -1); g_string_free(str, TRUE); g_free(tmp); } update_ui(); return TRUE; }
static void find_tags(const gchar *name, gboolean declaration, gboolean case_sensitive, MatchType match_type) { tagFile *tf; GeanyProject *prj; gchar *tag_filename = NULL; tagEntry entry; tagFileInfo info; prj = geany_data->app->project; if (!prj) return; msgwin_clear_tab(MSG_MESSAGE); msgwin_set_messages_dir(prj->base_path); tag_filename = get_tags_filename(); tf = tagsOpen(tag_filename, &info); if (tf) { if (find_first(tf, &entry, name, match_type)) { GPatternSpec *name_pat; gchar *name_case; gchar *path = NULL; gint num = 0; if (case_sensitive) name_case = g_strdup(name); else name_case = g_utf8_strdown(name, -1); SETPTR(name_case, g_strconcat("*", name_case, "*", NULL)); name_pat = g_pattern_spec_new(name_case); if (!filter_tag(&entry, name_pat, declaration, case_sensitive)) { path = g_build_filename(prj->base_path, entry.file, NULL); show_entry(&entry); num++; } while (find_next(tf, &entry, match_type)) { if (!filter_tag(&entry, name_pat, declaration, case_sensitive)) { if (!path) path = g_build_filename(prj->base_path, entry.file, NULL); show_entry(&entry); num++; } } if (num == 1) { GeanyDocument *doc = document_open_file(path, FALSE, NULL, NULL); if (doc != NULL) { navqueue_goto_line(document_get_current(), doc, entry.address.lineNumber); gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci)); } } g_pattern_spec_free(name_pat); g_free(name_case); g_free(path); } tagsClose(tf); } msgwin_switch_tab(MSG_MESSAGE, TRUE); g_free(tag_filename); }
static void configure_response_cb(GtkDialog *dialog, gint response, G_GNUC_UNUSED gpointer data) { if (response == GTK_RESPONSE_OK || response == GTK_RESPONSE_APPLY) { GKeyFile *config = g_key_file_new(); gchar *str; const gchar *text_dir, *text_time; gchar *config_dir = g_path_get_dirname(config_file); enable_autosave = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.checkbox_enable_autosave)); enable_autosave_losing_focus = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.checkbox_enable_autosave_losing_focus)); enable_instantsave = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.checkbox_enable_instantsave)); enable_backupcopy = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.checkbox_enable_backupcopy)); autosave_interval = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(pref_widgets.autosave_interval_spin)); autosave_print_msg = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.autosave_print_msg_checkbox)); autosave_save_all = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON(pref_widgets.autosave_save_all_radio2)); g_free(instantsave_default_ft); instantsave_default_ft = gtk_combo_box_text_get_active_text( GTK_COMBO_BOX_TEXT(pref_widgets.instantsave_ft_combo)); text_dir = gtk_entry_get_text(GTK_ENTRY(pref_widgets.backupcopy_entry_dir)); text_time = gtk_entry_get_text(GTK_ENTRY(pref_widgets.backupcopy_entry_time)); backupcopy_dir_levels = gtk_spin_button_get_value_as_int( GTK_SPIN_BUTTON(pref_widgets.backupcopy_spin_dir_levels)); g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_key_file_set_boolean(config, "saveactions", "enable_autosave", enable_autosave); g_key_file_set_boolean(config, "saveactions", "enable_autosave_losing_focus", enable_autosave_losing_focus); g_key_file_set_boolean(config, "saveactions", "enable_instantsave", enable_instantsave); g_key_file_set_boolean(config, "saveactions", "enable_backupcopy", enable_backupcopy); g_key_file_set_boolean(config, "autosave", "print_messages", autosave_print_msg); g_key_file_set_boolean(config, "autosave", "save_all", autosave_save_all); g_key_file_set_integer(config, "autosave", "interval", autosave_interval); if (instantsave_default_ft != NULL) g_key_file_set_string(config, "instantsave", "default_ft", instantsave_default_ft); g_key_file_set_integer(config, "backupcopy", "dir_levels", backupcopy_dir_levels); g_key_file_set_string(config, "backupcopy", "time_fmt", text_time); SETPTR(backupcopy_time_fmt, g_strdup(text_time)); if (enable_backupcopy) { if (!EMPTY(text_dir) && backupcopy_set_backup_dir(text_dir)) { g_key_file_set_string(config, "backupcopy", "backup_dir", text_dir); } else { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Backup directory does not exist or is not writable.")); } } if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ str = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, str); g_free(str); } if (enable_autosave) autosave_set_timeout(); /* apply the changes */ g_free(config_dir); g_key_file_free(config); } }
static gint socket_fd_open_unix(const gchar *path) { gint sock; struct sockaddr_un addr; gint val; gchar *real_path; sock = socket(PF_UNIX, SOCK_STREAM, 0); if (sock < 0) { log_error("Failed to create IPC socket", errno); return -1; } val = 1; if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &val, sizeof(val)) < 0) { log_error("Failed to set IPC socket option", errno); socket_fd_close(sock); return -1; } /* fix for #1888561: * in case the configuration directory is located on a network file system or any other * file system which doesn't support sockets, we just link the socket there and create the * real socket in the system's tmp directory assuming it supports sockets */ real_path = g_strdup_printf("%s%cgeany_socket.%08x", g_get_tmp_dir(), G_DIR_SEPARATOR, g_random_int()); if (utils_is_file_writable(real_path) != 0) { /* if real_path is not writable for us, fall back to ~/.config/geany/geany_socket_*_* */ /* instead of creating a symlink and print a warning */ g_warning("Socket %s could not be written, using %s as fallback.", real_path, path); SETPTR(real_path, g_strdup(path)); } /* create a symlink in e.g. ~/.config/geany/geany_socket_hostname__0 to /tmp/geany_socket.499602d2 */ else if (symlink(real_path, path) != 0) { gint saved_errno = errno; gchar* message = g_strdup_printf( "Failed to create IPC socket symlink %s -> %s)", real_path, path); log_error(message, saved_errno); g_free(message); socket_fd_close(sock); return -1; } memset(&addr, 0, sizeof(addr)); addr.sun_family = AF_UNIX; strncpy(addr.sun_path, real_path, sizeof(addr.sun_path) - 1); if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0) { gint saved_errno = errno; gchar* message = g_strdup_printf("Failed to bind IPC socket (%s)", real_path); log_error(message, saved_errno); g_free(message); socket_fd_close(sock); return -1; } if (listen(sock, 1) < 0) { gint saved_errno = errno; gchar* message = g_strdup_printf("Failed to listen on IPC socket (%s)", real_path); log_error(message, saved_errno); g_free(message); socket_fd_close(sock); return -1; } g_chmod(real_path, 0600); g_free(real_path); return sock; }
static void insertfree(void *currblock, size_t size) { int listcounter = 0; void *search_currblock = currblock; void *insert_currblock = NULL; for(;(listcounter < LISTS - 1) && (size > 1); listcounter++) { size >>= 1; } search_currblock = free_lists[listcounter]; while ((search_currblock != NULL) && (size > GETSIZE(HEADER(search_currblock)))) { insert_currblock = search_currblock; search_currblock = PREVFREE(search_currblock); } if (search_currblock != NULL) { if (insert_currblock != NULL) { SETPTR(PREVPTR(currblock), search_currblock); SETPTR(NEXTPTR(search_currblock), currblock); SETPTR(NEXTPTR(currblock), insert_currblock); SETPTR(PREVPTR(insert_currblock), currblock); } else { SETPTR(PREVPTR(currblock), search_currblock); SETPTR(NEXTPTR(search_currblock), currblock); SETPTR(NEXTPTR(currblock), NULL); free_lists[listcounter] = currblock; } } else { if (insert_currblock != NULL) { SETPTR(PREVPTR(currblock), NULL); SETPTR(NEXTPTR(currblock), insert_currblock); SETPTR(PREVPTR(insert_currblock), currblock); } else { SETPTR(PREVPTR(currblock), NULL); SETPTR(NEXTPTR(currblock), NULL); free_lists[listcounter] = currblock; } } return; }
static void store_populate_menu_items (GtkListStore *store, GtkMenuShell *menu, const gchar *parent_path) { GList *children; GList *node; children = gtk_container_get_children (GTK_CONTAINER (menu)); for (node = children; node; node = node->next) { if (GTK_IS_SEPARATOR_MENU_ITEM (node->data) || ! gtk_widget_get_visible (node->data)) { /* skip that */ } else if (GTK_IS_MENU_ITEM (node->data)) { GtkWidget *submenu; gchar *path; gchar *item_label; gboolean use_underline; GtkStockItem item; if (GTK_IS_IMAGE_MENU_ITEM (node->data) && gtk_image_menu_item_get_use_stock (node->data) && gtk_stock_lookup (gtk_menu_item_get_label (node->data), &item)) { item_label = g_strdup (item.label); use_underline = TRUE; } else { item_label = g_strdup (gtk_menu_item_get_label (node->data)); use_underline = gtk_menu_item_get_use_underline (node->data); } /* remove underlines */ if (use_underline) { gchar *p = item_label; gsize len = strlen (p); while ((p = strchr (p, '_')) != NULL) { len -= (gsize) (p - item_label); memmove (p, p + 1, len); } } if (parent_path) { path = g_strconcat (parent_path, PATH_SEPARATOR, item_label, NULL); } else { path = g_strdup (item_label); } submenu = gtk_menu_item_get_submenu (node->data); if (submenu) { /* go deeper in the menus... */ store_populate_menu_items (store, GTK_MENU_SHELL (submenu), path); } else { gchar *tmp; gchar *tooltip; gchar *label = g_markup_printf_escaped ("<big>%s</big>", item_label); tooltip = gtk_widget_get_tooltip_markup (node->data); if (tooltip) { SETPTR (label, g_strconcat (label, "\n<small>", tooltip, "</small>", NULL)); g_free (tooltip); } tmp = g_markup_escape_text (path, -1); SETPTR (label, g_strconcat (label, "\n<small><i>", tmp, "</i></small>", NULL)); g_free (tmp); gtk_list_store_insert_with_values (store, NULL, -1, COL_LABEL, label, COL_PATH, path, COL_TYPE, COL_TYPE_MENU_ITEM, COL_WIDGET, node->data, -1); g_free (label); } g_free (item_label); g_free (path); } else { g_warning ("Unknown widget type in the menu: %s", G_OBJECT_TYPE_NAME (node->data)); } } g_list_free (children); }