void utils_str_replace_all(gchar **haystack, const gchar *needle, const gchar *replacement) { GString *str; g_return_if_fail(*haystack != NULL); str = g_string_new(*haystack); g_free(*haystack); utils_string_replace_all(str, needle, replacement); *haystack = g_string_free(str, FALSE); }
void glatex_structure_lvlup(void) { gint i; GeanyDocument *doc = NULL; gchar *tmp = NULL; GString *haystack = NULL; doc = document_get_current(); if (doc == NULL) return; if (! sci_has_selection(doc->editor->sci)) return; sci_start_undo_action(doc->editor->sci); tmp = sci_get_selection_contents(doc->editor->sci); haystack = g_string_new(tmp); g_free(tmp); tmp = NULL; for (i = 0; i < GLATEX_STRUCTURE_N_LEVEL; i++) { if (utils_string_replace_all (haystack, glatex_structure_values[i], glatex_structure_values[glatex_structure_rotate(FALSE, i)] ) > 0) { tmp = g_string_free(haystack, FALSE); haystack = NULL; sci_replace_sel(doc->editor->sci, tmp); g_free(tmp); sci_end_undo_action(doc->editor->sci); break; } } if (haystack != NULL) g_string_free(haystack, 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; }
/* Callback for sending file as attachment */ static void send_as_attachment(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { GeanyDocument *doc; gchar *locale_filename = NULL; gchar *command = NULL; GError *error = NULL; GString *cmd_str = NULL; gchar *data; doc = document_get_current(); if (doc->file_name == NULL) { dialogs_show_save_as(); } else { document_save_file(doc, FALSE); } if (doc->file_name != NULL) { if (mailer) { locale_filename = utils_get_locale_from_utf8(doc->file_name); cmd_str = g_string_new(mailer); if ((use_address_dialog == TRUE) && (g_strrstr(mailer, "%r") != NULL)) { GKeyFile *config = NULL; gchar *config_dir = NULL; gchar *input = dialogs_show_input(_("Recipient's Address"), GTK_WINDOW(geany->main_widgets->window), _("Enter the recipient's e-mail address:"), address); if (input) { config = g_key_file_new(); g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_free(address); address = input; g_key_file_set_string(config, "tools", "address", address); } else { g_string_free(cmd_str, TRUE); g_free(locale_filename); return; } config_dir = g_path_get_dirname(config_file); 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 */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, data); g_free(data); } g_key_file_free(config); g_free(config_dir); } if (! utils_string_replace_all(cmd_str, "%f", locale_filename)) ui_set_statusbar(FALSE, _("Filename placeholder not found. The executed command might have failed.")); if (use_address_dialog == TRUE && address != NULL) { if (! utils_string_replace_all(cmd_str, "%r", address)) ui_set_statusbar(FALSE, _("Recipient address placeholder not found. The executed command might have failed.")); } else { /* Removes %r if option was not activ but was included into command */ utils_string_replace_all(cmd_str, "%r", ""); } utils_string_replace_all(cmd_str, "%b", g_path_get_basename(locale_filename)); command = g_string_free(cmd_str, FALSE); g_spawn_command_line_async(command, &error); if (error != NULL) { ui_set_statusbar(FALSE, _("Could not execute mailer. Please check your configuration.")); g_error_free(error); } g_free(locale_filename); g_free(command); } else { ui_set_statusbar(FALSE, _("Please define a mail client first.")); } } else { ui_set_statusbar(FALSE, _("File has to be saved before sending.")); } }
static void load_program(void) { char *args[] = { utils_get_locale_from_utf8(pref_gdb_executable), (char *) "--quiet", (char *) "--interpreter=mi2", NULL }; GError *gerror = NULL; statusbar_update_state(DS_EXTRA_2); plugin_blink(); while (gtk_events_pending()) gtk_main_iteration(); if (spawn_with_callbacks(NULL, NULL, args, NULL, GDB_SPAWN_FLAGS, obtain_send_channel_cb, NULL, receive_output_cb, NULL, GDB_BUFFER_SIZE, receive_errors_cb, NULL, 0, gdb_exit_cb, NULL, &gdb_pid, &gerror)) { gchar **environment = g_strsplit(program_environment, "\n", -1); gchar *const *envar; #ifdef G_OS_UNIX extern char *slave_pty_name; #else GString *escaped = g_string_new(program_executable); #endif /* startup */ gdb_state = ACTIVE; dc_clear(); utils_lock_all(TRUE); signal(SIGINT, SIG_IGN); wait_result = 0; wait_prompt = TRUE; g_string_truncate(commands, 0); leading_receive = TRUE; if (pref_gdb_async_mode) g_string_append(commands, "-gdb-set target-async on\n"); if (program_non_stop_mode) g_string_append(commands, "-gdb-set non-stop on\n"); #ifdef G_OS_UNIX append_startup("010-file-exec-and-symbols", program_executable); append_startup("-gdb-set inferior-tty", slave_pty_name); #else /* G_OS_UNIX */ utils_string_replace_all(escaped, "\\", "\\\\"); append_startup("010-file-exec-and-symbols", escaped->str); g_string_free(escaped, TRUE); g_string_append(commands, "-gdb-set new-console on\n"); #endif /* G_OS_UNIX */ append_startup("-environment-cd", program_working_dir); /* no escape needed */ append_startup("-exec-arguments", program_arguments); for (envar = environment; *envar; envar++) append_startup("-gdb-set environment", *envar); g_strfreev(environment); append_startup("011source -v", program_load_script); g_string_append(commands, "07-list-target-features\n"); breaks_query_async(commands); if (*program_executable || *program_load_script) { debug_load_error = FALSE; debug_auto_run = debug_auto_exit = program_auto_run_exit; } else debug_auto_run = debug_auto_exit = FALSE; if (option_open_panel_on_load) open_debug_panel(); registers_query_names(); } else { show_error(_("%s: %s."), pref_gdb_executable, gerror->message); g_error_free(gerror); } g_free(args[0]); if (gdb_state == INACTIVE) statusbar_update_state(DS_INACTIVE); }