summaryrefslogtreecommitdiff
path: root/src/include/engine/utils.c
diff options
context:
space:
mode:
authorbpc2003 <wpesfriendnva@gmail.com>2025-05-20 14:40:47 -0400
committerbpc2003 <wpesfriendnva@gmail.com>2025-05-20 14:40:47 -0400
commitbf76b8c582ed9c541438ebe90fc6415fb82f2ed3 (patch)
treea5cd3d6e77c21867784c34d0728046d202a08d34 /src/include/engine/utils.c
parent1abda4d6d97c3386694f85fe5f7cc6844ade67c2 (diff)
Add Formatting
Diffstat (limited to 'src/include/engine/utils.c')
-rw-r--r--src/include/engine/utils.c111
1 files changed, 54 insertions, 57 deletions
diff --git a/src/include/engine/utils.c b/src/include/engine/utils.c
index 909c123..f8ef7f0 100644
--- a/src/include/engine/utils.c
+++ b/src/include/engine/utils.c
@@ -5,67 +5,64 @@
static int delkey(tablist_t *, int, char *);
-void dellist(tablist_t *list)
-{
- for (int i = 0; i < list[0].len; ++i) {
- tablist_t *indexes = getkeys(list, i, NULL, 0);
- for (int j = 0; indexes[0].tab[j].flag; ++j)
- delkey(list, i, indexes[0].tab[j].key);
- free(indexes);
- }
+void dellist(tablist_t *list) {
+ for (int i = 0; i < list[0].len; ++i) {
+ tablist_t *indexes = getkeys(list, i, NULL, 0);
+ for (int j = 0; indexes[0].tab[j].flag; ++j)
+ delkey(list, i, indexes[0].tab[j].key);
+ free(indexes);
+ }
}
-int hash(char *key)
-{
- unsigned long h = 5381;
- for (int i = 0; i < strlen(key); ++i)
- h = ((h << 5) + h) + key[i];
- return h % TABLEN;
+int hash(char *key) {
+ unsigned long h = 5381;
+ for (int i = 0; i < strlen(key); ++i)
+ h = ((h << 5) + h) + key[i];
+ return h % TABLEN;
}
-tablist_t *copytab(tablist_t *dst, tablist_t *src)
-{
- if (dst == NULL)
- return NULL;
- dst[0].len = src[0].len;
- for (int i = 0; i < src[0].len; ++i) {
- for (int j = 0; j < TABLEN; ++j) {
- dst[i].tab[j] = (tabidx_t) { NULL, 0, { 0 } };
- if (src[i].tab[j].flag) {
- switch (src[i].tab[j].flag) {
- case 3:
- dst[i].tab[j].value.str =
- calloc(strlen(src[i].tab[j].value.str) + 1, sizeof(char));
- strcpy(dst[i].tab[j].value.str, src[i].tab[j].value.str);
- break;
- default:
- dst[i].tab[j].value = src[i].tab[j].value;
- break;
- }
- dst[i].tab[j].flag = src[i].tab[j].flag;
- dst[i].tab[j].key = calloc(strlen(src[i].tab[j].key) + 1, sizeof(char));
- strcpy(dst[i].tab[j].key, src[i].tab[j].key);
- }
- }
- }
- return dst;
+tablist_t *copytab(tablist_t *dst, tablist_t *src) {
+ if (dst == NULL)
+ return NULL;
+ dst[0].len = src[0].len;
+ for (int i = 0; i < src[0].len; ++i) {
+ for (int j = 0; j < TABLEN; ++j) {
+ dst[i].tab[j] = (tabidx_t){NULL, 0, {0}};
+ if (src[i].tab[j].flag) {
+ switch (src[i].tab[j].flag) {
+ case 3:
+ dst[i].tab[j].value.str = calloc(
+ strlen(src[i].tab[j].value.str) + 1, sizeof(char));
+ strcpy(dst[i].tab[j].value.str, src[i].tab[j].value.str);
+ break;
+ default:
+ dst[i].tab[j].value = src[i].tab[j].value;
+ break;
+ }
+ dst[i].tab[j].flag = src[i].tab[j].flag;
+ dst[i].tab[j].key =
+ calloc(strlen(src[i].tab[j].key) + 1, sizeof(char));
+ strcpy(dst[i].tab[j].key, src[i].tab[j].key);
+ }
+ }
+ }
+ return dst;
}
-static int delkey(tablist_t *list, int id, char *key)
-{
- int idx = hash(key);
- if (list[id].tab[idx].key == NULL)
- return 1;
- while (strcmp(list[id].tab[idx].key, key) && idx < TABLEN)
- idx++;
- if (idx >= TABLEN)
- return 2;
- free(list[id].tab[idx].key);
- list[id].tab[idx].key = NULL;
- if (list[id].tab[idx].flag == 3) {
- free(list[id].tab[idx].value.str);
- list[id].tab[idx].value.str = NULL;
- }
- list[id].tab[idx].flag = 0;
- return 0;
+static int delkey(tablist_t *list, int id, char *key) {
+ int idx = hash(key);
+ if (list[id].tab[idx].key == NULL)
+ return 1;
+ while (strcmp(list[id].tab[idx].key, key) && idx < TABLEN)
+ idx++;
+ if (idx >= TABLEN)
+ return 2;
+ free(list[id].tab[idx].key);
+ list[id].tab[idx].key = NULL;
+ if (list[id].tab[idx].flag == 3) {
+ free(list[id].tab[idx].value.str);
+ list[id].tab[idx].value.str = NULL;
+ }
+ list[id].tab[idx].flag = 0;
+ return 0;
}