- deps = gKernelModules[i].Dependencies;
-
- if( deps )
- {
- for( j = 0; deps[j]; j++ )
- {
- for( k = 0; k < giNumBuiltinModules; k++ ) {
- if(strcmp(deps[j], gKernelModules[k].Name) == 0)
- break;
- }
- // `k` is assumed to be less than `giNumBuiltinModules`
-
- // If a dependency failed, skip and mark as failed
- if( baIsLoaded[k] == -1 ) {
- baIsLoaded[i] = -1;
- numToInit --;
- break;
- }
- // If a dependency is not intialised, skip
- if( !baIsLoaded[k] ) break;
- }
- // Check if we broke out
- if( deps[j] ) continue;
- }
-
- // All Dependencies OK? Initialise
- StartupPrint(gKernelModules[i].Name);
- Log("Initialising %p '%s' v%i.%i...",
- &gKernelModules[i],
- gKernelModules[i].Name,
- gKernelModules[i].Version>>8, gKernelModules[i].Version & 0xFF
- );
- if( gKernelModules[i].Init(NULL) == 0 ) {
- Log("Loading Failed, all modules that depend on this will also fail");
- baIsLoaded[i] = -1;
- }
- // Mark as loaded
- else
- baIsLoaded[i] = 1;
- numToInit --;
+ // Ok, check if it's loading
+ for( mod = gLoadingModules->Next; mod; mod = mod->Next )
+ {
+ if(strcmp(deps[j], mod->Name) == 0)
+ break;
+ }
+ if( mod ) {
+ Log_Warning("Module", "Circular dependency detected (%s and %s)",
+ mod->Name, Module->Name);
+ LEAVE_RET('i', -1);
+ }
+
+ // So, if it's not loaded, we better load it then
+ for( i = 0; i < giNumBuiltinModules; i ++ )
+ {
+ if( strcmp(deps[j], gapBuiltinModules[i]->Name) == 0 )
+ break;
+ }
+ if( i == giNumBuiltinModules ) {
+ Log_Warning("Module", "Dependency '%s' for module '%s' failed",
+ deps[j], Module->Name);
+ return -1;
+ }
+
+ // Dependency is not loaded, so load it
+ ret = Module_int_Initialise(
+ gapBuiltinModules[i],
+ gasBuiltinModuleArgs ? gasBuiltinModuleArgs[i] : NULL
+ );
+ if( ret )
+ {
+ // The only "ok" error is NOTNEEDED
+ if(ret != MODULE_ERR_NOTNEEDED)
+ LEAVE_RET('i', -1);
+ }
+ }
+
+ // All Dependencies OK? Initialise
+ StartupPrint(Module->Name);
+ Log_Log("Module", "Initialising %p '%s' v%i.%i...",
+ Module, Module->Name,
+ Module->Version >> 8, Module->Version & 0xFF
+ );
+
+ if( ArgString )
+ args = str_split( ArgString, ',' );
+ else
+ args = NULL;
+
+ ret = Module->Init(args);
+
+ if(args) free(args);
+
+ // Remove from loading list
+ gLoadingModules = gLoadingModules->Next;
+
+ if( ret != MODULE_ERR_OK ) {
+ switch(ret)
+ {
+ case MODULE_ERR_MISC:
+ Log_Warning("Module", "Unable to load, reason: Miscelanious");
+ break;
+ case MODULE_ERR_NOTNEEDED:
+ Log_Warning("Module", "Unable to load, reason: Module not needed");
+ break;
+ case MODULE_ERR_MALLOC:
+ Log_Warning("Module", "Unable to load, reason: Error in malloc/realloc/calloc, probably not good");
+ break;
+ default:
+ Log_Warning("Module", "Unable to load reason - Unknown code %i", ret);
+ break;