pakfire_package_set_buildtime(pkg, t);
}
+ // Relations
+
+ PakfireRelationList l;
+
+ char* prerequires = pakfire_archive_get(archive, "dependencies.prerequires");
+ if (prerequires) {
+ l = pakfire_relationlist_create_from_string(archive->pakfire, prerequires);
+ pakfire_package_set_prerequires(pkg, l);
+ pakfire_relationlist_unref(l);
+ pakfire_free(prerequires);
+ }
+
+ char* requires = pakfire_archive_get(archive, "dependencies.requires");
+ if (requires) {
+ l = pakfire_relationlist_create_from_string(archive->pakfire, requires);
+ pakfire_package_set_requires(pkg, l);
+ pakfire_relationlist_unref(l);
+ pakfire_free(requires);
+ }
+
+ char* provides = pakfire_archive_get(archive, "dependencies.provides");
+ if (provides) {
+ l = pakfire_relationlist_create_from_string(archive->pakfire, provides);
+ pakfire_package_set_provides(pkg, l);
+ pakfire_relationlist_unref(l);
+ pakfire_free(provides);
+ }
+
+ char* obsoletes = pakfire_archive_get(archive, "dependencies.obsoletes");
+ if (obsoletes) {
+ l = pakfire_relationlist_create_from_string(archive->pakfire, obsoletes);
+ pakfire_package_set_obsoletes(pkg, l);
+ pakfire_relationlist_unref(l);
+ pakfire_free(obsoletes);
+ }
+
+ char* recommends = pakfire_archive_get(archive, "dependencies.recommends");
+ if (recommends) {
+ l = pakfire_relationlist_create_from_string(archive->pakfire, recommends);
+ pakfire_package_set_recommends(pkg, l);
+ pakfire_relationlist_unref(l);
+ pakfire_free(recommends);
+ }
+
+ char* suggests = pakfire_archive_get(archive, "dependencies.suggests");
+ if (suggests) {
+ l = pakfire_relationlist_create_from_string(archive->pakfire, suggests);
+ pakfire_package_set_suggests(pkg, l);
+ pakfire_relationlist_unref(l);
+ pakfire_free(suggests);
+ }
+
return pkg;
}
PakfireRelation pakfire_relation_create(Pakfire pakfire, const char* name, int cmp_type, const char* evr);
PakfireRelation pakfire_relation_create_from_id(Pakfire pakfire, Id id);
+PakfireRelation pakfire_relation_create_from_string(Pakfire pakfire, const char* s);
PakfireRelation pakfire_relation_ref(PakfireRelation relation);
PakfireRelation pakfire_relation_unref(PakfireRelation relation);
#include <pakfire/types.h>
PakfireRelationList pakfire_relationlist_create(Pakfire pakfire);
+PakfireRelationList pakfire_relationlist_create_from_string(Pakfire pakfire, const char* s);
PakfireRelationList pakfire_relationlist_ref(PakfireRelationList relationlist);
PakfireRelationList pakfire_relationlist_unref(PakfireRelationList relationlist);
size_t pakfire_string_to_size(const char* s);
char** pakfire_split_string(const char* s, char delim);
+void pakfire_partition_string(const char* s, const char* delim, char** s1, char** s2);
#endif /* PAKFIRE_UTIL_H */
pakfire_relationlist_add;
pakfire_relationlist_count;
pakfire_relationlist_create;
+ pakfire_relationlist_create_from_string;
pakfire_relationlist_get_clone;
pakfire_relationlist_ref;
pakfire_relationlist_unref;
pakfire_access;
pakfire_free;
pakfire_get_errno;
+ pakfire_partition_string;
pakfire_path_join;
pakfire_read_file_into_buffer;
pakfire_split_string;
return NULL;
}
+PAKFIRE_EXPORT void pakfire_package_set_prerequires(PakfirePackage pkg, PakfireRelationList relationlist) {
+ #warning TODO
+}
+
PAKFIRE_EXPORT PakfireRelationList pakfire_package_get_requires(PakfirePackage pkg) {
return pakfire_package_get_relationlist(pkg, SOLVABLE_REQUIRES);
}
int nrefs;
};
+const char* delimiters[] = {
+ ">=", ">", "<=", "<", "=", NULL,
+};
+
+static int cmp2type(const char* s) {
+ if (strcmp(s, ">=") == 0)
+ return PAKFIRE_GE;
+
+ if (strcmp(s, ">") == 0)
+ return PAKFIRE_GT;
+
+ if (strcmp(s, "<=") == 0)
+ return PAKFIRE_LE;
+
+ if (strcmp(s, "<") == 0)
+ return PAKFIRE_LT;
+
+ if (strcmp(s, "=") == 0)
+ return PAKFIRE_EQ;
+
+ return 0;
+}
+
static int cmptype2relflags(int type) {
int flags = 0;
return relation;
}
+PAKFIRE_EXPORT PakfireRelation pakfire_relation_create_from_string(Pakfire pakfire, const char* s) {
+ DEBUG(pakfire, "Parsing relation from string: %s\n", s);
+
+ char* name;
+ char* evr;
+
+ const char** delim = delimiters;
+ while (*delim) {
+ pakfire_partition_string(s, *delim, &name, &evr);
+
+ // Nothing to do for no match
+ if (!name && !evr) {
+ delim++;
+ continue;
+ }
+
+ // Create new relation object
+ PakfireRelation rel = pakfire_relation_create(pakfire, name, cmp2type(*delim), evr);
+
+ // Cleanup
+ pakfire_free(name);
+ pakfire_free(evr);
+
+ return rel;
+ }
+
+ // No delimiter was found
+ return pakfire_relation_create(pakfire, s, 0, NULL);
+}
+
PAKFIRE_EXPORT PakfireRelation pakfire_relation_ref(PakfireRelation relation) {
relation->nrefs++;
return relationlist;
}
+PAKFIRE_EXPORT PakfireRelationList pakfire_relationlist_create_from_string(Pakfire pakfire, const char* s) {
+ PakfireRelationList relationlist = pakfire_relationlist_create(pakfire);
+ if (!relationlist)
+ return NULL;
+
+ // Split input by newline
+ char** list = pakfire_split_string(s, '\n');
+ if (!list)
+ return relationlist;
+
+ char** item = list;
+ while (*item) {
+ PakfireRelation rel = pakfire_relation_create_from_string(relationlist->pakfire, *item);
+ if (rel) {
+ pakfire_relationlist_add(relationlist, rel);
+ pakfire_relation_unref(rel);
+ }
+
+ //pakfire_free(*item);
+ item++;
+ }
+
+ pakfire_free(list);
+
+ return relationlist;
+}
+
PAKFIRE_EXPORT PakfireRelationList pakfire_relationlist_ref(PakfireRelationList relationlist) {
relationlist->nrefs++;
return ret;
}
+
+PAKFIRE_EXPORT void pakfire_partition_string(const char* s, const char* delim, char** s1, char** s2) {
+ char* p = strstr(s, delim);
+
+ // Delim was not found
+ if (!p) {
+ *s1 = NULL;
+ *s2 = NULL;
+ return;
+ }
+
+ // Length of string before delim
+ size_t l = p - s;
+ printf("%zu\n", l);
+
+ *s1 = pakfire_malloc(l);
+ snprintf(*s1, l, "%s", s);
+
+ *s2 = pakfire_strdup(p + strlen(delim));
+}