[anjuta] am-project: Remove unused variables in Makefile.am



commit 8ff9450558c7a2bcd5676f6cfc68d6822a35dd30
Author: Sébastien Granjoux <seb sfo free fr>
Date:   Sun Jan 30 22:12:56 2011 +0100

    am-project: Remove unused variables in Makefile.am

 libanjuta/anjuta-token-list.c           |   56 ++++++++++++++--------
 libanjuta/anjuta-token-list.h           |    2 +-
 plugins/am-project/am-writer.c          |   58 +++++++++++++++--------
 plugins/am-project/projectparser.c      |    4 +-
 plugins/am-project/tests/data_target.at |    6 ++-
 plugins/am-project/tests/group.at       |    4 +-
 plugins/am-project/tests/source.at      |   14 +++--
 plugins/am-project/tests/target.at      |   78 ++++++++++++++++++++++++++++--
 8 files changed, 164 insertions(+), 58 deletions(-)
---
diff --git a/libanjuta/anjuta-token-list.c b/libanjuta/anjuta-token-list.c
index 120bc18..0b96adc 100644
--- a/libanjuta/anjuta-token-list.c
+++ b/libanjuta/anjuta-token-list.c
@@ -647,6 +647,14 @@ anjuta_token_remove_word (AnjutaToken *token)
 	return next;
 }
 
+/**
+ * anjuta_token_remove_list:
+ * @token: a #AnjutaToken a list element
+ *
+ * Remove a complete list of token.
+ *
+ * Return value: A #AnjutaToken representing the following token
+ */
 AnjutaToken *
 anjuta_token_remove_list (AnjutaToken *token)
 {
@@ -658,41 +666,49 @@ anjuta_token_remove_list (AnjutaToken *token)
 	anjuta_token_set_flags (list, ANJUTA_TOKEN_REMOVED);
 
 	prev = anjuta_token_previous_item (list);
-	if (anjuta_token_get_type (prev) == ANJUTA_TOKEN_EOL)
+	if (prev != NULL)
 	{
-		/* Remove line above if empty */
-		if (anjuta_token_get_type (anjuta_token_previous_item (prev)) == ANJUTA_TOKEN_EOL)
+		if (anjuta_token_get_type (prev) == ANJUTA_TOKEN_EOL)
 		{
-			anjuta_token_set_flags (prev, ANJUTA_TOKEN_REMOVED);
+			/* Remove line above if empty */
+			AnjutaToken *prev_prev = anjuta_token_previous_item (prev);
+		
+			if ((prev_prev == NULL) || (anjuta_token_get_type (prev_prev) == ANJUTA_TOKEN_EOL) || (anjuta_token_get_type (prev_prev) == ANJUTA_TOKEN_COMMENT))
+			{
+				anjuta_token_set_flags (prev, ANJUTA_TOKEN_REMOVED);
+			}
 		}
-	}
-	else if (anjuta_token_get_type (prev) == ANJUTA_TOKEN_COMMENT)
-	{
-		/* Remove comment above if there is an empty line after it */
-		do
+		else if (anjuta_token_get_type (prev) == ANJUTA_TOKEN_COMMENT)
 		{
-			prev = anjuta_token_previous_item (prev);
-		}
-		while ((prev != NULL) && (anjuta_token_get_type (prev) == ANJUTA_TOKEN_COMMENT));
-
-		if ((prev != NULL) && (anjuta_token_get_type (prev) == ANJUTA_TOKEN_EOL))
-		{
-			prev = list;
+			/* Remove comment above if there is an empty line after it */
 			do
 			{
-				anjuta_token_set_flags (prev, ANJUTA_TOKEN_REMOVED);
 				prev = anjuta_token_previous_item (prev);
 			}
 			while ((prev != NULL) && (anjuta_token_get_type (prev) == ANJUTA_TOKEN_COMMENT));
+
+			if ((prev != NULL) && (anjuta_token_get_type (prev) == ANJUTA_TOKEN_EOL))
+			{
+				prev = list;
+				do
+				{
+					anjuta_token_set_flags (prev, ANJUTA_TOKEN_REMOVED);
+					prev = anjuta_token_previous_item (prev);
+				}
+				while ((prev != NULL) && (anjuta_token_get_type (prev) == ANJUTA_TOKEN_COMMENT));
+			}
 		}
 	}
 	
 	next = anjuta_token_next_item (list);
-	if (anjuta_token_get_type (next) == ANJUTA_TOKEN_EOL)
+	if (next != NULL)
 	{
-		anjuta_token_set_flags (next, ANJUTA_TOKEN_REMOVED);
+		if (anjuta_token_get_type (next) == ANJUTA_TOKEN_EOL)
+		{
+			anjuta_token_set_flags (next, ANJUTA_TOKEN_REMOVED);
+		}
+		next = anjuta_token_next_item (next);
 	}
-	next = anjuta_token_next_item (next);
 	
 	return next;
 }
