Skip to content

Commit

Permalink
standardize the IMPLEMENTATION defines
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyGaul committed Nov 12, 2017
1 parent 9f854f2 commit 987f6a4
Show file tree
Hide file tree
Showing 22 changed files with 107 additions and 77 deletions.
2 changes: 1 addition & 1 deletion examples_tinyfiles/main.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <Windows.h>

#define TINYFILES_IMPL
#define TINYFILES_IMPLEMENTATION
#include "tinyfiles.h"

#include <stdio.h>
Expand Down
6 changes: 3 additions & 3 deletions examples_tinygl_and_tinyc2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
#include "glfw/glfw_config.h"
#include "glfw/glfw3.h"

#define TINYGL_IMPL
#define TINYGL_IMPLEMENTATION
#include "../tinygl.h"

#define TT_IMPLEMENTATION
#define TINYTIME_IMPLEMENTATION
#include "../tinytime.h"

#define TINYC2_IMPL
#define TINYC2_IMPLEMENTATION
#include "../tinyc2.h"

GLFWwindow* window;
Expand Down
2 changes: 1 addition & 1 deletion examples_tinysid/Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
sid : main.c
gcc -I../ main.c -o $@
gcc -I../ -Wall -pedantic -m64 main.c -o $@

do_sid : sid
sid ./preprocess_me
5 changes: 3 additions & 2 deletions examples_tinysid/main.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#define _CRT_SECURE_NO_WARNINGS

#define TINYSID_IMPL
#define TINYFILES_IMPL
#define TINYSID_IMPLEMENTATION
#include "../tinysid.h"

#define TINYFILES_IMPLEMENTATION
#include "../tinyfiles.h"

#include <string.h>
Expand Down
2 changes: 1 addition & 1 deletion examples_tinysound/demo/demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "stb_vorbis.c"

// create header + implementation
#define TS_IMPLEMENTATION
#define TINYSOUND_IMPLEMENTATION
#include "tinysound.h"

tsLoadedSound vorbis_loaded;
Expand Down
2 changes: 1 addition & 1 deletion examples_tinysound/hello/hello.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// create header + implementation
#define TS_IMPLEMENTATION
#define TINYSOUND_IMPLEMENTATION
#include "tinysound.h"

#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion examples_tinysound/pitch/demo.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define TS_IMPLEMENTATION
#define TINYSOUND_IMPLEMENTATION
#include "../../tinysound.h"

// this file was originally written by Aaron Balint, see:
Expand Down
7 changes: 5 additions & 2 deletions examples_tinysound/sdl_demo/main.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#include <Windows.h>

#define _CRT_SECURE_NO_WARNINGS
#include "SDL2/SDL.h"

#define TS_IMPLEMENTATION
#define TS_FORCE_SDL
#define TINYSOUND_IMPLEMENTATION
#define TINYSOUND_FORCE_SDL
#include "../../tinysound.h"

int main( int argc, char *args[] )
Expand Down
2 changes: 1 addition & 1 deletion test_tinyhuff/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define TINYHUFF_IMPL
#define TINYHUFF_IMPLEMENTATION
#include "../tinyhuff.h"

#include <stdio.h>
Expand Down
2 changes: 1 addition & 1 deletion test_tinyutf/main.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#define TINY_UTF_IMPLEMENTATION
#define TINYUTF_IMPLEMENTATION
#include "../tinyutf.h"

#include <stdlib.h>
Expand Down
7 changes: 4 additions & 3 deletions test_tinyutf/tinyutf.vcxproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
Expand All @@ -14,18 +14,19 @@
<ProjectGuid>{7A2B2134-E2A9-4AC5-BB85-14E3811B3B42}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>tinyutf</RootNamespace>
<WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<PlatformToolset>v120</PlatformToolset>
<PlatformToolset>v141</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
Expand Down
15 changes: 7 additions & 8 deletions tinyalloc.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
/*
tinyalloc.h - v1.01
To create implementation (the function definitions)
#define TINYALLOC_IMPLEMENTATION
in *one* C/CPP file (translation unit) that includes this file
SUMMARY:
This header contains a collection of allocators. None of the allocators are
Expand Down Expand Up @@ -32,12 +36,6 @@
1.01 (11/11/2017) added leak checker for malloc/free
*/

/*
To create implementation (the function definitions)
#define TINYALLOC_IMPL
in *one* C/CPP file (translation unit) that includes this file
*/

#if !defined(TINYALLOC_H)

typedef struct taStack taStack;
Expand Down Expand Up @@ -83,7 +81,8 @@ int TA_CHECK_FOR_LEAKS();
#define TINYALLOC_H
#endif

#if defined(TINYALLOC_IMPL)
#if defined(TINYALLOC_IMPLEMENTATION)
#undef TINYALLOC_IMPLEMENTATION

struct taStack
{
Expand Down Expand Up @@ -259,7 +258,7 @@ inline void taLeakCheckFree(void* mem)
inline int TA_CHECK_FOR_LEAKS() {}
#endif // TA_LEAK_CHECK

#endif // TINYALLOC_IMPL
#endif // TINYALLOC_IMPLEMENTATION

/*
This is free and unencumbered software released into the public domain.
Expand Down
14 changes: 6 additions & 8 deletions tinyc2.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/*
tinyc2.h - v1.03
To create implementation (the function definitions)
#define TINYC2_IMPLEMENTATION
in *one* C/CPP file (translation unit) that includes this file
SUMMARY:
tinyc2 is a single-file header that implements 2D collision detection routines
that test for overlap, and optionally can find the collision manifold. The
Expand Down Expand Up @@ -28,12 +32,6 @@
sro5h 1.03 - work involving quality of life fixes for manifolds
*/

/*
To create implementation (the function definitions)
#define TINYC2_IMPL
in *one* C/CPP file (translation unit) that includes this file
*/

/*
THE IMPORTANT PARTS:
Most of the math types in this header are for internal use. Users care about
Expand Down Expand Up @@ -408,7 +406,7 @@ C2_INLINE void c2BBVerts( c2v* out, c2AABB* bb )
#define TINYC2_H
#endif

#ifdef TINYC2_IMPL
#ifdef TINYC2_IMPLEMENTATION

int c2Collided( const void* A, const c2x* ax, C2_TYPE typeA, const void* B, const c2x* bx, C2_TYPE typeB )
{
Expand Down Expand Up @@ -1671,7 +1669,7 @@ void c2PolytoPolyManifold( const c2Poly* A, const c2x* ax_ptr, const c2Poly* B,
if ( flip ) m->normal = c2Neg( m->normal );
}

#endif // TINYC2_IMPL
#endif // TINYC2_IMPLEMENTATION

/*
zlib license:
Expand Down
5 changes: 3 additions & 2 deletions tinyfiles.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
tinyfiles.h - v1.0
To create implementation (the function definitions)
#define TINYFILES_IMPL
#define TINYFILES_IMPLEMENTATION
in *one* C/CPP file (translation unit) that includes this file
Summary:
Expand Down Expand Up @@ -187,7 +187,8 @@ void tfDoUnitTests();
#define TINYFILES_H
#endif

#ifdef TINYFILES_IMPL
#ifdef TINYFILES_IMPLEMENTATION
#undef TINYFILES_IMPLEMENTATION

#define tfSafeStrCpy( dst, src, n, max ) tfSafeStrCopy_internal( dst, src, n, max, __FILE__, __LINE__ )
static int tfSafeStrCopy_internal( char* dst, const char* src, int n, int max, const char* file, int line )
Expand Down
13 changes: 7 additions & 6 deletions tinygl.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
/*
tinygl - v1.02
To create implementation (the function definitions)
#define TINYGL_IMPLEMENTATION
in *one* C/CPP file (translation unit) that includes this file
Summary:
Wrapper for OpenGL ES 3.0+ for vertex attributes, shader creation, draw calls,
and post-processing fx. The API was carefully designed to facilitate trying out
one-off techqniques or experiments, of which are critical for certain kinds
of development styles (i.e. fast iteration). Credit goes to thatgamecompany
for the original designs + idea of this API style.
To create implementation (the function definitions)
#define TINYGL_IMPL
in *one* C/CPP file (translation unit) that includes this file
*/

/*
Expand Down Expand Up @@ -243,7 +243,8 @@ void tgCopy( float* dst, float* src );
#define TINYGL_H
#endif

#ifdef TINYGL_IMPL
#ifdef TINYGL_IMPLEMENTATION
#undef TINYGL_IMPLEMENTATION

#define TG_OFFSET_OF( type, member ) ((uint32_t)((size_t)(&((type*)0)->member)))

Expand Down Expand Up @@ -1231,4 +1232,4 @@ void tgPrintGLErrors_internal( char* file, uint32_t line )
}
#endif

#endif // TINYGL_IMPL
#endif // TINYGL_IMPLEMENTATION
17 changes: 8 additions & 9 deletions tinyhuff.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/*
tinyhuff.h - v1.00
To create implementation (the function definitions)
#define TINYHUFF_IMPLEMENTATION
in *one* C/CPP file (translation unit) that includes this file
SUMMARY:
This header contains functions to compress and decompress data streams via
Expand Down Expand Up @@ -76,7 +80,7 @@
you see fit. Compression keys can be used to store the compression keys themselves! This would
be effective since the keys usually contain many zero bytes and some repitition.
#define TINYHUFF_IMPL
#define TINYHUFF_IMPLEMENTATION
#include "../tinyhuff.h"
#include <stdio.h>
Expand Down Expand Up @@ -130,12 +134,6 @@
return 0;
}
/*
/*
To create implementation (the function definitions)
#define TINYHUFF_IMPL
in *one* C/CPP file (translation unit) that includes this file
*/

#if !defined( TINYHUFF_H )
Expand Down Expand Up @@ -175,7 +173,8 @@ void thDecompress( const thKey* decompression_key, const void* in, int in_bits,
#define TINYHUFF_H
#endif

#if defined( TINYHUFF_IMPL )
#if defined( TINYHUFF_IMPLEMENTATION )
#undef TINYHUFF_IMPLEMENTATION

const char* th_error_reason;

Expand Down Expand Up @@ -765,7 +764,7 @@ void thDecompress( const thKey* decompression_key, const void* in_buf, int in_bi

#endif // TH_INTERNAL_TESTS

#endif // TINYHUFF_IMPL
#endif // TINYHUFF_IMPLEMENTATION

/*
zlib license:
Expand Down
7 changes: 4 additions & 3 deletions tinypath.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
To create implementation (the function definitions)
#define TINYPATH_IMPL
#define TINYPATH_IMPLEMENTATION
in *one* C/CPP file (translation unit) that includes this file
Expand Down Expand Up @@ -85,7 +85,8 @@ void tpDoUnitTests();
#define TINYPATH_H
#endif

#if defined( TINYPATH_IMPL )
#if defined( TINYPATH_IMPLEMENTATION )
#endif TINYPATH_IMPLEMENTATION

#ifdef _WIN32

Expand Down Expand Up @@ -499,7 +500,7 @@ int tpCompact( const char* path, char* out, int n )

#endif // TP_UNIT_TESTS

#endif
#endif // TINYPATH_IMPLEMENTATION

/*
This is free and unencumbered software released into the public domain.
Expand Down
3 changes: 1 addition & 2 deletions tinypng.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/*
tinypng.h - v1.02
To create implementation (the function definitions)
#define TINYPNG_IMPLEMENTATION
in *one* C/CPP file (translation unit) that includes this file
Expand Down Expand Up @@ -1516,7 +1515,7 @@ int tpDefaultSaveAtlas( const char* out_path_image, const char* out_path_atlas_t
return 0;
}

#endif // TINYDEFLATE_IMPL
#endif // TINYPNG_IMPLEMENTATION

/*
This is free and unencumbered software released into the public domain.
Expand Down
11 changes: 8 additions & 3 deletions tinysid.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
/*
tinysid.h - v1.0
To create implementation (the function definitions)
#define TINYSID_IMPLEMENTATION
in *one* C/CPP file (translation unit) that includes this file
SUMMARY:
Implements a compile-time string hasher via preprocessing.
Preprocesses an input file and turns all SID( "string" ) instances
Expand Down Expand Up @@ -36,7 +40,8 @@ uint64_t FNV1a(const void* buf, int len);
#define TINYSID_H
#endif

#ifdef TINYSID_IMPL
#ifdef TINYSID_IMPLEMENTATION
#undef TINYSID_IMPLEMENTATION

#include <stdlib.h> // malloc, free
#include <stdio.h> // fopen, fseek, ftell, fclose, fwrite, fread
Expand Down Expand Up @@ -209,7 +214,7 @@ int tsPreprocess( const char* path, const char* out_path )

unsigned h = FNV1a_str_end( data, ptr ); // TODO: detect and report collisions
int bytes = ptr - data;
sprintf( out, "0x%.16" PRIx64 " /* \"%.*s\" */", h, bytes, data );
sprintf( out, "0x%.16" PRIx64 " /* \"%.*s\" */", (long long unsigned int)h, bytes, data );
out += 19 + bytes;

data = ptr + 1;
Expand All @@ -233,7 +238,7 @@ int tsPreprocess( const char* path, const char* out_path )
return fileWasModified;
}

#endif
#endif // TINYSID_IMPLEMENTATION

/*
zlib license:
Expand Down
Loading

0 comments on commit 987f6a4

Please sign in to comment.