mirror of
https://github.com/thepigeongenerator/mcaselector-lite.git
synced 2025-12-18 20:35:45 +01:00
Compare commits
6 Commits
8452f7d21e
...
29c8a2b6ea
| Author | SHA1 | Date | |
|---|---|---|---|
| 29c8a2b6ea | |||
| 8cd29225d1 | |||
| 20ec45f230 | |||
| 3cdee8b40c | |||
| 89ceb5263c | |||
| 4fa0a84c94 |
@@ -100,7 +100,7 @@ const u8 *nbt_nexttag(const u8 *restrict buf) {
|
|||||||
|
|
||||||
MALLOC static void *nbt_procarr(const u8 *restrict buf, i32 nmem, uint size) {
|
MALLOC static void *nbt_procarr(const u8 *restrict buf, i32 nmem, uint size) {
|
||||||
u8 *ptr = malloc(nmem * size);
|
u8 *ptr = malloc(nmem * size);
|
||||||
if (!ptr) NULL;
|
if (!ptr) return NULL;
|
||||||
memcpy(ptr, buf, nmem * size);
|
memcpy(ptr, buf, nmem * size);
|
||||||
|
|
||||||
/* Only include this code for little-endian systems. Since only they require this logic.
|
/* Only include this code for little-endian systems. Since only they require this logic.
|
||||||
@@ -129,14 +129,13 @@ MALLOC static void *nbt_procarr(const u8 *restrict buf, i32 nmem, uint size) {
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 const u8 *nbt_proctag(const u8 *restrict buf, u8 *restrict out, u16 slen) {
|
const u8 *nbt_proctag(const u8 *restrict buf, u16 slen, void *restrict out) {
|
||||||
const u8 *ptr = buf + 3 + slen;
|
const u8 *ptr = buf + 3 + slen;
|
||||||
|
|
||||||
switch (*buf) {
|
switch (*buf) {
|
||||||
// integral types
|
// integral types
|
||||||
case NBT_I8: *out = *ptr; return ptr + 1;
|
case NBT_I8: *(u8 *)out = *ptr; return ptr + 1;
|
||||||
case NBT_I16: *(u16 *)out = be16toh(*(u16 *)ptr); return ptr + 2;
|
case NBT_I16: *(u16 *)out = be16toh(*(u16 *)ptr); return ptr + 2;
|
||||||
case NBT_I32: // fall through
|
case NBT_I32: // fall through
|
||||||
case NBT_F32: *(u32 *)out = be16toh(*(u32 *)ptr); return ptr + 4;
|
case NBT_F32: *(u32 *)out = be16toh(*(u32 *)ptr); return ptr + 4;
|
||||||
@@ -154,7 +153,7 @@ static const u8 *nbt_proctag(const u8 *restrict buf, u8 *restrict out, u16 slen)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ptr; // TODO: return end of array
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct nbt_procdat nbt_initproc(struct nbt_path const *restrict pats, uint npats) {
|
struct nbt_procdat nbt_initproc(struct nbt_path const *restrict pats, uint npats) {
|
||||||
|
|||||||
@@ -52,7 +52,15 @@ struct nbt_procdat {
|
|||||||
|
|
||||||
/* searches for the end of a named tag without processing data, the final pointer is returned.
|
/* searches for the end of a named tag without processing data, the final pointer is returned.
|
||||||
* `NULL` is returned upon failure, the otherwise returned pointer is not guaranteed to be valid. */
|
* `NULL` is returned upon failure, the otherwise returned pointer is not guaranteed to be valid. */
|
||||||
PURE NONNULL((1)) const u8 *nbt_nexttag(const u8 *restrict buf);
|
const u8 *nbt_nexttag(const u8 *restrict buf) NONNULL((1)) PURE;
|
||||||
|
|
||||||
|
/* Processes the tag entered in `buf`, `buf` is assumed to be the start of a named tag. Where `slen` shall be the string length.
|
||||||
|
* The data in `buf` is processed and outputted to `out`. A pointer to the next tag is returned.
|
||||||
|
* - In the case for all basic types, `out` will require to be the width of said type.
|
||||||
|
* - In the case of arrays, a pointer shall be returned pointing to the data. TODO: it'd be nice to know how large this array is.
|
||||||
|
* - In the case of `NBT_LIST`, if it is of the type `NBT_Ixx` and `NBT_Fxx`, then it's handled. Otherwise the funcion shall fail.
|
||||||
|
* Upon failure, `NULL` is returned. */
|
||||||
|
const u8 *nbt_proctag(const u8 *restrict buf, u16 slen, void *restrict out) NONNULL((1, 3));
|
||||||
|
|
||||||
/* initialises a data structure used whilst processing the tags */
|
/* initialises a data structure used whilst processing the tags */
|
||||||
PURE NONNULL((1)) struct nbt_procdat nbt_initproc(struct nbt_path const *restrict pats, uint npats);
|
struct nbt_procdat nbt_initproc(struct nbt_path const *restrict pats, uint npats) NONNULL((1)) PURE;
|
||||||
|
|||||||
@@ -46,14 +46,14 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __has_attribute(__format__)
|
#if __has_attribute(__format__)
|
||||||
#define FORMAT(...) __attribute__((format(__VA_ARGS__)))
|
#define FORMAT(args) __attribute__((format args))
|
||||||
#else
|
#else
|
||||||
#define FORMAT(...)
|
#define FORMAT(args)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __has_attribute(__nonnull__)
|
#if __has_attribute(__nonnull__)
|
||||||
#define NONNULL(...) __attribute__((nonnull(__VA_ARGS__)))
|
#define NONNULL(args) __attribute__((__nonnull__ args))
|
||||||
#else
|
#else
|
||||||
#define NONNULL(...)
|
#define NONNULL(args)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -127,7 +127,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 */
|
/* 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, 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, size_t s1len, size_t s2len, size_t s3len) {
|
||||||
assert(s2 || (!s2 && !s2len)); // ensuring the programmer passes both s2 and s2len as 0, if they intend to
|
assert(s2 || (!s2 && !s2len)); // ensuring the programmer passes both s2 and s2len as 0, if they intend to
|
||||||
char *buf, *ptr;
|
char *buf, *ptr;
|
||||||
|
|||||||
@@ -67,4 +67,4 @@ int conf_procval(struct conf_entry const *opts, const char *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 !! */
|
||||||
MALLOC NONNULL((1)) char *conf_getpat(const char *);
|
char *conf_getpat(const char *) MALLOC NONNULL((1));
|
||||||
|
|||||||
Reference in New Issue
Block a user