mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-16 20:05:45 +01:00
reformat the code by enabeling assignment- and declaration alignment.
This commit is contained in:
@@ -24,9 +24,9 @@ AlignTrailingComments: true
|
||||
AlignConsecutiveMacros: AcrossEmptyLines
|
||||
AlignEscapedNewlines: Left
|
||||
AlignArrayOfStructures: Left
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignConsecutiveAssignments: Consecutive
|
||||
AlignConsecutiveBitFields: AcrossEmptyLines
|
||||
AlignConsecutiveDeclarations: None
|
||||
AlignConsecutiveDeclarations: Consecutive
|
||||
AlignConsecutiveShortCaseStatements:
|
||||
Enabled: true
|
||||
|
||||
|
||||
@@ -18,10 +18,10 @@
|
||||
#define CHUNKS 0x400 // amount of chunks in a file
|
||||
|
||||
enum mcx_compression {
|
||||
MCX_COMPRESSION_GZIP = 0x01,
|
||||
MCX_COMPRESSION_ZLIB = 0x02,
|
||||
MCX_COMPRESSION_NONE = 0x03,
|
||||
MCX_COMPRESSION_LZ4 = 0x04,
|
||||
MCX_COMPRESSION_GZIP = 0x01,
|
||||
MCX_COMPRESSION_ZLIB = 0x02,
|
||||
MCX_COMPRESSION_NONE = 0x03,
|
||||
MCX_COMPRESSION_LZ4 = 0x04,
|
||||
MCX_COMPRESSION_CUSTOM = 0x7F,
|
||||
};
|
||||
|
||||
@@ -97,7 +97,7 @@ static usize delchunk(u8 *restrict buf, u32 *restrict table, usize rmb, int sidx
|
||||
blen = slen * SECTOR; // compute the byte length of the chunk
|
||||
|
||||
// reset the table data
|
||||
table[sidx] = 0;
|
||||
table[sidx] = 0;
|
||||
table[sidx + CHUNKS] = htobe32(time(NULL)); // assign the current time to the timestamp, for correctness NOTE: might need to zero-out instead
|
||||
|
||||
// move the succeeding chunks over the deleted chunk
|
||||
@@ -129,7 +129,7 @@ usize mcx_delchunk_range(u8 *restrict buf, int start, int end) {
|
||||
// zeroes-out the chunk data within this range. (and set the timestamp)
|
||||
u32 ts = htobe32(time(NULL));
|
||||
for (int i = start; i <= end; i++) {
|
||||
table[i] = 0;
|
||||
table[i] = 0;
|
||||
table[i + CHUNKS] = ts;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
|
||||
/* contains chunk metadata */
|
||||
struct mcx_chunk {
|
||||
usize idx; // byte offset for start of chunk data
|
||||
u32 len; // byte length of chunk (+ padding)
|
||||
u32 time; // modification time in epoch seconds
|
||||
usize idx; // byte offset for start of chunk data
|
||||
u32 len; // byte length of chunk (+ padding)
|
||||
u32 time; // modification time in epoch seconds
|
||||
};
|
||||
|
||||
/* Deletes a single chunk (`chunk`) out of `buf`.
|
||||
|
||||
@@ -38,10 +38,10 @@ static inline u64 buftoh64(const void *restrict buf) {
|
||||
* Outputs the allocated data to `out`, returns where the next pointer would be. */
|
||||
static const u8 *procarr(const u8 *restrict buf, i32 nmemb, uint size, struct nbt_array *restrict out) {
|
||||
usize len = nmemb * size;
|
||||
*out = (struct nbt_array){
|
||||
out->nmemb = nmemb,
|
||||
out->dat = malloc(len),
|
||||
};
|
||||
*out = (struct nbt_array){
|
||||
out->nmemb = nmemb,
|
||||
out->dat = malloc(len),
|
||||
};
|
||||
if (!out->dat)
|
||||
return buf + len;
|
||||
|
||||
@@ -92,7 +92,7 @@ const u8 *nbt_proctag(const u8 *restrict buf, u16 slen, void *restrict out) {
|
||||
const u8 *ptr, *tmp;
|
||||
ptr = buf + 3 + slen;
|
||||
|
||||
i32 nmem;
|
||||
i32 nmem;
|
||||
uint size;
|
||||
|
||||
switch (*buf) {
|
||||
@@ -152,7 +152,7 @@ static const u8 *nexttag_list(const u8 *restrict ptr, uint *restrict const dpt,
|
||||
* Where the value is decremented until we reach `0`.
|
||||
* - `tags` shall contain `MAX_DEPTH` of items representing the list's stored type. */
|
||||
static const u8 *nexttag(const u8 *restrict tag, uint *restrict const dpt, i32 *restrict const lens, u8 *restrict const tags) {
|
||||
u8 type;
|
||||
u8 type;
|
||||
const u8 *ptr = tag;
|
||||
if (lens[*dpt]) {
|
||||
type = tags[*dpt];
|
||||
@@ -195,9 +195,9 @@ static const u8 *nexttag(const u8 *restrict tag, uint *restrict const dpt, i32 *
|
||||
*/
|
||||
const u8 *nbt_nexttag(const u8 *restrict buf) {
|
||||
const u8 *tag;
|
||||
u8 tags[MAX_DEPTH] = {0};
|
||||
i32 lens[MAX_DEPTH] = {0};
|
||||
uint dpt = 0;
|
||||
u8 tags[MAX_DEPTH] = {0};
|
||||
i32 lens[MAX_DEPTH] = {0};
|
||||
uint dpt = 0;
|
||||
|
||||
tag = buf;
|
||||
do {
|
||||
|
||||
@@ -21,23 +21,23 @@
|
||||
/* specifies the NBT tag IDs.
|
||||
* NOTE: every type is stored as BE (big-endian) in the file. */
|
||||
enum nbt_tagid {
|
||||
NBT_END = 0x00, // signifies the end of a compound tag
|
||||
NBT_I8 = 0x01, // next byte is for an 8 bit signed integer.
|
||||
NBT_I16 = 0x02, // next 2 bytes are for a 16 bit signed integer
|
||||
NBT_I32 = 0x03, // next 4 bytes are for a 32 bit signed integer
|
||||
NBT_I64 = 0x04, // next 8 bytes are for a 64 bit signed integer
|
||||
NBT_F32 = 0x05, // next 4 bytes are for a single-precision floating-point
|
||||
NBT_F64 = 0x06, // next 8 bytes are for a double-precision floating-point
|
||||
NBT_ARR_I8 = 0x07, // starts with a i32, denoting size, followed by the i8 data
|
||||
NBT_STR = 0x08, // starts with a u16, denoting size, followed by the UTF-8 data
|
||||
NBT_LIST = 0x09, // starts with an ID, followed by a 32 bit signed integer denoting the size
|
||||
NBT_END = 0x00, // signifies the end of a compound tag
|
||||
NBT_I8 = 0x01, // next byte is for an 8 bit signed integer.
|
||||
NBT_I16 = 0x02, // next 2 bytes are for a 16 bit signed integer
|
||||
NBT_I32 = 0x03, // next 4 bytes are for a 32 bit signed integer
|
||||
NBT_I64 = 0x04, // next 8 bytes are for a 64 bit signed integer
|
||||
NBT_F32 = 0x05, // next 4 bytes are for a single-precision floating-point
|
||||
NBT_F64 = 0x06, // next 8 bytes are for a double-precision floating-point
|
||||
NBT_ARR_I8 = 0x07, // starts with a i32, denoting size, followed by the i8 data
|
||||
NBT_STR = 0x08, // starts with a u16, denoting size, followed by the UTF-8 data
|
||||
NBT_LIST = 0x09, // starts with an ID, followed by a 32 bit signed integer denoting the size
|
||||
NBT_COMPOUND = 0x0A, // compound tag, contains tags and is delimited by `NBT_END`
|
||||
NBT_ARR_I32 = 0x0B, // starts with a i32, denoting size, followed by the i32 data
|
||||
NBT_ARR_I64 = 0x0C, // starts with a i32, denoting size, followed by the u32 data
|
||||
NBT_ARR_I32 = 0x0B, // starts with a i32, denoting size, followed by the i32 data
|
||||
NBT_ARR_I64 = 0x0C, // starts with a i32, denoting size, followed by the u32 data
|
||||
};
|
||||
|
||||
struct nbt_array {
|
||||
i32 nmemb;
|
||||
i32 nmemb;
|
||||
void *dat;
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ static GLuint pipe;
|
||||
static GLuint vbo; // vertex buffer object
|
||||
static GLuint vao; // vertex array object
|
||||
static GLuint screen_loc; // location to where OpenGL sends to the shaders of the screen dimensions
|
||||
static int win_w, win_h;
|
||||
static int win_w, win_h;
|
||||
|
||||
static void screen_resize(int w, int h) {
|
||||
i32 verts[VERTC][4] = {
|
||||
@@ -84,7 +84,7 @@ void render_free(void) {
|
||||
glDeleteVertexArrays(1, &vao);
|
||||
glDeleteBuffers(1, &vbo);
|
||||
glDeleteProgram(pipe);
|
||||
vbo = 0;
|
||||
vao = 0;
|
||||
vbo = 0;
|
||||
vao = 0;
|
||||
pipe = 0;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,6 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glad/gl.h>
|
||||
|
||||
int render_init(void);
|
||||
int render_init(void);
|
||||
void render_update(GLFWwindow *win);
|
||||
void render_free(void);
|
||||
|
||||
@@ -20,7 +20,7 @@ extern const uint sh_geom_glsl_len;
|
||||
/* Compiles a shader of `type` from `src` with `len` bytes.
|
||||
* Returns the integer for the shader. */
|
||||
static GLuint shader_compile(GLenum type, const char *src, usize len) {
|
||||
int ilen = len;
|
||||
int ilen = len;
|
||||
GLuint shader = glCreateShader(type);
|
||||
glShaderSource(shader, 1, &src, &ilen);
|
||||
glCompileShader(shader);
|
||||
|
||||
30
src/types.h
30
src/types.h
@@ -3,21 +3,21 @@
|
||||
#pragma once
|
||||
|
||||
typedef signed long long int llong;
|
||||
typedef unsigned short int ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ullong;
|
||||
typedef __INT8_TYPE__ i8;
|
||||
typedef __INT16_TYPE__ i16;
|
||||
typedef __INT32_TYPE__ i32;
|
||||
typedef __INT64_TYPE__ i64;
|
||||
typedef __UINT8_TYPE__ u8;
|
||||
typedef __UINT16_TYPE__ u16;
|
||||
typedef __UINT32_TYPE__ u32;
|
||||
typedef __UINT64_TYPE__ u64;
|
||||
typedef __SIZE_TYPE__ usize;
|
||||
typedef __INTPTR_TYPE__ intptr;
|
||||
typedef __UINTPTR_TYPE__ uintptr;
|
||||
typedef unsigned short int ushort;
|
||||
typedef unsigned int uint;
|
||||
typedef unsigned long ulong;
|
||||
typedef unsigned long long ullong;
|
||||
typedef __INT8_TYPE__ i8;
|
||||
typedef __INT16_TYPE__ i16;
|
||||
typedef __INT32_TYPE__ i32;
|
||||
typedef __INT64_TYPE__ i64;
|
||||
typedef __UINT8_TYPE__ u8;
|
||||
typedef __UINT16_TYPE__ u16;
|
||||
typedef __UINT32_TYPE__ u32;
|
||||
typedef __UINT64_TYPE__ u64;
|
||||
typedef __SIZE_TYPE__ usize;
|
||||
typedef __INTPTR_TYPE__ intptr;
|
||||
typedef __UINTPTR_TYPE__ uintptr;
|
||||
|
||||
#if __SIZEOF_FLOAT__ == 4
|
||||
typedef float f32;
|
||||
|
||||
@@ -36,9 +36,9 @@ int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict v
|
||||
|
||||
// everything after `=` is interpreted as a value
|
||||
if (!feq && buf[i] == '=') {
|
||||
feq = true;
|
||||
feq = true;
|
||||
*pos = '\0'; // terminate string
|
||||
pos = vout; // move pointer to start of value data
|
||||
pos = vout; // move pointer to start of value data
|
||||
continue;
|
||||
}
|
||||
*pos = buf[i]; // copy over the buffer's data
|
||||
@@ -67,7 +67,7 @@ int conf_procval(struct conf_entry const *opt, const char *restrict val) {
|
||||
// parse the data
|
||||
errno = 0;
|
||||
char *end;
|
||||
u8 dat[sizeof(u64)];
|
||||
u8 dat[sizeof(u64)];
|
||||
|
||||
switch (opt->type) {
|
||||
// signed integer data parsing
|
||||
|
||||
@@ -10,40 +10,40 @@
|
||||
|
||||
/* error codes */
|
||||
enum conf_err {
|
||||
CONF_ENODAT = -1, // no data was found
|
||||
CONF_ESYNTAX = 1, // couldn't extract clear key/val data
|
||||
CONF_ENOMATCH = 2, // couldn't find a match for the inputted key
|
||||
CONF_EINVALIDTYPE = 3, // the type inputted in conf_entry was invalid
|
||||
CONF_EPARSE = 4, // something went wrong whilst parsing
|
||||
CONF_ENODAT = -1, // no data was found
|
||||
CONF_ESYNTAX = 1, // couldn't extract clear key/val data
|
||||
CONF_ENOMATCH = 2, // couldn't find a match for the inputted key
|
||||
CONF_EINVALIDTYPE = 3, // the type inputted in conf_entry was invalid
|
||||
CONF_EPARSE = 4, // something went wrong whilst parsing
|
||||
};
|
||||
|
||||
/* defines the primitive types available in the config file */
|
||||
enum conf_primitive {
|
||||
CONF_STR = 0, // expects: `char**`, will output malloc'd data !!must be freed!!
|
||||
CONF_I8 = 1, // expects: `int8_t*`, will point to a location in memory where an i8 is stored.
|
||||
CONF_I16 = 2, // expects: `int16_t*`, will point to a location in memory where an i16 is stored.
|
||||
CONF_I32 = 4, // expects: `int32_t*`, will point to a location in memory where an i32 is stored.
|
||||
CONF_I64 = 8, // expects: `int64_t*`, will point to a location in memory where an i64 is stored.
|
||||
CONF_U8 = CONF_I8 | 0x80, // expects: `uint8_t*`, will point to a location in memory where an u8 is stored.
|
||||
CONF_U16 = CONF_I16 | 0x80, // expects: `uint16_t*`, will point to a location in memory where an u16 is stored.
|
||||
CONF_U32 = CONF_I32 | 0x80, // expects: `uint32_t*`, will point to a location in memory where an u32 is stored.
|
||||
CONF_U64 = CONF_I64 | 0x80, // expects: `uint64_t*`, will point to a location in memory where an u64 is stored.
|
||||
CONF_F32 = CONF_I32 | 0x40, // expects: `float*`, will point to a location in memory where an f32 is stored.
|
||||
CONF_F64 = CONF_I64 | 0x40, // expects: `double*`, will point to a location in memory where an f64 is stored.
|
||||
CONF_FSTR = 0x40, // expects: `struct conf_fstr*`, which contains the data for a fixed-width string
|
||||
CONF_STR = 0, // expects: `char**`, will output malloc'd data !!must be freed!!
|
||||
CONF_I8 = 1, // expects: `int8_t*`, will point to a location in memory where an i8 is stored.
|
||||
CONF_I16 = 2, // expects: `int16_t*`, will point to a location in memory where an i16 is stored.
|
||||
CONF_I32 = 4, // expects: `int32_t*`, will point to a location in memory where an i32 is stored.
|
||||
CONF_I64 = 8, // expects: `int64_t*`, will point to a location in memory where an i64 is stored.
|
||||
CONF_U8 = CONF_I8 | 0x80, // expects: `uint8_t*`, will point to a location in memory where an u8 is stored.
|
||||
CONF_U16 = CONF_I16 | 0x80, // expects: `uint16_t*`, will point to a location in memory where an u16 is stored.
|
||||
CONF_U32 = CONF_I32 | 0x80, // expects: `uint32_t*`, will point to a location in memory where an u32 is stored.
|
||||
CONF_U64 = CONF_I64 | 0x80, // expects: `uint64_t*`, will point to a location in memory where an u64 is stored.
|
||||
CONF_F32 = CONF_I32 | 0x40, // expects: `float*`, will point to a location in memory where an f32 is stored.
|
||||
CONF_F64 = CONF_I64 | 0x40, // expects: `double*`, will point to a location in memory where an f64 is stored.
|
||||
CONF_FSTR = 0x40, // expects: `struct conf_fstr*`, which contains the data for a fixed-width string
|
||||
};
|
||||
|
||||
/* for outputting a fixed string as this config field */
|
||||
struct conf_fstr {
|
||||
usize len; // length in BYTES of the output data
|
||||
char *out; // where we will output the data
|
||||
char *out; // where we will output the data
|
||||
};
|
||||
|
||||
/* defines the structure of a config file entry */
|
||||
struct conf_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
|
||||
u8 type; // the primitive type which we are querying for
|
||||
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
|
||||
u8 type; // the primitive type which we are querying for
|
||||
};
|
||||
|
||||
/* processes an incoming buffer.
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key, const char *restrict expect_val, int expect_return) {
|
||||
usize len = strlen(buf) + 1;
|
||||
char k[len], v[len];
|
||||
char k[len], v[len];
|
||||
*k = '\0', *v = '\0';
|
||||
(void)(assert_true(conf_procbuf(buf, k, v, len) == expect_return) &&
|
||||
assert_true(!strcmp(k, expect_key)) &&
|
||||
@@ -20,8 +20,8 @@ void test_conf_procbuf(const char *restrict buf, const char *restrict expect_key
|
||||
|
||||
void test_conf_matchopt(struct conf_entry *opts, usize optc, const char *restrict key, int expect_index) {
|
||||
usize idx = opts - conf_matchopt(opts, optc, key);
|
||||
idx = (ssize)idx < 0 ? -idx : idx;
|
||||
int i = idx < optc ? (int)idx : -1;
|
||||
idx = (ssize)idx < 0 ? -idx : idx;
|
||||
int i = idx < optc ? (int)idx : -1;
|
||||
assert_true(i == expect_index);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ void test_conf_procval_int(const char *val, u64 expect_value, int type) {
|
||||
}
|
||||
|
||||
void test_conf_procval_f32(const char *val, f32 expect_value) {
|
||||
u8 out[4];
|
||||
u8 out[4];
|
||||
f32 result;
|
||||
conf_procval(&(struct conf_entry){NULL, out, CONF_F32}, val);
|
||||
memcpy(&result, out, 4);
|
||||
@@ -54,14 +54,14 @@ void test_procval_str_predef(void) {
|
||||
}
|
||||
|
||||
void test_procval_fstr(void) {
|
||||
char buf[16];
|
||||
char buf[16];
|
||||
struct conf_fstr str = {sizeof(buf), buf};
|
||||
(void)(assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwoo wowld")) &&
|
||||
assert_true(!strcmp(str.out, "hewwoo wowld")));
|
||||
}
|
||||
|
||||
void test_procval_fstr_trunc(void) {
|
||||
char buf[8];
|
||||
char buf[8];
|
||||
struct conf_fstr str = {sizeof(buf), buf};
|
||||
(void)(assert_true(!conf_procval(&(struct conf_entry){NULL, &str, CONF_FSTR}, "hewwooo wowld")) &&
|
||||
assert_true(!strcmp(str.out, "hewwooo")));
|
||||
|
||||
Reference in New Issue
Block a user