COMPS_ObjList * __comps_split_arches(char *arches) { COMPS_ObjList *list; char *pch; list = COMPS_OBJECT_CREATE(COMPS_ObjList, NULL); pch = strtok(arches, " ,"); while (pch != NULL) { comps_objlist_append_x(list, (COMPS_Object*)comps_str(pch)); pch = strtok(NULL, " ,"); } return list; }
void comps_doccategory_add_groupid(COMPS_DocCategory *category, COMPS_DocGroupId *gid) { if (category == NULL || gid == NULL) { assert(0); return; } if (category->group_ids == NULL) { category->group_ids = COMPS_OBJECT_CREATE(COMPS_ObjList, NULL); } comps_objlist_append_x(category->group_ids, (COMPS_Object*)gid); }
void comps_docgroup_add_package(COMPS_DocGroup *group, COMPS_DocGroupPackage *package) { if (group == NULL || package == NULL) { assert(0); return; } if (group->packages == NULL) { group->packages = COMPS_OBJECT_CREATE(COMPS_ObjList, NULL); } comps_objlist_append_x(group->packages, (COMPS_Object*)package); }
COMPS_ObjList* comps_groups_union(COMPS_ObjList *groups1, COMPS_ObjList *groups2) { COMPS_HSListItem *hsit; COMPS_Set *set; COMPS_ObjList *ret; COMPS_DocGroup *tmpgroup; COMPS_ObjListIt *it; void *tmpdata; ret = (COMPS_ObjList*)comps_object_create(&COMPS_ObjList_ObjInfo, NULL); set = comps_set_create(); comps_set_init(set, NULL, NULL, NULL, &__comps_docgroup_idcmp); for (it = groups1 ? groups1->first : NULL; it != NULL; it = it->next) { comps_set_add(set, comps_object_copy(it->comps_obj)); } for (it = groups2 ? groups2->first : NULL; it != NULL; it = it->next) { if (comps_set_in(set, it->comps_obj)) { tmpgroup = comps_docgroup_union( (COMPS_DocGroup*)it->comps_obj, (COMPS_DocGroup*)comps_set_data_at(set, it->comps_obj)); tmpdata = comps_set_data_at(set, it->comps_obj); comps_set_remove(set, it->comps_obj); comps_object_destroy((COMPS_Object*)tmpdata); comps_set_add(set, tmpgroup); } else { comps_set_add(set, comps_object_copy(it->comps_obj)); } } for (hsit = set->data->first; hsit != NULL; hsit = hsit->next) { comps_objlist_append_x(ret, (COMPS_Object*)hsit->data); } comps_set_destroy(&set); return ret; }
static COMPS_ObjMRTreeData * __comps_objmrtree_data_create(char * key, unsigned int keylen, COMPS_Object *data) { COMPS_ObjMRTreeData * rtd; if ((rtd = malloc(sizeof(*rtd))) == NULL) return NULL; if ((rtd->key = malloc(sizeof(char) * (keylen+1))) == NULL) { free(rtd); return NULL; } memcpy(rtd->key, key, sizeof(char)*keylen); rtd->key[keylen] = '\0'; rtd->is_leaf = 1; rtd->data = (COMPS_ObjList*)comps_object_create(&COMPS_ObjList_ObjInfo, NULL); if (data) comps_objlist_append_x(rtd->data, data); rtd->subnodes = comps_hslist_create(); comps_hslist_init(rtd->subnodes, NULL, NULL, &comps_objmrtree_data_destroy_v); return rtd; }
END_TEST START_TEST(test_arch) { COMPS_Parsed *parsed; COMPS_Doc *doc2; COMPS_ObjList *arches, *list, *list2; COMPS_DocGroup *g; COMPS_DocCategory *c; COMPS_DocEnv *e; COMPS_DocGroupPackage *p; COMPS_Str *str; int x; COMPS_ObjListIt *it; char *grps[3][5] = {{"group1", "group3", "group4", NULL, NULL}, {"group1", "group2", "group3", "group4", NULL}, {"group3", "group4", NULL, NULL, NULL}}; char *g1_pkgs[3][8] = {{"pkg3", "pkg4", "pkg5", "pkg6", "pkg7", NULL, NULL, NULL}, {"pkg3", "pkg4", "pkg7", NULL, NULL, NULL, NULL, NULL}, {"pkg1", "pkg2", "pkg3", "pkg4", "pkg5", "pkg6", "pkg7", NULL}}; char *cats[3][5] = {{"cat1", "cat4", NULL, NULL, NULL}, {"cat1", "cat2", "cat4", NULL, NULL}, {"cat3", "cat4", NULL, NULL, NULL}}; char *c1_gids[3][9] = {{"g1", "g3", "g4", "g6", "g7", NULL, NULL, NULL, NULL}, {"g1", "g2", "g4", "g5", "g7", NULL, NULL, NULL, NULL}, {"g4", "g5", "g6", "g7", NULL, NULL, NULL, NULL, NULL}}; char *envs[3][5] = {{"env1", "env4", NULL, NULL, NULL}, {"env1", "env2", "env3", "env4", NULL}, {"env1", "env2", "env4", NULL, NULL}}; char *e1_gids[3][8] = {{"g1", "g3", "g4", NULL, NULL, NULL, NULL, NULL}, {"g1", "g2", "g5", NULL, NULL, NULL, NULL, NULL}, {"g2", "g4", NULL, NULL, NULL,NULL, NULL, NULL}}; char *e1_oids[3][8] = {{"o1", "o3", "o4", NULL, NULL, NULL, NULL, NULL}, {"o1", "o2", "o5", NULL, NULL, NULL, NULL, NULL}, {"o2", "o4", NULL, NULL, NULL,NULL, NULL, NULL}}; FILE *fp; //char *tmp; fprintf(stderr, "## Running test_parse arch\n"); parsed = comps_parse_parsed_create(); comps_parse_parsed_init(parsed, "UTF-8", 0); fp = fopen("main_arches.xml", "r"); comps_parse_file(parsed, fp, NULL); //comps_log_print(parsed->log); fail_if(parsed->fatal_error != 0, "Some fatal errors found after parsing"); //comps2xml_f(parsed->comps_doc, "fed2.xml", 0); arches = (COMPS_ObjList*)comps_object_create(&COMPS_ObjList_ObjInfo, NULL); comps_objlist_append_x(arches, (COMPS_Object*)comps_str("x86")); doc2 = comps_doc_arch_filter(parsed->comps_doc, arches); COMPS_OBJECT_DESTROY(arches); list = comps_doc_groups(doc2); ck_assert(list->len == 3); for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocGroup*)it->comps_obj; str = (COMPS_Str*)comps_docgroup_get_id(g); ck_assert_msg(strcmp(str->val, grps[0][x]) == 0, "%s != %s", str->val, grps[0][x]); COMPS_OBJECT_DESTROY(str); } g = (COMPS_DocGroup*)list->first->comps_obj; list2 = g->packages; for (x=0, it = list2->first; it != NULL; it = it->next, x++) { //printf("%s\n", ((COMPS_DocGroupPackage*)it->comps_obj)->name->val); if (g1_pkgs[0][x] == NULL) break; ck_assert(strcmp(((COMPS_DocGroupPackage*)it->comps_obj)->name->val, g1_pkgs[0][x]) == 0); } COMPS_OBJECT_DESTROY(list); list = comps_doc_categories(doc2); ck_assert(list->len == 2); for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocCategory*)it->comps_obj; str = (COMPS_Str*)comps_doccategory_get_id(g); ck_assert_msg(strcmp(str->val, cats[0][x]) == 0, "%s != %s", str->val, cats[0][x]); COMPS_OBJECT_DESTROY(str); } c = (COMPS_DocCategory*)list->first->comps_obj; list2 = c->group_ids; for (x=0, it = list2->first; it != NULL; it = it->next, x++) { //printf("%s\n", ((COMPS_DocGroupId*)it->comps_obj)->name->val); if (c1_gids[0][x] == NULL) break; ck_assert(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, c1_gids[0][x]) == 0); } COMPS_OBJECT_DESTROY(list); list = comps_doc_environments(doc2); ck_assert(list->len == 2); for (it = list->first, x=0; it != NULL; it = it->next, x++) { g = (COMPS_DocEnv*)it->comps_obj; str = (COMPS_Str*)comps_docenv_get_id(g); ck_assert_msg(strcmp(str->val, envs[0][x]) == 0, "%s != %s", str->val, envs[0][x]); COMPS_OBJECT_DESTROY(str); } e = (COMPS_DocEnv*)list->first->comps_obj; list2 = e->group_list; for (x=0, it = list2->first; it != NULL; it = it->next, x++) { //printf("%s\n", ((COMPS_DocGroupId*)it->comps_obj)->name->val); if (e1_gids[0][x] == NULL) break; ck_assert_msg(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, e1_gids[0][x]) == 0, "%s != %s", ((COMPS_DocGroupId*)it->comps_obj)->name->val, e1_gids[0][x]); } list2 = e->option_list; for (x=0, it = list2->first; it != NULL; it = it->next, x++) { if (e1_oids[0][x] == NULL) break; ck_assert(strcmp(((COMPS_DocGroupId*)it->comps_obj)->name->val, e1_oids[0][x]) == 0); } COMPS_OBJECT_DESTROY(list); COMPS_OBJECT_DESTROY(doc2); comps_parse_parsed_destroy(parsed); }
void comps_objmrtree_set_n(COMPS_ObjMRTree *rt, char *key, unsigned int len, void *ndata) { COMPS_HSListItem *it; COMPS_HSList *subnodes; COMPS_ObjMRTreeData *rtd; COMPS_ObjMRTreeData *rtdata; unsigned int klen, offset=0; unsigned x, found = 0; char ended, tmpch; if (rt->subnodes == NULL) return; subnodes = rt->subnodes; while (offset != len) { found = 0; for (it = subnodes->first; it != NULL; it=it->next) { if (((COMPS_ObjMRTreeData*)it->data)->key[0] == key[offset]) { found = 1; break; } } if (!found) { /* not found in subnodes; create new subnode */ rtd = comps_objmrtree_data_create_n(key+offset, len, ndata); comps_hslist_append(subnodes, rtd, 0); rt->len++; return; } else { rtdata = (COMPS_ObjMRTreeData*)it->data; ended = 0; for (x=1; ;x++) { if (rtdata->key[x] == 0) ended += 1; if (x == len-offset) ended += 2; if (ended != 0) break; if (key[offset+x] != rtdata->key[x]) break; } if (ended == 3) { //keys equals; append new data comps_objlist_append_x(rtdata->data, ndata); rt->len++; return; } else if (ended == 2) { //global key ends first; make global leaf comps_hslist_remove(subnodes, it); it->next = NULL; rtd = comps_objmrtree_data_create_n(key+offset, len, ndata); comps_hslist_append(subnodes, rtd, 0); ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes->last = it; ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes->first = it; klen = len-offset; memmove(rtdata->key,rtdata->key+(len-offset), sizeof(char)*klen); rtdata->key[len] = 0; rt->len++; return; } else if (ended == 1) { //local key ends first; go deeper subnodes = rtdata->subnodes; offset += x; } else { comps_hslist_remove(subnodes, it); tmpch = rtdata->key[x]; rtdata->key[x] = 0; rtd = comps_objmrtree_data_create(rtdata->key, NULL); rtd->is_leaf = 0; comps_hslist_append(subnodes, rtd, 0); rtd = comps_objmrtree_data_create_n(key+offset+x, len-offset-x, ndata); comps_hslist_append( ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes, rtd, 0); rtdata->key[x] = tmpch; it->next = NULL; ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes->last->next = it; ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes->last = it; //// printf("len: %d\n",(int)strlen(rtdata->key+x)); len = strlen(rtdata->key+x); memmove(rtdata->key,rtdata->key+x, sizeof(char)*len); rtdata->key = realloc(rtdata->key, sizeof(char)*(len+1)); rtdata->key[len] = 0; //// printf("new sub-key2: %s\n", rtdata->key); rt->len++; return; } } } }
void __comps_objmrtree_set(COMPS_ObjMRTree *rt, char *key, COMPS_Object *ndata) { static COMPS_HSListItem *it; COMPS_HSList *subnodes; COMPS_ObjMRTreeData *rtd; static COMPS_ObjMRTreeData *rtdata; size_t len, offset=0; unsigned x, found = 0; char ended, tmpch; len = strlen(key); if (rt->subnodes == NULL) return; subnodes = rt->subnodes; while (offset != len) { found = 0; for (it = subnodes->first; it != NULL; it = it->next) { if (((COMPS_ObjMRTreeData*)it->data)->key[0] == key[offset]) { found = 1; break; } } if (!found) { // not found in subnodes; create new subnode rtd = comps_objmrtree_data_create(key+offset, ndata); comps_hslist_append(subnodes, rtd, 0); rt->len++; return; } else { rtdata = (COMPS_ObjMRTreeData*)it->data; ended = 0; for (x=1; ;x++) { if (rtdata->key[x] == 0) ended += 1; if (x == len - offset) ended += 2; if (ended != 0) break; if (key[offset+x] != rtdata->key[x]) break; } if (ended == 3) { //keys equals; append new data comps_objlist_append_x(rtdata->data, ndata); rt->len++; return; } else if (ended == 2) { //global key ends first; make global leaf comps_hslist_remove(subnodes, it); it->next = NULL; rtd = comps_objmrtree_data_create(key, ndata); comps_hslist_append(subnodes, rtd, 0); ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes->last = it; ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes->first = it; len = strlen(key + offset); memmove(rtdata->key,rtdata->key+strlen(key+offset), strlen(rtdata->key) - len); rtdata->key[strlen(rtdata->key) - len] = 0; rtdata->key = realloc(rtdata->key, sizeof(char)* (strlen(rtdata->key)+1)); rt->len++; return; } else if (ended == 1) { //local key ends first; go deeper subnodes = rtdata->subnodes; offset += x; } else { /* keys differ */ comps_hslist_remove(subnodes, it); /*remove existing item*/ tmpch = rtdata->key[x]; rtdata->key[x] = '\0'; /*cut existing item key to common key*/ /* create new parent node with common key with no data*/ rtd = comps_objmrtree_data_create(rtdata->key, NULL); rtd->is_leaf = 0; /* append to the end of subnodes in current tree level*/ comps_hslist_append(subnodes, rtd, 0); /* create new item with differ part inserting key*/ rtd = comps_objmrtree_data_create(key+offset+x, ndata); comps_hslist_append( ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes, rtd, 0); /* create new item with differ part existing key*/ it->next = NULL; ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes->last->next = it; ((COMPS_ObjMRTreeData*)subnodes->last->data)->subnodes->last = it; rtdata->key[x] = tmpch; len = strlen(rtdata->key+x); memmove(rtdata->key,rtdata->key+x, sizeof(char)*len); rtdata->key = realloc(rtdata->key, sizeof(char)*(len+1)); rtdata->key[len] = 0; rt->len++; return; } } } }