mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-17 06:05:44 +01:00
apply new formatting rules to the whole project
This commit is contained in:
@@ -8,18 +8,18 @@
|
|||||||
#include "../util/types.h"
|
#include "../util/types.h"
|
||||||
|
|
||||||
/* returns the string length from a specific location in the buffer */
|
/* 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));
|
return be16toh(*(u16 *)(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns the length of an array from a specific location in the buffer */
|
/* 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));
|
return be32toh(*(i32 *)(buf));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compares the string in `buf` to `matstr`.
|
/* compares the string in `buf` to `matstr`.
|
||||||
* returns `=0` if equal, `>0` if buf is greater, `<0` if matstr is greater. */
|
* 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);
|
u16 len = nbt_strlen(buf);
|
||||||
|
|
||||||
// allocate and copy bytes
|
// 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.
|
/* returns the (expected) pointer of the tag following this one.
|
||||||
* `NULL` is returned if anything went wrong. */
|
* `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);
|
size_t len = nbt_tagdatlen(buf);
|
||||||
if (!len) return NULL; // TODO: compound tags should be handled here
|
if (!len) return NULL; // TODO: compound tags should be handled here
|
||||||
return buf + naml + len + 3;
|
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
|
// 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) */
|
/* 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) {
|
static const u8 *nbt_proctag(const u8 *restrict buf, u16 slen) {
|
||||||
u8 const *ptr = buf + 3 + slen;
|
const u8 *ptr = buf + 3 + slen;
|
||||||
u8 dat[8];
|
u8 dat[8];
|
||||||
size_t arrlen = 0;
|
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 */
|
/* 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++) {
|
for (uint i = 0; i < npats; i++) {
|
||||||
if (strncmp(pats[i].pat[dpt], cmp, len) == 0)
|
if (strncmp(pats[i].pat[dpt], cmp, len) == 0)
|
||||||
return pats[i].pat[dpt];
|
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
|
// 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
|
// ensure first and last tag(s) are valid
|
||||||
if (buf[0] != NBT_COMPOUND || buf[len - 1] != NBT_END)
|
if (buf[0] != NBT_COMPOUND || buf[len - 1] != NBT_END)
|
||||||
return 1;
|
return 1;
|
||||||
@@ -95,14 +95,14 @@ int nbt_proc(struct nbt_path const *restrict pats, uint npats, u8 const *restric
|
|||||||
assert(mdpt > 0);
|
assert(mdpt > 0);
|
||||||
|
|
||||||
// storing the segments of the current path
|
// storing the segments of the current path
|
||||||
char const *cpat[mdpt - 1];
|
const char *cpat[mdpt - 1];
|
||||||
memset((void *)cpat, 0, mdpt - 1);
|
memset((void *)cpat, 0, mdpt - 1);
|
||||||
|
|
||||||
// looping through the different tags
|
// 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) {
|
while (ptr < (buf + len) && dpt >= 0) {
|
||||||
u16 naml = nbt_strlen(ptr + 1);
|
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;
|
cpat[dpt] = mat;
|
||||||
|
|
||||||
if (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;
|
size_t mems = 0;
|
||||||
|
|
||||||
switch (*buf) {
|
switch (*buf) {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ enum nbt_tagid {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct nbt_path {
|
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
|
i16 len; // specifies the length of the NBT elements
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -44,10 +44,10 @@ struct nbt_path {
|
|||||||
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. */
|
/* 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 */
|
/* 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`. */
|
/* 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);
|
||||||
|
|||||||
@@ -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)
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
@@ -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 *);
|
||||||
|
|||||||
@@ -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;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user