Compare commits
No commits in common. "7e8de5f5fbb5970c9f6e1cd3b65a3c75d4d0d831" and "f1b29d1c3f0d62ea69804e618c9e7c8619bb0b26" have entirely different histories.
7e8de5f5fb
...
f1b29d1c3f
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +0,0 @@
|
|||||||
.cache
|
|
||||||
compile_commands.json
|
|
||||||
libwizapp.so
|
|
@ -17,11 +17,11 @@
|
|||||||
#define f64 double
|
#define f64 double
|
||||||
#define f128 long double
|
#define f128 long double
|
||||||
|
|
||||||
#define internal static
|
#define INTERNAL static
|
||||||
#define persistent static
|
#define PERSISTENT static
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#define class_mem static
|
#define CLASS_MEMBER static
|
||||||
#endif // __cplusplus
|
#endif // __cplusplus
|
||||||
|
|
||||||
#endif // !ALIASES_H
|
#endif // !ALIASES_H
|
||||||
|
16
compile
16
compile
@ -1,16 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
CC=clang
|
|
||||||
INCLUDE="\
|
|
||||||
-Ialiases \
|
|
||||||
-Icpath/include \
|
|
||||||
-Idstr/include \
|
|
||||||
"
|
|
||||||
SRC="\
|
|
||||||
cpath/src/*.c \
|
|
||||||
dstr/src/*.c \
|
|
||||||
"
|
|
||||||
CFLAGS="-shared -fPIC -Wall -Werror -pedantic"
|
|
||||||
OUT="libwizapp.so"
|
|
||||||
|
|
||||||
(set -x ; $CC $CFLAGS $INCLUDE $SRC -o $OUT)
|
|
@ -6,12 +6,13 @@
|
|||||||
#define NUMPARTS(...) \
|
#define NUMPARTS(...) \
|
||||||
(sizeof((const char *[]){"", __VA_ARGS__}) / sizeof(const char *) - 1)
|
(sizeof((const char *[]){"", __VA_ARGS__}) / sizeof(const char *) - 1)
|
||||||
|
|
||||||
#define cpath_join_path(DST, ...) \
|
#define JOIN_PATH(DST, ...) join_path(DST, NUMPARTS(__VA_ARGS__), __VA_ARGS__)
|
||||||
join_path(DST, NUMPARTS(__VA_ARGS__), __VA_ARGS__)
|
|
||||||
#define cpath_dirname(DST, PATH) dirup(DST, 1, PATH)
|
|
||||||
#define cpath_dirup(DST, COUNT, PATH) dirup(DST, COUNT, PATH)
|
|
||||||
|
|
||||||
void join_path(char *dst, u64 count, ...);
|
void join_path(char *dst, u64 count, ...);
|
||||||
|
|
||||||
|
#define DIRNAME(DST, PATH) dirup(DST, 1, PATH)
|
||||||
|
#define DIRUP(DST, COUNT, PATH) dirup(DST, COUNT, PATH)
|
||||||
|
|
||||||
void dirup(char *dst, u64 levels, const char *path);
|
void dirup(char *dst, u64 levels, const char *path);
|
||||||
|
|
||||||
#endif // !PATH_UTILS_H
|
#endif // !PATH_UTILS_H
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#if defined(__unix__) || defined(__APPLE__) || defined(__ANDROID__)
|
#if defined(__unix__) || defined(__APPLE__) || defined(__ANDROID__)
|
||||||
internal char path_sep = '/';
|
INTERNAL char path_sep = '/';
|
||||||
#elif defined(_WIN32) || defined(_WIN64)
|
#elif defined(_WIN32) || defined(_WIN64)
|
||||||
internal char path_sep = '\\';
|
INTERNAL char path_sep = '\\';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void join_root_and_leaf(const char *root, const char *leaf, char *dst);
|
void join_root_and_leaf(const char *root, const char *leaf, char *dst);
|
||||||
@ -32,10 +32,7 @@ void dirup(char *dst, u64 levels, const char *path) {
|
|||||||
u64 end_index = 0;
|
u64 end_index = 0;
|
||||||
u64 sep_count = 0;
|
u64 sep_count = 0;
|
||||||
|
|
||||||
u64 full_length;
|
u64 length = strlen(path);
|
||||||
u64 length;
|
|
||||||
length = full_length = strlen(path);
|
|
||||||
|
|
||||||
if (path[length - 1] == path_sep) {
|
if (path[length - 1] == path_sep) {
|
||||||
--length;
|
--length;
|
||||||
}
|
}
|
||||||
@ -55,14 +52,8 @@ void dirup(char *dst, u64 levels, const char *path) {
|
|||||||
end_index = 0;
|
end_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dst == path) {
|
|
||||||
memset(&dst[end_index], 0, full_length - end_index);
|
|
||||||
} else {
|
|
||||||
u64 dst_length = strlen(dst);
|
|
||||||
memset(dst, 0, dst_length);
|
|
||||||
strncpy(dst, path, end_index);
|
strncpy(dst, path, end_index);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void join_root_and_leaf(const char *root, const char *leaf, char *dst) {
|
void join_root_and_leaf(const char *root, const char *leaf, char *dst) {
|
||||||
u64 root_length = strlen(root);
|
u64 root_length = strlen(root);
|
||||||
|
@ -3,20 +3,20 @@
|
|||||||
|
|
||||||
#include "aliases.h"
|
#include "aliases.h"
|
||||||
|
|
||||||
typedef struct dstr String;
|
typedef struct dstring dstr_t;
|
||||||
|
|
||||||
String *dstr_with_capacity(u64 capacity);
|
dstr_t *dstr_with_capacity(u64 capacity);
|
||||||
String *dstr_from_string(const char *str);
|
dstr_t *dstr_from_string(const char *str);
|
||||||
void dstr_update(String **dst, const char *src);
|
void dstr_update(dstr_t **dst, const char *src);
|
||||||
void dstr_free(String **str);
|
void dstr_free(dstr_t **str);
|
||||||
void dstr_concat(String **dst, const char *src);
|
void dstr_concat(dstr_t **dst, const char *src);
|
||||||
void dstr_append(String **dst, char c);
|
void dstr_append(dstr_t **dst, char c);
|
||||||
void dstr_resize(String **str);
|
void dstr_resize(dstr_t **str);
|
||||||
void dstr_clear(String *str);
|
void dstr_clear(dstr_t *str);
|
||||||
void dstr_print(const String *str);
|
void dstr_print(const dstr_t *str);
|
||||||
i64 dstr_find(const String *str, const char *substr);
|
i64 dstr_find(const dstr_t *str, const char *substr);
|
||||||
u64 dstr_length(const String *str);
|
u64 dstr_length(const dstr_t *str);
|
||||||
u64 dstr_capacity(const String *str);
|
u64 dstr_capacity(const dstr_t *str);
|
||||||
const char *dstr_to_cstr(const String *str);
|
const char *dstr_to_cstr(const dstr_t *str);
|
||||||
|
|
||||||
#endif // !DSTR_H
|
#endif // !DSTR_H
|
||||||
|
@ -8,14 +8,14 @@
|
|||||||
// constantly reallocate
|
// constantly reallocate
|
||||||
#define CAPACITY_SCALAR 8
|
#define CAPACITY_SCALAR 8
|
||||||
|
|
||||||
struct dstr {
|
struct dstring {
|
||||||
u64 capacity;
|
u64 capacity;
|
||||||
u64 size;
|
u64 size;
|
||||||
char buf[];
|
char buf[];
|
||||||
};
|
};
|
||||||
|
|
||||||
String *dstr_with_capacity(u64 capacity) {
|
dstr_t *dstr_with_capacity(u64 capacity) {
|
||||||
String *out = (String *)malloc(sizeof(String) + capacity + 1);
|
dstr_t *out = (dstr_t *)malloc(sizeof(dstr_t) + capacity + 1);
|
||||||
|
|
||||||
if (!out) {
|
if (!out) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -28,7 +28,7 @@ String *dstr_with_capacity(u64 capacity) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
String *dstr_from_string(const char *str) {
|
dstr_t *dstr_from_string(const char *str) {
|
||||||
if (!str) {
|
if (!str) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ String *dstr_from_string(const char *str) {
|
|||||||
|
|
||||||
u64 capacity = length * CAPACITY_SCALAR;
|
u64 capacity = length * CAPACITY_SCALAR;
|
||||||
|
|
||||||
String *out = dstr_with_capacity(capacity);
|
dstr_t *out = dstr_with_capacity(capacity);
|
||||||
|
|
||||||
if (!out) {
|
if (!out) {
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -49,14 +49,14 @@ String *dstr_from_string(const char *str) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dstr_update(String **dst, const char *src) {
|
void dstr_update(dstr_t **dst, const char *src) {
|
||||||
if (!dst || !(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 length = strlen(src);
|
u64 length = strlen(src);
|
||||||
|
|
||||||
String *str = *dst;
|
dstr_t *str = *dst;
|
||||||
|
|
||||||
if (length <= str->capacity) {
|
if (length <= str->capacity) {
|
||||||
memset(str->buf, 0, str->capacity);
|
memset(str->buf, 0, str->capacity);
|
||||||
@ -67,7 +67,7 @@ void dstr_update(String **dst, const char *src) {
|
|||||||
} else {
|
} else {
|
||||||
u64 capacity = length * CAPACITY_SCALAR;
|
u64 capacity = length * CAPACITY_SCALAR;
|
||||||
|
|
||||||
String *tmp = (String *)realloc(*dst, sizeof(String) + capacity + 1);
|
dstr_t *tmp = (dstr_t *)realloc(*dst, sizeof(dstr_t) + capacity + 1);
|
||||||
|
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
return;
|
return;
|
||||||
@ -81,7 +81,7 @@ void dstr_update(String **dst, const char *src) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void dstr_free(String **str) {
|
void dstr_free(dstr_t **str) {
|
||||||
if (!str || !(*str)) {
|
if (!str || !(*str)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ void dstr_free(String **str) {
|
|||||||
*str = NULL;
|
*str = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dstr_concat(String **dst, const char *src) {
|
void dstr_concat(dstr_t **dst, const char *src) {
|
||||||
if (!dst || !(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -112,7 +112,7 @@ void dstr_concat(String **dst, const char *src) {
|
|||||||
dstr_update(dst, str);
|
dstr_update(dst, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dstr_append(String **dst, char c) {
|
void dstr_append(dstr_t **dst, char c) {
|
||||||
if (!dst || !(*dst)) {
|
if (!dst || !(*dst)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -128,14 +128,14 @@ void dstr_append(String **dst, char c) {
|
|||||||
dstr_update(dst, str);
|
dstr_update(dst, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void dstr_resize(String **str) {
|
void dstr_resize(dstr_t **str) {
|
||||||
if (!str || !(*str)) {
|
if (!str || !(*str)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 capacity = (*str)->size;
|
u64 capacity = (*str)->size;
|
||||||
|
|
||||||
String *tmp = (String *)realloc(*str, sizeof(String) + capacity + 1);
|
dstr_t *tmp = (dstr_t *)realloc(*str, sizeof(dstr_t) + capacity + 1);
|
||||||
|
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
return;
|
return;
|
||||||
@ -146,7 +146,7 @@ void dstr_resize(String **str) {
|
|||||||
*str = tmp;
|
*str = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dstr_clear(String *str) {
|
void dstr_clear(dstr_t *str) {
|
||||||
if (!str || str->size == 0) {
|
if (!str || str->size == 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -155,7 +155,7 @@ void dstr_clear(String *str) {
|
|||||||
str->size = 0;
|
str->size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dstr_print(const String *str) {
|
void dstr_print(const dstr_t *str) {
|
||||||
if (!str) {
|
if (!str) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -163,7 +163,7 @@ void dstr_print(const String *str) {
|
|||||||
printf("%s\n", str->buf);
|
printf("%s\n", str->buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 dstr_find(const String *str, const char *substr) {
|
i64 dstr_find(const dstr_t *str, const char *substr) {
|
||||||
if (!str || !substr) {
|
if (!str || !substr) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -194,7 +194,7 @@ i64 dstr_find(const String *str, const char *substr) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 dstr_length(const String *str) {
|
u64 dstr_length(const dstr_t *str) {
|
||||||
if (!str) {
|
if (!str) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -202,7 +202,7 @@ u64 dstr_length(const String *str) {
|
|||||||
return str->size;
|
return str->size;
|
||||||
}
|
}
|
||||||
|
|
||||||
u64 dstr_capacity(const String *str) {
|
u64 dstr_capacity(const dstr_t *str) {
|
||||||
if (!str) {
|
if (!str) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ u64 dstr_capacity(const String *str) {
|
|||||||
return str->capacity;
|
return str->capacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *dstr_to_cstr(const String *str) {
|
const char *dstr_to_cstr(const dstr_t *str) {
|
||||||
if (!str) {
|
if (!str) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user