refactor: started a codestyle

This commit is contained in:
Jef Roosens 2022-12-03 23:27:44 +01:00
parent 65d67b2c01
commit 3b4a56bd89
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
11 changed files with 128 additions and 120 deletions

View file

@ -1,4 +1,4 @@
#include "dynarray.h"
#include "cieter_dynarray.h"
struct dyn_array {
char **array;
@ -6,15 +6,15 @@ struct dyn_array {
size_t capacity;
};
DynArray *dynarray_init(size_t initial_capacity) {
DynArray *da = malloc(sizeof(DynArray));
CieterDynArray *cieter_dynarray_init(size_t initial_capacity) {
CieterDynArray *da = malloc(sizeof(CieterDynArray));
da->size = 0;
da->capacity = initial_capacity;
return da;
}
void dynarray_add(DynArray *da, const char *s) {
void cieter_dynarray_add(CieterDynArray *da, const char *s) {
// An empty dynarray does not have an allocated internal array yet
if (da->size == 0) {
da->array = malloc(sizeof(char*) * da->capacity);
@ -29,7 +29,7 @@ void dynarray_add(DynArray *da, const char *s) {
da->size++;
}
void dynarray_free(DynArray *da) {
void cieter_dynarray_free(CieterDynArray *da) {
if (da == NULL) {
return;
}
@ -45,11 +45,11 @@ void dynarray_free(DynArray *da) {
free(da);
}
char **dynarray_convert(DynArray *da) {
char **cieter_dynarray_convert(CieterDynArray *da) {
char **array = da->array;
da->array = NULL;
dynarray_free(da);
cieter_dynarray_free(da);
return array;
}

View file

@ -1,4 +1,4 @@
#include "package.h"
#include "cieter_package.h"
static char *ignored_names[5] = {
".BUILDINFO",
@ -9,11 +9,11 @@ static char *ignored_names[5] = {
};
static int ignored_words_len = sizeof(ignored_names) / sizeof(char *);
Pkg *package_init() {
return calloc(sizeof(PkgInfo), 1);
CieterPkg *package_init() {
return calloc(sizeof(CieterPkgInfo), 1);
}
Pkg *package_read_archive(const char *pkg_path) {
CieterPkg *package_read_archive(const char *pkg_path) {
struct archive *a = archive_read_new();
struct archive_entry *entry = archive_entry_new();
@ -36,8 +36,8 @@ Pkg *package_read_archive(const char *pkg_path) {
int compression_code = archive_filter_code(a, 0);
const char *path_name;
PkgInfo *pkg_info;
DynArray *files = dynarray_init(16);
CieterPkgInfo *pkg_info;
CieterDynArray *files = cieter_dynarray_init(16);
while (archive_read_next_header(a, &entry) == ARCHIVE_OK) {
path_name = archive_entry_pathname(entry);
@ -52,7 +52,7 @@ Pkg *package_read_archive(const char *pkg_path) {
}
if (!ignore) {
dynarray_add(files, path_name);
cieter_dynarray_add(files, path_name);
}
if (strcmp(path_name, ".PKGINFO") == 0) {
@ -84,7 +84,7 @@ Pkg *package_read_archive(const char *pkg_path) {
archive_entry_free(entry);
// Create final return value
Pkg *pkg = package_init();
CieterPkg *pkg = package_init();
pkg->path = strdup(pkg_path);
pkg->info = pkg_info;
pkg->files = files;
@ -93,6 +93,6 @@ Pkg *package_read_archive(const char *pkg_path) {
return pkg;
}
char *package_to_description(Pkg *pkg) {
char *package_to_description(CieterPkg *pkg) {
}

View file

@ -1,12 +1,12 @@
#include <stdbool.h>
#include "package_info.h"
#include "cieter_package_info.h"
PkgInfo *package_info_init() {
return calloc(1, sizeof(PkgInfo));
CieterPkgInfo *package_info_init() {
return calloc(1, sizeof(CieterPkgInfo));
}
void package_info_free(PkgInfo *pkg_info) {
void package_info_free(CieterPkgInfo *pkg_info) {
FREE_STRING(pkg_info->name);
FREE_STRING(pkg_info->base);
FREE_STRING(pkg_info->version);
@ -16,15 +16,15 @@ void package_info_free(PkgInfo *pkg_info) {
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);
cieter_dynarray_free(pkg_info->groups);
cieter_dynarray_free(pkg_info->licenses);
cieter_dynarray_free(pkg_info->replaces);
cieter_dynarray_free(pkg_info->depends);
cieter_dynarray_free(pkg_info->conflicts);
cieter_dynarray_free(pkg_info->provides);
cieter_dynarray_free(pkg_info->optdepends);
cieter_dynarray_free(pkg_info->makedepends);
cieter_dynarray_free(pkg_info->checkdepends);
free(pkg_info);
}
@ -59,11 +59,11 @@ 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) { \
if (pkg_info->field == NULL) { pkg_info->field = dynarray_init(4); } \
dynarray_add(pkg_info->field, value_ptr); goto advance; \
if (pkg_info->field == NULL) { pkg_info->field = cieter_dynarray_init(4); } \
cieter_dynarray_add(pkg_info->field, value_ptr); goto advance; \
}
int package_info_parse(PkgInfo *pkg_info, char *pkg_info_str) {
int package_info_parse(CieterPkgInfo *pkg_info, char *pkg_info_str) {
char *offset_ptr, *equals_ptr, *key_ptr, *value_ptr;
bool end = false;