mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-19 12:55:45 +01:00
create a custom definition for size_t and ssize_t, which is ssize and usize, for conveinience.
This commit is contained in:
@@ -14,14 +14,14 @@
|
||||
#include "atrb.h"
|
||||
#include "intdef.h"
|
||||
|
||||
int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict vout, size_t len) {
|
||||
int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict vout, usize len) {
|
||||
bool feq = false; // whether we've found the equal sign
|
||||
|
||||
// data traversal
|
||||
char *pos = kout; // will point to the next point in the buffer, where we'll write data
|
||||
|
||||
// acquire data
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
for (usize i = 0; i < len; i++) {
|
||||
// handling of termination tokens
|
||||
bool brk = false; // whether we broke out of the loop, and are done reading
|
||||
switch (buf[i]) {
|
||||
@@ -53,9 +53,9 @@ int conf_procbuf(const char *restrict buf, char *restrict kout, char *restrict v
|
||||
return (pos == kout) ? CONF_ENODAT : (!feq ? CONF_ESYNTAX : 0);
|
||||
}
|
||||
|
||||
struct conf_entry const *conf_matchopt(struct conf_entry const *opts, size_t optc, const char *restrict key) {
|
||||
struct conf_entry const *conf_matchopt(struct conf_entry const *opts, usize optc, const char *restrict key) {
|
||||
// find a match for the current key
|
||||
size_t i = 0;
|
||||
usize i = 0;
|
||||
for (; i < optc; i++) {
|
||||
if (strcmp(opts[i].key, key) == 0)
|
||||
return opts + i;
|
||||
@@ -128,7 +128,7 @@ int conf_procval(struct conf_entry const *opt, const char *restrict val) {
|
||||
|
||||
/* utility function for conf_getpat to concatenate 3 strings, where we already know the size */
|
||||
NONNULL((1, 3))
|
||||
static char *conf_getpat_concat(const char *restrict s1, const char *restrict s2, const char *restrict s3, size_t s1len, size_t s2len, size_t s3len) {
|
||||
static char *conf_getpat_concat(const char *restrict s1, const char *restrict s2, 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 they intend to
|
||||
char *buf, *ptr;
|
||||
|
||||
@@ -140,7 +140,7 @@ static char *conf_getpat_concat(const char *restrict s1, const char *restrict s2
|
||||
// copy data to the buffer
|
||||
ptr = memcpy(ptr, s1, s1len) + s1len; // copy s1 data to the buffer
|
||||
if (s2len) ptr = memcpy(ptr, s2, s2len) + s2len; // copy s2 data to the buffer (excluding 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 buf;
|
||||
@@ -149,8 +149,8 @@ static char *conf_getpat_concat(const char *restrict s1, const char *restrict s2
|
||||
/* appends str to the config directory string we acquire from environment variables. */
|
||||
char *conf_getpat(const char *restrict str) {
|
||||
char *buf = NULL;
|
||||
size_t len;
|
||||
size_t str_len = strlen(str);
|
||||
usize len;
|
||||
usize str_len = strlen(str);
|
||||
#if defined(__linux__)
|
||||
buf = getenv("XDG_CONFIG_HOME");
|
||||
if (!buf) {
|
||||
|
||||
@@ -35,7 +35,7 @@ enum conf_primitive {
|
||||
|
||||
/* for outputting a fixed string as this config field */
|
||||
struct conf_fstr {
|
||||
size_t len; // length in BYTES of the output data
|
||||
usize len; // length in BYTES of the output data
|
||||
char *out; // where we will output the data
|
||||
};
|
||||
|
||||
@@ -51,10 +51,10 @@ 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(const char *restrict buf, char *restrict kout, char *restrict vout, size_t 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 found. */
|
||||
struct conf_entry const *conf_matchopt(struct conf_entry const *opts, size_t 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.
|
||||
* - `val` points to a null-terminated string which contains the key and value.
|
||||
|
||||
@@ -19,6 +19,10 @@ typedef uint16_t u16;
|
||||
typedef uint32_t u32;
|
||||
typedef uint64_t u64;
|
||||
|
||||
#include <stdlib.h>
|
||||
typedef size_t usize;
|
||||
typedef ssize_t ssize;
|
||||
|
||||
/* floating point types */
|
||||
typedef float f32; // single-precision floating-point
|
||||
typedef double f64; // double-precision floating-point
|
||||
|
||||
Reference in New Issue
Block a user