Merge branch 'master' of https://github.com/felixbrendel/ftb
This commit is contained in:
@@ -96,6 +96,7 @@ expands to:
|
|||||||
goto TOKENPASTE2(finished, __LINE__); \
|
goto TOKENPASTE2(finished, __LINE__); \
|
||||||
} \
|
} \
|
||||||
else TOKENPASTE2(body,__LINE__):
|
else TOKENPASTE2(body,__LINE__):
|
||||||
|
;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
|
// #pragma message ("Compiling for Windows")
|
||||||
|
#define FTB_WINDOWS
|
||||||
|
#else
|
||||||
|
// #pragma message ("Compiling for Linux")
|
||||||
|
#define FTB_LINUX
|
||||||
|
#endif
|
||||||
@@ -8,6 +8,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "hashmap.hpp"
|
#include "hashmap.hpp"
|
||||||
|
#include "hooks.hpp"
|
||||||
|
|
||||||
FILE* ftb_stdout = stdout;
|
FILE* ftb_stdout = stdout;
|
||||||
|
|
||||||
@@ -443,16 +444,17 @@ auto print_str_line(FILE* f, char* str) -> s32 {
|
|||||||
return print_to_file(f, "%.*s", length, str);
|
return print_to_file(f, "%.*s", length, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deinit_printer() {
|
|
||||||
printer_map.dealloc();
|
|
||||||
type_map.dealloc();
|
|
||||||
}
|
|
||||||
|
|
||||||
void init_printer() {
|
void init_printer() {
|
||||||
color_stack.alloc();
|
color_stack.alloc();
|
||||||
printer_map.alloc();
|
printer_map.alloc();
|
||||||
type_map.alloc();
|
type_map.alloc();
|
||||||
|
|
||||||
|
system_shutdown_hook << [](){
|
||||||
|
color_stack.dealloc();
|
||||||
|
printer_map.dealloc();
|
||||||
|
type_map.dealloc();
|
||||||
|
};
|
||||||
|
|
||||||
register_printer("u32", print_u32, Printer_Function_Type::_32b);
|
register_printer("u32", print_u32, Printer_Function_Type::_32b);
|
||||||
register_printer("u64", print_u64, Printer_Function_Type::_64b);
|
register_printer("u64", print_u64, Printer_Function_Type::_64b);
|
||||||
register_printer("bool", print_bool, Printer_Function_Type::_32b);
|
register_printer("bool", print_bool, Printer_Function_Type::_32b);
|
||||||
|
|||||||
+3
-1
@@ -1,3 +1,5 @@
|
|||||||
|
#include "./types.hpp"
|
||||||
|
|
||||||
typedef s32 testresult;
|
typedef s32 testresult;
|
||||||
|
|
||||||
#define epsilon 2.2204460492503131E-16
|
#define epsilon 2.2204460492503131E-16
|
||||||
@@ -88,4 +90,4 @@ typedef s32 testresult;
|
|||||||
free(error); \
|
free(error); \
|
||||||
error = nullptr; \
|
error = nullptr; \
|
||||||
} \
|
} \
|
||||||
} \
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "platform.hpp"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@@ -22,24 +23,33 @@ typedef wchar_t path_char;
|
|||||||
typedef char path_char;
|
typedef char path_char;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct String {
|
struct StringSlice {
|
||||||
|
const char* data;
|
||||||
u64 length;
|
u64 length;
|
||||||
char* data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct StringSlice {
|
struct String {
|
||||||
|
char* data;
|
||||||
u64 length;
|
u64 length;
|
||||||
const char* data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
inline auto heap_copy_c_string(const char* str) -> char* {
|
||||||
|
#ifdef FTB_WINDOWS
|
||||||
|
return _strdup(str);
|
||||||
|
#else
|
||||||
|
return strdup(str);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
inline auto make_heap_string(const char* str) -> String {
|
inline auto make_heap_string(const char* str) -> String {
|
||||||
String ret;
|
String ret;
|
||||||
ret.length = strlen(str);
|
ret.length = strlen(str);
|
||||||
ret.data = _strdup(str);
|
ret.data = heap_copy_c_string(str);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline const StringSlice make_static_string(const char* str) {
|
inline auto make_static_string(const char* str) -> const StringSlice {
|
||||||
StringSlice ret;
|
StringSlice ret;
|
||||||
ret.length = strlen(str);
|
ret.length = strlen(str);
|
||||||
ret.data = str;
|
ret.data = str;
|
||||||
@@ -50,26 +60,21 @@ auto inline string_equal(const char* input, const char* check) -> bool {
|
|||||||
return strcmp(input, check) == 0;
|
return strcmp(input, check) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Str>
|
auto inline string_equal(StringSlice str, const char* check) -> bool {
|
||||||
auto inline string_equal(Str str, const char* check) -> bool {
|
|
||||||
if (str.length != strlen(check))
|
if (str.length != strlen(check))
|
||||||
return false;
|
return false;
|
||||||
return strncmp(str.data, check, str.length) == 0;
|
return strncmp(str.data, check, str.length) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename Str>
|
auto inline string_equal(const char* check, StringSlice str) -> bool {
|
||||||
auto inline string_equal(const char* check, Str str) -> bool {
|
|
||||||
if (str.length != strlen(check))
|
if (str.length != strlen(check))
|
||||||
return false;
|
return false;
|
||||||
return strncmp(str.data, check, str.length) == 0;
|
return strncmp(str.data, check, str.length) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename StrA, typename StrB>
|
auto inline string_equal(StringSlice str1, StringSlice str2) -> bool {
|
||||||
auto inline string_equal(StrA str1, StrB str2) -> bool {
|
|
||||||
if (str1.length != str2.length)
|
if (str1.length != str2.length)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return strncmp(str1.data, str2.data, str2.length) == 0;
|
return strncmp(str1.data, str2.data, str2.length) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
template auto string_equal(StringSlice str1, StringSlice str2) -> bool;
|
|
||||||
|
|||||||
Reference in New Issue
Block a user