refactor(WIP): replace event stubs with module identification logic

Replace the placeholder TODO logs in the polling loop with logic to
resolve filesystem events into specific module indices.

- Centralizing State: Refactored is_module_loaded to is_mod_loaded to
  check against the global stk_module_ids array, removing the need to
  pass local buffers and preparing for unified lifetime management.
- Standardizing Identity: Updated extract_module_id to use a
  consistent output buffer.
- Categorized Event Processing: Implemented a two-pass approach in
  stk_poll to count event types (LOAD, UNLOAD, RELOAD) and allocate
  tracking arrays, replacing the previous stubbed switch statement.
- Mapping Events to Indices: The poll loop now resolves filenames
  back to their specific loaded indices via is_mod_loaded to
  identify exactly which mod_id and index require action.
- Improved Flow Control: Introduced a finish_stk_poll label to
  ensure consistent cleanup and return values when no events are
  detected or processing is complete.
This commit is contained in:
2026-01-27 07:54:51 +01:00
parent c558032ea0
commit 9491b070d2
3 changed files with 52 additions and 39 deletions
+4 -25
View File
@@ -66,34 +66,13 @@ uint8_t is_valid_module_file(const char *filename)
return strcmp(ext, STK_MODULE_EXT) == 0;
}
int is_module_loaded(const char *filename,
char (*loaded_module_ids)[STK_MOD_ID_BUFFER],
size_t loaded_count)
int is_mod_loaded(const char *module_name)
{
char module_id[STK_MOD_ID_BUFFER];
const char *basename;
char *dot;
size_t i;
basename = strrchr(filename, '/');
#ifdef _WIN32
if (!basename)
basename = strrchr(filename, '\\');
#endif
if (!basename)
basename = filename;
else
basename++;
strncpy(module_id, basename, STK_MOD_ID_BUFFER - 1);
module_id[STK_MOD_ID_BUFFER - 1] = '\0';
dot = strrchr(module_id, '.');
if (dot)
*dot = '\0';
for (i = 0; i < loaded_count; i++)
if (strcmp(loaded_module_ids[i], module_id) == 0)
for (i = 0; i < module_count; i++)
if (strncmp(stk_module_ids[i], module_name,
STK_MOD_ID_BUFFER) == 0)
return i;
return -1;