gboolean amp_group_node_delete_token (AmpProject *project, AmpGroupNode *group, GError **error) { GList *item; AnjutaProjectNode *parent; /* Get parent group */ parent = anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (group), ANJUTA_PROJECT_GROUP); if (parent == NULL) return FALSE; for (item = amp_group_node_get_token (group, AM_GROUP_TOKEN_SUBDIRS); item != NULL; item = g_list_next (item)) { AnjutaToken *token = (AnjutaToken *)item->data; AnjutaTokenStyle *style; AnjutaToken *list; 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) { anjuta_token_remove_list (anjuta_token_list (list)); } amp_group_node_update_makefile (AMP_GROUP_NODE (parent), list); } /* Remove from configure file */ for (item = amp_group_node_get_token (group, AM_GROUP_TOKEN_CONFIGURE); item != NULL; item = g_list_next (item)) { AnjutaToken *token = (AnjutaToken *)item->data; AnjutaToken *args; AnjutaTokenStyle *style; args = anjuta_token_list (token); /* Try to use the same style than the current group list */ style = anjuta_token_style_new_from_base (project->ac_space_list); anjuta_token_style_update (style, args); anjuta_token_remove_word (token); anjuta_token_style_format (style, args); anjuta_token_style_free (style); amp_project_update_configure (project, args); } return TRUE; }
static gboolean amp_target_node_erase (AmpNode *target, AmpNode *parent, AmpProject *project, GError **error) { gboolean ok; GList * token_list; token_list = amp_target_node_get_all_token (AMP_TARGET_NODE (target)); ok = amp_target_node_delete_token (project, AMP_TARGET_NODE (target), token_list, error); g_list_free (token_list); /* Remove installation directory variable if the removed target was the * only one using it */ if (ok) { AnjutaProjectNode *node; const gchar *installdir; AnjutaProjectProperty *prop; gboolean used = FALSE; prop = amp_node_get_property_from_token (ANJUTA_PROJECT_NODE (target), AM_TOKEN__PROGRAMS, 6); installdir = prop->value; for (node = anjuta_project_node_first_child (ANJUTA_PROJECT_NODE (parent)); node != NULL; node = anjuta_project_node_next_sibling (node)) { if (node != ANJUTA_PROJECT_NODE (target)) { prop = amp_node_get_property_from_token (node, AM_TOKEN__PROGRAMS, 6); if ((prop != NULL) && (g_strcmp0 (installdir, prop->value) == 0)) { used = TRUE; break; } } } if (!used) { GList *item; for (item = anjuta_project_node_get_properties (ANJUTA_PROJECT_NODE (parent)); 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, installdir) == 0)) { /* Remove directory variable */ anjuta_token_remove_list (anjuta_token_list (prop->token)); amp_group_node_update_makefile (AMP_GROUP_NODE (parent), prop->token); break; } } } }; return ok; }
static AnjutaToken* amp_property_delete_token (AmpProject *project, AnjutaToken *token) { gboolean updated = FALSE; if (token != NULL) { anjuta_token_remove_list (anjuta_token_list (token)); updated = TRUE; } return token; }
gboolean amp_source_node_delete_token (AmpProject *project, AmpSourceNode *source, GError **error) { AnjutaProjectNode *group; AnjutaToken *token; /* Get parent group */ group = anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (source), ANJUTA_PROJECT_GROUP); if (group == NULL) return FALSE; token = amp_source_node_get_token (source); if (token != NULL) { AnjutaTokenStyle *style; AnjutaToken *list; 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) { anjuta_token_remove_list (anjuta_token_list (list)); } amp_group_node_update_makefile (AMP_GROUP_NODE (group), list); } return TRUE; }
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; }
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; }