Compare commits

...

15 Commits

Author SHA1 Message Date
d70888f9fb remove __attribute__((fallthrough)) from all that do not require it. Replace with // fall through in some places for readability 2025-07-24 16:32:41 +02:00
6dbf034ba1 add marker so I remember to add this back in 2025-07-24 16:29:03 +02:00
1ea37b6e86 fix: there is no need to let the compilation continue if it fails.
it actually makes it less easy to locate errors.
2025-07-24 16:29:03 +02:00
f3273ed5d0 fix: include my endian.h in nbt.h 2025-07-24 16:29:03 +02:00
6ccb55de8b remove unused function nbt_cmpstr, since we're performing this check directly now. 2025-07-24 16:29:03 +02:00
69dc174ff2 remove nbt_arrlen function 2025-07-24 16:29:03 +02:00
58d0dd01e2 move nbt_strlen to nbt.h, and rename to nbt_namelen 2025-07-24 16:29:03 +02:00
4005163d61 fix: use atrb_pure for functions reading global state 2025-07-24 16:29:03 +02:00
8964a1a563 fix: atrb for when _MSC_VER is defined did not have parameters 2025-07-24 16:29:03 +02:00
f0c5408c51 fix: error.h should exit with EXIT_FAILURE, rather than 1 2025-07-24 16:29:03 +02:00
1d5df8df0a apply new formatting rules to the whole project 2025-07-24 16:29:03 +02:00
cdf13b7529 change qualifier alignment to be left again 2025-07-24 16:28:25 +02:00
13e1ceddfc update nbt_proc function, still inoperable 2025-07-24 16:28:25 +02:00
333417dadd add funciton for data loading/processing 2025-07-24 16:28:25 +02:00
fd8db02e77 modify the array bytelength function to get the bytelength of a single tag. 2025-07-24 16:28:25 +02:00
16 changed files with 154 additions and 115 deletions

View File

@@ -87,7 +87,7 @@ BinPackArguments: true
DerivePointerAlignment: false DerivePointerAlignment: false
PointerAlignment: Right PointerAlignment: Right
ReferenceAlignment: Pointer ReferenceAlignment: Pointer
QualifierAlignment: Right QualifierAlignment: Left
# --------------------------- # ---------------------------
# include settings and sorting # include settings and sorting

View File

@@ -43,11 +43,7 @@ jobs:
git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT" git clone https://github.com/microsoft/vcpkg.git "$VCPKG_ROOT"
"$VCPKG_ROOT/bootstrap-vcpkg.sh" "$VCPKG_ROOT/bootstrap-vcpkg.sh"
"$VCPKG_ROOT/vcpkg" install $DEPS_VCPKG "$VCPKG_ROOT/vcpkg" install $DEPS_VCPKG
# compilation (using bulk compilation) - name: compilation (using bulk compilation)
- run: make all CALL=compile -j || echo "JOB_FAILED=1" >>"$GITHUB_ENV" run: make all CALL=compile -j
# executing unit tests (using bulk flags) - name: unit tests (using bulk flags)
- run: make all CALL=run DEBUG=test -j || echo "JOB_FAILED=1" >>"$GITHUB_ENV" run: make all CALL=run DEBUG=test -j
# exit if any errors occurred
- name: exit on errors
run: |
[ "$JOB_FAILED" != "1" ]

View File

