diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..02e08ad --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +[*.md] +indent_style = tab +indent_size = 4 + +[*.c] +indent_style = tab +indent_size = 4 + +[*.cpp] +indent_style = tab +indent_size = 4 diff --git a/Test/bloat.hpp b/Test/bloat.hpp index 3ae2c95..39429e4 100644 --- a/Test/bloat.hpp +++ b/Test/bloat.hpp @@ -97,8 +97,39 @@ namespace Memory } } -void fatal() -{ - Memory::cleanup(); - assert_crash("FATAL"); + sw log_fmt(char const *fmt, ...) + { +#if Build_Debug + sw res; + va_list va; + va_start(va, fmt); + res = zpl_printf_va(fmt, va); + va_end(va); + return res; + +#else + return 0; +#endif +} + +void fatal(char const *fmt, ...) +{ + local_persist thread_local + char buf[ZPL_PRINTF_MAXLEN] = { 0 }; + + va_list va; + +#if Build_Debug + va_start(va, fmt); + zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va); + va_end(va); + + assert_crash(buf); +#else + va_start(va, fmt); + zpl_printf_err_va( fmt, va); + va_end(va); + + exit(1); +#endif } diff --git a/Test/refactor.cpp b/Test/refactor.cpp index f3ab269..d5fa00c 100644 --- a/Test/refactor.cpp +++ b/Test/refactor.cpp @@ -6,10 +6,8 @@ namespace File { string Source = nullptr; string Destination = nullptr; - file_contents Content {}; - - zpl_arena Buffer; + zpl_arena Buffer; void cleanup() { @@ -43,8 +41,7 @@ namespace File if ( Content.data == nullptr ) { - zpl_printf( "Unable to open source file: %s\n", Source ); - fatal(); + fatal( "Unable to open source file: %s\n", Source ); } } @@ -58,8 +55,7 @@ namespace File if ( error != ZPL_FILE_ERROR_NONE ) { - zpl_printf( "Unable to open destination file: %s\n", Destination ); - fatal(); + fatal( "Unable to open destination file: %s\n", Destination ); } file_write( & file_dest, refactored, string_length(refactored) ); @@ -147,8 +143,7 @@ namespace Spec if ( length == 0 ) { - zpl_printf("Failed to find valid initial token"); - fatal(); + fatal("Failed to find valid initial token"); } token = string_append_length( token, line, length ); @@ -163,21 +158,19 @@ namespace Spec // Get the contents of the file. { - zpl_file file {}; + zpl_file file {}; file_error error = file_open( & file, File); if ( error != ZPL_FILE_ERROR_NONE ) { - zpl_printf("Could not open the specification file: %s", File); - fatal(); + fatal("Could not open the specification file: %s", File); } sw fsize = scast( sw, file_size( & file ) ); if ( fsize <= 0 ) { - zpl_printf("No content in specificaiton to process"); - fatal(); + fatal("No content in specificaiton to process"); } arena_init_from_allocator( & Buffer, heap(), (fsize + fsize % 64) * 10 + kilobytes(1) ); @@ -197,8 +190,7 @@ namespace Spec if ( left == 0 ) { - zpl_printf("Spec::process: lines array imporoperly setup"); - fatal(); + fatal("Spec::process: lines array imporoperly setup"); } // Skip the first line as its the version number and we only support __VERSION 1. @@ -404,7 +396,7 @@ namespace Spec } } - zpl_printf("Specification Line: %d is missing valid keyword", array_count(lines) - left); + log_fmt("Specification Line: %d is missing valid keyword", array_count(lines) - left); lines++; } } @@ -465,12 +457,6 @@ void refactor() u32 sig_length = string_length( ignore->Sig ); current = string_append_length( current, content, sig_length ); - // bool match = false; - // if ( str_compare( "zpl_printf", current, sig_length ) == 0 ) - // { - // match = true; - // } - if ( string_are_equal( ignore->Sig, current ) ) { char after = content[sig_length]; @@ -480,7 +466,7 @@ void refactor() continue; } - zpl_printf("\nIgnored %-81s line %d", current, line ); + log_fmt("\nIgnored %-81s line %d", current, line ); content += sig_length; left -= sig_length; @@ -521,7 +507,7 @@ void refactor() string_clear( preview ); preview = string_append_length( preview, content, length ); - zpl_printf("\nIgnored %-40s %-40s line %d", preview, ignore->Sig, line); + log_fmt("\nIgnored %-40s %-40s line %d", preview, ignore->Sig, line); content += length; left -= length; @@ -572,7 +558,7 @@ void refactor() array_append( tokens, entry ); - zpl_printf("\nFound %-81s line %d", current, line); + log_fmt("\nFound %-81s line %d", current, line); content += sig_length; left -= sig_length; @@ -629,7 +615,7 @@ void refactor() string_clear( preview ); preview = string_append_length( preview, content, length); - zpl_printf("\nFound %-40s %-40s line %d", preview, nspace->Sig, line); + log_fmt("\nFound %-40s %-40s line %d", preview, nspace->Sig, line); content += length; left -= length; @@ -722,8 +708,7 @@ void parse_options( int num, char** arguments ) } else { - zpl_printf( "-source not provided\n" ); - fatal(); + fatal( "-source not provided\n" ); } if ( opts_has_arg( & opts, "dst" ) ) @@ -749,8 +734,7 @@ void parse_options( int num, char** arguments ) } else { - zpl_printf( "Failed to parse arguments\n" ); - fatal(); + fatal( "Failed to parse arguments\n" ); } opts_free( & opts); diff --git a/bloat.hpp b/bloat.hpp index 70d5c01..f558efb 100644 --- a/bloat.hpp +++ b/bloat.hpp @@ -108,8 +108,39 @@ namespace Memory } } -void fatal() -{ - Memory::cleanup(); - zpl_assert_crash("FATAL"); + sw log_fmt(char const *fmt, ...) + { +#if Build_Debug + sw res; + va_list va; + va_start(va, fmt); + res = zpl_printf_va(fmt, va); + va_end(va); + return res; + +#else + return 0; +#endif +} + +void fatal(char const *fmt, ...) +{ + zpl_local_persist zpl_thread_local + char buf[ZPL_PRINTF_MAXLEN] = { 0 }; + + va_list va; + +#if Build_Debug + va_start(va, fmt); + zpl_snprintf_va(buf, ZPL_PRINTF_MAXLEN, fmt, va); + va_end(va); + + zpl_assert_crash(buf); +#else + va_start(va, fmt); + zpl_printf_err_va( fmt, va); + va_end(va); + + exit(1); +#endif } diff --git a/refactor.cpp b/refactor.cpp index 176bf58..a787ba9 100644 --- a/refactor.cpp +++ b/refactor.cpp @@ -43,8 +43,7 @@ namespace File if ( Content.data == nullptr ) { - zpl_printf( "Unable to open source file: %s\n", Source ); - fatal(); + fatal( "Unable to open source file: %s\n", Source ); } } @@ -58,8 +57,7 @@ namespace File if ( error != ZPL_FILE_ERROR_NONE ) { - zpl_printf( "Unable to open destination file: %s\n", Destination ); - fatal(); + fatal( "Unable to open destination file: %s\n", Destination ); } zpl_file_write( & file_dest, refactored, zpl_string_length(refactored) ); @@ -147,8 +145,7 @@ namespace Spec if ( length == 0 ) { - zpl_printf("Failed to find valid initial token"); - fatal(); + fatal("Failed to find valid initial token"); } token = zpl_string_append_length( token, line, length ); @@ -168,16 +165,14 @@ namespace Spec if ( error != ZPL_FILE_ERROR_NONE ) { - zpl_printf("Could not open the specification file: %s", File); - fatal(); + fatal("Could not open the specification file: %s", File); } sw fsize = scast( sw, zpl_file_size( & file ) ); if ( fsize <= 0 ) { - zpl_printf("No content in specificaiton to process"); - fatal(); + fatal("No content in specificaiton to process"); } zpl_arena_init_from_allocator( & Buffer, zpl_heap(), (fsize + fsize % 64) * 10 + zpl_kilobytes(1) ); @@ -197,8 +192,7 @@ namespace Spec if ( left == 0 ) { - zpl_printf("Spec::process: lines array imporoperly setup"); - fatal(); + fatal("Spec::process: lines array imporoperly setup"); } // Skip the first line as its the version number and we only support __VERSION 1. @@ -404,7 +398,7 @@ namespace Spec } } - zpl_printf("Specification Line: %d is missing valid keyword", zpl_array_count(lines) - left); + log_fmt("Specification Line: %d is missing valid keyword", zpl_array_count(lines) - left); lines++; } } @@ -465,12 +459,6 @@ void refactor() u32 sig_length = zpl_string_length( ignore->Sig ); current = zpl_string_append_length( current, content, sig_length ); - // bool match = false; - // if ( zpl_strncmp( "zpl_printf", current, sig_length ) == 0 ) - // { - // match = true; - // } - if ( zpl_string_are_equal( ignore->Sig, current ) ) { char before = content[-1]; @@ -482,7 +470,7 @@ void refactor() continue; } - zpl_printf("\nIgnored %-81s line %d", current, line ); + log_fmt("\nIgnored %-81s line %d", current, line ); content += sig_length; left -= sig_length; @@ -523,7 +511,7 @@ void refactor() zpl_string_clear( preview ); preview = zpl_string_append_length( preview, content, length ); - zpl_printf("\nIgnored %-40s %-40s line %d", preview, ignore->Sig, line); + log_fmt("\nIgnored %-40s %-40s line %d", preview, ignore->Sig, line); content += length; left -= length; @@ -576,7 +564,7 @@ void refactor() zpl_array_append( tokens, entry ); - zpl_printf("\nFound %-81s line %d", current, line); + log_fmt("\nFound %-81s line %d", current, line); content += sig_length; left -= sig_length; @@ -633,7 +621,7 @@ void refactor() zpl_string_clear( preview ); preview = zpl_string_append_length( preview, content, length); - zpl_printf("\nFound %-40s %-40s line %d", preview, nspace->Sig, line); + log_fmt("\nFound %-40s %-40s line %d", preview, nspace->Sig, line); content += length; left -= length; @@ -726,8 +714,7 @@ void parse_options( int num, char** arguments ) } else { - zpl_printf( "-source not provided\n" ); - fatal(); + fatal( "-source not provided\n" ); } if ( zpl_opts_has_arg( & opts, "dst" ) ) @@ -753,8 +740,7 @@ void parse_options( int num, char** arguments ) } else { - zpl_printf( "Failed to parse arguments\n" ); - fatal(); + fatal( "Failed to parse arguments\n" ); } zpl_opts_free( & opts);