void plugin_exec(gint plugin_num) { Plugin *plugin; gchar *stdout = NULL; GError *error = NULL; gint exit_status; GString *command_line = NULL; gint wordStart; gint wordEnd; gchar *current_selection; gint ac_length; gchar *data; if (main_window.current_editor == NULL) { return; } plugin = (Plugin *)g_list_nth_data(Plugins, plugin_num); if (!plugin) { g_print(_("Plugin is null!\n")); } //g_print("Plugin No: %d:%d (%s):%s\n", plugin_num, plugin->type, plugin->name, plugin->filename->str); command_line = g_string_new(plugin->filename->str); command_line = g_string_prepend(command_line, "'"); command_line = g_string_append(command_line, "' '"); if (plugin->type == GPHPEDIT_PLUGIN_TYPE_SELECTION) { wordStart = gtk_scintilla_get_selection_start(GTK_SCINTILLA(main_window.current_editor->scintilla)); wordEnd = gtk_scintilla_get_selection_end(GTK_SCINTILLA(main_window.current_editor->scintilla)); current_selection = gtk_scintilla_get_text_range (GTK_SCINTILLA(main_window.current_editor->scintilla), wordStart, wordEnd, &ac_length); command_line = g_string_append(command_line, current_selection); } else if (plugin->type == GPHPEDIT_PLUGIN_TYPE_FILENAME) { command_line = g_string_append(command_line, editor_convert_to_local(main_window.current_editor)); } command_line = g_string_append(command_line, "'"); //g_print("SPAWNING: %s\n", command_line->str); if (g_spawn_command_line_sync(command_line->str,&stdout,NULL, &exit_status,&error)) { data = strstr(stdout, "\n"); data++; //g_print("COMMAND: %s\nSTDOUT:%s\nOUTPUT: %s\n", command_line->str, stdout, data); if (g_strncasecmp(stdout, "INSERT", MIN(strlen(stdout), 6))==0) { if (data) { gtk_scintilla_insert_text(GTK_SCINTILLA(main_window.current_editor->scintilla), gtk_scintilla_get_current_pos(GTK_SCINTILLA(main_window.current_editor->scintilla)), data); } } else if (g_strncasecmp(stdout, "REPLACE", MIN(strlen(stdout), 7))==0) { if (data) { gtk_scintilla_replace_sel(GTK_SCINTILLA(main_window.current_editor->scintilla), data); } } else if (g_strncasecmp(stdout, "MESSAGE", MIN(strlen(stdout),7))==0) { info_dialog(plugin->name, data); } else if (g_strncasecmp(stdout, "OPEN", MIN(strlen(stdout), 4))==0) { if (DEBUG_MODE) { g_print("DEBUG: main_window.c:plugin_exec: Opening file :date: %s\n", data); } switch_to_file_or_open(data, 0); } else if (g_strncasecmp(stdout, "DEBUG", MIN(strlen(stdout), 5))==0) { debug_dump_editors(); DEBUG_MODE = TRUE; } g_free(stdout); } else { g_print(_("Spawning %s gave error %s\n"), plugin->filename->str, error->message); } }
void syntax_check_run(void) { GtkTreeIter iter; GString *command_line; gchar *output; gboolean using_temp; GString *filename; /* Tim: this doesn't work if php_binary_location is not an absolute path struct stat *buf = NULL; if (stat(preferences.php_binary_location, buf)==-1) { g_print("PHP command line binary not found.\n"); } else */ if (main_window.current_editor) { if (main_window.current_editor->saved==TRUE) { filename = g_string_new(editor_convert_to_local(main_window.current_editor)); using_temp = FALSE; } else { filename = save_as_temp_file(); using_temp = TRUE; } command_line = g_string_new(preferences.php_binary_location); command_line = g_string_append(command_line, " -q -l -d html_errors=Off -f "); command_line = g_string_append(command_line, filename->str); g_print("eject:%s\n", command_line->str); output = run_php_lint(command_line->str); g_string_free(command_line, TRUE); main_window.lint_store = gtk_list_store_new (1, G_TYPE_STRING); gtk_scintilla_start_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), 0, INDIC2_MASK); gtk_scintilla_set_styling(GTK_SCINTILLA(main_window.current_editor->scintilla), gtk_scintilla_get_length(GTK_SCINTILLA(main_window.current_editor->scintilla)), 0); gtk_list_store_clear(main_window.lint_store); if (output) { syntax_add_lines(output); g_free(output); } else { gtk_list_store_append (main_window.lint_store, &iter); gtk_list_store_set (main_window.lint_store, &iter, 0, _("Error calling PHP CLI (is PHP command line binary installed? If so, check if it's in your path or set php_binary in ~/.gnome2/gPHPEdit)\n"), -1); } gtk_tree_view_set_model(GTK_TREE_VIEW(main_window.lint_view), GTK_TREE_MODEL(main_window.lint_store)); if (using_temp) { unlink(filename->str); } g_string_free(filename, TRUE); } else { main_window.lint_store = gtk_list_store_new (1, G_TYPE_STRING); gtk_list_store_clear(main_window.lint_store); gtk_list_store_append (main_window.lint_store, &iter); gtk_list_store_set (main_window.lint_store, &iter, 0, _("You don't have any files open to check\n"), -1); gtk_tree_view_set_model(GTK_TREE_VIEW(main_window.lint_view), GTK_TREE_MODEL(main_window.lint_store)); } }
int syntax_check_run(void) { GtkTreeIter iter; GString *command_line; gchar *stderr; gchar *stdout; GString *filename; GError *error; gboolean using_temp; stdout=NULL; stderr=NULL; error=NULL; int return_code=0; Editor *editor=main_window_get_current_editor(); GtkListStore *lint_store=main_window_get_lint_store(); if(!editor) { // No 'working' files. lint_store=gtk_list_store_new(1, G_TYPE_STRING); gtk_list_store_clear(lint_store); gtk_list_store_append(lint_store, &iter); gtk_list_store_set(lint_store, &iter, 0, _("You don't have any files open to check\n"), -1); gtk_tree_view_set_model(GTK_TREE_VIEW(main_window_get_lint_view()), GTK_TREE_MODEL(lint_store)); return E_PHP_SYNTAX_NO_OPEN_FILES; } if(editor->saved==TRUE) { filename = g_string_new(editor_convert_to_local(editor)); using_temp = FALSE; } else { filename = save_as_temp_file(); using_temp = TRUE; } command_line = g_string_new(preferences.php_binary_location); command_line = g_string_append(command_line, " -q -l -d html_errors=Off -f "); command_line = g_string_append(command_line, filename->str); stdout=run_php_lint(command_line->str, FALSE); stderr=run_php_lint(command_line->str, TRUE); g_string_free(command_line, TRUE); lint_store = gtk_list_store_new(1, G_TYPE_STRING); gtk_scintilla_start_styling(GTK_SCINTILLA(editor->scintilla), 0, INDIC2_MASK); gtk_scintilla_set_styling(GTK_SCINTILLA(editor->scintilla), gtk_scintilla_get_length(GTK_SCINTILLA(editor->scintilla)), 0); gtk_list_store_clear(lint_store); return_code=0; if(stdout||stderr) { gtk_list_store_append(lint_store, &iter); gtk_list_store_set(lint_store, &iter, 0, _(stdout), -1); syntax_add_lines(stderr); return_code = E_PHP_SYNTAX_ERROR; } else { gtk_list_store_append(lint_store, &iter); gtk_list_store_set(lint_store, &iter, 0, _("Error calling PHP CLI. Is PHP command line binary installed? If so, check if it's in your path or set php_binary in ~/.gnome2/connectED.\n"), -1); return_code = E_PHP_SYNTAX_CLI_NOT_FOUND; } gtk_tree_view_set_model(GTK_TREE_VIEW(main_window_get_lint_view()), GTK_TREE_MODEL(lint_store)); if(using_temp) unlink(filename->str); g_free(stdout); g_free(stderr); g_string_free(filename, TRUE); return return_code; }//syntax_check