Compare commits
	
		
			8 Commits
		
	
	
		
			f1b29d1c3f
			...
			7e8de5f5fb
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 7e8de5f5fb | |||
| 293b16af31 | |||
| 0a82702503 | |||
| 36a4c04a5b | |||
| ad5d76d3cc | |||
| d5c19e2c58 | |||
| fc951c8bd8 | |||
| 75acf7da5d | 
							
								
								
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										3
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@@ -0,0 +1,3 @@
 | 
			
		||||
.cache
 | 
			
		||||
compile_commands.json
 | 
			
		||||
libwizapp.so
 | 
			
		||||
@@ -17,11 +17,11 @@
 | 
			
		||||
#define f64 double
 | 
			
		||||
#define f128 long double
 | 
			
		||||
 | 
			
		||||
#define INTERNAL static
 | 
			
		||||
#define PERSISTENT static
 | 
			
		||||
#define internal static
 | 
			
		||||
#define persistent static
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
#define CLASS_MEMBER static
 | 
			
		||||
#define class_mem static
 | 
			
		||||
#endif // __cplusplus
 | 
			
		||||
 | 
			
		||||
#endif // !ALIASES_H
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										16
									
								
								compile
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										16
									
								
								compile
									
									
									
									
									
										Executable file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
#!/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,13 +6,12 @@
 | 
			
		||||
#define NUMPARTS(...)                                                          \
 | 
			
		||||
  (sizeof((const char *[]){"", __VA_ARGS__}) / sizeof(const char *) - 1)
 | 
			
		||||
 | 
			
		||||
#define JOIN_PATH(DST, ...) join_path(DST, NUMPARTS(__VA_ARGS__), __VA_ARGS__)
 | 
			
		||||
#define cpath_join_path(DST, ...)                                              \
 | 
			
		||||
  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, ...);
 | 
			
		||||
 | 
			
		||||
#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);
 | 
			
		||||
 | 
			
		||||
#endif // !PATH_UTILS_H
 | 
			
		||||
 
 | 
			
		||||
@@ -5,9 +5,9 @@
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#if defined(__unix__) || defined(__APPLE__) || defined(__ANDROID__)
 | 
			
		||||
INTERNAL char path_sep = '/';
 | 
			
		||||
internal char path_sep = '/';
 | 
			
		||||
#elif defined(_WIN32) || defined(_WIN64)
 | 
			
		||||
INTERNAL char path_sep = '\\';
 | 
			
		||||
internal char path_sep = '\\';
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
void join_root_and_leaf(const char *root, const char *leaf, char *dst);
 | 
			
		||||