@@ -1,124 +1,147 @@
#include "nbt.h" #include "nbt.h"
#include <assert.h>
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include "../util/compat/endian.h" #include "../util/compat/endian.h"
#include "../util/types.h" #include "../util/types.h"
/* returns the string length from a specific location in the buffer */ const u8 *nbt_nexttag(const u8 *restrict buf, u16 naml) {
static inline u16 nbt_strlen(u8 const *restrict buf) { size_t len = nbt_tagdatlen(buf);
return be16toh(*(u16 *)(buf)); if (!len) return NULL; // TODO: compound tags should be handled here
return buf + naml + len + 3;
} }
/* returns the length of an array from a specific location in the buffer */ // TODO: not actually doing anything
static inline i32 nbt_arrlen(u8 const *restrict buf) { /* readies the output data for export, returns the new buffer position, or `NULL` upon an error (may be out of bounds) */
return be32toh(*(i32 *)(buf)); static const u8 *nbt_proctag(const u8 *restrict buf, u16 slen) {
} const u8 *ptr = buf + 3 + slen;
u8 dat[8];
/* compares the string in `buf` to `matstr`. size_t arrlen = 0;
* returns `=0` if equal, `>0` if buf is greater, `<0` if matstr is greater. */
static int nbt_cmpstr(char const *restrict matstr, u8 const *restrict buf) {
u16 len = nbt_strlen(buf);
// allocate and copy bytes
char str[len + 1];
memcpy(str, buf + 2, len);
str[len] = '\0';
return strncmp(str, matstr, len);
}
/* acquires the array's byte size (excluding name + size spec)
* returns `0` upon failure */
static size_t nbt_arrbsize(u8 const *restrict buf) {
i32 mems = 0;
switch (*buf) { switch (*buf) {
case NBT_ARR_I64: mems += sizeof(i64) - sizeof(i32); __attribute__((fallthrough)); // integral types
case NBT_ARR_I32: mems += sizeof(i32) - sizeof(i8); __attribute__((fallthrough)); case NBT_I8: *dat = *ptr; return ptr;
case NBT_ARR_I8: return +mems * nbt_arrlen(buf); // mems+1 multiplied by the array length case NBT_I16: *(u16 *)dat = be16toh(*(u16 *)ptr); return ptr + 2;
case NBT_I32: // fall through
case NBT_STR: return nbt_strlen(buf); case NBT_F32: *(u32 *)dat = be16toh(*(u32 *)ptr); return ptr + 4;
case NBT_I64: // fall through
case NBT_F64: *(u64 *)dat = be16toh(*(u64 *)ptr); return ptr + 8;
// arrays, handled differently
case NBT_LIST: case NBT_LIST:
mems = nbt_primsize(*buf); case NBT_ARR_I8:
if (mems > 0) return mems * nbt_arrlen(buf + 1); case NBT_STR:
return 0; case NBT_ARR_I32:
default: return 0; case NBT_ARR_I64:
// TODO: arrlen = nbt_arrbsize(ptr);
break;
default: return NULL;
} }
if (!arrlen) return NULL;
return ptr + nbt_primsize(*buf);
} }
/* returns the (expected) pointer of the tag following this one. /* finds which of `pats` is equivalent to `cmp`, assumes `cmp` is `≥len` bytes long */
* `NBT_COMPOUND` and `NBT_END` tags are not valid for this function and should be handled separately. static const char *getpat(struct nbt_path const *restrict pats, uint npats, i16 dpt, const char *restrict cmp, u16 len) {
* `NULL` is returned if anything went wrong. */ for (uint i = 0; i < npats; i++) {
static u8 const *nbt_nexttag(u8 const *restrict buf) { if (strncmp(pats[i].pat[dpt], cmp, len) == 0)
u8 const *nxt = buf + 1; return pats[i].pat[dpt];
nxt += nbt_strlen(nxt) + 2;
i32 tmp;
switch (*buf) {
case NBT_I8: __attribute__((fallthrough));
case NBT_I16: __attribute__((fallthrough));
case NBT_I32: __attribute__((fallthrough));
case NBT_I64: __attribute__((fallthrough));
case NBT_F32: __attribute__((fallthrough));
case NBT_F64:
tmp = nbt_primsize(*buf);
return (tmp >= 0) ? (nxt + tmp) : 0;
case NBT_LIST: nxt += 5; break;
case NBT_STR: nxt += 2; break;
case NBT_ARR_I8: __attribute__((fallthrough));
case NBT_ARR_I32: __attribute__((fallthrough));
case NBT_ARR_I64: nxt += 4; break;
default: return NULL; // failure on compound/end tags; these require more nuanced logic
} }
return NULL;
tmp = nbt_arrbsize(buf);
return (tmp >= 0) ? (nxt + tmp) : NULL;
} }
// TODO: make the user do the looping
int nbt_proc(struct nbt_path const *restrict pats, uint npats, const u8 *restrict buf, size_t len) {
// ensure first and last tag(s) are valid
if (buf[0] != NBT_COMPOUND || buf[len - 1] != NBT_END)
return 1;
default: return NULL; // failure on compound/end tags; these require more nuanced logic i16 dpt = 0;
i16 mdpt = 0;
// acquire the maximum depth that we'll need to go (exclusive)
for (uint i = 0; i < npats; i++) {
int tmp = pats[i].len - mdpt;
mdpt += -(tmp > 0) & tmp;
} }
} assert(mdpt > 0);
int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len) { // storing the segments of the current path
const char *cpat[mdpt - 1];
memset((void *)cpat, 0, mdpt - 1);
// first byte should be a compound tag // looping through the different tags
if (*buf != NBT_COMPOUND) return 1; const u8 *ptr = buf + nbt_namelen(buf) + 3;
uint ncomp = 1; while (ptr < (buf + len) && dpt >= 0) {
u16 naml = nbt_namelen(ptr);
const char *mat = getpat(pats, npats, dpt, (char *)(ptr + 3), naml);
cpat[dpt] = mat;
// ignore the first tag + its name, so we start with the juicy data if (mat) {
uint tmp = nbt_strlen(buf + 1) + 3; switch (*ptr) {
buf += tmp; case NBT_END: dpt--; break;
len -= tmp; case NBT_COMPOUND: dpt++; break;
default: ptr = nbt_proctag(ptr, naml); break;
}
} else {
ptr = nbt_nexttag(ptr, naml);
if (!ptr) return 1;
}
}
// TODO: finish function // TODO: finish function
return 0; return !dpt;
} }
int nbt_primsize(u8 tag) { int nbt_primsize(u8 tag) {
switch (tag) { switch (tag) {
case NBT_I8: return 1; case NBT_I8: return 1;
case NBT_I16: return 2; case NBT_I16: return 2;
case NBT_I32: __attribute__((fallthrough)); case NBT_I32: // fall through
case NBT_F32: return 4; case NBT_F32: return 4;
case NBT_I64: __attribute__((fallthrough)); case NBT_I64: // fall through
case NBT_F64: return 8; case NBT_F64: return 8;
default: return -1; default: return -1;
} }
} }
size_t nbt_tagdatlen(const u8 *restrict buf) {
size_t mems = 0;
switch (*buf) {
case NBT_I8:
case NBT_I16:
case NBT_I32:
case NBT_F32:
case NBT_I64:
case NBT_F64:
mems = nbt_primsize(*buf);
return -(mems >= 0) & mems;
case NBT_ARR_I64: mems += sizeof(i64) - sizeof(i32); __attribute__((fallthrough));
case NBT_ARR_I32: mems += sizeof(i32) - sizeof(i8); __attribute__((fallthrough));
case NBT_ARR_I8: return +mems * (i32)be32toh(*(u32 *)(buf)) + 4;
case NBT_STR: return be16toh(*(u16 *)buf) + 2;
case NBT_LIST:
mems = nbt_primsize(*buf);
if (mems > 0) return mems * (i32)be32toh(*(u32 *)(buf + 1)) + 5;
return 0;
default: return 0;
}
}
int nbt_isprim(u8 tag) { int nbt_isprim(u8 tag) {
switch (tag) { switch (tag) {
case NBT_I8: __attribute__((fallthrough)); case NBT_I8:
case NBT_I16: __attribute__((fallthrough)); case NBT_I16:
case NBT_I32: __attribute__((fallthrough)); case NBT_I32:
case NBT_F32: __attribute__((fallthrough)); case NBT_F32:
case NBT_I64: __attribute__((fallthrough)); case NBT_I64:
case NBT_F64: case NBT_F64:
return 1; return 1;
default: default:

View File

@@ -2,10 +2,12 @@
// Licensed under the MIT Licence. See LICENSE for details // Licensed under the MIT Licence. See LICENSE for details
#pragma once #pragma once
#include <assert.h>
#include <stdbool.h> #include <stdbool.h>
#include <stdlib.h> #include <stdlib.h>
#include "../util/atrb.h" #include "../util/atrb.h"
#include "../util/compat/endian.h"
#include "../util/types.h" #include "../util/types.h"
/* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload. /* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload.
@@ -34,12 +36,30 @@ enum nbt_tagid {
NBT_ARR_I64 = 0x0C, // starts with a i32, denoting size, followed by the u32 data NBT_ARR_I64 = 0x0C, // starts with a i32, denoting size, followed by the u32 data
}; };
int nbt_proc(void **restrict datout, u8 const *restrict buf, size_t len); struct nbt_path {
const char **restrict pat; // specifies the NBT path components as separate elements
i16 len; // specifies the length of the NBT elements
};
/* returns the name length of a specific tag. `buf` is the pointer to start of the tag */
atrb_pure atrb_nonnull(1) static inline u16 nbt_namelen(const u8 *restrict buf) {
assert(*buf != NBT_END);
return be16toh(*(u16 *)(buf + 1));
}
/* returns the (expected) pointer of the tag following this one.
* `NULL` is returned if anything went wrong. */
atrb_pure atrb_nonnull(1) const u8 *nbt_nexttag(const u8 *restrict buf, u16 naml);
/* checks whether the tag is a primitive data tag. (not recommended for filtering tags, use a `switch`) /* checks whether the tag is a primitive data tag. (not recommended for filtering tags, use a `switch`)
* returns a boolean value. */ * returns a boolean value. */
atrb_const int nbt_isprim(u8 tag); atrb_const int nbt_isprim(u8 tag);
/* gets the byte size of an NBT tag's data (excluding id and name), returns `0` upon error. */
atrb_pure size_t nbt_tagdatlen(const u8 *buf);
/* gets the tag size of primitive types, returns `>0` on success, `<0` on failure */ /* gets the tag size of primitive types, returns `>0` on success, `<0` on failure */
atrb_const int nbt_primsize(u8 tag); atrb_const int nbt_primsize(u8 tag);
/* processes the uncompressed `NBT` data in `buf`, with a size of `len`. */
atrb_nonnull(1, 3) int nbt_proc(struct nbt_path const *restrict paths, uint npaths, const u8 *restrict buf, size_t len);

View File

@@ -17,5 +17,5 @@
#define fatal(s, ...) \ #define fatal(s, ...) \
do { \ do { \
printf("\033[101m" __FILE__ ":" MACRO_STR2(__LINE__) ": [FAT]: " s "\033[0m\n", ##__VA_ARGS__); \ printf("\033[101m" __FILE__ ":" MACRO_STR2(__LINE__) ": [FAT]: " s "\033[0m\n", ##__VA_ARGS__); \
exit(1); \ exit(EXIT_FAILURE); \
} while (0) } while (0)

View File

@@ -4,7 +4,7 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
void key_callback(GLFWwindow* win, int key, int scancode, int action, int mods) { void key_callback(GLFWwindow *win, int key, int scancode, int action, int mods) {
(void)win, (void)key, (void)scancode, (void)action, (void)mods; // make the compiler shut up as this is fine (void)win, (void)key, (void)scancode, (void)action, (void)mods; // make the compiler shut up as this is fine
#ifndef NDEBUG #ifndef NDEBUG
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)

View File

@@ -4,4 +4,4 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
void key_callback(GLFWwindow* win, int key, int scancode, int action, int mods); void key_callback(GLFWwindow *win, int key, int scancode, int action, int mods);

View File

@@ -7,4 +7,4 @@
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
int render_init(void); int render_init(void);
void render_update(GLFWwindow* win); void render_update(GLFWwindow *win);

View File

@@ -12,7 +12,7 @@
#define NAM_E(name) _binary_res_##name##_end // name of an end variable #define NAM_E(name) _binary_res_##name##_end // name of an end variable
// macro for generating the variable declarations // macro for generating the variable declarations
#define DEF_GLSL(name) \ #define DEF_GLSL(name) \
extern char const NAM_S(name)[]; \ extern char const NAM_S(name)[]; \
extern char const NAM_E(name)[] extern char const NAM_E(name)[]
@@ -24,7 +24,7 @@ DEF_GLSL(sh_geom_glsl);
// NOLINTEND // NOLINTEND
/* compile a shader */ /* compile a shader */
static GLuint shader_compile(GLenum type, char const* src, size_t len) { static GLuint shader_compile(GLenum type, const char *src, size_t len) {
int ilen = len; int ilen = len;
GLuint shader = glCreateShader(type); GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &src, &ilen); glShaderSource(shader, 1, &src, &ilen);

View File

@@ -16,7 +16,7 @@
#define WIN_DEFAULT_WIDTH 640 #define WIN_DEFAULT_WIDTH 640
#define WIN_DEFAULT_HEIGHT 480 #define WIN_DEFAULT_HEIGHT 480
static GLFWwindow* win = NULL; static GLFWwindow *win = NULL;
int window_init(void) { int window_init(void) {
#ifndef NDEBUG #ifndef NDEBUG

View File

@@ -17,7 +17,7 @@
#define WIN_DEFAULT_HEIGHT 480 #define WIN_DEFAULT_HEIGHT 480
// callback for GLFW errors // callback for GLFW errors
static void error_callback(int err, char const *const msg) { static void error_callback(int err, const char *const msg) {
fprintf(stderr, "\033[91mE: glfw returned (%i); \"%s\"\033[0m\n", err, msg); fprintf(stderr, "\033[91mE: glfw returned (%i); \"%s\"\033[0m\n", err, msg);
} }

View File

@@ -14,11 +14,11 @@
#define atrb_format(...) __attribute__((format(__VA_ARGS__))) #define atrb_format(...) __attribute__((format(__VA_ARGS__)))
#define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__))) #define atrb_nonnull(...) __attribute__((nonnull(__VA_ARGS__)))
#elif defined(_MSC_VER) #elif defined(_MSC_VER)
#define atrb __declspec #define atrb(...) __declspec(__VA_ARGS__)
#define atrb_deprecated __declspec(deprecated) #define atrb_deprecated __declspec(deprecated)
#define atrb_noreturn __declspec(noreturn) #define atrb_noreturn __declspec(noreturn)
#else #else
#define atrb #define atrb()
#define atrb_deprecated #define atrb_deprecated
#define atrb_unused #define atrb_unused
#define atrb_pure #define atrb_pure

View File

@@ -13,7 +13,7 @@
/* tests a files access with F_OK, X_OK, R_OK, W_OK OR'd together /* tests a files access with F_OK, X_OK, R_OK, W_OK OR'd together
returns 0 upon success. -1 when errno is set and anything else when one or more of the permissions isn't set */ returns 0 upon success. -1 when errno is set and anything else when one or more of the permissions isn't set */
static inline int faccess(char const *restrict fname, int perms); static inline int faccess(const char *restrict fname, int perms);
// define the constants if they haven't been // define the constants if they haven't been
#ifndef F_OK #ifndef F_OK

View File

@@ -41,7 +41,7 @@ struct conf_fstr {
/* defines the structure of a config file entry */ /* defines the structure of a config file entry */
struct conf_entry { struct conf_entry {
char const *key; // the key of this entry const char *key; // the key of this entry
void *out; // the pointer to which the data is written value is read if the given option is incorrect or missing void *out; // the pointer to which the data is written value is read if the given option is incorrect or missing
uint8_t type; // the primitive type which we are querying for uint8_t type; // the primitive type which we are querying for
}; };
@@ -51,15 +51,15 @@ struct conf_entry {
* `kout` and `vout` will contain a null-terminated string if the function returned successfully. * `kout` and `vout` will contain a null-terminated string if the function returned successfully.
* returns `0` on success, `<0` when no data was found. `>0` when data was invalid but something went wrong. * returns `0` on success, `<0` when no data was found. `>0` when data was invalid but something went wrong.
* see `CONF_E*` or `enum conf_err` */ * see `CONF_E*` or `enum conf_err` */
int conf_procbuf(char const *restrict buf, char *restrict kout, char *restrict vout, size_t len); int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict vout, size_t len);
/* matches the key with one of the options and returns the pointer. Returns NULL if none could be found. */ /* matches the key with one of the options and returns the pointer. Returns NULL if none could be found. */
struct conf_entry const *conf_matchopt(struct conf_entry const *opts, size_t optc, char const *restrict key); struct conf_entry const *conf_matchopt(struct conf_entry const *opts, size_t optc, const char *restrict key);
/* processes the value belonging to the key and outputs the result to opts. /* processes the value belonging to the key and outputs the result to opts.
* - `val` points to a null-terminated string which contains the key and value. * - `val` points to a null-terminated string which contains the key and value.
* returns `0` upon success, non-zero upon failure. For information about specific error codes, see `enum conf_err` */ * returns `0` upon success, non-zero upon failure. For information about specific error codes, see `enum conf_err` */
int conf_procval(struct conf_entry const *opts, char const *restrict val); int conf_procval(struct conf_entry const *opts, const char *restrict val);
/* acquires the config file path, appending str to the end (you need to handle path separators yourself) /* acquires the config file path, appending str to the end (you need to handle path separators yourself)
* expecting str to be null-terminated * expecting str to be null-terminated
@@ -67,4 +67,4 @@ int conf_procval(struct conf_entry const *opts, char const *restrict val);
* - windows: reads %APPDATA%, if empty %USERPROFILE%\AppData\Roaming is used, if both are empty NULL is returned. * - windows: reads %APPDATA%, if empty %USERPROFILE%\AppData\Roaming is used, if both are empty NULL is returned.
* - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL is returned. * - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL is returned.
* !! A malloc'd null-terminated string is returned !! */ * !! A malloc'd null-terminated string is returned !! */
atrb_malloc atrb_nonnull(1) char *conf_getpat(char const *); atrb_malloc atrb_nonnull(1) char *conf_getpat(const char *);

View File

@@ -19,7 +19,7 @@ struct test_getpat_envdat {
/* save the current environment variables */ /* save the current environment variables */
static void env_save(struct test_getpat_envdat *s) { static void env_save(struct test_getpat_envdat *s) {
char const *tmp; const char *tmp;
tmp = getenv("XDG_CONFIG_HOME"); tmp = getenv("XDG_CONFIG_HOME");
s->xdg_config_home = tmp ? strdup(tmp) : NULL; s->xdg_config_home = tmp ? strdup(tmp) : NULL;
@@ -64,9 +64,9 @@ static void env_restore(struct test_getpat_envdat *s) {
/* check procbuf's functionality */ /* check procbuf's functionality */
struct test_procbuf { struct test_procbuf {
char const *in; // data in const char *in; // data in
char const *xkey; // expected key const char *xkey; // expected key
char const *xval; // expected value const char *xval; // expected value
int xret; // expected return type int xret; // expected return type
}; };
int test_procbuf(void *arg) { int test_procbuf(void *arg) {
@@ -81,7 +81,7 @@ int test_procbuf(void *arg) {
/* check matchopt functionality */ /* check matchopt functionality */
struct test_matchopt { struct test_matchopt {
char const *key; // key to search for (key1, key2, key3) const char *key; // key to search for (key1, key2, key3)
int xidx; // expect index (<0 is NULL, may not be more than 2) int xidx; // expect index (<0 is NULL, may not be more than 2)
}; };
int test_matchopt(void *arg) { int test_matchopt(void *arg) {
@@ -96,7 +96,7 @@ int test_matchopt(void *arg) {
} }
struct test_procval_int { struct test_procval_int {
char const *val; const char *val;
u64 xres; u64 xres;
u8 type; u8 type;
}; };

View File

@@ -3,12 +3,12 @@
#pragma once #pragma once
#include <stdio.h> #include <stdio.h>
char const *test_ctest; const char *test_ctest;
size_t test_runs = 0; size_t test_runs = 0;
// evaluates the test // evaluates the test
// returns 1 upon error // returns 1 upon error
static inline int assert_helper(int cond, char const *restrict fname, unsigned ln, char const *restrict fnname, char const *restrict expr) { static inline int assert_helper(int cond, const char *restrict fname, unsigned ln, const char *restrict fnname, const char *restrict expr) {
test_runs++; test_runs++;
if (cond) if (cond)
printf("[\033[32;1m OK \033[0m] %s %s -> %s:%u (%s)\n", test_ctest, fnname, fname, ln, expr); printf("[\033[32;1m OK \033[0m] %s %s -> %s:%u (%s)\n", test_ctest, fnname, fname, ln, expr);
@@ -22,7 +22,7 @@ static inline int assert_helper(int cond, char const *restrict fname, unsigned l
// contains the data for executing a single test // contains the data for executing a single test
struct testdat { struct testdat {
char const *name; // test name const char *name; // test name
int (*test)(void *); // test, returns 0 upon success, non-zero upon failure int (*test)(void *); // test, returns 0 upon success, non-zero upon failure
void *args; // arguments to the test void *args; // arguments to the test
}; };