for (const struct __relation* relation = relations; relation->type; relation++) {
char* relations = pakfire_archive_get(archive, "dependencies", relation->type);
- if (!relations)
- continue;
-
- char* p = relations;
- while (*p) {
- char* e = strchr(p, '\n');
-
- // Terminate the string
- if (e)
- *e = '\0';
-
- // Add the dependency
- relation->func(pkg, p);
-
- // End loop when we reached the end
- if (!e)
- break;
-
- // Or continue at the next line
- p = e + 1;
- }
+ if (relations)
+ pakfire_parse_deps(archive->pakfire, pkg, relation->func, relations);
}
// Import filelist
pakfire_package_set_filelist(pkg, archive->filelist);
return pkg;
-
-ERROR:
- return NULL;
}
struct pakfire_scriptlet* pakfire_archive_get_scriptlet(
for (const struct dependency* deps = dependencies; deps->field; deps++) {
const char* relations = (const char*)sqlite3_column_text(stmt, deps->field);
if (relations) {
- // Copy list
- char* p = strdupa(relations);
- if (!p) {
- r = 1;
- goto ERROR;
- }
-
- while (*p) {
- char* e = strchr(p, '\n');
-
- // Terminate the string
- if (e)
- *e = '\0';
-
- // Add the dependency
- deps->func(pkg, p);
-
- // End loop when we reached the end
- if (!e)
- break;
-
- // Or continue at the next line
- p = e + 1;
- }
+ pakfire_parse_deps(db->pakfire, pkg, deps->func, relations);
}
}
#include <pakfire/types.h>
Id pakfire_parse_dep(Pakfire pakfire, const char* s);
+void pakfire_parse_deps(Pakfire pakfire, PakfirePackage pkg,
+ void (*func)(PakfirePackage pkg, const char* dep), const char* deps);
#define pakfire_string_format(s, fmt, ...) snprintf(s, sizeof(s) - 1, fmt, __VA_ARGS__)
#define pakfire_string_set(s, value) pakfire_string_format(s, "%s", value)
free(value);
}
+ // Fetch build dependencies
if (is_source) {
- // Fetch build dependencies
char* requires = pakfire_parser_get(parser, "build", "requires");
-
- if (requires && *requires) {
- char* p = requires;
-
- while (*p) {
- char* e = strchr(p, '\n');
-
- // Terminate the string
- if (e)
- *e = '\0';
-
- // Add the dependency
- pakfire_package_add_requires(*pkg, p);
-
- // End loop when we reached the end
- if (!e)
- break;
-
- // Or continue at the next line
- p = e + 1;
- }
- }
+ if (requires && *requires)
+ pakfire_parse_deps(parser->pakfire, *pkg,
+ pakfire_package_add_requires, requires);
}
// All okay
return id;
}
+void pakfire_parse_deps(Pakfire pakfire, PakfirePackage pkg,
+ void (*func)(PakfirePackage pkg, const char* dep), const char* deps) {
+ char* p = strdupa(deps);
+
+ while (*p) {
+ char* e = strchr(p, '\n');
+
+ // Terminate the string
+ if (e)
+ *e = '\0';
+
+ // Add the dependency
+ func(pkg, p);
+
+ // End loop when we reached the end
+ if (!e)
+ break;
+
+ // Or continue at the next line
+ p = e + 1;
+ }
+}
+
int pakfire_string_startswith(const char* s, const char* prefix) {
return !strncmp(s, prefix, strlen(prefix));
}