From 38414d5cb90b428e1c8843692db41e1c926ce2be Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 9 Jul 2017 15:00:06 -0400 Subject: [PATCH 1/5] fucked everything over --- meta/4ed_file_moving.h | 14 ++++----- meta/build.cpp | 49 ++++++++++++++---------------- string/4coder_string_build_num.txt | 2 +- string/string_builder.cpp | 30 +++++++++--------- 4 files changed, 45 insertions(+), 50 deletions(-) diff --git a/meta/4ed_file_moving.h b/meta/4ed_file_moving.h index 8ed07b3c..7733e1a4 100644 --- a/meta/4ed_file_moving.h +++ b/meta/4ed_file_moving.h @@ -76,9 +76,9 @@ internal char **fm_prepare_list_internal(char **l1, ...); internal char **fm_list_one_item(char *item); // File System Navigation -typedef umem Temp_Memory; -internal Temp_Memory fm_begin_temp(); -internal void fm_end_temp(Temp_Memory temp); +typedef umem String_Temp; +internal String_Temp fm_begin_temp(); +internal void fm_end_temp(String_Temp temp); internal i32 fm_get_current_directory(char *buffer, i32 max); @@ -186,13 +186,13 @@ fm__init_memory(){ fm_arena_memory = (char*)malloc(fm_arena_max); } -internal Temp_Memory +internal String_Temp fm_begin_temp(){ return(fm_arena_pos); } internal void -fm_end_temp(Temp_Memory temp){ +fm_end_temp(String_Temp temp){ fm_arena_pos = temp; } @@ -503,7 +503,7 @@ fm__prepare(umem item_size, void *i1, va_list list){ umem size = listsize(i1, item_size); void *result = (void*)fm__push(size); memcpy(result, i1, size); - + void *ln = va_arg(list, void*); for (;ln != 0;){ size = listsize(ln, item_size); @@ -511,7 +511,7 @@ fm__prepare(umem item_size, void *i1, va_list list){ memcpy(new_str, ln, size); ln = va_arg(list, void*); } - + void *terminator = (void*)fm__push(item_size); memset(terminator, 0, item_size); return(result); diff --git a/meta/build.cpp b/meta/build.cpp index 327426e8..9f91d195 100644 --- a/meta/build.cpp +++ b/meta/build.cpp @@ -189,20 +189,19 @@ get_defines_from_flags(u32 flags){ "user32.lib winmm.lib gdi32.lib opengl32.lib " \ "..\\foreign_x86\\freetype.lib" - #define CL_ICON "..\\res\\icon.res" static void build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ Temp_Dir temp = fm_pushdir(out_path); - + Build_Line line; fm_init_build_line(&line); if (arch == Arch_X86){ fm_add_to_line(line, "%s\\windows_scripts\\setup_cl_x86.bat &", code_path); } - + fm_add_to_line(line, "cl"); if (flags & OPTS){ @@ -210,8 +209,8 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c } switch (arch){ - case Arch_X64: fm_add_to_line(line, "/DFTECH_64_BIT"); break; - case Arch_X86: fm_add_to_line(line, "/DFTECH_32_BIT"); break; + case Arch_X64: fm_add_to_line(line, "-DFTECH_64_BIT"); break; + case Arch_X86: fm_add_to_line(line, "-DFTECH_32_BIT"); break; default: InvalidCodePath; } @@ -219,7 +218,7 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c if (inc_folders != 0){ for (u32 i = 0; inc_folders[i] != 0; ++i){ char *str = fm_str(code_path, "/", inc_folders[i]); - fm_add_to_line(line, "/I%s", str); + fm_add_to_line(line, "-I%s", str); } } @@ -236,51 +235,51 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c } if (flags & DEBUG_INFO){ - fm_add_to_line(line, "/Zi"); + fm_add_to_line(line, "-Zi"); } if (flags & OPTIMIZATION){ - fm_add_to_line(line, "/O2"); + fm_add_to_line(line, "-O2"); } if (flags & SHARED_CODE){ - fm_add_to_line(line, "/LD"); + fm_add_to_line(line, "-LD"); } if (defines != 0){ for (u32 i = 0; defines[i] != 0; ++i){ - char *define_flag = fm_str("/D", defines[i]); - fm_add_to_line(line, define_flag); + char *define_flag = fm_str("-D", defines[i]); + fm_add_to_line(line, "%s", define_flag); } } - + for (u32 i = 0; code_files[i]; ++i){ fm_add_to_line(line, "\"%s\\%s\"", code_path, code_files[i]); } - - fm_add_to_line(line, "/Fe%s", out_file); - - fm_add_to_line(line, "/link /INCREMENTAL:NO"); + + fm_add_to_line(line, "-Fe%s", out_file); + + fm_add_to_line(line, "-link -INCREMENTAL:NO"); switch (arch){ - case Arch_X64: fm_add_to_line(line, "/MACHINE:X64"); break; - case Arch_X86: fm_add_to_line(line, "/MACHINE:X86"); break; + case Arch_X64: fm_add_to_line(line, "-MACHINE:X64"); break; + case Arch_X86: fm_add_to_line(line, "-MACHINE:X86"); break; default: InvalidCodePath; } if (flags & DEBUG_INFO){ - fm_add_to_line(line, "/DEBUG"); + fm_add_to_line(line, "-DEBUG"); } if (flags & SHARED_CODE){ Assert(exports != 0); fm_add_to_line(line, "/OPT:REF"); for (u32 i = 0; exports[i] != 0; ++i){ - char *str = fm_str("/EXPORT:", exports[i]); + char *str = fm_str("-EXPORT:", exports[i]); fm_add_to_line(line, "%s", str); } } else{ - fm_add_to_line(line, "/NODEFAULTLIB:library"); + fm_add_to_line(line, "-NODEFAULTLIB:library"); } fm_finish_build_line(&line); @@ -355,8 +354,6 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c } fm_add_to_line(line, GCC_INCLUDES" %s", freetype_include); -#else - fm_add_to_line(line, GCC_INCLUDES); #endif } #endif @@ -387,7 +384,7 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c fm_add_to_line(line, "%s", define_flag); } } - + fm_add_to_line(line, "-I\"%s\"", code_path); for (u32 i = 0; code_files[i] != 0; ++i){ fm_add_to_line(line, "\"%s/%s\"", code_path, code_files[i]); @@ -568,7 +565,7 @@ package(char *cdir){ char *tier = tiers[tier_index]; u32 flags = base_flags | tier_flags[tier_index]; - Temp_Memory temp = fm_begin_temp(); + String_Temp temp = fm_begin_temp(); char *tier_package_root = fm_str(base_package_root, "_", tier); for (u32 arch = 0; arch < Arch_COUNT; ++arch){ char *par_dir = fm_str(tier_package_root, "_", arch_names[arch]); @@ -622,7 +619,7 @@ package(char *cdir){ // NOTE(allen): power { - Temp_Memory temp = fm_begin_temp(); + String_Temp temp = fm_begin_temp(); char *pack_power_par_dir = fm_str("../current_dist_power"); char *pack_power_dir = fm_str(pack_power_par_dir, "/power"); diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt index 5e3d1b74..f92a4013 100644 --- a/string/4coder_string_build_num.txt +++ b/string/4coder_string_build_num.txt @@ -1,5 +1,5 @@ 1 0 -87 +88 diff --git a/string/string_builder.cpp b/string/string_builder.cpp index 6604a190..9af5b47e 100644 --- a/string/string_builder.cpp +++ b/string/string_builder.cpp @@ -6,16 +6,6 @@ Created 21.01.2017 (dd.mm.yyyy) // TOP -#include "../4cpp/4cpp_lexer.h" -// TODO(allen): Make sure to only publish the 4coder_string.h if it builds and passes a series of tests. -#define FSTRING_IMPLEMENTATION -#include "../4coder_lib/4coder_string.h" - -#include "../4ed_defines.h" -#include "../meta/4ed_meta_defines.h" -#include "../meta/4ed_file_moving.h" - - #define BUILD_NUMBER_FILE "4coder_string_build_num.txt" #define GENERATED_FILE "4coder_string.h" @@ -24,6 +14,16 @@ Created 21.01.2017 (dd.mm.yyyy) #define BACKUP_FOLDER ".." SLASH ".." SLASH "string_backup" #define PUBLISH_FOLDER ".." SLASH "4coder_helper" +#include "../4cpp/4cpp_lexer.h" +// TODO(allen): Make sure to only publish the 4coder_string.h if it builds and passes a series of tests. +#define FSTRING_IMPLEMENTATION +#include "../4coder_lib/4coder_string.h" + +#include "../4ed_defines.h" +#include "../meta/4ed_meta_defines.h" + +#define FTECH_FILE_MOVING_IMPLEMENTATION +#include "../meta/4ed_file_moving.h" #include #include @@ -158,11 +158,12 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){ internal void file_move(char *path, char *file_name){ - copy_file(0, file_name, path, 0, file_name); + fm_copy_file(fm_str(file_name), fm_str(path, file_name)); } int main(){ META_BEGIN(); + fm_init_system(); i32 size = (512 << 20); void *mem = malloc(size); @@ -467,11 +468,11 @@ int main(){ // NOTE(allen): Publish the new file. (Would like to be able to automatically test the result before publishing). { - make_folder_if_missing(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, 0); + fm_make_folder_if_missing(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN); file_move(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, INTERNAL_STRING); file_move(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, GENERATED_FILE); //file_move(PUBLISH_FOLDER, GENERATED_FILE); - delete_file(GENERATED_FILE); + fm_delete_file(GENERATED_FILE); printf("published "GENERATED_FILE": v%d.%d.%d\n", major_number, minor_number, build_number); save_build_number(BUILD_NUMBER_FILE, major_number, minor_number, build_number + 1); } @@ -479,8 +480,5 @@ int main(){ META_FINISH(); } -#define FTECH_FILE_MOVING_IMPLEMENTATION -#include "../meta/4ed_file_moving.h" - // BOTTOM From f7f9192b4147a85216a7557c87a44be710ebebb3 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 9 Jul 2017 15:00:13 -0400 Subject: [PATCH 2/5] Revert "fucked everything over" This reverts commit 38414d5cb90b428e1c8843692db41e1c926ce2be. --- meta/4ed_file_moving.h | 14 ++++----- meta/build.cpp | 49 ++++++++++++++++-------------- string/4coder_string_build_num.txt | 2 +- string/string_builder.cpp | 30 +++++++++--------- 4 files changed, 50 insertions(+), 45 deletions(-) diff --git a/meta/4ed_file_moving.h b/meta/4ed_file_moving.h index 7733e1a4..8ed07b3c 100644 --- a/meta/4ed_file_moving.h +++ b/meta/4ed_file_moving.h @@ -76,9 +76,9 @@ internal char **fm_prepare_list_internal(char **l1, ...); internal char **fm_list_one_item(char *item); // File System Navigation -typedef umem String_Temp; -internal String_Temp fm_begin_temp(); -internal void fm_end_temp(String_Temp temp); +typedef umem Temp_Memory; +internal Temp_Memory fm_begin_temp(); +internal void fm_end_temp(Temp_Memory temp); internal i32 fm_get_current_directory(char *buffer, i32 max); @@ -186,13 +186,13 @@ fm__init_memory(){ fm_arena_memory = (char*)malloc(fm_arena_max); } -internal String_Temp +internal Temp_Memory fm_begin_temp(){ return(fm_arena_pos); } internal void -fm_end_temp(String_Temp temp){ +fm_end_temp(Temp_Memory temp){ fm_arena_pos = temp; } @@ -503,7 +503,7 @@ fm__prepare(umem item_size, void *i1, va_list list){ umem size = listsize(i1, item_size); void *result = (void*)fm__push(size); memcpy(result, i1, size); - + void *ln = va_arg(list, void*); for (;ln != 0;){ size = listsize(ln, item_size); @@ -511,7 +511,7 @@ fm__prepare(umem item_size, void *i1, va_list list){ memcpy(new_str, ln, size); ln = va_arg(list, void*); } - + void *terminator = (void*)fm__push(item_size); memset(terminator, 0, item_size); return(result); diff --git a/meta/build.cpp b/meta/build.cpp index 9f91d195..327426e8 100644 --- a/meta/build.cpp +++ b/meta/build.cpp @@ -189,19 +189,20 @@ get_defines_from_flags(u32 flags){ "user32.lib winmm.lib gdi32.lib opengl32.lib " \ "..\\foreign_x86\\freetype.lib" + #define CL_ICON "..\\res\\icon.res" static void build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ Temp_Dir temp = fm_pushdir(out_path); - + Build_Line line; fm_init_build_line(&line); if (arch == Arch_X86){ fm_add_to_line(line, "%s\\windows_scripts\\setup_cl_x86.bat &", code_path); } - + fm_add_to_line(line, "cl"); if (flags & OPTS){ @@ -209,8 +210,8 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c } switch (arch){ - case Arch_X64: fm_add_to_line(line, "-DFTECH_64_BIT"); break; - case Arch_X86: fm_add_to_line(line, "-DFTECH_32_BIT"); break; + case Arch_X64: fm_add_to_line(line, "/DFTECH_64_BIT"); break; + case Arch_X86: fm_add_to_line(line, "/DFTECH_32_BIT"); break; default: InvalidCodePath; } @@ -218,7 +219,7 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c if (inc_folders != 0){ for (u32 i = 0; inc_folders[i] != 0; ++i){ char *str = fm_str(code_path, "/", inc_folders[i]); - fm_add_to_line(line, "-I%s", str); + fm_add_to_line(line, "/I%s", str); } } @@ -235,51 +236,51 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c } if (flags & DEBUG_INFO){ - fm_add_to_line(line, "-Zi"); + fm_add_to_line(line, "/Zi"); } if (flags & OPTIMIZATION){ - fm_add_to_line(line, "-O2"); + fm_add_to_line(line, "/O2"); } if (flags & SHARED_CODE){ - fm_add_to_line(line, "-LD"); + fm_add_to_line(line, "/LD"); } if (defines != 0){ for (u32 i = 0; defines[i] != 0; ++i){ - char *define_flag = fm_str("-D", defines[i]); - fm_add_to_line(line, "%s", define_flag); + char *define_flag = fm_str("/D", defines[i]); + fm_add_to_line(line, define_flag); } } - + for (u32 i = 0; code_files[i]; ++i){ fm_add_to_line(line, "\"%s\\%s\"", code_path, code_files[i]); } - - fm_add_to_line(line, "-Fe%s", out_file); - - fm_add_to_line(line, "-link -INCREMENTAL:NO"); + + fm_add_to_line(line, "/Fe%s", out_file); + + fm_add_to_line(line, "/link /INCREMENTAL:NO"); switch (arch){ - case Arch_X64: fm_add_to_line(line, "-MACHINE:X64"); break; - case Arch_X86: fm_add_to_line(line, "-MACHINE:X86"); break; + case Arch_X64: fm_add_to_line(line, "/MACHINE:X64"); break; + case Arch_X86: fm_add_to_line(line, "/MACHINE:X86"); break; default: InvalidCodePath; } if (flags & DEBUG_INFO){ - fm_add_to_line(line, "-DEBUG"); + fm_add_to_line(line, "/DEBUG"); } if (flags & SHARED_CODE){ Assert(exports != 0); fm_add_to_line(line, "/OPT:REF"); for (u32 i = 0; exports[i] != 0; ++i){ - char *str = fm_str("-EXPORT:", exports[i]); + char *str = fm_str("/EXPORT:", exports[i]); fm_add_to_line(line, "%s", str); } } else{ - fm_add_to_line(line, "-NODEFAULTLIB:library"); + fm_add_to_line(line, "/NODEFAULTLIB:library"); } fm_finish_build_line(&line); @@ -354,6 +355,8 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c } fm_add_to_line(line, GCC_INCLUDES" %s", freetype_include); +#else + fm_add_to_line(line, GCC_INCLUDES); #endif } #endif @@ -384,7 +387,7 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c fm_add_to_line(line, "%s", define_flag); } } - + fm_add_to_line(line, "-I\"%s\"", code_path); for (u32 i = 0; code_files[i] != 0; ++i){ fm_add_to_line(line, "\"%s/%s\"", code_path, code_files[i]); @@ -565,7 +568,7 @@ package(char *cdir){ char *tier = tiers[tier_index]; u32 flags = base_flags | tier_flags[tier_index]; - String_Temp temp = fm_begin_temp(); + Temp_Memory temp = fm_begin_temp(); char *tier_package_root = fm_str(base_package_root, "_", tier); for (u32 arch = 0; arch < Arch_COUNT; ++arch){ char *par_dir = fm_str(tier_package_root, "_", arch_names[arch]); @@ -619,7 +622,7 @@ package(char *cdir){ // NOTE(allen): power { - String_Temp temp = fm_begin_temp(); + Temp_Memory temp = fm_begin_temp(); char *pack_power_par_dir = fm_str("../current_dist_power"); char *pack_power_dir = fm_str(pack_power_par_dir, "/power"); diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt index f92a4013..5e3d1b74 100644 --- a/string/4coder_string_build_num.txt +++ b/string/4coder_string_build_num.txt @@ -1,5 +1,5 @@ 1 0 -88 +87 diff --git a/string/string_builder.cpp b/string/string_builder.cpp index 9af5b47e..6604a190 100644 --- a/string/string_builder.cpp +++ b/string/string_builder.cpp @@ -6,6 +6,16 @@ Created 21.01.2017 (dd.mm.yyyy) // TOP +#include "../4cpp/4cpp_lexer.h" +// TODO(allen): Make sure to only publish the 4coder_string.h if it builds and passes a series of tests. +#define FSTRING_IMPLEMENTATION +#include "../4coder_lib/4coder_string.h" + +#include "../4ed_defines.h" +#include "../meta/4ed_meta_defines.h" +#include "../meta/4ed_file_moving.h" + + #define BUILD_NUMBER_FILE "4coder_string_build_num.txt" #define GENERATED_FILE "4coder_string.h" @@ -14,16 +24,6 @@ Created 21.01.2017 (dd.mm.yyyy) #define BACKUP_FOLDER ".." SLASH ".." SLASH "string_backup" #define PUBLISH_FOLDER ".." SLASH "4coder_helper" -#include "../4cpp/4cpp_lexer.h" -// TODO(allen): Make sure to only publish the 4coder_string.h if it builds and passes a series of tests. -#define FSTRING_IMPLEMENTATION -#include "../4coder_lib/4coder_string.h" - -#include "../4ed_defines.h" -#include "../meta/4ed_meta_defines.h" - -#define FTECH_FILE_MOVING_IMPLEMENTATION -#include "../meta/4ed_file_moving.h" #include #include @@ -158,12 +158,11 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){ internal void file_move(char *path, char *file_name){ - fm_copy_file(fm_str(file_name), fm_str(path, file_name)); + copy_file(0, file_name, path, 0, file_name); } int main(){ META_BEGIN(); - fm_init_system(); i32 size = (512 << 20); void *mem = malloc(size); @@ -468,11 +467,11 @@ int main(){ // NOTE(allen): Publish the new file. (Would like to be able to automatically test the result before publishing). { - fm_make_folder_if_missing(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN); + make_folder_if_missing(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, 0); file_move(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, INTERNAL_STRING); file_move(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, GENERATED_FILE); //file_move(PUBLISH_FOLDER, GENERATED_FILE); - fm_delete_file(GENERATED_FILE); + delete_file(GENERATED_FILE); printf("published "GENERATED_FILE": v%d.%d.%d\n", major_number, minor_number, build_number); save_build_number(BUILD_NUMBER_FILE, major_number, minor_number, build_number + 1); } @@ -480,5 +479,8 @@ int main(){ META_FINISH(); } +#define FTECH_FILE_MOVING_IMPLEMENTATION +#include "../meta/4ed_file_moving.h" + // BOTTOM From dabda53ddcc60e2db905e0c17fd75c4a064b6153 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 9 Jul 2017 15:22:57 -0400 Subject: [PATCH 3/5] name fixing, project fixing, temp memory collision fixing --- build.bat | 2 +- build.sh | 2 +- string/build.bat => build_string.bat | 2 +- string/build.sh => build_string.sh | 2 +- meta/{build.cpp => 4ed_build.cpp} | 84 +- meta/4ed_file_moving.h | 14 +- ...erator.cpp => 4ed_fsm_table_generator.cpp} | 0 meta/{meta_parser.cpp => 4ed_meta_parser.cpp} | 0 meta/4ed_metagen.cpp | 4 +- meta/{out_context.cpp => 4ed_out_context.cpp} | 0 project.4coder | 23 +- ...document.cpp => 4ed_abstract_document.cpp} | 0 site/{sitegen.cpp => 4ed_sitegen.cpp} | 6 +- string/4coder_string.h | 2273 +++++++++++++++++ ...ard_preamble.h => 4ed_standard_preamble.h} | 0 ...ing_builder.cpp => 4ed_string_builder.cpp} | 11 +- 16 files changed, 2350 insertions(+), 73 deletions(-) rename string/build.bat => build_string.bat (83%) rename string/build.sh => build_string.sh (69%) mode change 100755 => 100644 rename meta/{build.cpp => 4ed_build.cpp} (92%) rename meta/{fsm_table_generator.cpp => 4ed_fsm_table_generator.cpp} (100%) rename meta/{meta_parser.cpp => 4ed_meta_parser.cpp} (100%) rename meta/{out_context.cpp => 4ed_out_context.cpp} (100%) rename site/{abstract_document.cpp => 4ed_abstract_document.cpp} (100%) rename site/{sitegen.cpp => 4ed_sitegen.cpp} (99%) create mode 100644 string/4coder_string.h rename string/{4tech_standard_preamble.h => 4ed_standard_preamble.h} (100%) rename string/{string_builder.cpp => 4ed_string_builder.cpp} (98%) diff --git a/build.bat b/build.bat index 9c47c1af..773c5089 100644 --- a/build.bat +++ b/build.bat @@ -9,7 +9,7 @@ SET BUILD_MODE=%1 if "%BUILD_MODE%" == "" (SET BUILD_MODE="/DDEV_BUILD") pushd ..\build -cl %OPTS% kernel32.lib ..\code\meta\build.cpp /Zi /Febuild %BUILD_MODE% +cl %OPTS% kernel32.lib ..\code\meta\4ed_build.cpp /Zi /Febuild %BUILD_MODE% if %ERRORLEVEL% neq 0 (set FirstError=1) if %ERRORLEVEL% neq 0 (goto END) popd diff --git a/build.sh b/build.sh index e4ee756b..10c61be5 100755 --- a/build.sh +++ b/build.sh @@ -39,7 +39,7 @@ fi FLAGS="-D_GNU_SOURCE -fPIC -fpermissive $BUILD_MODE" # Execute -g++ $WARNINGS $FLAGS $CODE_HOME/meta/build.cpp -g -o ../build/build +g++ $WARNINGS $FLAGS $CODE_HOME/meta/4ed_build.cpp -g -o ../build/build ../build/build diff --git a/string/build.bat b/build_string.bat similarity index 83% rename from string/build.bat rename to build_string.bat index 4da879ec..d4299d9d 100644 --- a/string/build.bat +++ b/build_string.bat @@ -6,7 +6,7 @@ SET OPTS=%OPTS% -wd4611 -GR- -EHa- -nologo -FC SET FirstError=0 pushd ..\build -cl %OPTS% ..\code\string\string_builder.cpp /Zi /Festring_builder +cl %OPTS% ..\code\string\4ed_string_builder.cpp /Zi /Festring_builder if %ERRORLEVEL% neq 0 (set FirstError=1) if %ERRORLEVEL% neq 0 (goto END) popd diff --git a/string/build.sh b/build_string.sh old mode 100755 new mode 100644 similarity index 69% rename from string/build.sh rename to build_string.sh index b56cb914..2832e70c --- a/string/build.sh +++ b/build_string.sh @@ -3,7 +3,7 @@ WARNINGS="-Wno-write-strings -Wno-comment -Wno-logical-op-parentheses -Wno-null-dereference -Wno-switch" FLAGS="-D_GNU_SOURCE -fPIC -fpermissive" -g++ $WARNINGS $FLAGS ../code/string/string_builder.cpp -g -o ../build/string_builder +g++ $WARNINGS $FLAGS ../code/string/4ed_string_builder.cpp -g -o ../build/string_builder pushd string ../../build/string_builder diff --git a/meta/build.cpp b/meta/4ed_build.cpp similarity index 92% rename from meta/build.cpp rename to meta/4ed_build.cpp index 327426e8..846c1c1c 100644 --- a/meta/build.cpp +++ b/meta/4ed_build.cpp @@ -1,6 +1,11 @@ /* -4coder development build rule. -*/ + * Mr. 4th Dimention - Allen Webster + * + * ??.??.???? + * + * 4coder development build rule. + * + */ // TOP @@ -189,20 +194,19 @@ get_defines_from_flags(u32 flags){ "user32.lib winmm.lib gdi32.lib opengl32.lib " \ "..\\foreign_x86\\freetype.lib" - #define CL_ICON "..\\res\\icon.res" -static void +internal void build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ Temp_Dir temp = fm_pushdir(out_path); - + Build_Line line; fm_init_build_line(&line); if (arch == Arch_X86){ fm_add_to_line(line, "%s\\windows_scripts\\setup_cl_x86.bat &", code_path); } - + fm_add_to_line(line, "cl"); if (flags & OPTS){ @@ -210,8 +214,8 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c } switch (arch){ - case Arch_X64: fm_add_to_line(line, "/DFTECH_64_BIT"); break; - case Arch_X86: fm_add_to_line(line, "/DFTECH_32_BIT"); break; + case Arch_X64: fm_add_to_line(line, "-DFTECH_64_BIT"); break; + case Arch_X86: fm_add_to_line(line, "-DFTECH_32_BIT"); break; default: InvalidCodePath; } @@ -219,7 +223,7 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c if (inc_folders != 0){ for (u32 i = 0; inc_folders[i] != 0; ++i){ char *str = fm_str(code_path, "/", inc_folders[i]); - fm_add_to_line(line, "/I%s", str); + fm_add_to_line(line, "-I%s", str); } } @@ -236,51 +240,51 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c } if (flags & DEBUG_INFO){ - fm_add_to_line(line, "/Zi"); + fm_add_to_line(line, "-Zi"); } if (flags & OPTIMIZATION){ - fm_add_to_line(line, "/O2"); + fm_add_to_line(line, "-O2"); } if (flags & SHARED_CODE){ - fm_add_to_line(line, "/LD"); + fm_add_to_line(line, "-LD"); } if (defines != 0){ for (u32 i = 0; defines[i] != 0; ++i){ - char *define_flag = fm_str("/D", defines[i]); - fm_add_to_line(line, define_flag); + char *define_flag = fm_str("-D", defines[i]); + fm_add_to_line(line, "%s", define_flag); } } - + for (u32 i = 0; code_files[i]; ++i){ fm_add_to_line(line, "\"%s\\%s\"", code_path, code_files[i]); } - - fm_add_to_line(line, "/Fe%s", out_file); - - fm_add_to_line(line, "/link /INCREMENTAL:NO"); + + fm_add_to_line(line, "-Fe%s", out_file); + + fm_add_to_line(line, "-link -INCREMENTAL:NO"); switch (arch){ - case Arch_X64: fm_add_to_line(line, "/MACHINE:X64"); break; - case Arch_X86: fm_add_to_line(line, "/MACHINE:X86"); break; + case Arch_X64: fm_add_to_line(line, "-MACHINE:X64"); break; + case Arch_X86: fm_add_to_line(line, "-MACHINE:X86"); break; default: InvalidCodePath; } if (flags & DEBUG_INFO){ - fm_add_to_line(line, "/DEBUG"); + fm_add_to_line(line, "-DEBUG"); } if (flags & SHARED_CODE){ Assert(exports != 0); - fm_add_to_line(line, "/OPT:REF"); + fm_add_to_line(line, "-OPT:REF"); for (u32 i = 0; exports[i] != 0; ++i){ - char *str = fm_str("/EXPORT:", exports[i]); + char *str = fm_str("-EXPORT:", exports[i]); fm_add_to_line(line, "%s", str); } } else{ - fm_add_to_line(line, "/NODEFAULTLIB:library"); + fm_add_to_line(line, "-NODEFAULTLIB:library"); } fm_finish_build_line(&line); @@ -320,7 +324,7 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c # error gcc options not set for this platform #endif -static void +internal void build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ Build_Line line; fm_init_build_line(&line); @@ -387,7 +391,7 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c fm_add_to_line(line, "%s", define_flag); } } - + fm_add_to_line(line, "-I\"%s\"", code_path); for (u32 i = 0; code_files[i] != 0; ++i){ fm_add_to_line(line, "\"%s/%s\"", code_path, code_files[i]); @@ -408,7 +412,7 @@ build(u32 flags, u32 arch, char *code_path, char **code_files, char *out_path, c # error build function not defined for this compiler #endif -static void +internal void build(u32 flags, u32 arch, char *code_path, char *code_file, char *out_path, char *out_file, char **defines, char **exports, char **inc_folders){ char *code_files[2]; code_files[0] = code_file; @@ -416,10 +420,10 @@ build(u32 flags, u32 arch, char *code_path, char *code_file, char *out_path, cha build(flags, arch, code_path, code_files, out_path, out_file, defines, exports, inc_folders); } -static void +internal void site_build(char *cdir, u32 flags){ { - char *file = fm_str("site/sitegen.cpp"); + char *file = fm_str("site/4ed_sitegen.cpp"); char *dir = fm_str(BUILD_DIR); BEGIN_TIME_SECTION(); build(OPTS | flags, Arch_X64, cdir, file, dir, "sitegen", get_defines_from_flags(flags), 0, includes); @@ -439,7 +443,7 @@ site_build(char *cdir, u32 flags){ } } -static void +internal void build_and_run(char *cdir, char *filename, char *name, u32 flags){ char *dir = fm_str(BUILD_DIR); @@ -458,17 +462,17 @@ build_and_run(char *cdir, char *filename, char *name, u32 flags){ } } -static void +internal void fsm_generator(char *cdir){ - build_and_run(cdir, "meta/fsm_table_generator.cpp", "fsmgen", OPTS | DEBUG_INFO); + build_and_run(cdir, "meta/4ed_fsm_table_generator.cpp", "fsmgen", OPTS | DEBUG_INFO); } -static void +internal void metagen(char *cdir){ build_and_run(cdir, "meta/4ed_metagen.cpp", "metagen", OPTS | DEBUG_INFO); } -static void +internal void do_buildsuper(char *cdir, char *file, u32 arch){ BEGIN_TIME_SECTION(); Temp_Dir temp = fm_pushdir(fm_str(BUILD_DIR)); @@ -485,7 +489,7 @@ do_buildsuper(char *cdir, char *file, u32 arch){ END_TIME_SECTION("build custom"); } -static void +internal void build_main(char *cdir, b32 update_local_theme, u32 flags, u32 arch){ char *dir = fm_str(BUILD_DIR); @@ -515,7 +519,7 @@ build_main(char *cdir, b32 update_local_theme, u32 flags, u32 arch){ } } -static void +internal void standard_build(char *cdir, u32 flags, u32 arch){ fsm_generator(cdir); metagen(cdir); @@ -541,7 +545,7 @@ get_4coder_dist_name(u32 platform, char *tier, u32 arch){ return(name); } -static void +internal void package(char *cdir){ // NOTE(allen): meta fsm_generator(cdir); @@ -568,7 +572,7 @@ package(char *cdir){ char *tier = tiers[tier_index]; u32 flags = base_flags | tier_flags[tier_index]; - Temp_Memory temp = fm_begin_temp(); + String_Temp temp = fm_begin_temp(); char *tier_package_root = fm_str(base_package_root, "_", tier); for (u32 arch = 0; arch < Arch_COUNT; ++arch){ char *par_dir = fm_str(tier_package_root, "_", arch_names[arch]); @@ -622,7 +626,7 @@ package(char *cdir){ // NOTE(allen): power { - Temp_Memory temp = fm_begin_temp(); + String_Temp temp = fm_begin_temp(); char *pack_power_par_dir = fm_str("../current_dist_power"); char *pack_power_dir = fm_str(pack_power_par_dir, "/power"); diff --git a/meta/4ed_file_moving.h b/meta/4ed_file_moving.h index 8ed07b3c..7733e1a4 100644 --- a/meta/4ed_file_moving.h +++ b/meta/4ed_file_moving.h @@ -76,9 +76,9 @@ internal char **fm_prepare_list_internal(char **l1, ...); internal char **fm_list_one_item(char *item); // File System Navigation -typedef umem Temp_Memory; -internal Temp_Memory fm_begin_temp(); -internal void fm_end_temp(Temp_Memory temp); +typedef umem String_Temp; +internal String_Temp fm_begin_temp(); +internal void fm_end_temp(String_Temp temp); internal i32 fm_get_current_directory(char *buffer, i32 max); @@ -186,13 +186,13 @@ fm__init_memory(){ fm_arena_memory = (char*)malloc(fm_arena_max); } -internal Temp_Memory +internal String_Temp fm_begin_temp(){ return(fm_arena_pos); } internal void -fm_end_temp(Temp_Memory temp){ +fm_end_temp(String_Temp temp){ fm_arena_pos = temp; } @@ -503,7 +503,7 @@ fm__prepare(umem item_size, void *i1, va_list list){ umem size = listsize(i1, item_size); void *result = (void*)fm__push(size); memcpy(result, i1, size); - + void *ln = va_arg(list, void*); for (;ln != 0;){ size = listsize(ln, item_size); @@ -511,7 +511,7 @@ fm__prepare(umem item_size, void *i1, va_list list){ memcpy(new_str, ln, size); ln = va_arg(list, void*); } - + void *terminator = (void*)fm__push(item_size); memset(terminator, 0, item_size); return(result); diff --git a/meta/fsm_table_generator.cpp b/meta/4ed_fsm_table_generator.cpp similarity index 100% rename from meta/fsm_table_generator.cpp rename to meta/4ed_fsm_table_generator.cpp diff --git a/meta/meta_parser.cpp b/meta/4ed_meta_parser.cpp similarity index 100% rename from meta/meta_parser.cpp rename to meta/4ed_meta_parser.cpp diff --git a/meta/4ed_metagen.cpp b/meta/4ed_metagen.cpp index b7ddc884..6dcf33fa 100644 --- a/meta/4ed_metagen.cpp +++ b/meta/4ed_metagen.cpp @@ -28,8 +28,8 @@ #include #include -#include "meta_parser.cpp" -#include "out_context.cpp" +#include "4ed_meta_parser.cpp" +#include "4ed_out_context.cpp" ////////////////////////////////////////////////////////////////////////////////////////////////// char *keys_that_need_codes[] = { diff --git a/meta/out_context.cpp b/meta/4ed_out_context.cpp similarity index 100% rename from meta/out_context.cpp rename to meta/4ed_out_context.cpp diff --git a/project.4coder b/project.4coder index 92444508..2c59a44b 100644 --- a/project.4coder +++ b/project.4coder @@ -1,15 +1,16 @@ extensions=".c.cpp.h.m.bat.sh.4coder"; open_recursively=true; -fkey_command_win[1] = {"echo build: x64 & build.bat", "*compilation*", true , true }; -fkey_command_win[2] = {"build_site.bat", "*site*", false , true }; -fkey_command_win[3] = {"string\\build.bat", "*compilation*", true , true }; -fkey_command_win[4] = {"echo build: x86 & build.bat /DDEV_BUILD_X86", "*compilation*", true , true }; -fkey_command_win[5] = {"..\\misc\\run.bat", "*run*", false, false }; -fkey_command_win[6] = {"run_profile.bat", "*profile*", false, true }; -fkey_command_win[12] = {"package.bat", "*package*", false, true }; +fkey_command_win[1] = {"echo build: x64 & build.bat", "*compilation*" , true , true }; +fkey_command_win[2] = {"build_site.bat" , "*site*" , false, true }; +fkey_command_win[3] = {"build_string.bat" , "*compilation*" , true , true }; +fkey_command_win[4] = {"echo build: x86 & build.bat /DDEV_BUILD_X86" , "*compilation*", true, true }; +fkey_command_win[5] = {"..\\misc\\run.bat" , "*run*" , false, false }; +fkey_command_win[6] = {"run_profile.bat" , "*profile*" , false, true }; +fkey_command_win[12] = {"package.bat" , "*package*" , false, true }; -fkey_command_linux[1] = {"echo build: x64 & ./build.sh", "*compilation*", true , true }; -fkey_command_linux[2] = {"build_site.sh", "*site*", false , true }; -fkey_command_linux[4] = {"echo build: x86 & ./build.sh -DDEV_BUILD_X86", "*compilation*", true, true }; -fkey_command_linux[12] = {"./package.sh", "*package*", false, true }; +fkey_command_linux[1] = {"echo build: x64 & ./build.sh", "*compilation*" , true , true }; +fkey_command_linux[2] = {"build_site.sh" , "*site*" , false, true }; +fkey_command_linux[3] = {"build_string.sh" , "*compilation*" , true , true }; +fkey_command_linux[4] = {"echo build: x86 & ./build.sh -DDEV_BUILD_X86" , "*compilation*", true, true }; +fkey_command_linux[12] = {"./package.sh" , "*package*" , false, true }; diff --git a/site/abstract_document.cpp b/site/4ed_abstract_document.cpp similarity index 100% rename from site/abstract_document.cpp rename to site/4ed_abstract_document.cpp diff --git a/site/sitegen.cpp b/site/4ed_sitegen.cpp similarity index 99% rename from site/sitegen.cpp rename to site/4ed_sitegen.cpp index 8520aa4f..806cb297 100644 --- a/site/sitegen.cpp +++ b/site/4ed_sitegen.cpp @@ -29,9 +29,9 @@ #include "../4coder_lib/4coder_mem.h" #include "../4cpp/4cpp_lexer.h" -#include "../meta/meta_parser.cpp" -#include "../meta/out_context.cpp" -#include "abstract_document.cpp" +#include "../meta/4ed_meta_parser.cpp" +#include "../meta/4ed_out_context.cpp" +#include "4ed_abstract_document.cpp" /////////////////////////////////////////////////////////////////////////// diff --git a/string/4coder_string.h b/string/4coder_string.h new file mode 100644 index 00000000..bb23cae5 --- /dev/null +++ b/string/4coder_string.h @@ -0,0 +1,2273 @@ +/* +4coder_string.h - Version 1.0.87 +no warranty implied; use at your own risk + +This software is in the public domain. Where that dedication is not +recognized, you are granted a perpetual, irrevocable license to copy, +distribute, and modify this file as you see fit. + +To include implementation: #define FSTRING_IMPLEMENTATION +To use in C mode: #define FSTRING_C +*/ + +// TOP + + + +#if !defined(FSTRING_LINK) +# define FSTRING_LINK static +#endif + +#if !defined(FSTRING_INLINE) +# if defined(FSTRING_C) +# define FSTRING_INLINE static +# else +# define FSTRING_INLINE inline +# endif +#endif + +#if !defined(FSTRING_GUARD) +#define literal(s) (s), (sizeof(s)-1) + +typedef struct String{ + char *str; + i32_4tech size; + i32_4tech memory_size; +} String; + +static String null_string = {0}; +#endif + +#if !defined(FCODER_STRING_H) +#define FCODER_STRING_H + +FSTRING_INLINE b32_4tech char_is_slash(char c); +FSTRING_INLINE b32_4tech char_is_upper(char c); +FSTRING_INLINE b32_4tech char_is_upper_utf8(char c); +FSTRING_INLINE b32_4tech char_is_lower(char c); +FSTRING_INLINE b32_4tech char_is_lower_utf8(u8_4tech c); +FSTRING_INLINE char char_to_upper(char c); +FSTRING_INLINE char char_to_lower(char c); +FSTRING_INLINE b32_4tech char_is_whitespace(char c); +FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c); +FSTRING_INLINE b32_4tech char_is_alpha_numeric_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c); +FSTRING_INLINE b32_4tech char_is_alpha_numeric_true_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_alpha(char c); +FSTRING_INLINE b32_4tech char_is_alpha_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_alpha_true(char c); +FSTRING_INLINE b32_4tech char_is_alpha_true_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_hex(char c); +FSTRING_INLINE b32_4tech char_is_hex_utf8(u8_4tech c); +FSTRING_INLINE b32_4tech char_is_numeric(char c); +FSTRING_INLINE b32_4tech char_is_numeric_utf8(u8_4tech c); +FSTRING_INLINE String make_string_cap(void *str, i32_4tech size, i32_4tech mem_size); +FSTRING_INLINE String make_string(void *str, i32_4tech size); +#ifndef make_lit_string +# define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) +#endif +#ifndef make_fixed_width_string +# define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) +#endif +#ifndef expand_str +# define expand_str(s) ((s).str), ((s).size) +#endif +FSTRING_LINK i32_4tech str_size(char *str); +FSTRING_INLINE String make_string_slowly(void *str); +FSTRING_INLINE String substr_tail(String str, i32_4tech start); +FSTRING_INLINE String substr(String str, i32_4tech start, i32_4tech size); +FSTRING_LINK String skip_whitespace(String str); +FSTRING_LINK String skip_whitespace_measure(String str, i32_4tech *skip_length); +FSTRING_LINK String chop_whitespace(String str); +FSTRING_LINK String skip_chop_whitespace(String str); +FSTRING_LINK String skip_chop_whitespace_measure(String str, i32_4tech *skip_length); +FSTRING_INLINE String tailstr(String str); +FSTRING_LINK b32_4tech match_cc(char *a, char *b); +FSTRING_LINK b32_4tech match_sc(String a, char *b); +FSTRING_INLINE b32_4tech match_cs(char *a, String b); +FSTRING_LINK b32_4tech match_ss(String a, String b); +FSTRING_LINK b32_4tech match_part_ccl(char *a, char *b, i32_4tech *len); +FSTRING_LINK b32_4tech match_part_scl(String a, char *b, i32_4tech *len); +FSTRING_INLINE b32_4tech match_part_cc(char *a, char *b); +FSTRING_INLINE b32_4tech match_part_sc(String a, char *b); +FSTRING_LINK b32_4tech match_part_cs(char *a, String b); +FSTRING_LINK b32_4tech match_part_ss(String a, String b); +FSTRING_LINK b32_4tech match_insensitive_cc(char *a, char *b); +FSTRING_LINK b32_4tech match_insensitive_sc(String a, char *b); +FSTRING_INLINE b32_4tech match_insensitive_cs(char *a, String b); +FSTRING_LINK b32_4tech match_insensitive_ss(String a, String b); +FSTRING_LINK b32_4tech match_part_insensitive_ccl(char *a, char *b, i32_4tech *len); +FSTRING_LINK b32_4tech match_part_insensitive_scl(String a, char *b, i32_4tech *len); +FSTRING_INLINE b32_4tech match_part_insensitive_cc(char *a, char *b); +FSTRING_INLINE b32_4tech match_part_insensitive_sc(String a, char *b); +FSTRING_LINK b32_4tech match_part_insensitive_cs(char *a, String b); +FSTRING_LINK b32_4tech match_part_insensitive_ss(String a, String b); +FSTRING_LINK i32_4tech compare_cc(char *a, char *b); +FSTRING_LINK i32_4tech compare_sc(String a, char *b); +FSTRING_INLINE i32_4tech compare_cs(char *a, String b); +FSTRING_LINK i32_4tech compare_ss(String a, String b); +FSTRING_LINK i32_4tech find_c_char(char *str, i32_4tech start, char character); +FSTRING_LINK i32_4tech find_s_char(String str, i32_4tech start, char character); +FSTRING_LINK i32_4tech rfind_s_char(String str, i32_4tech start, char character); +FSTRING_LINK i32_4tech find_c_chars(char *str, i32_4tech start, char *characters); +FSTRING_LINK i32_4tech find_s_chars(String str, i32_4tech start, char *characters); +FSTRING_LINK i32_4tech find_substr_c(char *str, i32_4tech start, String seek); +FSTRING_LINK i32_4tech find_substr_s(String str, i32_4tech start, String seek); +FSTRING_LINK i32_4tech rfind_substr_s(String str, i32_4tech start, String seek); +FSTRING_LINK i32_4tech find_substr_insensitive_c(char *str, i32_4tech start, String seek); +FSTRING_LINK i32_4tech find_substr_insensitive_s(String str, i32_4tech start, String seek); +FSTRING_INLINE b32_4tech has_substr_c(char *s, String seek); +FSTRING_INLINE b32_4tech has_substr_s(String s, String seek); +FSTRING_INLINE b32_4tech has_substr_insensitive_c(char *s, String seek); +FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String seek); +FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src); +FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src); +FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src); +FSTRING_LINK b32_4tech copy_checked_cs(char *dest, i32_4tech dest_cap, String src); +FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src); +FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src); +FSTRING_LINK b32_4tech copy_partial_cs(char *dest, i32_4tech dest_cap, String src); +FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src); +FSTRING_INLINE void copy_ss(String *dest, String src); +FSTRING_INLINE void copy_sc(String *dest, char *src); +FSTRING_LINK b32_4tech append_checked_ss(String *dest, String src); +FSTRING_LINK b32_4tech append_partial_sc(String *dest, char *src); +FSTRING_LINK b32_4tech append_partial_ss(String *dest, String src); +FSTRING_LINK b32_4tech append_s_char(String *dest, char c); +FSTRING_INLINE b32_4tech append_ss(String *dest, String src); +FSTRING_INLINE b32_4tech append_sc(String *dest, char *src); +FSTRING_LINK b32_4tech terminate_with_null(String *str); +FSTRING_LINK b32_4tech append_padding(String *dest, char c, i32_4tech target_size); +FSTRING_LINK void replace_char(String *str, char replace, char with); +FSTRING_LINK void to_lower_cc(char *src, char *dst); +FSTRING_LINK void to_lower_ss(String *dst, String src); +FSTRING_LINK void to_lower_s(String *str); +FSTRING_LINK void to_upper_cc(char *src, char *dst); +FSTRING_LINK void to_upper_ss(String *dst, String src); +FSTRING_LINK void to_upper_s(String *str); +FSTRING_LINK void to_camel_cc(char *src, char *dst); +FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x); +FSTRING_LINK b32_4tech int_to_str(String *dest, i32_4tech x); +FSTRING_LINK b32_4tech append_int_to_str(String *dest, i32_4tech x); +FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x); +FSTRING_LINK b32_4tech u64_to_str(String *dest, uint64_t x); +FSTRING_LINK b32_4tech append_u64_to_str(String *dest, uint64_t x); +FSTRING_LINK i32_4tech float_to_str_size(float x); +FSTRING_LINK b32_4tech append_float_to_str(String *dest, float x); +FSTRING_LINK b32_4tech float_to_str(String *dest, float x); +FSTRING_LINK i32_4tech str_is_int_c(char *str); +FSTRING_LINK b32_4tech str_is_int_s(String str); +FSTRING_LINK i32_4tech str_to_int_c(char *str); +FSTRING_LINK i32_4tech str_to_int_s(String str); +FSTRING_LINK i32_4tech hexchar_to_int(char c); +FSTRING_LINK char int_to_hexchar(i32_4tech x); +FSTRING_LINK u32_4tech hexstr_to_int(String str); +FSTRING_LINK b32_4tech color_to_hexstr(String *s, u32_4tech color); +FSTRING_LINK b32_4tech hexstr_to_color(String s, u32_4tech *out); +FSTRING_LINK i32_4tech reverse_seek_slash_pos(String str, i32_4tech pos); +FSTRING_INLINE i32_4tech reverse_seek_slash(String str); +FSTRING_INLINE String front_of_directory(String dir); +FSTRING_INLINE String path_of_directory(String dir); +FSTRING_LINK b32_4tech set_last_folder_sc(String *dir, char *folder_name, char slash); +FSTRING_LINK b32_4tech set_last_folder_ss(String *dir, String folder_name, char slash); +FSTRING_LINK String file_extension(String str); +FSTRING_LINK b32_4tech remove_extension(String *str); +FSTRING_LINK b32_4tech remove_last_folder(String *str); +FSTRING_LINK b32_4tech string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index); +FSTRING_LINK b32_4tech string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index); +FSTRING_LINK String get_first_double_line(String source); +FSTRING_LINK String get_next_double_line(String source, String line); +FSTRING_LINK String get_next_word(String source, String prev_word); +FSTRING_LINK String get_first_word(String source); + +#endif + +#if !defined(FSTRING_C) && !defined(FSTRING_GUARD) + +FSTRING_INLINE String make_string(void *str, i32_4tech size, i32_4tech mem_size){return(make_string_cap(str,size,mem_size));} +FSTRING_INLINE String substr(String str, i32_4tech start){return(substr_tail(str,start));} +FSTRING_LINK String skip_whitespace(String str, i32_4tech *skip_length){return(skip_whitespace_measure(str,skip_length));} +FSTRING_LINK String skip_chop_whitespace(String str, i32_4tech *skip_length){return(skip_chop_whitespace_measure(str,skip_length));} +FSTRING_LINK b32_4tech match(char *a, char *b){return(match_cc(a,b));} +FSTRING_LINK b32_4tech match(String a, char *b){return(match_sc(a,b));} +FSTRING_INLINE b32_4tech match(char *a, String b){return(match_cs(a,b));} +FSTRING_LINK b32_4tech match(String a, String b){return(match_ss(a,b));} +FSTRING_LINK b32_4tech match_part(char *a, char *b, i32_4tech *len){return(match_part_ccl(a,b,len));} +FSTRING_LINK b32_4tech match_part(String a, char *b, i32_4tech *len){return(match_part_scl(a,b,len));} +FSTRING_INLINE b32_4tech match_part(char *a, char *b){return(match_part_cc(a,b));} +FSTRING_INLINE b32_4tech match_part(String a, char *b){return(match_part_sc(a,b));} +FSTRING_LINK b32_4tech match_part(char *a, String b){return(match_part_cs(a,b));} +FSTRING_LINK b32_4tech match_part(String a, String b){return(match_part_ss(a,b));} +FSTRING_LINK b32_4tech match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} +FSTRING_LINK b32_4tech match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} +FSTRING_INLINE b32_4tech match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} +FSTRING_LINK b32_4tech match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} +FSTRING_LINK b32_4tech match_part_insensitive(char *a, char *b, i32_4tech *len){return(match_part_insensitive_ccl(a,b,len));} +FSTRING_LINK b32_4tech match_part_insensitive(String a, char *b, i32_4tech *len){return(match_part_insensitive_scl(a,b,len));} +FSTRING_INLINE b32_4tech match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} +FSTRING_INLINE b32_4tech match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} +FSTRING_LINK b32_4tech match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} +FSTRING_LINK b32_4tech match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} +FSTRING_LINK i32_4tech compare(char *a, char *b){return(compare_cc(a,b));} +FSTRING_LINK i32_4tech compare(String a, char *b){return(compare_sc(a,b));} +FSTRING_INLINE i32_4tech compare(char *a, String b){return(compare_cs(a,b));} +FSTRING_LINK i32_4tech compare(String a, String b){return(compare_ss(a,b));} +FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char character){return(find_c_char(str,start,character));} +FSTRING_LINK i32_4tech find(String str, i32_4tech start, char character){return(find_s_char(str,start,character));} +FSTRING_LINK i32_4tech rfind(String str, i32_4tech start, char character){return(rfind_s_char(str,start,character));} +FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char *characters){return(find_c_chars(str,start,characters));} +FSTRING_LINK i32_4tech find(String str, i32_4tech start, char *characters){return(find_s_chars(str,start,characters));} +FSTRING_LINK i32_4tech find_substr(char *str, i32_4tech start, String seek){return(find_substr_c(str,start,seek));} +FSTRING_LINK i32_4tech find_substr(String str, i32_4tech start, String seek){return(find_substr_s(str,start,seek));} +FSTRING_LINK i32_4tech rfind_substr(String str, i32_4tech start, String seek){return(rfind_substr_s(str,start,seek));} +FSTRING_LINK i32_4tech find_substr_insensitive(char *str, i32_4tech start, String seek){return(find_substr_insensitive_c(str,start,seek));} +FSTRING_LINK i32_4tech find_substr_insensitive(String str, i32_4tech start, String seek){return(find_substr_insensitive_s(str,start,seek));} +FSTRING_INLINE b32_4tech has_substr(char *s, String seek){return(has_substr_c(s,seek));} +FSTRING_INLINE b32_4tech has_substr(String s, String seek){return(has_substr_s(s,seek));} +FSTRING_INLINE b32_4tech has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} +FSTRING_INLINE b32_4tech has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} +FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} +FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} +FSTRING_LINK b32_4tech copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} +FSTRING_LINK b32_4tech copy_checked(char *dest, i32_4tech dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));} +FSTRING_LINK b32_4tech copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} +FSTRING_LINK b32_4tech copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} +FSTRING_LINK b32_4tech copy_partial(char *dest, i32_4tech dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));} +FSTRING_INLINE i32_4tech copy(char *dest, char *src){return(copy_cc(dest,src));} +FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));} +FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));} +FSTRING_LINK b32_4tech append_checked(String *dest, String src){return(append_checked_ss(dest,src));} +FSTRING_LINK b32_4tech append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} +FSTRING_LINK b32_4tech append_partial(String *dest, String src){return(append_partial_ss(dest,src));} +FSTRING_LINK b32_4tech append(String *dest, char c){return(append_s_char(dest,c));} +FSTRING_INLINE b32_4tech append(String *dest, String src){return(append_ss(dest,src));} +FSTRING_INLINE b32_4tech append(String *dest, char *src){return(append_sc(dest,src));} +FSTRING_LINK void to_lower(char *src, char *dst){return(to_lower_cc(src,dst));} +FSTRING_LINK void to_lower(String *dst, String src){return(to_lower_ss(dst,src));} +FSTRING_LINK void to_lower(String *str){return(to_lower_s(str));} +FSTRING_LINK void to_upper(char *src, char *dst){return(to_upper_cc(src,dst));} +FSTRING_LINK void to_upper(String *dst, String src){return(to_upper_ss(dst,src));} +FSTRING_LINK void to_upper(String *str){return(to_upper_s(str));} +FSTRING_LINK void to_camel(char *src, char *dst){return(to_camel_cc(src,dst));} +FSTRING_LINK i32_4tech str_is_int(char *str){return(str_is_int_c(str));} +FSTRING_LINK b32_4tech str_is_int(String str){return(str_is_int_s(str));} +FSTRING_LINK i32_4tech str_to_int(char *str){return(str_to_int_c(str));} +FSTRING_LINK i32_4tech str_to_int(String str){return(str_to_int_s(str));} +FSTRING_LINK i32_4tech reverse_seek_slash(String str, i32_4tech pos){return(reverse_seek_slash_pos(str,pos));} +FSTRING_LINK b32_4tech set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} +FSTRING_LINK b32_4tech set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} +FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} + +#endif + + +// +// Character Helpers +// + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_slash(char c) +{ + return (c == '\\' || c == '/'); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_upper(char c) +{ + return (c >= 'A' && c <= 'Z'); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_upper_utf8(char c) +{ + return ((c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_lower(char c) +{ + return (c >= 'a' && c <= 'z'); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_lower_utf8(u8_4tech c) +{ + return ((c >= 'a' && c <= 'z') || (unsigned char)c >= 128); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE char +char_to_upper(char c) +{ + return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE char +char_to_lower(char c) +{ + return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_whitespace(char c) +{ + return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_alpha_numeric(char c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_alpha_numeric_utf8(u8_4tech c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (unsigned char)c >= 128); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_alpha_numeric_true(char c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_alpha_numeric_true_utf8(u8_4tech c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (unsigned char)c >= 128); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_alpha(char c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_alpha_utf8(u8_4tech c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (unsigned char)c >= 128); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_alpha_true(char c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_alpha_true_utf8(u8_4tech c) +{ + return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_hex(char c) +{ + return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_hex_utf8(u8_4tech c) +{ + return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (unsigned char)c >= 128); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_numeric(char c) +{ + return (c >= '0' && c <= '9'); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +char_is_numeric_utf8(u8_4tech c) +{ + return ((c >= '0' && c <= '9') || (unsigned char)c >= 128); +} +#endif + + +// +// String Making Functions +// + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE String +make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ + String result; + result.str = (char*)str; + result.size = size; + result.memory_size = mem_size; + return(result); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE String +make_string(void *str, i32_4tech size){ + String result; + result.str = (char*)str; + result.size = size; + result.memory_size = size; + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +str_size(char *str) +{ + i32_4tech i = 0; + while (str[i]) ++i; + return(i); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE String +make_string_slowly(void *str) +{ + String result; + result.str = (char*)str; + result.size = str_size((char*)str); + result.memory_size = result.size+1; + return(result); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE String +substr_tail(String str, i32_4tech start) +{ + String result; + result.str = str.str + start; + result.size = str.size - start; + result.memory_size = 0; + return(result); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE String +substr(String str, i32_4tech start, i32_4tech size) +{ + String result; + result.str = str.str + start; + result.size = size; + if (start + size > str.size){ + result.size = str.size - start; + } + result.memory_size = 0; + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +skip_whitespace(String str) +{ + String result = {0}; + i32_4tech i = 0; + for (; i < str.size && char_is_whitespace(str.str[i]); ++i); + result = substr(str, i, str.size - i); + return(result); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +skip_whitespace_measure(String str, i32_4tech *skip_length) +{ + String result = {0}; + i32_4tech i = 0; + for (; i < str.size && char_is_whitespace(str.str[i]); ++i); + result = substr(str, i, str.size - i); + *skip_length = i; + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +chop_whitespace(String str) +{ + String result = {0}; + i32_4tech i = str.size; + for (; i > 0 && char_is_whitespace(str.str[i-1]); --i); + result = substr(str, 0, i); + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +skip_chop_whitespace(String str) +{ + str = skip_whitespace(str); + str = chop_whitespace(str); + return(str); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +skip_chop_whitespace_measure(String str, i32_4tech *skip_length) +{ + str = skip_whitespace_measure(str, skip_length); + str = chop_whitespace(str); + return(str); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE String +tailstr(String str) +{ + String result; + result.str = str.str + str.size; + result.memory_size = str.memory_size - str.size; + result.size = 0; + return(result); +} +#endif + + +// +// String Comparison +// + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_cc(char *a, char *b){ + for (i32_4tech i = 0;; ++i){ + if (a[i] != b[i]){ + return 0; + } + if (a[i] == 0){ + return 1; + } + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_sc(String a, char *b){ + i32_4tech i = 0; + for (; i < a.size; ++i){ + if (a.str[i] != b[i]){ + return 0; + } + } + if (b[i] != 0){ + return 0; + } + return 1; +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +match_cs(char *a, String b){ + return(match_sc(b,a)); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_ss(String a, String b){ + if (a.size != b.size){ + return 0; + } + for (i32_4tech i = 0; i < b.size; ++i){ + if (a.str[i] != b.str[i]){ + return 0; + } + } + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_part_ccl(char *a, char *b, i32_4tech *len){ + i32_4tech i; + for (i = 0; b[i] != 0; ++i){ + if (a[i] != b[i]){ + return 0; + } + } + *len = i; + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_part_scl(String a, char *b, i32_4tech *len){ + i32_4tech i; + for (i = 0; b[i] != 0; ++i){ + if (a.str[i] != b[i] || i == a.size){ + return 0; + } + } + *len = i; + return 1; +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +match_part_cc(char *a, char *b){ + i32_4tech x; + return match_part_ccl(a,b,&x); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +match_part_sc(String a, char *b){ + i32_4tech x; + return match_part_scl(a,b,&x); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_part_cs(char *a, String b){ + for (i32_4tech i = 0; i != b.size; ++i){ + if (a[i] != b.str[i]){ + return 0; + } + } + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_part_ss(String a, String b){ + if (a.size < b.size){ + return 0; + } + for (i32_4tech i = 0; i < b.size; ++i){ + if (a.str[i] != b.str[i]){ + return 0; + } + } + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_insensitive_cc(char *a, char *b){ + for (i32_4tech i = 0;; ++i){ + if (char_to_upper(a[i]) != + char_to_upper(b[i])){ + return 0; + } + if (a[i] == 0){ + return 1; + } + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_insensitive_sc(String a, char *b){ + i32_4tech i = 0; + for (; i < a.size; ++i){ + if (char_to_upper(a.str[i]) != + char_to_upper(b[i])){ + return 0; + } + } + if (b[i] != 0){ + return 0; + } + return 1; +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +match_insensitive_cs(char *a, String b){ + return match_insensitive_sc(b,a); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_insensitive_ss(String a, String b){ + if (a.size != b.size){ + return 0; + } + for (i32_4tech i = 0; i < b.size; ++i){ + if (char_to_upper(a.str[i]) != + char_to_upper(b.str[i])){ + return 0; + } + } + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ + i32_4tech i; + for (i = 0; b[i] != 0; ++i){ + if (char_to_upper(a[i]) != char_to_upper(b[i])){ + return 0; + } + } + *len = i; + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_part_insensitive_scl(String a, char *b, i32_4tech *len){ + i32_4tech i; + for (i = 0; b[i] != 0; ++i){ + if (char_to_upper(a.str[i]) != char_to_upper(b[i]) || + i == a.size){ + return 0; + } + } + *len = i; + return 1; +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +match_part_insensitive_cc(char *a, char *b){ + i32_4tech x; + return match_part_insensitive_ccl(a,b,&x); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +match_part_insensitive_sc(String a, char *b){ + i32_4tech x; + return match_part_insensitive_scl(a,b,&x); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_part_insensitive_cs(char *a, String b){ + for (i32_4tech i = 0; i != b.size; ++i){ + if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ + return(0); + } + } + return(1); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +match_part_insensitive_ss(String a, String b){ + if (a.size < b.size){ + return(0); + } + for (i32_4tech i = 0; i < b.size; ++i){ + if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ + return(0); + } + } + return(1); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +compare_cc(char *a, char *b){ + i32_4tech i = 0, r = 0; + while (a[i] == b[i] && a[i] != 0){ + ++i; + } + r = (a[i] > b[i]) - (a[i] < b[i]); + return(r); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +compare_sc(String a, char *b){ + i32_4tech i = 0, r = 0; + while (i < a.size && a.str[i] == b[i]){ + ++i; + } + if (i < a.size){ + r = (a.str[i] > b[i]) - (a.str[i] < b[i]); + } + else{ + if (b[i] == 0){ + r = 0; + } + else{ + r = -1; + } + } + return(r); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE i32_4tech +compare_cs(char *a, String b){ + i32_4tech r = -compare_sc(b,a); + return(r); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +compare_ss(String a, String b){ + i32_4tech i = 0, r = 0; + i32_4tech m = a.size; + if (b.size < m){ + m = b.size; + } + while (i < m && a.str[i] == b.str[i]){ + ++i; + } + + if (i < m){ + r = (a.str[i] > b.str[i]) - (b.str[i] > a.str[i]); + } + else{ + r = (a.size > b.size) - (b.size > a.size); + } + + return(r); +} +#endif + +// +// Finding Characters and Substrings +// + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +find_c_char(char *str, i32_4tech start, char character){ + i32_4tech i = start; + while (str[i] != character && str[i] != 0) ++i; + return(i); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +find_s_char(String str, i32_4tech start, char character){ + i32_4tech i = start; + while (i < str.size && str.str[i] != character) ++i; + return(i); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +rfind_s_char(String str, i32_4tech start, char character){ + i32_4tech i = start; + while (i >= 0 && str.str[i] != character) --i; + return(i); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +find_c_chars(char *str, i32_4tech start, char *characters){ + i32_4tech i = start, j; + while (str[i] != 0){ + for (j = 0; characters[j]; ++j){ + if (str[i] == characters[j]){ + return(i); + } + } + ++i; + } + return(i); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +find_s_chars(String str, i32_4tech start, char *characters){ + i32_4tech i = start, j; + while (i < str.size){ + for (j = 0; characters[j]; ++j){ + if (str.str[i] == characters[j]){ + return(i); + } + } + ++i; + } + return(i); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +find_substr_c(char *str, i32_4tech start, String seek){ + i32_4tech i, j, k; + b32_4tech hit; + + if (seek.size == 0){ + i = str_size(str); + return(i); + } + for (i = start; str[i]; ++i){ + if (str[i] == seek.str[0]){ + hit = 1; + for (j = 1, k = i+1; j < seek.size; ++j, ++k){ + if (str[k] != seek.str[j]){ + hit = 0; + break; + } + } + if (hit){ + return(i); + } + } + } + return(i); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +find_substr_s(String str, i32_4tech start, String seek){ + i32_4tech stop_at, i, j, k; + b32_4tech hit; + + if (seek.size == 0){ + return str.size; + } + stop_at = str.size - seek.size + 1; + for (i = start; i < stop_at; ++i){ + if (str.str[i] == seek.str[0]){ + hit = 1; + for (j = 1, k = i+1; j < seek.size; ++j, ++k){ + if (str.str[k] != seek.str[j]){ + hit = 0; + break; + } + } + if (hit){ + return i; + } + } + } + return(str.size); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +rfind_substr_s(String str, i32_4tech start, String seek){ + i32_4tech i, j, k; + b32_4tech hit; + + if (seek.size == 0){ + return -1; + } + if (start + seek.size > str.size){ + start = str.size - seek.size; + } + for (i = start; i >= 0; --i){ + if (str.str[i] == seek.str[0]){ + hit = 1; + for (j = 1, k = i+1; j < seek.size; ++j, ++k){ + if (str.str[k] != seek.str[j]){ + hit = 0; + break; + } + } + if (hit){ + return i; + } + } + } + return -1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +find_substr_insensitive_c(char *str, i32_4tech start, String seek){ + i32_4tech i, j, k; + b32_4tech hit; + char a_upper, b_upper; + char first_test_char; + + if (seek.size == 0){ + return str_size(str); + } + first_test_char = char_to_upper(seek.str[0]); + for (i = start; str[i]; ++i){ + a_upper = char_to_upper(str[i]); + if (a_upper == first_test_char){ + hit = 1; + for (j = 1, k = i+1; j < seek.size; ++j, ++k){ + a_upper = char_to_upper(str[k]); + b_upper = char_to_upper(seek.str[j]); + if (a_upper != b_upper){ + hit = 0; + break; + } + } + if (hit){ + return i; + } + } + } + return i; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +find_substr_insensitive_s(String str, i32_4tech start, String seek){ + i32_4tech i, j, k; + i32_4tech stop_at; + b32_4tech hit; + char a_upper, b_upper; + char first_test_char; + + if (seek.size == 0){ + return str.size; + } + stop_at = str.size - seek.size + 1; + first_test_char = char_to_upper(seek.str[0]); + for (i = start; i < stop_at; ++i){ + a_upper = char_to_upper(str.str[i]); + if (a_upper == first_test_char){ + hit = 1; + for (j = 1, k = i+1; j < seek.size; ++j, ++k){ + a_upper = char_to_upper(str.str[k]); + b_upper = char_to_upper(seek.str[j]); + if (a_upper != b_upper){ + hit = 0; + break; + } + } + if (hit){ + return i; + } + } + } + return str.size; +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +has_substr_c(char *s, String seek){ + return (s[find_substr_c(s, 0, seek)] != 0); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +has_substr_s(String s, String seek){ + return (find_substr_s(s, 0, seek) < s.size); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +has_substr_insensitive_c(char *s, String seek){ + return (s[find_substr_insensitive_c(s, 0, seek)] != 0); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +has_substr_insensitive_s(String s, String seek){ + return (find_substr_insensitive_s(s, 0, seek) < s.size); +} +#endif + +// +// String Copies and Appends +// + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +copy_fast_unsafe_cc(char *dest, char *src){ + char *start = dest; + while (*src != 0){ + *dest = *src; + ++dest; + ++src; + } + return (i32_4tech)(dest - start); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +copy_fast_unsafe_cs(char *dest, String src){ + i32_4tech i = 0; + while (i != src.size){ + dest[i] = src.str[i]; + ++i; + } + return(src.size); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +copy_checked_ss(String *dest, String src){ + char *dest_str; + i32_4tech i; + if (dest->memory_size < src.size){ + return 0; + } + dest_str = dest->str; + for (i = 0; i < src.size; ++i){ + dest_str[i] = src.str[i]; + } + dest->size = src.size; + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +copy_checked_cs(char *dest, i32_4tech dest_cap, String src){ + i32_4tech i; + if (dest_cap < src.size){ + return 0; + } + for (i = 0; i < src.size; ++i){ + dest[i] = src.str[i]; + } + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +copy_partial_sc(String *dest, char *src){ + i32_4tech i = 0; + i32_4tech memory_size = dest->memory_size; + char *dest_str = dest->str; + while (src[i] != 0){ + if (i >= memory_size){ + return 0; + } + dest_str[i] = src[i]; + ++i; + } + dest->size = i; + return 1; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +copy_partial_ss(String *dest, String src){ + char *dest_str = dest->str; + i32_4tech memory_size = dest->memory_size; + b32_4tech result = 0; + if (memory_size >= src.size){ + result = 1; + memory_size = src.size; + } + for (i32_4tech i = 0; i < memory_size; ++i){ + dest_str[i] = src.str[i]; + } + dest->size = memory_size; + return(result); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +copy_partial_cs(char *dest, i32_4tech dest_cap, String src){ + b32_4tech result = 0; + i32_4tech copy_size = dest_cap; + i32_4tech i; + if (dest_cap >= src.size){ + result = 1; + copy_size = src.size; + } + for (i = 0; i < copy_size; ++i){ + dest[i] = src.str[i]; + } + return(result); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE i32_4tech +copy_cc(char *dest, char *src){ + return copy_fast_unsafe_cc(dest, src); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE void +copy_ss(String *dest, String src){ + copy_checked_ss(dest, src); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE void +copy_sc(String *dest, char *src){ + copy_partial_sc(dest, src); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +append_checked_ss(String *dest, String src){ + String end; + end = tailstr(*dest); + b32_4tech result = copy_checked_ss(&end, src); + // NOTE(allen): This depends on end.size still being 0 if + // the check failed and no coppy occurred. + dest->size += end.size; + return result; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +append_partial_sc(String *dest, char *src){ + String end = tailstr(*dest); + b32_4tech result = copy_partial_sc(&end, src); + dest->size += end.size; + return result; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +append_partial_ss(String *dest, String src){ + String end = tailstr(*dest); + b32_4tech result = copy_partial_ss(&end, src); + dest->size += end.size; + return result; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +append_s_char(String *dest, char c){ + b32_4tech result = 0; + if (dest->size < dest->memory_size){ + dest->str[dest->size++] = c; + result = 1; + } + return result; +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +append_ss(String *dest, String src){ + return append_partial_ss(dest, src); +} +#endif + + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE b32_4tech +append_sc(String *dest, char *src){ + return append_partial_sc(dest, src); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +terminate_with_null(String *str){ + b32_4tech result = 0; + if (str->size < str->memory_size){ + str->str[str->size] = 0; + result = 1; + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +append_padding(String *dest, char c, i32_4tech target_size){ + b32_4tech result = 1; + i32_4tech offset = target_size - dest->size; + i32_4tech r = 0; + if (offset > 0){ + for (r = 0; r < offset; ++r){ + if (append_s_char(dest, c) == 0){ + result = 0; + break; + } + } + } + return(result); +} +#endif + + +// +// Other Edits +// + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK void +replace_char(String *str, char replace, char with){ + char *s = str->str; + i32_4tech i = 0; + for (i = 0; i < str->size; ++i, ++s){ + if (*s == replace) *s = with; + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK void +to_lower_cc(char *src, char *dst){ + for (; *src != 0; ++src){ + *dst++ = char_to_lower(*src); + } + *dst++ = 0; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK void +to_lower_ss(String *dst, String src){ + i32_4tech i = 0; + i32_4tech size = src.size; + char *c = src.str; + char *d = dst->str; + + if (dst->memory_size >= size){ + for (; i < size; ++i){ + *d++ = char_to_lower(*c++); + } + dst->size = size; + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK void +to_lower_s(String *str){ + i32_4tech i = 0; + i32_4tech size = str->size; + char *c = str->str; + for (; i < size; ++c, ++i){ + *c = char_to_lower(*c); + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK void +to_upper_cc(char *src, char *dst){ + for (; *src != 0; ++src){ + *dst++ = char_to_upper(*src); + } + *dst++ = 0; +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK void +to_upper_ss(String *dst, String src){ + i32_4tech i = 0; + i32_4tech size = src.size; + char *c = src.str; + char *d = dst->str; + + if (dst->memory_size >= size){ + for (; i < size; ++i){ + *d++ = char_to_upper(*c++); + } + dst->size = size; + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK void +to_upper_s(String *str){ + i32_4tech i = 0; + i32_4tech size = str->size; + char *c = str->str; + for (; i < size; ++c, ++i){ + *c = char_to_upper(*c); + } +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK void +to_camel_cc(char *src, char *dst){ + char *c, ch; + i32_4tech is_first = 1; + for (c = src; *c != 0; ++c){ + ch = *c; + if (char_is_alpha_numeric_true(ch)){ + if (is_first){ + is_first = 0; + ch = char_to_upper(ch); + } + else{ + ch = char_to_lower(ch); + } + } + else{ + is_first = 1; + } + *dst++ = ch; + } + *dst = 0; +} +#endif + + +// +// String <-> Number Conversions +// + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +int_to_str_size(i32_4tech x){ + i32_4tech size = 1; + if (x < 0){ + size = 2; + } + x /= 10; + while (x != 0){ + x /= 10; + ++size; + } + return(size); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +int_to_str(String *dest, i32_4tech x){ + b32_4tech result = 1; + char *str = dest->str; + i32_4tech memory_size = dest->memory_size; + i32_4tech size, i, j; + b32_4tech negative; + + if (x == 0){ + str[0] = '0'; + dest->size = 1; + } + else{ + size = 0; + negative = 0; + if (x < 0){ + negative = 1; + x = -x; + str[size++] = '-'; + } + while (x != 0){ + if (size == memory_size){ + result = 0; + break; + } + i = x % 10; + x /= 10; + str[size++] = (char)('0' + i); + } + if (result){ + // NOTE(allen): Start i = 0 if not negative, start i = 1 if is negative because - should not be flipped if it is negative :) + for (i = negative, j = size-1; i < j; ++i, --j){ + char temp = str[i]; + str[i] = str[j]; + str[j] = temp; + } + dest->size = size; + } + else{ + dest->size = 0; + } + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +append_int_to_str(String *dest, i32_4tech x){ + String last_part = tailstr(*dest); + b32_4tech result = int_to_str(&last_part, x); + if (result){ + dest->size += last_part.size; + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +u64_to_str_size(uint64_t x){ + i32_4tech size = 1; + x /= 10; + while (x != 0){ + x /= 10; + ++size; + } + return(size); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +u64_to_str(String *dest, uint64_t x){ + b32_4tech result = 1; + char *str = dest->str; + i32_4tech memory_size = dest->memory_size; + i32_4tech size, i, j; + + if (x == 0){ + str[0] = '0'; + dest->size = 1; + } + else{ + size = 0; + while (x != 0){ + if (size == memory_size){ + result = 0; + break; + } + i = x % 10; + x /= 10; + str[size++] = (char)('0' + i); + } + if (result){ + for (i = 0, j = size-1; i < j; ++i, --j){ + char temp = str[i]; + str[i] = str[j]; + str[j] = temp; + } + dest->size = size; + } + else{ + dest->size = 0; + } + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +append_u64_to_str(String *dest, uint64_t x){ + String last_part = tailstr(*dest); + b32_4tech result = u64_to_str(&last_part, x); + if (result){ + dest->size += last_part.size; + } + return(result); +} +#endif + +#if !defined(FSTRING_GUARD) +typedef struct Float_To_Str_Variables{ + b32_4tech negative; + i32_4tech int_part; + i32_4tech dec_part; +} Float_To_Str_Variables; + +static Float_To_Str_Variables +get_float_vars(float x){ + Float_To_Str_Variables vars = {0}; + + if (x < 0){ + vars.negative = 1; + x = -x; + } + + vars.int_part = (i32_4tech)(x); + vars.dec_part = (i32_4tech)((x - vars.int_part) * 1000); + + return(vars); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +float_to_str_size(float x){ + Float_To_Str_Variables vars = get_float_vars(x); + i32_4tech size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); + return(size); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +append_float_to_str(String *dest, float x){ + b32_4tech result = 1; + Float_To_Str_Variables vars = get_float_vars(x); + + if (vars.negative){ + append_s_char(dest, '-'); + } + + append_int_to_str(dest, vars.int_part); + append_s_char(dest, '.'); + append_int_to_str(dest, vars.dec_part); + + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +float_to_str(String *dest, float x){ + b32_4tech result = 1; + dest->size = 0; + append_float_to_str(dest, x); + return(result); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +str_is_int_c(char *str){ + b32_4tech result = 1; + for (; *str; ++str){ + if (!char_is_numeric(*str)){ + result = 0; + break; + } + } + return(result); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +str_is_int_s(String str){ + b32_4tech result = 1; + for (i32_4tech i = 0; i < str.size; ++i){ + if (!char_is_numeric(str.str[i])){ + result = 0; + break; + } + } + return(result); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +str_to_int_c(char *str){ + i32_4tech x = 0; + for (; *str; ++str){ + if (*str >= '0' && *str <= '9'){ + x *= 10; + x += *str - '0'; + } + else{ + x = 0; + break; + } + } + return(x); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +str_to_int_s(String str){ + i32_4tech x, i; + if (str.size == 0){ + x = 0; + } + else{ + x = str.str[0] - '0'; + for (i = 1; i < str.size; ++i){ + x *= 10; + x += str.str[i] - '0'; + } + } + return(x); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +hexchar_to_int(char c){ + i32_4tech x = 0; + if (c >= '0' && c <= '9'){ + x = c-'0'; + } + else if (c > 'F'){ + x = c+(10-'a'); + } + else{ + x = c+(10-'A'); + } + return(x); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK char +int_to_hexchar(i32_4tech x){ + return (x<10)?((char)x+'0'):((char)x+'a'-10); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK u32_4tech +hexstr_to_int(String str){ + u32_4tech x; + i32_4tech i; + if (str.size == 0){ + x = 0; + } + else{ + x = hexchar_to_int(str.str[0]); + for (i = 1; i < str.size; ++i){ + x *= 0x10; + x += hexchar_to_int(str.str[i]); + } + } + return(x); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +color_to_hexstr(String *s, u32_4tech color){ + b32_4tech result = 0; + i32_4tech i; + + if (s->memory_size == 7 || s->memory_size == 8){ + result = 1; + s->size = 6; + s->str[6] = 0; + color = color & 0x00FFFFFF; + for (i = 5; i >= 0; --i){ + s->str[i] = int_to_hexchar(color & 0xF); + color >>= 4; + } + } + else if (s->memory_size > 8){ + result = 1; + s->size = 8; + s->str[8] = 0; + for (i = 7; i >= 0; --i){ + s->str[i] = int_to_hexchar(color & 0xF); + color >>= 4; + } + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +hexstr_to_color(String s, u32_4tech *out){ + b32_4tech result = 0; + u32_4tech color = 0; + if (s.size == 6){ + result = 1; + color = (u32_4tech)hexstr_to_int(s); + color |= (0xFF << 24); + *out = color; + } + else if (s.size == 8){ + result = 1; + color = (u32_4tech)hexstr_to_int(s); + *out = color; + } + return(result); +} +#endif + +// +// Directory String Management +// + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK i32_4tech +reverse_seek_slash_pos(String str, i32_4tech pos){ + i32_4tech i = str.size - 1 - pos; + while (i >= 0 && !char_is_slash(str.str[i])){ + --i; + } + return i; +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE i32_4tech +reverse_seek_slash(String str){ + return(reverse_seek_slash_pos(str, 0)); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE String +front_of_directory(String dir){ + return substr_tail(dir, reverse_seek_slash(dir) + 1); +} +#endif + +#if !defined(FSTRING_GUARD) + FSTRING_INLINE String +path_of_directory(String dir){ + return substr(dir, 0, reverse_seek_slash(dir) + 1); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +set_last_folder_sc(String *dir, char *folder_name, char slash){ + b32_4tech result = 0; + i32_4tech size = reverse_seek_slash(*dir) + 1; + dir->size = size; + if (append_sc(dir, folder_name)){ + if (append_s_char(dir, slash)){ + result = 1; + } + } + if (!result){ + dir->size = size; + } + return(result); +} +#endif + + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +set_last_folder_ss(String *dir, String folder_name, char slash){ + b32_4tech result = 0; + i32_4tech size = reverse_seek_slash(*dir) + 1; + dir->size = size; + if (append_ss(dir, folder_name)){ + if (append_s_char(dir, slash)){ + result = 1; + } + } + if (!result){ + dir->size = size; + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +file_extension(String str){ + i32_4tech i; + for (i = str.size - 1; i >= 0; --i){ + if (str.str[i] == '.') break; + } + ++i; + return(make_string(str.str+i, str.size-i)); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +remove_extension(String *str){ + b32_4tech result = 0; + i32_4tech i; + for (i = str->size - 1; i >= 0; --i){ + if (str->str[i] == '.') break; + } + if (i >= 0){ + result = 1; + str->size = i + 1; + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +remove_last_folder(String *str){ + b32_4tech result = 0; + i32_4tech end = reverse_seek_slash_pos(*str, 1); + if (end >= 0){ + result = 1; + str->size = end + 1; + } + return(result); +} +#endif + +// TODO(allen): Add hash-table extension to string sets. + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){ + b32_4tech result = 0; + i32_4tech i = 0; + uint8_t *ptr = (uint8_t*)str_set; + for (; i < count; ++i, ptr += item_size){ + if (match_ss(*(String*)ptr, str)){ + *match_index = i; + result = 1; + break; + } + } + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK b32_4tech +string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index){ + b32_4tech result = string_set_match_table(str_set, sizeof(String), count, str, match_index); + return(result); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_first_double_line(String source){ + String line = {0}; + i32_4tech pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); + i32_4tech pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + line = substr(source, 0, pos0); + return(line); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_next_double_line(String source, String line){ + String next = {0}; + i32_4tech pos = (i32_4tech)(line.str - source.str) + line.size; + i32_4tech start = 0, pos0 = 0, pos1 = 0; + + if (pos < source.size){ + //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); + start = pos + 1; + + if (start < source.size){ + pos0 = find_substr_s(source, start, make_lit_string("\n\n")); + pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); + if (pos1 < pos0){ + pos0 = pos1; + } + next = substr(source, start, pos0 - start); + } + } + + return(next); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_next_word(String source, String prev_word){ + + String word = {0}; + i32_4tech pos0 = (i32_4tech)(prev_word.str - source.str) + prev_word.size; + i32_4tech pos1 = 0; + char c = 0; + + for (; pos0 < source.size; ++pos0){ + c = source.str[pos0]; + if (!(char_is_whitespace(c) || c == '(' || c == ')')){ + break; + } + } + + if (pos0 < source.size){ + for (pos1 = pos0; pos1 < source.size; ++pos1){ + c = source.str[pos1]; + if (char_is_whitespace(c) || c == '(' || c == ')'){ + break; + } + } + + word = substr(source, pos0, pos1 - pos0); + } + + return(word); +} +#endif + +#if defined(FSTRING_IMPLEMENTATION) + FSTRING_LINK String +get_first_word(String source){ + String start_str = make_string(source.str, 0); + String word = get_next_word(source, start_str); + return(word); +} +#endif + +// TODO(allen): eliminate this. +#ifndef FSTRING_EXPERIMENTAL +#define FSTRING_EXPERIMENTAL + +// NOTE(allen): experimental section, things below here are +// not promoted to public API level yet. + +typedef struct Absolutes{ + String a[8]; + i32_4tech count; +} Absolutes; + +static void +get_absolutes(String name, Absolutes *absolutes, b32_4tech implicit_first, b32_4tech implicit_last){ + if (name.size != 0){ + i32_4tech count = 0; + i32_4tech max = (sizeof(absolutes->a)/sizeof(*absolutes->a)) - 1; + if (implicit_last) --max; + + String str; + str.str = name.str; + str.size = 0; + str.memory_size = 0; + b32_4tech prev_was_wild = 0; + + if (implicit_first){ + absolutes->a[count++] = str; + prev_was_wild = 1; + } + + i32_4tech i; + for (i = 0; i < name.size; ++i){ + if (name.str[i] == '*' && count < max){ + if (!prev_was_wild){ + str.memory_size = str.size; + absolutes->a[count++] = str; + str.size = 0; + } + str.str = name.str + i + 1; + prev_was_wild = 1; + } + else{ + ++str.size; + prev_was_wild = 0; + } + } + + str.memory_size = str.size; + absolutes->a[count++] = str; + + if (implicit_last){ + str.size = 0; + str.memory_size = 0; + absolutes->a[count++] = str; + } + + absolutes->count = count; + } + else{ + absolutes->count = 0; + } +} + +static b32_4tech +wildcard_match_c(Absolutes *absolutes, char *x, i32_4tech case_sensitive){ + b32_4tech r = 1; + + if (absolutes->count > 0){ + String *a = absolutes->a; + + b32_4tech (*match_func)(char*, String); + b32_4tech (*match_part_func)(char*, String); + + if (case_sensitive){ + match_func = match_cs; + match_part_func = match_part_cs; + } + else{ + match_func = match_insensitive_cs; + match_part_func = match_part_insensitive_cs; + } + + if (absolutes->count == 1){ + r = match_func(x, *a); + } + else{ + if (!match_part_func(x, *a)){ + r = 0; + } + else{ + String *max = a + absolutes->count - 1; + x += a->size; + ++a; + while (a < max){ + if (*x == 0){ + r = 0; + break; + } + if (match_part_func(x, *a)){ + x += a->size; + ++a; + } + else{ + ++x; + } + } + if (r && a->size > 0){ + r = 0; + while (*x != 0){ + if (match_part_func(x, *a) && *(x + a->size) == 0){ + r = 1; + break; + } + else{ + ++x; + } + } + } + } + } + } + return(r); +} + +static b32_4tech +wildcard_match_s(Absolutes *absolutes, String x, i32_4tech case_sensitive){ + terminate_with_null(&x); + return(wildcard_match_c(absolutes, x.str, case_sensitive)); +} + +#endif + +#if defined(FSTRING_IMPLEMENTATION) +#undef FSTRING_IMPLEMENTATION +#define FSTRING_IMPL_GUARD +#endif + +#if !defined(FSTRING_GUARD) +#define FSTRING_GUARD +#endif + +// BOTTOM + diff --git a/string/4tech_standard_preamble.h b/string/4ed_standard_preamble.h similarity index 100% rename from string/4tech_standard_preamble.h rename to string/4ed_standard_preamble.h diff --git a/string/string_builder.cpp b/string/4ed_string_builder.cpp similarity index 98% rename from string/string_builder.cpp rename to string/4ed_string_builder.cpp index 6604a190..7bdba67f 100644 --- a/string/string_builder.cpp +++ b/string/4ed_string_builder.cpp @@ -37,7 +37,8 @@ Created 21.01.2017 (dd.mm.yyyy) #define V_MAJ STR_(V_MAJ_NUM) #define V_MIN STR_(V_MIN_NUM) -#include "../meta/meta_parser.cpp" +#include "../meta/4ed_meta_parser.cpp" +#include "../meta/4ed_out_context.cpp" static b32 parse_build_number(char *file_name, i32 *major_out, i32 *minor_out, i32 *build_out){ @@ -96,8 +97,6 @@ save_build_number(char *file_name, i32 major, i32 minor, i32 build){ /////////////////////////////// -#include "../meta/out_context.cpp" - // // Meta Parse Rules // @@ -158,7 +157,7 @@ print_function_body_code(String *out, Parse_Context *context, int32_t start){ internal void file_move(char *path, char *file_name){ - copy_file(0, file_name, path, 0, file_name); + fm_copy_file(fm_str(file_name), fm_str(path, "/", file_name)); } int main(){ @@ -467,11 +466,11 @@ int main(){ // NOTE(allen): Publish the new file. (Would like to be able to automatically test the result before publishing). { - make_folder_if_missing(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, 0); + fm_make_folder_if_missing(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN); file_move(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, INTERNAL_STRING); file_move(BACKUP_FOLDER SLASH V_MAJ SLASH V_MIN, GENERATED_FILE); //file_move(PUBLISH_FOLDER, GENERATED_FILE); - delete_file(GENERATED_FILE); + fm_delete_file(GENERATED_FILE); printf("published "GENERATED_FILE": v%d.%d.%d\n", major_number, minor_number, build_number); save_build_number(BUILD_NUMBER_FILE, major_number, minor_number, build_number + 1); } From 39a56b2aa9592dced5d4a45456ae3a90221e4506 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 9 Jul 2017 15:25:24 -0400 Subject: [PATCH 4/5] organizing string builder --- string/4coder_string.h | 2273 ---------------------------- string/4coder_string_build_num.txt | 2 +- string/4ed_string_builder.cpp | 37 +- 3 files changed, 21 insertions(+), 2291 deletions(-) delete mode 100644 string/4coder_string.h diff --git a/string/4coder_string.h b/string/4coder_string.h deleted file mode 100644 index bb23cae5..00000000 --- a/string/4coder_string.h +++ /dev/null @@ -1,2273 +0,0 @@ -/* -4coder_string.h - Version 1.0.87 -no warranty implied; use at your own risk - -This software is in the public domain. Where that dedication is not -recognized, you are granted a perpetual, irrevocable license to copy, -distribute, and modify this file as you see fit. - -To include implementation: #define FSTRING_IMPLEMENTATION -To use in C mode: #define FSTRING_C -*/ - -// TOP - - - -#if !defined(FSTRING_LINK) -# define FSTRING_LINK static -#endif - -#if !defined(FSTRING_INLINE) -# if defined(FSTRING_C) -# define FSTRING_INLINE static -# else -# define FSTRING_INLINE inline -# endif -#endif - -#if !defined(FSTRING_GUARD) -#define literal(s) (s), (sizeof(s)-1) - -typedef struct String{ - char *str; - i32_4tech size; - i32_4tech memory_size; -} String; - -static String null_string = {0}; -#endif - -#if !defined(FCODER_STRING_H) -#define FCODER_STRING_H - -FSTRING_INLINE b32_4tech char_is_slash(char c); -FSTRING_INLINE b32_4tech char_is_upper(char c); -FSTRING_INLINE b32_4tech char_is_upper_utf8(char c); -FSTRING_INLINE b32_4tech char_is_lower(char c); -FSTRING_INLINE b32_4tech char_is_lower_utf8(u8_4tech c); -FSTRING_INLINE char char_to_upper(char c); -FSTRING_INLINE char char_to_lower(char c); -FSTRING_INLINE b32_4tech char_is_whitespace(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_true(char c); -FSTRING_INLINE b32_4tech char_is_alpha_numeric_true_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha(char c); -FSTRING_INLINE b32_4tech char_is_alpha_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_alpha_true(char c); -FSTRING_INLINE b32_4tech char_is_alpha_true_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_hex(char c); -FSTRING_INLINE b32_4tech char_is_hex_utf8(u8_4tech c); -FSTRING_INLINE b32_4tech char_is_numeric(char c); -FSTRING_INLINE b32_4tech char_is_numeric_utf8(u8_4tech c); -FSTRING_INLINE String make_string_cap(void *str, i32_4tech size, i32_4tech mem_size); -FSTRING_INLINE String make_string(void *str, i32_4tech size); -#ifndef make_lit_string -# define make_lit_string(s) (make_string_cap((char*)(s), sizeof(s)-1, sizeof(s))) -#endif -#ifndef make_fixed_width_string -# define make_fixed_width_string(s) (make_string_cap((char*)(s), 0, sizeof(s))) -#endif -#ifndef expand_str -# define expand_str(s) ((s).str), ((s).size) -#endif -FSTRING_LINK i32_4tech str_size(char *str); -FSTRING_INLINE String make_string_slowly(void *str); -FSTRING_INLINE String substr_tail(String str, i32_4tech start); -FSTRING_INLINE String substr(String str, i32_4tech start, i32_4tech size); -FSTRING_LINK String skip_whitespace(String str); -FSTRING_LINK String skip_whitespace_measure(String str, i32_4tech *skip_length); -FSTRING_LINK String chop_whitespace(String str); -FSTRING_LINK String skip_chop_whitespace(String str); -FSTRING_LINK String skip_chop_whitespace_measure(String str, i32_4tech *skip_length); -FSTRING_INLINE String tailstr(String str); -FSTRING_LINK b32_4tech match_cc(char *a, char *b); -FSTRING_LINK b32_4tech match_sc(String a, char *b); -FSTRING_INLINE b32_4tech match_cs(char *a, String b); -FSTRING_LINK b32_4tech match_ss(String a, String b); -FSTRING_LINK b32_4tech match_part_ccl(char *a, char *b, i32_4tech *len); -FSTRING_LINK b32_4tech match_part_scl(String a, char *b, i32_4tech *len); -FSTRING_INLINE b32_4tech match_part_cc(char *a, char *b); -FSTRING_INLINE b32_4tech match_part_sc(String a, char *b); -FSTRING_LINK b32_4tech match_part_cs(char *a, String b); -FSTRING_LINK b32_4tech match_part_ss(String a, String b); -FSTRING_LINK b32_4tech match_insensitive_cc(char *a, char *b); -FSTRING_LINK b32_4tech match_insensitive_sc(String a, char *b); -FSTRING_INLINE b32_4tech match_insensitive_cs(char *a, String b); -FSTRING_LINK b32_4tech match_insensitive_ss(String a, String b); -FSTRING_LINK b32_4tech match_part_insensitive_ccl(char *a, char *b, i32_4tech *len); -FSTRING_LINK b32_4tech match_part_insensitive_scl(String a, char *b, i32_4tech *len); -FSTRING_INLINE b32_4tech match_part_insensitive_cc(char *a, char *b); -FSTRING_INLINE b32_4tech match_part_insensitive_sc(String a, char *b); -FSTRING_LINK b32_4tech match_part_insensitive_cs(char *a, String b); -FSTRING_LINK b32_4tech match_part_insensitive_ss(String a, String b); -FSTRING_LINK i32_4tech compare_cc(char *a, char *b); -FSTRING_LINK i32_4tech compare_sc(String a, char *b); -FSTRING_INLINE i32_4tech compare_cs(char *a, String b); -FSTRING_LINK i32_4tech compare_ss(String a, String b); -FSTRING_LINK i32_4tech find_c_char(char *str, i32_4tech start, char character); -FSTRING_LINK i32_4tech find_s_char(String str, i32_4tech start, char character); -FSTRING_LINK i32_4tech rfind_s_char(String str, i32_4tech start, char character); -FSTRING_LINK i32_4tech find_c_chars(char *str, i32_4tech start, char *characters); -FSTRING_LINK i32_4tech find_s_chars(String str, i32_4tech start, char *characters); -FSTRING_LINK i32_4tech find_substr_c(char *str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_s(String str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech rfind_substr_s(String str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_insensitive_c(char *str, i32_4tech start, String seek); -FSTRING_LINK i32_4tech find_substr_insensitive_s(String str, i32_4tech start, String seek); -FSTRING_INLINE b32_4tech has_substr_c(char *s, String seek); -FSTRING_INLINE b32_4tech has_substr_s(String s, String seek); -FSTRING_INLINE b32_4tech has_substr_insensitive_c(char *s, String seek); -FSTRING_INLINE b32_4tech has_substr_insensitive_s(String s, String seek); -FSTRING_LINK i32_4tech copy_fast_unsafe_cc(char *dest, char *src); -FSTRING_LINK i32_4tech copy_fast_unsafe_cs(char *dest, String src); -FSTRING_LINK b32_4tech copy_checked_ss(String *dest, String src); -FSTRING_LINK b32_4tech copy_checked_cs(char *dest, i32_4tech dest_cap, String src); -FSTRING_LINK b32_4tech copy_partial_sc(String *dest, char *src); -FSTRING_LINK b32_4tech copy_partial_ss(String *dest, String src); -FSTRING_LINK b32_4tech copy_partial_cs(char *dest, i32_4tech dest_cap, String src); -FSTRING_INLINE i32_4tech copy_cc(char *dest, char *src); -FSTRING_INLINE void copy_ss(String *dest, String src); -FSTRING_INLINE void copy_sc(String *dest, char *src); -FSTRING_LINK b32_4tech append_checked_ss(String *dest, String src); -FSTRING_LINK b32_4tech append_partial_sc(String *dest, char *src); -FSTRING_LINK b32_4tech append_partial_ss(String *dest, String src); -FSTRING_LINK b32_4tech append_s_char(String *dest, char c); -FSTRING_INLINE b32_4tech append_ss(String *dest, String src); -FSTRING_INLINE b32_4tech append_sc(String *dest, char *src); -FSTRING_LINK b32_4tech terminate_with_null(String *str); -FSTRING_LINK b32_4tech append_padding(String *dest, char c, i32_4tech target_size); -FSTRING_LINK void replace_char(String *str, char replace, char with); -FSTRING_LINK void to_lower_cc(char *src, char *dst); -FSTRING_LINK void to_lower_ss(String *dst, String src); -FSTRING_LINK void to_lower_s(String *str); -FSTRING_LINK void to_upper_cc(char *src, char *dst); -FSTRING_LINK void to_upper_ss(String *dst, String src); -FSTRING_LINK void to_upper_s(String *str); -FSTRING_LINK void to_camel_cc(char *src, char *dst); -FSTRING_LINK i32_4tech int_to_str_size(i32_4tech x); -FSTRING_LINK b32_4tech int_to_str(String *dest, i32_4tech x); -FSTRING_LINK b32_4tech append_int_to_str(String *dest, i32_4tech x); -FSTRING_LINK i32_4tech u64_to_str_size(uint64_t x); -FSTRING_LINK b32_4tech u64_to_str(String *dest, uint64_t x); -FSTRING_LINK b32_4tech append_u64_to_str(String *dest, uint64_t x); -FSTRING_LINK i32_4tech float_to_str_size(float x); -FSTRING_LINK b32_4tech append_float_to_str(String *dest, float x); -FSTRING_LINK b32_4tech float_to_str(String *dest, float x); -FSTRING_LINK i32_4tech str_is_int_c(char *str); -FSTRING_LINK b32_4tech str_is_int_s(String str); -FSTRING_LINK i32_4tech str_to_int_c(char *str); -FSTRING_LINK i32_4tech str_to_int_s(String str); -FSTRING_LINK i32_4tech hexchar_to_int(char c); -FSTRING_LINK char int_to_hexchar(i32_4tech x); -FSTRING_LINK u32_4tech hexstr_to_int(String str); -FSTRING_LINK b32_4tech color_to_hexstr(String *s, u32_4tech color); -FSTRING_LINK b32_4tech hexstr_to_color(String s, u32_4tech *out); -FSTRING_LINK i32_4tech reverse_seek_slash_pos(String str, i32_4tech pos); -FSTRING_INLINE i32_4tech reverse_seek_slash(String str); -FSTRING_INLINE String front_of_directory(String dir); -FSTRING_INLINE String path_of_directory(String dir); -FSTRING_LINK b32_4tech set_last_folder_sc(String *dir, char *folder_name, char slash); -FSTRING_LINK b32_4tech set_last_folder_ss(String *dir, String folder_name, char slash); -FSTRING_LINK String file_extension(String str); -FSTRING_LINK b32_4tech remove_extension(String *str); -FSTRING_LINK b32_4tech remove_last_folder(String *str); -FSTRING_LINK b32_4tech string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index); -FSTRING_LINK b32_4tech string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index); -FSTRING_LINK String get_first_double_line(String source); -FSTRING_LINK String get_next_double_line(String source, String line); -FSTRING_LINK String get_next_word(String source, String prev_word); -FSTRING_LINK String get_first_word(String source); - -#endif - -#if !defined(FSTRING_C) && !defined(FSTRING_GUARD) - -FSTRING_INLINE String make_string(void *str, i32_4tech size, i32_4tech mem_size){return(make_string_cap(str,size,mem_size));} -FSTRING_INLINE String substr(String str, i32_4tech start){return(substr_tail(str,start));} -FSTRING_LINK String skip_whitespace(String str, i32_4tech *skip_length){return(skip_whitespace_measure(str,skip_length));} -FSTRING_LINK String skip_chop_whitespace(String str, i32_4tech *skip_length){return(skip_chop_whitespace_measure(str,skip_length));} -FSTRING_LINK b32_4tech match(char *a, char *b){return(match_cc(a,b));} -FSTRING_LINK b32_4tech match(String a, char *b){return(match_sc(a,b));} -FSTRING_INLINE b32_4tech match(char *a, String b){return(match_cs(a,b));} -FSTRING_LINK b32_4tech match(String a, String b){return(match_ss(a,b));} -FSTRING_LINK b32_4tech match_part(char *a, char *b, i32_4tech *len){return(match_part_ccl(a,b,len));} -FSTRING_LINK b32_4tech match_part(String a, char *b, i32_4tech *len){return(match_part_scl(a,b,len));} -FSTRING_INLINE b32_4tech match_part(char *a, char *b){return(match_part_cc(a,b));} -FSTRING_INLINE b32_4tech match_part(String a, char *b){return(match_part_sc(a,b));} -FSTRING_LINK b32_4tech match_part(char *a, String b){return(match_part_cs(a,b));} -FSTRING_LINK b32_4tech match_part(String a, String b){return(match_part_ss(a,b));} -FSTRING_LINK b32_4tech match_insensitive(char *a, char *b){return(match_insensitive_cc(a,b));} -FSTRING_LINK b32_4tech match_insensitive(String a, char *b){return(match_insensitive_sc(a,b));} -FSTRING_INLINE b32_4tech match_insensitive(char *a, String b){return(match_insensitive_cs(a,b));} -FSTRING_LINK b32_4tech match_insensitive(String a, String b){return(match_insensitive_ss(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(char *a, char *b, i32_4tech *len){return(match_part_insensitive_ccl(a,b,len));} -FSTRING_LINK b32_4tech match_part_insensitive(String a, char *b, i32_4tech *len){return(match_part_insensitive_scl(a,b,len));} -FSTRING_INLINE b32_4tech match_part_insensitive(char *a, char *b){return(match_part_insensitive_cc(a,b));} -FSTRING_INLINE b32_4tech match_part_insensitive(String a, char *b){return(match_part_insensitive_sc(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(char *a, String b){return(match_part_insensitive_cs(a,b));} -FSTRING_LINK b32_4tech match_part_insensitive(String a, String b){return(match_part_insensitive_ss(a,b));} -FSTRING_LINK i32_4tech compare(char *a, char *b){return(compare_cc(a,b));} -FSTRING_LINK i32_4tech compare(String a, char *b){return(compare_sc(a,b));} -FSTRING_INLINE i32_4tech compare(char *a, String b){return(compare_cs(a,b));} -FSTRING_LINK i32_4tech compare(String a, String b){return(compare_ss(a,b));} -FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char character){return(find_c_char(str,start,character));} -FSTRING_LINK i32_4tech find(String str, i32_4tech start, char character){return(find_s_char(str,start,character));} -FSTRING_LINK i32_4tech rfind(String str, i32_4tech start, char character){return(rfind_s_char(str,start,character));} -FSTRING_LINK i32_4tech find(char *str, i32_4tech start, char *characters){return(find_c_chars(str,start,characters));} -FSTRING_LINK i32_4tech find(String str, i32_4tech start, char *characters){return(find_s_chars(str,start,characters));} -FSTRING_LINK i32_4tech find_substr(char *str, i32_4tech start, String seek){return(find_substr_c(str,start,seek));} -FSTRING_LINK i32_4tech find_substr(String str, i32_4tech start, String seek){return(find_substr_s(str,start,seek));} -FSTRING_LINK i32_4tech rfind_substr(String str, i32_4tech start, String seek){return(rfind_substr_s(str,start,seek));} -FSTRING_LINK i32_4tech find_substr_insensitive(char *str, i32_4tech start, String seek){return(find_substr_insensitive_c(str,start,seek));} -FSTRING_LINK i32_4tech find_substr_insensitive(String str, i32_4tech start, String seek){return(find_substr_insensitive_s(str,start,seek));} -FSTRING_INLINE b32_4tech has_substr(char *s, String seek){return(has_substr_c(s,seek));} -FSTRING_INLINE b32_4tech has_substr(String s, String seek){return(has_substr_s(s,seek));} -FSTRING_INLINE b32_4tech has_substr_insensitive(char *s, String seek){return(has_substr_insensitive_c(s,seek));} -FSTRING_INLINE b32_4tech has_substr_insensitive(String s, String seek){return(has_substr_insensitive_s(s,seek));} -FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, char *src){return(copy_fast_unsafe_cc(dest,src));} -FSTRING_LINK i32_4tech copy_fast_unsafe(char *dest, String src){return(copy_fast_unsafe_cs(dest,src));} -FSTRING_LINK b32_4tech copy_checked(String *dest, String src){return(copy_checked_ss(dest,src));} -FSTRING_LINK b32_4tech copy_checked(char *dest, i32_4tech dest_cap, String src){return(copy_checked_cs(dest,dest_cap,src));} -FSTRING_LINK b32_4tech copy_partial(String *dest, char *src){return(copy_partial_sc(dest,src));} -FSTRING_LINK b32_4tech copy_partial(String *dest, String src){return(copy_partial_ss(dest,src));} -FSTRING_LINK b32_4tech copy_partial(char *dest, i32_4tech dest_cap, String src){return(copy_partial_cs(dest,dest_cap,src));} -FSTRING_INLINE i32_4tech copy(char *dest, char *src){return(copy_cc(dest,src));} -FSTRING_INLINE void copy(String *dest, String src){return(copy_ss(dest,src));} -FSTRING_INLINE void copy(String *dest, char *src){return(copy_sc(dest,src));} -FSTRING_LINK b32_4tech append_checked(String *dest, String src){return(append_checked_ss(dest,src));} -FSTRING_LINK b32_4tech append_partial(String *dest, char *src){return(append_partial_sc(dest,src));} -FSTRING_LINK b32_4tech append_partial(String *dest, String src){return(append_partial_ss(dest,src));} -FSTRING_LINK b32_4tech append(String *dest, char c){return(append_s_char(dest,c));} -FSTRING_INLINE b32_4tech append(String *dest, String src){return(append_ss(dest,src));} -FSTRING_INLINE b32_4tech append(String *dest, char *src){return(append_sc(dest,src));} -FSTRING_LINK void to_lower(char *src, char *dst){return(to_lower_cc(src,dst));} -FSTRING_LINK void to_lower(String *dst, String src){return(to_lower_ss(dst,src));} -FSTRING_LINK void to_lower(String *str){return(to_lower_s(str));} -FSTRING_LINK void to_upper(char *src, char *dst){return(to_upper_cc(src,dst));} -FSTRING_LINK void to_upper(String *dst, String src){return(to_upper_ss(dst,src));} -FSTRING_LINK void to_upper(String *str){return(to_upper_s(str));} -FSTRING_LINK void to_camel(char *src, char *dst){return(to_camel_cc(src,dst));} -FSTRING_LINK i32_4tech str_is_int(char *str){return(str_is_int_c(str));} -FSTRING_LINK b32_4tech str_is_int(String str){return(str_is_int_s(str));} -FSTRING_LINK i32_4tech str_to_int(char *str){return(str_to_int_c(str));} -FSTRING_LINK i32_4tech str_to_int(String str){return(str_to_int_s(str));} -FSTRING_LINK i32_4tech reverse_seek_slash(String str, i32_4tech pos){return(reverse_seek_slash_pos(str,pos));} -FSTRING_LINK b32_4tech set_last_folder(String *dir, char *folder_name, char slash){return(set_last_folder_sc(dir,folder_name,slash));} -FSTRING_LINK b32_4tech set_last_folder(String *dir, String folder_name, char slash){return(set_last_folder_ss(dir,folder_name,slash));} -FSTRING_LINK b32_4tech string_set_match(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){return(string_set_match_table(str_set,item_size,count,str,match_index));} - -#endif - - -// -// Character Helpers -// - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_slash(char c) -{ - return (c == '\\' || c == '/'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_upper(char c) -{ - return (c >= 'A' && c <= 'Z'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_upper_utf8(char c) -{ - return ((c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_lower(char c) -{ - return (c >= 'a' && c <= 'z'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_lower_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE char -char_to_upper(char c) -{ - return (c >= 'a' && c <= 'z') ? c + (char)('A' - 'a') : c; -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE char -char_to_lower(char c) -{ - return (c >= 'A' && c <= 'Z') ? c - (char)('A' - 'a') : c; -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_whitespace(char c) -{ - return (c == ' ' || c == '\n' || c == '\r' || c == '\t'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_numeric(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_numeric_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '_' || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_numeric_true(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9')); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_numeric_true_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == '_' || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_true(char c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_alpha_true_utf8(u8_4tech c) -{ - return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_hex(char c) -{ - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f')); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_hex_utf8(u8_4tech c) -{ - return ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (unsigned char)c >= 128); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_numeric(char c) -{ - return (c >= '0' && c <= '9'); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -char_is_numeric_utf8(u8_4tech c) -{ - return ((c >= '0' && c <= '9') || (unsigned char)c >= 128); -} -#endif - - -// -// String Making Functions -// - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -make_string_cap(void *str, i32_4tech size, i32_4tech mem_size){ - String result; - result.str = (char*)str; - result.size = size; - result.memory_size = mem_size; - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -make_string(void *str, i32_4tech size){ - String result; - result.str = (char*)str; - result.size = size; - result.memory_size = size; - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -str_size(char *str) -{ - i32_4tech i = 0; - while (str[i]) ++i; - return(i); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -make_string_slowly(void *str) -{ - String result; - result.str = (char*)str; - result.size = str_size((char*)str); - result.memory_size = result.size+1; - return(result); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -substr_tail(String str, i32_4tech start) -{ - String result; - result.str = str.str + start; - result.size = str.size - start; - result.memory_size = 0; - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -substr(String str, i32_4tech start, i32_4tech size) -{ - String result; - result.str = str.str + start; - result.size = size; - if (start + size > str.size){ - result.size = str.size - start; - } - result.memory_size = 0; - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -skip_whitespace(String str) -{ - String result = {0}; - i32_4tech i = 0; - for (; i < str.size && char_is_whitespace(str.str[i]); ++i); - result = substr(str, i, str.size - i); - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -skip_whitespace_measure(String str, i32_4tech *skip_length) -{ - String result = {0}; - i32_4tech i = 0; - for (; i < str.size && char_is_whitespace(str.str[i]); ++i); - result = substr(str, i, str.size - i); - *skip_length = i; - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -chop_whitespace(String str) -{ - String result = {0}; - i32_4tech i = str.size; - for (; i > 0 && char_is_whitespace(str.str[i-1]); --i); - result = substr(str, 0, i); - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -skip_chop_whitespace(String str) -{ - str = skip_whitespace(str); - str = chop_whitespace(str); - return(str); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -skip_chop_whitespace_measure(String str, i32_4tech *skip_length) -{ - str = skip_whitespace_measure(str, skip_length); - str = chop_whitespace(str); - return(str); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -tailstr(String str) -{ - String result; - result.str = str.str + str.size; - result.memory_size = str.memory_size - str.size; - result.size = 0; - return(result); -} -#endif - - -// -// String Comparison -// - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_cc(char *a, char *b){ - for (i32_4tech i = 0;; ++i){ - if (a[i] != b[i]){ - return 0; - } - if (a[i] == 0){ - return 1; - } - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_sc(String a, char *b){ - i32_4tech i = 0; - for (; i < a.size; ++i){ - if (a.str[i] != b[i]){ - return 0; - } - } - if (b[i] != 0){ - return 0; - } - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_cs(char *a, String b){ - return(match_sc(b,a)); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_ss(String a, String b){ - if (a.size != b.size){ - return 0; - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (a.str[i] != b.str[i]){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_ccl(char *a, char *b, i32_4tech *len){ - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (a[i] != b[i]){ - return 0; - } - } - *len = i; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_scl(String a, char *b, i32_4tech *len){ - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (a.str[i] != b[i] || i == a.size){ - return 0; - } - } - *len = i; - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_part_cc(char *a, char *b){ - i32_4tech x; - return match_part_ccl(a,b,&x); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_part_sc(String a, char *b){ - i32_4tech x; - return match_part_scl(a,b,&x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_cs(char *a, String b){ - for (i32_4tech i = 0; i != b.size; ++i){ - if (a[i] != b.str[i]){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_ss(String a, String b){ - if (a.size < b.size){ - return 0; - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (a.str[i] != b.str[i]){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_insensitive_cc(char *a, char *b){ - for (i32_4tech i = 0;; ++i){ - if (char_to_upper(a[i]) != - char_to_upper(b[i])){ - return 0; - } - if (a[i] == 0){ - return 1; - } - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_insensitive_sc(String a, char *b){ - i32_4tech i = 0; - for (; i < a.size; ++i){ - if (char_to_upper(a.str[i]) != - char_to_upper(b[i])){ - return 0; - } - } - if (b[i] != 0){ - return 0; - } - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_insensitive_cs(char *a, String b){ - return match_insensitive_sc(b,a); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_insensitive_ss(String a, String b){ - if (a.size != b.size){ - return 0; - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (char_to_upper(a.str[i]) != - char_to_upper(b.str[i])){ - return 0; - } - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_insensitive_ccl(char *a, char *b, i32_4tech *len){ - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (char_to_upper(a[i]) != char_to_upper(b[i])){ - return 0; - } - } - *len = i; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_insensitive_scl(String a, char *b, i32_4tech *len){ - i32_4tech i; - for (i = 0; b[i] != 0; ++i){ - if (char_to_upper(a.str[i]) != char_to_upper(b[i]) || - i == a.size){ - return 0; - } - } - *len = i; - return 1; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_part_insensitive_cc(char *a, char *b){ - i32_4tech x; - return match_part_insensitive_ccl(a,b,&x); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -match_part_insensitive_sc(String a, char *b){ - i32_4tech x; - return match_part_insensitive_scl(a,b,&x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_insensitive_cs(char *a, String b){ - for (i32_4tech i = 0; i != b.size; ++i){ - if (char_to_upper(a[i]) != char_to_upper(b.str[i])){ - return(0); - } - } - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -match_part_insensitive_ss(String a, String b){ - if (a.size < b.size){ - return(0); - } - for (i32_4tech i = 0; i < b.size; ++i){ - if (char_to_upper(a.str[i]) != char_to_upper(b.str[i])){ - return(0); - } - } - return(1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -compare_cc(char *a, char *b){ - i32_4tech i = 0, r = 0; - while (a[i] == b[i] && a[i] != 0){ - ++i; - } - r = (a[i] > b[i]) - (a[i] < b[i]); - return(r); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -compare_sc(String a, char *b){ - i32_4tech i = 0, r = 0; - while (i < a.size && a.str[i] == b[i]){ - ++i; - } - if (i < a.size){ - r = (a.str[i] > b[i]) - (a.str[i] < b[i]); - } - else{ - if (b[i] == 0){ - r = 0; - } - else{ - r = -1; - } - } - return(r); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech -compare_cs(char *a, String b){ - i32_4tech r = -compare_sc(b,a); - return(r); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -compare_ss(String a, String b){ - i32_4tech i = 0, r = 0; - i32_4tech m = a.size; - if (b.size < m){ - m = b.size; - } - while (i < m && a.str[i] == b.str[i]){ - ++i; - } - - if (i < m){ - r = (a.str[i] > b.str[i]) - (b.str[i] > a.str[i]); - } - else{ - r = (a.size > b.size) - (b.size > a.size); - } - - return(r); -} -#endif - -// -// Finding Characters and Substrings -// - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_c_char(char *str, i32_4tech start, char character){ - i32_4tech i = start; - while (str[i] != character && str[i] != 0) ++i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_s_char(String str, i32_4tech start, char character){ - i32_4tech i = start; - while (i < str.size && str.str[i] != character) ++i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -rfind_s_char(String str, i32_4tech start, char character){ - i32_4tech i = start; - while (i >= 0 && str.str[i] != character) --i; - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_c_chars(char *str, i32_4tech start, char *characters){ - i32_4tech i = start, j; - while (str[i] != 0){ - for (j = 0; characters[j]; ++j){ - if (str[i] == characters[j]){ - return(i); - } - } - ++i; - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_s_chars(String str, i32_4tech start, char *characters){ - i32_4tech i = start, j; - while (i < str.size){ - for (j = 0; characters[j]; ++j){ - if (str.str[i] == characters[j]){ - return(i); - } - } - ++i; - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_substr_c(char *str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - i = str_size(str); - return(i); - } - for (i = start; str[i]; ++i){ - if (str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return(i); - } - } - } - return(i); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_substr_s(String str, i32_4tech start, String seek){ - i32_4tech stop_at, i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - return str.size; - } - stop_at = str.size - seek.size + 1; - for (i = start; i < stop_at; ++i){ - if (str.str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str.str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return(str.size); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -rfind_substr_s(String str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; - - if (seek.size == 0){ - return -1; - } - if (start + seek.size > str.size){ - start = str.size - seek.size; - } - for (i = start; i >= 0; --i){ - if (str.str[i] == seek.str[0]){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - if (str.str[k] != seek.str[j]){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return -1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_substr_insensitive_c(char *str, i32_4tech start, String seek){ - i32_4tech i, j, k; - b32_4tech hit; - char a_upper, b_upper; - char first_test_char; - - if (seek.size == 0){ - return str_size(str); - } - first_test_char = char_to_upper(seek.str[0]); - for (i = start; str[i]; ++i){ - a_upper = char_to_upper(str[i]); - if (a_upper == first_test_char){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - a_upper = char_to_upper(str[k]); - b_upper = char_to_upper(seek.str[j]); - if (a_upper != b_upper){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return i; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -find_substr_insensitive_s(String str, i32_4tech start, String seek){ - i32_4tech i, j, k; - i32_4tech stop_at; - b32_4tech hit; - char a_upper, b_upper; - char first_test_char; - - if (seek.size == 0){ - return str.size; - } - stop_at = str.size - seek.size + 1; - first_test_char = char_to_upper(seek.str[0]); - for (i = start; i < stop_at; ++i){ - a_upper = char_to_upper(str.str[i]); - if (a_upper == first_test_char){ - hit = 1; - for (j = 1, k = i+1; j < seek.size; ++j, ++k){ - a_upper = char_to_upper(str.str[k]); - b_upper = char_to_upper(seek.str[j]); - if (a_upper != b_upper){ - hit = 0; - break; - } - } - if (hit){ - return i; - } - } - } - return str.size; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -has_substr_c(char *s, String seek){ - return (s[find_substr_c(s, 0, seek)] != 0); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -has_substr_s(String s, String seek){ - return (find_substr_s(s, 0, seek) < s.size); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -has_substr_insensitive_c(char *s, String seek){ - return (s[find_substr_insensitive_c(s, 0, seek)] != 0); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -has_substr_insensitive_s(String s, String seek){ - return (find_substr_insensitive_s(s, 0, seek) < s.size); -} -#endif - -// -// String Copies and Appends -// - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -copy_fast_unsafe_cc(char *dest, char *src){ - char *start = dest; - while (*src != 0){ - *dest = *src; - ++dest; - ++src; - } - return (i32_4tech)(dest - start); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -copy_fast_unsafe_cs(char *dest, String src){ - i32_4tech i = 0; - while (i != src.size){ - dest[i] = src.str[i]; - ++i; - } - return(src.size); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_checked_ss(String *dest, String src){ - char *dest_str; - i32_4tech i; - if (dest->memory_size < src.size){ - return 0; - } - dest_str = dest->str; - for (i = 0; i < src.size; ++i){ - dest_str[i] = src.str[i]; - } - dest->size = src.size; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_checked_cs(char *dest, i32_4tech dest_cap, String src){ - i32_4tech i; - if (dest_cap < src.size){ - return 0; - } - for (i = 0; i < src.size; ++i){ - dest[i] = src.str[i]; - } - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_partial_sc(String *dest, char *src){ - i32_4tech i = 0; - i32_4tech memory_size = dest->memory_size; - char *dest_str = dest->str; - while (src[i] != 0){ - if (i >= memory_size){ - return 0; - } - dest_str[i] = src[i]; - ++i; - } - dest->size = i; - return 1; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_partial_ss(String *dest, String src){ - char *dest_str = dest->str; - i32_4tech memory_size = dest->memory_size; - b32_4tech result = 0; - if (memory_size >= src.size){ - result = 1; - memory_size = src.size; - } - for (i32_4tech i = 0; i < memory_size; ++i){ - dest_str[i] = src.str[i]; - } - dest->size = memory_size; - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -copy_partial_cs(char *dest, i32_4tech dest_cap, String src){ - b32_4tech result = 0; - i32_4tech copy_size = dest_cap; - i32_4tech i; - if (dest_cap >= src.size){ - result = 1; - copy_size = src.size; - } - for (i = 0; i < copy_size; ++i){ - dest[i] = src.str[i]; - } - return(result); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech -copy_cc(char *dest, char *src){ - return copy_fast_unsafe_cc(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE void -copy_ss(String *dest, String src){ - copy_checked_ss(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE void -copy_sc(String *dest, char *src){ - copy_partial_sc(dest, src); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_checked_ss(String *dest, String src){ - String end; - end = tailstr(*dest); - b32_4tech result = copy_checked_ss(&end, src); - // NOTE(allen): This depends on end.size still being 0 if - // the check failed and no coppy occurred. - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_partial_sc(String *dest, char *src){ - String end = tailstr(*dest); - b32_4tech result = copy_partial_sc(&end, src); - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_partial_ss(String *dest, String src){ - String end = tailstr(*dest); - b32_4tech result = copy_partial_ss(&end, src); - dest->size += end.size; - return result; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_s_char(String *dest, char c){ - b32_4tech result = 0; - if (dest->size < dest->memory_size){ - dest->str[dest->size++] = c; - result = 1; - } - return result; -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -append_ss(String *dest, String src){ - return append_partial_ss(dest, src); -} -#endif - - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE b32_4tech -append_sc(String *dest, char *src){ - return append_partial_sc(dest, src); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -terminate_with_null(String *str){ - b32_4tech result = 0; - if (str->size < str->memory_size){ - str->str[str->size] = 0; - result = 1; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_padding(String *dest, char c, i32_4tech target_size){ - b32_4tech result = 1; - i32_4tech offset = target_size - dest->size; - i32_4tech r = 0; - if (offset > 0){ - for (r = 0; r < offset; ++r){ - if (append_s_char(dest, c) == 0){ - result = 0; - break; - } - } - } - return(result); -} -#endif - - -// -// Other Edits -// - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -replace_char(String *str, char replace, char with){ - char *s = str->str; - i32_4tech i = 0; - for (i = 0; i < str->size; ++i, ++s){ - if (*s == replace) *s = with; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_lower_cc(char *src, char *dst){ - for (; *src != 0; ++src){ - *dst++ = char_to_lower(*src); - } - *dst++ = 0; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_lower_ss(String *dst, String src){ - i32_4tech i = 0; - i32_4tech size = src.size; - char *c = src.str; - char *d = dst->str; - - if (dst->memory_size >= size){ - for (; i < size; ++i){ - *d++ = char_to_lower(*c++); - } - dst->size = size; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_lower_s(String *str){ - i32_4tech i = 0; - i32_4tech size = str->size; - char *c = str->str; - for (; i < size; ++c, ++i){ - *c = char_to_lower(*c); - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_upper_cc(char *src, char *dst){ - for (; *src != 0; ++src){ - *dst++ = char_to_upper(*src); - } - *dst++ = 0; -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_upper_ss(String *dst, String src){ - i32_4tech i = 0; - i32_4tech size = src.size; - char *c = src.str; - char *d = dst->str; - - if (dst->memory_size >= size){ - for (; i < size; ++i){ - *d++ = char_to_upper(*c++); - } - dst->size = size; - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_upper_s(String *str){ - i32_4tech i = 0; - i32_4tech size = str->size; - char *c = str->str; - for (; i < size; ++c, ++i){ - *c = char_to_upper(*c); - } -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK void -to_camel_cc(char *src, char *dst){ - char *c, ch; - i32_4tech is_first = 1; - for (c = src; *c != 0; ++c){ - ch = *c; - if (char_is_alpha_numeric_true(ch)){ - if (is_first){ - is_first = 0; - ch = char_to_upper(ch); - } - else{ - ch = char_to_lower(ch); - } - } - else{ - is_first = 1; - } - *dst++ = ch; - } - *dst = 0; -} -#endif - - -// -// String <-> Number Conversions -// - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -int_to_str_size(i32_4tech x){ - i32_4tech size = 1; - if (x < 0){ - size = 2; - } - x /= 10; - while (x != 0){ - x /= 10; - ++size; - } - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -int_to_str(String *dest, i32_4tech x){ - b32_4tech result = 1; - char *str = dest->str; - i32_4tech memory_size = dest->memory_size; - i32_4tech size, i, j; - b32_4tech negative; - - if (x == 0){ - str[0] = '0'; - dest->size = 1; - } - else{ - size = 0; - negative = 0; - if (x < 0){ - negative = 1; - x = -x; - str[size++] = '-'; - } - while (x != 0){ - if (size == memory_size){ - result = 0; - break; - } - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - if (result){ - // NOTE(allen): Start i = 0 if not negative, start i = 1 if is negative because - should not be flipped if it is negative :) - for (i = negative, j = size-1; i < j; ++i, --j){ - char temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - dest->size = size; - } - else{ - dest->size = 0; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_int_to_str(String *dest, i32_4tech x){ - String last_part = tailstr(*dest); - b32_4tech result = int_to_str(&last_part, x); - if (result){ - dest->size += last_part.size; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -u64_to_str_size(uint64_t x){ - i32_4tech size = 1; - x /= 10; - while (x != 0){ - x /= 10; - ++size; - } - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -u64_to_str(String *dest, uint64_t x){ - b32_4tech result = 1; - char *str = dest->str; - i32_4tech memory_size = dest->memory_size; - i32_4tech size, i, j; - - if (x == 0){ - str[0] = '0'; - dest->size = 1; - } - else{ - size = 0; - while (x != 0){ - if (size == memory_size){ - result = 0; - break; - } - i = x % 10; - x /= 10; - str[size++] = (char)('0' + i); - } - if (result){ - for (i = 0, j = size-1; i < j; ++i, --j){ - char temp = str[i]; - str[i] = str[j]; - str[j] = temp; - } - dest->size = size; - } - else{ - dest->size = 0; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_u64_to_str(String *dest, uint64_t x){ - String last_part = tailstr(*dest); - b32_4tech result = u64_to_str(&last_part, x); - if (result){ - dest->size += last_part.size; - } - return(result); -} -#endif - -#if !defined(FSTRING_GUARD) -typedef struct Float_To_Str_Variables{ - b32_4tech negative; - i32_4tech int_part; - i32_4tech dec_part; -} Float_To_Str_Variables; - -static Float_To_Str_Variables -get_float_vars(float x){ - Float_To_Str_Variables vars = {0}; - - if (x < 0){ - vars.negative = 1; - x = -x; - } - - vars.int_part = (i32_4tech)(x); - vars.dec_part = (i32_4tech)((x - vars.int_part) * 1000); - - return(vars); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -float_to_str_size(float x){ - Float_To_Str_Variables vars = get_float_vars(x); - i32_4tech size = vars.negative + int_to_str_size(vars.int_part) + 1 + int_to_str_size(vars.dec_part); - return(size); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -append_float_to_str(String *dest, float x){ - b32_4tech result = 1; - Float_To_Str_Variables vars = get_float_vars(x); - - if (vars.negative){ - append_s_char(dest, '-'); - } - - append_int_to_str(dest, vars.int_part); - append_s_char(dest, '.'); - append_int_to_str(dest, vars.dec_part); - - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -float_to_str(String *dest, float x){ - b32_4tech result = 1; - dest->size = 0; - append_float_to_str(dest, x); - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -str_is_int_c(char *str){ - b32_4tech result = 1; - for (; *str; ++str){ - if (!char_is_numeric(*str)){ - result = 0; - break; - } - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -str_is_int_s(String str){ - b32_4tech result = 1; - for (i32_4tech i = 0; i < str.size; ++i){ - if (!char_is_numeric(str.str[i])){ - result = 0; - break; - } - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -str_to_int_c(char *str){ - i32_4tech x = 0; - for (; *str; ++str){ - if (*str >= '0' && *str <= '9'){ - x *= 10; - x += *str - '0'; - } - else{ - x = 0; - break; - } - } - return(x); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -str_to_int_s(String str){ - i32_4tech x, i; - if (str.size == 0){ - x = 0; - } - else{ - x = str.str[0] - '0'; - for (i = 1; i < str.size; ++i){ - x *= 10; - x += str.str[i] - '0'; - } - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -hexchar_to_int(char c){ - i32_4tech x = 0; - if (c >= '0' && c <= '9'){ - x = c-'0'; - } - else if (c > 'F'){ - x = c+(10-'a'); - } - else{ - x = c+(10-'A'); - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK char -int_to_hexchar(i32_4tech x){ - return (x<10)?((char)x+'0'):((char)x+'a'-10); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK u32_4tech -hexstr_to_int(String str){ - u32_4tech x; - i32_4tech i; - if (str.size == 0){ - x = 0; - } - else{ - x = hexchar_to_int(str.str[0]); - for (i = 1; i < str.size; ++i){ - x *= 0x10; - x += hexchar_to_int(str.str[i]); - } - } - return(x); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -color_to_hexstr(String *s, u32_4tech color){ - b32_4tech result = 0; - i32_4tech i; - - if (s->memory_size == 7 || s->memory_size == 8){ - result = 1; - s->size = 6; - s->str[6] = 0; - color = color & 0x00FFFFFF; - for (i = 5; i >= 0; --i){ - s->str[i] = int_to_hexchar(color & 0xF); - color >>= 4; - } - } - else if (s->memory_size > 8){ - result = 1; - s->size = 8; - s->str[8] = 0; - for (i = 7; i >= 0; --i){ - s->str[i] = int_to_hexchar(color & 0xF); - color >>= 4; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -hexstr_to_color(String s, u32_4tech *out){ - b32_4tech result = 0; - u32_4tech color = 0; - if (s.size == 6){ - result = 1; - color = (u32_4tech)hexstr_to_int(s); - color |= (0xFF << 24); - *out = color; - } - else if (s.size == 8){ - result = 1; - color = (u32_4tech)hexstr_to_int(s); - *out = color; - } - return(result); -} -#endif - -// -// Directory String Management -// - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK i32_4tech -reverse_seek_slash_pos(String str, i32_4tech pos){ - i32_4tech i = str.size - 1 - pos; - while (i >= 0 && !char_is_slash(str.str[i])){ - --i; - } - return i; -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE i32_4tech -reverse_seek_slash(String str){ - return(reverse_seek_slash_pos(str, 0)); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -front_of_directory(String dir){ - return substr_tail(dir, reverse_seek_slash(dir) + 1); -} -#endif - -#if !defined(FSTRING_GUARD) - FSTRING_INLINE String -path_of_directory(String dir){ - return substr(dir, 0, reverse_seek_slash(dir) + 1); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -set_last_folder_sc(String *dir, char *folder_name, char slash){ - b32_4tech result = 0; - i32_4tech size = reverse_seek_slash(*dir) + 1; - dir->size = size; - if (append_sc(dir, folder_name)){ - if (append_s_char(dir, slash)){ - result = 1; - } - } - if (!result){ - dir->size = size; - } - return(result); -} -#endif - - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -set_last_folder_ss(String *dir, String folder_name, char slash){ - b32_4tech result = 0; - i32_4tech size = reverse_seek_slash(*dir) + 1; - dir->size = size; - if (append_ss(dir, folder_name)){ - if (append_s_char(dir, slash)){ - result = 1; - } - } - if (!result){ - dir->size = size; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -file_extension(String str){ - i32_4tech i; - for (i = str.size - 1; i >= 0; --i){ - if (str.str[i] == '.') break; - } - ++i; - return(make_string(str.str+i, str.size-i)); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -remove_extension(String *str){ - b32_4tech result = 0; - i32_4tech i; - for (i = str->size - 1; i >= 0; --i){ - if (str->str[i] == '.') break; - } - if (i >= 0){ - result = 1; - str->size = i + 1; - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -remove_last_folder(String *str){ - b32_4tech result = 0; - i32_4tech end = reverse_seek_slash_pos(*str, 1); - if (end >= 0){ - result = 1; - str->size = end + 1; - } - return(result); -} -#endif - -// TODO(allen): Add hash-table extension to string sets. - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -string_set_match_table(void *str_set, i32_4tech item_size, i32_4tech count, String str, i32_4tech *match_index){ - b32_4tech result = 0; - i32_4tech i = 0; - uint8_t *ptr = (uint8_t*)str_set; - for (; i < count; ++i, ptr += item_size){ - if (match_ss(*(String*)ptr, str)){ - *match_index = i; - result = 1; - break; - } - } - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK b32_4tech -string_set_match(String *str_set, i32_4tech count, String str, i32_4tech *match_index){ - b32_4tech result = string_set_match_table(str_set, sizeof(String), count, str, match_index); - return(result); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -get_first_double_line(String source){ - String line = {0}; - i32_4tech pos0 = find_substr_s(source, 0, make_lit_string("\n\n")); - i32_4tech pos1 = find_substr_s(source, 0, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - line = substr(source, 0, pos0); - return(line); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -get_next_double_line(String source, String line){ - String next = {0}; - i32_4tech pos = (i32_4tech)(line.str - source.str) + line.size; - i32_4tech start = 0, pos0 = 0, pos1 = 0; - - if (pos < source.size){ - //Assert(source.str[pos] == '\n' || source.str[pos] == '\r'); - start = pos + 1; - - if (start < source.size){ - pos0 = find_substr_s(source, start, make_lit_string("\n\n")); - pos1 = find_substr_s(source, start, make_lit_string("\r\n\r\n")); - if (pos1 < pos0){ - pos0 = pos1; - } - next = substr(source, start, pos0 - start); - } - } - - return(next); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -get_next_word(String source, String prev_word){ - - String word = {0}; - i32_4tech pos0 = (i32_4tech)(prev_word.str - source.str) + prev_word.size; - i32_4tech pos1 = 0; - char c = 0; - - for (; pos0 < source.size; ++pos0){ - c = source.str[pos0]; - if (!(char_is_whitespace(c) || c == '(' || c == ')')){ - break; - } - } - - if (pos0 < source.size){ - for (pos1 = pos0; pos1 < source.size; ++pos1){ - c = source.str[pos1]; - if (char_is_whitespace(c) || c == '(' || c == ')'){ - break; - } - } - - word = substr(source, pos0, pos1 - pos0); - } - - return(word); -} -#endif - -#if defined(FSTRING_IMPLEMENTATION) - FSTRING_LINK String -get_first_word(String source){ - String start_str = make_string(source.str, 0); - String word = get_next_word(source, start_str); - return(word); -} -#endif - -// TODO(allen): eliminate this. -#ifndef FSTRING_EXPERIMENTAL -#define FSTRING_EXPERIMENTAL - -// NOTE(allen): experimental section, things below here are -// not promoted to public API level yet. - -typedef struct Absolutes{ - String a[8]; - i32_4tech count; -} Absolutes; - -static void -get_absolutes(String name, Absolutes *absolutes, b32_4tech implicit_first, b32_4tech implicit_last){ - if (name.size != 0){ - i32_4tech count = 0; - i32_4tech max = (sizeof(absolutes->a)/sizeof(*absolutes->a)) - 1; - if (implicit_last) --max; - - String str; - str.str = name.str; - str.size = 0; - str.memory_size = 0; - b32_4tech prev_was_wild = 0; - - if (implicit_first){ - absolutes->a[count++] = str; - prev_was_wild = 1; - } - - i32_4tech i; - for (i = 0; i < name.size; ++i){ - if (name.str[i] == '*' && count < max){ - if (!prev_was_wild){ - str.memory_size = str.size; - absolutes->a[count++] = str; - str.size = 0; - } - str.str = name.str + i + 1; - prev_was_wild = 1; - } - else{ - ++str.size; - prev_was_wild = 0; - } - } - - str.memory_size = str.size; - absolutes->a[count++] = str; - - if (implicit_last){ - str.size = 0; - str.memory_size = 0; - absolutes->a[count++] = str; - } - - absolutes->count = count; - } - else{ - absolutes->count = 0; - } -} - -static b32_4tech -wildcard_match_c(Absolutes *absolutes, char *x, i32_4tech case_sensitive){ - b32_4tech r = 1; - - if (absolutes->count > 0){ - String *a = absolutes->a; - - b32_4tech (*match_func)(char*, String); - b32_4tech (*match_part_func)(char*, String); - - if (case_sensitive){ - match_func = match_cs; - match_part_func = match_part_cs; - } - else{ - match_func = match_insensitive_cs; - match_part_func = match_part_insensitive_cs; - } - - if (absolutes->count == 1){ - r = match_func(x, *a); - } - else{ - if (!match_part_func(x, *a)){ - r = 0; - } - else{ - String *max = a + absolutes->count - 1; - x += a->size; - ++a; - while (a < max){ - if (*x == 0){ - r = 0; - break; - } - if (match_part_func(x, *a)){ - x += a->size; - ++a; - } - else{ - ++x; - } - } - if (r && a->size > 0){ - r = 0; - while (*x != 0){ - if (match_part_func(x, *a) && *(x + a->size) == 0){ - r = 1; - break; - } - else{ - ++x; - } - } - } - } - } - } - return(r); -} - -static b32_4tech -wildcard_match_s(Absolutes *absolutes, String x, i32_4tech case_sensitive){ - terminate_with_null(&x); - return(wildcard_match_c(absolutes, x.str, case_sensitive)); -} - -#endif - -#if defined(FSTRING_IMPLEMENTATION) -#undef FSTRING_IMPLEMENTATION -#define FSTRING_IMPL_GUARD -#endif - -#if !defined(FSTRING_GUARD) -#define FSTRING_GUARD -#endif - -// BOTTOM - diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt index 5e3d1b74..f92a4013 100644 --- a/string/4coder_string_build_num.txt +++ b/string/4coder_string_build_num.txt @@ -1,5 +1,5 @@ 1 0 -87 +88 diff --git a/string/4ed_string_builder.cpp b/string/4ed_string_builder.cpp index 7bdba67f..3c1e5d9b 100644 --- a/string/4ed_string_builder.cpp +++ b/string/4ed_string_builder.cpp @@ -1,20 +1,15 @@ /* -Builder for the 4coder_string.h header. -By Allen Webster -Created 21.01.2017 (dd.mm.yyyy) -*/ + * Mr. 4th Dimention - Allen Webster + * + * 21.01.2017 + * + * Builder for the 4coder_string.h header. + * + */ // TOP -#include "../4cpp/4cpp_lexer.h" // TODO(allen): Make sure to only publish the 4coder_string.h if it builds and passes a series of tests. -#define FSTRING_IMPLEMENTATION -#include "../4coder_lib/4coder_string.h" - -#include "../4ed_defines.h" -#include "../meta/4ed_meta_defines.h" -#include "../meta/4ed_file_moving.h" - #define BUILD_NUMBER_FILE "4coder_string_build_num.txt" @@ -24,22 +19,29 @@ Created 21.01.2017 (dd.mm.yyyy) #define BACKUP_FOLDER ".." SLASH ".." SLASH "string_backup" #define PUBLISH_FOLDER ".." SLASH "4coder_helper" +#include "../4cpp/4cpp_lexer.h" +#define FSTRING_IMPLEMENTATION +#include "../4coder_lib/4coder_string.h" + +#include "../4ed_defines.h" +#include "../meta/4ed_meta_defines.h" +#include "../meta/4ed_file_moving.h" + +#include "../4coder_lib/4coder_mem.h" + +#include "../meta/4ed_meta_parser.cpp" +#include "../meta/4ed_out_context.cpp" #include #include #include -#include "../4coder_lib/4coder_mem.h" - #define V_MAJ_NUM 1 #define V_MIN_NUM 0 #define V_MAJ STR_(V_MAJ_NUM) #define V_MIN STR_(V_MIN_NUM) -#include "../meta/4ed_meta_parser.cpp" -#include "../meta/4ed_out_context.cpp" - static b32 parse_build_number(char *file_name, i32 *major_out, i32 *minor_out, i32 *build_out){ b32 result = false; @@ -162,6 +164,7 @@ file_move(char *path, char *file_name){ int main(){ META_BEGIN(); + fm_init_system(); i32 size = (512 << 20); void *mem = malloc(size); From 8791fe28a5afae59ebb8a15f68f41284392609e2 Mon Sep 17 00:00:00 2001 From: Allen Webster Date: Sun, 9 Jul 2017 15:49:41 -0400 Subject: [PATCH 5/5] got string builder working through the primary build.cpp --- build_string.bat | 34 ++++++++++++++++-------------- meta/4ed_build.cpp | 24 ++++++++++++++++++++- string/4coder_string_build_num.txt | 2 +- string/4ed_string_builder.cpp | 2 -- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/build_string.bat b/build_string.bat index d4299d9d..ec550bbf 100644 --- a/build_string.bat +++ b/build_string.bat @@ -1,19 +1,21 @@ @echo off -SET OPTS=-W4 -wd4310 -wd4100 -wd4201 -wd4505 -wd4996 -wd4127 -wd4510 -wd4512 -wd4610 -wd4390 -WX -SET OPTS=%OPTS% -wd4611 -GR- -EHa- -nologo -FC +build.bat /DSTRING_BUILD -SET FirstError=0 - -pushd ..\build -cl %OPTS% ..\code\string\4ed_string_builder.cpp /Zi /Festring_builder -if %ERRORLEVEL% neq 0 (set FirstError=1) -if %ERRORLEVEL% neq 0 (goto END) -popd - -pushd string -..\..\build\string_builder -if %ERRORLEVEL% neq 0 (set FirstError=1) -popd - -:END +REM SET OPTS=-W4 -wd4310 -wd4100 -wd4201 -wd4505 -wd4996 -wd4127 -wd4510 -wd4512 -wd4610 -wd4390 -WX +REM SET OPTS=%OPTS% -wd4611 -GR- -EHa- -nologo -FC +REM +REM SET FirstError=0 +REM +REM pushd ..\build +REM cl %OPTS% ..\code\string\4ed_string_builder.cpp /Zi /Festring_builder +REM if %ERRORLEVEL% neq 0 (set FirstError=1) +REM if %ERRORLEVEL% neq 0 (goto END) +REM popd +REM +REM pushd string +REM ..\..\build\string_builder +REM if %ERRORLEVEL% neq 0 (set FirstError=1) +REM popd +REM +REM :END diff --git a/meta/4ed_build.cpp b/meta/4ed_build.cpp index 846c1c1c..6dc29981 100644 --- a/meta/4ed_build.cpp +++ b/meta/4ed_build.cpp @@ -430,7 +430,7 @@ site_build(char *cdir, u32 flags){ END_TIME_SECTION("build sitegen"); } - { + if (prev_error == 0){ BEGIN_TIME_SECTION(); char *cmd = fm_str(BUILD_DIR"/sitegen"); char *code_dir = fm_str("."); @@ -472,6 +472,25 @@ metagen(char *cdir){ build_and_run(cdir, "meta/4ed_metagen.cpp", "metagen", OPTS | DEBUG_INFO); } +internal void +string_build(char *cdir){ + char *dir = fm_str(BUILD_DIR); + + { + char *file = fm_str("string/4ed_string_builder.cpp"); + BEGIN_TIME_SECTION(); + build(OPTS | DEBUG_INFO, Arch_X64, cdir, file, dir, "string_builder", 0, 0, includes); + END_TIME_SECTION("build string_builder"); + } + + if (prev_error == 0){ + char *cmd = fm_str(cdir, "/", dir, "/string_builder"); + BEGIN_TIME_SECTION(); + fm_execute_in_dir(fm_str(cdir, "/string"), cmd, 0); + END_TIME_SECTION("run string_builder"); + } +} + internal void do_buildsuper(char *cdir, char *file, u32 arch){ BEGIN_TIME_SECTION(); @@ -668,6 +687,9 @@ int main(int argc, char **argv){ #elif defined(SITE_BUILD) site_build(cdir, DEBUG_INFO); +#elif defined(STRING_BUILD) + string_build(cdir); + #else # error No build type specified. #endif diff --git a/string/4coder_string_build_num.txt b/string/4coder_string_build_num.txt index f92a4013..89534ae9 100644 --- a/string/4coder_string_build_num.txt +++ b/string/4coder_string_build_num.txt @@ -1,5 +1,5 @@ 1 0 -88 +91 diff --git a/string/4ed_string_builder.cpp b/string/4ed_string_builder.cpp index 3c1e5d9b..1947dc5a 100644 --- a/string/4ed_string_builder.cpp +++ b/string/4ed_string_builder.cpp @@ -281,8 +281,6 @@ int main(){ Item_Node *item = string_unit.set.items + j; if (item->t == Item_Function){ - //append_ss (&line, item->marker); - //append_padding (&line, ' ', RETURN_PADDING); append_ss (&line, item->ret); append_padding (&line, ' ', SIG_PADDING); append_ss (&line, item->name);