SF.net SVN: geany: [434] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Sun Jun 11 22:39:19 UTC 2006


Revision: 434
Author:   eht16
Date:     2006-06-11 15:39:11 -0700 (Sun, 11 Jun 2006)
ViewCVS:  http://svn.sourceforge.net/geany/?rev=434&view=rev

Log Message:
-----------
document_open_file() returns the index of the opened file.
Open or switch to files when clicking on compiler error messages and the error message mentions another file than the opened one.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/document.c
    trunk/src/document.h
    trunk/src/utils.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2006-06-11 19:04:17 UTC (rev 433)
+++ trunk/ChangeLog	2006-06-11 22:39:11 UTC (rev 434)
@@ -8,6 +8,11 @@
  * src/geany.h, src/callbacks.c, src/main.c:
    Improved the handling of GIOChannels(for named pipes), ensure they
    are closed in a proper way.
+ * src/document.c: document_open_file() returns the index of the opened
+                   file.
+ * src/utils.c: Open or switch to files when clicking on compiler error
+                messages and the error message mentions another file
+                than the opened one.
 
 
 2006-06-10  Enrico Troeger  <enrico.troeger at uvena.de>

Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c	2006-06-11 19:04:17 UTC (rev 433)
+++ trunk/src/document.c	2006-06-11 22:39:11 UTC (rev 434)
@@ -399,8 +399,9 @@
  * set the cursor to pos.
  * If idx is greater than -1, it reloads the file in the tab corresponding to
  * idx and set the cursor to position 0. In this case, filename should be NULL
+ * It returns the idx of the opened file or -1 if an error occurred.
  */
-void document_open_file(gint idx, const gchar *filename, gint pos, gboolean readonly, filetype *ft)
+int document_open_file(gint idx, const gchar *filename, gint pos, gboolean readonly, filetype *ft)
 {
 	gint editor_mode;
 	gsize size;
@@ -427,7 +428,7 @@
 		if (filename == NULL)
 		{
 			msgwin_status_add(_("Invalid filename"));
-			return;
+			return -1;
 		}
 
 		// try to get the UTF-8 equivalent for the filename, fallback to filename if error
@@ -449,9 +450,10 @@
 			gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook),
 					gtk_notebook_page_num(GTK_NOTEBOOK(app->notebook),
 					(GtkWidget*) doc_list[idx].sci));
+			sci_goto_pos(doc_list[idx].sci, pos, TRUE);
 			g_free(utf8_filename);
 			g_free(locale_filename);
-			return;
+			return idx;
 		}
 	}
 
@@ -460,7 +462,7 @@
 		msgwin_status_add(_("Could not open file %s (%s)"), utf8_filename, g_strerror(errno));
 		g_free(utf8_filename);
 		g_free(locale_filename);
-		return;
+		return -1;
 	}
 
 #ifdef GEANY_WIN32
@@ -474,7 +476,7 @@
 		g_error_free(err);
 		g_free(utf8_filename);
 		g_free(locale_filename);
-		return;
+		return -1;
 	}
 
 	/* Determine character encoding and convert to utf-8*/
@@ -495,7 +497,7 @@
 				g_free(data);
 				g_free(utf8_filename);
 				g_free(locale_filename);
-				return;
+				return -1;
 			}
 			else
 			{
@@ -579,6 +581,8 @@
 	g_free(locale_filename);
 	//gettimeofday(&tv1, &tz);
 	//geany_debug("%s: %d", filename, (gint)(tv1.tv_usec - tv.tv_usec));
+
+	return idx;
 }
 
 

Modified: trunk/src/document.h
===================================================================
--- trunk/src/document.h	2006-06-11 19:04:17 UTC (rev 433)
+++ trunk/src/document.h	2006-06-11 22:39:11 UTC (rev 434)
@@ -76,9 +76,10 @@
 /* If idx is set to -1, it creates a new tab, opens the file from filename and
  * set the cursor to pos.
  * If idx is greater than -1, it reloads the file in the tab corresponding to
- * idx and set the cursor to position 0.
+ * idx and set the cursor to position 0. In this case, filename should be NULL
+ * It returns the idx of the opened file or -1 if an error occurred.
  */
