Update rexm.c

Readded the fall-through in OP_CREATE

Added some safety checks to UpdateRequiredFiles() so it plays nicely outside of the raylib.com context (would segfault previously)
This commit is contained in:
Teeto44 2025-10-01 09:24:59 -04:00
parent db46e540d6
commit e9ccb4192f

View File

@ -215,7 +215,7 @@ int main(int argc, char *argv[])
#else #else
// Cross-platform relative fallbacks (run from tools/rexm directory) // Cross-platform relative fallbacks (run from tools/rexm directory)
if (!exBasePath) exBasePath = "../../examples"; if (!exBasePath) exBasePath = "../../examples";
if (!exWebPath) exWebPath = "../../examples"; if (!exWebPath) exWebPath = "../../raylib.com/examples";
if (!exTemplateFilePath) exTemplateFilePath = "../../examples/examples_template.c"; if (!exTemplateFilePath) exTemplateFilePath = "../../examples/examples_template.c";
if (!exTemplateScreenshot) exTemplateScreenshot = "../../examples/examples_template.png"; if (!exTemplateScreenshot) exTemplateScreenshot = "../../examples/examples_template.png";
if (!exCollectionFilePath) exCollectionFilePath = "../../examples/examples_list.txt"; if (!exCollectionFilePath) exCollectionFilePath = "../../examples/examples_list.txt";
@ -446,7 +446,7 @@ int main(int argc, char *argv[])
SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), exTextUpdated[1]); SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), exTextUpdated[1]);
for (int i = 0; i < 6; i++) { MemFree(exTextUpdated[i]); exTextUpdated[i] = NULL; } for (int i = 0; i < 6; i++) { MemFree(exTextUpdated[i]); exTextUpdated[i] = NULL; }
UnloadFileText(exText); UnloadFileText(exText);
} break; }
case OP_ADD: // Add: Example from command-line input filename case OP_ADD: // Add: Example from command-line input filename
{ {
// Add: raylib/examples/<category>/<category>_example_name.c // Add: raylib/examples/<category>/<category>_example_name.c
@ -1670,11 +1670,22 @@ static int UpdateRequiredFiles(void)
// NOTE: Entries format: exampleEntry('⭐️☆☆☆' , 'core' , 'basic_window'), // NOTE: Entries format: exampleEntry('⭐️☆☆☆' , 'core' , 'basic_window'),
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
char *jsText = LoadFileText(TextFormat("%s/../common/examples.js", exWebPath)); char *jsText = LoadFileText(TextFormat("%s/../common/examples.js", exWebPath));
char *jsTextUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1); // Updated examples.js copy, 2MB if (!jsText)
{
LOG("INFO: examples.js not found, skipping web examples list update\n");
}
else
{
int jsListStartIndex = TextFindIndex(jsText, "//EXAMPLE_DATA_LIST_START"); int jsListStartIndex = TextFindIndex(jsText, "//EXAMPLE_DATA_LIST_START");
int jsListEndIndex = TextFindIndex(jsText, "//EXAMPLE_DATA_LIST_END"); int jsListEndIndex = TextFindIndex(jsText, "//EXAMPLE_DATA_LIST_END");
if ((jsListStartIndex < 0) || (jsListEndIndex < 0))
{
LOG("WARNING: examples.js markers not found, skipping update\n");
UnloadFileText(jsText);
}
else
{
char *jsTextUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1); // Updated examples.js copy, 2MB
int jsIndex = 0; int jsIndex = 0;
memcpy(jsTextUpdated, jsText, jsListStartIndex); memcpy(jsTextUpdated, jsText, jsListStartIndex);
jsIndex = sprintf(jsTextUpdated + jsListStartIndex, "//EXAMPLE_DATA_LIST_START\n"); jsIndex = sprintf(jsTextUpdated + jsListStartIndex, "//EXAMPLE_DATA_LIST_START\n");
@ -1718,6 +1729,8 @@ static int UpdateRequiredFiles(void)
SaveFileText(TextFormat("%s/../common/examples.js", exWebPath), jsTextUpdated); SaveFileText(TextFormat("%s/../common/examples.js", exWebPath), jsTextUpdated);
UnloadFileText(jsText); UnloadFileText(jsText);
RL_FREE(jsTextUpdated); RL_FREE(jsTextUpdated);
}
}
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
return result; return result;