tmp: revert enabling a column limit

This commit is contained in:
2025-10-16 23:35:30 +02:00
parent 1aa34f7d3f
commit 316726a610
13 changed files with 85 additions and 138 deletions

View File

@@ -7,7 +7,7 @@
# --------------------------- # ---------------------------
BasedOnStyle: GNU BasedOnStyle: GNU
Standard: Auto Standard: Auto
ColumnLimit: 100 ColumnLimit: 0
LineEnding: LF LineEnding: LF
UseTab: ForContinuationAndIndentation UseTab: ForContinuationAndIndentation
TabWidth: 8 TabWidth: 8
@@ -39,7 +39,7 @@ AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never AllowShortIfStatementsOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: true AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true AllowShortEnumsOnASingleLine: true
AllowShortLoopsOnASingleLine: false AllowShortLoopsOnASingleLine: true
# --------------------------- # ---------------------------
# break and wrapping options # break and wrapping options

View File

@@ -25,8 +25,7 @@ enum mcx_compression {
MCX_COMPRESSION_CUSTOM = 0x7F, MCX_COMPRESSION_CUSTOM = 0x7F,
}; };
/* First 4 bytes is an i32 indicating remaining bytes. /* first 4 bytes is an i32 indicating remaining bytes, the following byte defines the compression scheme */
* The following byte defines the compression scheme */
static int mcx_loadchunk(const u8 *restrict buf, const i32 *restrict table, int idx) static int mcx_loadchunk(const u8 *restrict buf, const i32 *restrict table, int idx)
{ {
const u8 *chunk = buf + (be32toh(table[idx]) >> 8) * SECTOR; const u8 *chunk = buf + (be32toh(table[idx]) >> 8) * SECTOR;
@@ -98,15 +97,12 @@ static usize delchunk(u8 *restrict buf, u32 *restrict table, usize rmb, int sidx
// load the table data // load the table data
usize slen, bidx, blen; usize slen, bidx, blen;
slen = be32toh(table[sidx]) & 0xFF; // acquire the sector length of the chunk slen = be32toh(table[sidx]) & 0xFF; // acquire the sector length of the chunk
bidx = (be32toh(table[sidx]) >> 8) * SECTOR; // acquire and compute the byte offset the bidx = (be32toh(table[sidx]) >> 8) * SECTOR; // acquire and compute the byte offset the chunk starts at
// chunk starts at
blen = slen * SECTOR; // compute the byte length of the chunk blen = slen * SECTOR; // compute the byte length of the chunk
// reset the table data // reset the table data
table[sidx] = 0; table[sidx] = 0;
table[sidx + CHUNKS] = htobe32(time(NULL)); // assign the current time to the timestamp, for table[sidx + CHUNKS] = htobe32(time(NULL)); // assign the current time to the timestamp, for correctness NOTE: might need to zero-out instead
// correctness NOTE: might need to zero-out
// instead
// move the succeeding chunks over the deleted chunk // move the succeeding chunks over the deleted chunk
u8 *dst = buf + bidx - rmb; u8 *dst = buf + bidx - rmb;
@@ -115,11 +111,9 @@ static usize delchunk(u8 *restrict buf, u32 *restrict table, usize rmb, int sidx
return blen; return blen;
} }
/* Call `delchunk` with the parameters and some defaults. /* Call `delchunk` with the parameters and some defaults. Ensuring the table is copied correctly as well.
* Ensuring the table is copied correctly as well. * This is done instead of `delchunk` being globally linked, because
* This is done instead of `delchunk` being globally linked, * `delchunk` requests more specific parameters, which is confusing outside this module. */
* because `delchunk` requests more specific parameters,
* which is confusing outside this module. */
usize mcx_delchunk(u8 *restrict buf, int chunk) usize mcx_delchunk(u8 *restrict buf, int chunk)
{ {
u32 table[TABLE]; u32 table[TABLE];
@@ -161,15 +155,14 @@ static int cmp_chunkids(const void *restrict x, const void *restrict y)
} }
/* Sorts the chunks marked for deletion from smallest to greatest index. /* Sorts the chunks marked for deletion from smallest to greatest index.
* Then performs the deletion in this order. * Then performs the deletion in this order. Making sure to only update the chunks up to the next. */
* Making sure to only update the chunks up to the next. */
usize mcx_delchunk_bulk(u8 *restrict buf, const u16 *restrict chunks, int chunkc) usize mcx_delchunk_bulk(u8 *restrict buf, const u16 *restrict chunks, int chunkc)
{ {
// ensure the chunks ids we're working on are sorted from least to greatest // ensure the chunks ids we're working on are sorted from least to greatest
u16 chunkids[chunkc + 1]; u16 chunkids[chunkc + 1];
memcpy(chunkids, chunks, chunkc); memcpy(chunkids, chunks, chunkc);
qsort(chunkids, chunkc, sizeof(int), cmp_chunkids); qsort(chunkids, chunkc, sizeof(int), cmp_chunkids);
chunkids[chunkc] = CHUNKS; // move the rest of the chunks chunkids[chunkc] = CHUNKS; // set the spare chunk to the max chunks, so the rest of the chunks are moved
u32 table[TABLE]; u32 table[TABLE];
memcpy(table, buf, sizeof(table)); memcpy(table, buf, sizeof(table));

View File

@@ -6,7 +6,7 @@
void input_callback(GLFWwindow *win, int key, int scancode, int action, int mods) void input_callback(GLFWwindow *win, int key, int scancode, int action, int mods)
{ {
(void)win, (void)key, (void)scancode, (void)action, (void)mods; (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)
glfwSetWindowShouldClose(win, 1); glfwSetWindowShouldClose(win, 1);

View File

@@ -44,7 +44,7 @@ int render_init(void)
if (len > 0) { if (len > 0) {
char log[len]; char log[len];
glGetProgramInfoLog(pipe, len, &len, log); glGetProgramInfoLog(pipe, len, &len, log);
log[len - 1] = '\0'; // terminate the string one character sooner log[len - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
fatal("error whilst linking the pipe: '%s'", log); fatal("error whilst linking the pipe: '%s'", log);
} }

View File

@@ -72,6 +72,5 @@ enum map_colour_id {
MAP_COLOUR_COUNT, MAP_COLOUR_COUNT,
}; };
/* contains the colours of the map on their' respective index - 1. /* contains the colours of the map on their' respective index - 1. (NONE should be handled separately) */
* (NONE should be handled separately) */
extern u8vec4 map_colours[MAP_COLOUR_COUNT]; extern u8vec4 map_colours[MAP_COLOUR_COUNT];

View File

@@ -9,9 +9,7 @@
#include "../util/error.h" #include "../util/error.h"
/* NOTE: we are currently just sucking up the memory costs for ease. We can either include the // NOTE: we are currently just sucking up the memory costs for ease. We can either include the source files themselves. Or use compression, where I'd prefer the latter for ease of installation.
* source files themselves. Or use compression, where I'd prefer the latter for ease of
* installation. */
extern const char sh_vert_glsl[]; extern const char sh_vert_glsl[];
extern const char sh_frag_glsl[]; extern const char sh_frag_glsl[];
extern const char sh_geom_glsl[]; extern const char sh_geom_glsl[];
@@ -33,8 +31,7 @@ static GLuint shader_compile(GLenum type, const char *src, usize len)
if (ilen > 0) { if (ilen > 0) {
char log[ilen]; char log[ilen];
glGetShaderInfoLog(shader, ilen, &ilen, log); glGetShaderInfoLog(shader, ilen, &ilen, log);
log[ilen - 1] = '\0'; // terminate the string one character sooner since the log log[ilen - 1] = '\0'; // terminate the string one character sooner since the log includes a newline
// includes a newline
error("error whilst compiling shader type '0x%X': '%s'", type, log); error("error whilst compiling shader type '0x%X': '%s'", type, log);
} }

View File

@@ -30,8 +30,8 @@ int window_init(void)
glfwWindowHint(GLFW_GREEN_BITS, 8); glfwWindowHint(GLFW_GREEN_BITS, 8);
glfwWindowHint(GLFW_BLUE_BITS, 8); glfwWindowHint(GLFW_BLUE_BITS, 8);
glfwWindowHint(GLFW_ALPHA_BITS, 0); glfwWindowHint(GLFW_ALPHA_BITS, 0);
/* NOTE: on my system; x86_64, GTX 1650 580.82.09-2, X11, i3, this causes one direct, /* NOTE: on my system; x86_64, GTX 1650 580.82.09-2, X11, i3, this causes one direct, 2 indirect memory leaks.
* 2 indirect memory leaks. This is not my fault, and can safely be ignored. */ * This is not my fault, and can safely be ignored. */
win = glfwCreateWindow(640, 480, "MCA-Selector lite", NULL, NULL); win = glfwCreateWindow(640, 480, "MCA-Selector lite", NULL, NULL);
if (!win) if (!win)
return 1; return 1;
@@ -39,18 +39,19 @@ int window_init(void)
glfwMakeContextCurrent(win); glfwMakeContextCurrent(win);
if (!gladLoadGL(glfwGetProcAddress)) if (!gladLoadGL(glfwGetProcAddress))
return 1; return 1;
/* wait 1 screen update for a redraw a.k.a. "vsync". glfwSwapInterval(1); // wait 1 screen update for a redraw a.k.a. "vsync". (not really applicable in this case but eh)
(not really applicable in this case, but eh) */
glfwSwapInterval(1);
glfwSetKeyCallback(win, input_callback); glfwSetKeyCallback(win, input_callback);
debug("version info:\n" debug(
"version info:\n"
"\tvendor: %s\n" "\tvendor: %s\n"
"\trenderer: %s\n" "\trenderer: %s\n"
"\tversion: %s\n" "\tversion: %s\n"
"\tshading lang: %s\n", "\tshading lang: %s\n",
glGetString(GL_VENDOR), glGetString(GL_RENDERER), glGetString(GL_VERSION), glGetString(GL_VENDOR),
glGetString(GL_RENDERER),
glGetString(GL_VERSION),
glGetString(GL_SHADING_LANGUAGE_VERSION)); glGetString(GL_SHADING_LANGUAGE_VERSION));
return 0; return 0;
} }

View File

@@ -32,7 +32,7 @@ int main(int argc, char **argv)
atexit(quit); atexit(quit);
glfwSetErrorCallback(error_callback); glfwSetErrorCallback(error_callback);
glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // we won't need them glfwInitHint(GLFW_JOYSTICK_HAT_BUTTONS, GLFW_FALSE); // disable joystick buttons; since we won't need them
if (!glfwInit() || window_init()) if (!glfwInit() || window_init())
fatal("failed to initialise!"); fatal("failed to initialise!");

View File

@@ -11,9 +11,8 @@
#error platform not supported! #error platform not supported!
#endif #endif
/* 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, returns 0 upon success. -1 when errno is set and anything else when one or more of the permissions isn't set */
anything else when one or more of the permissions isn't set */
static inline int faccess(const char *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
@@ -31,24 +30,16 @@ static inline int faccess(const char *restrict fname, int perms);
#endif #endif
#if defined __unix__ && _POSIX_C_SOURCE >= 200809L #if defined __unix__ && _POSIX_C_SOURCE >= 200809L
#define PATH_SEP \ #define PATH_SEP '/' // contains the path separator as a character. Yes it is extremely annoying that this has to exist.
'/' // contains the path separator as a character. Yes it is extremely annoying that this #define PATH_SEP_STR "/" // contains the path separator as a string, useful for concatenation. Yes it is extremely annoying that this has to exist.
// has to exist.
#define PATH_SEP_STR \
"/" // contains the path separator as a string, useful for concatenation. Yes it is
// extremely annoying that this has to exist.
int faccess(char const *restrict fname, int perms) int faccess(char const *restrict fname, int perms)
{ {
return access(fname, perms); return access(fname, perms);
} }
#elif defined(_WIN32) #elif defined(_WIN32)
#define PATH_SEP \ #define PATH_SEP '\\' // contains the path separator as a character. Yes it is extremely annoying that this has to exist.
'\\' // contains the path separator as a character. Yes it is extremely annoying that this #define PATH_SEP_STR "\\" // contains the path separator as a string, useful for concatenation. Yes it is extremely annoying that this has to exist.
// has to exist.
#define PATH_SEP_STR \
"\\" // contains the path separator as a string, useful for concatenation. Yes it is
// extremely annoying that this has to exist.
int faccess(char const *restrict fname, int perms) int faccess(char const *restrict fname, int perms)
{ {

View File

@@ -29,7 +29,9 @@ int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict v
case '\n': case '\n':
case '\r': case '\r':
case '\0': case '\0':
case '#': brk = true; break; case '#':
brk = true;
break;
} }
if (brk) if (brk)
break; break;
@@ -44,8 +46,8 @@ int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict v
*pos = buf[i]; // copy over the buffer's data *pos = buf[i]; // copy over the buffer's data
pos++; // increment the position pointer pos++; // increment the position pointer
} }
// null-terminate what we've got now (yes, there should be enough space for this since \0 // null-terminate what we've got now (yes, there should be enough space for this since \0 isn't stored)
// isn't stored) this also ensures the value is valid, even if none is given // this also ensures the value is valid, even if none is given
*pos = '\0'; *pos = '\0';
// no data if we didn't move from the key position // no data if we didn't move from the key position
@@ -53,8 +55,7 @@ int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict v
return (pos == kout) ? CONF_ENODAT : (!feq ? CONF_ESYNTAX : 0); return (pos == kout) ? CONF_ENODAT : (!feq ? CONF_ESYNTAX : 0);
} }
struct conf_entry const *conf_matchopt(struct conf_entry const *opts, usize optc, struct conf_entry const *conf_matchopt(struct conf_entry const *opts, usize optc, const char *restrict key)
const char *restrict key)
{ {
// find a match for the current key // find a match for the current key
usize i = 0; usize i = 0;
@@ -95,8 +96,7 @@ int conf_procval(struct conf_entry const *opt, const char *restrict val)
// string data parsing // string data parsing
case CONF_STR: case CONF_STR:
if (*(char **)opt->out) { if (*(char **)opt->out) {
free(*(char **)opt->out); // if the same key is given multiple times, free free(*(char **)opt->out); // if the same key is given multiple times, free the memory so we don't leak.
// the memory so we don't leak.
warn("encountered a dynamic string multiple times, this is sub-optimal."); warn("encountered a dynamic string multiple times, this is sub-optimal.");
} }
*(char **)opt->out = strdup(val); *(char **)opt->out = strdup(val);
@@ -116,53 +116,25 @@ int conf_procval(struct conf_entry const *opt, const char *restrict val)
} }
switch (opt->type) { switch (opt->type) {
case CONF_U8: case CONF_U8: *(u8 *)opt->out = *(u64 *)dat >= UINT8_MAX ? UINT8_MAX : *(u64 *)dat; return 0;
*(u8 *)opt->out = *(u64 *)dat >= UINT8_MAX ? UINT8_MAX : *(u64 *)dat; case CONF_U16: *(u16 *)opt->out = *(u64 *)dat >= UINT16_MAX ? UINT16_MAX : *(u64 *)dat; return 0;
return 0; case CONF_U32: *(u32 *)opt->out = *(u64 *)dat >= UINT32_MAX ? UINT32_MAX : *(u64 *)dat; return 0;
case CONF_U16: case CONF_U64: *(u64 *)opt->out = *(u64 *)dat >= UINT64_MAX ? UINT64_MAX : *(u64 *)dat; return 0;
*(u16 *)opt->out = *(u64 *)dat >= UINT16_MAX ? UINT16_MAX : *(u64 *)dat; case CONF_I8: *(i8 *)opt->out = *(i64 *)dat >= INT8_MAX ? INT8_MAX : (*(i64 *)dat <= INT8_MIN ? INT8_MIN : *(i64 *)dat); return 0;
return 0; case CONF_I16: *(i16 *)opt->out = *(i64 *)dat >= INT16_MAX ? INT16_MAX : (*(i64 *)dat <= INT16_MIN ? INT16_MIN : *(i64 *)dat); return 0;
case CONF_U32: case CONF_I32: *(i32 *)opt->out = *(i64 *)dat >= INT32_MAX ? INT32_MAX : (*(i64 *)dat <= INT32_MIN ? INT32_MIN : *(i64 *)dat); return 0;
*(u32 *)opt->out = *(u64 *)dat >= UINT32_MAX ? UINT32_MAX : *(u64 *)dat; case CONF_I64: *(i64 *)opt->out = *(i64 *)dat >= INT64_MAX ? INT64_MAX : (*(i64 *)dat <= INT64_MIN ? INT64_MIN : *(i64 *)dat); return 0;
return 0;
case CONF_U64:
*(u64 *)opt->out = *(u64 *)dat >= UINT64_MAX ? UINT64_MAX : *(u64 *)dat;
return 0;
case CONF_I8:
*(i8 *)opt->out = *(i64 *)dat >= INT8_MAX ?
INT8_MAX :
(*(i64 *)dat <= INT8_MIN ? INT8_MIN : *(i64 *)dat);
return 0;
case CONF_I16:
*(i16 *)opt->out = *(i64 *)dat >= INT16_MAX ?
INT16_MAX :
(*(i64 *)dat <= INT16_MIN ? INT16_MIN : *(i64 *)dat);
return 0;
case CONF_I32:
*(i32 *)opt->out = *(i64 *)dat >= INT32_MAX ?
INT32_MAX :
(*(i64 *)dat <= INT32_MIN ? INT32_MIN : *(i64 *)dat);
return 0;
case CONF_I64:
*(i64 *)opt->out = *(i64 *)dat >= INT64_MAX ?
INT64_MAX :
(*(i64 *)dat <= INT64_MIN ? INT64_MIN : *(i64 *)dat);
return 0;
case CONF_F32: *(f32 *)opt->out = *(f32 *)dat; return 0; case CONF_F32: *(f32 *)opt->out = *(f32 *)dat; return 0;
case CONF_F64: *(f64 *)opt->out = *(f64 *)dat; return 0; case CONF_F64: *(f64 *)opt->out = *(f64 *)dat; return 0;
default: default: fatal("invalid switch state, all cases should be handled already"); // abort; this shouldn't be possible, so I blame the programmer
/* abort; this shouldn't be possible so I blame the programmer. */
fatal("invalid switch state, all cases should be handled already");
} }
} }
/* utility function for conf_getpat to concatenate 3 strings, where we already know the size */ /* utility function for conf_getpat to concatenate 3 strings, where we already know the size */
NONNULL((1, 3)) NONNULL((1, 3))
static char *conf_getpat_concat(const char *restrict s1, const char *restrict s2, static char *conf_getpat_concat(const char *restrict s1, const char *restrict s2, const char *restrict s3, usize s1len, usize s2len, usize s3len)
const char *restrict s3, usize s1len, usize s2len, usize s3len)
{ {
assert(s2 || (!s2 && !s2len)); // ensuring the programmer passes both s2 and s2len as 0, if assert(s2 || (!s2 && !s2len)); // ensuring the programmer passes both s2 and s2len as 0, if they intend to
// they intend to
char *buf, *ptr; char *buf, *ptr;
// allocate enough data for all three to the buffer // allocate enough data for all three to the buffer
@@ -174,8 +146,7 @@ static char *conf_getpat_concat(const char *restrict s1, const char *restrict s2
// copy data to the buffer // copy data to the buffer
ptr = memcpy(ptr, s1, s1len) + s1len; // copy s1 data to the buffer ptr = memcpy(ptr, s1, s1len) + s1len; // copy s1 data to the buffer
if (s2len) if (s2len)
ptr = memcpy(ptr, s2, s2len) + s2len; // copy s2 data to the buffer (excluding ptr = memcpy(ptr, s2, s2len) + s2len; // copy s2 data to the buffer (excluding null-terminator)
// null-terminator)
(void)strcpy(ptr, s3); // copy s3 as a string, thus including null-terminator (void)strcpy(ptr, s3); // copy s3 as a string, thus including null-terminator
// return the buffer // return the buffer

View File

@@ -19,18 +19,18 @@ enum conf_err {
/* defines the primitive types available in the config file */ /* defines the primitive types available in the config file */
enum conf_primitive { enum conf_primitive {
CONF_STR = 0, // expects `char**`, will output malloc'd data CONF_STR = 0, // expects: `char**`, will output malloc'd data !!must be freed!!
CONF_I8 = 1, // expects `int8_t*`, CONF_I8 = 1, // expects: `int8_t*`, will point to a location in memory where an i8 is stored.
CONF_I16 = 2, // expects `int16_t*`, CONF_I16 = 2, // expects: `int16_t*`, will point to a location in memory where an i16 is stored.
CONF_I32 = 4, // expects `int32_t*`, CONF_I32 = 4, // expects: `int32_t*`, will point to a location in memory where an i32 is stored.
CONF_I64 = 8, // expects `int64_t*`, 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*`, 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*`, 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*`, 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*`, 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*`, 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*`, 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*` 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 */ /* for outputting a fixed string as this config field */
@@ -42,33 +42,29 @@ 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 {
const char *key; // the key of this entry const char *key; // the key of this entry
void *out; // where data will be written, is read when key is missing or invalid 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 u8 type; // the primitive type which we are querying for
}; };
/* processes an incoming buffer. /* processes an incoming buffer.
* `buf`, `kout` and `vout` mustn't overlap, and must be (at least) `len` bytes long! * `buf`, `kout` and `vout` mustn't overlap, and must be (at least) `len` bytes long!
* `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 * returns `0` on success, `<0` when no data was found. `>0` when data was invalid but something went wrong.
* went wrong. see `CONF_E*` or `enum conf_err` */ * see `CONF_E*` or `enum conf_err` */
int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict vout, usize len); int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict vout, usize len);
/* matches the key with one of the options and returns the pointer. Returns NULL if none could be /* matches the key with one of the options and returns the pointer. Returns NULL if none could be found. */
* found. */ struct conf_entry const *conf_matchopt(struct conf_entry const *opts, usize optc, const char *restrict key);
struct conf_entry const *conf_matchopt(struct conf_entry const *opts, usize 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. * returns `0` upon success, non-zero upon failure. For information about specific error codes, see `enum conf_err` */
* For information about specific error codes, see`enum conf_err` */
int conf_procval(struct conf_entry const *opts, const char *restrict val); int conf_procval(struct conf_entry const *opts, const char *restrict val);
/* acquires the config file path, appending str to the end expecting str to be null-terminated /* acquires the config file path, appending str to the end (you need to handle path separators yourself)
* note: you must handle path separators yourself. * expecting str to be null-terminated
* checks the following environment variables for each platform in order: * - linux: reads $XDG_CONFIG_HOME, if empty $HOME/.config is used, if $HOME is empty NULL is returned.
* LINUX: `$XDG_CONFIG_HOME`, `$HOME/.config`. * - windows: reads %APPDATA%, if empty %USERPROFILE%\AppData\Roaming is used, if both are empty NULL is returned.
* WINDOWS: `%APPDATA%`, `%USERPROFILE%\AppData\Roaming`. * - osx: reads $HOME, uses $HOME/Library/Application Support, if $HOME is empty NULL is returned.
* MACOSX: `$HOME/Library/Application Support`. * !! A malloc'd null-terminated string is returned !! */
* `NULL` is returned if the path couldn't be found. */
char *conf_getpat(const char *) MALLOC NONNULL((1)); char *conf_getpat(const char *) MALLOC NONNULL((1));

View File

@@ -7,8 +7,7 @@
#include "../types.h" #include "../types.h"
static void error_log(FILE *restrict stream, const char *restrict pfx, uint ln, static void error_log(FILE *restrict stream, const char *restrict pfx, uint ln, const char *restrict file, const char *restrict fmt, va_list ap)
const char *restrict file, const char *restrict fmt, va_list ap)
{ {
fprintf(stream, "(%s:%u) [%s] '", file, ln, pfx); fprintf(stream, "(%s:%u) [%s] '", file, ln, pfx);
vfprintf(stream, fmt, ap); vfprintf(stream, fmt, ap);