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 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_MEMBER static
 | 
					#define class_mem static
 | 
				
			||||||
#endif // __cplusplus
 | 
					#endif // __cplusplus
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // !ALIASES_H
 | 
					#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(...)                                                          \
 | 
					#define NUMPARTS(...)                                                          \
 | 
				
			||||||
  (sizeof((const char *[]){"", __VA_ARGS__}) / sizeof(const char *) - 1)
 | 
					  (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, ...);
 | 
					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,7 +32,10 @@ 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 length = strlen(path);
 | 
					  u64 full_length;
 | 
				
			||||||
 | 
					  u64 length;
 | 
				
			||||||
 | 
					  length = full_length = strlen(path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (path[length - 1] == path_sep) {
 | 
					  if (path[length - 1] == path_sep) {
 | 
				
			||||||
    --length;
 | 
					    --length;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -52,7 +55,13 @@ void dirup(char *dst, u64 levels, const char *path) {
 | 
				
			|||||||
    end_index = 0;
 | 
					    end_index = 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  strncpy(dst, path, end_index);
 | 
					  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) {
 | 
					void join_root_and_leaf(const char *root, const char *leaf, char *dst) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,20 +3,20 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#include "aliases.h"
 | 
					#include "aliases.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
typedef struct dstring dstr_t;
 | 
					typedef struct dstr String;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dstr_t *dstr_with_capacity(u64 capacity);
 | 
					String *dstr_with_capacity(u64 capacity);
 | 
				
			||||||
dstr_t *dstr_from_string(const char *str);
 | 
					String *dstr_from_string(const char *str);
 | 
				
			||||||
void dstr_update(dstr_t **dst, const char *src);
 | 
					void dstr_update(String **dst, const char *src);
 | 
				
			||||||
void dstr_free(dstr_t **str);
 | 
					void dstr_free(String **str);
 | 
				
			||||||
void dstr_concat(dstr_t **dst, const char *src);
 | 
					void dstr_concat(String **dst, const char *src);
 | 
				
			||||||
void dstr_append(dstr_t **dst, char c);
 | 
					void dstr_append(String **dst, char c);
 | 
				
			||||||
void dstr_resize(dstr_t **str);
 | 
					void dstr_resize(String **str);
 | 
				
			||||||
void dstr_clear(dstr_t *str);
 | 
					void dstr_clear(String *str);
 | 
				
			||||||
void dstr_print(const dstr_t *str);
 | 
					void dstr_print(const String *str);
 | 
				
			||||||
i64 dstr_find(const dstr_t *str, const char *substr);
 | 
					i64 dstr_find(const String *str, const char *substr);
 | 
				
			||||||
u64 dstr_length(const dstr_t *str);
 | 
					u64 dstr_length(const String *str);
 | 
				
			||||||
u64 dstr_capacity(const dstr_t *str);
 | 
					u64 dstr_capacity(const String *str);
 | 
				
			||||||
const char *dstr_to_cstr(const dstr_t *str);
 | 
					const char *dstr_to_cstr(const String *str);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // !DSTR_H
 | 
					#endif // !DSTR_H
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,14 +8,14 @@
 | 
				
			|||||||
// constantly reallocate
 | 
					// constantly reallocate
 | 
				
			||||||
#define CAPACITY_SCALAR 8
 | 
					#define CAPACITY_SCALAR 8
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct dstring {
 | 
					struct dstr {
 | 
				
			||||||
  u64 capacity;
 | 
					  u64 capacity;
 | 
				
			||||||
  u64 size;
 | 
					  u64 size;
 | 
				
			||||||
  char buf[];
 | 
					  char buf[];
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dstr_t *dstr_with_capacity(u64 capacity) {
 | 
					String *dstr_with_capacity(u64 capacity) {
 | 
				
			||||||
  dstr_t *out = (dstr_t *)malloc(sizeof(dstr_t) + capacity + 1);
 | 
					  String *out = (String *)malloc(sizeof(String) + capacity + 1);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!out) {
 | 
					  if (!out) {
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
@@ -28,7 +28,7 @@ dstr_t *dstr_with_capacity(u64 capacity) {
 | 
				
			|||||||
  return out;
 | 
					  return out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
dstr_t *dstr_from_string(const char *str) {
 | 
					String *dstr_from_string(const char *str) {
 | 
				
			||||||
  if (!str) {
 | 
					  if (!str) {
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -37,7 +37,7 @@ dstr_t *dstr_from_string(const char *str) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  u64 capacity = length * CAPACITY_SCALAR;
 | 
					  u64 capacity = length * CAPACITY_SCALAR;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  dstr_t *out = dstr_with_capacity(capacity);
 | 
					  String *out = dstr_with_capacity(capacity);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!out) {
 | 
					  if (!out) {
 | 
				
			||||||
    return NULL;
 | 
					    return NULL;
 | 
				
			||||||
@@ -49,14 +49,14 @@ dstr_t *dstr_from_string(const char *str) {
 | 
				
			|||||||
  return out;
 | 
					  return out;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void dstr_update(dstr_t **dst, const char *src) {
 | 
					void dstr_update(String **dst, const char *src) {
 | 
				
			||||||
  if (!dst || !(*dst)) {
 | 
					  if (!dst || !(*dst)) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  u64 length = strlen(src);
 | 
					  u64 length = strlen(src);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  dstr_t *str = *dst;
 | 
					  String *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(dstr_t **dst, const char *src) {
 | 
				
			|||||||
  } else {
 | 
					  } else {
 | 
				
			||||||
    u64 capacity = length * CAPACITY_SCALAR;
 | 
					    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) {
 | 
					    if (!tmp) {
 | 
				
			||||||
      return;
 | 
					      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)) {
 | 
					  if (!str || !(*str)) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -90,7 +90,7 @@ void dstr_free(dstr_t **str) {
 | 
				
			|||||||
  *str = NULL;
 | 
					  *str = NULL;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void dstr_concat(dstr_t **dst, const char *src) {
 | 
					void dstr_concat(String **dst, const char *src) {
 | 
				
			||||||
  if (!dst || !(*dst)) {
 | 
					  if (!dst || !(*dst)) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -112,7 +112,7 @@ void dstr_concat(dstr_t **dst, const char *src) {
 | 
				
			|||||||
  dstr_update(dst, str);
 | 
					  dstr_update(dst, str);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void dstr_append(dstr_t **dst, char c) {
 | 
					void dstr_append(String **dst, char c) {
 | 
				
			||||||
  if (!dst || !(*dst)) {
 | 
					  if (!dst || !(*dst)) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -128,14 +128,14 @@ void dstr_append(dstr_t **dst, char c) {
 | 
				
			|||||||
  dstr_update(dst, str);
 | 
					  dstr_update(dst, str);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void dstr_resize(dstr_t **str) {
 | 
					void dstr_resize(String **str) {
 | 
				
			||||||
  if (!str || !(*str)) {
 | 
					  if (!str || !(*str)) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  u64 capacity = (*str)->size;
 | 
					  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) {
 | 
					  if (!tmp) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
@@ -146,7 +146,7 @@ void dstr_resize(dstr_t **str) {
 | 
				
			|||||||
  *str = tmp;
 | 
					  *str = tmp;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void dstr_clear(dstr_t *str) {
 | 
					void dstr_clear(String *str) {
 | 
				
			||||||
  if (!str || str->size == 0) {
 | 
					  if (!str || str->size == 0) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -155,7 +155,7 @@ void dstr_clear(dstr_t *str) {
 | 
				
			|||||||
  str->size = 0;
 | 
					  str->size = 0;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void dstr_print(const dstr_t *str) {
 | 
					void dstr_print(const String *str) {
 | 
				
			||||||
  if (!str) {
 | 
					  if (!str) {
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -163,7 +163,7 @@ void dstr_print(const dstr_t *str) {
 | 
				
			|||||||
  printf("%s\n", str->buf);
 | 
					  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) {
 | 
					  if (!str || !substr) {
 | 
				
			||||||
    return -1;
 | 
					    return -1;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -194,7 +194,7 @@ i64 dstr_find(const dstr_t *str, const char *substr) {
 | 
				
			|||||||
  return -1;
 | 
					  return -1;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
u64 dstr_length(const dstr_t *str) {
 | 
					u64 dstr_length(const String *str) {
 | 
				
			||||||
  if (!str) {
 | 
					  if (!str) {
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -202,7 +202,7 @@ u64 dstr_length(const dstr_t *str) {
 | 
				
			|||||||
  return str->size;
 | 
					  return str->size;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
u64 dstr_capacity(const dstr_t *str) {
 | 
					u64 dstr_capacity(const String *str) {
 | 
				
			||||||
  if (!str) {
 | 
					  if (!str) {
 | 
				
			||||||
    return 0;
 | 
					    return 0;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -210,7 +210,7 @@ u64 dstr_capacity(const dstr_t *str) {
 | 
				
			|||||||
  return str->capacity;
 | 
					  return str->capacity;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const char *dstr_to_cstr(const dstr_t *str) {
 | 
					const char *dstr_to_cstr(const String *str) {
 | 
				
			||||||
  if (!str) {
 | 
					  if (!str) {
 | 
				
			||||||
    return "";
 | 
					    return "";
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user