コード例 #1
0
ファイル: syntax_check.c プロジェクト: peavey/gphpedit
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));
	}
}
コード例 #2
0
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