@@ -32,7 +32,10 @@ void dirup(char *dst, u64 levels, const char *path) {
 | 
			
		||||
  u64 end_index = 0;
 | 
			
		||||
  u64 sep_count = 0;
 | 
			
		||||
 | 
			
		||||
  u64 length = strlen(path);
 | 
			
		||||
  u64 full_length;
 | 
			
		||||
  u64 length;
 | 
			
		||||
  length = full_length = strlen(path);
 | 
			
		||||
 | 
			
		||||
  if (path[length - 1] == path_sep) {
 | 
			
		||||
    --length;
 | 
			
		||||
  }
 | 
			
		||||
@@ -52,7 +55,13 @@ void dirup(char *dst, u64 levels, const char *path) {
 | 
			
		||||
    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);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void join_root_and_leaf(const char *root, const char *leaf, char *dst) {
 | 
			
		||||
 
 | 
			
		||||
@@ -3,20 +3,20 @@
 | 
			
		||||
 | 
			
		||||
#include "aliases.h"
 | 
			
		||||
 | 
			
		||||
typedef struct dstring dstr_t;
 | 
			
		||||
typedef struct dstr String;
 | 
			
		||||
 | 
			
		||||
dstr_t *dstr_with_capacity(u64 capacity);
 | 
			
		||||
dstr_t *dstr_from_string(const char *str);
 | 
			
		||||
void dstr_update(dstr_t **dst, const char *src);
 | 
			
		||||
void dstr_free(dstr_t **str);
 | 
			
		||||
void dstr_concat(dstr_t **dst, const char *src);
 | 
			
		||||
void dstr_append(dstr_t **dst, char c);
 | 
			
		||||
void dstr_resize(dstr_t **str);
 | 
			
		||||
void dstr_clear(dstr_t *str);
 | 
			
		||||
void dstr_print(const dstr_t *str);
 | 
			
		||||
i64 dstr_find(const dstr_t *str, const char *substr);
 | 
			
		||||
u64 dstr_length(const dstr_t *str);
 | 
			
		||||
u64 dstr_capacity(const dstr_t *str);
 | 
			
		||||
const char *dstr_to_cstr(const dstr_t *str);
 | 
			
		||||
String *dstr_with_capacity(u64 capacity);
 | 
			
		||||
String *dstr_from_string(const char *str);
 | 
			
		||||
void dstr_update(String **dst, const char *src);
 | 
			
		||||
void dstr_free(String **str);
 | 
			
		||||
void dstr_concat(String **dst, const char *src);
 | 
			
		||||
void dstr_append(String **dst, char c);
 | 
			
		||||
void dstr_resize(String **str);
 | 
			
		||||
void dstr_clear(String *str);
 | 
			
		||||
void dstr_print(const String *str);
 | 
			
		||||
i64 dstr_find(const String *str, const char *substr);
 | 
			
		||||
u64 dstr_length(const String *str);
 | 
			
		||||
u64 dstr_capacity(const String *str);
 | 
			
		||||
const char *dstr_to_cstr(const String *str);
 | 
			
		||||
 | 
			
		||||
#endif // !DSTR_H
 | 
			
		||||
 
 | 
			
		||||
@@ -8,14 +8,14 @@
 | 
			
		||||
// constantly reallocate
 | 
			
		||||
#define CAPACITY_SCALAR 8
 | 
			
		||||
 | 
			
		||||
struct dstring {
 | 
			
		||||
struct dstr {
 | 
			
		||||
  u64 capacity;
 | 
			
		||||
  u64 size;
 | 
			
		||||
  char buf[];
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
dstr_t *dstr_with_capacity(u64 capacity) {
 | 
			
		||||
  dstr_t *out = (dstr_t *)malloc(sizeof(dstr_t) + capacity + 1);
 | 
			
		||||
String *dstr_with_capacity(u64 capacity) {
 | 
			
		||||
  String *out = (String *)malloc(sizeof(String) + capacity + 1);
 | 
			
		||||
 | 
			
		||||
  if (!out) {
 | 
			
		||||
    return NULL;
 | 
			
		||||
@@ -28,7 +28,7 @@ dstr_t *dstr_with_capacity(u64 capacity) {
 | 
			
		||||
  return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
dstr_t *dstr_from_string(const char *str) {
 | 
			
		||||
String *dstr_from_string(const char *str) {
 | 
			
		||||
  if (!str) {
 | 
			
		||||
    return NULL;
 | 
			
		||||
  }
 | 
			
		||||
@@ -37,7 +37,7 @@ dstr_t *dstr_from_string(const char *str) {
 | 
			
		||||
 | 
			
		||||
  u64 capacity = length * CAPACITY_SCALAR;
 | 
			
		||||
 | 
			
		||||
  dstr_t *out = dstr_with_capacity(capacity);
 | 
			
		||||
  String *out = dstr_with_capacity(capacity);
 | 
			
		||||
 | 
			
		||||
  if (!out) {
 | 
			
		||||
    return NULL;
 | 
			
		||||
@@ -49,14 +49,14 @@ dstr_t *dstr_from_string(const char *str) {
 | 
			
		||||
  return out;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dstr_update(dstr_t **dst, const char *src) {
 | 
			
		||||
void dstr_update(String **dst, const char *src) {
 | 
			
		||||
  if (!dst || !(*dst)) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  u64 length = strlen(src);
 | 
			
		||||
 | 
			
		||||
  dstr_t *str = *dst;
 | 
			
		||||
  String *str = *dst;
 | 
			
		||||
 | 
			
		||||
  if (length <= str->capacity) {
 | 
			
		||||
    memset(str->buf, 0, str->capacity);
 | 
			
		||||
@@ -67,7 +67,7 @@ void dstr_update(dstr_t **dst, const char *src) {
 | 
			
		||||
  } else {
 | 
			
		||||
    u64 capacity = length * CAPACITY_SCALAR;
 | 
			
		||||
 | 
			
		||||
    dstr_t *tmp = (dstr_t *)realloc(*dst, sizeof(dstr_t) + capacity + 1);
 | 
			
		||||
    String *tmp = (String *)realloc(*dst, sizeof(String) + capacity + 1);
 | 
			
		||||
 | 
			
		||||
    if (!tmp) {
 | 
			
		||||
      return;
 | 
			
		||||
@@ -81,7 +81,7 @@ void dstr_update(dstr_t **dst, const char *src) {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dstr_free(dstr_t **str) {
 | 
			
		||||
void dstr_free(String **str) {
 | 
			
		||||
  if (!str || !(*str)) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
@@ -90,7 +90,7 @@ void dstr_free(dstr_t **str) {
 | 
			
		||||
  *str = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dstr_concat(dstr_t **dst, const char *src) {
 | 
			
		||||
void dstr_concat(String **dst, const char *src) {
 | 
			
		||||
  if (!dst || !(*dst)) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
@@ -112,7 +112,7 @@ void dstr_concat(dstr_t **dst, const char *src) {
 | 
			
		||||
  dstr_update(dst, str);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dstr_append(dstr_t **dst, char c) {
 | 
			
		||||
void dstr_append(String **dst, char c) {
 | 
			
		||||
  if (!dst || !(*dst)) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
@@ -128,14 +128,14 @@ void dstr_append(dstr_t **dst, char c) {
 | 
			
		||||
  dstr_update(dst, str);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dstr_resize(dstr_t **str) {
 | 
			
		||||
void dstr_resize(String **str) {
 | 
			
		||||
  if (!str || !(*str)) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  u64 capacity = (*str)->size;
 | 
			
		||||
 | 
			
		||||
  dstr_t *tmp = (dstr_t *)realloc(*str, sizeof(dstr_t) + capacity + 1);
 | 
			
		||||
  String *tmp = (String *)realloc(*str, sizeof(String) + capacity + 1);
 | 
			
		||||
 | 
			
		||||
  if (!tmp) {
 | 
			
		||||
    return;
 | 
			
		||||
@@ -146,7 +146,7 @@ void dstr_resize(dstr_t **str) {
 | 
			
		||||
  *str = tmp;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dstr_clear(dstr_t *str) {
 | 
			
		||||
void dstr_clear(String *str) {
 | 
			
		||||
  if (!str || str->size == 0) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
@@ -155,7 +155,7 @@ void dstr_clear(dstr_t *str) {
 | 
			
		||||
  str->size = 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void dstr_print(const dstr_t *str) {
 | 
			
		||||
void dstr_print(const String *str) {
 | 
			
		||||
  if (!str) {
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
@@ -163,7 +163,7 @@ void dstr_print(const dstr_t *str) {
 | 
			
		||||
  printf("%s\n", str->buf);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
i64 dstr_find(const dstr_t *str, const char *substr) {
 | 
			
		||||
i64 dstr_find(const String *str, const char *substr) {
 | 
			
		||||
  if (!str || !substr) {
 | 
			
		||||
    return -1;
 | 
			
		||||
  }
 | 
			
		||||
@@ -194,7 +194,7 @@ i64 dstr_find(const dstr_t *str, const char *substr) {
 | 
			
		||||
  return -1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
u64 dstr_length(const dstr_t *str) {
 | 
			
		||||
u64 dstr_length(const String *str) {
 | 
			
		||||
  if (!str) {
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
@@ -202,7 +202,7 @@ u64 dstr_length(const dstr_t *str) {
 | 
			
		||||
  return str->size;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
u64 dstr_capacity(const dstr_t *str) {
 | 
			
		||||
u64 dstr_capacity(const String *str) {
 | 
			
		||||
  if (!str) {
 | 
			
		||||
    return 0;
 | 
			
		||||
  }
 | 
			
		||||
@@ -210,7 +210,7 @@ u64 dstr_capacity(const dstr_t *str) {
 | 
			
		||||
  return str->capacity;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const char *dstr_to_cstr(const dstr_t *str) {
 | 
			
		||||
const char *dstr_to_cstr(const String *str) {
 | 
			
		||||
  if (!str) {
 | 
			
		||||
    return "";
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user