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 * anjuta_token_find_target_property_position (AmpTargetNode *target, AnjutaTokenType type) { AnjutaToken *pos = NULL; gboolean after = FALSE; GList *list; AmpGroupNode *group; AnjutaToken *makefile; group = AMP_GROUP_NODE (anjuta_project_node_parent_type (ANJUTA_PROJECT_NODE (target), ANJUTA_PROJECT_GROUP)); /* Try to find a better position */ /* 1. With the other properties of the target */ list = amp_target_node_get_all_token (target); if (list != NULL) { GList *link; AnjutaTokenType best = 0; for (link = list; link != NULL; link = g_list_next (link)) { AnjutaToken *token = (AnjutaToken *)link->data; AnjutaTokenType existing = anjuta_token_get_type (token); if ((existing < AM_TOKEN_FIRST_ORDERED_TARGET_MACRO) || (existing > AM_TOKEN_LAST_ORDERED_TARGET_MACRO)) { token = anjuta_token_list (token); if (token != NULL) existing = anjuta_token_get_type (token); } if ((existing >= AM_TOKEN_FIRST_ORDERED_TARGET_MACRO) && (existing <= AM_TOKEN_LAST_ORDERED_TARGET_MACRO)) { if (existing > type) { if ((best == 0) || ((existing - type) < best)) { best = existing - type; pos = token; after = FALSE; } } else { if ((best == 0) || ((type -existing) < best)) { best = type - existing; pos = token; after = TRUE; } } } } g_list_free (list); } /* 2. With properties of sibling targets */ if (pos == NULL) { AnjutaProjectNode *prev = ANJUTA_PROJECT_NODE (target); AnjutaProjectNode *next = ANJUTA_PROJECT_NODE (target); AmpTargetNode *sibling; AnjutaTokenFile *makefile; AnjutaToken *target_list = NULL; GList *link; link = amp_target_node_get_token (target, ANJUTA_TOKEN_ARGUMENT); if ((link != NULL) && (link->data != NULL)) { target_list = anjuta_token_list ((AnjutaToken *)link->data); } makefile = amp_group_node_get_make_token_file (group); if (makefile != NULL) { after = TRUE; while ((prev != NULL) || (next != NULL)) { /* Find sibling */ if (after) { while (prev != NULL) { prev = anjuta_project_node_prev_sibling (prev); if (anjuta_project_node_get_node_type (prev) == ANJUTA_PROJECT_TARGET) break; } sibling = AMP_TARGET_NODE (prev); } else { while (next != NULL) { next = anjuta_project_node_next_sibling (next); if (anjuta_project_node_get_node_type (next) == ANJUTA_PROJECT_TARGET) break; } sibling = AMP_TARGET_NODE (next); } list = sibling == NULL ? NULL : amp_target_node_get_all_token (sibling); /* Check that the target is in the same list */ if ((list != NULL) && (target_list != NULL)) { AnjutaToken *token; link = amp_target_node_get_token (sibling, ANJUTA_TOKEN_ARGUMENT); if ((link != NULL) && (link->data != NULL)) { token = anjuta_token_list ((AnjutaToken *)link->data); } if ((token != NULL) && (target_list != token)) { /* Target is in another list, do not use it, nor following ones */ list = NULL; if (after) { prev = NULL; } else { next = NULL; } } } if (list != NULL) { gsize best = 0; for (link = list; link != NULL; link = g_list_next (link)) { AnjutaToken *token = (AnjutaToken *)link->data; AnjutaTokenType existing = anjuta_token_get_type (token); if ((existing < AM_TOKEN_FIRST_ORDERED_TARGET_MACRO) || (existing > AM_TOKEN_LAST_ORDERED_TARGET_MACRO)) { token = anjuta_token_list (token); if (token != NULL) existing = anjuta_token_get_type (token); } if ((existing >= AM_TOKEN_FIRST_ORDERED_TARGET_MACRO) && (existing <= AM_TOKEN_LAST_ORDERED_TARGET_MACRO)) { gsize tpos; tpos = anjuta_token_file_get_token_position (makefile, token); if ((best == 0) || (after && (tpos > best)) || (!after && (tpos < best))) { pos = token; best = tpos; } } } g_list_free (list); list = NULL; if (best != 0) break; } after = after ? FALSE : TRUE; } } } /* 3. After target declaration */ if (pos == NULL) { list = amp_target_node_get_token (AMP_TARGET_NODE (target), ANJUTA_TOKEN_ARGUMENT); if (list != NULL) { pos = (AnjutaToken *)list->data; if (pos != NULL) { pos = anjuta_token_list (pos); if (pos != NULL) { pos = anjuta_token_list (pos); } } } after = TRUE; } /* 4. At the end of the file */ if (pos == NULL) { makefile = amp_group_node_get_makefile_token (group); for (pos = anjuta_token_first_item (makefile); (pos != NULL) && (anjuta_token_next_item (pos) != NULL); pos = anjuta_token_next_item (pos)); after = TRUE; } /* 5. Create new file */ if (pos == NULL) { /* Empty file */ pos = anjuta_token_new_string (ANJUTA_TOKEN_COMMENT | ANJUTA_TOKEN_ADDED, "## Process this file with automake to produce Makefile.in\n"); anjuta_token_append_child (makefile, pos); amp_group_node_update_makefile (group, pos); } /* Find end of line */ if (after) { while (pos != NULL) { if (anjuta_token_get_type (pos) == ANJUTA_TOKEN_EOL) break; if (anjuta_token_next (pos) == NULL) { pos = anjuta_token_insert_token_list (after, pos, ANJUTA_TOKEN_EOL, "\n", NULL); break; } pos = anjuta_token_next (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); return pos; }