From b3bfc19108a600caba35522cf140326517f56a5a Mon Sep 17 00:00:00 2001 From: gingerBill Date: Sun, 27 Sep 2015 17:40:52 +0100 Subject: [PATCH] Fix Silly Mistakes --- gb_ini.h | 94 ++++++++++++------------ gb_string.h | 207 ++++++++++++++++++++++++++-------------------------- 2 files changed, 151 insertions(+), 150 deletions(-) diff --git a/gb_ini.h b/gb_ini.h index b7c3ebd..3e59aac 100644 --- a/gb_ini.h +++ b/gb_ini.h @@ -154,7 +154,7 @@ static GB_INI_HANDLER(test_ini_handler) int main(int argc, char** argv) { Library lib = {}; - + using namespace gb; Ini_Error err = ini_parse("test.ini", &test_ini_handler, &lib); @@ -255,6 +255,51 @@ gb_ini_error_string(const struct gb_Ini_Error err) } #endif +#ifdef GB_INI_CPP +#if !defined(__cplusplus) +#error You need to compile as C++ for the C++ version of gb_ini.h to work +#endif + +namespace gb +{ +typedef gb_Ini_Error Ini_Error; +typedef gb_Ini_Handler Ini_Handler; + +// Just a copy but with the GB_ prefix stripped +enum +{ + INI_ERROR_NONE = 0, + + INI_ERROR_FILE_ERROR, + INI_ERROR_MISSING_SECTION_BRACKET, + INI_ERROR_ASSIGNMENT_MISSING, + INI_ERROR_HANDLER_ERROR, + + // No need for enum count +}; + +Ini_Error +ini_parse(const char* filename, Ini_Handler* handler_func, void* data) +{ + return gb_ini_parse(filename, handler_func, data); +} + +Ini_Error +ini_parse(FILE* file, Ini_Handler* handler_func, void* data) +{ + return gb_ini_parse_file(file, handler_func, data); +} + +const char* +ini_error_string(const Ini_Error err) +{ + return GB_ERROR_STRINGS[err.type]; +} + +} // namespace gb +#endif // GB_INI_CPP +#endif // GB_INI_INCLUDE_GB_INI_H + #ifdef GB_INI_IMPLEMENTATION #include #include @@ -351,7 +396,7 @@ gb_ini_parse_file(FILE* file, gb_Ini_Handler* handler_func, void* data) { start += 3; } -#endif +#endif start = gb__left_whitespace_skip(gb__right_whitespace_strip(start)); @@ -413,48 +458,3 @@ gb_ini_parse_file(FILE* file, gb_Ini_Handler* handler_func, void* data) } #endif // GB_INI_IMPLEMENTATION - -#ifdef GB_INI_CPP -#if !defined(__cplusplus) -#error You need to compile as C++ for the C++ version of gb_ini.h to work -#endif - -namespace gb -{ -typedef gb_Ini_Error Ini_Error; -typedef gb_Ini_Handler Ini_Handler; - -// Just a copy but with the GB_ prefix stripped -enum -{ - INI_ERROR_NONE = 0, - - INI_ERROR_FILE_ERROR, - INI_ERROR_MISSING_SECTION_BRACKET, - INI_ERROR_ASSIGNMENT_MISSING, - INI_ERROR_HANDLER_ERROR, - - // No need for enum count -}; - -Ini_Error -ini_parse(const char* filename, Ini_Handler* handler_func, void* data) -{ - return gb_ini_parse(filename, handler_func, data); -} - -Ini_Error -ini_parse(FILE* file, Ini_Handler* handler_func, void* data) -{ - return gb_ini_parse_file(file, handler_func, data); -} - -const char* -ini_error_string(const Ini_Error err) -{ - return GB_ERROR_STRINGS[err.type]; -} - -} // namespace gb -#endif // GB_INI_CPP -#endif // GB_INI_INCLUDE_GB_INI_H diff --git a/gb_string.h b/gb_string.h index c5bd397..db48c84 100644 --- a/gb_string.h +++ b/gb_string.h @@ -112,12 +112,13 @@ // // C example #if 0 +#include +#include + #define GB_STRING_IMPLEMENTATION #include "gb_string.h" -#include - -void string_test(void) +int main(int argc, char** argv) { gb_String str = gb_make_string("Hello"); gb_String other_str = gb_make_string_length(", ", 2); @@ -150,13 +151,14 @@ void string_test(void) // // C++ example #if 0 +#include +#include + #define GB_STRING_CPP #define GB_STRING_IMPLEMENTATION #include "gb_string.h" -#include - -void string_test() +int main(int argc, char** argv) { using namespace gb; @@ -243,7 +245,7 @@ struct gb_String_Header gb_usize cap; }; -#define GB_STRING_HEADER(s) ((struct gb_String_Header*)((s) - sizeof(struct gb_String_Header))) +#define GB_STRING_HEADER(s) ((struct gb_String_Header*)s - 1) gb_String gb_make_string(const char* str); gb_String gb_make_string_length(const void* str, gb_usize len); @@ -275,6 +277,101 @@ gb_String gb_trim_string(gb_String str, const char* cut_set); } #endif +#if defined(GB_STRING_CPP) + +#if !defined(__cplusplus) +#error You need to compile as C++ for the C++ version of gb_string.h to work +#endif + +namespace gb +{ +typedef gb_String String; +typedef gb_usize usize; + +gb_inline String make_string(const char* str = "") +{ + return gb_make_string(str); +} + +gb_inline String make_string(const void* str, usize len) +{ + return gb_make_string_length(str, len); +} + +gb_inline void free_string(String& str) +{ + gb_make_string(str); + str = GB_NULLPTR; +} + +gb_inline String duplicate_string(const String str) +{ + return gb_duplicate_string(str); +} + +gb_inline usize string_length(const String str) +{ + return gb_string_length(str); +} + +gb_inline usize string_capacity(const String str) +{ + return gb_string_capacity(str); +} + +gb_inline usize string_available_space(const String str) +{ + return gb_string_available_space(str); +} + +gb_inline void clear_string(String str) +{ + gb_clear_string(str); +} + +gb_inline void append_string_length(String& str, const void* other, usize len) +{ + str = gb_append_string_length(str, other, len); +} + +gb_inline void append_string(String& str, const String other) +{ + str = gb_append_string(str, other); +} + +gb_inline void append_cstring(String& str, const char* other) +{ + str = gb_append_cstring(str, other); +} + +gb_inline void set_string(String& str, const char* cstr) +{ + str = gb_set_string(str, cstr); +} + +gb_inline void string_make_space_for(String& str, usize add_len) +{ + str = gb_string_make_space_for(str, add_len); +} + +gb_inline usize string_allocation_size(const String str) +{ + return gb_string_allocation_size(str); +} + +gb_inline bool strings_are_equal(const String lhs, const String rhs) +{ + return gb_strings_are_equal(lhs, rhs) == GB_TRUE; +} + +gb_inline void trim_string(String& str, const char* cut_set) +{ + str = gb_trim_string(str, cut_set); +} + +} // namespace gb +#endif // GB_STRING_CPP +#endif // GB_STRING_H #ifdef GB_STRING_IMPLEMENTATION static void gb_set_string_length(gb_String str, gb_usize len) { @@ -491,99 +588,3 @@ gb_String gb_trim_string(gb_String str, const char* cut_set) #endif // GB_STRING_IMPLEMENTATION -#if defined(GB_STRING_CPP) - -#if !defined(__cplusplus) -#error You need to compile as C++ for the C++ version of gb_string.h to work -#endif - -namespace gb -{ -typedef gb_String String; -typedef gb_usize usize; - -gb_inline String make_string(const char* str = "") -{ - return gb_make_string(str); -} - -gb_inline String make_string(const void* str, usize len) -{ - return gb_make_string_length(str, len); -} - -gb_inline void free_string(String& str) -{ - gb_make_string(str); - str = GB_NULLPTR; -} - -gb_inline String duplicate_string(const String str) -{ - return gb_duplicate_string(str); -} - -gb_inline usize string_length(const String str) -{ - return gb_string_length(str); -} - -gb_inline usize string_capacity(const String str) -{ - return gb_string_capacity(str); -} - -gb_inline usize string_available_space(const String str) -{ - return gb_string_available_space(str); -} - -gb_inline void clear_string(String str) -{ - gb_clear_string(str); -} - -gb_inline void append_string_length(String& str, const void* other, usize len) -{ - str = gb_append_string_length(str, other, len); -} - -gb_inline void append_string(String& str, const String other) -{ - str = gb_append_string(str, other); -} - -gb_inline void append_cstring(String& str, const char* other) -{ - str = gb_append_cstring(str, other); -} - -gb_inline void set_string(String& str, const char* cstr) -{ - str = gb_set_string(str, cstr); -} - -gb_inline void string_make_space_for(String& str, usize add_len) -{ - str = gb_string_make_space_for(str, add_len); -} - -gb_inline usize string_allocation_size(const String str) -{ - return gb_string_allocation_size(str); -} - -gb_inline bool strings_are_equal(const String lhs, const String rhs) -{ - return gb_strings_are_equal(lhs, rhs) == GB_TRUE; -} - -gb_inline void trim_string(String& str, const char* cut_set) -{ - str = gb_trim_string(str, cut_set); -} - -} // namespace gb -#endif // GB_STRING_CPP - -#endif // GB_STRING_HP