-void document_open_file(gint, const gchar*, gint, gboolean, filetype*);
+int document_open_file(gint, const gchar*, gint, gboolean, filetype*);
 
 
 /* This saves the file, which is in on-disk encoding (which may not

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2006-06-11 19:04:17 UTC (rev 433)
+++ trunk/src/utils.c	2006-06-11 22:39:11 UTC (rev 434)
@@ -2289,7 +2289,9 @@
  * and when something useful is found, it jumps to file and scrolls to the line  */
 void utils_parse_compiler_error_line(const gchar *string)
 {
+	/// TODO remove the assignment
 	gint idx = document_get_cur_idx();
+	gint idx_of_error_file = document_get_cur_idx();
 	gint line = -1;
 
 	if (string == NULL || ! doc_list[app->cur_idx].is_valid ||
@@ -2302,23 +2304,53 @@
 		case GEANY_FILETYPES_C:
 		case GEANY_FILETYPES_CPP:
 		case GEANY_FILETYPES_RUBY:
+		case GEANY_FILETYPES_JAVA:
 		{
-			gchar *colon = strchr(string, ':');
+			// empty.h:4: Warnung: type defaults to `int' in declaration of `foo'
+			// empty.c:21: error: conflicting types for `foo'
+			gchar **fields = g_strsplit(string, ":", 3);
 			gchar *end = NULL;
+			gchar *path;
+			gchar *filename;
 
-			// skip the colon, but only if it was found
-			if (colon != NULL) colon++;
-			else return;
+			// parse the line
+			if (g_strv_length(fields) < 3 || fields[0] == NULL || fields[1] == NULL)
+			{
+				g_strfreev(fields);
+				return;
+			}
 
-			line = strtol(colon, &end, 10);
+			/// FIXME this is C99
+			line = strtol(fields[1], &end, 10);
 
 			// if the line could not be read, line is 0 and an error occurred, so we leave
-			if (colon == end)
+			if (fields[1] == end)
+			{
+				g_strfreev(fields);
 				return;
+			}
 
+			// get the basename of the built file to get the path to look for other files
+			path = g_path_get_dirname(doc_list[app->cur_idx].file_name);
+			filename = g_strconcat(path, G_DIR_SEPARATOR_S, fields[0], NULL);
+
+			// use document_open_file to find an already opened file, or to open it in place
+			idx_of_error_file = document_open_file(-1, filename, 0, FALSE, NULL);
+
+			g_free(path);
+			g_free(filename);
+
+			if (idx_of_error_file == -1 || ! doc_list[idx_of_error_file].is_valid)
+			{
+				g_strfreev(fields);
+				return;
+			}
+
 			break;
 		}
-		// the error output of python, perl and php -l on errors euals in "line xx", so they are "compatible"
+		/// TODO parse also the file where the error occurred like above
+		// the error output of python, perl and php -l on errors equals in "line xx", so they
+		// are "compatible"
 		case GEANY_FILETYPES_PHP:
 		case GEANY_FILETYPES_PERL:
 		case GEANY_FILETYPES_TCL:
@@ -2344,22 +2376,49 @@
 				if (space == end)
 					return;
 			}
+			idx_of_error_file = app->cur_idx;
 			break;
 		}
 		case GEANY_FILETYPES_PASCAL:
 		{	// bandit.pas(149,3) Fatal: Syntax error, ";" expected but "ELSE" found
-			gchar *space = strchr(string, '(');
+			// still untested with other files than the opened
+			gchar **fields = g_strsplit(string, "(", 2);
 			gchar *end = NULL;
+			gchar *path;
+			gchar *filename;
 
-			if (space == NULL) return;
-			space++;
+			// parse the line
+			if (g_strv_length(fields) < 2 || fields[0] == NULL || fields[1] == NULL)
+			{
+				g_strfreev(fields);
+				return;
+			}
 
-			line = strtol(space, &end, 10);
+			line = strtol(fields[1], &end, 10);
 
 			// if the line could not be read, line is 0 and an error occurred, so we leave
-			if (space == end)
+			if (fields[1] == end)
+			{
+				g_strfreev(fields);
 				return;
+			}
 
+			// get the basename of the built file to get the path to look for other files
+			path = g_path_get_dirname(doc_list[app->cur_idx].file_name);
+			filename = g_strconcat(path, G_DIR_SEPARATOR_S, fields[0], NULL);
+
+			// use document_open_file to find an already opened file, or to open it in place
+			idx_of_error_file = document_open_file(-1, filename, 0, FALSE, NULL);
+
+			g_free(path);
+			g_free(filename);
+
+			if (idx_of_error_file == -1 || ! doc_list[idx_of_error_file].is_valid)
+			{
+				g_strfreev(fields);
+				return;
+			}
+
 			break;
 		}
 	}
@@ -2367,12 +2426,12 @@
 	// finally jump to the line (and file)
 	if (line != -1)
 	{
-		if (idx != app->cur_idx)
+		if (idx != idx_of_error_file)
 		{
 			gtk_notebook_set_current_page(GTK_NOTEBOOK(app->notebook),
 									gtk_notebook_page_num(GTK_NOTEBOOK(app->notebook),
-									GTK_WIDGET(doc_list[app->cur_idx].sci)));
+									GTK_WIDGET(doc_list[idx_of_error_file].sci)));
 		}
-		utils_goto_line(app->cur_idx, line);
+		utils_goto_line(idx_of_error_file, line);
 	}
 }


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Commits mailing list