static void quick_find() { gtk_tree_store_clear(list); const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry)); if(strcmp(text, "") == 0) { return; } get_path(); row_pos = 1; gboolean case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_case)); GError *error = NULL; gint std_out, std_err; gchar **cmd; gchar *command = g_strconcat(executable, " ", case_sensitive ? "" : "-i ", g_shell_quote(text), NULL); if(!g_shell_parse_argv(command, NULL, &cmd, &error)) { ui_set_statusbar(TRUE, _("quick-find failed: %s (%s)"), error->message, command); g_error_free(error); g_free(command); return; } g_free(command); gchar **env = utils_copy_environment( NULL, "GEAN", "running from geany", NULL ); if(g_spawn_async_with_pipes( base_directory, cmd, env, 0, NULL, NULL, NULL, NULL, &std_out, &std_err, &error )) { #ifdef G_OS_WIN32 GIOChannel *err_channel = g_io_channel_win32_new_fd(std_err); GIOChannel *out_channel = g_io_channel_win32_new_fd(std_out); #else GIOChannel *err_channel = g_io_channel_unix_new(std_err); GIOChannel *out_channel = g_io_channel_unix_new(std_out); #endif g_io_channel_set_encoding(out_channel, NULL, NULL); g_io_add_watch(out_channel, G_IO_IN | G_IO_HUP, (GIOFunc)output_out, GUINT_TO_POINTER(0)); g_io_channel_set_encoding(err_channel, NULL, NULL); g_io_add_watch(err_channel, G_IO_IN | G_IO_HUP, (GIOFunc)output_out, GUINT_TO_POINTER(1)); } else { printf("quick-find ERROR %s: %s\n", cmd[0], error->message); ui_set_statusbar(TRUE, _("quick-find ERROR %s: %s"), cmd[0], error->message); g_error_free(error); } g_free(cmd); g_free(env); }
/* * starts gdb, collects commands and start the first one */ gboolean run(const gchar* file, const gchar* commandline, GList* env, GList *witer, GList *biter, const gchar* terminal_device, dbg_callbacks* callbacks) { GError *err = NULL; dbg_cbs = callbacks; /* spawn GDB */ const gchar *exclude[] = { "LANG", NULL }; gchar **gdb_env = utils_copy_environment(exclude, "LANG", "C", NULL); if (!g_spawn_async_with_pipes(NULL, (gchar**)gdb_args, gdb_env, GDB_SPAWN_FLAGS, NULL, NULL, &gdb_pid, &gdb_in, &gdb_out, NULL, &err)) { dbg_cbs->report_error(_("Failed to spawn gdb process")); return FALSE; } g_strfreev(gdb_env); /* move gdb to it's own process group */ setpgid(gdb_pid, 0); /* set handler for gdb process exit event */ g_child_watch_add(gdb_pid, on_gdb_exit, NULL); gdb_src = g_child_watch_source_new(gdb_pid); /* create GDB GIO chanels */ gdb_ch_in = g_io_channel_unix_new(gdb_in); gdb_ch_out = g_io_channel_unix_new(gdb_out); /* reading starting gdb messages */ GList *lines = read_until_prompt(); GList *line = lines; while (line) { gchar *unescaped = g_strcompress((gchar*)line->data); if (strlen(unescaped)) { colorize_message((gchar*)line->data); } line = line->next; } g_list_foreach(lines, (GFunc)g_free, NULL); g_list_free(lines); /* add initial watches to the list */ while (witer) { gchar *name = (gchar*)witer->data; variable *var = variable_new(name, VT_WATCH); watches = g_list_append(watches, var); witer = witer->next; } /* collect commands */ GList *commands = NULL; /* loading file */ GString *command = g_string_new(""); g_string_printf(command, "-file-exec-and-symbols %s", file); commands = add_to_queue(commands, _("~\"Loading target file ...\""), command->str, _("Error loading file"), FALSE); g_string_free(command, TRUE); /* setting asyncronous mode */ commands = add_to_queue(commands, NULL, "-gdb-set target-async 1", _("Error configuring GDB"), FALSE); /* setting null-stop array printing */ commands = add_to_queue(commands, NULL, "-interpreter-exec console \"set print null-stop\"", _("Error configuring GDB"), FALSE); /* enable pretty printing */ commands = add_to_queue(commands, NULL, "-enable-pretty-printing", _("Error configuring GDB"), FALSE); /* set locale */ command = g_string_new(""); g_string_printf(command, "-gdb-set environment LANG=%s", g_getenv("LANG")); commands = add_to_queue(commands, NULL, command->str, NULL, FALSE); g_string_free(command, TRUE); /* set arguments */ command = g_string_new(""); g_string_printf(command, "-exec-arguments %s", commandline); commands = add_to_queue(commands, NULL, command->str, NULL, FALSE); g_string_free(command, TRUE); /* set passed evironment */ GList *iter = env; while (iter) { gchar *name = (gchar*)iter->data; iter = iter->next; gchar *value = (gchar*)iter->data; command = g_string_new(""); g_string_printf(command, "-gdb-set environment %s=%s", name, value); commands = add_to_queue(commands, NULL, command->str, NULL, FALSE); g_string_free(command, TRUE); iter = iter->next; } /* set breaks */ int bp_index = 1; while (biter) { breakpoint *bp = (breakpoint*)biter->data; command = g_string_new(""); g_string_printf(command, "-break-insert -f %s:%i", bp->file, bp->line); GString *error_message = g_string_new(""); g_string_printf(error_message, _("Breakpoint at %s:%i cannot be set\nDebugger message: %s"), bp->file, bp->line, "%s"); commands = add_to_queue(commands, NULL, command->str, error_message->str, TRUE); g_string_free(command, TRUE); g_string_free(error_message, TRUE); if (bp->hitscount) { command = g_string_new(""); g_string_printf(command, "-break-after %i %i", bp_index, bp->hitscount); commands = add_to_queue(commands, NULL, command->str, error_message->str, TRUE); g_string_free(command, TRUE); } if (strlen(bp->condition)) { command = g_string_new(""); g_string_printf (command, "-break-condition %i %s", bp_index, bp->condition); commands = add_to_queue(commands, NULL, command->str, error_message->str, TRUE); g_string_free(command, TRUE); } if (!bp->enabled) { command = g_string_new(""); g_string_printf (command, "-break-disable %i", bp_index); commands = add_to_queue(commands, NULL, command->str, error_message->str, TRUE); g_string_free(command, TRUE); } bp_index++; biter = biter->next; } /* set debugging terminal */ command = g_string_new("-inferior-tty-set "); g_string_append(command, terminal_device); commands = add_to_queue(commands, NULL, command->str, NULL, FALSE); g_string_free(command, TRUE); /* connect read callback to the output chanel */ gdb_id_out = g_io_add_watch(gdb_ch_out, G_IO_IN, on_read_async_output, commands); queue_item *item = (queue_item*)commands->data; /* send message to debugger messages window */ if (item->message) { dbg_cbs->send_message(item->message->str, "grey"); } /* send first command */ gdb_input_write_line(item->command->str); return TRUE; }