forked from vieter-v/vieter
feat(package.c): some cleanup
parent
3c0422b998
commit
640e2914bf
2
Makefile
2
Makefile
|
@ -1,6 +1,6 @@
|
|||
# =====CONFIG=====
|
||||
SRC_DIR := src
|
||||
SOURCES != find '$(SRC_DIR)' -iname '*.v'
|
||||
SOURCES != find '$(SRC_DIR)' -type f \( -iname '*.v' -or -iname '*.c' -or -iname '*.h' \)
|
||||
|
||||
V_PATH ?= v
|
||||
# We need to use GCC because TCC doesn't like the way we use C bindings
|
||||
|
|
|
@ -29,15 +29,27 @@ void dynarray_add(DynArray *da, const char *s) {
|
|||
da->size++;
|
||||
}
|
||||
|
||||
void dynarray_free(DynArray **ptp) {
|
||||
DynArray *da = *ptp;
|
||||
void dynarray_free(DynArray *da) {
|
||||
if (da == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (da->array != NULL) {
|
||||
for (size_t i = 0; i < da->size; i++) {
|
||||
free(da->array[i]);
|
||||
}
|
||||
|
||||
free(da->array);
|
||||
free(da);
|
||||
|
||||
*ptp = NULL;
|
||||
}
|
||||
|
||||
free(da);
|
||||
}
|
||||
|
||||
char **dynarray_convert(DynArray *da) {
|
||||
char **array = da->array;
|
||||
|
||||
da->array = NULL;
|
||||
dynarray_free(da);
|
||||
|
||||
return array;
|
||||
}
|
||||
|
|
|
@ -8,7 +8,12 @@ typedef struct dyn_array DynArray;
|
|||
|
||||
DynArray *dynarray_init(size_t initial_capacity);
|
||||
void dynarray_add(DynArray *da, const char * s);
|
||||
char ** dynarray_get_array(DynArray *da);
|
||||
void dynarray_free(DynArray **ptp);
|
||||
void dynarray_free(DynArray *da);
|
||||
|
||||
/**
|
||||
* Convert a DynArray into an array by freeing all its surrounding components
|
||||
* and returning the underlying array pointer.
|
||||
*/
|
||||
char **dynarray_convert(DynArray *da);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -92,3 +92,7 @@ Pkg *package_read_archive(const char *pkg_path) {
|
|||
|
||||
return pkg;
|
||||
}
|
||||
|
||||
char *package_to_description(Pkg *pkg) {
|
||||
|
||||
}
|
||||
|
|
|
@ -21,5 +21,6 @@ typedef struct pkg {
|
|||
|
||||
Pkg *package_read_archive(const char *pkg_path);
|
||||
void package_free(Pkg ** ptp);
|
||||
char *package_to_description(Pkg *pkg);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,24 +3,10 @@
|
|||
#include "package_info.h"
|
||||
|
||||
PkgInfo *package_info_init() {
|
||||
PkgInfo *pkg_info = calloc(1, sizeof(PkgInfo));
|
||||
|
||||
pkg_info->groups = dynarray_init(4);
|
||||
pkg_info->licenses = dynarray_init(4);
|
||||
pkg_info->replaces = dynarray_init(4);
|
||||
pkg_info->depends = dynarray_init(4);
|
||||
pkg_info->conflicts = dynarray_init(4);
|
||||
pkg_info->provides = dynarray_init(4);
|
||||
pkg_info->optdepends = dynarray_init(4);
|
||||
pkg_info->makedepends = dynarray_init(4);
|
||||
pkg_info->checkdepends = dynarray_init(4);
|
||||
|
||||
return pkg_info;
|
||||
return calloc(1, sizeof(PkgInfo));
|
||||
}
|
||||
|
||||
void package_info_free(PkgInfo **ptp) {
|
||||
PkgInfo *pkg_info = *ptp;
|
||||
|
||||
void package_info_free(PkgInfo *pkg_info) {
|
||||
FREE_STRING(pkg_info->name);
|
||||
FREE_STRING(pkg_info->base);
|
||||
FREE_STRING(pkg_info->version);
|
||||
|
@ -30,17 +16,17 @@ void package_info_free(PkgInfo **ptp) {
|
|||
FREE_STRING(pkg_info->packager);
|
||||
FREE_STRING(pkg_info->pgpsig);
|
||||
|
||||
dynarray_free(&pkg_info->groups);
|
||||
dynarray_free(&pkg_info->licenses);
|
||||
dynarray_free(&pkg_info->replaces);
|
||||
dynarray_free(&pkg_info->depends);
|
||||
dynarray_free(&pkg_info->conflicts);
|
||||
dynarray_free(&pkg_info->provides);
|
||||
dynarray_free(&pkg_info->optdepends);
|
||||
dynarray_free(&pkg_info->makedepends);
|
||||
dynarray_free(&pkg_info->checkdepends);
|
||||
dynarray_free(pkg_info->groups);
|
||||
dynarray_free(pkg_info->licenses);
|
||||
dynarray_free(pkg_info->replaces);
|
||||
dynarray_free(pkg_info->depends);
|
||||
dynarray_free(pkg_info->conflicts);
|
||||
dynarray_free(pkg_info->provides);
|
||||
dynarray_free(pkg_info->optdepends);
|
||||
dynarray_free(pkg_info->makedepends);
|
||||
dynarray_free(pkg_info->checkdepends);
|
||||
|
||||
*ptp = NULL;
|
||||
free(pkg_info);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -72,7 +58,10 @@ static inline void trim_spaces_back(char *ptr) {
|
|||
|
||||
#define PKG_INFO_STRING(key, field) if (strcmp(key_ptr, key) == 0) { pkg_info->field = strdup(value_ptr); goto advance; }
|
||||
#define PKG_INFO_INT(key, field) if (strcmp(key_ptr, key) == 0) { pkg_info->field = atoi(value_ptr); goto advance; }
|
||||
#define PKG_INFO_ARRAY(key, field) if (strcmp(key_ptr, key) == 0) { dynarray_add(pkg_info->field, value_ptr); goto advance; }
|
||||
#define PKG_INFO_ARRAY(key, field) if (strcmp(key_ptr, key) == 0) { \
|
||||
if (pkg_info->field == NULL) { pkg_info->field = dynarray_init(4); } \
|
||||
dynarray_add(pkg_info->field, value_ptr); goto advance; \
|
||||
}
|
||||
|
||||
int package_info_parse(PkgInfo *pkg_info, char *pkg_info_str) {
|
||||
char *offset_ptr, *equals_ptr, *key_ptr, *value_ptr;
|
||||
|
|
|
@ -34,6 +34,6 @@ typedef struct pkg_info {
|
|||
|
||||
PkgInfo *package_info_init();
|
||||
int package_info_parse(PkgInfo *pkg_info, char *pkg_info_str);
|
||||
void package_info_free(PkgInfo **ptp);
|
||||
void package_info_free(PkgInfo *pkg_info);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue