mirror of
https://github.com/mattiasgustavsson/libs.git
synced 2026-11-30 16:48:22 +01:00
Added more libs, updated readme
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
[](https://ko-fi.com/W7W1B1W7)
|
||||
|
||||
# libs
|
||||
Single-file public domain libraries for C/C++ (dual licensed under MIT).
|
||||
|
||||
@@ -12,3 +10,37 @@ Single-file public domain libraries for C/C++ (dual licensed under MIT).
|
||||
* [strpool.h](docs/strpool.md) - Highly efficient string pool for C/C++.
|
||||
* [thread.h](docs/thread.md) - Cross platform threading functions for C/C++.
|
||||
|
||||
|
||||
# wip libs
|
||||
More libs, work-in-progress, some are unfinished, some are complete but lacking documentation.
|
||||
|
||||
* array.h - Dynamic array library for C/C++.
|
||||
* buffer.h - Memory buffer with read/write operations, for C/C++.
|
||||
* crtemu.h - Cathode ray tube emulation shader for C/C++.
|
||||
* cstr.h - String interning and manipulation library for C/C++.
|
||||
* dialog.h - Loading and management of dialogs for a custom game dialog system.
|
||||
* dir.h - Directory listing functions for C/C++.
|
||||
* frametimer.h - Framerate timer functionality, for C/C++.
|
||||
* id3tag.h - Read/write ID3 tags from/to mp3 files in C/C++.
|
||||
* img.h - Image processing functions for C/C++.
|
||||
* mus.h - Parsing library for MUS music files (as used in DOS games).
|
||||
* paldither.h - Convert true-color image to custom palette, with dither.
|
||||
* palettize.h - Median-cut palette generation and remapping for C/C++.
|
||||
* palrle.h - Run-length encoding of palettized bitmaps, for C/C++.
|
||||
* pixelfont.h - Custom pixel font format builder and renderer.
|
||||
* sysfont.h - Simple debug text renderer for C/C++.
|
||||
* testfw.h - Basic test framework for C/C++.
|
||||
|
||||
|
||||
# repackaged libs
|
||||
Single-file header-only versions of libs written by other people, released under the same license as the original lib.
|
||||
I recommend using the latest version of these libs - I only repackage them like this to fit my single-file-libs centered
|
||||
dev paradigm, and if you don't absolutely need that, you are better off using the original multi-file versions.
|
||||
|
||||
* ftplib.h - FTP client lib for C/C++. *By Thomas Pfau.*
|
||||
* hoedown.h - Markdown to HTML renderer for C/C++. *By Porte/Marti/Mendez/Torres.*
|
||||
* libxdiff.h - File Differential Library. *By Davide Libenzi.*
|
||||
* lzma.h - LZMA data compression/decompression library. *By Igor Pavlov.*
|
||||
* opl.h - OPL3 (SoundBlaster16) emulation with MIDI compatible interface. *Based on code by Aaron Giles and Mateusz Viste*
|
||||
* samplerate.h - Sample-rate converter (libsamplerate) for C/C++. *By Erik de Castro Lopo*
|
||||
* speech.h - Very basic text-to-speech synthesizer library for C/C++. *By Jari Komppa / Nick Ing-Simmons (et al)*
|
||||
|
||||
@@ -25,7 +25,7 @@ before you include this file in *one* C/C++ file to create the implementation.
|
||||
#define array_create( type ) ARRAY_CAST( (void*)internal_array_create( sizeof( type ), NULL ) )
|
||||
#define array_create_memctx( type, memctx ) ARRAY_CAST( (void*)internal_array_create( sizeof( type ), (memctx) ) )
|
||||
#define array_destroy( array ) internal_array_destroy( (struct internal_array_t*) (array) )
|
||||
#define array_add( array, item ) ARRAY_CAST( internal_array_add( (struct internal_array_t*) (array), (void*) (item) ) )
|
||||
#define array_add( array, item ) ARRAY_CAST( internal_array_add( (struct internal_array_t*) (array), (void*) (item), (int)sizeof( *item ) ) )
|
||||
#define array_remove( array, index ) internal_array_remove( (struct internal_array_t*) (array), (index) )
|
||||
#define array_remove_ordered( array, index ) internal_array_remove_ordered( (struct internal_array_t*) (array), (index) )
|
||||
#define array_get( array, index, item ) internal_array_get( (struct internal_array_t*) (array), (index), (void*) (item) )
|
||||
@@ -71,7 +71,7 @@ struct internal_array_t;
|
||||
|
||||
struct internal_array_t* internal_array_create( int item_size, void* memctx );
|
||||
void internal_array_destroy( struct internal_array_t* array );
|
||||
void* internal_array_add( struct internal_array_t* array, void* item );
|
||||
void* internal_array_add( struct internal_array_t* array, void* item, int item_size );
|
||||
void internal_array_remove( struct internal_array_t* array, int index );
|
||||
void internal_array_remove_ordered( struct internal_array_t* array, int index );
|
||||
ARRAY_BOOL_T internal_array_get( struct internal_array_t* array, int index, void* item );
|
||||
@@ -94,6 +94,12 @@ void* internal_array_item( struct internal_array_t* array, int index );
|
||||
#ifdef ARRAY_IMPLEMENTATION
|
||||
#undef ARRAY_IMPLEMENTATION
|
||||
|
||||
#ifndef ARRAY_ASSERT
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <assert.h>
|
||||
#define ARRAY_ASSERT( condition, message ) assert( condition && message );
|
||||
#endif
|
||||
|
||||
#ifndef ARRAY_MALLOC
|
||||
#define _CRT_NONSTDC_NO_DEPRECATE
|
||||
@@ -165,7 +171,8 @@ void internal_array_destroy( struct internal_array_t* array ) {
|
||||
}
|
||||
|
||||
|
||||
void* internal_array_add( struct internal_array_t* array, void* item ) {
|
||||
void* internal_array_add( struct internal_array_t* array, void* item, int item_size ) {
|
||||
ARRAY_ASSERT( item_size == array->item_size, "Invalid item" );
|
||||
if( array->count >= array->capacity ) {
|
||||
array->capacity *= 2;
|
||||
void* items = array->items;
|
||||
|
||||
+368215
File diff suppressed because it is too large
Load Diff
@@ -3,7 +3,7 @@
|
||||
Licensing information can be found at the end of the file.
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
testfw.h - v1.1 - Basic test framwework for C/C++.
|
||||
testfw.h - v1.1 - Basic test framework for C/C++.
|
||||
|
||||
Do this:
|
||||
#define TESTFW_IMPLEMENTATION
|
||||
@@ -15,26 +15,32 @@ before you include this file in *one* C/C++ file to create the implementation.
|
||||
|
||||
#define TESTFW_INIT() testfw_init()
|
||||
#define TESTFW_SUMMARY() testfw_summary( __FILE__, __func__, __LINE__ )
|
||||
#if defined( _WIN32 ) && !defined( TESTFW_NO_SEH )
|
||||
#if defined( _WIN32 ) && !defined( TESTFW_NO_SEH ) && !defined( __TINYC__ )
|
||||
#if defined __cplusplus
|
||||
extern "C" unsigned long __cdecl _exception_code(void);
|
||||
#else
|
||||
unsigned long __cdecl _exception_code(void);
|
||||
#endif
|
||||
#define TESTFW_TEST_BEGIN( desc ) testfw_test_begin( desc, __FILE__, __func__, __LINE__ ); __try {
|
||||
#define TESTFW_TEST_END() } __except( EXCEPTION_EXECUTE_HANDLER ) { testfw_exception( GetExceptionCode() ); } \
|
||||
#define TESTFW_TEST_END() } __except( 1 /*EXCEPTION_EXECUTE_HANDLER*/ ) \
|
||||
{ testfw_exception( _exception_code/*GetExceptionCode*/() ); } \
|
||||
testfw_test_end( __FILE__, __func__, __LINE__ )
|
||||
#else
|
||||
#define TESTFW_TEST_BEGIN( desc ) testfw_test_begin( desc, __FILE__, __func__, __LINE__ )
|
||||
#define TESTFW_TEST_END() testfw_test_end( __FILE__, __func__, __LINE__ )
|
||||
#define TESTFW_TEST_BEGIN( desc ) testfw_test_begin( desc, __FILE__, __func__, __LINE__ ); {
|
||||
#define TESTFW_TEST_END() testfw_test_end( __FILE__, __func__, __LINE__ ); }
|
||||
#endif
|
||||
#define TESTFW_EXPECTED( expression ) testfw_expected( (expression) ? 1 : 0, #expression, __FILE__, __func__, __LINE__ )
|
||||
|
||||
void testfw_init();
|
||||
void testfw_init( void );
|
||||
int testfw_summary( char const* filename, char const* funcname, int line );
|
||||
void testfw_test_begin( char const* desc, char const* filename, char const* funcname, int line );
|
||||
void testfw_test_end( char const* filename, char const* funcname, int line );
|
||||
void testfw_expected( int expression, char const* expression_str, char const* filename, char const* funcname, int line );
|
||||
void testfw_print_test_desc();
|
||||
void testfw_print_test_desc( void );
|
||||
void testfw_print_failure( char const* filename, int line );
|
||||
void testfw_assertion_count_inc();
|
||||
void testfw_current_test_assertion_failed();
|
||||
#if defined( _WIN32 ) && !defined( TESTFW_NO_SEH )
|
||||
void testfw_assertion_count_inc( void );
|
||||
void testfw_current_test_assertion_failed( void );
|
||||
#if defined( _WIN32 ) && !defined( TESTFW_NO_SEH ) && !defined( __TINYC__ )
|
||||
void testfw_exception( unsigned int exception_code );
|
||||
#endif
|
||||
|
||||
@@ -50,7 +56,7 @@ void testfw_current_test_assertion_failed();
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <string.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined( _WIN32 ) && !defined( __TINYC__ )
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4619 ) // pragma warning : there is no warning number 'number'
|
||||
#pragma warning( disable: 4668 ) // 'symbol' is not defined as a preprocessor macro, replacing with '0'
|
||||
@@ -63,7 +69,7 @@ void testfw_current_test_assertion_failed();
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
#include <stdio.h>
|
||||
|
||||
#define TESTFW_PRINTF printf
|
||||
#define TESTFW_PRINTF( format, ... ) printf( format, ##__VA_ARGS__ )
|
||||
#endif
|
||||
|
||||
#ifdef TESTFW_NO_ANSI
|
||||
@@ -157,17 +163,17 @@ static struct
|
||||
int tests_failed;
|
||||
int assertions_total;
|
||||
int assertions_failed;
|
||||
testfw_internal_current_test_state_t current_test;
|
||||
#if defined( _WIN32 ) && defined( _DEBUG )
|
||||
struct testfw_internal_current_test_state_t current_test;
|
||||
#if defined( _WIN32 ) && defined( _DEBUG ) && !defined( __TINYC__ )
|
||||
int total_leaks;
|
||||
#endif
|
||||
} testfw_internal_state = {};
|
||||
} testfw_internal_state;
|
||||
|
||||
|
||||
static void testfw_internal_print_progress_divider( char ch, int fail, int total )
|
||||
{
|
||||
int width = 79;
|
||||
int first = (int)( ( width * fail ) / total );
|
||||
int first = (int)( ( width * fail ) / ( total ? total : 1 ) );
|
||||
int second = width - first;
|
||||
if( fail > 0 && first == 0 )
|
||||
{
|
||||
@@ -183,10 +189,12 @@ static void testfw_internal_print_progress_divider( char ch, int fail, int total
|
||||
}
|
||||
|
||||
|
||||
#if defined( _WIN32 ) && defined( _DEBUG )
|
||||
#if defined( _WIN32 ) && defined( _DEBUG ) && !defined( __TINYC__ )
|
||||
|
||||
static int testfw_internal_debug_report_hook( int report_type, char* message, int* return_value )
|
||||
{
|
||||
_flushall();
|
||||
(void) report_type;
|
||||
*return_value = 0; // Don't break to debugger
|
||||
|
||||
if( stricmp( message, "Detected memory leaks!\n" ) == 0 )
|
||||
@@ -236,22 +244,40 @@ static void testfw_internal_print_progress_divider( char ch, int fail, int total
|
||||
#endif /* _WIN32 && _DEBUG */
|
||||
|
||||
|
||||
void testfw_init()
|
||||
#if defined( _WIN32 )
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
void testfw_init( void )
|
||||
{
|
||||
memset( &testfw_internal_state, 0, sizeof( testfw_internal_state ) );
|
||||
|
||||
#ifdef _WIN32
|
||||
int flag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); // Get current flag
|
||||
flag ^= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit
|
||||
_CrtSetDbgFlag( flag ); // Set flag to the new value
|
||||
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
|
||||
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
|
||||
_CrtSetReportHook2( _CRT_RPTHOOK_INSTALL, testfw_internal_debug_report_hook );
|
||||
#if defined( _WIN32 )
|
||||
#if !defined( __TINYC__ )
|
||||
int flag = _CrtSetDbgFlag( _CRTDBG_REPORT_FLAG ); // Get current flag
|
||||
flag ^= _CRTDBG_LEAK_CHECK_DF; // Turn on leak-checking bit
|
||||
_CrtSetDbgFlag( flag ); // Set flag to the new value
|
||||
_CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE );
|
||||
_CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDOUT );
|
||||
_CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE );
|
||||
_CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDOUT );
|
||||
_CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE );
|
||||
_CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDOUT );
|
||||
_CrtSetReportHook2( _CRT_RPTHOOK_INSTALL, testfw_internal_debug_report_hook );
|
||||
_CrtSetReportHook( testfw_internal_debug_report_hook );
|
||||
#endif /* __TINYC__ */
|
||||
HANDLE handle = GetStdHandle( STD_OUTPUT_HANDLE );
|
||||
if( handle != INVALID_HANDLE_VALUE ) {
|
||||
DWORD mode = 0;
|
||||
GetConsoleMode( handle, &mode );
|
||||
SetConsoleMode( handle, mode | 0x0004 /*ENABLE_VIRTUAL_TERMINAL_PROCESSING*/ );
|
||||
}
|
||||
#endif /* _WIN32 */
|
||||
}
|
||||
|
||||
|
||||
static int testfw_internal_must_be_in_test()
|
||||
static int testfw_internal_must_be_in_test( void )
|
||||
{
|
||||
if( !testfw_internal_state.current_test.is_active )
|
||||
TESTFW_PRINTF( "\n\n%sEXPECTED TO BE IN AN ACTIVE TEST, BUT NO TEST IS CURRENTLY ACTIVE.%s\n\n",
|
||||
@@ -260,7 +286,7 @@ static int testfw_internal_must_be_in_test()
|
||||
}
|
||||
|
||||
|
||||
static int testfw_internal_can_not_be_in_test()
|
||||
static int testfw_internal_can_not_be_in_test( void )
|
||||
{
|
||||
if( testfw_internal_state.current_test.is_active )
|
||||
TESTFW_PRINTF( "\n\n%sEXPECTED TO NOT BE IN AN ACTIVE TEST, BUT A TEST IS CURRENTLY ACTIVE.%s\n\n",
|
||||
@@ -269,7 +295,7 @@ static int testfw_internal_can_not_be_in_test()
|
||||
}
|
||||
|
||||
|
||||
void testfw_print_test_desc()
|
||||
void testfw_print_test_desc( void )
|
||||
{
|
||||
if( testfw_internal_must_be_in_test() ) return;
|
||||
|
||||
@@ -282,10 +308,10 @@ void testfw_print_test_desc()
|
||||
TESTFW_PRINTF( "%s\n", testfw_internal_state.current_test.desc ? testfw_internal_state.current_test.desc :
|
||||
"<NO DESCRIPTION>" );
|
||||
TESTFW_PRINTF( "-------------------------------------------------------------------------------\n" );
|
||||
TESTFW_PRINTF( "%s%s(%d): %s%s\n", TESTFW_ANSI_GREY, testfw_internal_state.current_test.file,
|
||||
TESTFW_PRINTF( "%s%s(%d): %s%s\n", TESTFW_ANSI_LIGHT_GREY, testfw_internal_state.current_test.file,
|
||||
testfw_internal_state.current_test.line, TESTFW_ANSI_RESET, testfw_internal_state.current_test.func );
|
||||
|
||||
TESTFW_PRINTF( "%s", TESTFW_ANSI_GREY );
|
||||
TESTFW_PRINTF( "%s", TESTFW_ANSI_LIGHT_GREY );
|
||||
TESTFW_PRINTF( "...............................................................................\n" );
|
||||
TESTFW_PRINTF( "%s", TESTFW_ANSI_RESET );
|
||||
}
|
||||
@@ -294,6 +320,8 @@ void testfw_print_test_desc()
|
||||
|
||||
int testfw_summary( char const* filename, char const* funcname, int line )
|
||||
{
|
||||
(void) filename; (void) funcname; (void) line;
|
||||
|
||||
if( testfw_internal_can_not_be_in_test() ) return -1;
|
||||
|
||||
TESTFW_PRINTF( "\n" );
|
||||
@@ -315,7 +343,7 @@ int testfw_summary( char const* filename, char const* funcname, int line )
|
||||
|
||||
TESTFW_PRINTF( "\n\n" );
|
||||
|
||||
#if defined( _WIN32 ) && defined( _DEBUG )
|
||||
#if defined( _WIN32 ) && defined( _DEBUG ) && !defined( __TINYC__ )
|
||||
int result = _CrtDumpMemoryLeaks();
|
||||
testfw_internal_state.tests_failed += result ? 1 : 0;
|
||||
#endif
|
||||
@@ -343,13 +371,19 @@ void testfw_test_begin( char const* desc, char const* filename, char const* func
|
||||
|
||||
void testfw_test_end( char const* filename, char const* funcname, int line )
|
||||
{
|
||||
(void) filename; (void) funcname; (void) line;
|
||||
if( testfw_internal_must_be_in_test() ) return;
|
||||
|
||||
memset( &testfw_internal_state.current_test, 0, sizeof( testfw_internal_state.current_test ) );
|
||||
}
|
||||
|
||||
|
||||
#if defined( _WIN32 ) && !defined( TESTFW_NO_SEH )
|
||||
#if defined( _WIN32 ) && !defined( TESTFW_NO_SEH ) && !defined( __TINYC__ )
|
||||
#pragma warning( push )
|
||||
#pragma warning( disable: 4668 )
|
||||
#include <windows.h>
|
||||
#pragma warning( pop )
|
||||
|
||||
void testfw_exception( unsigned int exception_code )
|
||||
{
|
||||
if( testfw_internal_must_be_in_test() ) return;
|
||||
@@ -434,14 +468,14 @@ void testfw_test_end( char const* filename, char const* funcname, int line )
|
||||
}
|
||||
|
||||
testfw_print_test_desc();
|
||||
TESTFW_PRINTF( "\n%s%s(%d): %sFAILED:%s\n", TESTFW_ANSI_GREY, testfw_internal_state.current_test.file, testfw_internal_state.current_test.line, TESTFW_ANSI_LIGHT_RED,
|
||||
TESTFW_ANSI_RESET );
|
||||
TESTFW_PRINTF( "\n%s%s(%d): %sFAILED:%s\n", TESTFW_ANSI_LIGHT_GREY, testfw_internal_state.current_test.file,
|
||||
testfw_internal_state.current_test.line, TESTFW_ANSI_LIGHT_RED, TESTFW_ANSI_RESET );
|
||||
TESTFW_PRINTF( "\n %sEXCEPTION( %s%s%s )%s\n", TESTFW_ANSI_CYAN, TESTFW_ANSI_WHITE, exception_str,
|
||||
TESTFW_ANSI_CYAN, TESTFW_ANSI_RESET );
|
||||
TESTFW_ANSI_LIGHT_GREY, TESTFW_ANSI_RESET );
|
||||
}
|
||||
#endif
|
||||
|
||||
void testfw_current_test_assertion_failed()
|
||||
void testfw_current_test_assertion_failed( void )
|
||||
{
|
||||
if( testfw_internal_must_be_in_test() ) return;
|
||||
|
||||
@@ -455,7 +489,7 @@ void testfw_current_test_assertion_failed()
|
||||
}
|
||||
|
||||
|
||||
void testfw_assertion_count_inc()
|
||||
void testfw_assertion_count_inc( void )
|
||||
{
|
||||
if( testfw_internal_must_be_in_test() ) return;
|
||||
|
||||
@@ -465,7 +499,7 @@ void testfw_assertion_count_inc()
|
||||
|
||||
void testfw_print_failure( char const* filename, int line )
|
||||
{
|
||||
TESTFW_PRINTF( "\n%s%s(%d): %sFAILED:%s\n", TESTFW_ANSI_GREY, filename, line, TESTFW_ANSI_LIGHT_RED,
|
||||
TESTFW_PRINTF( "\n%s%s(%d): %sFAILED:%s\n", TESTFW_ANSI_LIGHT_GREY, filename, line, TESTFW_ANSI_LIGHT_RED,
|
||||
TESTFW_ANSI_RESET );
|
||||
}
|
||||
|
||||
@@ -473,6 +507,7 @@ void testfw_print_failure( char const* filename, int line )
|
||||
void testfw_expected( int expression, char const* expression_str, char const* filename,
|
||||
char const* funcname, int line )
|
||||
{
|
||||
(void) funcname;
|
||||
if( testfw_internal_must_be_in_test() ) return;
|
||||
|
||||
testfw_assertion_count_inc();
|
||||
@@ -482,8 +517,8 @@ void testfw_expected( int expression, char const* expression_str, char const* fi
|
||||
testfw_current_test_assertion_failed();
|
||||
testfw_print_test_desc();
|
||||
testfw_print_failure( filename, line );
|
||||
TESTFW_PRINTF( "\n %sTESTFW_EXPECTED( %s%s%s )%s\n", TESTFW_ANSI_CYAN, TESTFW_ANSI_WHITE, expression_str,
|
||||
TESTFW_ANSI_CYAN, TESTFW_ANSI_RESET );
|
||||
TESTFW_PRINTF( "\n %sTESTFW_EXPECTED( %s%s%s )%s\n", TESTFW_ANSI_LIGHT_MAGENTA, TESTFW_ANSI_WHITE, expression_str,
|
||||
TESTFW_ANSI_LIGHT_MAGENTA, TESTFW_ANSI_RESET );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -543,4 +578,4 @@ ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user