Ejemplo n.º 1
0
gboolean amp_project_update_am_property (AmpProject *project, AnjutaProjectNode *node, AnjutaProjectProperty *property)
{
	AnjutaProjectNode *group;
	AnjutaToken *args;

	/* Find group  of the property */
	if (anjuta_project_node_get_node_type (node) == ANJUTA_PROJECT_GROUP)
	{
		group = node;
	}
	else
	{
		group = anjuta_project_node_parent_type (node, ANJUTA_PROJECT_GROUP);
	}

	if (property->value == NULL)
	{
		/* Remove property */
		if (((AmpPropertyInfo *)property->info)->token_type == AM_TOKEN__PROGRAMS)
		{
			/* Properties added in the target name */
			args = amp_property_rename_target (project, node);
		}
		else
		{
			/* Other properties having their own variable */
			args = amp_property_delete_token (project, ((AmpProperty *)property)->token);
		}

		anjuta_project_node_remove_property (node, property);
	}
	else
	{
		if (((AmpPropertyInfo *)property->info)->token_type == AM_TOKEN__PROGRAMS)
		{
			/* Properties added in the target name */
			args = amp_property_rename_target (project, node);
		}
		else
		{
			/* Other properties having their own variable */
			GString *new_value;
			AnjutaToken *arg;
			AnjutaToken *token;
			const gchar *value;
			AnjutaTokenStyle *style;

			args = ((AmpProperty *)property)->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);

			if (args == NULL)
			{
				args = amp_project_write_property_list (AMP_GROUP_NODE (group), node, (AmpPropertyInfo *)property->info);
				((AmpProperty *)property)->token = args;
			}

			switch (property->info->type)
			{
			case ANJUTA_PROJECT_PROPERTY_LIST:
				new_value = g_string_new (property->value);
				g_string_assign (new_value, "");
				value = property->value;

				for (arg = anjuta_token_first_word (args); arg != NULL;)
				{
					gchar *arg_value = anjuta_token_evaluate_name (arg);

					while (isspace (*value)) value++;

					if (*value == '\0')
					{
						AnjutaToken *next;

						next = anjuta_token_next_word (arg);
						anjuta_token_remove_word (arg);
						arg = next;
					}
					else
					{
						const gchar *end;
						gchar *name;

						for (end = value; !isspace (*end) && (*end != '\0'); end++);
						name = g_strndup (value, end - value);

						if (strcmp (arg_value, name) != 0)
						{
							/* New argument in property list */
							AnjutaToken *token;

							token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, name);
							anjuta_token_insert_word_before (args, arg, token);
						}
						else
						{
							arg = anjuta_token_next_word (arg);
						}
						value = end;

						if (arg_value != NULL)
						{
							if (new_value->len != 0) g_string_append_c (new_value, ' ');
							g_string_append (new_value, name);
						}
					}
					g_free (arg_value);
				}

				while (*value != '\0')
				{
					AnjutaToken *token;
					const gchar *end;
					gchar *name;

					while (isspace (*value)) value++;
					if (*value == '\0') break;

					for (end = value; !isspace (*end) && (*end != '\0'); end++);

					name = g_strndup (value, end - value);
					token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, name);

					anjuta_token_insert_word_before (args, NULL, token);

					if (new_value->len != 0) g_string_append_c (new_value, ' ');
					g_string_append (new_value, name);

					g_free (name);
					value = end;
				}

				anjuta_token_style_format (style, args);
				anjuta_token_style_free (style);

				g_free (property->value);
				property->value = g_string_free (new_value, FALSE);

				break;
			case ANJUTA_PROJECT_PROPERTY_MAP:

				token =  anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, property->value);
				anjuta_token_insert_word_after (args, NULL, token);

				for (token = anjuta_token_next_word (token); token != NULL; token = anjuta_token_next_word (token))
				{
					anjuta_token_remove_word (token);
				}
				break;
			default:
				break;
			}
		}
	}

	if (args != NULL) amp_group_node_update_makefile (AMP_GROUP_NODE (group), args);

	return args != NULL ? TRUE : FALSE;
}
Ejemplo n.º 2
0
gboolean
amp_project_update_ac_property (AmpProject *project, AnjutaProjectProperty *property)
{
	AnjutaToken *token;
	AnjutaToken *arg;
	AnjutaToken *args;
	AmpProperty *prop;
	AmpPropertyInfo *info;

	if (g_strcmp0 (((AmpPropertyInfo *)property->info)->value, property->value) == 0)
	{
		/* Remove property */
		info = (AmpPropertyInfo *)property->info;
		prop = (AmpProperty *)property;

		if (info->position == -1)
		{
			token = prop->token;

			anjuta_token_remove_list (anjuta_token_list (token));
		}

		anjuta_project_node_remove_property (ANJUTA_PROJECT_NODE (project), property);
	}
	else
	{
		info = (AmpPropertyInfo *)property->info;
		prop = find_similar_property (ANJUTA_PROJECT_NODE (project), (AmpProperty *)property);
		args = prop != NULL ? prop->token : NULL;

		prop = (AmpProperty *)property;

		if (args == NULL)
		{
			AnjutaToken *group;
			AnjutaToken *configure;
			const char *suffix;

			configure = amp_project_get_configure_token (project);
			token = anjuta_token_find_position (configure, TRUE, info->token_type, NULL);
			if (token == NULL)
			{
				token = skip_comment (configure);
				if (token == NULL)
				{
					token = anjuta_token_append_child (configure, anjuta_token_new_string (COMMENT | ANJUTA_TOKEN_ADDED, "#"));
					token = anjuta_token_insert_after (token, anjuta_token_new_string (SPACE | ANJUTA_TOKEN_ADDED, " Created by Anjuta project manager"));
					token = anjuta_token_insert_after (token, anjuta_token_new_string (END_OF_LINE | ANJUTA_TOKEN_ADDED, "\n"));
					token = anjuta_token_insert_after (token, anjuta_token_new_string (END_OF_LINE | ANJUTA_TOKEN_ADDED, "\n"));
				}
			}

			suffix = info->suffix;
			token = anjuta_token_insert_after (token, anjuta_token_new_string (AC_TOKEN_AC_INIT | ANJUTA_TOKEN_ADDED, suffix));
			if (suffix[strlen(suffix) - 1] == '(')
			{
				group = anjuta_token_insert_after (token, anjuta_token_new_static (ANJUTA_TOKEN_LIST | ANJUTA_TOKEN_ADDED, NULL));
				args = group;
				token = anjuta_token_insert_after (group, anjuta_token_new_static (ANJUTA_TOKEN_LAST | ANJUTA_TOKEN_ADDED, NULL));
				anjuta_token_merge (group, token);
			}
			anjuta_token_insert_after (token, anjuta_token_new_string (END_OF_LINE | ANJUTA_TOKEN_ADDED, "\n"));
		}
		if (args != NULL)
		{
			guint pos;

			token = anjuta_token_new_string (ANJUTA_TOKEN_NAME | ANJUTA_TOKEN_ADDED, prop->base.value);
			arg = anjuta_token_insert_before (token, anjuta_token_new_static (ANJUTA_TOKEN_ITEM | ANJUTA_TOKEN_ADDED, NULL));
			anjuta_token_merge (arg, token);

			pos = info->position;
			if (pos == -1) pos = 0;
			anjuta_token_replace_nth_word (args, pos, arg);
			anjuta_token_style_format (project->arg_list, args);
		}
	}

	amp_project_update_configure (project, token);

	return TRUE;
}