[anjuta] am-project: Define target type with a string identifier in projectparser



commit 8251b85dc696ff54bf2ef8342d6c7ae63055fba6
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sat Dec 25 21:42:14 2010 +0100

    am-project: Define target type with a string identifier in projectparser

 plugins/am-project/projectparser.c |   91 ++++++++++++++++++++----------------
 plugins/am-project/tests/target.at |    6 +-
 2 files changed, 54 insertions(+), 43 deletions(-)
---
diff --git a/plugins/am-project/projectparser.c b/plugins/am-project/projectparser.c
index 77a36ff..4a26274 100644
--- a/plugins/am-project/projectparser.c
+++ b/plugins/am-project/projectparser.c
@@ -334,32 +334,27 @@ get_file (AnjutaProjectNode *target, const char *id)
 	return g_file_resolve_relative_path (anjuta_project_node_get_file (group), id);
 }
 
-static AnjutaProjectNodeType
-get_target_type (IAnjutaProject *project, const char *id)
+static gint
+compare_id (const gchar *id, const gchar *name)
 {
-	AnjutaProjectNodeType type;
-	const GList *list;
-	const GList *item;
-	guint num = atoi (id);
-	
-	list = ianjuta_project_get_node_info (project, NULL);
-	type = 0;
-	for (item = list; item != NULL; item = g_list_next (item))
-	{
-		AnjutaProjectNodeInfo *info = (AnjutaProjectNodeInfo *)item->data;
+		const gchar *ptr;
+		gboolean next = FALSE;
+		gint miss = 0;
 
-		if ((info->type & ANJUTA_PROJECT_TYPE_MASK) == ANJUTA_PROJECT_TARGET)
+		for (ptr = name; *ptr != '\0'; ptr++)
 		{
-			if (num == 0)
-			{
-				type = info->type;
-				break;
-			}
-			num--;
+				if (!next && (*id != '\0') && (g_ascii_toupper (*ptr) == g_ascii_toupper (*id)))
+				{
+					id++;
+				}
+				else
+				{
+					miss++;
+					next = !g_ascii_isspace (*ptr);
+				}
 		}
-	}
 
-	return type;
+		return (*id == '\0') ? miss : -1;
 }
 
 static AnjutaProjectProperty *
@@ -371,26 +366,11 @@ get_project_property (IAnjutaProject *project, AnjutaProjectNode *parent, const
 
 	for (item = anjuta_project_node_get_native_properties (parent); item != NULL; item = g_list_next (item))
 	{
-		const gchar *name = ((AnjutaProjectProperty *)item->data)->name;
-		const gchar *ptr;
-		const gchar *iptr = id;
-		gboolean next = FALSE;
-		gint miss = 0;
+		gint miss;
 
-		for (ptr = name; *ptr != '\0'; ptr++)
-		{
-				if (!next && (*iptr != '\0') && (g_ascii_toupper (*ptr) == g_ascii_toupper (*iptr)))
-				{
-					iptr++;
-				}
-				else
-				{
-					miss++;
-					next = !g_ascii_isspace (*ptr);
-				}
-		}
-
-		if ((*iptr == '\0') && (miss < best))
+		miss = compare_id (id, ((AnjutaProjectProperty *)item->data)->name);
+		
+		if ((miss >= 0) && (miss < best))
 		{
 			best = miss;
 			prop =  ((AnjutaProjectProperty *)item->data);
@@ -400,6 +380,37 @@ get_project_property (IAnjutaProject *project, AnjutaProjectNode *parent, const
 	return prop;
 }
 
+static AnjutaProjectNodeType
+get_target_type (IAnjutaProject *project, const char *id)
+{
+	AnjutaProjectNodeType type;
+	const GList *list;
+	const GList *item;
+	gint best = G_MAXINT;
+	
+	list = ianjuta_project_get_node_info (project, NULL);
+	type = 0;
+	for (item = list; item != NULL; item = g_list_next (item))
+	{
+		AnjutaProjectNodeInfo *info = (AnjutaProjectNodeInfo *)item->data;
+
+		if ((info->type & ANJUTA_PROJECT_TYPE_MASK) == ANJUTA_PROJECT_TARGET)
+		{
+			gint miss;
+
+			miss = compare_id (id, info->name);
+
+			if ((miss >= 0) && (miss < best))
+			{
+				best = miss;
+				type = info->type;
+			}
+		}
+	}
+
+	return type;
+}
+
 static void
 amp_project_wait_ready (IAnjutaProject *project)
 {
diff --git a/plugins/am-project/tests/target.at b/plugins/am-project/tests/target.at
index 8542616..306aebd 100644
--- a/plugins/am-project/tests/target.at
+++ b/plugins/am-project/tests/target.at
@@ -20,7 +20,7 @@ bin_PROGRAMS = target1
 ]])
 AT_PARSER_CHECK([load empty \
 		 move empty1 \
-		 add target 0 target1 3 \
+		 add target 0 target1 prog \
 		 list \
 		 save])
 AT_CHECK([diff -b empty1/Makefile.am reference])
@@ -45,7 +45,7 @@ bin_PROGRAMS = target1 \
 ]])
 AT_PARSER_CHECK([load empty1 \
 		 move empty2 \
-		 add target 0 target2 3 after 0:0\
+		 add target 0 target2 prog after 0:0\
 		 list \
 		 save])
 AT_CHECK([diff -b empty2/Makefile.am reference])
@@ -110,7 +110,7 @@ bin_PROGRAMS = target1
 ]])
 AT_PARSER_CHECK([load empty4 \
 		 move empty5 \
-		 add target 0 target1 3 \
+		 add target 0 target1 prog \
 		 list \
 		 save])
 AT_CHECK([diff -b empty5/Makefile.am reference])



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]