Review libc dependencies and remove when possible
Just for clarification, no plans to remove libc dependency, just did some code analysis to see how much raylib depend on stardard C library. My conclusions: - stdlib.h: primary dependency is for malloc() and free() - stdio.h: primary dependency is for FILE access, maybe it could go through a custom ABI? - string.h: just around 8 functions required - math.h: just around 8 functions required - others: 1-2 functions required for some other headers
This commit is contained in:
parent
3cd9e3896a
commit
b5fe41f41a
11 changed files with 73 additions and 67 deletions
|
@ -133,7 +133,7 @@ void SetCameraMoveControls(int frontKey, int backKey,
|
||||||
|
|
||||||
#if defined(CAMERA_IMPLEMENTATION)
|
#if defined(CAMERA_IMPLEMENTATION)
|
||||||
|
|
||||||
#include <math.h> // Required for: sqrt(), sinf(), cosf()
|
#include <math.h> // Required for: sinf(), cosf(), sqrtf()
|
||||||
|
|
||||||
#ifndef PI
|
#ifndef PI
|
||||||
#define PI 3.14159265358979323846
|
#define PI 3.14159265358979323846
|
||||||
|
|
16
src/core.c
16
src/core.c
|
@ -151,14 +151,12 @@
|
||||||
#define SUPPORT_HIGH_DPI // Force HighDPI support on macOS
|
#define SUPPORT_HIGH_DPI // Force HighDPI support on macOS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h> // Standard input / output lib
|
|
||||||
#include <stdlib.h> // Required for: srand(), rand(), atexit()
|
#include <stdlib.h> // Required for: srand(), rand(), atexit()
|
||||||
#include <stdint.h> // Required for: typedef unsigned long long int uint64_t, used by hi-res timer
|
#include <stdio.h> // Required for: FILE, fopen(), fseek(), fread(), fwrite(), fclose() [Used in StorageSaveValue()/StorageLoadValue()]
|
||||||
|
#include <string.h> // Required for: strrchr(), strcmp(), strlen()
|
||||||
#include <time.h> // Required for: time() - Android/RPI hi-res timer (NOTE: Linux only!)
|
#include <time.h> // Required for: time() - Android/RPI hi-res timer (NOTE: Linux only!)
|
||||||
#include <math.h> // Required for: tan() [Used in BeginMode3D() to set perspective]
|
#include <math.h> // Required for: tan() [Used in BeginMode3D()]
|
||||||
#include <string.h> // Required for: strrchr(), strcmp()
|
|
||||||
//#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
|
||||||
#include <ctype.h> // Required for: tolower() [Used in IsFileExtension()]
|
|
||||||
#include <sys/stat.h> // Required for stat() [Used in GetLastWriteTime()]
|
#include <sys/stat.h> // Required for stat() [Used in GetLastWriteTime()]
|
||||||
|
|
||||||
#if (defined(PLATFORM_DESKTOP) || defined(PLATFORM_UWP)) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__))
|
#if (defined(PLATFORM_DESKTOP) || defined(PLATFORM_UWP)) && defined(_WIN32) && (defined(_MSC_VER) || defined(__TINYC__))
|
||||||
|
@ -1635,7 +1633,7 @@ double GetTime(void)
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
uint64_t time = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
unsigned long long int time = (unsigned long long int)ts.tv_sec*1000000000LLU + (unsigned long long int)ts.tv_nsec;
|
||||||
|
|
||||||
return (double)(time - CORE.Time.base)*1e-9; // Elapsed time since InitTimer()
|
return (double)(time - CORE.Time.base)*1e-9; // Elapsed time since InitTimer()
|
||||||
#endif
|
#endif
|
||||||
|
@ -2205,7 +2203,7 @@ int StorageLoadValue(int position)
|
||||||
// Get file size
|
// Get file size
|
||||||
fseek(storageFile, 0, SEEK_END);
|
fseek(storageFile, 0, SEEK_END);
|
||||||
int fileSize = ftell(storageFile); // Size in bytes
|
int fileSize = ftell(storageFile); // Size in bytes
|
||||||
rewind(storageFile);
|
fseek(storageFile, 0, SEEK_SET); // Reset file pointer
|
||||||
|
|
||||||
if (fileSize < (position*4)) TRACELOG(LOG_WARNING, "Storage position could not be found");
|
if (fileSize < (position*4)) TRACELOG(LOG_WARNING, "Storage position could not be found");
|
||||||
else
|
else
|
||||||
|
@ -3349,7 +3347,7 @@ static void InitTimer(void)
|
||||||
|
|
||||||
if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) // Success
|
if (clock_gettime(CLOCK_MONOTONIC, &now) == 0) // Success
|
||||||
{
|
{
|
||||||
CORE.Time.base = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec;
|
CORE.Time.base = (unsigned long long int)now.tv_sec*1000000000LLU + (unsigned long long int)now.tv_nsec;
|
||||||
}
|
}
|
||||||
else TRACELOG(LOG_WARNING, "No hi-resolution timer available");
|
else TRACELOG(LOG_WARNING, "No hi-resolution timer available");
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -152,8 +152,7 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
|
||||||
#include <sys/time.h> // Required for: timespec
|
#include <sys/time.h> // Required for: timespec
|
||||||
#include <time.h> // Required for: clock_gettime()
|
#include <time.h> // Required for: clock_gettime()
|
||||||
|
|
||||||
#include <math.h> // Required for: atan2(), sqrt()
|
#include <math.h> // Required for: sqrtf(), atan2f()
|
||||||
#include <stdint.h> // Required for: uint64_t
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__APPLE__) // macOS also defines __MACH__
|
#if defined(__APPLE__) // macOS also defines __MACH__
|
||||||
|
@ -533,7 +532,7 @@ static double GetCurrentTime(void)
|
||||||
// NOTE: Only for Linux-based systems
|
// NOTE: Only for Linux-based systems
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
uint64_t nowTime = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec; // Time in nanoseconds
|
(unsigned long long int) nowTime = ((unsigned long long int))now.tv_sec*1000000000LLU + ((unsigned long long int))now.tv_nsec; // Time in nanoseconds
|
||||||
|
|
||||||
time = ((double)nowTime/1000000.0); // Time in miliseconds
|
time = ((double)nowTime/1000000.0); // Time in miliseconds
|
||||||
#endif
|
#endif
|
||||||
|
@ -549,7 +548,7 @@ static double GetCurrentTime(void)
|
||||||
// NOTE: OS X does not have clock_gettime(), using clock_get_time()
|
// NOTE: OS X does not have clock_gettime(), using clock_get_time()
|
||||||
clock_get_time(cclock, &now);
|
clock_get_time(cclock, &now);
|
||||||
mach_port_deallocate(mach_task_self(), cclock);
|
mach_port_deallocate(mach_task_self(), cclock);
|
||||||
uint64_t nowTime = (uint64_t)now.tv_sec*1000000000LLU + (uint64_t)now.tv_nsec; // Time in nanoseconds
|
(unsigned long long int) nowTime = ((unsigned long long int))now.tv_sec*1000000000LLU + ((unsigned long long int))now.tv_nsec; // Time in nanoseconds
|
||||||
|
|
||||||
time = ((double)nowTime/1000000.0); // Time in miliseconds
|
time = ((double)nowTime/1000000.0); // Time in miliseconds
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -45,10 +45,10 @@
|
||||||
|
|
||||||
#include "utils.h" // Required for: fopen() Android mapping
|
#include "utils.h" // Required for: fopen() Android mapping
|
||||||
|
|
||||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fscanf(), feof(), rewind(), fgets()
|
|
||||||
#include <stdlib.h> // Required for: malloc(), free()
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
#include <string.h> // Required for: strcmp()
|
#include <stdio.h> // Required for: FILE, fopen(), fclose()
|
||||||
#include <math.h> // Required for: sin(), cos()
|
#include <string.h> // Required for: strncmp() [Used in LoadModelAnimations()], strlen() [Used in LoadTextureFromCgltfImage()]
|
||||||
|
#include <math.h> // Required for: sinf(), cosf(), sqrtf()
|
||||||
|
|
||||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
|
||||||
|
|
||||||
|
|
19
src/raudio.c
19
src/raudio.c
|
@ -78,8 +78,6 @@
|
||||||
#include "utils.h" // Required for: fopen() Android mapping
|
#include "utils.h" // Required for: fopen() Android mapping
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
// @raysan5: To avoid conflicting windows.h symbols with raylib, so flags are defined
|
// @raysan5: To avoid conflicting windows.h symbols with raylib, so flags are defined
|
||||||
// WARNING: Those flags avoid inclusion of some Win32 headers that could be required
|
// WARNING: Those flags avoid inclusion of some Win32 headers that could be required
|
||||||
|
@ -163,9 +161,12 @@ typedef struct tagBITMAPINFOHEADER {
|
||||||
#undef PlaySound // Win32 API: windows.h > mmsystem.h defines PlaySound macro
|
#undef PlaySound // Win32 API: windows.h > mmsystem.h defines PlaySound macro
|
||||||
|
|
||||||
#include <stdlib.h> // Required for: malloc(), free()
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
#include <string.h> // Required for: strcmp(), strncmp()
|
|
||||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
||||||
|
|
||||||
|
#if defined(RAUDIO_STANDALONE)
|
||||||
|
#include <string.h> // Required for: strcmp() [Used in IsFileExtension()]
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(SUPPORT_FILEFORMAT_OGG)
|
#if defined(SUPPORT_FILEFORMAT_OGG)
|
||||||
#define STB_VORBIS_IMPLEMENTATION
|
#define STB_VORBIS_IMPLEMENTATION
|
||||||
#include "external/stb_vorbis.h" // OGG loading functions
|
#include "external/stb_vorbis.h" // OGG loading functions
|
||||||
|
@ -1860,8 +1861,14 @@ static Wave LoadWAV(const char *fileName)
|
||||||
fread(&wavRiffHeader, sizeof(WAVRiffHeader), 1, wavFile);
|
fread(&wavRiffHeader, sizeof(WAVRiffHeader), 1, wavFile);
|
||||||
|
|
||||||
// Check for RIFF and WAVE tags
|
// Check for RIFF and WAVE tags
|
||||||
if (strncmp(wavRiffHeader.chunkID, "RIFF", 4) ||
|
if ((wavRiffHeader.chunkID[0] != 'R') ||
|
||||||
strncmp(wavRiffHeader.format, "WAVE", 4))
|
(wavRiffHeader.chunkID[1] != 'I') ||
|
||||||
|
(wavRiffHeader.chunkID[2] != 'F') ||
|
||||||
|
(wavRiffHeader.chunkID[3] != 'F') ||
|
||||||
|
(wavRiffHeader.format[0] != 'W') ||
|
||||||
|
(wavRiffHeader.format[1] != 'A') ||
|
||||||
|
(wavRiffHeader.format[2] != 'V') ||
|
||||||
|
(wavRiffHeader.format[3] != 'E'))
|
||||||
{
|
{
|
||||||
TRACELOG(LOG_WARNING, "[%s] Invalid RIFF or WAVE Header", fileName);
|
TRACELOG(LOG_WARNING, "[%s] Invalid RIFF or WAVE Header", fileName);
|
||||||
}
|
}
|
||||||
|
@ -2037,7 +2044,7 @@ static Wave LoadOGG(const char *fileName)
|
||||||
wave.data = (short *)RL_MALLOC(wave.sampleCount*wave.channels*sizeof(short));
|
wave.data = (short *)RL_MALLOC(wave.sampleCount*wave.channels*sizeof(short));
|
||||||
|
|
||||||
// NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!)
|
// NOTE: Returns the number of samples to process (be careful! we ask for number of shorts!)
|
||||||
int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, (short *)wave.data, wave.sampleCount*wave.channels);
|
//int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(oggFile, info.channels, (short *)wave.data, wave.sampleCount*wave.channels);
|
||||||
|
|
||||||
TRACELOGD("[%s] Samples obtained: %i", fileName, numSamplesOgg);
|
TRACELOGD("[%s] Samples obtained: %i", fileName, numSamplesOgg);
|
||||||
|
|
||||||
|
|
|
@ -135,7 +135,7 @@
|
||||||
typedef struct float3 { float v[3]; } float3;
|
typedef struct float3 { float v[3]; } float3;
|
||||||
typedef struct float16 { float v[16]; } float16;
|
typedef struct float16 { float v[16]; } float16;
|
||||||
|
|
||||||
#include <math.h> // Required for: sinf(), cosf(), tan(), fabs()
|
#include <math.h> // Required for: sinf(), cosf(), sqrtf(), tan(), fabs()
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module Functions Definition - Utils math
|
// Module Functions Definition - Utils math
|
||||||
|
|
16
src/rlgl.h
16
src/rlgl.h
|
@ -621,10 +621,10 @@ RLAPI int GetPixelDataSize(int width, int height, int format);// Get pixel data
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on LoadText()]
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
#include <stdlib.h> // Required for: malloc(), free(), rand()
|
#include <stdio.h> // Required for: fopen(), fseek(), fread(), fclose() [LoadText]
|
||||||
#include <string.h> // Required for: strcmp(), strlen(), strtok() [Used only in extensions loading]
|
#include <string.h> // Required for: strcmp(), strlen() [Used in rlglInit(), on extensions loading]
|
||||||
#include <math.h> // Required for: atan2()
|
#include <math.h> // Required for: atan2f()
|
||||||
|
|
||||||
#if !defined(RLGL_STANDALONE)
|
#if !defined(RLGL_STANDALONE)
|
||||||
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
#include "raymath.h" // Required for: Vector3 and Matrix functions
|
||||||
|
@ -677,7 +677,7 @@ RLAPI int GetPixelDataSize(int width, int height, int format);// Get pixel data
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(RLGL_STANDALONE)
|
#if defined(RLGL_STANDALONE)
|
||||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() [Used only on TRACELOG()]
|
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end() [Used in TraceLog()]
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
@ -3683,10 +3683,10 @@ void SetVrConfiguration(VrDeviceInfo hmd, Shader distortion)
|
||||||
TRACELOGD("VR: Distortion Shader: Scale = { %f, %f }", scale[0], scale[1]);
|
TRACELOGD("VR: Distortion Shader: Scale = { %f, %f }", scale[0], scale[1]);
|
||||||
TRACELOGD("VR: Distortion Shader: ScaleIn = { %f, %f }", scaleIn[0], scaleIn[1]);
|
TRACELOGD("VR: Distortion Shader: ScaleIn = { %f, %f }", scaleIn[0], scaleIn[1]);
|
||||||
|
|
||||||
// Fovy is normally computed with: 2*atan2(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)
|
// Fovy is normally computed with: 2*atan2f(hmd.vScreenSize, 2*hmd.eyeToScreenDistance)
|
||||||
// ...but with lens distortion it is increased (see Oculus SDK Documentation)
|
// ...but with lens distortion it is increased (see Oculus SDK Documentation)
|
||||||
//float fovy = 2.0f*atan2(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance); // Really need distortionScale?
|
//float fovy = 2.0f*atan2f(hmd.vScreenSize*0.5f*distortionScale, hmd.eyeToScreenDistance); // Really need distortionScale?
|
||||||
float fovy = 2.0f*(float)atan2(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance);
|
float fovy = 2.0f*(float)atan2f(hmd.vScreenSize*0.5f, hmd.eyeToScreenDistance);
|
||||||
|
|
||||||
// Compute camera projection matrices
|
// Compute camera projection matrices
|
||||||
float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1]
|
float projOffset = 4.0f*lensShift; // Scaled to projection space coordinates [-1..1]
|
||||||
|
|
|
@ -42,8 +42,8 @@
|
||||||
|
|
||||||
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
|
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
|
||||||
|
|
||||||
#include <stdlib.h> // Required for: abs(), fabs()
|
#include <stdlib.h> // Required for: fabs()
|
||||||
#include <math.h> // Required for: sinf(), cosf(), sqrtf()
|
#include <math.h> // Required for: sinf(), asinf(), cosf(), acosf(), sqrtf()
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Defines and Macros
|
// Defines and Macros
|
||||||
|
|
65
src/text.c
65
src/text.c
|
@ -54,10 +54,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h> // Required for: malloc(), free()
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
#include <string.h> // Required for: strlen()
|
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fgets()
|
||||||
#include <stdarg.h> // Required for: va_list, va_start(), vsprintf(), va_end()
|
#include <string.h> // Required for: strcmp(), strstr(), strcpy(), strncpy(), strcat(), strncat(), sscanf()
|
||||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fscanf(), feof(), rewind(), fgets()
|
#include <stdarg.h> // Required for: va_list, va_start(), vsprintf(), va_end() [Used in TextFormat()]
|
||||||
#include <ctype.h> // Required for: toupper(), tolower()
|
|
||||||
|
|
||||||
#include "utils.h" // Required for: fopen() Android mapping
|
#include "utils.h" // Required for: fopen() Android mapping
|
||||||
|
|
||||||
|
@ -824,7 +823,7 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float scale,
|
||||||
// NOTE: chars spacing is NOT proportional to fontSize
|
// NOTE: chars spacing is NOT proportional to fontSize
|
||||||
void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
|
void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
|
||||||
{
|
{
|
||||||
int length = strlen(text); // Total length in bytes of the text, scanned by codepoints in loop
|
int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
|
||||||
|
|
||||||
int textOffsetY = 0; // Offset between lines (on line break '\n')
|
int textOffsetY = 0; // Offset between lines (on line break '\n')
|
||||||
float textOffsetX = 0.0f; // Offset X to next character to draw
|
float textOffsetX = 0.0f; // Offset X to next character to draw
|
||||||
|
@ -878,7 +877,7 @@ void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, flo
|
||||||
// Draw text using font inside rectangle limits with support for text selection
|
// Draw text using font inside rectangle limits with support for text selection
|
||||||
void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, Color selectTint, Color selectBackTint)
|
void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, int selectStart, int selectLength, Color selectTint, Color selectBackTint)
|
||||||
{
|
{
|
||||||
int length = strlen(text); // Total length in bytes of the text, scanned by codepoints in loop
|
int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop
|
||||||
|
|
||||||
int textOffsetY = 0; // Offset between lines (on line break '\n')
|
int textOffsetY = 0; // Offset between lines (on line break '\n')
|
||||||
float textOffsetX = 0.0f; // Offset X to next character to draw
|
float textOffsetX = 0.0f; // Offset X to next character to draw
|
||||||
|
@ -1030,7 +1029,7 @@ int MeasureText(const char *text, int fontSize)
|
||||||
// Measure string size for Font
|
// Measure string size for Font
|
||||||
Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing)
|
Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing)
|
||||||
{
|
{
|
||||||
int len = strlen(text);
|
int len = TextLength(text);
|
||||||
int tempLen = 0; // Used to count longer text line num chars
|
int tempLen = 0; // Used to count longer text line num chars
|
||||||
int lenCounter = 0;
|
int lenCounter = 0;
|
||||||
|
|
||||||
|
@ -1145,7 +1144,7 @@ bool TextIsEqual(const char *text1, const char *text2)
|
||||||
// Get text length in bytes, check for \0 character
|
// Get text length in bytes, check for \0 character
|
||||||
unsigned int TextLength(const char *text)
|
unsigned int TextLength(const char *text)
|
||||||
{
|
{
|
||||||
unsigned int length = 0;
|
unsigned int length = 0; //strlen(text)
|
||||||
|
|
||||||
while (*text++) length++;
|
while (*text++) length++;
|
||||||
|
|
||||||
|
@ -1176,12 +1175,11 @@ const char *TextFormat(const char *text, ...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get a piece of a text string
|
// Get a piece of a text string
|
||||||
// REQUIRES: strlen()
|
|
||||||
const char *TextSubtext(const char *text, int position, int length)
|
const char *TextSubtext(const char *text, int position, int length)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
|
|
||||||
int textLength = strlen(text);
|
int textLength = TextLength(text);
|
||||||
|
|
||||||
if (position >= textLength)
|
if (position >= textLength)
|
||||||
{
|
{
|
||||||
|
@ -1203,7 +1201,7 @@ const char *TextSubtext(const char *text, int position, int length)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Replace text string
|
// Replace text string
|
||||||
// REQUIRES: strlen(), strstr(), strncpy(), strcpy()
|
// REQUIRES: strstr(), strncpy(), strcpy()
|
||||||
// WARNING: Internally allocated memory must be freed by the user (if return != NULL)
|
// WARNING: Internally allocated memory must be freed by the user (if return != NULL)
|
||||||
char *TextReplace(char *text, const char *replace, const char *by)
|
char *TextReplace(char *text, const char *replace, const char *by)
|
||||||
{
|
{
|
||||||
|
@ -1219,18 +1217,18 @@ char *TextReplace(char *text, const char *replace, const char *by)
|
||||||
// Sanity checks and initialization
|
// Sanity checks and initialization
|
||||||
if (!text || !replace) return NULL;
|
if (!text || !replace) return NULL;
|
||||||
|
|
||||||
replaceLen = strlen(replace);
|
replaceLen = TextLength(replace);
|
||||||
if (replaceLen == 0) return NULL; // Empty replace causes infinite loop during count
|
if (replaceLen == 0) return NULL; // Empty replace causes infinite loop during count
|
||||||
|
|
||||||
if (!by) by = ""; // Replace by nothing if not provided
|
if (!by) by = ""; // Replace by nothing if not provided
|
||||||
byLen = strlen(by);
|
byLen = TextLength(by);
|
||||||
|
|
||||||
// Count the number of replacements needed
|
// Count the number of replacements needed
|
||||||
insertPoint = text;
|
insertPoint = text;
|
||||||
for (count = 0; (temp = strstr(insertPoint, replace)); count++) insertPoint = temp + replaceLen;
|
for (count = 0; (temp = strstr(insertPoint, replace)); count++) insertPoint = temp + replaceLen;
|
||||||
|
|
||||||
// Allocate returning string and point temp to it
|
// Allocate returning string and point temp to it
|
||||||
temp = result = RL_MALLOC(strlen(text) + (byLen - replaceLen)*count + 1);
|
temp = result = RL_MALLOC(TextLength(text) + (byLen - replaceLen)*count + 1);
|
||||||
|
|
||||||
if (!result) return NULL; // Memory could not be allocated
|
if (!result) return NULL; // Memory could not be allocated
|
||||||
|
|
||||||
|
@ -1254,12 +1252,12 @@ char *TextReplace(char *text, const char *replace, const char *by)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert text in a specific position, moves all text forward
|
// Insert text in a specific position, moves all text forward
|
||||||
// REQUIRES: strlen(), strcpy(), strtok()
|
// REQUIRES: strcpy()
|
||||||
// WARNING: Allocated memory should be manually freed
|
// WARNING: Allocated memory should be manually freed
|
||||||
char *TextInsert(const char *text, const char *insert, int position)
|
char *TextInsert(const char *text, const char *insert, int position)
|
||||||
{
|
{
|
||||||
int textLen = strlen(text);
|
int textLen = TextLength(text);
|
||||||
int insertLen = strlen(insert);
|
int insertLen = TextLength(insert);
|
||||||
|
|
||||||
char *result = (char *)RL_MALLOC(textLen + insertLen + 1);
|
char *result = (char *)RL_MALLOC(textLen + insertLen + 1);
|
||||||
|
|
||||||
|
@ -1280,11 +1278,11 @@ const char *TextJoin(const char **textList, int count, const char *delimiter)
|
||||||
memset(text, 0, MAX_TEXT_BUFFER_LENGTH);
|
memset(text, 0, MAX_TEXT_BUFFER_LENGTH);
|
||||||
|
|
||||||
int totalLength = 0;
|
int totalLength = 0;
|
||||||
int delimiterLen = strlen(delimiter);
|
int delimiterLen = TextLength(delimiter);
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
int textListLength = strlen(textList[i]);
|
int textListLength = TextLength(textList[i]);
|
||||||
|
|
||||||
// Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH
|
// Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH
|
||||||
if ((totalLength + textListLength) < MAX_TEXT_BUFFER_LENGTH)
|
if ((totalLength + textListLength) < MAX_TEXT_BUFFER_LENGTH)
|
||||||
|
@ -1348,7 +1346,7 @@ const char **TextSplit(const char *text, char delimiter, int *count)
|
||||||
void TextAppend(char *text, const char *append, int *position)
|
void TextAppend(char *text, const char *append, int *position)
|
||||||
{
|
{
|
||||||
strcpy(text + *position, append);
|
strcpy(text + *position, append);
|
||||||
*position += strlen(append);
|
*position += TextLength(append);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find first text occurrence within a string
|
// Find first text occurrence within a string
|
||||||
|
@ -1365,14 +1363,17 @@ int TextFindIndex(const char *text, const char *find)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get upper case version of provided string
|
// Get upper case version of provided string
|
||||||
// REQUIRES: toupper()
|
|
||||||
const char *TextToUpper(const char *text)
|
const char *TextToUpper(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
|
|
||||||
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
||||||
{
|
{
|
||||||
if (text[i] != '\0') buffer[i] = (char)toupper(text[i]);
|
if (text[i] != '\0')
|
||||||
|
{
|
||||||
|
//buffer[i] = (char)toupper(text[i]);
|
||||||
|
if ((text[i] >= 'a') && (text[i] <= 'z')) buffer[i] = text[i] - 32;
|
||||||
|
}
|
||||||
else { buffer[i] = '\0'; break; }
|
else { buffer[i] = '\0'; break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1380,14 +1381,17 @@ const char *TextToUpper(const char *text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get lower case version of provided string
|
// Get lower case version of provided string
|
||||||
// REQUIRES: tolower()
|
|
||||||
const char *TextToLower(const char *text)
|
const char *TextToLower(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
|
|
||||||
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++)
|
||||||
{
|
{
|
||||||
if (text[i] != '\0') buffer[i] = (char)tolower(text[i]);
|
if (text[i] != '\0')
|
||||||
|
{
|
||||||
|
//buffer[i] = (char)tolower(text[i]);
|
||||||
|
if ((text[i] >= 'A') && (text[i] <= 'Z')) buffer[i] = text[i] + 32;
|
||||||
|
}
|
||||||
else { buffer[i] = '\0'; break; }
|
else { buffer[i] = '\0'; break; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1395,12 +1399,11 @@ const char *TextToLower(const char *text)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get Pascal case notation version of provided string
|
// Get Pascal case notation version of provided string
|
||||||
// REQUIRES: toupper()
|
|
||||||
const char *TextToPascal(const char *text)
|
const char *TextToPascal(const char *text)
|
||||||
{
|
{
|
||||||
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 };
|
||||||
|
|
||||||
buffer[0] = (char)toupper(text[0]);
|
buffer[0] = (char)TextToUpper(text[0]);
|
||||||
|
|
||||||
for (int i = 1, j = 1; i < MAX_TEXT_BUFFER_LENGTH; i++, j++)
|
for (int i = 1, j = 1; i < MAX_TEXT_BUFFER_LENGTH; i++, j++)
|
||||||
{
|
{
|
||||||
|
@ -1410,7 +1413,7 @@ const char *TextToPascal(const char *text)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
j++;
|
j++;
|
||||||
buffer[i] = (char)toupper(text[j]);
|
buffer[i] = (char)TextToUpper(text[j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { buffer[i] = '\0'; break; }
|
else { buffer[i] = '\0'; break; }
|
||||||
|
@ -1466,7 +1469,7 @@ int *GetCodepoints(const char *text, int *count)
|
||||||
memset(codepoints, 0, MAX_TEXT_UNICODE_CHARS*sizeof(int));
|
memset(codepoints, 0, MAX_TEXT_UNICODE_CHARS*sizeof(int));
|
||||||
|
|
||||||
int bytesProcessed = 0;
|
int bytesProcessed = 0;
|
||||||
int textLength = strlen(text);
|
int textLength = TextLength(text);
|
||||||
int codepointsCount = 0;
|
int codepointsCount = 0;
|
||||||
|
|
||||||
for (int i = 0; i < textLength; codepointsCount++)
|
for (int i = 0; i < textLength; codepointsCount++)
|
||||||
|
@ -1721,12 +1724,12 @@ static Font LoadBMFont(const char *fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: We need some extra space to avoid memory corruption on next allocations!
|
// NOTE: We need some extra space to avoid memory corruption on next allocations!
|
||||||
texPath = RL_MALLOC(strlen(fileName) - strlen(lastSlash) + strlen(texFileName) + 4);
|
texPath = RL_MALLOC(TextLength(fileName) - TextLength(lastSlash) + TextLength(texFileName) + 4);
|
||||||
|
|
||||||
// NOTE: strcat() and strncat() required a '\0' terminated string to work!
|
// NOTE: strcat() and strncat() required a '\0' terminated string to work!
|
||||||
*texPath = '\0';
|
*texPath = '\0';
|
||||||
strncat(texPath, fileName, strlen(fileName) - strlen(lastSlash) + 1);
|
strncat(texPath, fileName, TextLength(fileName) - TextLength(lastSlash) + 1);
|
||||||
strncat(texPath, texFileName, strlen(texFileName));
|
strncat(texPath, texFileName, TextLength(texFileName));
|
||||||
|
|
||||||
TRACELOGD("[%s] Font texture loading path: %s", fileName, texPath);
|
TRACELOGD("[%s] Font texture loading path: %s", fileName, texPath);
|
||||||
|
|
||||||
|
|
|
@ -65,8 +65,8 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdlib.h> // Required for: malloc(), free()
|
#include <stdlib.h> // Required for: malloc(), free()
|
||||||
#include <string.h> // Required for: strlen()
|
|
||||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
||||||
|
#include <string.h> // Required for: strlen() [Used in ImageTextEx()]
|
||||||
|
|
||||||
#include "utils.h" // Required for: fopen() Android mapping
|
#include "utils.h" // Required for: fopen() Android mapping
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,6 @@ static UWPMessage *UWPInMessages[MAX_UWP_MESSAGES]; // Messages in from UWP
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
// This should be in <stdio.h>, but Travis does not find it...
|
|
||||||
FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
|
FILE *funopen(const void *cookie, int (*readfn)(void *, char *, int), int (*writefn)(void *, const char *, int),
|
||||||
fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
|
fpos_t (*seekfn)(void *, fpos_t, int), int (*closefn)(void *));
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue