Replace pragma onces with guards because preproc names are useful

This commit is contained in:
Krzosa Karol
2024-01-28 19:17:13 +01:00
parent 57b61e366f
commit 908cfca794
15 changed files with 184 additions and 152 deletions

View File

@@ -1,4 +1,6 @@
#pragma once #ifndef FIRST_CORE_HEADER
#define FIRST_CORE_HEADER
#include "../standalone_libraries/preproc_env.h" #include "../standalone_libraries/preproc_env.h"
#include "../standalone_libraries/stb_sprintf.h" #include "../standalone_libraries/stb_sprintf.h"
#include "../standalone_libraries/io.h" #include "../standalone_libraries/io.h"
@@ -29,3 +31,5 @@
if (!allocator.p) allocator = M_GetSystemAllocator(); if (!allocator.p) allocator = M_GetSystemAllocator();
#include "../standalone_libraries/array.hpp" #include "../standalone_libraries/array.hpp"
#endif #endif
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_ARRAY_HEADER
#define FIRST_ARRAY_HEADER
#ifndef ARRAY_REALLOCATE #ifndef ARRAY_REALLOCATE
#include <stdlib.h> #include <stdlib.h>
@@ -33,7 +34,7 @@
// if (it == 4) ForArrayRemovableDeclare(); // if (it == 4) ForArrayRemovableDeclare();
// } // }
// //
#ifdef DEFER_HEADER #ifdef FIRST_DEFER_HEADER
#define ForArrayRemovable(a) for (int __i = 0; __i < (a).len; __i += 1) #define ForArrayRemovable(a) for (int __i = 0; __i < (a).len; __i += 1)
#define ForArrayRemovablePrepare(a) \ #define ForArrayRemovablePrepare(a) \
auto &it = (a)[__i]; \ auto &it = (a)[__i]; \
@@ -301,3 +302,5 @@ struct Array {
} }
} }
}; };
#endif

View File

@@ -1,4 +1,6 @@
#pragma once #ifndef FIRST_CL_HEADER
#define FIRST_CL_HEADER
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#include <stddef.h> #include <stddef.h>
@@ -296,3 +298,5 @@ CL_INLINE bool CL_IsKeywordOrIdent(CL_Kind kind) {
bool result = CL_IsKeyword(kind) || kind == CL_IDENTIFIER; bool result = CL_IsKeyword(kind) || kind == CL_IDENTIFIER;
return result; return result;
} }
#endif

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef FIRST_DEFER_HEADER
#define DEFER_HEADER #define FIRST_DEFER_HEADER
template <typename T> template <typename T>
struct DEFER_ExitScope { struct DEFER_ExitScope {
@@ -21,3 +21,5 @@ class DEFER_ExitScopeHelp {
#define DEFER_CONCAT_INTERNAL(x, y) x##y #define DEFER_CONCAT_INTERNAL(x, y) x##y
#define DEFER_CONCAT(x, y) DEFER_CONCAT_INTERNAL(x, y) #define DEFER_CONCAT(x, y) DEFER_CONCAT_INTERNAL(x, y)
#define defer const auto DEFER_CONCAT(defer__, __LINE__) = DEFER_ExitScopeHelp() + [&]() #define defer const auto DEFER_CONCAT(defer__, __LINE__) = DEFER_ExitScopeHelp() + [&]()
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_HASH_HEADER
#define FIRST_HASH_HEADER
#include <stdint.h> #include <stdint.h>
#ifndef HASH_API_FUNCTION #ifndef HASH_API_FUNCTION
@@ -24,3 +25,4 @@ HASH_API_FUNCTION uint64_t HashMix(uint64_t x, uint64_t y);
#define WRAP_AROUND_POWER_OF_2(x, pow2) (((x) & ((pow2)-1llu))) #define WRAP_AROUND_POWER_OF_2(x, pow2) (((x) & ((pow2)-1llu)))
static inline float GetRandomNormalF(RandomSeed *series) { return (float)GetRandomNormal(series); } static inline float GetRandomNormalF(RandomSeed *series) { return (float)GetRandomNormal(series); }
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_IO_HEADER
#define FIRST_IO_HEADER
#include <stdbool.h> #include <stdbool.h>
#ifndef IO_API #ifndef IO_API
@@ -87,3 +88,4 @@ const int IO_KindWarningf = 2;
#define IO_Printf(...) IO__Printf(IO_KindPrintf, __FILE__, __LINE__, __VA_ARGS__) #define IO_Printf(...) IO__Printf(IO_KindPrintf, __FILE__, __LINE__, __VA_ARGS__)
#define IO_Warningf(...) IO__Printf(IO_KindWarningf, __FILE__, __LINE__, __VA_ARGS__) #define IO_Warningf(...) IO__Printf(IO_KindWarningf, __FILE__, __LINE__, __VA_ARGS__)
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_LL_HEADER
#define FIRST_LL_HEADER
#define SLL_QUEUE_ADD_MOD(f, l, n, next) \ #define SLL_QUEUE_ADD_MOD(f, l, n, next) \
do { \ do { \
(n)->next = 0; \ (n)->next = 0; \
@@ -123,3 +124,4 @@
} while (0) } while (0)
#define DLL_INSERT_NEXT(base, new) DLL_INSERT_NEXT_MOD(base, new, next, prev) #define DLL_INSERT_NEXT(base, new) DLL_INSERT_NEXT_MOD(base, new, next, prev)
#define DLL_INSERT_PREV(base, new) DLL_INSERT_NEXT_MOD(base, new, next, prev) #define DLL_INSERT_PREV(base, new) DLL_INSERT_NEXT_MOD(base, new, next, prev)
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_LIB_HEADER
#define FIRST_LIB_HEADER
typedef void *LIB_Library; typedef void *LIB_Library;
LIB_Library LIB_LoadLibrary(char *str); LIB_Library LIB_LoadLibrary(char *str);
@@ -8,3 +9,4 @@ bool LIB_UnloadLibrary(LIB_Library lib);
#ifndef LIB_EXPORT #ifndef LIB_EXPORT
#define LIB_EXPORT __declspec(dllexport) #define LIB_EXPORT __declspec(dllexport)
#endif #endif
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_MU_HEADER
#define FIRST_MU_HEADER
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
@@ -366,3 +367,4 @@ typedef struct MU_Event {
*/ */
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_ENV_HEADER
#define FIRST_ENV_HEADER
#ifndef _CRT_SECURE_NO_WARNINGS #ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS #define _CRT_SECURE_NO_WARNINGS
#endif #endif
@@ -116,3 +117,4 @@
// #pragma clang diagnostic push // #pragma clang diagnostic push
// #pragma clang diagnostic ignored "-Wmicrosoft-enum-forward-reference" // #pragma clang diagnostic ignored "-Wmicrosoft-enum-forward-reference"
// #endif // #endif
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_REGEX_HEADER
#define FIRST_REGEX_HEADER
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
@@ -91,3 +92,4 @@ RE_API RE_Match RE3_FindAgain(RE_Regex *regex, char *string, RE_Int len, RE_Matc
RE_API RE_Int RE3_MatchFront(RE_Regex *regex, char *string, RE_Int len, char *string_front); RE_API RE_Int RE3_MatchFront(RE_Regex *regex, char *string, RE_Int len, char *string_front);
RE_API RE_Regex *RE1_Parse(char *buff, RE_Int buffsize, char *string); RE_API RE_Regex *RE1_Parse(char *buff, RE_Int buffsize, char *string);
RE_API RE_Regex *RE2_Parse(char *buff, RE_Int buffsize, char *string, RE_Int len); RE_API RE_Regex *RE2_Parse(char *buff, RE_Int buffsize, char *string, RE_Int len);
#endif

View File

@@ -530,7 +530,7 @@ S8_API S8_String S8_AddF(S8_Allocator allocator, S8_List *list, const char *str,
return result; return result;
} }
#ifdef UTF_HEADER #ifdef FIRST_UTF_HEADER
S8_API S16_String S8_ToWidecharEx(S8_Allocator allocator, S8_String string) { S8_API S16_String S8_ToWidecharEx(S8_Allocator allocator, S8_String string) {
S8_ASSERT(sizeof(wchar_t) == 2); S8_ASSERT(sizeof(wchar_t) == 2);

View File

@@ -1,5 +1,5 @@
#pragma once #ifndef FIRST_S8_STRING
#define S8_HEADER #define FIRST_S8_STRING
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
@@ -32,7 +32,7 @@ struct S8_String {
S8_String(char *s, int64_t l) : str(s), len(l) {} S8_String(char *s, int64_t l) : str(s), len(l) {}
S8_String(const char *s) : str((char *)s), len(S8_Length((char *)s)) {} S8_String(const char *s) : str((char *)s), len(S8_Length((char *)s)) {}
S8_String(const char *s, int64_t l) : str((char *)s), len(l) {} S8_String(const char *s, int64_t l) : str((char *)s), len(l) {}
#if defined(UTF_HEADER) #if defined(FIRST_UTF_HEADER)
struct Iter { struct Iter {
UTF8_Iter i; UTF8_Iter i;
@@ -47,7 +47,7 @@ struct S8_String {
Iter begin() { return {UTF8_IterateEx(str, (int)len)}; } Iter begin() { return {UTF8_IterateEx(str, (int)len)}; }
Iter end() { return {}; } Iter end() { return {}; }
#endif // UTF_HEADER #endif // FIRST_UTF_HEADER
#endif // __cplusplus #endif // __cplusplus
}; };
@@ -192,3 +192,4 @@ inline S8_String operator""_s(const char *str, size_t size) { return {(char *)st
inline bool operator==(S8_String a, S8_String b) { return S8_AreEqual(a, b, 0); } inline bool operator==(S8_String a, S8_String b) { return S8_AreEqual(a, b, 0); }
inline bool operator!=(S8_String a, S8_String b) { return !S8_AreEqual(a, b, 0); } inline bool operator!=(S8_String a, S8_String b) { return !S8_AreEqual(a, b, 0); }
#endif #endif
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_TABLE_HEADER
#define FIRST_TABLE_HEADER
#include <stdint.h> #include <stdint.h>
/* /*
Hash table implementation: Hash table implementation:
@@ -222,7 +223,7 @@ struct Table {
return get(hash, default_value); return get(hash, default_value);
} }
#ifdef S8_HEADER #ifdef FIRST_S8_HEADER
Value *get(S8_String s) { Value *get(S8_String s) {
uint64_t hash = TABLE_HASH_BYTES(s.str, (unsigned)s.len); uint64_t hash = TABLE_HASH_BYTES(s.str, (unsigned)s.len);
return get(hash); return get(hash);
@@ -260,3 +261,4 @@ struct Table {
values = 0; values = 0;
} }
}; };
#endif

View File

@@ -1,4 +1,5 @@
#pragma once #ifndef FIRST_UTF_HEADER
#define FIRST_UTF_HEADER
#define UTF_HEADER #define UTF_HEADER
#include <stdint.h> #include <stdint.h>
typedef struct UTF32_Result UTF32_Result; typedef struct UTF32_Result UTF32_Result;
@@ -51,3 +52,4 @@ UTF_API UTF8_Iter UTF8_IterateEx(char *str, int len);
UTF_API UTF8_Iter UTF8_Iterate(char *str); UTF_API UTF8_Iter UTF8_Iterate(char *str);
#define UTF8_For(name, str, len) for (UTF8_Iter name = UTF8_IterateEx(str, (int)len); name.item; UTF8_Advance(&name)) #define UTF8_For(name, str, len) for (UTF8_Iter name = UTF8_IterateEx(str, (int)len); name.item; UTF8_Advance(&name))
#endif