From 1d5df8df0a825ea6f6634c45fcf128af2bdce84f Mon Sep 17 00:00:00 2001 From: Quinn Date: Thu, 24 Jul 2025 11:40:12 +0200 Subject: [PATCH] apply new formatting rules to the whole project --- src/dat/nbt.c | 24 ++++++++++++------------ src/dat/nbt.h | 6 +++--- src/io/input.c | 2 +- src/io/input.h | 2 +- src/io/render.h | 2 +- src/io/shader.c | 4 ++-- src/io/window.c | 2 +- src/main.c | 2 +- src/util/compat/io.h | 2 +- src/util/conf.h | 10 +++++----- test/t_conf.h | 12 ++++++------ test/test.h | 6 +++--- 12 files changed, 37 insertions(+), 37 deletions(-) diff --git a/src/dat/nbt.c b/src/dat/nbt.c index 0f07f5e..934f476 100644 --- a/src/dat/nbt.c +++ b/src/dat/nbt.c @@ -8,18 +8,18 @@ #include "../util/types.h" /* returns the string length from a specific location in the buffer */ -static inline u16 nbt_strlen(u8 const *restrict buf) { +static inline u16 nbt_strlen(const u8 *restrict buf) { return be16toh(*(u16 *)(buf)); } /* returns the length of an array from a specific location in the buffer */ -static inline i32 nbt_arrlen(u8 const *restrict buf) { +static inline i32 nbt_arrlen(const u8 *restrict buf) { return be32toh(*(i32 *)(buf)); } /* compares the string in `buf` to `matstr`. * 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) { +static int nbt_cmpstr(const char *restrict matstr, const u8 *restrict buf) { u16 len = nbt_strlen(buf); // allocate and copy bytes @@ -32,7 +32,7 @@ static int nbt_cmpstr(char const *restrict matstr, u8 const *restrict buf) { /* returns the (expected) pointer of the tag following this one. * `NULL` is returned if anything went wrong. */ -static u8 const *nbt_nexttag(u8 const *restrict buf, u16 naml) { +static const u8 *nbt_nexttag(const u8 *restrict buf, u16 naml) { size_t len = nbt_tagdatlen(buf); if (!len) return NULL; // TODO: compound tags should be handled here return buf + naml + len + 3; @@ -40,8 +40,8 @@ static u8 const *nbt_nexttag(u8 const *restrict buf, u16 naml) { // TODO: not actually doing anything /* readies the output data for export, returns the new buffer position, or `NULL` upon an error (may be out of bounds) */ -static u8 const *nbt_proctag(u8 const *restrict buf, u16 slen) { - u8 const *ptr = buf + 3 + slen; +static const u8 *nbt_proctag(const u8 *restrict buf, u16 slen) { + const u8 *ptr = buf + 3 + slen; u8 dat[8]; size_t arrlen = 0; @@ -70,7 +70,7 @@ static u8 const *nbt_proctag(u8 const *restrict buf, u16 slen) { } /* finds which of `pats` is equivalent to `cmp`, assumes `cmp` is `≥len` bytes long */ -static char const *getpat(struct nbt_path const *restrict pats, uint npats, i16 dpt, char const *restrict cmp, u16 len) { +static const char *getpat(struct nbt_path const *restrict pats, uint npats, i16 dpt, const char *restrict cmp, u16 len) { for (uint i = 0; i < npats; i++) { if (strncmp(pats[i].pat[dpt], cmp, len) == 0) return pats[i].pat[dpt]; @@ -79,7 +79,7 @@ static char const *getpat(struct nbt_path const *restrict pats, uint npats, i16 } // TODO: make the user do the looping -int nbt_proc(struct nbt_path const *restrict pats, uint npats, u8 const *restrict buf, size_t len) { +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; @@ -95,14 +95,14 @@ int nbt_proc(struct nbt_path const *restrict pats, uint npats, u8 const *restric assert(mdpt > 0); // storing the segments of the current path - char const *cpat[mdpt - 1]; + const char *cpat[mdpt - 1]; memset((void *)cpat, 0, mdpt - 1); // looping through the different tags - u8 const *ptr = buf + nbt_strlen(buf + 1) + 3; + const u8 *ptr = buf + nbt_strlen(buf + 1) + 3; while (ptr < (buf + len) && dpt >= 0) { u16 naml = nbt_strlen(ptr + 1); - char const *mat = getpat(pats, npats, dpt, (char *)(ptr + 3), naml); + const char *mat = getpat(pats, npats, dpt, (char *)(ptr + 3), naml); cpat[dpt] = mat; if (mat) { @@ -133,7 +133,7 @@ int nbt_primsize(u8 tag) { } } -size_t nbt_tagdatlen(u8 const *restrict buf) { +size_t nbt_tagdatlen(const u8 *restrict buf) { size_t mems = 0; switch (*buf) { diff --git a/src/dat/nbt.h b/src/dat/nbt.h index 64892de..805dd8b 100644 --- a/src/dat/nbt.h +++ b/src/dat/nbt.h @@ -35,7 +35,7 @@ enum nbt_tagid { }; struct nbt_path { - char const **restrict pat; // specifies the NBT path components as separate elements + const char **restrict pat; // specifies the NBT path components as separate elements i16 len; // specifies the length of the NBT elements }; @@ -44,10 +44,10 @@ struct nbt_path { 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_const size_t nbt_tagdatlen(u8 const *buf); +atrb_const size_t nbt_tagdatlen(const u8 *buf); /* gets the tag size of primitive types, returns `>0` on success, `<0` on failure */ 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, u8 const *restrict buf, size_t len); +atrb_nonnull(1, 3) int nbt_proc(struct nbt_path const *restrict paths, uint npaths, const u8 *restrict buf, size_t len); diff --git a/src/io/input.c b/src/io/input.c index a25ad00..08aa6b4 100644 --- a/src/io/input.c +++ b/src/io/input.c @@ -4,7 +4,7 @@ #include -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 #ifndef NDEBUG if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) diff --git a/src/io/input.h b/src/io/input.h index 2ef4053..8589b34 100644 --- a/src/io/input.h +++ b/src/io/input.h @@ -4,4 +4,4 @@ #include -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); diff --git a/src/io/render.h b/src/io/render.h index 0da1475..f866ecd 100644 --- a/src/io/render.h +++ b/src/io/render.h @@ -7,4 +7,4 @@ #include int render_init(void); -void render_update(GLFWwindow* win); +void render_update(GLFWwindow *win); diff --git a/src/io/shader.c b/src/io/shader.c index 593f4dd..52704ec 100644 --- a/src/io/shader.c +++ b/src/io/shader.c @@ -12,7 +12,7 @@ #define NAM_E(name) _binary_res_##name##_end // name of an end variable // macro for generating the variable declarations -#define DEF_GLSL(name) \ +#define DEF_GLSL(name) \ extern char const NAM_S(name)[]; \ extern char const NAM_E(name)[] @@ -24,7 +24,7 @@ DEF_GLSL(sh_geom_glsl); // NOLINTEND /* 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; GLuint shader = glCreateShader(type); glShaderSource(shader, 1, &src, &ilen); diff --git a/src/io/window.c b/src/io/window.c index 36be6d8..e0fe7c2 100644 --- a/src/io/window.c +++ b/src/io/window.c @@ -16,7 +16,7 @@ #define WIN_DEFAULT_WIDTH 640 #define WIN_DEFAULT_HEIGHT 480 -static GLFWwindow* win = NULL; +static GLFWwindow *win = NULL; int window_init(void) { #ifndef NDEBUG diff --git a/src/main.c b/src/main.c index 376bb23..85fcdcc 100644 --- a/src/main.c +++ b/src/main.c @@ -17,7 +17,7 @@ #define WIN_DEFAULT_HEIGHT 480 // 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); } diff --git a/src/util/compat/io.h b/src/util/compat/io.h index 42f4523..53b9a29 100644 --- a/src/util/compat/io.h +++ b/src/util/compat/io.h @@ -13,7 +13,7 @@ /* 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 */ -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 #ifndef F_OK diff --git a/src/util/conf.h b/src/util/conf.h index cacb5ee..f70a72b 100644 --- a/src/util/conf.h +++ b/src/util/conf.h @@ -41,7 +41,7 @@ struct conf_fstr { /* defines the structure of a config file 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 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. * 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` */ -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. */ -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. * - `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` */ -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) * 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. * - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL 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 *); diff --git a/test/t_conf.h b/test/t_conf.h index 51e9450..2f6a074 100644 --- a/test/t_conf.h +++ b/test/t_conf.h @@ -19,7 +19,7 @@ struct test_getpat_envdat { /* save the current environment variables */ static void env_save(struct test_getpat_envdat *s) { - char const *tmp; + const char *tmp; tmp = getenv("XDG_CONFIG_HOME"); 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 */ struct test_procbuf { - char const *in; // data in - char const *xkey; // expected key - char const *xval; // expected value + const char *in; // data in + const char *xkey; // expected key + const char *xval; // expected value int xret; // expected return type }; int test_procbuf(void *arg) { @@ -81,7 +81,7 @@ int test_procbuf(void *arg) { /* check matchopt functionality */ 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 test_matchopt(void *arg) { @@ -96,7 +96,7 @@ int test_matchopt(void *arg) { } struct test_procval_int { - char const *val; + const char *val; u64 xres; u8 type; }; diff --git a/test/test.h b/test/test.h index ab66349..a7f7c88 100644 --- a/test/test.h +++ b/test/test.h @@ -3,12 +3,12 @@ #pragma once #include -char const *test_ctest; +const char *test_ctest; size_t test_runs = 0; // evaluates the test // 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++; if (cond) 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 struct testdat { - char const *name; // test name + const char *name; // test name int (*test)(void *); // test, returns 0 upon success, non-zero upon failure void *args; // arguments to the test };