Debian Codegraph @

tools/rexm/rexm.c

raw symbols SCIP
1 /*******************************************************************************************
2 *
3 * rexm [raylib examples manager] - A simple and easy-to-use raylib examples collection manager
4 *
5 * Supported processes:
6 * - create <new_example_name>
7 * - add <example_name>
8 * - rename <old_examples_name> <new_example_name>
9 * - remove <example_name>
10 * - build <example_name>
11 * - test <example_name>
12 * - validate // All examples
13 * - update // All examples
14 *
15 * Files involved in the processes:
16 * - raylib/examples/<category>/<category>_example_name.c
17 * - raylib/examples/<category>/<category>_example_name.png
18 * - raylib/examples/<category>/resources/..
19 * - raylib/examples/Makefile
20 * - raylib/examples/Makefile.Web
21 * - raylib/examples/README.md
22 * - raylib/projects/VS2022/examples/<category>_example_name.vcxproj
23 * - raylib/projects/VS2022/raylib.sln
24 * - raylib.com/common/examples.js
25 * - raylib.com/examples/<category>/<category>_example_name.html
26 * - raylib.com/examples/<category>/<category>_example_name.data
27 * - raylib.com/examples/<category>/<category>_example_name.wasm
28 * - raylib.com/examples/<category>/<category>_example_name.js
29 * - ...
30 *
31 * LICENSE: zlib/libpng
32 *
33 * Copyright (c) 2025-2026 Ramon Santamaria (@raysan5)
34 *
35 * This software is provided "as-is", without any express or implied warranty. In no event
36 * will the authors be held liable for any damages arising from the use of this software.
37 *
38 * Permission is granted to anyone to use this software for any purpose, including commercial
39 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
40 *
41 * 1. The origin of this software must not be misrepresented; you must not claim that you
42 * wrote the original software. If you use this software in a product, an acknowledgment
43 * in the product documentation would be appreciated but is not required.
44 *
45 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
46 * as being the original software.
47 *
48 * 3. This notice may not be removed or altered from any source distribution.
49 *
50 **********************************************************************************************/
51
52 #include "raylib.h"
53
54 #include <stdio.h> // Required for: rename(), remove()
55 #include <string.h> // Required for: strcmp(), strcpy()
56 #include <stdlib.h> // Required for: NULL, calloc(), free()
57
58 #define SUPPORT_LOG_INFO
59 #if defined(SUPPORT_LOG_INFO) //&& defined(_DEBUG)
60 #define LOG(...) printf("REXM: "__VA_ARGS__)
61 #else
62 #define LOG(...)
63 #endif
64
65 #define REXM_MAX_EXAMPLES 512
66 #define REXM_MAX_EXAMPLE_CATEGORIES 7
67
68 #define REXM_MAX_BUFFER_SIZE (2*1024*1024) // 2MB
69
70 #define REXM_MAX_RESOURCE_PATHS 256
71 #define REXM_MAX_RESOURCE_PATH_LENGTH 256
72
73 // Create local commit with changes on example renaming
74 //#define RENAME_AUTO_COMMIT_CREATION
75
76 #if defined(__GNUC__) // GCC and Clang
77 #pragma GCC diagnostic push
78 // Avoid GCC/Clang complaining about sprintf() second parameter not being a string literal (being TextFormat())
79 #pragma GCC diagnostic ignored "-Wformat-security"
80 #endif
81
82 //----------------------------------------------------------------------------------
83 // Types and Structures Definition
84 //----------------------------------------------------------------------------------
85 // raylib example info struct
86 typedef struct {
87 char category[16]; // Example category: core, shapes, textures, text, models, shaders, audio
88 char name[128]; // Example name: <category>_name_part
89 int stars; // Example stars count: ★☆☆☆
90 char verCreated[12]; // Example raylib creation version
91 char verUpdated[12]; // Example raylib last update version
92 int yearCreated; // Example year created
93 int yearReviewed; // Example year reviewed
94 char author[64]; // Example author
95 char authorGitHub[64]; // Example author, GitHub user name
96
97 int status; // Example validation status flags
98 int resCount; // Example resources counter
99 char **resPaths; // Example resources paths (MAX: 256)
100 } rlExampleInfo;
101
102 // Automated testing data
103 typedef struct {
104 int buildwarns; // Example building warnings count (by GCC compiler)
105 int warnings; // Example run output log warnings count
106 int status; // Example run testing status flags (>0 = FAILS)
107 } rlExampleTesting;
108
109 // Validation status for a single example
110 typedef enum {
111 VALID_OK = 0, // All required files and entries are present
112 VALID_MISSING_C = 1 << 0, // Missing .c source file
113 VALID_MISSING_PNG = 1 << 1, // Missing screenshot .png
114 VALID_INVALID_PNG = 1 << 2, // Invalid screenshot .png (using template one)
115 VALID_MISSING_RESOURCES = 1 << 3, // Missing resources listed in the code
116 VALID_MISSING_VCXPROJ = 1 << 4, // Missing Visual Studio .vcxproj file
117 VALID_NOT_IN_VCXSOL = 1 << 5, // Project not included in solution file
118 VALID_NOT_IN_MAKEFILE = 1 << 6, // Not listed in Makefile
119 VALID_NOT_IN_MAKEFILE_WEB = 1 << 7, // Not listed in Makefile.Web
120 VALID_NOT_IN_README = 1 << 8, // Not listed in README.md
121 VALID_NOT_IN_JS = 1 << 9, // Not listed in examples.js
122 VALID_INCONSISTENT_INFO = 1 << 10, // Inconsistent info between collection and example header (stars, author...)
123 VALID_MISSING_WEB_OUTPUT = 1 << 11, // Missing .html/.data/.wasm/.js
124 VALID_MISSING_WEB_METADATA = 1 << 12, // Missing .html example metadata
125 VALID_INVALID_CATEGORY = 1 << 13, // Not a recognized category
126 VALID_UNKNOWN_ERROR = 1 << 14 // Unknown failure case (fallback)
127 } rlExampleValidationStatus;
128
129 typedef enum {
130 TESTING_OK = 0, // All automated testing ok
131 TESTING_FAIL_INIT = 1 << 0, // Initialization (InitWindow()) -> "INFO: DISPLAY: Device initialized successfully"
132 TESTING_FAIL_CLOSE = 1 << 1, // Closing (CloseWindow()) -> "INFO: Window closed successfully"
133 TESTING_FAIL_ASSETS = 1 << 2, // Assets loading (WARNING: FILE:) -> "WARNING: FILEIO:"
134 TESTING_FAIL_RLGL = 1 << 3, // OpenGL-wrapped initialization -> "INFO: RLGL: Default OpenGL state initialized successfully"
135 TESTING_FAIL_PLATFORM = 1 << 4, // Platform initialization -> "INFO: PLATFORM: DESKTOP (GLFW - Win32): Initialized successfully"
136 TESTING_FAIL_FONT = 1 << 5, // Font deefault initialization -> "INFO: FONT: Default font loaded successfully (224 glyphs)"
137 TESTING_FAIL_TIMER = 1 << 6, // Timer initialization -> "INFO: TIMER: Target time per frame: 16.667 milliseconds"
138 TESTING_FAIL_OTHER = 1 << 7, // Other types of warnings (WARNING:)
139 } rlExampleTestingStatus;
140
141 // Example management operations
142 typedef enum {
143 OP_NONE = 0, // No process to do
144 OP_CREATE = 1, // Create new example, using default template
145 OP_ADD = 2, // Add existing examples (hopefully following template)
146 OP_RENAME = 3, // Rename existing example
147 OP_REMOVE = 4, // Remove existing example
148 OP_VALIDATE = 5, // Validate examples, using [examples_list.txt] as main source by default
149 OP_UPDATE = 6, // Validate and update required examples (as far as possible): ALL
150 OP_BUILD = 7, // Build example(s) for desktop and web, copy web output - Multiple examples supported
151 OP_TEST = 8, // Test example(s), checking output log "WARNING" - Multiple examples supported
152 OP_TESTLOG = 9, // Process available examples logs to generate report
153 } rlExampleOperation;
154
155 static const char *exCategories[REXM_MAX_EXAMPLE_CATEGORIES] = { "core", "shapes", "textures", "text", "models", "shaders", "audio" };
156
157 // Paths required for examples management
158 // NOTE: Paths can be provided with environment variables
159 static const char *exBasePath = NULL; // Env: REXM_EXAMPLES_BASE_PATH
160 static const char *exWebPath = NULL; // Env: REXM_EXAMPLES_WEB_PATH
161 static const char *exTemplateFilePath = NULL; // Env: REXM_EXAMPLES_TEMPLATE_FILE_PATH
162 static const char *exTemplateScreenshot = NULL; // Env: REXM_EXAMPLES_TEMPLATE_SCREENSHOT_PATH
163 static const char *exCollectionFilePath = NULL; // Env: REXM_EXAMPLES_COLLECTION_FILE_PATH
164 static const char *exVSProjectSolutionFile = NULL; // Env REXM_EXAMPLES_VS2022_SLN_FILE
165
166 //----------------------------------------------------------------------------------
167 // Module Internal Functions Declaration
168 //----------------------------------------------------------------------------------
169 // Update required files from examples collection
170 // UPDATES: Makefile, Makefile.Web, README.md, examples.js
171 static int UpdateRequiredFiles(void);
172
173 // Load examples collection information
174 // NOTE 1: Load by category: "ALL", "core", "shapes", "textures", "text", "models", "shaders", audio"
175 // NOTE 2: Sort examples list on request flag
176 static rlExampleInfo *LoadExampleData(const char *filter, bool sort, int *exCount);
177 static void UnloadExampleData(rlExampleInfo *exInfo);
178
179 // Load example info from file header
180 static rlExampleInfo *LoadExampleInfo(const char *exFileName);
181 static void UnloadExampleInfo(rlExampleInfo *exInfo);
182
183 // raylib example line info parser
184 // Parses following line format: core/core_basic_window;★☆☆☆;1.0;1.0;"Ray"/@raysan5
185 static int ParseExampleInfoLine(const char *line, rlExampleInfo *entry);
186
187 // Sort array of strings by name
188 // WARNING: items[] pointers are reorganized
189 static void SortExampleByName(rlExampleInfo *items, int count);
190
191 // Scan resource paths in example file
192 static char **LoadExampleResourcePaths(const char *filePath, int *resPathCount);
193
194 // Clear resource paths scanned
195 static void UnloadExampleResourcePaths(char **resPaths);
196
197 // Add/remove VS project (.vcxproj) tofrom existing VS solution (.sln)
198 static int AddVSProjectToSolution(const char *slnFile, const char *projFile, const char *category);
199 static int RemoveVSProjectFromSolution(const char *slnFile, const char *exName);
200
201 // Generate unique UUID v4 string
202 // Output format: {9A2F48CC-0DA8-47C0-884E-02E37F9BE6C1}
203 // TODO: It seems generated UUID is not valid for VS2022
204 static const char *GenerateUUIDv4(void);
205
206 // Update source code header and comments metadata
207 static void UpdateSourceMetadata(const char *exSrcPath, const rlExampleInfo *info);
208 // Update generated Web example .html file metadata
209 static void UpdateWebMetadata(const char *exHtmlPath, const char *exFilePath);
210
211 // Check if text string is in a list of strings and get index, -1 if not found
212 static int GetTextListIndex(const char *text, const char **list, int listCount);
213
214 //------------------------------------------------------------------------------------
215 // Program main entry point
216 //------------------------------------------------------------------------------------
217 int main(int argc, char *argv[])
218 {
219 SetTraceLogLevel(LOG_NONE);
220
221 // Path values can be configured with environment variables
222 exBasePath = getenv("REXM_EXAMPLES_BASE_PATH");
223 exWebPath = getenv("REXM_EXAMPLES_WEB_PATH");
224 exTemplateFilePath = getenv("REXM_EXAMPLES_TEMPLATE_FILE_PATH");
225 exTemplateScreenshot = getenv("REXM_EXAMPLES_TEMPLATE_SCREENSHOT_PATH");
226 exCollectionFilePath = getenv("REXM_EXAMPLES_COLLECTION_FILE_PATH");
227 exVSProjectSolutionFile = getenv("REXM_EXAMPLES_VS2022_SLN_FILE");
228
229 #if defined(_WIN32)
230 if (!exBasePath) exBasePath = "C:/GitHub/raylib/examples";
231 if (!exWebPath) exWebPath = "C:/GitHub/raylib.com/examples";
232 if (!exTemplateFilePath) exTemplateFilePath = "C:/GitHub/raylib/examples/examples_template.c";
233 if (!exTemplateScreenshot) exTemplateScreenshot = "C:/GitHub/raylib/examples/examples_template.png";
234 if (!exCollectionFilePath) exCollectionFilePath = "C:/GitHub/raylib/examples/examples_list.txt";
235 if (!exVSProjectSolutionFile) exVSProjectSolutionFile = "C:/GitHub/raylib/projects/VS2022/raylib.sln";
236 #else
237 // Cross-platform relative fallbacks (run from tools/rexm directory)
238 if (!exBasePath) exBasePath = "../../examples";
239 if (!exWebPath) exWebPath = "../../raylib.com/examples";
240 if (!exTemplateFilePath) exTemplateFilePath = "../../examples/examples_template.c";
241 if (!exTemplateScreenshot) exTemplateScreenshot = "../../examples/examples_template.png";
242 if (!exCollectionFilePath) exCollectionFilePath = "../../examples/examples_list.txt";
243 if (!exVSProjectSolutionFile) exVSProjectSolutionFile = "../../projects/VS2022/raylib.sln";
244 #endif
245
246 char inFileName[1024] = { 0 }; // Example input filename (to be added)
247
248 char exName[64] = { 0 }; // Example name, without extension: core_basic_window
249 char exCategory[32] = { 0 }; // Example category: core
250 char exRecategory[32] = { 0 }; // Example re-name category: shapes
251 char exRename[64] = { 0 }; // Example re-name, without extension
252
253 char *exBuildList[256] = { 0 }; // Example build list for: ALL, <category>, single-example
254 int exBuildListCount = 0; // Example build list file count
255
256 int opCode = OP_NONE; // Operation code: 0-None(Help), 1-Create, 2-Add, 3-Rename, 4-Remove
257 bool showUsage = false; // Flag to show usage help
258 bool verbose = false; // Flag for verbose log info
259
260 // Command-line usage mode: command args processing
261 //--------------------------------------------------------------------------------------
262 if (argc > 1)
263 {
264 // Supported commands:
265 // create <new_example_name> : Creates an empty example, from internal template
266 // add <example_name> : Add existing example, category extracted from name
267 // rename <old_examples_name> <new_example_name> : Rename an existing example
268 // remove <example_name> : Remove an existing example
269 // build <example_name> : Build example for Desktop and Web platforms
270 // validate : Validate examples collection, generates report
271 // update : Validate and update examples collection, generates report
272
273 if (strcmp(argv[1], "create") == 0)
274 {
275 // Check for valid upcoming argument
276 if (argc == 2) LOG("WARNING: No filename provided to create\n");
277 else if (argc > 3) LOG("WARNING: Too many arguments provided\n");
278 else
279 {
280 // Security checks for file name to verify category is included
281 int catIndex = TextFindIndex(argv[2], "_");
282 if (catIndex > 3)
283 {
284 char cat[12] = { 0 };
285 strncpy(cat, argv[2], catIndex);
286 bool catFound = false;
287 for (int i = 0; i < REXM_MAX_EXAMPLE_CATEGORIES; i++)
288 {
289 if (TextIsEqual(cat, exCategories[i])) { catFound = true; break; }
290 }
291
292 if (catFound)
293 {
294 strcpy(exName, argv[2]); // Register filename for new example creation
295 strncpy(exCategory, exName, TextFindIndex(exName, "_"));
296 opCode = OP_CREATE;
297 }
298 else LOG("WARNING: Example category is not valid\n");
299 }
300 else LOG("WARNING: Example name does not include category\n");
301 }
302 }
303 else if (strcmp(argv[1], "add") == 0)
304 {
305 // Check for valid upcoming argument
306 if (argc == 2) LOG("WARNING: No filename provided to create\n");
307 else if (argc > 3) LOG("WARNING: Too many arguments provided\n");
308 else
309 {
310 if (IsFileExtension(argv[2], ".c")) // Check for valid file extension: input
311 {
312 if (FileExists(argv[2]))
313 {
314 // Security checks for file name to verify category is included
315 int catIndex = TextFindIndex(GetFileName(argv[2]), "_");
316 if (catIndex > 3)
317 {
318 char cat[12] = { 0 };
319 strncpy(cat, GetFileName(argv[2]), catIndex);
320 bool catFound = false;
321 for (int i = 0; i < REXM_MAX_EXAMPLE_CATEGORIES; i++)
322 {
323 if (TextIsEqual(cat, exCategories[i])) { catFound = true; break; }
324 }
325
326 if (catFound)
327 {
328 strcpy(inFileName, argv[2]); // Register filename for addition
329 strcpy(exName, GetFileNameWithoutExt(inFileName)); // Register example name
330 strncpy(exCategory, exName, TextFindIndex(exName, "_"));
331 opCode = OP_ADD;
332 }
333 else LOG("WARNING: Example category is not valid\n");
334 }
335 else LOG("WARNING: Example name does not include category\n");
336 }
337 else LOG("WARNING: Input file not found, include path\n");
338 }
339 else LOG("WARNING: Input file extension not recognized (.c)\n");
340 }
341 }
342 else if (strcmp(argv[1], "rename") == 0)
343 {
344 if (argc == 2) LOG("WARNING: No filename provided to be renamed\n");
345 else if (argc == 3) LOG("WARNING: No new filename provided to be renamed\n");
346 else if (argc > 4) LOG("WARNING: Too many arguments provided\n");
347 else
348 {
349 // Verify example exists in collection to be removed
350 char *exColInfo = LoadFileText(exCollectionFilePath);
351 if (TextFindIndex(exColInfo, argv[2]) != -1) // Example in the collection
352 {
353 // Security checks for new file name to verify category is included
354 int newCatIndex = TextFindIndex(argv[3], "_");
355 if (newCatIndex > 3)
356 {
357 char cat[12] = { 0 };
358 strncpy(cat, argv[3], newCatIndex);
359 bool newCatFound = false;
360 for (int i = 0; i < REXM_MAX_EXAMPLE_CATEGORIES; i++)
361 {
362 if (TextIsEqual(cat, exCategories[i])) { newCatFound = true; break; }
363 }
364
365 if (newCatFound)
366 {
367 strcpy(exName, argv[2]); // Register example name
368 strncpy(exCategory, exName, TextFindIndex(exName, "_"));
369 strcpy(exRename, argv[3]);
370 strncpy(exRecategory, exRename, TextFindIndex(exRename, "_"));
371 opCode = OP_RENAME;
372 }
373 else LOG("WARNING: Example new category is not valid\n");
374 }
375 else LOG("WARNING: Example new name does not include category\n");
376 }
377 else LOG("WARNING: RENAME: Example not available in the collection\n");
378 UnloadFileText(exColInfo);
379 }
380 }
381 else if (strcmp(argv[1], "remove") == 0)
382 {
383 // Check for valid upcoming argument
384 if (argc == 2) LOG("WARNING: No filename provided to create\n");
385 else if (argc > 3) LOG("WARNING: Too many arguments provided\n");
386 else
387 {
388 // Verify example exists in collection to be removed
389 char *exColInfo = LoadFileText(exCollectionFilePath);
390 if (TextFindIndex(exColInfo, argv[2]) != -1) // Example in the collection
391 {
392 strcpy(exName, argv[2]); // Register filename for removal
393 strncpy(exCategory, exName, TextFindIndex(exName, "_"));
394 opCode = OP_REMOVE;
395 }
396 else LOG("WARNING: REMOVE: Example not available in the collection\n");
397 UnloadFileText(exColInfo);
398 }
399 }
400 else if (strcmp(argv[1], "validate") == 0)
401 {
402 // Validate examples in collection (report results)
403 // All examples in collection match all files requirements
404
405 opCode = OP_VALIDATE;
406 }
407 else if (strcmp(argv[1], "update") == 0)
408 {
409 // Validate and update examples in collection
410 // All examples in collection match all files requirements
411
412 opCode = OP_UPDATE;
413 }
414 else if ((strcmp(argv[1], "build") == 0) || (strcmp(argv[1], "test") == 0) || (strcmp(argv[1], "testlog") == 0))
415 {
416 // Build/Test example(s) for PLATFORM_DESKTOP and PLATFORM_WEB
417 // NOTE: Build outputs to default directory, usually where the .c file is located,
418 // to avoid issues with copying resources (at least on Desktop)
419 // Web build files (.html, .wasm, .js, .data) are copied to raylib.com/examples repo
420 // Check for valid upcoming argument
421 if (argc == 2) LOG("WARNING: No example name/category provided\n");
422 else if (argc > 3) LOG("WARNING: Too many arguments provided\n");
423 else
424 {
425 // Support building/testing not only individual examples but multiple: ALL/<category>
426 int exBuildListInfoCount = 0;
427 rlExampleInfo *exBuildListInfo = LoadExampleData(argv[2], false, &exBuildListInfoCount);
428
429 for (int i = 0; i < exBuildListInfoCount; i++)
430 {
431 if (!TextIsEqual(exBuildListInfo[i].category, "others"))
432 {
433 exBuildList[exBuildListCount] = (char *)RL_CALLOC(256, sizeof(char));
434 strcpy(exBuildList[exBuildListCount], exBuildListInfo[i].name);
435 exBuildListCount++;
436 }
437 }
438
439 UnloadExampleData(exBuildListInfo);
440
441 if (exBuildListCount == 0) LOG("WARNING: BUILD: Example requested not available in the collection\n");
442 else
443 {
444 if (strcmp(argv[1], "build") == 0) opCode = OP_BUILD;
445 else if (strcmp(argv[1], "test") == 0) opCode = OP_TEST;
446 else if (strcmp(argv[1], "testlog") == 0) opCode = OP_TESTLOG;
447 }
448 }
449 }
450
451 // Process command line options arguments
452 for (int i = 1; i < argc; i++)
453 {
454 if ((strcmp(argv[i], "-h") == 0) || (strcmp(argv[i], "--help") == 0)) showUsage = true;
455 else if ((strcmp(argv[i], "-v") == 0) || (strcmp(argv[i], "--verbose") == 0)) verbose = true;
456 }
457 }
458
459 // Command-line usage mode: command execution
460 switch (opCode)
461 {
462 case OP_CREATE: // Create: New example from template
463 {
464 LOG("INFO: Command requested: CREATE\n");
465 LOG("INFO: Example to create: %s\n", exName);
466
467 // Create: raylib/examples/<category>/<category>_example_name.c
468 char *exText = LoadFileText(exTemplateFilePath);
469 char *exTextUpdated[6] = { 0 };
470 int exIndex = TextFindIndex(exText, "/****************");
471
472 // Update required info with some defaults
473 exTextUpdated[0] = TextReplaceAlloc(exText + exIndex, "<module>", exCategory);
474 exTextUpdated[1] = TextReplaceAlloc(exTextUpdated[0], "<name>", exName + strlen(exCategory) + 1);
475 //TextReplaceAlloc(newExample, "<user_name>", "Ray");
476 //TextReplaceAlloc(newExample, "@<user_github>", "@raysan5");
477 //TextReplaceAlloc(newExample, "<year_created>", 2026);
478 //TextReplaceAlloc(newExample, "<year_updated>", 2026);
479
480 SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), exTextUpdated[1]);
481 for (int i = 0; i < 6; i++) { MemFree(exTextUpdated[i]); exTextUpdated[i] = NULL; }
482 UnloadFileText(exText);
483 }
484 case OP_ADD: // Add: Example from command-line input filename
485 {
486 if (opCode != OP_CREATE) LOG("INFO: Command requested: ADD\n");
487 LOG("INFO: Example file to be added: %s\n", inFileName);
488
489 // Add: raylib/examples/<category>/<category>_example_name.c
490 if (opCode != OP_CREATE) FileCopy(inFileName, TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
491
492 // Create: raylib/examples/<category>/<category>_example_name.png
493 if (FileExists(TextFormat("%s/%s.png", GetDirectoryPath(inFileName), exName)))
494 {
495 LOG("INFO: [%s] Copying file screenshot...\n", GetFileName(inFileName));
496 FileCopy(TextFormat("%s/%s.png", GetDirectoryPath(inFileName), exName),
497 TextFormat("%s/%s/%s.png", exBasePath, exCategory, exName));
498 }
499 else // No screenshot available next to source file
500 {
501 // Copy screenshot template
502 LOG("WARNING: [%s] No screenshot found, using placeholder screenshot\n", GetFileName(inFileName));
503 FileCopy(exTemplateScreenshot, TextFormat("%s/%s/%s.png", exBasePath, exCategory, exName));
504 }
505
506 // Copy: raylib/examples/<category>/resources/...
507 // -----------------------------------------------------------------------------------------
508 // Scan resources used in example to copy
509 // NOTE: resources path will be relative to example source file directory
510 int resPathCount = 0;
511 LOG("INFO: [%s] Scanning file for resources...\n", GetFileName(inFileName));
512 char **resPaths = LoadExampleResourcePaths(TextFormat("%s/%s.c", GetDirectoryPath(inFileName), exName), &resPathCount);
513
514 if (resPathCount > 0)
515 {
516 LOG("INFO: [%s] Required resources found: %i\n", GetFileName(inFileName), resPathCount);
517
518 for (int r = 0; r < resPathCount; r++)
519 {
520 // WARNING: Special case to consider: shaders, resource paths could use conditions: "glsl%i"
521 // In this case, multiple resources are required: glsl100, glsl120, glsl330
522 if (TextFindIndex(resPaths[r], "glsl%i") > -1)
523 {
524 int glslVer[3] = { 100, 120, 330 };
525
526 for (int v = 0; v < 3; v++)
527 {
528 char *resPathUpdated = TextReplace(resPaths[r], "glsl%i", TextFormat("glsl%i", glslVer[v]));
529
530 LOG("INFO: [%s] Resource required [%i/%i]: %s\n", GetFileName(inFileName), r, resPathCount, resPathUpdated);
531
532 if (FileExists(TextFormat("%s/%s", GetDirectoryPath(inFileName), resPathUpdated)))
533 {
534 // Verify the resources are placed in "resources" directory
535 if (TextFindIndex(resPathUpdated, "resources/") > 0)
536 {
537 // NOTE: Look for resources in the path of the provided .c to be added
538 // To be copied to <category>/resources directory, extra dirs are automatically created if required
539 FileCopy(TextFormat("%s/%s", GetDirectoryPath(inFileName), resPathUpdated),
540 TextFormat("%s/%s/%s", exBasePath, exCategory, resPathUpdated));
541 }
542 else LOG("WARNING: Example resource must be placed in 'resources' directory next to .c file\n");
543 }
544 else LOG("WARNING: Example resource can not be found in: %s\n", TextFormat("%s/%s", GetDirectoryPath(inFileName), resPathUpdated));
545 }
546 }
547 else
548 {
549 LOG("INFO: [%s] Resource required [%i/%i]: %s\n", GetFileName(inFileName), r, resPathCount, resPaths[r]);
550
551 if (FileExists(TextFormat("%s/%s", GetDirectoryPath(inFileName), resPaths[r])))
552 {
553 // Verify the resources are placed in "resources" directory
554 if (TextFindIndex(resPaths[r], "resources/") > 0)
555 {
556 // NOTE: Look for resources in the path of the provided .c to be added
557 // To be copied to <category>/resources directory, extra dirs are automatically created if required
558 FileCopy(TextFormat("%s/%s", GetDirectoryPath(inFileName), resPaths[r]),
559 TextFormat("%s/%s/%s", exBasePath, exCategory, resPaths[r]));
560 }
561 else LOG("WARNING: Example resource must be placed in 'resources' directory next to .c file\n");
562 }
563 else LOG("WARNING: Example resource can not be found in: %s\n", TextFormat("%s/%s", GetDirectoryPath(inFileName), resPaths[r]));
564 }
565 }
566 }
567
568 UnloadExampleResourcePaths(resPaths);
569 // -----------------------------------------------------------------------------------------
570
571 // Add example to the collection list, if not already there
572 // NOTE: Required format: shapes;shapes_basic_shapes;★☆☆☆;1.0;4.2;2014;2026;"Ray";@raysan5
573 //------------------------------------------------------------------------------------------------
574 char *exCollectionList = LoadFileText(exCollectionFilePath);
575 if (TextFindIndex(exCollectionList, exName) == -1) // Example not found
576 {
577 LOG("INFO: [%s] Adding example to collection list (%s)\n", GetFileName(inFileName), exCategory);
578
579 char *exCollectionListUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1); // Updated list copy, 2MB
580
581 // Add example to the main list, by category
582 // by default add it last in the category list
583 // NOTE: When populating to other files, lists are sorted by name
584 int nextCategoryIndex = 0;
585 if (TextIsEqual(exCategory, "core")) nextCategoryIndex = 1;
586 else if (TextIsEqual(exCategory, "shapes")) nextCategoryIndex = 2;
587 else if (TextIsEqual(exCategory, "textures")) nextCategoryIndex = 3;
588 else if (TextIsEqual(exCategory, "text")) nextCategoryIndex = 4;
589 else if (TextIsEqual(exCategory, "models")) nextCategoryIndex = 5;
590 else if (TextIsEqual(exCategory, "shaders")) nextCategoryIndex = 6;
591 else if (TextIsEqual(exCategory, "audio")) nextCategoryIndex = 7;
592
593 // Get required example info from example file header (if provided)
594
595 // NOTE: Load example info from provided example header
596 rlExampleInfo *exInfo = LoadExampleInfo(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
597
598 LOG("INFO: [%s] Example info: \n", GetFileName(inFileName));
599 LOG(" > Author: %s (@%s)\n", exInfo->author, exInfo->authorGitHub);
600 LOG(" > Stars: %i\n", exInfo->stars);
601 LOG(" > Version-Update: %s-%s\n", exInfo->verCreated, exInfo->verUpdated);
602 LOG(" > Created-Reviewed: %i-%i\n", exInfo->yearCreated, exInfo->yearReviewed);
603
604 // Get example difficulty stars text
605 char starsText[16] = { 0 };
606 for (int i = 0; i < 4; i++)
607 {
608 // NOTE: Every UTF-8 star are 3 bytes
609 if (i < exInfo->stars) strcpy(starsText + 3*i, "★");
610 else strcpy(starsText + 3*i, "☆");
611 }
612
613 if (nextCategoryIndex == -1)
614 {
615 // Add example to collection at the EOF
616 int endIndex = (int)strlen(exCollectionList);
617 memcpy(exCollectionListUpdated, exCollectionList, endIndex);
618 sprintf(exCollectionListUpdated + endIndex, TextFormat("%s;%s;%s;%s;%s;%i;%i;\"%s\";@%s\n",
619 exInfo->category, exInfo->name, starsText, exInfo->verCreated, exInfo->verUpdated, exInfo->yearCreated, exInfo->yearReviewed, exInfo->author, exInfo->authorGitHub));
620 }
621 else
622 {
623 // Add example to collection, at the end of the category list
624 int categoryIndex = TextFindIndex(exCollectionList, exCategories[nextCategoryIndex]);
625 memcpy(exCollectionListUpdated, exCollectionList, categoryIndex);
626 int textWritenSize = sprintf(exCollectionListUpdated + categoryIndex, TextFormat("%s;%s;%s;%s;%s;%i;%i;\"%s\";@%s\n",
627 exInfo->category, exInfo->name, starsText, exInfo->verCreated, exInfo->verUpdated, exInfo->yearCreated, exInfo->yearReviewed, exInfo->author, exInfo->authorGitHub));
628 memcpy(exCollectionListUpdated + categoryIndex + textWritenSize, exCollectionList + categoryIndex, strlen(exCollectionList) - categoryIndex);
629 }
630
631 UnloadExampleInfo(exInfo);
632
633 SaveFileText(exCollectionFilePath, exCollectionListUpdated);
634 RL_FREE(exCollectionListUpdated);
635 }
636 else LOG("WARNING: ADD: Example is already on the collection\n");
637 UnloadFileText(exCollectionList);
638 //------------------------------------------------------------------------------------------------
639
640 // Update: Metadata, Makefile, Makefile.Web, README.md, examples.js
641 //------------------------------------------------------------------------------------------------
642 UpdateRequiredFiles();
643 //------------------------------------------------------------------------------------------------
644
645 // Create: raylib/projects/VS2022/examples/<category>_example_name.vcxproj
646 //------------------------------------------------------------------------------------------------
647 LOG("INFO: [%s] Creating example project\n", TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName));
648 // WARNING: When adding new project a unique UUID should be assigned!
649 FileCopy(TextFormat("%s/../projects/VS2022/examples/core_basic_window.vcxproj", exBasePath),
650 TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName));
651 FileTextReplace(TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName),
652 "core_basic_window", exName);
653 FileTextReplace(TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName),
654 "..\\..\\examples\\core", TextFormat("..\\..\\examples\\%s", exCategory));
655
656 // Edit: raylib/projects/VS2022/raylib.sln --> Add new example project
657 // WARNING: This function uses TextFormat() extensively inside,
658 // we must store provided file paths because pointers will be overwriten
659 // TODO: It seems projects are added to solution BUT not to required solution folder,
660 // that process still requires to be done manually
661 LOG("INFO: [%s] Adding project to raylib solution (.sln)\n",
662 TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName));
663 AddVSProjectToSolution(exVSProjectSolutionFile,
664 TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName), exCategory);
665 //------------------------------------------------------------------------------------------------
666
667 // Recompile example (on raylib side)
668 // NOTE: Tools requirements: emscripten, w64devkit
669 // Compile to: raylib.com/examples/<category>/<category>_example_name.html
670 // Compile to: raylib.com/examples/<category>/<category>_example_name.data
671 // Compile to: raylib.com/examples/<category>/<category>_example_name.wasm
672 // Compile to: raylib.com/examples/<category>/<category>_example_name.js
673 //------------------------------------------------------------------------------------------------
674 // WARNING 1: EMSDK_PATH must be set to proper location when calling from GitHub Actions
675 // WARNING 2: raylib.a and raylib.web.a must be available when compiling locally
676 #if defined(_WIN32)
677 LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: Win32)\n", GetFileNameWithoutExt(inFileName));
678 //putenv("RAYLIB_DIR=C:\\GitHub\\raylib");
679 _putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
680 system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
681 #else
682 LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: POSIX)\n", GetFileNameWithoutExt(inFileName));
683 system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
684 #endif
685 // Update generated .html metadata
686 LOG("INFO: [%s] Updating HTML Metadata...\n", TextFormat("%s.html", exName));
687 UpdateWebMetadata(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exName),
688 TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
689
690 // Copy results to web side
691 LOG("INFO: [%s] Copy example build to raylib.com\n", exName);
692 FileCopy(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exName),
693 TextFormat("%s/%s/%s.html", exWebPath, exCategory, exName));
694 FileCopy(TextFormat("%s/%s/%s.data", exBasePath, exCategory, exName),
695 TextFormat("%s/%s/%s.data", exWebPath, exCategory, exName));
696 FileCopy(TextFormat("%s/%s/%s.wasm", exBasePath, exCategory, exName),
697 TextFormat("%s/%s/%s.wasm", exWebPath, exCategory, exName));
698 FileCopy(TextFormat("%s/%s/%s.js", exBasePath, exCategory, exName),
699 TextFormat("%s/%s/%s.js", exWebPath, exCategory, exName));
700 //------------------------------------------------------------------------------------------------
701
702 } break;
703 case OP_RENAME: // Rename
704 {
705 LOG("INFO: Command requested: RENAME\n");
706 LOG("INFO: Example to be renamed: %s --> %s\n", exName, exRename);
707
708 // NOTE: At this point provided values have been validated:
709 // exName, exCategory, exRename, exRecategory
710 if (strcmp(exCategory, exRecategory) == 0)
711 {
712 // Rename example on collection
713 FileTextReplace(exCollectionFilePath, TextFormat("%s;%s", exCategory, exName),
714 TextFormat("%s;%s", exRecategory, exRename));
715
716 // Edit: Rename example code and screenshot files .c and .png
717 FileRename(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName),
718 TextFormat("%s/%s/%s.c", exBasePath, exCategory, exRename));
719 FileRename(TextFormat("%s/%s/%s.png", exBasePath, exCategory, exName),
720 TextFormat("%s/%s/%s.png", exBasePath, exCategory, exRename));
721
722 // Edit: Update example source code metadata
723 int exListCount = 0;
724 rlExampleInfo *exList = LoadExampleData(exCategory, false, &exListCount);
725 for (int i = 0; i < exListCount; i++)
726 {
727 if (strcmp(exList[i].name, exRename) == 0)
728 UpdateSourceMetadata(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exRename), &exList[i]);
729 }
730 UnloadExampleData(exList);
731
732 // NOTE: Example resource files do not need to be changed...
733 // unless the example is moved from one caegory to another
734
735 // Edit: Rename example on required files
736 FileTextReplace(TextFormat("%s/Makefile", exBasePath), exName, exRename);
737 FileTextReplace(TextFormat("%s/Makefile.Web", exBasePath), exName, exRename);
738 FileTextReplace(TextFormat("%s/README.md", exBasePath), exName, exRename);
739 FileTextReplace(TextFormat("%s/../common/examples.js", exWebPath),
740 exName + strlen(exCategory) + 1, exRename + strlen(exRecategory) + 1); // Skip category
741
742 // Edit: Rename example project and solution
743 FileTextReplace(TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName), exName, exRename);
744 FileRename(TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName),
745 TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exRename));
746 FileTextReplace(TextFormat("%s/../projects/VS2022/raylib.sln", exBasePath), exName, exRename);
747 }
748 else
749 {
750 // WARNING: Rename with change of category
751 // TODO: Reorder collection to place renamed example at the end of category
752 FileTextReplace(exCollectionFilePath, TextFormat("%s;%s", exCategory, exName),
753 TextFormat("%s;%s", exRecategory, exRename));
754
755 // TODO: Move example resources from <exCategory>/resources to <exRecategory>/resources
756 // WARNING: Resources can be shared with other examples in the category
757
758 // Edit: Rename example code file (copy and remove)
759 FileCopy(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName),
760 TextFormat("%s/%s/%s.c", exBasePath, exCategory, exRename));
761 FileRemove(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
762 // Edit: Rename example screenshot file (copy and remove)
763 FileCopy(TextFormat("%s/%s/%s.png", exBasePath, exCategory, exName),
764 TextFormat("%s/%s/%s.png", exBasePath, exCategory, exRename));
765 FileRemove(TextFormat("%s/%s/%s.png", exBasePath, exCategory, exName));
766
767 // Edit: Update required files: Makefile, Makefile.Web, README.md, examples.js
768 UpdateRequiredFiles();
769 }
770
771 // Remove old web compilation
772 FileRemove(TextFormat("%s/%s/%s.html", exWebPath, exCategory, exName));
773 FileRemove(TextFormat("%s/%s/%s.data", exWebPath, exCategory, exName));
774 FileRemove(TextFormat("%s/%s/%s.wasm", exWebPath, exCategory, exName));
775 FileRemove(TextFormat("%s/%s/%s.js", exWebPath, exCategory, exName));
776
777 // Recompile example (on raylib side)
778 // WARNING: EMSDK_PATH must be set to proper location when calling from GitHub Actions
779 #if defined(_WIN32)
780 _putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
781 system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exRecategory, exRename));
782 #else
783 system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exRecategory, exRename));
784 #endif
785 // Update generated .html metadata
786 UpdateWebMetadata(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exRename),
787 TextFormat("%s/%s/%s.c", exBasePath, exCategory, exRename));
788
789 // Copy results to web side
790 FileCopy(TextFormat("%s/%s/%s.html", exBasePath, exRecategory, exRename),
791 TextFormat("%s/%s/%s.html", exWebPath, exRecategory, exRename));
792 FileCopy(TextFormat("%s/%s/%s.data", exBasePath, exRecategory, exRename),
793 TextFormat("%s/%s/%s.data", exWebPath, exRecategory, exRename));
794 FileCopy(TextFormat("%s/%s/%s.wasm", exBasePath, exRecategory, exRename),
795 TextFormat("%s/%s/%s.wasm", exWebPath, exRecategory, exRename));
796 FileCopy(TextFormat("%s/%s/%s.js", exBasePath, exRecategory, exRename),
797 TextFormat("%s/%s/%s.js", exWebPath, exRecategory, exRename));
798
799 #if defined(RENAME_AUTO_COMMIT_CREATION)
800 // Create GitHub commit with changes (local)
801 putenv("PATH=%PATH%;C:\\Program Files\\Git\\bin");
802 ChangeDirectory("C:\\GitHub\\raylib");
803 system("git --version");
804 system("git status");
805 system("git add -A");
806 int result = system(TextFormat("git commit -m \"REXM: RENAME: example: `%s` --> `%s`\"", exName, exRename)); // Commit changes (only tracked files)
807 if (result != 0) LOG("WARNING: Error committing changes\n");
808 ChangeDirectory("C:/GitHub/raylib.com");
809 system("git add -A");
810 result = system(TextFormat("git commit -m \"REXM: RENAME: example: `%s` --> `%s`\"", exName, exRename)); // Commit changes (only tracked files)
811 if (result != 0) LOG("WARNING: Error committing changes\n");
812 //result = system("git push"); // Push to the remote (origin, current branch)
813 //if (result != 0) LOG("WARNING: Error pushing changes\n");
814 #endif
815
816 } break;
817 case OP_REMOVE: // Remove
818 {
819 LOG("INFO: Command requested: REMOVE\n");
820 LOG("INFO: Example to be removed: %s\n", exName);
821
822 // Remove example from collection for files update
823 //------------------------------------------------------------------------------------------------
824 LOG("INFO: [%s] Removing example from collection\n", exName);
825 char *exCollectionList = LoadFileText(exCollectionFilePath);
826 int exIndex = TextFindIndex(exCollectionList, TextFormat("%s;%s", exCategory, exName));
827 if (exIndex > 0) // Example found
828 {
829 char *exCollectionListUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1); // Updated list copy, 2MB
830
831 memcpy(exCollectionListUpdated, exCollectionList, exIndex);
832 int lineLen = 0;
833 for (int i = exIndex; (exCollectionList[i] != '\n') && (exCollectionList[i] != '\0'); i++) lineLen++;
834 // Remove line and copy the rest next
835 memcpy(exCollectionListUpdated + exIndex, exCollectionList + exIndex + lineLen + 1, strlen(exCollectionList) - exIndex - lineLen);
836
837 SaveFileText(exCollectionFilePath, exCollectionListUpdated);
838 RL_FREE(exCollectionListUpdated);
839 }
840 else LOG("WARNING: REMOVE: Example not found in the collection\n");
841 UnloadFileText(exCollectionList);
842 //------------------------------------------------------------------------------------------------
843
844 // Remove: raylib/examples/<category>/resources/..
845 // WARNING: Some of those resources could be used by other examples,
846 // just leave this process to manual update for now!
847 // -----------------------------------------------------------------------------------------
848 /*
849 // Scan resources used in example to be removed
850 int resPathCount = 0;
851 char **resPaths = ScanExampleResources(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), &resPathCount);
852
853 if (resPathCount > 0)
854 {
855 for (int r = 0; r < resPathCount; r++)
856 {
857 // WARNING: Special case to consider: shaders, resource paths could use conditions: "glsl%i"
858 // In this case, multiple resources are required: glsl100, glsl120, glsl330
859 if (TextFindIndex(resPaths[r], "glsl%i") > -1)
860 {
861 int glslVer[3] = { 100, 120, 330 };
862
863 for (int v = 0; v < 3; v++)
864 {
865 FileRemove(TextFormat("%s/%s/%s", exBasePath, exCategory, TextReplace(resPaths[r], "glsl%i", TextFormat("glsl%i", glslVer[v]))));
866 }
867 }
868 else FileRemove(TextFormat("%s/%s/%s", exBasePath, exCategory, resPaths[r]));
869 }
870 }
871
872 ClearExampleResources(resPaths);
873 */
874 // -----------------------------------------------------------------------------------------
875
876 // Remove: raylib/examples/<category>/<category>_example_name.c
877 // Remove: raylib/examples/<category>/<category>_example_name.png
878 LOG("INFO: [%s] Removing example code file\n", TextFormat("%s.c", exName));
879 FileRemove(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
880 LOG("INFO: [%s] Removing example screenshot file\n", TextFormat("%s.png", exName));
881 FileRemove(TextFormat("%s/%s/%s.png", exBasePath, exCategory, exName));
882
883 // Edit: Update required files: Makefile, Makefile.Web, README.md, examples.js
884 UpdateRequiredFiles();
885
886 // Remove: raylib/projects/VS2022/examples/<category>_example_name.vcxproj
887 LOG("INFO: [%s] Removing example project file\n", TextFormat("%s.vcxproj", exName));
888 FileRemove(TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exName));
889
890 // Edit: raylib/projects/VS2022/raylib.sln --> Remove example project
891 LOG("INFO: [%s] Removing example from raylib solution (.sln)\n", exName);
892 RemoveVSProjectFromSolution(TextFormat("%s/../projects/VS2022/raylib.sln", exBasePath), exName);
893
894 // Remove: Delete example build from local copy (if exists)
895 FileRemove(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exName));
896 FileRemove(TextFormat("%s/%s/%s.data", exBasePath, exCategory, exName));
897 FileRemove(TextFormat("%s/%s/%s.wasm", exBasePath, exCategory, exName));
898 FileRemove(TextFormat("%s/%s/%s.js", exBasePath, exCategory, exName));
899
900 // Remove: raylib.com/examples/<category>/<category>_example_name.html
901 // Remove: raylib.com/examples/<category>/<category>_example_name.data
902 // Remove: raylib.com/examples/<category>/<category>_example_name.wasm
903 // Remove: raylib.com/examples/<category>/<category>_example_name.js
904 LOG("INFO: [%s] Deleting example from raylib.com\n", exName);
905 FileRemove(TextFormat("%s/%s/%s.html", exWebPath, exCategory, exName));
906 FileRemove(TextFormat("%s/%s/%s.data", exWebPath, exCategory, exName));
907 FileRemove(TextFormat("%s/%s/%s.wasm", exWebPath, exCategory, exName));
908 FileRemove(TextFormat("%s/%s/%s.js", exWebPath, exCategory, exName));
909
910 } break;
911 case OP_BUILD:
912 {
913 LOG("INFO: Command requested: BUILD\n");
914 LOG("INFO: Example(s) to be built: %i [%s]\n", exBuildListCount, (exBuildListCount == 1)? exBuildList[0] : argv[2]);
915
916 #if defined(_WIN32)
917 // Set required environment variables
918 //putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath));
919 _putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
920 //putenv("MAKE=mingw32-make");
921 //ChangeDirectory(exBasePath);
922 #endif
923 for (int i = 0; i < exBuildListCount; i++)
924 {
925 // Get example name and category
926 memset(exName, 0, 64);
927 strcpy(exName, exBuildList[i]);
928 memset(exCategory, 0, 32);
929 strncpy(exCategory, exName, TextFindIndex(exName, "_"));
930
931 LOG("INFO: [%i/%i] Building example: [%s]\n", i + 1, exBuildListCount, exName);
932
933 // Build example for PLATFORM_DESKTOP
934 #if defined(_WIN32)
935 LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: Win32)\n", exName);
936 system(TextFormat("mingw32-make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exCategory, exName));
937 #elif defined(PLATFORM_DRM)
938 LOG("INFO: [%s] Building example for PLATFORM_DRM (Host: POSIX)\n", exName);
939 system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DRM -B > %s/%s/logs/%s.build.log 2>&1",
940 exBasePath, exCategory, exName, exBasePath, exCategory, exName));
941 #else
942 LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: POSIX)\n", exName);
943 system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B", exBasePath, exCategory, exName));
944 #endif
945
946 #if !defined(PLATFORM_DRM)
947 // Build example for PLATFORM_WEB
948 // Build: raylib.com/examples/<category>/<category>_example_name.html
949 // Build: raylib.com/examples/<category>/<category>_example_name.data
950 // Build: raylib.com/examples/<category>/<category>_example_name.wasm
951 // Build: raylib.com/examples/<category>/<category>_example_name.js
952 #if defined(_WIN32)
953 LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: Win32)\n", exName);
954 system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
955 #else
956 LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: POSIX)\n", exName);
957 system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
958 #endif
959 // Update generated .html metadata
960 LOG("INFO: [%s] Updating HTML Metadata...\n", TextFormat("%s.html", exName));
961 UpdateWebMetadata(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exName),
962 TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
963
964 // Copy results to web side
965 LOG("INFO: [%s] Copy example build to raylib.com\n", exName);
966 FileCopy(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exName),
967 TextFormat("%s/%s/%s.html", exWebPath, exCategory, exName));
968 FileCopy(TextFormat("%s/%s/%s.data", exBasePath, exCategory, exName),
969 TextFormat("%s/%s/%s.data", exWebPath, exCategory, exName));
970 FileCopy(TextFormat("%s/%s/%s.wasm", exBasePath, exCategory, exName),
971 TextFormat("%s/%s/%s.wasm", exWebPath, exCategory, exName));
972 FileCopy(TextFormat("%s/%s/%s.js", exBasePath, exCategory, exName),
973 TextFormat("%s/%s/%s.js", exWebPath, exCategory, exName));
974 #endif // !PLATFORM_DRM
975
976 // Once example processed, free memory from list
977 RL_FREE(exBuildList[i]);
978 }
979
980 } break;
981 case OP_VALIDATE: // Validate: report and actions
982 case OP_UPDATE:
983 {
984 LOG("INFO: Command requested: %s\n", (opCode == OP_VALIDATE)? "VALIDATE" : "UPDATE");
985 LOG("INFO: Example collection is being %s\n", (opCode == OP_VALIDATE)? "validated" : "validated and updated");
986 /*
987 // Validation flags available:
988 VALID_MISSING_C
989 VALID_MISSING_PNG
990 VALID_INVALID_PNG
991 VALID_MISSING_RESOURCES
992 VALID_MISSING_VCXPROJ
993 VALID_NOT_IN_VCXSOL
994 VALID_NOT_IN_MAKEFILE
995 VALID_NOT_IN_MAKEFILE_WEB
996 VALID_NOT_IN_README
997 VALID_NOT_IN_JS
998 VALID_INCONSISTENT_INFO
999 VALID_MISSING_WEB_OUTPUT
1000 VALID_INVALID_CATEGORY
1001 */
1002
1003 // Validate and update examples collection list
1004 // NOTE: New .c examples found are added at the end of its category
1005 //---------------------------------------------------------------------------------------------------
1006 // Scan available example .c files and add to collection missing ones
1007 // NOTE: Source of truth is what we have in the examples directories (on validation/update)
1008 LOG("INFO: Scanning available example (.c) files to be added to collection...\n");
1009 FilePathList clist = LoadDirectoryFilesEx(exBasePath, ".c", true);
1010
1011 // Load examples collection list file (raylib/examples/examples_list.txt)
1012 char *exList = LoadFileText(exCollectionFilePath);
1013 int exListLen = (int)strlen(exList);
1014
1015 char *exListUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1);
1016 bool listUpdated = false;
1017
1018 // Add new examples to the collection list if not found
1019 // WARNING: Added to the end of category, order defines place on raylib webpage
1020 for (unsigned int i = 0; i < clist.count; i++)
1021 {
1022 // NOTE: Skipping "examples_template" from checks
1023 if (!TextIsEqual(GetFileNameWithoutExt(clist.paths[i]), "examples_template") &&
1024 (TextFindIndex(exList, GetFileNameWithoutExt(clist.paths[i])) == -1))
1025 {
1026 // Get new example data
1027 rlExampleInfo *exInfo = LoadExampleInfo(clist.paths[i]);
1028
1029 // Get example category, -1 if not found in list
1030 int catIndex = GetTextListIndex(exInfo->category, exCategories, REXM_MAX_EXAMPLE_CATEGORIES);
1031
1032 if (catIndex > -1)
1033 {
1034 int nextCatIndex = catIndex + 1;
1035 if (nextCatIndex > (REXM_MAX_EXAMPLE_CATEGORIES - 1)) nextCatIndex = -1; // EOF
1036
1037 // Find position to add new example on list, just before the following category
1038 // Category order: core, shapes, textures, text, models, shaders, audio
1039 int exListNextCatIndex = -1;
1040 if (nextCatIndex != -1) exListNextCatIndex = TextFindIndex(exList, TextFormat("\n%s", exCategories[nextCatIndex])) + 1;
1041 else exListNextCatIndex = exListLen; // EOF
1042
1043 strncpy(exListUpdated, exList, exListNextCatIndex);
1044
1045 // Get example difficulty stars
1046 char starsText[16] = { 0 };
1047 for (int s = 0; s < 4; s++)
1048 {
1049 // NOTE: Every UTF-8 star are 3 bytes
1050 if (s < exInfo->stars) strcpy(starsText + 3*s, "★");
1051 else strcpy(starsText + 3*s, "☆");
1052 }
1053
1054 // Add new example to the list
1055 int exListNewExLen = sprintf(exListUpdated + exListNextCatIndex,
1056 TextFormat("%s;%s;%s;%s;%s;%i;%i;\"%s\";@%s\n",
1057 exInfo->category, exInfo->name, starsText, exInfo->verCreated,
1058 exInfo->verUpdated, exInfo->yearCreated, exInfo->yearReviewed,
1059 exInfo->author, exInfo->authorGitHub));
1060
1061 // Add the following examples to the end of collection list
1062 strncpy(exListUpdated + exListNextCatIndex + exListNewExLen, exList + exListNextCatIndex, exListLen - exListNextCatIndex);
1063
1064 listUpdated = true;
1065 }
1066
1067 UnloadExampleInfo(exInfo);
1068 }
1069 }
1070
1071 /*
1072 // Check and remove duplicate example entries
1073 int lineCount = 0;
1074 char **exListLines = LoadTextLines(exList, &lineCount);
1075 int exListUpdatedOffset = 0;
1076 exListUpdatedOffset = sprintf(exListUpdated, "%s\n", exListLines[0]);
1077
1078 for (int i = 1; i < lineCount; i++)
1079 {
1080 if ((TextFindIndex(exListUpdated, exListLines[i]) == -1) || (exListLines[i][0] == '#'))
1081 exListUpdatedOffset += sprintf(exListUpdated + exListUpdatedOffset, "%s\n", exListLines[i]);
1082 else listUpdated = true;
1083 }
1084
1085 UnloadTextLines(exListLines, lineCount);
1086 */
1087
1088 if (listUpdated) SaveFileText(exCollectionFilePath, exListUpdated);
1089
1090 UnloadFileText(exList);
1091 RL_FREE(exListUpdated);
1092
1093 UnloadDirectoryFiles(clist);
1094 //---------------------------------------------------------------------------------------------------
1095
1096 // Check all examples in collection [examples_list.txt] -> Source of truth!
1097 LOG("INFO: Validating examples in collection...\n");
1098 int exCollectionCount = 0;
1099 rlExampleInfo *exCollection = LoadExampleData("ALL", false, &exCollectionCount);
1100
1101 // Set status information for all examples, using "status" field in the struct
1102 for (int i = 0; i < exCollectionCount; i++)
1103 {
1104 rlExampleInfo *exInfo = &exCollection[i];
1105 exInfo->status = 0;
1106
1107 LOG("INFO: [%s] Validating example...\n", exInfo->name);
1108
1109 // Validate: raylib/examples/<category>/<category>_example_name.c -> File exists?
1110 if (!FileExists(TextFormat("%s/%s/%s.c", exBasePath, exInfo->category, exInfo->name))) exInfo->status |= VALID_MISSING_C;
1111
1112 // Validate: raylib/examples/<category>/<category>_example_name.png -> File exists?
1113 if (!FileExists(TextFormat("%s/%s/%s.png", exBasePath, exInfo->category, exInfo->name))) exInfo->status |= VALID_MISSING_PNG;
1114
1115 // Validate: example screenshot is not the template default one
1116 Image imScreenshot = LoadImage(TextFormat("%s/%s/%s.png", exBasePath, exInfo->category, exInfo->name));
1117 Image imTemplate = LoadImage(TextFormat("%s/examples_template.png", exBasePath));
1118 if (memcmp(imScreenshot.data, imTemplate.data, GetPixelDataSize(imScreenshot.width, imScreenshot.height, imScreenshot.format)) == 0)
1119 exInfo->status |= VALID_INVALID_PNG;
1120 UnloadImage(imTemplate);
1121 UnloadImage(imScreenshot);
1122
1123 // Validate: raylib/examples/Makefile -> Example listed?
1124 if (FileTextFindIndex(TextFormat("%s/Makefile", exBasePath), exInfo->name) == -1) exInfo->status |= VALID_NOT_IN_MAKEFILE;
1125
1126 // Validate: raylib/examples/Makefile.Web -> Example listed?
1127 if (FileTextFindIndex(TextFormat("%s/Makefile.Web", exBasePath), exInfo->name) == -1) exInfo->status |= VALID_NOT_IN_MAKEFILE_WEB;
1128
1129 // Validate: raylib/examples/README.md -> Example listed?
1130 if (FileTextFindIndex(TextFormat("%s/README.md", exBasePath), exInfo->name) == -1) exInfo->status |= VALID_NOT_IN_README;
1131
1132 // Validate: raylib.com/common/examples.js -> Example listed?
1133 if (FileTextFindIndex(TextFormat("%s/../common/examples.js", exWebPath), exInfo->name + TextFindIndex(exInfo->name, "_") + 1) == -1) exInfo->status |= VALID_NOT_IN_JS;
1134
1135 // Validate: raylib/projects/VS2022/examples/<category>_example_name.vcxproj -> File exists?
1136 if (!FileExists(TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exInfo->name))) exInfo->status |= VALID_MISSING_VCXPROJ;
1137
1138 // Validate: raylib/projects/VS2022/raylib.sln -> Example listed?
1139 if (FileTextFindIndex(TextFormat("%s/../projects/VS2022/raylib.sln", exBasePath), exInfo->name) == -1) exInfo->status |= VALID_NOT_IN_VCXSOL;
1140
1141 // Validate: raylib/examples/<category>/resources/.. -> Example resources available?
1142 // Scan resources used in example to check for missing resource files
1143 // WARNING: Some paths could be for files to save, not files to load, verify it
1144 char **resPaths = LoadExampleResourcePaths(TextFormat("%s/%s/%s.c", exBasePath, exInfo->category, exInfo->name), &exInfo->resCount);
1145 if (exInfo->resCount > 0)
1146 {
1147 for (int r = 0; r < exInfo->resCount; r++)
1148 {
1149 // WARNING: Special case to consider: shaders, resource paths could use conditions: "glsl%i"
1150 // In this case, multiple resources are required: glsl100, glsl120, glsl330
1151 if (TextFindIndex(resPaths[r], "glsl%i") > -1)
1152 {
1153 int glslVer[3] = { 100, 120, 330 };
1154
1155 for (int v = 0; v < 3; v++)
1156 {
1157 char *resPathUpdated = TextReplace(resPaths[r], "glsl%i", TextFormat("glsl%i", glslVer[v]));
1158 if (!FileExists(TextFormat("%s/%s/%s", exBasePath, exInfo->category, resPathUpdated)))
1159 {
1160 exInfo->status |= VALID_MISSING_RESOURCES;
1161 // Logging missing resources for convenience
1162 LOG("WARNING: [%s] Missing resource: %s\n", exInfo->name, resPathUpdated);
1163 }
1164 }
1165 }
1166 else
1167 {
1168 if (!FileExists(TextFormat("%s/%s/%s", exBasePath, exInfo->category, resPaths[r])))
1169 {
1170 exInfo->status |= VALID_MISSING_RESOURCES;
1171 LOG("WARNING: [%s] Missing resource: %s\n", exInfo->name, resPaths[r]);
1172 }
1173 }
1174 }
1175 }
1176 UnloadExampleResourcePaths(resPaths);
1177
1178 // Validate: raylib.com/examples/<category>/<category>_example_name.html -> File exists?
1179 // Validate: raylib.com/examples/<category>/<category>_example_name.data -> File exists?
1180 // Validate: raylib.com/examples/<category>/<category>_example_name.wasm -> File exists?
1181 // Validate: raylib.com/examples/<category>/<category>_example_name.js -> File exists?
1182 if (!TextIsEqual(exInfo->category, "others") &&
1183 (!FileExists(TextFormat("%s/%s/%s.html", exWebPath, exInfo->category, exInfo->name)) ||
1184 !FileExists(TextFormat("%s/%s/%s.wasm", exWebPath, exInfo->category, exInfo->name)) ||
1185 !FileExists(TextFormat("%s/%s/%s.js", exWebPath, exInfo->category, exInfo->name)) ||
1186 ((exInfo->resCount > 0) && !FileExists(TextFormat("%s/%s/%s.data", exWebPath, exInfo->category, exInfo->name)))))
1187 {
1188 exInfo->status |= VALID_MISSING_WEB_OUTPUT;
1189 }
1190
1191 // Validate: raylib.com/examples/<category>/<category>_example_name.html -> Metadata
1192 if (FileExists(TextFormat("%s/%s/%s.html", exWebPath, exInfo->category, exInfo->name)))
1193 {
1194 char *exHtmlText = LoadFileText(TextFormat("%s/%s/%s.html", exWebPath, exInfo->category, exInfo->name));
1195
1196 if ((TextFindIndex(exHtmlText, "raylib web game") > -1) || // title
1197 (TextFindIndex(exHtmlText, "New raylib web videogame, developed using raylib videogames library") > -1) || // description
1198 (TextFindIndex(exHtmlText, "https://www.raylib.com/common/raylib_logo.png") > -1) || // image
1199 (TextFindIndex(exHtmlText, "https://www.raylib.com/games.html") > -1) || // url
1200 (TextFindIndex(exHtmlText, "https://github.com/raysan5/raylib';") > -1)) // source code button
1201 {
1202 exInfo->status |= VALID_MISSING_WEB_METADATA;
1203 }
1204
1205 UnloadFileText(exHtmlText);
1206 }
1207
1208 // NOTE: Additional validation elements
1209 // Validate: Example naming conventions: <category>/<category>_example_name, valid category
1210 if ((TextFindIndex(exInfo->name, exInfo->category) == -1) ||
1211 (!TextIsEqual(exInfo->category, "core") && !TextIsEqual(exInfo->category, "shapes") &&
1212 !TextIsEqual(exInfo->category, "textures") && !TextIsEqual(exInfo->category, "text") &&
1213 !TextIsEqual(exInfo->category, "models") && !TextIsEqual(exInfo->category, "shaders") &&
1214 !TextIsEqual(exInfo->category, "audio") && !TextIsEqual(exInfo->category, "others"))) exInfo->status |= VALID_INVALID_CATEGORY;
1215
1216 // Validate: Example info (stars, author, github) missmatches with example header content
1217 rlExampleInfo *exInfoHeader = LoadExampleInfo(TextFormat("%s/%s/%s.c", exBasePath, exInfo->category, exInfo->name));
1218
1219 if ((strcmp(exInfo->name, exInfoHeader->name) != 0) || // NOTE: Get it from example, not file
1220 (strcmp(exInfo->category, exInfoHeader->category) != 0) ||
1221 (strcmp(exInfo->author, exInfoHeader->author) != 0) ||
1222 (strcmp(exInfo->authorGitHub, exInfoHeader->authorGitHub) != 0) ||
1223 (exInfo->stars != exInfoHeader->stars) ||
1224 (strcmp(exInfo->verCreated, exInfoHeader->verCreated) != 0) ||
1225 (strcmp(exInfo->verUpdated, exInfoHeader->verUpdated) != 0))
1226 {
1227 exInfo->status |= VALID_INCONSISTENT_INFO;
1228 }
1229
1230 if (exInfo->status == 0) LOG("INFO: [%s] Validation result: OK\n", exInfo->name);
1231 else LOG("WARNING: [%s] Validation result: ISSUES FOUND\n", exInfo->name);
1232
1233 UnloadExampleInfo(exInfoHeader);
1234 }
1235
1236 if (opCode == OP_UPDATE)
1237 {
1238 LOG("INFO: Updating examples with issues in collection...\n");
1239
1240 // Actions to fix/review anything possible from validation results
1241 //------------------------------------------------------------------------------------------------
1242 // Update files: Makefile, Makefile.Web, README.md, examples.js
1243 // Solves: VALID_NOT_IN_MAKEFILE, VALID_NOT_IN_MAKEFILE_WEB, VALID_NOT_IN_README, VALID_NOT_IN_JS
1244 // WARNING: Makefile.Web needs to be updated before trying to rebuild web example!
1245 UpdateRequiredFiles();
1246 for (int i = 0; i < exCollectionCount; i++)
1247 {
1248 exCollection[i].status &= ~VALID_NOT_IN_MAKEFILE;
1249 exCollection[i].status &= ~VALID_NOT_IN_MAKEFILE_WEB;
1250 exCollection[i].status &= ~VALID_NOT_IN_README;
1251 exCollection[i].status &= ~VALID_NOT_IN_JS;
1252 }
1253
1254 // Check examples "status" information
1255 for (int i = 0; i < exCollectionCount; i++)
1256 {
1257 rlExampleInfo *exInfo = &exCollection[i];
1258
1259 if (exInfo->status & VALID_MISSING_C) LOG("WARNING: [%s] Missing code file\n", exInfo->name);
1260 else
1261 {
1262 // NOTE: Some issues can not be automatically fixed, only logged
1263 if (exInfo->status & VALID_MISSING_PNG) LOG("WARNING: [%s] Missing screenshot file\n", exInfo->name);
1264 if (exInfo->status & VALID_INVALID_PNG) LOG("WARNING: [%s] Invalid screenshot file (using template)\n", exInfo->name);
1265 if (exInfo->status & VALID_MISSING_RESOURCES) LOG("WARNING: [%s] Missing resources detected\n", exInfo->name);
1266 if (exInfo->status & VALID_INCONSISTENT_INFO) LOG("WARNING: [%s] Inconsistent example header info\n", exInfo->name);
1267 if (exInfo->status & VALID_INVALID_CATEGORY) LOG("WARNING: [%s] Invalid example category\n", exInfo->name);
1268
1269 // NOTE: Some examples should be excluded from VS2022 solution because
1270 // they have specific platform/linkage requirements:
1271 if ((strcmp(exInfo->name, "web_basic_window") == 0) ||
1272 (strcmp(exInfo->name, "raylib_opengl_interop") == 0)) continue;
1273
1274 // Review: Add: raylib/projects/VS2022/examples/<category>_example_name.vcxproj
1275 // Review: Add: raylib/projects/VS2022/raylib.sln
1276 // Solves: VALID_MISSING_VCXPROJ, VALID_NOT_IN_VCXSOL
1277 if (exInfo->status & VALID_MISSING_VCXPROJ)
1278 {
1279 LOG("WARNING: [%s] Missing VS2022 project file\n", exInfo->name);
1280 LOG("INFO: [%s.vcxproj] Creating VS2022 project file\n", exInfo->name);
1281 FileCopy(TextFormat("%s/../projects/VS2022/examples/core_basic_window.vcxproj", exBasePath),
1282 TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exInfo->name));
1283 FileTextReplace(TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exInfo->name),
1284 "core_basic_window", exInfo->name);
1285 FileTextReplace(TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exInfo->name),
1286 "..\\..\\examples\\core", TextFormat("..\\..\\examples\\%s", exInfo->category));
1287
1288 exInfo->status &= ~VALID_MISSING_VCXPROJ;
1289 }
1290
1291 // Add project (.vcxproj) to raylib solution (.sln)
1292 if (exInfo->status & VALID_NOT_IN_VCXSOL)
1293 {
1294 LOG("WARNING: [%s.vcxproj] Project not included in raylib solution (.sln)\n", exInfo->name);
1295 LOG("INFO: [%s.vcxproj] Adding project to raylib solution (.sln)\n", exInfo->name);
1296 AddVSProjectToSolution(exVSProjectSolutionFile,
1297 TextFormat("%s/../projects/VS2022/examples/%s.vcxproj", exBasePath, exInfo->name), exInfo->category);
1298
1299 exInfo->status &= ~VALID_NOT_IN_VCXSOL;
1300 }
1301
1302 // Review: Add/Remove: raylib.com/examples/<category>/<category>_example_name.html
1303 // Review: Add/Remove: raylib.com/examples/<category>/<category>_example_name.data
1304 // Review: Add/Remove: raylib.com/examples/<category>/<category>_example_name.wasm
1305 // Review: Add/Remove: raylib.com/examples/<category>/<category>_example_name.js
1306 // Solves: VALID_MISSING_WEB_OUTPUT
1307 if ((strcmp(exInfo->category, "others") != 0) && // Skipping "others" category
1308 ((exInfo->status & VALID_MISSING_WEB_OUTPUT) || (exInfo->status & VALID_MISSING_WEB_METADATA)))
1309 {
1310 LOG("WARNING: [%s] Example not available on raylib web\n", exInfo->name);
1311
1312 // Build example for PLATFORM_WEB
1313 #if defined(_WIN32)
1314 LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: Win32)\n", exInfo->name);
1315 _putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
1316 system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exInfo->category, exInfo->name));
1317 #else
1318 LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: POSIX)\n", exInfo->name);
1319 system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exInfo->category, exInfo->name));
1320 #endif
1321
1322 // Update generated .html metadata
1323 LOG("INFO: [%s.html] Updating HTML Metadata...\n", exInfo->name);
1324 UpdateWebMetadata(TextFormat("%s/%s/%s.html", exBasePath, exInfo->category, exInfo->name),
1325 TextFormat("%s/%s/%s.c", exBasePath, exInfo->category, exInfo->name));
1326
1327 // Copy results to web side
1328 LOG("INFO: [%s] Copy example build to raylib.com\n", exInfo->name);
1329 FileCopy(TextFormat("%s/%s/%s.html", exBasePath, exInfo->category, exInfo->name),
1330 TextFormat("%s/%s/%s.html", exWebPath, exInfo->category, exInfo->name));
1331 FileCopy(TextFormat("%s/%s/%s.data", exBasePath, exInfo->category, exInfo->name),
1332 TextFormat("%s/%s/%s.data", exWebPath, exInfo->category, exInfo->name));
1333 FileCopy(TextFormat("%s/%s/%s.wasm", exBasePath, exInfo->category, exInfo->name),
1334 TextFormat("%s/%s/%s.wasm", exWebPath, exInfo->category, exInfo->name));
1335 FileCopy(TextFormat("%s/%s/%s.js", exBasePath, exInfo->category, exInfo->name),
1336 TextFormat("%s/%s/%s.js", exWebPath, exInfo->category, exInfo->name));
1337
1338 exInfo->status &= ~VALID_MISSING_WEB_OUTPUT;
1339 exInfo->status &= ~VALID_MISSING_WEB_METADATA;
1340 }
1341
1342 if (exInfo->status & VALID_INCONSISTENT_INFO)
1343 {
1344 // Update source code header info
1345 LOG("WARNING: [%s.c] Inconsistent source code metadata\n", exInfo->name);
1346 LOG("INFO: [%s.c] Updating source code metadata...\n", exInfo->name);
1347 UpdateSourceMetadata(TextFormat("%s/%s/%s.c", exBasePath, exInfo->category, exInfo->name), exInfo);
1348
1349 exInfo->status &= ~VALID_INCONSISTENT_INFO;
1350 }
1351 }
1352 }
1353 //------------------------------------------------------------------------------------------------
1354 }
1355
1356 // Generate validation report/table with results (.md)
1357 //-----------------------------------------------------------------------------------------------------
1358 /*
1359 Columns:
1360 [C] VALID_MISSING_C // Missing .c source file
1361 [PNG] VALID_MISSING_PNG // Missing screenshot .png
1362 [WPNG] VALID_INVALID_PNG // Invalid png screenshot (using template one)
1363 [RES] VALID_MISSING_RESOURCES // Missing resources listed in the code
1364 [VCX] VALID_MISSING_VCXPROJ // Missing Visual Studio .vcxproj file
1365 [SOL] VALID_NOT_IN_VCXSOL // Project not included in solution file
1366 [MK] VALID_NOT_IN_MAKEFILE // Not listed in Makefile
1367 [MKWEB] VALID_NOT_IN_MAKEFILE_WEB // Not listed in Makefile.Web
1368 [RDME] VALID_NOT_IN_README // Not listed in README.md
1369 [JS] VALID_NOT_IN_JS // Not listed in examples.js
1370 [WOUT] VALID_MISSING_WEB_OUTPUT // Missing .html/.data/.wasm/.js
1371 [WMETA] VALID_MISSING_WEB_METADATA // Missing .html example metadata
1372 [INFO] VALID_INCONSISTENT_INFO // Inconsistent info between collection and example header (stars, author...)
1373 [CAT] VALID_INVALID_CATEGORY // Not a recognized category
1374
1375 | [EXAMPLE NAME] | [C] |[CAT]|[INFO]|[PNG]|[WPNG]|[RES]|[MK] |[MKWEB]|[VCX]|[SOL]|[RDME]|[JS] |[WOUT]|[WMETA]|
1376 |:-----------------------------|:---:|:---:|:----:|:---:|:----:|:---:|:---:|:-----:|:---:|:---:|:----:|:---:|:----:|:-----:|
1377 | core_basic_window | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
1378 | shapes_colors_palette | ✘ | ✔ | ✘ | ✔ | ✘ | ✔ | ✔ | ✘ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
1379 | text_format_text | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✘ | ✔ | ✘ | ✔ | ✔ | ✔ | ✔ |
1380 */
1381 LOG("INFO: [examples_validation.md] Generating examples validation report...\n");
1382
1383 char *report = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1);
1384
1385 int repIndex = 0;
1386 repIndex += sprintf(report + repIndex, "# EXAMPLES COLLECTION - VALIDATION REPORT\n\n");
1387
1388 repIndex += sprintf(report + repIndex, "```\nExample elements validated:\n\n");
1389 repIndex += sprintf(report + repIndex, " - [C] : Missing .c source file\n");
1390 repIndex += sprintf(report + repIndex, " - [CAT] : Not a recognized category\n");
1391 repIndex += sprintf(report + repIndex, " - [INFO] : Inconsistent example header info (stars, author...)\n");
1392 repIndex += sprintf(report + repIndex, " - [PNG] : Missing screenshot .png\n");
1393 repIndex += sprintf(report + repIndex, " - [WPNG] : Invalid png screenshot (using default one)\n");
1394 repIndex += sprintf(report + repIndex, " - [RES] : Missing resources listed in the code\n");
1395 repIndex += sprintf(report + repIndex, " - [MK] : Not listed in Makefile\n");
1396 repIndex += sprintf(report + repIndex, " - [MKWEB] : Not listed in Makefile.Web\n");
1397 repIndex += sprintf(report + repIndex, " - [VCX] : Missing Visual Studio project file\n");
1398 repIndex += sprintf(report + repIndex, " - [SOL] : Project not included in solution file\n");
1399 repIndex += sprintf(report + repIndex, " - [RDME] : Not listed in README.md\n");
1400 repIndex += sprintf(report + repIndex, " - [JS] : Not listed in Web (examples.js)\n");
1401 repIndex += sprintf(report + repIndex, " - [WOUT] : Missing Web build (.html/.data/.wasm/.js)\n");
1402 repIndex += sprintf(report + repIndex, " - [WMETA] : Missing Web .html example metadata\n```\n");
1403
1404 repIndex += sprintf(report + repIndex, "| **EXAMPLE NAME** | [C] | [CAT]| [INFO]|[PNG]|[WPNG]| [RES]| [MK] |[MKWEB]| [VCX]| [SOL]|[RDME]|[JS] | [WOUT]|[WMETA]|\n");
1405 repIndex += sprintf(report + repIndex, "|:---------------------------------|:---:|:----:|:-----:|:---:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|:---:|:-----:|:-----:|\n");
1406
1407 for (int i = 0; i < exCollectionCount; i++)
1408 {
1409 repIndex += sprintf(report + repIndex, "| %-32s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s |\n",
1410 exCollection[i].name,
1411 (exCollection[i].status & VALID_MISSING_C)? "❌" : "✔",
1412 (exCollection[i].status & VALID_INVALID_CATEGORY)? "❌" : "✔",
1413 (exCollection[i].status & VALID_INCONSISTENT_INFO)? "❌" : "✔",
1414 (exCollection[i].status & VALID_MISSING_PNG)? "❌" : "✔",
1415 (exCollection[i].status & VALID_INVALID_PNG)? "❌" : "✔",
1416 (exCollection[i].status & VALID_MISSING_RESOURCES)? "❌" : "✔",
1417 (exCollection[i].status & VALID_NOT_IN_MAKEFILE)? "❌" : "✔",
1418 (exCollection[i].status & VALID_NOT_IN_MAKEFILE_WEB)? "❌" : "✔",
1419 (exCollection[i].status & VALID_MISSING_VCXPROJ)? "❌" : "✔",
1420 (exCollection[i].status & VALID_NOT_IN_VCXSOL)? "❌" : "✔",
1421 (exCollection[i].status & VALID_NOT_IN_README)? "❌" : "✔",
1422 (exCollection[i].status & VALID_NOT_IN_JS)? "❌" : "✔",
1423 (exCollection[i].status & VALID_MISSING_WEB_OUTPUT)? "❌" : "✔",
1424 (exCollection[i].status & VALID_MISSING_WEB_METADATA)? "❌" : "✔");
1425 }
1426
1427 SaveFileText(TextFormat("%s/../tools/rexm/reports/%s", exBasePath, "examples_validation.md"), report);
1428 RL_FREE(report);
1429 //-----------------------------------------------------------------------------------------------------
1430
1431 // Generate a report with only the examples missing some elements
1432 //-----------------------------------------------------------------------------------------------------
1433 LOG("INFO: [examples_issues.md] Generating examples issues report...\n");
1434
1435 char *reportIssues = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1);
1436
1437 repIndex = 0;
1438 repIndex += sprintf(reportIssues + repIndex, "# EXAMPLES COLLECTION - VALIDATION REPORT\n\n");
1439
1440 repIndex += sprintf(reportIssues + repIndex, "```\nExample elements validated:\n\n");
1441 repIndex += sprintf(reportIssues + repIndex, " - [C] : Missing .c source file\n");
1442 repIndex += sprintf(reportIssues + repIndex, " - [CAT] : Not a recognized category\n");
1443 repIndex += sprintf(reportIssues + repIndex, " - [INFO] : Inconsistent example header info (stars, author...)\n");
1444 repIndex += sprintf(reportIssues + repIndex, " - [PNG] : Missing screenshot .png\n");
1445 repIndex += sprintf(reportIssues + repIndex, " - [WPNG] : Invalid png screenshot (using default one)\n");
1446 repIndex += sprintf(reportIssues + repIndex, " - [RES] : Missing resources listed in the code\n");
1447 repIndex += sprintf(reportIssues + repIndex, " - [MK] : Not listed in Makefile\n");
1448 repIndex += sprintf(reportIssues + repIndex, " - [MKWEB] : Not listed in Makefile.Web\n");
1449 repIndex += sprintf(reportIssues + repIndex, " - [VCX] : Missing Visual Studio project file\n");
1450 repIndex += sprintf(reportIssues + repIndex, " - [SOL] : Project not included in solution file\n");
1451 repIndex += sprintf(reportIssues + repIndex, " - [RDME] : Not listed in README.md\n");
1452 repIndex += sprintf(reportIssues + repIndex, " - [JS] : Not listed in Web (examples.js)\n");
1453 repIndex += sprintf(reportIssues + repIndex, " - [WOUT] : Missing Web build (.html/.data/.wasm/.js)\n");
1454 repIndex += sprintf(reportIssues + repIndex, " - [WMETA] : Missing Web .html example metadata\n```\n");
1455
1456 repIndex += sprintf(reportIssues + repIndex, "| **EXAMPLE NAME** | [C] | [CAT]| [INFO]|[PNG]|[WPNG]| [RES]| [MK] |[MKWEB]| [VCX]| [SOL]|[RDME]|[JS] | [WOUT]|[WMETA]|\n");
1457 repIndex += sprintf(reportIssues + repIndex, "|:---------------------------------|:---:|:----:|:-----:|:---:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|:---:|:-----:|:-----:|\n");
1458
1459 for (int i = 0; i < exCollectionCount; i++)
1460 {
1461 if (exCollection[i].status > 0)
1462 {
1463 repIndex += sprintf(reportIssues + repIndex, "| %-32s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s | %s |\n",
1464 exCollection[i].name,
1465 (exCollection[i].status & VALID_MISSING_C)? "❌" : "✔",
1466 (exCollection[i].status & VALID_INVALID_CATEGORY)? "❌" : "✔",
1467 (exCollection[i].status & VALID_INCONSISTENT_INFO)? "❌" : "✔",
1468 (exCollection[i].status & VALID_MISSING_PNG)? "❌" : "✔",
1469 (exCollection[i].status & VALID_INVALID_PNG)? "❌" : "✔",
1470 (exCollection[i].status & VALID_MISSING_RESOURCES)? "❌" : "✔",
1471 (exCollection[i].status & VALID_NOT_IN_MAKEFILE)? "❌" : "✔",
1472 (exCollection[i].status & VALID_NOT_IN_MAKEFILE_WEB)? "❌" : "✔",
1473 (exCollection[i].status & VALID_MISSING_VCXPROJ)? "❌" : "✔",
1474 (exCollection[i].status & VALID_NOT_IN_VCXSOL)? "❌" : "✔",
1475 (exCollection[i].status & VALID_NOT_IN_README)? "❌" : "✔",
1476 (exCollection[i].status & VALID_NOT_IN_JS)? "❌" : "✔",
1477 (exCollection[i].status & VALID_MISSING_WEB_OUTPUT)? "❌" : "✔",
1478 (exCollection[i].status & VALID_MISSING_WEB_METADATA)? "❌" : "✔");
1479 }
1480 }
1481
1482 SaveFileText(TextFormat("%s/../tools/rexm/reports/%s", exBasePath, "examples_issues.md"), reportIssues);
1483 RL_FREE(reportIssues);
1484 //-----------------------------------------------------------------------------------------------------
1485
1486 UnloadExampleData(exCollection);
1487 //------------------------------------------------------------------------------------------------
1488
1489 } break;
1490 case OP_TEST:
1491 {
1492 LOG("INFO: Command requested: TEST\n");
1493 LOG("INFO: Example(s) to be build and tested: %i [%s]\n", exBuildListCount, (exBuildListCount == 1)? exBuildList[0] : argv[2]);
1494
1495 #if defined(_WIN32)
1496 // Set required environment variables
1497 //putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath));
1498 //_putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
1499 //putenv("MAKE=mingw32-make");
1500 //ChangeDirectory(exBasePath);
1501 //_putenv("MAKE_PATH=C:\\raylib\\w64devkit\\bin");
1502 //_putenv("EMSDK_PATH = C:\\raylib\\emsdk");
1503 //_putenv("PYTHON_PATH=$(EMSDK_PATH)\\python\\3.13.3_64bit");
1504 //_putenv("NODE_PATH=$(EMSDK_PATH)\\node\\22.16.0_64bit\\bin");
1505 //_putenv("PATH=%PATH%;$(MAKE_PATH);$(EMSDK_PATH);$(NODE_PATH);$(PYTHON_PATH)");
1506
1507 _putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin;C:\\raylib\\emsdk\\python\\3.13.3_64bit;C:\\raylib\\emsdk\\node\\22.16.0_64bit\\bin");
1508 #endif
1509
1510 for (int i = 0; i < exBuildListCount; i++)
1511 {
1512 // Get example name and category
1513 memset(exName, 0, 64);
1514 strcpy(exName, exBuildList[i]);
1515 memset(exCategory, 0, 32);
1516 strncpy(exCategory, exName, TextFindIndex(exName, "_"));
1517
1518 // Skip some examples from building
1519 if ((strcmp(exName, "core_custom_logging") == 0) ||
1520 (strcmp(exName, "core_window_should_close") == 0) ||
1521 (strcmp(exName, "core_custom_frame_control") == 0)) continue;
1522
1523 LOG("INFO: [%i/%i] Testing example: [%s]\n", i + 1, exBuildListCount, exName);
1524
1525 // Create directory for logs (build and run logs)
1526 MakeDirectory(TextFormat("%s/%s/logs", exBasePath, exCategory));
1527
1528 // Steps to follow
1529 // STEP 1: Load example.c and replace required code to inject basic testing code: frames to run
1530 // OPTION 1: Code injection required multiple changes for testing but it does not require raylib changes!
1531 // OPTION 2: Support testing on raylib side: Args processing and events injection: SUPPORT_AUTOMATD_TESTING_SYSTEM, EVENTS_TESTING_MODE
1532 // STEP 2: Build example (PLATFORM_DESKTOP)
1533 // STEP 3: Run example with arguments: --frames 2 > <example>.out.log
1534 // STEP 4: Load <example>.out.log and check "WARNING:" messages -> Some could maybe be ignored
1535 // STEP 5: Generate report with results
1536
1537 // STEP 1: Load example and inject required code
1538 // PROBLEM: As we need to modify the example source code for building, we need to keep a copy or something
1539 // WARNING: If we make a copy and something fails, it could not be restored at the end
1540 // PROBLEM: Trying to build a copy won't work because Makefile is setup to look for specific example on specific path -> No output dir config
1541 // IDEA: Create directory for testing data -> It implies moving files and set working dir...
1542 // SOLUTION: Make a copy of original file -> Modify original -> Build -> Rename to <example>.test.exe
1543 FileCopy(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName),
1544 TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName));
1545 char *srcText = LoadFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
1546
1547 //#define BUILD_TESTING_WEB
1548 #if defined(BUILD_TESTING_WEB)
1549 static const char *mainReplaceText =
1550 "#include <stdio.h>\n"
1551 "#include <string.h>\n"
1552 "#include <stdlib.h>\n"
1553 "#include <emscripten/emscripten.h>\n\n"
1554 "static char logText[4096] = { 0 };\n"
1555 "static int logTextOffset = 0;\n\n"
1556 "void CustomTraceLog(int msgType, const char *text, va_list args)\n{\n"
1557 " if (logTextOffset < 3800)\n {\n"
1558 " switch (msgType)\n {\n"
1559 " case LOG_INFO: logTextOffset += sprintf(logText + logTextOffset, \"INFO: \"); break;\n"
1560 " case LOG_ERROR: logTextOffset += sprintf(logText + logTextOffset, \"ERROR: \"); break;\n"
1561 " case LOG_WARNING: logTextOffset += sprintf(logText + logTextOffset, \"WARNING: \"); break;\n"
1562 " case LOG_DEBUG: logTextOffset += sprintf(logText + logTextOffset, \"DEBUG: \"); break;\n"
1563 " default: break;\n }\n"
1564 " logTextOffset += vsprintf(logText + logTextOffset, text, args);\n"
1565 " logTextOffset += sprintf(logText + logTextOffset, \"\\n\");\n}\n}\n\n"
1566 "int main(int argc, char *argv[])\n{\n"
1567 " SetTraceLogCallback(CustomTraceLog);\n"
1568 " int requestedTestFrames = 0;\n"
1569 " int testFramesCount = 0;\n"
1570 " if ((argc > 1) && (argc == 3) && (strcmp(argv[1], \"--frames\") != 0)) requestedTestFrames = atoi(argv[2]);\n";
1571
1572 static const char *returnReplaceText =
1573 " SaveFileText(\"outputLogFileName\", logText);\n"
1574 " emscripten_run_script(\"saveFileFromMEMFSToDisk('outputLogFileName','outputLogFileName')\");\n\n"
1575 " return 0";
1576 char *returnReplaceTextUpdated = TextReplaceAlloc(returnReplaceText, "outputLogFileName", TextFormat("%s.log", exName));
1577
1578 char *srcTextUpdated[4] = { 0 };
1579 srcTextUpdated[0] = TextReplaceAlloc(srcText, "int main(void)\n{", mainReplaceText);
1580 srcTextUpdated[1] = TextReplaceAlloc(srcTextUpdated[0], "WindowShouldClose()", "WindowShouldClose() && (testFramesCount < requestedTestFrames)");
1581 srcTextUpdated[2] = TextReplaceAlloc(srcTextUpdated[1], "EndDrawing();", "EndDrawing(); testFramesCount++;");
1582 srcTextUpdated[3] = TextReplaceAlloc(srcTextUpdated[2], " return 0", returnReplaceTextUpdated);
1583 MemFree(returnReplaceTextUpdated);
1584 UnloadFileText(srcText);
1585
1586 SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), srcTextUpdated[3]);
1587 for (int i = 0; i < 4; i++) { MemFree(srcTextUpdated[i]); srcTextUpdated[i] = NULL; }
1588
1589 // Build example for PLATFORM_WEB
1590 // Build: raylib.com/examples/<category>/<category>_example_name.html
1591 // Build: raylib.com/examples/<category>/<category>_example_name.data
1592 // Build: raylib.com/examples/<category>/<category>_example_name.wasm
1593 // Build: raylib.com/examples/<category>/<category>_example_name.js
1594 #if defined(_WIN32)
1595 LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: Win32)\n", exName);
1596 system(TextFormat("mingw32-make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B > %s/%s/logs/%s.build.log 2>&1",
1597 exBasePath, exCategory, exName, exBasePath, exCategory, exName));
1598 #else
1599 LOG("INFO: [%s] Building example for PLATFORM_WEB (Host: POSIX)\n", exName);
1600 system(TextFormat("make -C %s -f Makefile.Web %s/%s PLATFORM=PLATFORM_WEB -B", exBasePath, exCategory, exName));
1601 #endif
1602 // Restore original source code before continue
1603 FileCopy(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName),
1604 TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
1605 FileRemove(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName));
1606
1607 // STEP 3: Run example on browser
1608 if (FileExists(TextFormat("%s/%s/%s.html", exBasePath, exCategory, exName)) &&
1609 FileExists(TextFormat("%s/%s/%s.wasm", exBasePath, exCategory, exName)) &&
1610 FileExists(TextFormat("%s/%s/%s.js", exBasePath, exCategory, exName)))
1611 {
1612 // WARNING: Example download is asynchronous so reading fails on next step
1613 // when looking for a file that could not have been downloaded yet
1614 ChangeDirectory(TextFormat("%s", exBasePath));
1615 if (i == 0) system("start python -m http.server 8080"); // Init localhost just once
1616 system(TextFormat("start explorer \"http:\\localhost:8080/%s/%s.html", exCategory, exName));
1617 }
1618
1619 // NOTE: Example .log is automatically downloaded into system Downloads directory on browser-example exectution
1620
1621 #else // BUILD_TESTING_DESKTOP
1622
1623 static const char *mainReplaceText =
1624 "#include <string.h>\n"
1625 "#include <stdlib.h>\n"
1626 "int main(int argc, char *argv[])\n{\n"
1627 " int requestedTestFrames = 0;\n"
1628 " int testFramesCount = 0;\n"
1629 " if ((argc > 1) && (argc == 3) && (strcmp(argv[1], \"--frames\") != 0)) requestedTestFrames = atoi(argv[2]);\n";
1630
1631 char *srcTextUpdated[3] = { 0 };
1632 srcTextUpdated[0] = TextReplaceAlloc(srcText, "int main(void)\n{", mainReplaceText);
1633 srcTextUpdated[1] = TextReplaceAlloc(srcTextUpdated[0], "WindowShouldClose()", "WindowShouldClose() && (testFramesCount < requestedTestFrames)");
1634 srcTextUpdated[2] = TextReplaceAlloc(srcTextUpdated[1], "EndDrawing();", "EndDrawing(); testFramesCount++;");
1635 UnloadFileText(srcText);
1636
1637 SaveFileText(TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName), srcTextUpdated[2]);
1638 for (int i = 0; i < 3; i++) { MemFree(srcTextUpdated[i]); srcTextUpdated[i] = NULL; }
1639
1640 // STEP 2: Build example for DESKTOP platform
1641 #if defined(_WIN32)
1642 // Set required environment variables
1643 //putenv(TextFormat("RAYLIB_DIR=%s\\..", exBasePath));
1644 _putenv("PATH=%PATH%;C:\\raylib\\w64devkit\\bin");
1645 //putenv("MAKE=mingw32-make");
1646 //ChangeDirectory(exBasePath);
1647 #endif
1648 // Build example for PLATFORM_DESKTOP
1649 #if defined(_WIN32)
1650 LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: Win32)\n", exName);
1651 system(TextFormat("mingw32-make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B > %s/%s/logs/%s.build.log 2>&1",
1652 exBasePath, exCategory, exName, exBasePath, exCategory, exName));
1653 #elif defined(PLATFORM_DRM)
1654 LOG("INFO: [%s] Building example for PLATFORM_DRM (Host: POSIX)\n", exName);
1655 system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DRM -B > %s/%s/logs/%s.build.log 2>&1",
1656 exBasePath, exCategory, exName, exBasePath, exCategory, exName));
1657 #else
1658 LOG("INFO: [%s] Building example for PLATFORM_DESKTOP (Host: POSIX)\n", exName);
1659 system(TextFormat("make -C %s %s/%s PLATFORM=PLATFORM_DESKTOP -B > %s/%s/logs/%s.build.log 2>&1",
1660 exBasePath, exCategory, exName, exBasePath, exCategory, exName));
1661 #endif
1662 // Restore original source code before continue
1663 FileCopy(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName),
1664 TextFormat("%s/%s/%s.c", exBasePath, exCategory, exName));
1665 FileRemove(TextFormat("%s/%s/%s.original.c", exBasePath, exCategory, exName));
1666
1667 // STEP 3: Run example with required arguments
1668 // NOTE: Not easy to retrieve process return value from system(), it's platform dependent
1669 ChangeDirectory(TextFormat("%s/%s", exBasePath, exCategory));
1670
1671 #if defined(_WIN32)
1672 system(TextFormat("%s --frames 2 > logs/%s.log", exName, exName));
1673 #else
1674 system(TextFormat("./%s --frames 2 > logs/%s.log", exName, exName));
1675 #endif
1676 #endif
1677 }
1678 } break;
1679 case OP_TESTLOG:
1680 {
1681 // STEP 4: Load and validate available logs info
1682 //---------------------------------------------------------------------------------------------
1683 rlExampleTesting *testing = (rlExampleTesting *)RL_CALLOC(exBuildListCount, sizeof(rlExampleTesting));
1684
1685 for (int i = 0; i < exBuildListCount; i++)
1686 {
1687 // Get example name and category
1688 memset(exName, 0, 64);
1689 strcpy(exName, exBuildList[i]);
1690 memset(exCategory, 0, 32);
1691 strncpy(exCategory, exName, TextFindIndex(exName, "_"));
1692
1693 // Skip some examples from building
1694 if ((strcmp(exName, "core_custom_logging") == 0) ||
1695 (strcmp(exName, "core_window_should_close") == 0) ||
1696 (strcmp(exName, "core_custom_frame_control") == 0)) continue;
1697
1698 LOG("INFO: [%i/%i] Checking example log: [%s]\n", i + 1, exBuildListCount, exName);
1699
1700 // Load <example_name>.build.log to check for compilation warnings
1701 char *exTestBuildLog = LoadFileText(TextFormat("%s/%s/logs/%s.build.log", exBasePath, exCategory, exName));
1702 if (exTestBuildLog == NULL)
1703 {
1704 LOG("WARNING: [%s] Build log could not be loaded\n", exName);
1705 continue;
1706 }
1707
1708 // Load build log text lines
1709 int exTestBuildLogLinesCount = 0;
1710 char **exTestBuildLogLines = LoadTextLines(exTestBuildLog, &exTestBuildLogLinesCount);
1711
1712 for (int k = 0; k < exTestBuildLogLinesCount; k++)
1713 {
1714 // Checking compilation warnings generated
1715 if (TextFindIndex(exTestBuildLogLines[k], "warning:") >= 0) testing[i].buildwarns++;
1716 }
1717
1718 UnloadTextLines(exTestBuildLogLines, exTestBuildLogLinesCount);
1719 UnloadFileText(exTestBuildLog);
1720
1721 #if defined(BUILD_TESTING_WEB)
1722 // TODO: REVIEW: Hardcoded path where web logs are copied after automatic download
1723 char *exTestLog = LoadFileText(TextFormat("D:/testing_logs_web/%s.log", exName));
1724 #else
1725 char *exTestLog = LoadFileText(TextFormat("%s/%s/logs/%s.log", exBasePath, exCategory, exName));
1726 #endif
1727 if (exTestLog == NULL)
1728 {
1729 LOG("WARNING: [%s] Execution log could not be loaded\n", exName);
1730 testing[i].status = 0b1111111;
1731 continue;
1732 }
1733
1734 /*
1735 TESTING_FAIL_INIT = 1 << 0, // Initialization (InitWindow()) -> "INFO: DISPLAY: Device initialized successfully"
1736 TESTING_FAIL_CLOSE = 1 << 1, // Closing (CloseWindow()) -> "INFO: Window closed successfully"
1737 TESTING_FAIL_ASSETS = 1 << 2, // Assets loading (WARNING: FILE:) -> "WARNING: FILEIO:"
1738 TESTING_FAIL_RLGL = 1 << 3, // OpenGL-wrapped initialization -> "INFO: RLGL: Default OpenGL state initialized successfully"
1739 TESTING_FAIL_PLATFORM = 1 << 4, // Platform initialization -> "INFO: PLATFORM: DESKTOP (GLFW - Win32): Initialized successfully"
1740 TESTING_FAIL_FONT = 1 << 5, // Font default initialization -> "INFO: FONT: Default font loaded successfully (224 glyphs)"
1741 TESTING_FAIL_TIMER = 1 << 6, // Timer initialization -> "INFO: TIMER: Target time per frame: 16.667 milliseconds"
1742 */
1743
1744 if (TextFindIndex(exTestLog, "INFO: DISPLAY: Device initialized successfully") == -1) testing[i].status |= TESTING_FAIL_INIT;
1745 if (TextFindIndex(exTestLog, "INFO: Window closed successfully") == -1) testing[i].status |= TESTING_FAIL_CLOSE;
1746 if (TextFindIndex(exTestLog, "WARNING: FILEIO:") >= 0) testing[i].status |= TESTING_FAIL_ASSETS;
1747 if (TextFindIndex(exTestLog, "INFO: RLGL: Default OpenGL state initialized successfully") == -1) testing[i].status |= TESTING_FAIL_RLGL;
1748 if (TextFindIndex(exTestLog, "INFO: PLATFORM:") == -1) testing[i].status |= TESTING_FAIL_PLATFORM;
1749 if (TextFindIndex(exTestLog, "INFO: FONT: Default font loaded successfully") == -1) testing[i].status |= TESTING_FAIL_FONT;
1750 if (TextFindIndex(exTestLog, "INFO: TIMER: Target time per frame:") == -1) testing[i].status |= TESTING_FAIL_TIMER;
1751
1752 // Load build log text lines
1753 int exTestLogLinesCount = 0;
1754 char **exTestLogLines = LoadTextLines(exTestLog, &exTestLogLinesCount);
1755 for (int k = 0; k < exTestLogLinesCount; k++)
1756 {
1757 #if defined(BUILD_TESTING_WEB)
1758 if (TextFindIndex(exTestLogLines[k], "WARNING: GL: NPOT") >= 0) continue; // Ignore web-specific warning
1759 #endif
1760 #if defined(PLATFORM_DRM)
1761 if (TextFindIndex(exTestLogLines[k], "WARNING: DISPLAY: No graphic") >= 0) continue; // Ignore specific warning
1762 if (TextFindIndex(exTestLogLines[k], "WARNING: GetCurrentMonitor()") >= 0) continue; // Ignore specific warning
1763 if (TextFindIndex(exTestLogLines[k], "WARNING: SetWindowPosition()") >= 0) continue; // Ignore specific warning
1764 #endif
1765 if (TextFindIndex(exTestLogLines[k], "WARNING") >= 0) testing[i].warnings++;
1766 }
1767 UnloadTextLines(exTestLogLines, exTestLogLinesCount);
1768 UnloadFileText(exTestLog);
1769 }
1770 //---------------------------------------------------------------------------------------------
1771
1772 // STEP 5: Generate testing report/table with results (.md)
1773 //-----------------------------------------------------------------------------------------------------
1774 #if defined(BUILD_TESTING_WEB)
1775 const char *osName = "Web";
1776 #else
1777 #if defined(PLATFORM_DRM)
1778 const char *osName = "DRM";
1779 #elif defined(PLATFORM_DESKTOP)
1780 #if defined(_WIN32)
1781 const char *osName = "Windows";
1782 #elif defined(__linux__)
1783 const char *osName = "Linux";
1784 #elif defined(__FreeBSD__)
1785 const char *osName = "FreeBSD";
1786 #elif defined(__APPLE__)
1787 const char *osName = "macOS";
1788 #endif // Desktop OSs
1789 #endif
1790 #endif
1791 /*
1792 Columns:
1793 - [CWARN] : Compilation WARNING messages
1794 - [LWARN] : Log WARNING messages count
1795 - [INIT] : Initialization
1796 - [CLOSE] : Closing
1797 - [ASSETS] : Assets loading
1798 - [RLGL] : OpenGL-wrapped initialization
1799 - [PLAT] : Platform initialization
1800 - [FONT] : Font default initialization
1801 - [TIMER] : Timer initialization
1802
1803 | **EXAMPLE NAME** | [CWARN] | [LWARN] | [INIT] | [CLOSE] | [ASSETS] | [RLGL] | [PLAT] | [FONT] | [TIMER] |
1804 |:---------------------------------|:-------:|:-------:|:------:|:-------:|:--------:|:------:|:------:|:------:|:-------:|
1805 | core_basic window | 0 | 0 | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ | ✔ |
1806 */
1807 LOG("INFO: [examples_testing_os.md] Generating examples testing report...\n");
1808
1809 char *report = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1);
1810
1811 int repIndex = 0;
1812 repIndex += sprintf(report + repIndex, "# EXAMPLES COLLECTION - TESTING REPORT\n\n");
1813 repIndex += sprintf(report + repIndex, TextFormat("## Tested Platform: %s\n\n", osName));
1814
1815 repIndex += sprintf(report + repIndex, "```\nExample automated testing elements validated:\n");
1816 repIndex += sprintf(report + repIndex, " - [CWARN] : Compilation WARNING messages\n");
1817 repIndex += sprintf(report + repIndex, " - [LWARN] : Log WARNING messages count\n");
1818 repIndex += sprintf(report + repIndex, " - [INIT] : Initialization\n");
1819 repIndex += sprintf(report + repIndex, " - [CLOSE] : Closing\n");
1820 repIndex += sprintf(report + repIndex, " - [ASSETS] : Assets loading\n");
1821 repIndex += sprintf(report + repIndex, " - [RLGL] : OpenGL-wrapped initialization\n");
1822 repIndex += sprintf(report + repIndex, " - [PLAT] : Platform initialization\n");
1823 repIndex += sprintf(report + repIndex, " - [FONT] : Font default initialization\n");
1824 repIndex += sprintf(report + repIndex, " - [TIMER] : Timer initialization\n```\n");
1825
1826 repIndex += sprintf(report + repIndex, "| **EXAMPLE NAME** | [CWARN] | [LWARN] | [INIT] | [CLOSE] | [ASSETS] | [RLGL] | [PLAT] | [FONT] | [TIMER] |\n");
1827 repIndex += sprintf(report + repIndex, "|:---------------------------------|:-------:|:-------:|:------:|:-------:|:--------:|:------:|:------:|:------:|:-------:|\n");
1828
1829 /*
1830 TESTING_FAIL_INIT = 1 << 0, // Initialization (InitWindow()) -> "INFO: DISPLAY: Device initialized successfully"
1831 TESTING_FAIL_CLOSE = 1 << 1, // Closing (CloseWindow()) -> "INFO: Window closed successfully"
1832 TESTING_FAIL_ASSETS = 1 << 2, // Assets loading (WARNING: FILE:) -> "WARNING: FILEIO:"
1833 TESTING_FAIL_RLGL = 1 << 3, // OpenGL-wrapped initialization -> "INFO: RLGL: Default OpenGL state initialized successfully"
1834 TESTING_FAIL_PLATFORM = 1 << 4, // Platform initialization -> "INFO: PLATFORM: DESKTOP (GLFW - Win32): Initialized successfully"
1835 TESTING_FAIL_FONT = 1 << 5, // Font default initialization -> "INFO: FONT: Default font loaded successfully (224 glyphs)"
1836 TESTING_FAIL_TIMER = 1 << 6, // Timer initialization -> "INFO: TIMER: Target time per frame: 16.667 milliseconds"
1837 */
1838 for (int i = 0; i < exBuildListCount; i++)
1839 {
1840 if ((testing[i].buildwarns > 0) || (testing[i].warnings > 0) || (testing[i].status > 0))
1841 {
1842 repIndex += sprintf(report + repIndex, "| %-32s | %i | %i | %s | %s | %s | %s | %s | %s | %s |\n",
1843 exBuildList[i],
1844 testing[i].buildwarns,
1845 testing[i].warnings,
1846 (testing[i].status & TESTING_FAIL_INIT)? "❌" : "✔",
1847 (testing[i].status & TESTING_FAIL_CLOSE)? "❌" : "✔",
1848 (testing[i].status & TESTING_FAIL_ASSETS)? "❌" : "✔",
1849 (testing[i].status & TESTING_FAIL_RLGL)? "❌" : "✔",
1850 (testing[i].status & TESTING_FAIL_PLATFORM)? "❌" : "✔",
1851 (testing[i].status & TESTING_FAIL_FONT)? "❌" : "✔",
1852 (testing[i].status & TESTING_FAIL_TIMER)? "❌" : "✔");
1853 }
1854 }
1855
1856 repIndex += sprintf(report + repIndex, "\n");
1857
1858 SaveFileText(TextFormat("%s/../tools/rexm/reports/examples_testing_%s.md", exBasePath, TextToLower(osName)), report);
1859
1860 RL_FREE(report);
1861 //-----------------------------------------------------------------------------------------------------
1862
1863 } break;
1864 default: // Help
1865 {
1866 // Supported commands:
1867 // create <new_example_name> : Creates an empty example, from internal template
1868 // add <example_name> : Add existing example, category extracted from name
1869 // rename <old_examples_name> <new_example_name> : Rename an existing example
1870 // remove <example_name> : Remove an existing example
1871 // build <example_name> : Build example for Desktop and Web platforms
1872 // validate : Validate examples collection, generates report
1873 // update : Validate and update examples collection, generates report
1874
1875 printf("\n////////////////////////////////////////////////////////////////////////////////////////////\n");
1876 printf("// //\n");
1877 printf("// rexm [raylib examples manager] - A simple command-line tool to manage raylib examples //\n");
1878 printf("// powered by raylib v6.0 //\n");
1879 printf("// //\n");
1880 printf("// Copyright (c) 2025-2026 Ramon Santamaria (@raysan5) //\n");
1881 printf("// //\n");
1882 printf("////////////////////////////////////////////////////////////////////////////////////////////\n\n");
1883
1884 printf("USAGE:\n\n");
1885 printf(" > rexm <command> <example_name> [<example_rename>]\n\n");
1886
1887 printf("COMMANDS:\n\n");
1888 printf(" create <new_example_name> : Creates an empty example, from internal template\n");
1889 printf(" add <example_name> : Add existing example, category extracted from name\n");
1890 printf(" Supported categories: core, shapes, textures, text, models\n");
1891 printf(" rename <old_examples_name> <new_example_name> : Rename an existing example\n");
1892 printf(" remove <example_name> : Remove an existing example\n");
1893 printf(" build <example_name> : Build example for Desktop and Web platforms\n");
1894 printf(" test <example_name> : Build and Test example for Desktop and Web platforms\n");
1895 printf(" validate : Validate examples collection, generates report\n");
1896 printf(" update : Validate and update examples collection, generates report\n\n");
1897 printf("OPTIONS:\n\n");
1898 printf(" -h, --help : Show tool version and command line usage help\n");
1899 printf(" -v, --verbose : Verbose mode, show additional logs on processes\n");
1900 printf("\nEXAMPLES:\n\n");
1901 printf(" > rexm add shapes_custom_stars\n");
1902 printf(" Add and updates new example provided <shapes_custom_stars>\n\n");
1903 printf(" > rexm rename core_basic_window core_cool_window\n");
1904 printf(" Renames and updates example <core_basic_window> to <core_cool_window>\n\n");
1905 printf(" > rexm update\n");
1906 printf(" Validates all examples in collection and updates missing elements\n\n");
1907 } break;
1908 }
1909
1910 return 0;
1911 }
1912
1913 //----------------------------------------------------------------------------------
1914 // Module Internal Functions Definition
1915 //----------------------------------------------------------------------------------
1916 // Update required files from examples collection
1917 static int UpdateRequiredFiles(void)
1918 {
1919 int result = 0;
1920
1921 // Edit: Example source code metadata for consistency
1922 //------------------------------------------------------------------------------------------------
1923 LOG("INFO: Updating all examples metadata...\n");
1924 int exListCount = 0;
1925 rlExampleInfo *exList = LoadExampleData("ALL", true, &exListCount);
1926 for (int i = 0; i < exListCount; i++)
1927 {
1928 rlExampleInfo *info = &exList[i];
1929 UpdateSourceMetadata(TextFormat("%s/%s/%s.c", exBasePath, info->category, info->name), info);
1930 }
1931 UnloadExampleData(exList);
1932 //------------------------------------------------------------------------------------------------
1933
1934 // Edit: raylib/examples/Makefile --> Update from collection
1935 //------------------------------------------------------------------------------------------------
1936 LOG("INFO: Updating raylib/examples/Makefile\n");
1937 char *mkText = LoadFileText(TextFormat("%s/Makefile", exBasePath));
1938 char *mkTextUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1); // Updated Makefile copy, 2MB
1939
1940 int mkListStartIndex = TextFindIndex(mkText, "#EXAMPLES_LIST_START");
1941 int mkListEndIndex = TextFindIndex(mkText, "#EXAMPLES_LIST_END");
1942
1943 int mkIndex = 0;
1944 memcpy(mkTextUpdated, mkText, mkListStartIndex);
1945 mkIndex = sprintf(mkTextUpdated + mkListStartIndex, "#EXAMPLES_LIST_START\n");
1946
1947 for (int i = 0; i < REXM_MAX_EXAMPLE_CATEGORIES; i++)
1948 {
1949 mkIndex += sprintf(mkTextUpdated + mkListStartIndex + mkIndex, TextFormat("%s = \\\n", TextToUpper(exCategories[i])));
1950
1951 int exCollectionCount = 0;
1952 rlExampleInfo *exCollection = LoadExampleData(exCategories[i], true, &exCollectionCount);
1953
1954 for (int x = 0; x < exCollectionCount - 1; x++) mkIndex += sprintf(mkTextUpdated + mkListStartIndex + mkIndex, TextFormat(" %s/%s \\\n", exCollection[x].category, exCollection[x].name));
1955 mkIndex += sprintf(mkTextUpdated + mkListStartIndex + mkIndex, TextFormat(" %s/%s\n\n", exCollection[exCollectionCount - 1].category, exCollection[exCollectionCount - 1].name));
1956
1957 UnloadExampleData(exCollection);
1958 }
1959
1960 // Add the remaining part of the original file
1961 memcpy(mkTextUpdated + mkListStartIndex + mkIndex - 1, mkText + mkListEndIndex, strlen(mkText) - mkListEndIndex);
1962
1963 // Save updated file
1964 SaveFileText(TextFormat("%s/Makefile", exBasePath), mkTextUpdated);
1965 UnloadFileText(mkText);
1966 RL_FREE(mkTextUpdated);
1967 //------------------------------------------------------------------------------------------------
1968
1969 // Edit: raylib/examples/Makefile.Web --> Update from collection
1970 //------------------------------------------------------------------------------------------------
1971 LOG("INFO: Updating raylib/examples/Makefile.Web\n");
1972 char *mkwText = LoadFileText(TextFormat("%s/Makefile.Web", exBasePath));
1973 char *mkwTextUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1); // Updated Makefile copy, 2MB
1974
1975 int mkwListStartIndex = TextFindIndex(mkwText, "#EXAMPLES_LIST_START");
1976 int mkwListEndIndex = TextFindIndex(mkwText, "#EXAMPLES_LIST_END");
1977
1978 int mkwIndex = 0;
1979 memcpy(mkwTextUpdated, mkwText, mkwListStartIndex);
1980 mkwIndex = sprintf(mkwTextUpdated + mkwListStartIndex, "#EXAMPLES_LIST_START\n");
1981
1982 for (int i = 0; i < REXM_MAX_EXAMPLE_CATEGORIES; i++)
1983 {
1984 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, TextFormat("%s = \\\n", TextToUpper(exCategories[i])));
1985
1986 int exCollectionCount = 0;
1987 rlExampleInfo *exCollection = LoadExampleData(exCategories[i], true, &exCollectionCount);
1988
1989 for (int x = 0; x < exCollectionCount - 1; x++) mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, TextFormat(" %s/%s \\\n", exCollection[x].category, exCollection[x].name));
1990 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, TextFormat(" %s/%s\n\n", exCollection[exCollectionCount - 1].category, exCollection[exCollectionCount - 1].name));
1991
1992 UnloadExampleData(exCollection);
1993 }
1994
1995 // Add examples individual targets, considering every example resources
1996 // Some required makefile code...
1997 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "# Default target entry\n");
1998 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "all: $(CORE) $(SHAPES) $(TEXT) $(TEXTURES) $(MODELS) $(SHADERS) $(AUDIO)\n\n");
1999 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "core: $(CORE)\n");
2000 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "shapes: $(SHAPES)\n");
2001 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "textures: $(TEXTURES)\n");
2002 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "text: $(TEXT)\n");
2003 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "models: $(MODELS)\n");
2004 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "shaders: $(SHADERS)\n");
2005 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, "audio: $(AUDIO)\n\n");
2006
2007 for (int i = 0; i < REXM_MAX_EXAMPLE_CATEGORIES; i++)
2008 {
2009 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, TextFormat("# Compile %s examples\n", TextToUpper(exCategories[i])));
2010
2011 int exCollectionCount = 0;
2012 rlExampleInfo *exCollection = LoadExampleData(exCategories[i], true, &exCollectionCount);
2013
2014 for (int x = 0; x < exCollectionCount; x++)
2015 {
2016 // Scan resources used in example to list
2017 int resPathCount = 0;
2018 char **resPaths = LoadExampleResourcePaths(TextFormat("%s/%s/%s.c", exBasePath, exCollection[x].category, exCollection[x].name), &resPathCount);
2019
2020 if (resPathCount > 0)
2021 {
2022 /*
2023 // WARNING: Compilation line starts with [TAB]
2024 shaders/shaders_vertex_displacement: shaders/shaders_vertex_displacement.c
2025 $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \
2026 --preload-file shaders/resources/shaders/glsl100/vertex_displacement.vs@resources/shaders/glsl100/vertex_displacement.vs \
2027 --preload-file shaders/resources/shaders/glsl330/vertex_displacement.vs@resources/shaders/glsl330/vertex_displacement.vs \
2028 --preload-file shaders/resources/shaders/glsl100/vertex_displacement.fs@resources/shaders/glsl100/vertex_displacement.fs \
2029 --preload-file shaders/resources/shaders/glsl330/vertex_displacement.fs@resources/shaders/glsl330/vertex_displacement.fs
2030 */
2031 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex,
2032 TextFormat("%s/%s: %s/%s.c\n", exCollection[x].category, exCollection[x].name, exCollection[x].category, exCollection[x].name));
2033 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, " $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM) \\\n");
2034
2035 for (int r = 0; r < resPathCount; r++)
2036 {
2037 // WARNING: Special case to consider: shaders, resource paths could use conditions: "glsl%i"
2038 // In this case, we focus on web building for: glsl100
2039 if (TextFindIndex(resPaths[r], "glsl%i") > -1)
2040 {
2041 char *resPathUpdated = TextReplaceAlloc(resPaths[r], "glsl%i", "glsl100");
2042 memset(resPaths[r], 0, 256);
2043 strcpy(resPaths[r], resPathUpdated);
2044 RL_FREE(resPathUpdated);
2045 }
2046
2047 if (r < (resPathCount - 1))
2048 {
2049 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex,
2050 TextFormat(" --preload-file %s/%s@%s \\\n", exCollection[x].category, resPaths[r], resPaths[r]));
2051 }
2052 else
2053 {
2054 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex,
2055 TextFormat(" --preload-file %s/%s@%s\n\n", exCollection[x].category, resPaths[r], resPaths[r]));
2056 }
2057 }
2058 }
2059 else // Example does not require resources
2060 {
2061 /*
2062 // WARNING: Compilation line starts with [TAB]
2063 core/core_2d_camera: core/core_2d_camera.c
2064 $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)
2065 */
2066 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex,
2067 TextFormat("%s/%s: %s/%s.c\n", exCollection[x].category, exCollection[x].name, exCollection[x].category, exCollection[x].name));
2068 mkwIndex += sprintf(mkwTextUpdated + mkwListStartIndex + mkwIndex, " $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDE_PATHS) $(LDFLAGS) $(LDLIBS) -D$(PLATFORM)\n\n");
2069 }
2070
2071 UnloadExampleResourcePaths(resPaths);
2072 }
2073
2074 UnloadExampleData(exCollection);
2075 }
2076
2077 // Add the remaining part of the original file
2078 memcpy(mkwTextUpdated + mkwListStartIndex + mkwIndex - 1, mkwText + mkwListEndIndex, strlen(mkwText) - mkwListEndIndex);
2079
2080 // Save updated file
2081 SaveFileText(TextFormat("%s/Makefile.Web", exBasePath), mkwTextUpdated);
2082 UnloadFileText(mkwText);
2083 RL_FREE(mkwTextUpdated);
2084 //------------------------------------------------------------------------------------------------
2085
2086 // Edit: raylib/examples/README.md --> Update from collection
2087 //------------------------------------------------------------------------------------------------
2088 LOG("INFO: Updating raylib/examples/README.md\n");
2089 // NOTE: Using [examples_list.txt] to update/regen README.md
2090 // Lines format: | 01 | [core_basic_window](core/core_basic_window.c) | <img src="core/core_basic_window.png" alt="core_basic_window" width="80"> | ⭐️☆☆☆ | 1.0 | 1.0 | [Ray](https://github.com/raysan5) |
2091 char *mdText = LoadFileText(TextFormat("%s/README.md", exBasePath));
2092 char *mdTextUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1); // Updated examples.js copy, 2MB
2093
2094 int mdListStartIndex = TextFindIndex(mdText, "## EXAMPLES COLLECTION");
2095
2096 int mdIndex = 0;
2097 memcpy(mdTextUpdated, mdText, mdListStartIndex);
2098
2099 int exCollectionFullCount = 0;
2100 rlExampleInfo *exCollectionFull = LoadExampleData("ALL", false, &exCollectionFullCount);
2101 UnloadExampleData(exCollectionFull);
2102
2103 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, TextFormat("## EXAMPLES COLLECTION [TOTAL: %i]\n", exCollectionFullCount));
2104
2105 // NOTE: We keep a global examples counter
2106 for (int i = 0; i < REXM_MAX_EXAMPLE_CATEGORIES; i++)
2107 {
2108 int exCollectionCount = 0;
2109 rlExampleInfo *exCollection = LoadExampleData(exCategories[i], false, &exCollectionCount);
2110
2111 // Every category includes some introductory text, as it is quite short, just copying it here
2112 if (i == 0) // "core"
2113 {
2114 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, TextFormat("\n### category: core [%i]\n\n", exCollectionCount));
2115 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2116 "Examples using raylib [core](../src/rcore.c) module platform functionality: window creation, inputs, drawing modes and system functionality.\n\n");
2117 }
2118 else if (i == 1) // "shapes"
2119 {
2120 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, TextFormat("\n### category: shapes [%i]\n\n", exCollectionCount));
2121 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2122 "Examples using raylib shapes drawing functionality, provided by raylib [shapes](../src/rshapes.c) module.\n\n");
2123 }
2124 else if (i == 2) // "textures"
2125 {
2126 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, TextFormat("\n### category: textures [%i]\n\n", exCollectionCount));
2127 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2128 "Examples using raylib textures functionality, including image/textures loading/generation and drawing, provided by raylib [textures](../src/rtextures.c) module.\n\n");
2129 }
2130 else if (i == 3) // "text"
2131 {
2132 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, TextFormat("\n### category: text [%i]\n\n", exCollectionCount));
2133 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2134 "Examples using raylib text functionality, including sprite fonts loading/generation and text drawing, provided by raylib [text](../src/rtext.c) module.\n\n");
2135 }
2136 else if (i == 4) // "models"
2137 {
2138 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, TextFormat("\n### category: models [%i]\n\n", exCollectionCount));
2139 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2140 "Examples using raylib models functionality, including models loading/generation and drawing, provided by raylib [models](../src/rmodels.c) module.\n\n");
2141 }
2142 else if (i == 5) // "shaders"
2143 {
2144 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, TextFormat("\n### category: shaders [%i]\n\n", exCollectionCount));
2145 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2146 "Examples using raylib shaders functionality, including shaders loading, parameters configuration and drawing using them (model shaders and postprocessing shaders). This functionality is directly provided by raylib [rlgl](../src/rlgl.h) module.\n\n");
2147 }
2148 else if (i == 6) // "audio"
2149 {
2150 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, TextFormat("\n### category: audio [%i]\n\n", exCollectionCount));
2151 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2152 "Examples using raylib audio functionality, including sound/music loading and playing. This functionality is provided by raylib [raudio](../src/raudio.c) module. Note this module can be used standalone independently of raylib.\n\n");
2153 }
2154
2155 // Table header required
2156 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, "| example | image | difficulty<br>level | version<br>created | last version<br>updated | original<br>developer |\n");
2157 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex, "|-----------|--------|:-------------------:|:------------------:|:-----------------------:|:----------------------|\n");
2158
2159 char starsText[16] = { 0 };
2160 for (int x = 0; x < exCollectionCount; x++)
2161 {
2162 for (int s = 0; s < 4; s++)
2163 {
2164 if (s < exCollection[x].stars) strcpy(starsText + 3*s, "⭐️"); // WARNING: Different than '★', more visual
2165 else strcpy(starsText + 3*s, "☆");
2166 }
2167
2168 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2169 TextFormat("| [%s](%s/%s.c) | <img src=\"%s/%s.png\" alt=\"%s\" width=\"80\"> | %s | %s | %s | [%s](https://github.com/%s) |\n",
2170 exCollection[x].name, exCollection[x].category, exCollection[x].name, exCollection[x].category, exCollection[x].name, exCollection[x].name,
2171 starsText, exCollection[x].verCreated, exCollection[x].verUpdated, exCollection[x].author, exCollection[x].authorGitHub));
2172 }
2173
2174 UnloadExampleData(exCollection);
2175 }
2176
2177 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2178 "\nSome example missing? As always, contributions are welcome, feel free to send new examples!\n");
2179 mdIndex += sprintf(mdTextUpdated + mdListStartIndex + mdIndex,
2180 "Here is an [examples template](examples_template.c) with instructions to start with!\n");
2181
2182 // Save updated file
2183 SaveFileText(TextFormat("%s/README.md", exBasePath), mdTextUpdated);
2184 UnloadFileText(mdText);
2185 RL_FREE(mdTextUpdated);
2186 //------------------------------------------------------------------------------------------------
2187
2188 // Edit: raylib.com/common/examples.js --> Update from collection
2189 // NOTE: Entries format: exampleEntry('⭐️☆☆☆' , 'core' , 'basic_window'),
2190 //------------------------------------------------------------------------------------------------
2191 LOG("INFO: Updating raylib.com/common/examples.js\n");
2192 char *jsText = LoadFileText(TextFormat("%s/../common/examples.js", exWebPath));
2193 if (!jsText)
2194 {
2195 LOG("INFO: examples.js not found, skipping web examples list update\n");
2196 }
2197 else
2198 {
2199 int jsListStartIndex = TextFindIndex(jsText, "//EXAMPLE_DATA_LIST_START");
2200 int jsListEndIndex = TextFindIndex(jsText, "//EXAMPLE_DATA_LIST_END");
2201 if ((jsListStartIndex < 0) || (jsListEndIndex < 0))
2202 {
2203 LOG("WARNING: examples.js markers not found, skipping update\n");
2204 UnloadFileText(jsText);
2205 }
2206 else
2207 {
2208 char *jsTextUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1); // Updated examples.js copy, 2MB
2209 int jsIndex = 0;
2210 memcpy(jsTextUpdated, jsText, jsListStartIndex);
2211 jsIndex = sprintf(jsTextUpdated + jsListStartIndex, "//EXAMPLE_DATA_LIST_START\n");
2212 jsIndex += sprintf(jsTextUpdated + jsListStartIndex + jsIndex, " var exampleData = [\n");
2213
2214 char starsText[16] = { 0 };
2215
2216 for (int i = 0; i < REXM_MAX_EXAMPLE_CATEGORIES; i++)
2217 {
2218 int exCollectionCount = 0;
2219 rlExampleInfo *exCollection = LoadExampleData(exCategories[i], false, &exCollectionCount);
2220 for (int x = 0; x < exCollectionCount; x++)
2221 {
2222 for (int s = 0; s < 4; s++)
2223 {
2224 if (s < exCollection[x].stars) strcpy(starsText + 3*s, "⭐️"); // WARNING: Different than '★', more visual
2225 else strcpy(starsText + 3*s, "☆");
2226 }
2227
2228 if ((i == 6) && (x == (exCollectionCount - 1)))
2229 {
2230 // NOTE: Last line to add, special case to consider
2231 jsIndex += sprintf(jsTextUpdated + jsListStartIndex + jsIndex,
2232 TextFormat(" exampleEntry('%s', '%s', '%s')];\n", starsText, exCollection[x].category, exCollection[x].name + strlen(exCollection[x].category) + 1));
2233 }
2234 else
2235 {
2236 jsIndex += sprintf(jsTextUpdated + jsListStartIndex + jsIndex,
2237 TextFormat(" exampleEntry('%s', '%s', '%s'),\n", starsText, exCollection[x].category, exCollection[x].name + strlen(exCollection[x].category) + 1));
2238 }
2239 }
2240
2241 UnloadExampleData(exCollection);
2242 }
2243
2244 // Add the remaining part of the original file
2245 memcpy(jsTextUpdated + jsListStartIndex + jsIndex, jsText + jsListEndIndex, strlen(jsText) - jsListEndIndex);
2246
2247 // Save updated file
2248 SaveFileText(TextFormat("%s/../common/examples.js", exWebPath), jsTextUpdated);
2249 UnloadFileText(jsText);
2250 RL_FREE(jsTextUpdated);
2251 }
2252 }
2253 //------------------------------------------------------------------------------------------------
2254
2255 return result;
2256 }
2257
2258 // Load examples information from collection data
2259 static rlExampleInfo *LoadExampleData(const char *filter, bool sort, int *exCount)
2260 {
2261 #define MAX_EXAMPLES_INFO 256
2262
2263 rlExampleInfo *exInfo = (rlExampleInfo *)RL_CALLOC(MAX_EXAMPLES_INFO, sizeof(rlExampleInfo));
2264 int exCounter = 0;
2265 *exCount = 0;
2266
2267 // Load main collection list file: "raylib/examples/examples_list.txt"
2268 char *text = LoadFileText(exCollectionFilePath);
2269
2270 if (text != NULL)
2271 {
2272 int lineCount = 0;
2273 char **lines = LoadTextLines(text, &lineCount);
2274
2275 for (int i = 0; i < lineCount; i++)
2276 {
2277 // Basic validation for lines start categories
2278 if ((lines[i][0] != '#') &&
2279 ((lines[i][0] == 'c') || // core
2280 (lines[i][0] == 's') || // shapes, shaders
2281 (lines[i][0] == 't') || // textures, text
2282 (lines[i][0] == 'm') || // models
2283 (lines[i][0] == 'a'))) // audio
2284 {
2285 rlExampleInfo info = { 0 };
2286 int result = ParseExampleInfoLine(lines[i], &info);
2287 if (result == 1) // Success on parsing
2288 {
2289 if (strcmp(filter, "ALL") == 0)
2290 {
2291 // Add all examples to the list
2292 memcpy(&exInfo[exCounter], &info, sizeof(rlExampleInfo));
2293 exCounter++;
2294 }
2295 else if (strcmp(info.category, filter) == 0)
2296 {
2297 // Get only specific category examples
2298 memcpy(&exInfo[exCounter], &info, sizeof(rlExampleInfo));
2299 exCounter++;
2300 }
2301 else if (strcmp(info.name, filter) == 0)
2302 {
2303 // Get only requested example
2304 memcpy(&exInfo[exCounter], &info, sizeof(rlExampleInfo));
2305 exCounter++;
2306 break;
2307 }
2308 }
2309 }
2310 }
2311
2312 UnloadTextLines(lines, lineCount);
2313 UnloadFileText(text);
2314 }
2315
2316 // Sorting required
2317 if (sort) SortExampleByName(exInfo, exCounter);
2318
2319 *exCount = exCounter;
2320 return exInfo;
2321 }
2322
2323 // Unload examples collection data
2324 static void UnloadExampleData(rlExampleInfo *exInfo)
2325 {
2326 RL_FREE(exInfo);
2327 }
2328
2329 // Get example info from example file header
2330 // WARNING: Expecting the example to follow raylib_example_template.c
2331 static rlExampleInfo *LoadExampleInfo(const char *exFileName)
2332 {
2333 rlExampleInfo *exInfo = NULL;
2334
2335 if (FileExists(exFileName) && IsFileExtension(exFileName, ".c"))
2336 {
2337 // Example found in collection
2338 exInfo = (rlExampleInfo *)RL_CALLOC(1, sizeof(rlExampleInfo));
2339
2340 strncpy(exInfo->name, GetFileNameWithoutExt(exFileName), 128 - 1);
2341 strncpy(exInfo->category, exInfo->name, TextFindIndex(exInfo->name, "_"));
2342
2343 char *exText = LoadFileText(exFileName);
2344
2345 // Get example difficulty stars
2346 // NOTE: Counting the unicode char occurrences: ★
2347 int starsIndex = TextFindIndex(exText, "★");
2348 if (starsIndex > 0)
2349 {
2350 const char *starPtr = exText + starsIndex;
2351 while (*starPtr)
2352 {
2353 if (((unsigned char)starPtr[0] == 0xe2) &&
2354 ((unsigned char)starPtr[1] == 0x98) &&
2355 ((unsigned char)starPtr[2] == 0x85))
2356 {
2357 exInfo->stars++;
2358 starPtr += 3; // Advance past multibyte character
2359 }
2360 else starPtr++;
2361 }
2362 }
2363
2364 // Get example create with raylib version
2365 int verCreateIndex = TextFindIndex(exText, "created with raylib "); // Version = index + 20
2366 int verCreatedLen = 0;
2367 for (int i = verCreateIndex + 20; (exText[i] != ' ') && (exText[i] != '\n') && (exText[i] != ','); i++) verCreatedLen++;
2368 if (verCreateIndex > 0) strncpy(exInfo->verCreated, exText + verCreateIndex + 20, verCreatedLen);
2369 else strcpy(exInfo->verCreated, RAYLIB_VERSION); // Use current raylib version
2370
2371 // Get example update with raylib version
2372 int verUpdateIndex = TextFindIndex(exText, "updated with raylib "); // Version = index + 20
2373 int verUpdateLen = 0;
2374 for (int i = verUpdateIndex + 20; (exText[i] != ' ') && (exText[i] != '\n') && (exText[i] != ','); i++) verUpdateLen++;
2375 if (verUpdateIndex > 0) strncpy(exInfo->verUpdated, exText + verUpdateIndex + 20, verUpdateLen);
2376 else strcpy(exInfo->verUpdated, RAYLIB_VERSION); // Use current raylib version
2377
2378 // Get example years created/reviewed and creator and github user
2379 // NOTE: Using copyright line instead of "Example contributed by " because
2380 // most examples do not contain that line --> TODO: Review examples header formating?
2381 // Expected format: Copyright (c) <year_created>-<year_updated> <user_name> (@<user_github>)
2382 // Alternatives: Copyright (c) <year_created> <author_name> (@<user_github>) and <contrib_name> (@<contrib_user>)
2383 int copyrightIndex = TextFindIndex(exText, "Copyright (c) ");
2384 int yearStartIndex = copyrightIndex + 14;
2385 char yearText[5] = { 0 };
2386 strncpy(yearText, exText + yearStartIndex, 4);
2387 exInfo->yearCreated = TextToInteger(yearText);
2388 // Check for review year included (or just use creation year)
2389 if (exText[yearStartIndex + 4] == '-') strncpy(yearText, exText + yearStartIndex + 5, 4);
2390 exInfo->yearReviewed = TextToInteger(yearText);
2391 int yearEndIndex = TextFindIndex(exText + yearStartIndex, " ");
2392 int authorStartIndex = yearStartIndex + yearEndIndex + 1;
2393 int authorEndIndex = TextFindIndex(exText + authorStartIndex, " (@");
2394 if (authorEndIndex != -1) // Github user also available
2395 {
2396 authorEndIndex += authorStartIndex;
2397 strncpy(exInfo->author, exText + authorStartIndex, authorEndIndex - authorStartIndex);
2398
2399 // Get GitHub user
2400 int userStartIndex = authorEndIndex + 3;
2401 int userEndIndex = TextFindIndex(exText + userStartIndex, ")");
2402 userEndIndex += userStartIndex;
2403 strncpy(exInfo->authorGitHub, exText + userStartIndex, userEndIndex - userStartIndex);
2404 }
2405 else // GitHub user not found to set end, using '\n'
2406 {
2407 authorEndIndex = TextFindIndex(exText + authorStartIndex, "\n");
2408 authorEndIndex += authorStartIndex;
2409 strncpy(exInfo->author, exText + authorStartIndex, authorEndIndex - authorStartIndex);
2410 }
2411
2412 UnloadFileText(exText);
2413
2414 exInfo->resPaths = LoadExampleResourcePaths(exFileName, &exInfo->resCount);
2415 }
2416
2417 return exInfo;
2418 }
2419
2420 // Unload example information
2421 static void UnloadExampleInfo(rlExampleInfo *exInfo)
2422 {
2423 UnloadExampleResourcePaths(exInfo->resPaths);
2424 RL_FREE(exInfo);
2425 }
2426
2427 // raylib example line info parser
2428 // Parses following line format: core;core_basic_window;★☆☆☆;1.0;1.0;2013;2026;"Ray";@raysan5
2429 static int ParseExampleInfoLine(const char *line, rlExampleInfo *entry)
2430 {
2431 #define MAX_EXAMPLE_INFO_LINE_LEN 512
2432
2433 char temp[MAX_EXAMPLE_INFO_LINE_LEN] = { 0 };
2434 strncpy(temp, line, MAX_EXAMPLE_INFO_LINE_LEN);
2435 temp[MAX_EXAMPLE_INFO_LINE_LEN - 1] = '\0'; // Ensure null termination
2436
2437 int tokenCount = 0;
2438 char **tokens = TextSplit(line, ';', &tokenCount);
2439
2440 if (tokenCount != 9)
2441 {
2442 LOG("REXM: WARNING: Example collection line contains invalid number of tokens: %i\n", tokenCount);
2443 }
2444
2445 // Get category and name
2446 strcpy(entry->category, tokens[0]);
2447 strcpy(entry->name, tokens[1]);
2448
2449 // Parsing stars
2450 // NOTE: Counting the unicode char occurrences: ★
2451 const char *starPtr = tokens[2];
2452 while (*starPtr)
2453 {
2454 if (((unsigned char)starPtr[0] == 0xe2) &&
2455 ((unsigned char)starPtr[1] == 0x98) &&
2456 ((unsigned char)starPtr[2] == 0x85))
2457 {
2458 entry->stars++;
2459 starPtr += 3; // Advance past multibyte character
2460 }
2461 else starPtr++;
2462 }
2463
2464 // Get raylib creation/update versions
2465 strcpy(entry->verCreated, tokens[3]);
2466 strcpy(entry->verUpdated, tokens[4]);
2467
2468 // Get year created and year reviewed
2469 entry->yearCreated = TextToInteger(tokens[5]);
2470 entry->yearReviewed = TextToInteger(tokens[6]);
2471
2472 // Get author and github
2473 if (tokens[7][0] == '"') tokens[7] += 1;
2474 if (tokens[7][strlen(tokens[7]) - 1] == '"') tokens[7][strlen(tokens[7]) - 1] = '\0';
2475 strcpy(entry->author, tokens[7]);
2476 strcpy(entry->authorGitHub, tokens[8] + 1); // Skip '@'
2477
2478 return 1;
2479 }
2480
2481 // Text compare, required for qsort() function
2482 static int rlExampleInfoCompare(const void *a, const void *b)
2483 {
2484 const rlExampleInfo *ex1 = (const rlExampleInfo *)a;
2485 const rlExampleInfo *ex2 = (const rlExampleInfo *)b;
2486
2487 return strcmp(ex1->name, ex2->name);
2488 }
2489
2490 // Sort array of strings by name
2491 // WARNING: items[] pointers are reorganized
2492 static void SortExampleByName(rlExampleInfo *items, int count)
2493 {
2494 qsort(items, count, sizeof(rlExampleInfo), rlExampleInfoCompare);
2495 }
2496
2497 // Scan asset paths from a source code file (raylib)
2498 // WARNING: Supported asset file extensions are hardcoded by used file types
2499 // but new examples could require other file extensions to be added
2500 static char **LoadExampleResourcePaths(const char *srcFilePath, int *resPathCount)
2501 {
2502 char **paths = (char **)RL_CALLOC(REXM_MAX_RESOURCE_PATHS, sizeof(char **));
2503 for (int i = 0; i < REXM_MAX_RESOURCE_PATHS; i++) paths[i] = (char *)RL_CALLOC(REXM_MAX_RESOURCE_PATH_LENGTH, sizeof(char));
2504
2505 int resCounter = 0;
2506 char *code = LoadFileText(srcFilePath);
2507
2508 if (code != NULL)
2509 {
2510 // Resources extensions to check
2511 const char *exts[] = { ".png", ".bmp", ".jpg", ".qoi", ".gif", ".raw", ".hdr", ".ttf", ".fnt", ".wav", ".ogg", ".mp3", ".flac", ".mod", ".xm", ".qoa", ".obj", ".iqm", ".glb", ".m3d", ".vox", ".vs", ".fs", ".txt" };
2512 const int extCount = sizeof(exts)/sizeof(char *);
2513
2514 char *ptr = code;
2515 while ((ptr = strchr(ptr, '"')) != NULL)
2516 {
2517 char *start = ptr + 1;
2518 char *end = strchr(start, '"');
2519 if (!end) break;
2520
2521 // WARNING: Some paths could be for saving files, not loading, those "resource" files must be omitted
2522 // TODO: HACK: Just check previous position from pointer for function name including the string and the index "distance"
2523 // This is a quick solution, the good one would be getting the data loading function names...
2524 int functionIndex01 = TextFindIndex(ptr - 40, "ExportImage"); // Check ExportImage()
2525 int functionIndex02 = TextFindIndex(ptr - 10, "TraceLog"); // Check TraceLog()
2526 int functionIndex03 = TextFindIndex(ptr - 40, "TakeScreenshot"); // Check TakeScreenshot()
2527 int functionIndex04 = TextFindIndex(ptr - 40, "SaveFileData"); // Check SaveFileData()
2528 int functionIndex05 = TextFindIndex(ptr - 40, "SaveFileText"); // Check SaveFileText()
2529
2530 if (!((functionIndex01 != -1) && (functionIndex01 < 40)) && // Not found ExportImage() before ""
2531 !((functionIndex02 != -1) && (functionIndex02 < 10)) && // Not found TraceLog() before ""
2532 !((functionIndex03 != -1) && (functionIndex03 < 40)) && // Not found TakeScreenshot() before ""
2533 !((functionIndex04 != -1) && (functionIndex04 < 40)) && // Not found TakeScreenshot() before ""
2534 !((functionIndex05 != -1) && (functionIndex05 < 40))) // Not found SaveFileText() before ""
2535 {
2536 int len = (int)(end - start);
2537 if ((len > 0) && (len < REXM_MAX_RESOURCE_PATH_LENGTH))
2538 {
2539 char buffer[REXM_MAX_RESOURCE_PATH_LENGTH] = { 0 };
2540 strncpy(buffer, start, len);
2541 buffer[len] = '\0';
2542
2543 // Check for known extensions
2544 for (int i = 0; i < extCount; i++)
2545 {
2546 // NOTE: IsFileExtension() expects a NULL terminated fileName string,
2547 // it looks for the last '.' and checks "extension" after that
2548 if (IsFileExtension(buffer, exts[i]))
2549 {
2550 // Avoid duplicates
2551 bool found = false;
2552 for (int j = 0; j < resCounter; j++)
2553 {
2554 if (strcmp(paths[j], buffer) == 0) { found = true; break; }
2555 }
2556
2557 if (!found && (resCounter < REXM_MAX_RESOURCE_PATHS))
2558 {
2559 strcpy(paths[resCounter], buffer);
2560 resCounter++;
2561 }
2562
2563 break;
2564 }
2565 }
2566 }
2567 }
2568
2569 ptr = end + 1;
2570 }
2571
2572 UnloadFileText(code);
2573 }
2574
2575 /*
2576 // WARNING: Some resources could require linked resources: .fnt --> .png, .mtl --> .png, .gltf --> .png
2577 // So doing a recursive pass to scan possible files with second resources
2578 int currentAssetCounter = resCounter;
2579 for (int i = 0; i < currentAssetCounter; i++)
2580 {
2581 if (IsFileExtension(paths[i], ".fnt;.gltf"))
2582 {
2583 int assetCount2 = 0;
2584 // ERROR: srcFilePath changes on rcursive call and TextFormat() static arrays are override
2585 char **assetPaths2 = LoadExampleResourcePaths(TextFormat("%s/%s", GetDirectoryPath(srcFilePath), paths[i]), &assetCount2);
2586
2587 for (int j = 0; j < assetCount2; j++)
2588 {
2589 strcpy(paths[resCounter], TextFormat("%s/%s", GetDirectoryPath(paths[i]) + 2, assetPaths2[j]));
2590 resCounter++;
2591 }
2592
2593 UnloadExampleResourcePaths(assetPaths2);
2594 }
2595 }
2596 */
2597
2598 *resPathCount = resCounter;
2599 return paths;
2600 }
2601
2602 // Clear resource paths scanned
2603 static void UnloadExampleResourcePaths(char **resPaths)
2604 {
2605 for (int i = 0; i < REXM_MAX_RESOURCE_PATHS; i++) RL_FREE(resPaths[i]);
2606
2607 RL_FREE(resPaths);
2608 }
2609
2610 // Add VS project (.vcxproj) to existing VS solution (.sln)
2611 // WARNING: Adding a .vcxproj to .sln can not be automated with:
2612 // - "dotnet" tool (C# projects only)
2613 // - "devenv" tool (no adding support, only building)
2614 // It must be done manually editing the .sln file
2615 static int AddVSProjectToSolution(const char *slnFile, const char *projFile, const char *category)
2616 {
2617 int result = 0;
2618
2619 // WARNING: Function uses extensively TextFormat(),
2620 // *projFile ptr could be overwriten after a while -> Use copied string
2621
2622 // Generate unique UUID
2623 const char *uuid = GenerateUUIDv4();
2624
2625 // Replace default UUID (core_basic_window) on project file by new one
2626 FileTextReplace(projFile, "0981CA98-E4A5-4DF1-987F-A41D09131EFC", uuid);
2627
2628 char *slnText = LoadFileText(slnFile);
2629 char *slnTextUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1);
2630
2631 // Add project to solution
2632 //----------------------------------------------------------------------------------------
2633 // Format: Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "<project_name>", "examples\<project_name>.vcxproj", "{<project_uuid>}"
2634 // NOTE: Find a position to insert new project: At the end of the projects list, same strategy as VS2022 "Add Project"
2635 int prjStartIndex = TextFindIndex(slnText, "Global");
2636
2637 // Add new project info
2638 // WARNING: UUID can actually be duplicated and it still works...
2639 strncpy(slnTextUpdated, slnText, prjStartIndex);
2640 int offsetIndex = sprintf(slnTextUpdated + prjStartIndex,
2641 TextFormat("Project(\"{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}\") = \"%s\", \"examples\\%s\", \"{%s}\"\n",
2642 GetFileNameWithoutExt(projFile), GetFileName(projFile), uuid));
2643 offsetIndex += prjStartIndex;
2644 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "EndProject\n");
2645 //----------------------------------------------------------------------------------------
2646
2647 // Update project config
2648 //----------------------------------------------------------------------------------------
2649 // Find position to add project config: At the end of global section, same strategy as VS2022 "Add Project"
2650 int projConfStartIndex = TextFindIndex(slnText, "GlobalSection(ProjectConfigurationPlatforms) = postSolution");
2651 strncpy(slnTextUpdated + offsetIndex, slnText + prjStartIndex, projConfStartIndex - prjStartIndex);
2652 offsetIndex += (projConfStartIndex - prjStartIndex);
2653
2654 int projConfEndIndex = TextFindIndex(slnText + projConfStartIndex, "EndGlobalSection");
2655 projConfEndIndex += projConfStartIndex;
2656
2657 strncpy(slnTextUpdated + offsetIndex, slnText + projConfStartIndex, projConfEndIndex - projConfStartIndex);
2658 offsetIndex += (projConfEndIndex - projConfStartIndex);
2659
2660 // Add project config lines
2661 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t{%s}.Debug.DLL|ARM64.ActiveCfg = Debug.DLL|ARM64\n", uuid));
2662 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug.DLL|ARM64.Build.0 = Debug.DLL|ARM64\n", uuid));
2663 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug.DLL|x64.ActiveCfg = Debug.DLL|x64\n", uuid));
2664 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug.DLL|x64.Build.0 = Debug.DLL|x64\n", uuid));
2665 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug.DLL|x86.ActiveCfg = Debug.DLL|Win32\n", uuid));
2666 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug.DLL|x86.Build.0 = Debug.DLL|Win32\n", uuid));
2667 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug|ARM64.ActiveCfg = Debug|ARM64\n", uuid));
2668 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug|ARM64.Build.0 = Debug|ARM64\n", uuid));
2669 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug|x64.ActiveCfg = Debug|x64\n", uuid));
2670 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug|x64.Build.0 = Debug|x64\n", uuid));
2671 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug|x86.ActiveCfg = Debug|Win32\n", uuid));
2672 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Debug|x86.Build.0 = Debug|Win32\n", uuid));
2673 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release.DLL|ARM64.ActiveCfg = Release.DLL|ARM64\n", uuid));
2674 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release.DLL|ARM64.Build.0 = Release.DLL|ARM64\n", uuid));
2675 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release.DLL|x64.ActiveCfg = Release.DLL|x64\n", uuid));
2676 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release.DLL|x64.Build.0 = Release.DLL|x64\n", uuid));
2677 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release.DLL|x86.ActiveCfg = Release.DLL|Win32\n", uuid));
2678 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release.DLL|x86.Build.0 = Release.DLL|Win32\n", uuid));
2679 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release|ARM64.ActiveCfg = Release|ARM64\n", uuid));
2680 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release|ARM64.Build.0 = Release|ARM64\n", uuid));
2681 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release|x64.ActiveCfg = Release|x64\n", uuid));
2682 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release|x64.Build.0 = Release|x64\n", uuid));
2683 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release|x86.ActiveCfg = Release|Win32\n", uuid));
2684 offsetIndex += sprintf(slnTextUpdated + offsetIndex, TextFormat("\t\t{%s}.Release|x86.Build.0 = Release|Win32\n", uuid));
2685 // Write next section directly to avoid copy logic
2686 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "\tEndGlobalSection\n");
2687 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "\tGlobalSection(SolutionProperties) = preSolution\n");
2688 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "\t\tHideSolutionNode = FALSE\n");
2689 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "\tEndGlobalSection\n\t");
2690 //----------------------------------------------------------------------------------------
2691
2692 // Place project to explorer folder
2693 //----------------------------------------------------------------------------------------
2694 // Find position to add project folder: At the end of global section, same strategy as VS2022 "Add Project"
2695 int projFolderStartIndex = TextFindIndex(slnText, "GlobalSection(NestedProjects) = preSolution");
2696 int projFolderEndIndex = TextFindIndex(slnText + projFolderStartIndex, "\tEndGlobalSection");
2697 projFolderEndIndex += projFolderStartIndex;
2698
2699 strncpy(slnTextUpdated + offsetIndex, slnText + projFolderStartIndex, projFolderEndIndex - projFolderStartIndex);
2700 offsetIndex += (projFolderEndIndex - projFolderStartIndex);
2701
2702 // Add project folder line
2703 // NOTE: Folder uuid depends on category
2704 if (strcmp(category, "core") == 0) offsetIndex += sprintf(slnTextUpdated + offsetIndex,
2705 TextFormat("\t\t{%s} = {6C82BAAE-BDDF-457D-8FA8-7E2490B07035}\n", uuid));
2706 else if (strcmp(category, "shapes") == 0) offsetIndex += sprintf(slnTextUpdated + offsetIndex,
2707 TextFormat("\t\t{%s} = {278D8859-20B1-428F-8448-064F46E1F021}\n", uuid));
2708 else if (strcmp(category, "textures") == 0) offsetIndex += sprintf(slnTextUpdated + offsetIndex,
2709 TextFormat("\t\t{%s} = {DA049009-21FF-4AC0-84E4-830DD1BCD0CE}\n", uuid));
2710 else if (strcmp(category, "text") == 0) offsetIndex += sprintf(slnTextUpdated + offsetIndex,
2711 TextFormat("\t\t{%s} = {8D3C83B7-F1E0-4C2E-9E34-EE5F6AB2502A}\n", uuid));
2712 else if (strcmp(category, "models") == 0) offsetIndex += sprintf(slnTextUpdated + offsetIndex,
2713 TextFormat("\t\t{%s} = {AF5BEC5C-1F2B-4DA8-B12D-D09FE569237C}\n", uuid));
2714 else if (strcmp(category, "shaders") == 0) offsetIndex += sprintf(slnTextUpdated + offsetIndex,
2715 TextFormat("\t\t{%s} = {5317807F-61D4-4E0F-B6DC-2D9F12621ED9}\n", uuid));
2716 else if (strcmp(category, "audio") == 0) offsetIndex += sprintf(slnTextUpdated + offsetIndex,
2717 TextFormat("\t\t{%s} = {CC132A4D-D081-4C26-BFB9-AB11984054F8}\n", uuid));
2718 else if (strcmp(category, "other") == 0) offsetIndex += sprintf(slnTextUpdated + offsetIndex,
2719 TextFormat("\t\t{%s} = {E9D708A5-9C1F-4B84-A795-C5F191801762}\n", uuid));
2720 else LOG("WARNING: Provided category is not valid: %s\n", category);
2721 //----------------------------------------------------------------------------------------
2722
2723 // Write end of file, no need to copy from original file
2724 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "\tEndGlobalSection\n");
2725 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "\tGlobalSection(ExtensibilityGlobals) = postSolution\n");
2726 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "\t\tSolutionGuid = {E926C768-6307-4423-A1EC-57E95B1FAB29}\n");
2727 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "\tEndGlobalSection\n");
2728 offsetIndex += sprintf(slnTextUpdated + offsetIndex, "EndGlobal\n");
2729
2730 SaveFileText(slnFile, slnTextUpdated);
2731 UnloadFileText(slnText);
2732 RL_FREE(slnTextUpdated);
2733
2734 return result;
2735 }
2736
2737 // Remove VS project (.vcxproj) to existing VS solution (.sln)
2738 static int RemoveVSProjectFromSolution(const char *slnFile, const char *exName)
2739 {
2740 int result = 0;
2741
2742 // Lines to be removed from solution file:
2743 //Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "core_random_values", "examples\core_random_values.vcxproj", "{B332DCA8-3599-4A99-917A-82261BDC27AC}"
2744 //EndProject
2745 // All lines starting with:
2746 //"\t\t{B332DCA8-3599-4A99-917A-82261BDC27AC}."
2747
2748 char *slnText = LoadFileText(slnFile);
2749 char *slnTextUpdated = (char *)RL_CALLOC(REXM_MAX_BUFFER_SIZE, 1);
2750
2751 int lineCount = 0;
2752 char **lines = LoadTextLines(slnText, &lineCount); // WARNING: Max 512 lines, we need +4000!
2753
2754 char uuid[38] = { 0 };
2755 strcpy(uuid, "ABCDEF00-0123-4567-89AB-000000000012"); // Temp value
2756 int textUpdatedOfsset = 0;
2757 int exNameLen = (int)strlen(exName);
2758
2759 for (int i = 0, index = 0; i < lineCount; i++)
2760 {
2761 index = TextFindIndex(lines[i], exName);
2762 if (index > 0)
2763 {
2764 // Found line with project --> get UUID
2765 strncpy(uuid, lines[i] + index + exNameLen*2 + 26, 36);
2766
2767 // Skip copying line and also next one
2768 i++;
2769 }
2770 else
2771 {
2772 if (TextFindIndex(lines[i], uuid) == -1)
2773 textUpdatedOfsset += sprintf(slnTextUpdated + textUpdatedOfsset, "%s\n", lines[i]);
2774 }
2775 }
2776
2777 SaveFileText(slnFile, slnTextUpdated);
2778
2779 UnloadTextLines(lines, lineCount);
2780 UnloadFileText(slnText);
2781 RL_FREE(slnTextUpdated);
2782
2783 return result;
2784 }
2785
2786 // Generate unique UUID v4 string
2787 // Output format: {9A2F48CC-0DA8-47C0-884E-02E37F9BE6C1}
2788 static const char *GenerateUUIDv4(void)
2789 {
2790 static char uuid[38] = { 0 };
2791 memset(uuid, 0, 38);
2792
2793 unsigned char bytes[16] = { 0 };
2794
2795 for (int i = 0; i < 16; i++) bytes[i] = (unsigned char)GetRandomValue(0, 255);
2796
2797 // Set version (4) and variant (RFC 4122)
2798 bytes[6] = (bytes[6] & 0x0F) | 0x40; // Version
2799 bytes[8] = (bytes[8] & 0x3F) | 0x80; // Variant
2800
2801 snprintf(uuid, 38,
2802 "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
2803 bytes[0], bytes[1], bytes[2], bytes[3],
2804 bytes[4], bytes[5],
2805 bytes[6], bytes[7],
2806 bytes[8], bytes[9],
2807 bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]);
2808
2809 return uuid;
2810 }
2811
2812 // Update source code header and comments metadata
2813 static void UpdateSourceMetadata(const char *exSrcPath, const rlExampleInfo *info)
2814 {
2815 if (FileExists(exSrcPath) && IsFileExtension(exSrcPath, ".c") && (!TextIsEqual(info->category, "others")))
2816 {
2817 // WARNING: Cache a copy of exSrcPath to avoid modifications by TextFormat()
2818 char exSourcePath[512] = { 0 };
2819 strcpy(exSourcePath, exSrcPath);
2820
2821 char *exText = LoadFileText(exSourcePath);
2822 char *exTextUpdated[6] = { 0 }; // Pointers to multiple updated text versions
2823 char *exTextUpdatedPtr = exText; // Pointer to current valid text version
2824
2825 char exNameFormated[256] = { 0 }; // Example name without category and using spaces
2826 int exNameIndex = TextFindIndex(info->name, "_");
2827 strcpy(exNameFormated, info->name + exNameIndex + 1);
2828 int exNameLen = (int)strlen(exNameFormated);
2829 for (int i = 0; i < exNameLen; i++) { if (exNameFormated[i] == '_') exNameFormated[i] = ' '; }
2830
2831 // Update example header title (line #3 - ALWAYS)
2832 // String: "* raylib [shaders] example - texture drawing"
2833 exTextUpdated[0] = TextReplaceBetweenAlloc(exTextUpdatedPtr, "* raylib [", "\n",
2834 TextFormat("%s] example - %s", info->category, exNameFormated));
2835 if (exTextUpdated[0] != NULL) exTextUpdatedPtr = exTextUpdated[0];
2836
2837 // Update example complexity rating
2838 // String: "* Example complexity rating: [★★☆☆] 2/4"
2839 // Get example difficulty stars text
2840 char starsText[16] = { 0 };
2841 for (int i = 0; i < 4; i++)
2842 {
2843 // NOTE: Every UTF-8 star are 3 bytes
2844 if (i < info->stars) strcpy(starsText + 3*i, "★");
2845 else strcpy(starsText + 3*i, "☆");
2846 }
2847 exTextUpdated[1] = TextReplaceBetweenAlloc(exTextUpdatedPtr, "* Example complexity rating: [", "/4\n",
2848 TextFormat("%s] %i", starsText, info->stars));
2849 if (exTextUpdated[1] != NULL) exTextUpdatedPtr = exTextUpdated[1];
2850
2851 // Update example creation/update raylib versions
2852 // String: "* Example originally created with raylib 2.0, last time updated with raylib 3.7
2853 exTextUpdated[2] = TextReplaceBetweenAlloc(exTextUpdatedPtr, "* Example originally created with raylib ", "\n",
2854 TextFormat("%s, last time updated with raylib %s", info->verCreated, info->verUpdated));
2855 if (exTextUpdated[2] != NULL) exTextUpdatedPtr = exTextUpdated[2];
2856
2857 // Update copyright message
2858 // String: "* Copyright (c) 2019-2026 Contributor Name (@github_user) and Ramon Santamaria (@raysan5)"
2859 if (info->yearCreated == info->yearReviewed)
2860 {
2861 exTextUpdated[3] = TextReplaceBetweenAlloc(exTextUpdatedPtr, "Copyright (c) ", ")",
2862 TextFormat("%i %s (@%s", info->yearCreated, info->author, info->authorGitHub));
2863 if (exTextUpdated[3] != NULL) exTextUpdatedPtr = exTextUpdated[3];
2864 }
2865 else
2866 {
2867 exTextUpdated[3] = TextReplaceBetweenAlloc(exTextUpdatedPtr, "Copyright (c) ", ")",
2868 TextFormat("%i-%i %s (@%s", info->yearCreated, info->yearReviewed, info->author, info->authorGitHub));
2869 if (exTextUpdated[3] != NULL) exTextUpdatedPtr = exTextUpdated[3];
2870 }
2871
2872 // Update window title
2873 // String: "InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture drawing");"
2874 exTextUpdated[4] = TextReplaceBetweenAlloc(exTextUpdated[3], "InitWindow(screenWidth, screenHeight, \"", "\");",
2875 TextFormat("raylib [%s] example - %s", info->category, exNameFormated));
2876 if (exTextUpdated[4] != NULL) exTextUpdatedPtr = exTextUpdated[4];
2877
2878 // Update contributors names
2879 // String: "* Example contributed by Contributor Name (@github_user) and reviewed by Ramon Santamaria (@raysan5)"
2880 // WARNING: Not all examples are contributed by someone, so the result of this replace can be NULL (string not found)
2881 exTextUpdated[5] = TextReplaceBetweenAlloc(exTextUpdatedPtr, "* Example contributed by ", ")",
2882 TextFormat("%s (@%s", info->author, info->authorGitHub));
2883 if (exTextUpdated[5] != NULL) exTextUpdatedPtr = exTextUpdated[5];
2884
2885 if (exTextUpdatedPtr != NULL) SaveFileText(exSourcePath, exTextUpdatedPtr);
2886
2887 for (int i = 0; i < 6; i++) { MemFree(exTextUpdated[i]); exTextUpdated[i] = NULL; }
2888
2889 UnloadFileText(exText);
2890 }
2891 }
2892
2893 // Update generated Web example .html file metadata
2894 static void UpdateWebMetadata(const char *exHtmlPath, const char *exFilePath)
2895 {
2896 if (FileExists(exHtmlPath) && IsFileExtension(exHtmlPath, ".html"))
2897 {
2898 // WARNING: Cache a copy of exHtmlPath to avoid modifications by TextFormat()
2899 char exHtmlPathCopy[512] = { 0 };
2900 strcpy(exHtmlPathCopy, exHtmlPath);
2901
2902 char *exHtmlText = LoadFileText(exHtmlPathCopy);
2903 char *exHtmlTextUpdated[6] = { 0 }; // Pointers to multiple updated text versions
2904
2905 char exName[64] = { 0 }; // Example name: fileName without extension
2906 char exCategory[16] = { 0 }; // Example category: core, shapes, text, textures, models, audio, shaders
2907 char exDescription[256] = { 0 }; // Example description: example text line #3
2908 char exTitle[64] = { 0 }; // Example title: fileName without extension, replacing underscores by spaces
2909
2910 // Get example name: replace underscore by spaces
2911 strncpy(exName, GetFileNameWithoutExt(exHtmlPathCopy), 64 - 1);
2912 strcpy(exTitle, exName);
2913 for (int i = 0; (i < 64) && (exTitle[i] != '\0'); i++) { if (exTitle[i] == '_') exTitle[i] = ' '; }
2914
2915 // Get example category from exName: copy until first underscore
2916 for (int i = 0; (exName[i] != '_'); i++) exCategory[i] = exName[i];
2917
2918 // Get example description: copy line #3 from example file
2919 char *exText = LoadFileText(exFilePath);
2920 int lineCount = 0;
2921 char **lines = LoadTextLines(exText, &lineCount);
2922 int lineLength = (int)strlen(lines[2]);
2923 strncpy(exDescription, lines[2] + 4, lineLength - 4);
2924 UnloadTextLines(lines, lineCount);
2925 UnloadFileText(exText);
2926
2927 // Update example.html required text
2928 exHtmlTextUpdated[0] = TextReplaceAlloc(exHtmlText, "raylib web game", exTitle);
2929 exHtmlTextUpdated[1] = TextReplaceAlloc(exHtmlTextUpdated[0], "New raylib web videogame, developed using raylib videogames library", exDescription);
2930 exHtmlTextUpdated[2] = TextReplaceAlloc(exHtmlTextUpdated[1], "https://www.raylib.com/common/raylib_logo.png",
2931 TextFormat("https://raw.githubusercontent.com/raysan5/raylib/master/examples/%s/%s.png", exCategory, exName));
2932 exHtmlTextUpdated[3] = TextReplaceAlloc(exHtmlTextUpdated[2], "https://www.raylib.com/games.html",
2933 TextFormat("https://www.raylib.com/examples/%s/%s.html", exCategory, exName));
2934 exHtmlTextUpdated[4] = TextReplaceAlloc(exHtmlTextUpdated[3], "raylib - example", TextFormat("raylib - %s", exName)); // og:site_name
2935 exHtmlTextUpdated[5] = TextReplaceAlloc(exHtmlTextUpdated[4], "https://github.com/raysan5/raylib",
2936 TextFormat("https://github.com/raysan5/raylib/blob/master/examples/%s/%s.c", exCategory, exName));
2937
2938 SaveFileText(exHtmlPathCopy, exHtmlTextUpdated[5]);
2939
2940 //LOG("INFO: [%s] Updated successfully\n",files.paths[i]);
2941 //LOG(" - Name / Title: %s / %s\n", exName, exTitle);
2942 //LOG(" - Description: %s\n", exDescription);
2943 //LOG(" - URL: %s\n", TextFormat("https://www.raylib.com/examples/%s/%s.html", exCategory, exName));
2944 //LOG(" - URL Source: %s\n", TextFormat("https://github.com/raysan5/raylib/blob/master/examples/%s/%s.c", exCategory, exName));
2945
2946 for (int i = 0; i < 6; i++) { MemFree(exHtmlTextUpdated[i]); exHtmlTextUpdated[i] = NULL; }
2947
2948 UnloadFileText(exHtmlText);
2949 }
2950 }
2951
2952 // Check if text string is a list of strings
2953 static int GetTextListIndex(const char *text, const char **list, int listCount)
2954 {
2955 int result = -1;
2956
2957 for (int i = 0; i < listCount; i++)
2958 {
2959 if (TextIsEqual(text, list[i])) { result = i; break; }
2960 }
2961
2962 return result;
2963 }
2964
2965 #if defined(__GNUC__) // GCC and Clang
2966 #pragma GCC diagnostic pop
2967 #endif