diff --git a/libanjuta/anjuta-token-list.h b/libanjuta/anjuta-token-list.h
index 87b260f..05bff78 100644
--- a/libanjuta/anjuta-token-list.h
+++ b/libanjuta/anjuta-token-list.h
@@ -53,7 +53,7 @@ AnjutaToken *anjuta_token_replace_nth_word (AnjutaToken *list, guint n, AnjutaTo
 AnjutaToken *anjuta_token_insert_word_before (AnjutaToken *list, AnjutaToken *sibling, AnjutaToken *baby);
 AnjutaToken *anjuta_token_insert_word_after (AnjutaToken *list, AnjutaToken *sibling, AnjutaToken *baby);
 AnjutaToken *anjuta_token_remove_word (AnjutaToken *token);
-AnjutaToken *anjuta_token_remove_list (AnjutaToken *name);
+AnjutaToken *anjuta_token_remove_list (AnjutaToken *token);
 
 AnjutaToken *anjuta_token_insert_token_list (gboolean after, AnjutaToken *list,...);
 AnjutaToken *anjuta_token_find_type (AnjutaToken *list, gint flags, AnjutaTokenType* types);
diff --git a/plugins/am-project/am-writer.c b/plugins/am-project/am-writer.c
index ca0ae28..1fd10e4 100644
--- a/plugins/am-project/am-writer.c
+++ b/plugins/am-project/am-writer.c
@@ -309,6 +309,7 @@ amp_group_node_delete_token (AmpProject  *project, AmpGroupNode *group, GError *
 		AnjutaToken *token = (AnjutaToken *)item->data;
 		AnjutaToken *args;
 		AnjutaTokenStyle *style;
+		AnjutaToken *list;
 
 		args = anjuta_token_list (token);
 
@@ -317,10 +318,16 @@ amp_group_node_delete_token (AmpProject  *project, AmpGroupNode *group, GError *
 		anjuta_token_style_update (style, args);
 		
 		anjuta_token_remove_word (token);
-		
 		anjuta_token_style_format (style, args);
 		anjuta_token_style_free (style);
 
+		/* Remove whole variable if empty */
+		list = anjuta_token_list (token);
+		if (anjuta_token_first_word (list) == NULL)
+		{
+			anjuta_token_remove_list (list);
+		}
+		
 		amp_group_node_update_makefile (AMP_GROUP_NODE (parent), args);
 	}
 
@@ -387,12 +394,15 @@ amp_project_write_target (AmpGroupNode *group, gint type, const gchar *name, gbo
 		pos = sibling;
 	}
 
-	token = anjuta_token_new_string (ANJUTA_TOKEN_EOL | ANJUTA_TOKEN_ADDED, "\n");
-	anjuta_token_insert_after (pos, token);
-	amp_group_node_update_makefile (group, token);
-	pos = token;
+	pos = anjuta_token_insert_token_list (after, pos,
+		    ANJUTA_TOKEN_EOL, "\n",
+		    NULL);
+	pos = anjuta_token_insert_token_list (after, pos,
+		    ANJUTA_TOKEN_EOL, "\n",
+		    NULL);
+	amp_group_node_update_makefile (group, pos);
 	
-	token = anjuta_token_insert_token_list (after, pos,
+	token = anjuta_token_insert_token_list (FALSE, pos,
 	    		ANJUTA_TOKEN_LIST, NULL,
 	    		type, name,
 	    		ANJUTA_TOKEN_SPACE, " ",
@@ -574,6 +584,7 @@ amp_target_node_delete_token (AmpProject  *project, AmpTargetNode *target, GErro
 	{
 		AnjutaToken *token = (AnjutaToken *)item->data;
 		AnjutaToken *args;
+		AnjutaToken *list;
 		AnjutaTokenStyle *style;
 
 		args = anjuta_token_list (token);
@@ -583,10 +594,16 @@ amp_target_node_delete_token (AmpProject  *project, AmpTargetNode *target, GErro
 		anjuta_token_style_update (style, args);
 		
 		anjuta_token_remove_word (token);
-		
 		anjuta_token_style_format (style, args);
 		anjuta_token_style_free (style);
 
+		/* Remove whole variable if empty */
+		list = anjuta_token_list (token);
+		if (anjuta_token_first_word (list) == NULL)
+		{
+			anjuta_token_remove_list (list);
+		}
+
 		amp_group_node_update_makefile (parent, args);
 	}
 
@@ -629,21 +646,17 @@ amp_project_write_source_list (AmpGroupNode *group, const gchar *name, gboolean
 		{
 			pos = token;
 		}
-		else
-		{
-			pos = anjuta_token_insert_token_list (after, pos,
-			    ANJUTA_TOKEN_EOL, "\n",
-			    NULL);
-			amp_group_node_update_makefile (group, pos);
-		}
 	}
-	
+
+	pos = anjuta_token_insert_token_list (after, pos,
+		    ANJUTA_TOKEN_EOL, "\n",
+		    NULL);
 	pos = anjuta_token_insert_token_list (after, pos,
 		    ANJUTA_TOKEN_EOL, "\n",
 		    NULL);
 	amp_group_node_update_makefile (group, pos);
 	
-	token = anjuta_token_insert_token_list (after, pos,
+	token = anjuta_token_insert_token_list (FALSE, pos,
 	    		ANJUTA_TOKEN_LIST, NULL,
 	    		ANJUTA_TOKEN_NAME, name,
 	    		ANJUTA_TOKEN_SPACE, " ",
@@ -766,7 +779,7 @@ amp_source_node_create_token (AmpProject  *project, AmpSourceNode *source, GErro
 		/* Try to use the same style than the current target list */
 		anjuta_token_style_format (style, args);
 		anjuta_token_style_free (style);
-		
+
 		amp_group_node_update_makefile (group, token);
 		
 		amp_source_node_add_token (source, token);
@@ -794,18 +807,25 @@ amp_source_node_delete_token (AmpProject  *project, AmpSourceNode *source, GErro
 	{
 		AnjutaToken *args;
 		AnjutaTokenStyle *style;
+		AnjutaToken *list;
 
 		args = anjuta_token_list (token);
 
 		/* Try to use the same style than the current target list */
 		style = anjuta_token_style_new_from_base (project->am_space_list);
 		anjuta_token_style_update (style, args);
-		
+
 		anjuta_token_remove_word (token);
-		
 		anjuta_token_style_format (style, args);
 		anjuta_token_style_free (style);
 
+		/* Remove whole variable if empty */
+		list = anjuta_token_list (token);
+		if (anjuta_token_first_word (list) == NULL)
+		{
+			anjuta_token_remove_list (list);
+		}
+		
 		amp_group_node_update_makefile (AMP_GROUP_NODE (group), args);
 	}
 
diff --git a/plugins/am-project/projectparser.c b/plugins/am-project/projectparser.c
index 05c3e72..4d84e55 100644
--- a/plugins/am-project/projectparser.c
+++ b/plugins/am-project/projectparser.c
@@ -686,7 +686,9 @@ main(int argc, char *argv[])
 				item = get_project_property (project, node, command[2]);
 				if (item != NULL)
 				{
-					ianjuta_project_set_property (project, node, item, command[3], NULL);
+					gchar *value = g_shell_unquote (command[3], NULL);
+					ianjuta_project_set_property (project, node, item, value, NULL);
+					g_free (value);
 				}
 			}
 			command += 3;
diff --git a/plugins/am-project/tests/data_target.at b/plugins/am-project/tests/data_target.at
index 2376da0..c2b14c1 100644
--- a/plugins/am-project/tests/data_target.at
+++ b/plugins/am-project/tests/data_target.at
@@ -79,7 +79,8 @@ AT_DATA([reference],
 target1dir = $(target_dir)
 target1_DATA = data1.txt
 
-data_DATA = data4.txt \
+data_DATA = \
+	data4.txt \
 	data5.txt
 ]])
 AT_PARSER_CHECK([load data1 \
@@ -107,7 +108,8 @@ AT_DATA([reference],
 [[## Process this file with automake to produce Makefile.in
 
 
-data_DATA = data4.txt \
+data_DATA = \
+	data4.txt \
 	data5.txt
 ]])
 AT_PARSER_CHECK([load data2 \
diff --git a/plugins/am-project/tests/group.at b/plugins/am-project/tests/group.at
index 428d935..05313fd 100644
--- a/plugins/am-project/tests/group.at
+++ b/plugins/am-project/tests/group.at
@@ -98,9 +98,7 @@ AT_DATA([expect],
 [[    GROUP (0): empty4
 ]])
 AT_DATA([reference.am],
-[[SUBDIRS = \ 
-
-
+[[ 
 ]])
 AT_DATA([reference.ac],
 [[AC_CONFIG_FILES(Makefile)
diff --git a/plugins/am-project/tests/source.at b/plugins/am-project/tests/source.at
index 3240f89..8d712c7 100644
--- a/plugins/am-project/tests/source.at
+++ b/plugins/am-project/tests/source.at
@@ -20,7 +20,8 @@ AT_DATA([reference],
 [[
 bin_PROGRAMS = target1
 
-target1_SOURCES = source1
+target1_SOURCES = \
+	source1
 ]])
 AT_PARSER_CHECK([load empty \
 		 move empty1 \
@@ -45,7 +46,8 @@ AT_DATA([reference],
 [[
 bin_PROGRAMS = target1
 
-target1_SOURCES = source1 \
+target1_SOURCES = \
+	source1 \
 	source2
 ]])
 AT_PARSER_CHECK([load empty1 \
@@ -70,7 +72,8 @@ AT_DATA([reference],
 [[
 bin_PROGRAMS = target1
 
-target1_SOURCES =	source2
+target1_SOURCES = \
+	source2
 ]])
 AT_PARSER_CHECK([load empty2 \
 		 move empty3 \
@@ -93,8 +96,6 @@ AT_DATA([expect],
 AT_DATA([reference],
 [[
 bin_PROGRAMS = target1
-
-target1_SOURCES =
 ]])
 AT_PARSER_CHECK([load empty3 \
 		 move empty4 \
@@ -118,7 +119,8 @@ AT_DATA([reference],
 [[
 bin_PROGRAMS = target1
 
-target1_SOURCES = source1
+target1_SOURCES = \
+	source1
 ]])
 AT_PARSER_CHECK([load empty4 \
 		 move empty5 \
diff --git a/plugins/am-project/tests/target.at b/plugins/am-project/tests/target.at
index 306aebd..d6f7d82 100644
--- a/plugins/am-project/tests/target.at
+++ b/plugins/am-project/tests/target.at
@@ -16,7 +16,8 @@ AT_DATA([expect],
 AT_DATA([reference],
 [[## Process this file with automake to produce Makefile.in
 
-bin_PROGRAMS = target1
+bin_PROGRAMS = \
+	target1
 ]])
 AT_PARSER_CHECK([load empty \
 		 move empty1 \
@@ -40,7 +41,8 @@ AT_DATA([expect],
 AT_DATA([reference],
 [[## Process this file with automake to produce Makefile.in
 
-bin_PROGRAMS = target1 \
+bin_PROGRAMS = \
+	target1 \
 	target2
 ]])
 AT_PARSER_CHECK([load empty1 \
@@ -63,7 +65,8 @@ AT_DATA([expect],
 AT_DATA([reference],
 [[## Process this file with automake to produce Makefile.in
 
-bin_PROGRAMS = target2
+bin_PROGRAMS = \
+	target2
 ]])
 AT_PARSER_CHECK([load empty2 \
 		 move empty3 \
@@ -82,8 +85,6 @@ AT_DATA([expect],
 ]])
 AT_DATA([reference],
 [[## Process this file with automake to produce Makefile.in
-
-bin_PROGRAMS =
 ]])
 AT_PARSER_CHECK([load empty3 \
 		 move empty4 \
@@ -106,7 +107,8 @@ AT_DATA([expect],
 AT_DATA([reference],
 [[## Process this file with automake to produce Makefile.in
 
-bin_PROGRAMS = target1
+bin_PROGRAMS = \
+	target1
 ]])
 AT_PARSER_CHECK([load empty4 \
 		 move empty5 \
@@ -120,4 +122,68 @@ AT_CHECK([diff -b output expect])
 
 
 
+AT_DATA([expect],
+[[    GROUP (0): empty6
+        TARGET (0:0): target1
+            PROPERTY (Installation directory): bindir
+            SOURCE (0:0:0): source1
+        TARGET (0:1): target2
+            PROPERTY (Installation directory): bindir
+]])
+AT_DATA([reference],
+[[## Process this file with automake to produce Makefile.in
+
+bin_PROGRAMS = \
+	target1 \
+	target2
+
+target1_SOURCES = \
+	source1
+]])
+AT_PARSER_CHECK([load empty5 \
+		 move empty6 \
+		 add source 0:0 source1 \
+		 add target 0 target2 prog \
+		 list \
+		 save])
+AT_CHECK([diff -b empty6/Makefile.am reference])
+AT_PARSER_CHECK([load empty6 \
+		 list])
+AT_CHECK([diff -b output expect])
+
+
+
+AT_DATA([expect],
+[[    GROUP (0): empty7
+        TARGET (0:0): target1
+            PROPERTY (Installation directory): bindir
+            SOURCE (0:0:0): source1
+        TARGET (0:1): target2
+            PROPERTY (Installation directory): bindir
+            PROPERTY (C compiler flags): -g
+]])
+AT_DATA([reference],
+[[## Process this file with automake to produce Makefile.in
+
+bin_PROGRAMS = \
+	target1 \
+	target2
+
+target1_SOURCES = \
+	source1
+
+target2_CFLAGS = -g
+]])
+AT_PARSER_CHECK([load empty6 \
+		 move empty7 \
+		 set 0:1 ccflags '\-g' \
+		 list \
+		 save])
+AT_CHECK([diff -b empty7/Makefile.am reference])
+AT_PARSER_CHECK([load empty7 \
+		 list])
+AT_CHECK([diff -b output expect])
+
+
+
 AT_CLEANUP



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