示例#1
0
文件: amp-group.c 项目: GNOME/anjuta
void
amp_group_node_update_variable (AmpGroupNode *group, AnjutaToken *variable)
{
	AnjutaToken *arg;
	char *name = NULL;
	AnjutaToken *value = NULL;
	AmpVariable *var;

	arg = anjuta_token_first_item (variable);
	name = g_strstrip (anjuta_token_evaluate (arg));
	value = anjuta_token_last_item (variable);

	var = (AmpVariable *)g_hash_table_lookup (group->variables, name);
	if (var != NULL)
	{
		var->value = value;
	}
	else
	{
		var = amp_variable_new (name, 0, value);
		g_hash_table_insert (group->variables, var->name, var);
	}

	if (name) g_free (name);
}
示例#2
0
void
mkp_project_update_variable (MkpProject *project, AnjutaToken *variable)
{
	AnjutaToken *arg;
	char *name = NULL;
	MakeTokenType assign = 0;
	AnjutaToken *value = NULL;

	//fprintf(stdout, "update variable");
	//anjuta_token_dump (variable);

	arg = anjuta_token_first_item (variable);
	name = g_strstrip (anjuta_token_evaluate (arg));
	arg = anjuta_token_next_item (arg);

	//g_message ("new variable %s", name);
	switch (anjuta_token_get_type (arg))
	{
	case MK_TOKEN_EQUAL:
	case MK_TOKEN_IMMEDIATE_EQUAL:
	case MK_TOKEN_CONDITIONAL_EQUAL:
	case MK_TOKEN_APPEND:
		assign = anjuta_token_get_type (arg);
		break;
	default:
		break;
	}

	value = anjuta_token_next_item (arg);

	if (assign != 0)
	{
		MkpVariable *var;

		//g_message ("assign %d name %s value %s\n", assign, name, anjuta_token_evaluate (value));
		var = (MkpVariable *)g_hash_table_lookup (project->variables, name);
		if (var != NULL)
		{
			var->assign = assign;
			var->value = value;
		}
		else
		{
			var = mkp_variable_new (name, assign, value);
			g_hash_table_insert (project->variables, var->name, var);
		}

	}

	//g_message ("update variable %s", name);

	if (name) g_free (name);
}
示例#3
0
文件: amp-module.c 项目: GNOME/anjuta
void
amp_module_node_add_token (AmpModuleNode *module, AnjutaToken *token)
{
	gchar *name;

	module->module = token;
	name = anjuta_token_evaluate (anjuta_token_first_item (token));
	if (name != NULL)
	{
		g_free (module->base.name);
		module->base.name = name;
	}
}
示例#4
0
void
anjuta_token_style_update (AnjutaTokenStyle *style, AnjutaToken *list)
{
	AnjutaToken *token;
	AnjutaToken *next_token;
	guint prev = 0;
	guint next = 0;
	guint line_width = 0;
	guint sep_count = 0;

	/* Initialize first line width */
	for (token = list; token != NULL; token = anjuta_token_previous (token))
	{
		gchar *value;
		gchar *eol = NULL;
		gsize len = 0;

		value = anjuta_token_evaluate (token);
		if (value != NULL)
		{
			eol = strrchr (value, '\n');
			len = strlen (value);
			g_free (value);
		}

		if (eol != NULL)
		{
			line_width = value + len - eol;
			break;
		}

		line_width += len;
	}

	for (token = anjuta_token_first_item (list); token != NULL; token = next_token)
	{
		gchar *value = NULL;
		const gchar *eol;
		gsize len;
		gint type;

		next_token = anjuta_token_next_item (token);
		type = anjuta_token_get_type (token);
		next = next_token == NULL ? 0 : anjuta_token_get_type (next_token);

		value = anjuta_token_evaluate (token);
		if (value == NULL) continue;

		len = strlen (value);
		eol = strrchr (value, '\n');
		if (eol != NULL) len -= (eol - value);
		g_free (value);

		line_width += len;

		switch (type)
		{
			case ANJUTA_TOKEN_START:
			case ANJUTA_TOKEN_LAST:
			case ANJUTA_TOKEN_NEXT:
				break;
			default:
				if (eol != NULL)
				{
					line_width = len;
					sep_count = 0;
				}
				continue;
		}

		value = anjuta_token_evaluate (token);
		anjuta_token_style_insert_separator_between (style, 0, type, value);
		if (type == ANJUTA_TOKEN_NEXT)
		{
			anjuta_token_style_insert_separator_between (style, next, prev, value);
			anjuta_token_style_insert_separator_between (style, next, ANJUTA_TOKEN_ANY, value);
			anjuta_token_style_insert_separator_between (style, ANJUTA_TOKEN_ANY, prev, value);
		}
		g_free (value);

		if (eol == NULL)
		{
			sep_count++;
		}
		else
		{
			if ((sep_count > 1) && (line_width > style->max_width))
			{
				style->max_width = line_width;
			}
			sep_count = 0;
			line_width = len;
		}
	}
}
示例#5
0
文件: mk-rule.c 项目: kyoushuu/anjuta
void
mkp_project_enumerate_targets (MkpProject *project, AnjutaProjectNode *parent)
{
	GHashTableIter iter;
	gpointer key;
	MkpRule *rule;

	/* Check pattern rules */
	for (g_hash_table_iter_init (&iter, project->rules); g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&rule);)
	{
		if (rule->phony) continue;

		if (g_hash_table_lookup (project->suffix, rule->name))
		{
			/* Single suffix rule */
			rule->pattern = TRUE;
			rule->part = NULL;
		}
		else
		{
			GString *pattern = g_string_sized_new (16);
			GList *suffix;
			GList *src;

			/* Check double suffix rule */
			suffix = g_hash_table_get_keys (project->suffix);

			for (src = g_list_first (suffix); src != NULL; src = g_list_next (src))
			{
				GList *obj;

				for (obj = g_list_first (suffix); obj != NULL; obj = g_list_next (obj))
				{
					g_string_assign (pattern, src->data);
					g_string_append (pattern, obj->data);

					if (strcmp (pattern->str, rule->name) == 0)
					{
						rule->pattern = TRUE;
						rule->part = rule->name + strlen (src->data);
						break;
					}
				}
				if (rule->pattern) break;
			}

			g_string_free (pattern, TRUE);
			g_list_free (suffix);
		}
	}

	/* Create new target */
	for (g_hash_table_iter_init (&iter, project->rules); g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&rule);)
	{
		MkpTarget *target;
		AnjutaToken *prerequisite;
		AnjutaToken *arg;

		//g_message ("rule =%s=", rule->name);
		if (rule->phony || rule->pattern) continue;

		/* Create target */
		target = MKP_TARGET(mkp_target_new (rule->name, ANJUTA_PROJECT_UNKNOWN));
		mkp_target_add_token (target, rule->rule);
		anjuta_project_node_append (parent, ANJUTA_PROJECT_NODE(target));

		/* Get prerequisite */
		prerequisite = anjuta_token_first_word (rule->rule);
		if (prerequisite != NULL) prerequisite = anjuta_token_next_word (prerequisite);
		if (prerequisite != NULL) prerequisite = anjuta_token_next_word (prerequisite);

		/* Add prerequisite */
		for (arg = anjuta_token_first_word (prerequisite); arg != NULL; arg = anjuta_token_next_word (arg))
		{
			AnjutaProjectNode *node;
			gchar *name;
			GList *dependencies;

			name = anjuta_token_evaluate (arg);
			if (name != NULL)
			{
				name = g_strstrip (name);
				dependencies = mkp_project_find_dependencies (project, name, parent, 0);
				if (dependencies == NULL)
				{
					/* Add only one object node */
					node = mkp_object_new (name);
					node->type = ANJUTA_PROJECT_OBJECT | ANJUTA_PROJECT_PROJECT;
					anjuta_project_node_append (ANJUTA_PROJECT_NODE(target), ANJUTA_PROJECT_NODE(node));
					g_free (name);
				}
				else
				{
					GFile *src_file;
					gchar *name;

					AnjutaProjectNode *parent = (AnjutaProjectNode *)target;
					while (g_list_next (dependencies) != NULL)
					{
						/* Create object nodes */
						name = (gchar *)dependencies->data;
						node = mkp_object_new (name);
						node->type = ANJUTA_PROJECT_OBJECT | ANJUTA_PROJECT_PROJECT;
						anjuta_project_node_append (parent, node);
						g_free (name);
						parent = node;
						dependencies = g_list_delete_link (dependencies, dependencies);
					}

					/* Create source node */
					name = (gchar *)dependencies->data;
					src_file = g_file_get_child (project->root_file, name);
					node = mkp_source_new (src_file);
					node->type = ANJUTA_PROJECT_SOURCE | ANJUTA_PROJECT_PROJECT;
					g_object_unref (src_file);
					anjuta_project_node_append (parent, node);
					g_free (name);
					g_list_free (dependencies);
				}
			}
		}
	}
}
示例#6
0
文件: mk-rule.c 项目: kyoushuu/anjuta
void
mkp_project_add_rule (MkpProject *project, AnjutaToken *group)
{
	AnjutaToken *targ;
	AnjutaToken *dep;
	AnjutaToken *arg;
	gboolean double_colon = FALSE;

	//fprintf(stdout, "add rule\n");
	//anjuta_token_dump (group);

	targ = anjuta_token_first_item (group);
	arg = anjuta_token_next_word (targ);
	if (anjuta_token_get_type (arg) == MK_TOKEN_DOUBLE_COLON) double_colon = TRUE;
	dep = anjuta_token_next_word (arg);
	for (arg = anjuta_token_first_word (targ); arg != NULL; arg = anjuta_token_next_word (arg))
	{
		AnjutaToken *src = NULL;
		gchar *target = NULL;
		gboolean order = FALSE;
		gboolean no_token = TRUE;
		MkpRule *rule = NULL;

		switch (anjuta_token_get_type (arg))
		{
		case MK_TOKEN__PHONY:
			for (src = anjuta_token_first_word (dep); src != NULL; src = anjuta_token_next_word (src))
			{
				if (anjuta_token_get_type (src) != MK_TOKEN_ORDER)
				{
					target = anjuta_token_evaluate (src);

					rule = g_hash_table_lookup (project->rules, target);
					if (rule == NULL)
					{
						rule = mkp_rule_new (target, NULL);
						g_hash_table_insert (project->rules, rule->name, rule);
					}
					rule->phony = TRUE;

					//g_message ("    with target %s", target);
					if (target != NULL) g_free (target);
				}
			}
			break;
		case MK_TOKEN__SUFFIXES:
			for (src = anjuta_token_first_word (dep); src != NULL; src = anjuta_token_next_word (src))
			{
				if (anjuta_token_get_type (src) != MK_TOKEN_ORDER)
				{
					gchar *suffix;

					suffix = anjuta_token_evaluate (src);
					/* The pointer value must only be not NULL, it does not matter if it is
	 				 * invalid */
					g_hash_table_replace (project->suffix, suffix, suffix);
					//g_message ("    with suffix %s", suffix);
					no_token = FALSE;
				}
			}
			if (no_token == TRUE)
			{
				/* Clear all suffix */
				g_hash_table_remove_all (project->suffix);
			}
			break;
		case MK_TOKEN__DEFAULT:
		case MK_TOKEN__PRECIOUS:
		case MK_TOKEN__INTERMEDIATE:
		case MK_TOKEN__SECONDARY:
		case MK_TOKEN__SECONDEXPANSION:
		case MK_TOKEN__DELETE_ON_ERROR:
		case MK_TOKEN__IGNORE:
		case MK_TOKEN__LOW_RESOLUTION_TIME:
		case MK_TOKEN__SILENT:
		case MK_TOKEN__EXPORT_ALL_VARIABLES:
		case MK_TOKEN__NOTPARALLEL:
			/* Do nothing with these targets, just ignore them */
			break;
		default:
			target = g_strstrip (anjuta_token_evaluate (arg));
			if (*target == '\0') break;
			//g_message ("add rule =%s=", target);

			rule = g_hash_table_lookup (project->rules, target);
			if (rule == NULL)
			{
				rule = mkp_rule_new (target, group);
				g_hash_table_insert (project->rules, rule->name, rule);
			}
			else
			{
				rule->rule = group;
			}

			for (src = anjuta_token_first_word (dep); src != NULL; src = anjuta_token_next_word (src))
			{
				gchar *src_name = anjuta_token_evaluate (src);

				if (src_name != NULL)
				{
					//g_message ("    with source %s", src_name);
					if (anjuta_token_get_type (src) == MK_TOKEN_ORDER)
					{
						order = TRUE;
					}
					rule->prerequisite = g_list_prepend (rule->prerequisite, src_name);
				}
			}

			if (target != NULL) g_free (target);
		}
	}
}
示例#7
0
文件: am-writer.c 项目: GNOME/anjuta
gboolean
amp_target_node_delete_token (AmpProject  *project, AmpTargetNode *target, GList *list, GError **error)
{
	GList *item;
	GList *removed_dir = NULL;
	AmpGroupNode *parent;

	/* Get parent group */
	parent = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP));

	/* Remove all associated token */
	for (item = list; item != NULL;	 item = g_list_next (item))
	{
		AnjutaToken *token = (AnjutaToken *)item->data;
		AnjutaTokenStyle *style;
		AnjutaToken *list;

		switch (anjuta_token_get_type (token))
		{
		case ANJUTA_TOKEN_ARGUMENT:

			list = 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, list);

			anjuta_token_remove_word (token);
			anjuta_token_style_format (style, list);
			anjuta_token_style_free (style);

			/* Remove whole variable if empty */
			if (anjuta_token_first_word (list) == NULL)
			{
				AnjutaToken *variable = anjuta_token_list (list);
				gchar *value;
				gint flags;
				gchar *install = NULL;

				value = anjuta_token_evaluate (anjuta_token_first_word (variable));
				split_automake_variable (value, &flags, &install, NULL);

				if (install != NULL)
				{
					/* Mark all removed directory, normally only one */
					removed_dir = g_list_prepend (removed_dir, g_strdup (install));
				}
				g_free (value);
				anjuta_token_remove_list (variable);
			}

			amp_group_node_update_makefile (parent, list);

			break;
		case AM_TOKEN__SOURCES:
		case AM_TOKEN__DATA:
		case AM_TOKEN__HEADERS:
		case AM_TOKEN__LISP:
		case AM_TOKEN__MANS:
		case AM_TOKEN__PYTHON:
		case AM_TOKEN__JAVA:
		case AM_TOKEN__SCRIPTS:
		case AM_TOKEN__TEXINFOS:
        case AM_TOKEN_TARGET_LDFLAGS:
        case AM_TOKEN_TARGET_CPPFLAGS:
        case AM_TOKEN_TARGET_CFLAGS:
        case AM_TOKEN_TARGET_CXXFLAGS:
        case AM_TOKEN_TARGET_JAVACFLAGS:
        case AM_TOKEN_TARGET_VALAFLAGS:
        case AM_TOKEN_TARGET_FCFLAGS:
        case AM_TOKEN_TARGET_OBJCFLAGS:
        case AM_TOKEN_TARGET_LFLAGS:
        case AM_TOKEN_TARGET_YFLAGS:
        case AM_TOKEN_TARGET_DEPENDENCIES:
        case AM_TOKEN_TARGET_LIBADD:
        case AM_TOKEN_TARGET_LDADD:
			anjuta_token_remove_list (token);
			amp_group_node_update_makefile (parent, token);
			break;
		};
		amp_target_node_remove_token (target, token);
	}

	/* Check if we need to remove dir variable */
	for (item = removed_dir; item != NULL; item = g_list_next(item))
	{
		gchar* dir = (gchar *)item->data;
		GList *list;

		/* Check if dir is used in another target */
		for (list = amp_group_node_get_token (parent, AM_GROUP_TARGET); list != NULL; list = g_list_next (list))
		{
			AnjutaToken *target_list = (AnjutaToken *)list->data;
			gchar *value;
			gint flags;
			gchar *install = NULL;
			gboolean same;

			value = anjuta_token_evaluate (anjuta_token_first_word (target_list));
			/* value can be NULL if we have a list can has just been removed */
			if (value != NULL) split_automake_variable (value, &flags, &install, NULL);

			same = g_strcmp0 (install, dir) == 0;
			g_free (value);

			if (same)
			{
				/* directory use elsewhere */

				g_free (dir);
				dir = NULL;
				break;
			}
		}

		if (dir != NULL)
		{
			/* Directory is not used anymore, remove variable */
			gchar* install = g_strconcat (dir, "dir", NULL);

			for (list = anjuta_project_node_get_properties (ANJUTA_PROJECT_NODE(parent)); list != NULL; list = g_list_next (list))
			{
				AmpProperty *prop = (AmpProperty *)list->data;

				if ((((AmpPropertyInfo *)prop->base.info)->token_type == AM_TOKEN_DIR) &&
				    (g_strcmp0(prop->base.name, install) == 0))
				{
					AnjutaProjectProperty *new_prop;

					new_prop = amp_node_map_property_set (ANJUTA_PROJECT_NODE (parent), prop->base.info->id, prop->base.name, NULL);
					amp_project_update_am_property (project, ANJUTA_PROJECT_NODE (parent), new_prop);
				}
			}
			g_free (install);
			g_free (dir);
		}
	}
	g_list_free (removed_dir);


	return TRUE;
}
示例#8
0
文件: am-writer.c 项目: GNOME/anjuta
gboolean
amp_target_node_create_token (AmpProject  *project, AmpTargetNode *target, GError **error)
{
	AnjutaToken *args;
	AnjutaToken *var;
	AnjutaToken *prev;
	AmpNodeInfo *info;
	gchar *targetname;
	const gchar *name;
	GList *last;
	AnjutaProjectNode *sibling;
	AmpGroupNode *parent;
	gboolean after;

	/* Get parent target */
	parent = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP));

	info = (AmpNodeInfo *)amp_project_get_type_info (project, anjuta_project_node_get_full_type (ANJUTA_PROJECT_NODE (target)));
	name = anjuta_project_node_get_name (ANJUTA_PROJECT_NODE (target));

	/* Find a sibling if possible */
	after = TRUE;
	for (sibling = anjuta_project_node_prev_sibling (ANJUTA_PROJECT_NODE (target)); sibling != NULL; sibling = anjuta_project_node_prev_sibling (sibling))
	{
		if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_TARGET) break;
	}
	if (sibling == NULL)
	{
		after = FALSE;
		for (sibling = anjuta_project_node_next_sibling (ANJUTA_PROJECT_NODE (target)); sibling != NULL; sibling = anjuta_project_node_next_sibling (sibling))
		{
			if (anjuta_project_node_get_node_type (sibling) == ANJUTA_PROJECT_TARGET) break;
		}
	}
	if (sibling == NULL) after = TRUE;

	/* Add in Makefile.am */
	targetname = g_strconcat (amp_target_node_get_install_directory (target) != NULL ? amp_target_node_get_install_directory (target) : info->install, "_", info->prefix, NULL);

	// Get token corresponding to sibling and check if the target are compatible
	args = NULL;
	var = NULL;
	prev = NULL;
	if (sibling != NULL)
	{
		last = amp_target_node_get_token (AMP_TARGET_NODE (sibling), ANJUTA_TOKEN_ARGUMENT);

		if (last != NULL)
		{
			AnjutaToken *token = (AnjutaToken *)last->data;

			/* Check that the sibling is of the same kind */
			token = anjuta_token_list (token);
			if (token != NULL)
			{
				token = anjuta_token_list (token);
				var = token;
				if (token != NULL)
				{
					token = anjuta_token_first_item (token);
					if (token != NULL)
					{
						gchar *value;

						value = anjuta_token_evaluate (token);

						if ((value != NULL) && (strcmp (targetname, value) == 0))
						{
							g_free (value);
							prev = (AnjutaToken *)last->data;
							args = anjuta_token_list (prev);
						}
					}
				}
			}
		}
	}


	/* Check if a valid target variable is already defined */
	if (args == NULL)
	{
		for (last = amp_group_node_get_token (parent, AM_GROUP_TARGET); last != NULL; last = g_list_next (last))
		{
			gchar *value = anjuta_token_evaluate (anjuta_token_first_word ((AnjutaToken *)last->data));

			if ((value != NULL) && (strcmp (targetname, value) == 0))
			{
				g_free (value);
				args = anjuta_token_last_item ((AnjutaToken *)last->data);
				break;
			}
			g_free (value);
		}
	}


	if (args == NULL)
	{
		args = amp_project_write_target (parent, info->token, targetname, FALSE, NULL);
	}
	g_free (targetname);

	switch (anjuta_project_node_get_full_type (ANJUTA_PROJECT_NODE (target)) & ANJUTA_PROJECT_ID_MASK)
	{
	case ANJUTA_PROJECT_SHAREDLIB:
	case ANJUTA_PROJECT_STATICLIB:
	case ANJUTA_PROJECT_LT_MODULE:
	case ANJUTA_PROJECT_PROGRAM:
		amp_target_add_in_list (project, args, ANJUTA_PROJECT_NODE (target), after, prev);
		break;
	default:
		if (args != NULL)
		{
			amp_target_node_add_token (target, AM_TOKEN__SOURCES, args);
		}
		break;
	}

	return TRUE;
}
示例#9
0
文件: am-writer.c 项目: GNOME/anjuta
static AnjutaToken *
amp_property_rename_target (AmpProject *project, AnjutaProjectNode *node)
{
	AnjutaProjectNode *group;
	GList *infos;
	GList *item;
	GString *new_name;
	AmpNodeInfo *info;
	GList *list;
	AnjutaToken *update = NULL;
	AnjutaToken *existing_target_list;
	gboolean after;
	gchar *target_dir;

	g_return_val_if_fail (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_TARGET, NULL);

	group = anjuta_project_node_parent_type (node, ANJUTA_PROJECT_GROUP);

	/* Find all program properties */
	infos = NULL;
	for (item = anjuta_project_node_get_properties_info (node); item != NULL; item = g_list_next (item))
	{
		AmpPropertyInfo *info = (AmpPropertyInfo *)item->data;

		if (info->token_type == AM_TOKEN__PROGRAMS)
		{
			infos = g_list_insert_sorted (infos, info, compare_property_position);
		}
	}

	/* Create new name */
	new_name = g_string_new (NULL);
	for (item = infos; item != NULL; item = g_list_next (item))
	{
		AmpPropertyInfo *info = (AmpPropertyInfo *)item->data;
		AmpProperty *prop;

		/* Check if property is enabled by another property */
		if (info->link != NULL)
		{
			AnjutaProjectProperty *en_prop;

			en_prop = anjuta_project_node_get_property (node, info->link->id);

			if ((en_prop->value != NULL) && (*en_prop->value == '1')) continue;
		}

		prop = (AmpProperty *)anjuta_project_node_get_property (node, info->base.id);
		if ((prop == (AmpProperty *)info->base.default_value) || (g_strcmp0 (prop->base.value, info->base.default_value->value) == 0))
		{
			/* Default value, add only string properties */
			if (info->base.type == ANJUTA_PROJECT_PROPERTY_STRING)
			{
				g_string_append (new_name, info->suffix);
				g_string_append_c (new_name, '_');
			}
		}
		else
		{
			switch (info->base.type)
			{
			case ANJUTA_PROJECT_PROPERTY_STRING:
				if ((info->flags & AM_PROPERTY_DIRECTORY) &&
				    (strlen (prop->base.value) > 4) &&
				    (strcmp (prop->base.value + strlen (prop->base.value) - 3, "dir") == 0))
				{
					/* Remove "dir" suffix */
					g_string_append_len (new_name, prop->base.value, strlen (prop->base.value) - 3);
				}
				else
				{
					g_string_append (new_name, prop->base.value);
				}
				g_string_append_c (new_name, '_');
				break;
			case ANJUTA_PROJECT_PROPERTY_BOOLEAN:
				if ((prop->base.value != NULL) && (g_strcmp0 (prop->base.value, info->base.default_value->value) != 0))
				{
					g_string_append (new_name, info->suffix);
				}
				break;
			default:
				break;
			}
		}
	}

	info = (AmpNodeInfo *)amp_project_get_type_info (project, anjuta_project_node_get_full_type (node));
	g_string_append (new_name, info->prefix);

	if ((anjuta_project_node_get_full_type (node) & ANJUTA_PROJECT_ID_MASK) == ANJUTA_PROJECT_DATA)
	{
		list = amp_target_node_get_token (AMP_TARGET_NODE (node), AM_TOKEN__DATA);

		if ((list != NULL) && (list->data != NULL))
		{
			AnjutaToken *old_token;
			AnjutaToken *parent;

			parent = (AnjutaToken *)list->data;
			old_token = anjuta_token_first_word (parent);
			if (old_token != NULL)
			{
				AnjutaToken *token;
			
				
				token = anjuta_token_new_string (ANJUTA_TOKEN_ADDED, new_name->str);
				update = anjuta_token_insert_word_after (parent, old_token, token);
				anjuta_token_remove_word (old_token);
				update = parent;
			}
		}
	}
	else
	{
    	// Check if the target already exist.
		after = TRUE;
		for (item = amp_group_node_get_token (AMP_GROUP_NODE (group), AM_GROUP_TARGET); item != NULL; item = g_list_next (item))
		{
			existing_target_list = (AnjutaToken *)item->data;
			gchar *target_name = anjuta_token_evaluate (anjuta_token_first_word (existing_target_list));
			gboolean same;

			same = strcmp (target_name,  new_name->str) == 0;
			g_free (target_name);

			if (after)
			{
				GList *list;
				GList *item;

				list = amp_target_node_get_token (AMP_TARGET_NODE (node), ANJUTA_TOKEN_ARGUMENT);
				for (item = g_list_first (list); item != NULL; item = g_list_next (item))
				{
					AnjutaToken *arg = (AnjutaToken *)item->data;
					AnjutaToken *target_list;

					if (arg != NULL)
					{
						target_list = anjuta_token_list (arg);
						if (anjuta_token_list (target_list) == existing_target_list)
						{
							/* token in group_node are stored in reverse order */
							after = FALSE;
							break;
						}
					}
				}
			}

			if (same)
			{
				existing_target_list = anjuta_token_last_item (existing_target_list);
				break;
			}
			existing_target_list = NULL;
		}

		if (existing_target_list != NULL)
		{
			GList *token_list;

			/* Get old tokens */
			token_list = g_list_copy (amp_target_node_get_token (AMP_TARGET_NODE (node), ANJUTA_TOKEN_ARGUMENT));

			/* Add target in already existing list */
			amp_target_add_in_list (project, existing_target_list, node, after, NULL);

			/* Remove old token */
			amp_target_node_delete_token (project, AMP_TARGET_NODE (node), token_list, NULL);
			g_list_free (token_list);
		}
		else
		{
			list = amp_target_node_get_token (AMP_TARGET_NODE (node), ANJUTA_TOKEN_ARGUMENT);
			for (item = g_list_first (list); item != NULL; item = g_list_next (item))
			{
				AnjutaToken *arg = (AnjutaToken *)item->data;
				AnjutaToken *target_list;

				if (arg == NULL) continue;

				target_list = anjuta_token_list (arg);

				if (anjuta_token_nth_word (target_list, 1) == NULL)
				{
					/* Only one target in list, just replace list name */
					AnjutaToken *target_variable = anjuta_token_list (target_list);

					if (target_variable != NULL)
					{
						AnjutaToken *old_token;

						old_token = anjuta_token_first_word (target_variable);
						if (old_token != NULL)
						{
							AnjutaToken *token;

							token = anjuta_token_new_string (ANJUTA_TOKEN_ADDED, new_name->str);
							update = anjuta_token_insert_word_after (target_variable, old_token, token);
							anjuta_token_remove_word (old_token);
							update = target_variable;
						}
					}
				}
				else
				{
					gchar *old_target;
					AmpNodeInfo *info;
					gboolean after = TRUE;
					AnjutaToken *sibling = NULL;
					AnjutaTokenStyle *style;
					AnjutaToken *token;

					old_target = anjuta_token_evaluate (arg);

					/* Find sibling target */
					if (anjuta_token_first_word (target_list) == arg)
					{
						sibling = anjuta_token_next_word (arg);
						after = FALSE;
					}
					else
					{
						for (sibling = anjuta_token_first_word (target_list); sibling != NULL; sibling = anjuta_token_next_word (sibling))
						{
							if (anjuta_token_next_word (sibling) == arg) break;
						}
						after = TRUE;
					}

					/* More than one target, remove target in list */
					arg = anjuta_token_remove_word (arg);
					if (arg != NULL) amp_group_node_update_makefile (AMP_GROUP_NODE (group), arg);


					/* Add target in new list */
					style = anjuta_token_style_new_from_base (project->am_space_list);
					anjuta_token_style_update (style, target_list);

					info = (AmpNodeInfo *)amp_project_get_type_info (project, anjuta_project_node_get_full_type (node));
					target_list = amp_project_write_target (AMP_GROUP_NODE (group), info->token, new_name->str, after, sibling);

					token = anjuta_token_new_string (ANJUTA_TOKEN_ARGUMENT | ANJUTA_TOKEN_ADDED, old_target);
					anjuta_token_insert_word_after (target_list, NULL, token);

					/* Try to use the same style than the current target list */
					anjuta_token_style_format (style, target_list);
					anjuta_token_style_free (style);

					amp_group_node_update_makefile (AMP_GROUP_NODE (group), token);
					amp_target_node_add_token (AMP_TARGET_NODE (node), ANJUTA_TOKEN_ARGUMENT, token);

					g_free (old_target);

					update = anjuta_token_list (target_list);
				}
			}
		}
	}


	/* Add directory variable if needed */
	target_dir = NULL;
	for (item = anjuta_project_node_get_properties (node); item != NULL; item = g_list_next (item))
	{
		AmpProperty *prop = (AmpProperty *)item->data;

		if ((((AmpPropertyInfo *)prop->base.info)->token_type == AM_TOKEN__PROGRAMS) && (((AmpPropertyInfo *)prop->base.info)->flags & AM_PROPERTY_DIRECTORY))
		{
			target_dir = prop->base.value;
			if ((strlen (target_dir) <= 3) || (strcmp (target_dir + strlen(target_dir) - 3, "dir") != 0))
			{
				target_dir = g_strconcat (target_dir, "dir", NULL);
				g_free (prop->base.value);
				prop->base.value = target_dir;
			}
			break;
		}
	}

	/* If it is a standard directory do not add a variable*/
	if (target_dir != NULL)
	{
		const gchar **std_dir;

		for (std_dir = AmpStandardDirectory; *std_dir != NULL; std_dir++)
		{
			if (strcmp(*std_dir, target_dir) == 0)
			{
				target_dir = NULL;
				break;
			}
		}
	}

	if (target_dir != NULL)
	{
		for (item = anjuta_project_node_get_properties (group); item != NULL; item = g_list_next (item))
		{
			AmpProperty *prop = (AmpProperty *)item->data;

			if ((((AmpPropertyInfo *)prop->base.info)->token_type == AM_TOKEN_DIR) && (g_strcmp0 (prop->base.name, target_dir) == 0))
			{
				/* Find already existing directory variable */
				target_dir = NULL;
				break;
			}
		}
	}

	if ((update != NULL) && (target_dir != NULL))
	{
		update = anjuta_token_insert_token_list (FALSE, update,
					AM_TOKEN_DIR, NULL,
    				ANJUTA_TOKEN_NAME, target_dir,
    				ANJUTA_TOKEN_SPACE, " ",
    				ANJUTA_TOKEN_OPERATOR, "=",
        			ANJUTA_TOKEN_SPACE, " ",
    				ANJUTA_TOKEN_LIST, NULL,
        			ANJUTA_TOKEN_SPACE, " ",
					ANJUTA_TOKEN_EOL, "\n",
    				NULL);
	}

	g_string_free (new_name, TRUE);


	return update;
}
示例#10
0
gchar *
mkp_variable_evaluate (MkpVariable *variable, MkpProject *project)
{
	return anjuta_token_evaluate (variable->value);
}