From f5784844a8a61c73c55f4cdbfe4b6460cac42964 Mon Sep 17 00:00:00 2001 From: Quinn Date: Wed, 21 Jan 2026 16:26:23 +0100 Subject: [PATCH] Move more of the utility headers into `/include/mcaselector-lite`. These headers have no associated C files, and are mainly used for utility logic. Having them in `/include` makes them more easily located, and more globally used. We are using "classic" header guards here over `#pragma once` for better support. Since `#pragma once` is defined by the compiler, rather than standard C. Why isn't it used across the project? I have no idea. --- {src/util => include/mcaselector-lite}/atrb.h | 5 ++++- include/{ => mcaselector-lite}/endian.h | 6 +++--- {src/util => include/mcaselector-lite}/macro.h | 5 ++++- {src => include/mcaselector-lite}/types.h | 4 +++- {src/util => include/mcaselector-lite}/util.h | 5 ++++- {src/util => include/mcaselector-lite}/vec.h | 7 +++++-- src/dat/mcx.c | 4 ++-- src/dat/mcx.h | 4 ++-- src/dat/nbt.c | 5 ++--- src/dat/nbt.h | 6 +++--- src/io/conf.c | 4 ++-- src/io/conf.h | 4 ++-- src/io/win/render.c | 2 +- src/io/win/window.c | 2 +- src/util/error.c | 3 +-- src/util/error.h | 5 ++--- 16 files changed, 41 insertions(+), 30 deletions(-) rename {src/util => include/mcaselector-lite}/atrb.h (92%) rename include/{ => mcaselector-lite}/endian.h (93%) rename {src/util => include/mcaselector-lite}/macro.h (86%) rename {src => include/mcaselector-lite}/types.h (91%) rename {src/util => include/mcaselector-lite}/util.h (83%) rename {src/util => include/mcaselector-lite}/vec.h (86%) diff --git a/src/util/atrb.h b/include/mcaselector-lite/atrb.h similarity index 92% rename from src/util/atrb.h rename to include/mcaselector-lite/atrb.h index 9d1f358..f8eeaa3 100644 --- a/src/util/atrb.h +++ b/include/mcaselector-lite/atrb.h @@ -3,7 +3,8 @@ * Copyright (C)2025 quinnthepigeon@proton.me Quinn * For further information, view COPYING and CONTRIBUTORS * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#pragma once +#ifndef MCASELECTOR_LITE_ATRB_H +#define MCASELECTOR_LITE_ATRB_H #if defined(__GNUC__) #if __has_attribute(__pure__) @@ -64,3 +65,5 @@ #define ASSUME(args) __attribute__((__assume__ args)) #endif #endif + +#endif /* MCASELECTOR_LITE_ATRB_H */ diff --git a/include/endian.h b/include/mcaselector-lite/endian.h similarity index 93% rename from include/endian.h rename to include/mcaselector-lite/endian.h index f7c9f63..52e6e86 100644 --- a/include/endian.h +++ b/include/mcaselector-lite/endian.h @@ -3,8 +3,8 @@ * Copyright (C)2025 quinnthepigeon@proton.me Quinn * For further information, view COPYING and CONTRIBUTORS * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#ifndef PORTABLE_ENDIAN_H -#define PORTABLE_ENDIAN_H 1 +#ifndef MCASELECTOR_LITE_ENDIAN_H +#define MCASELECTOR_LITE_ENDIAN_H #if defined(__GNUC__) #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ @@ -40,4 +40,4 @@ #else #error GNU C is unavailable #endif /* __GNUC__ */ -#endif /* PORTABLE_ENDIAN_H */ +#endif /* MCASELECTOR_LITE_ENDIAN_H */ diff --git a/src/util/macro.h b/include/mcaselector-lite/macro.h similarity index 86% rename from src/util/macro.h rename to include/mcaselector-lite/macro.h index ffd92cb..abd5fde 100644 --- a/src/util/macro.h +++ b/include/mcaselector-lite/macro.h @@ -3,10 +3,13 @@ * Copyright (C)2025 quinnthepigeon@proton.me Quinn * For further information, view COPYING and CONTRIBUTORS * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#pragma once +#ifndef MCASELECTOR_LITE_MACRO_H +#define MCASELECTOR_LITE_MACRO_H #define WIDTHOF(t) (sizeof(t) * 8) // gets the bit width of a type #define MACRO_CAT(x, y) x##y // concatenate two macro variables together #define MACRO_CAT2(x, y) MACRO_CAT(x, y) // concatenate two macro variables together #define MACRO_STR(v) #v // for converting macro variable into a string #define MACRO_STR2(v) MACRO_STR(v) // for a recursive string generation + +#endif /* MCASELECTOR_LITE_MACRO_H */ diff --git a/src/types.h b/include/mcaselector-lite/types.h similarity index 91% rename from src/types.h rename to include/mcaselector-lite/types.h index d977720..d04edbf 100644 --- a/src/types.h +++ b/include/mcaselector-lite/types.h @@ -3,7 +3,8 @@ * Copyright (C)2025 quinnthepigeon@proton.me Quinn * For further information, view COPYING and CONTRIBUTORS * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#pragma once +#ifndef MCASELECTOR_LITE_TYPES_H +#define MCASELECTOR_LITE_TYPES_H typedef signed long long int llong; typedef unsigned short int ushort; @@ -36,3 +37,4 @@ typedef float f32; #if __SIZEOF_DOUBLE__ == 8 typedef double f64; #endif +#endif /* MCASELECTOR_LITE_TYPES_H */ diff --git a/src/util/util.h b/include/mcaselector-lite/util.h similarity index 83% rename from src/util/util.h rename to include/mcaselector-lite/util.h index 4b773c1..b15e861 100644 --- a/src/util/util.h +++ b/include/mcaselector-lite/util.h @@ -3,9 +3,12 @@ * Copyright (C)2025 quinnthepigeon@proton.me Quinn * For further information, view COPYING and CONTRIBUTORS * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#pragma once +#ifndef MCASELECTOR_LITE_UTIL_H +#define MCASELECTOR_LITE_UTIL_H /* Acquires the next power of two of value `x`. * Automatically determines the type (and therefore the width) of `x`. * Explicitly cast `x` to a desired width, if necessary. */ #define bit_ceil(x) (1 << (sizeof(__typeof__(x)) * 8 - __builtin_clzg(((x) - !!(x)) | 1))) + +#endif /* MCASELECTOR_LITE_UTIL_H */ diff --git a/src/util/vec.h b/include/mcaselector-lite/vec.h similarity index 86% rename from src/util/vec.h rename to include/mcaselector-lite/vec.h index 1b7e962..a13f9b8 100644 --- a/src/util/vec.h +++ b/include/mcaselector-lite/vec.h @@ -3,9 +3,10 @@ * Copyright (C)2025 quinnthepigeon@proton.me Quinn * For further information, view COPYING and CONTRIBUTORS * at: www.github.com/thepigeongenerator/mcaselector-lite */ -#pragma once +#ifndef MCASELECTOR_LITE_VEC_H +#define MCASELECTOR_LITE_VEC_H -#include "../types.h" +#include #if defined(__has_attribute) && __has_attribute(vector_size) typedef float fvec2 __attribute__((vector_size(sizeof(float) * 2))); // SMID vector for 2 `float` @@ -21,3 +22,5 @@ typedef u8 u8vec4 __attribute__((vector_size(sizeof(u8) * 4))); // SMID vector f #define VY 1 #define VZ 2 #define VW 3 + +#endif /* MCASELECTOR_LITE_VEC_H */ diff --git a/src/dat/mcx.c b/src/dat/mcx.c index fd52228..e5725f6 100644 --- a/src/dat/mcx.c +++ b/src/dat/mcx.c @@ -7,13 +7,13 @@ #include #include -#include +#include +#include #include #include #include #include -#include "../types.h" #include "../util/error.h" #define SECTOR 0x1000 // sector size diff --git a/src/dat/mcx.h b/src/dat/mcx.h index 949920f..161e672 100644 --- a/src/dat/mcx.h +++ b/src/dat/mcx.h @@ -5,10 +5,10 @@ * at: www.github.com/thepigeongenerator/mcaselector-lite */ #pragma once +#include +#include #include -#include "../types.h" -#include "../util/atrb.h" /* contains chunk metadata */ struct mcx_chunk { diff --git a/src/dat/nbt.c b/src/dat/nbt.c index 46c61f4..73dde5f 100644 --- a/src/dat/nbt.c +++ b/src/dat/nbt.c @@ -6,13 +6,12 @@ #include "nbt.h" #include -#include +#include +#include #include #include #include -#include "../types.h" - #define MAX_DEPTH 512 /* Extracts a big endian 16 bit integer from address `buf`, converts it to host byte size if needed and returns. */ diff --git a/src/dat/nbt.h b/src/dat/nbt.h index e21decd..6cdaf6b 100644 --- a/src/dat/nbt.h +++ b/src/dat/nbt.h @@ -6,12 +6,12 @@ #pragma once #include -#include +#include +#include +#include #include #include -#include "../types.h" -#include "../util/atrb.h" /* NBT (named binary tag) is a tree data structure. Tags have a numeric type ID, name and a payload. * NBT files are a compressed `compound` tag. GZip is the compression used in most cases, diff --git a/src/io/conf.c b/src/io/conf.c index f1d11e6..268f8c6 100644 --- a/src/io/conf.c +++ b/src/io/conf.c @@ -7,11 +7,11 @@ #include #include +#include +#include #include #include -#include "../types.h" -#include "../util/atrb.h" /* Matches s1 with s2, returns a pointer to s1 where the match stopped. */ static const char *strmat(const char *s1, const char *s2) PURE NONNULL((1, 2)); diff --git a/src/io/conf.h b/src/io/conf.h index c11e539..c464b76 100644 --- a/src/io/conf.h +++ b/src/io/conf.h @@ -4,8 +4,8 @@ * For further information, view COPYING and CONTRIBUTORS * at: www.github.com/thepigeongenerator/mcaselector-lite */ #pragma once -#include "../types.h" -#include "../util/atrb.h" +#include +#include enum conf_type { CONF_STR = 0x00, diff --git a/src/io/win/render.c b/src/io/win/render.c index 162e5ac..5ff9711 100644 --- a/src/io/win/render.c +++ b/src/io/win/render.c @@ -7,9 +7,9 @@ #include #include +#include #include -#include "../../types.h" #include "../../util/error.h" #include "shader.h" diff --git a/src/io/win/window.c b/src/io/win/window.c index 9168e27..b7a2fc0 100644 --- a/src/io/win/window.c +++ b/src/io/win/window.c @@ -8,8 +8,8 @@ #include #include #include +#include -#include "../../types.h" #include "../../util/error.h" #include "input.h" #include "render.h" diff --git a/src/util/error.c b/src/util/error.c index e2f7a19..3f17c7b 100644 --- a/src/util/error.c +++ b/src/util/error.c @@ -5,11 +5,10 @@ * at: www.github.com/thepigeongenerator/mcaselector-lite */ #include "error.h" +#include #include #include -#include "../types.h" - static void error_log(FILE *restrict stream, const char *restrict pfx, uint ln, const char *restrict file, const char *restrict fmt, va_list ap) { fprintf(stream, "(%s:%u) [%s] '", file, ln, pfx); diff --git a/src/util/error.h b/src/util/error.h index 4a24590..7646cc3 100644 --- a/src/util/error.h +++ b/src/util/error.h @@ -5,12 +5,11 @@ * at: www.github.com/thepigeongenerator/mcaselector-lite */ #pragma once +#include +#include #include #include -#include "../types.h" -#include "atrb.h" - void error_debug(uint ln, const char *restrict file, const char *restrict fmt, ...); void error_info(uint ln, const char *restrict file, const char *restrict fmt, ...); void error_warn(uint ln, const char *restrict file, const char *restrict fmt, ...);