- // Commands
- // - Mount
- if(strncmp("mount ", fData+i, 6) == 0) {
- i += 6;
- i += System_Int_GetString(fData+i, &sArg1);
- if(!sArg1) goto read2eol;
- i += System_Int_GetString(fData+i, &sArg2);
- if(!sArg2) goto read2eol;
- i += System_Int_GetString(fData+i, &sArg3);
- if(!sArg3) goto read2eol;
- //Log("[CFG ] Mount '%s' to '%s' (%s)\n", sArg1, sArg2, sArg3);
- VFS_Mount(sArg1, sArg2, sArg3, "");
- }
- // - Load Module
- else if(strncmp("module ", fData+i, 6) == 0) {
- i += 7;
- i += System_Int_GetString(fData+i, &sArg1);
- if(!sArg1) goto read2eol;
- //Log("[CFG ] Load Module '%s'\n", sArg1);
- Module_LoadFile(sArg1, ""); //!\todo Use the rest of the line as the argument string
- }
- // - Load Module
- else if(strncmp("edimod ", fData+i, 6) == 0) {
- i += 7;
- i += System_Int_GetString(fData+i, &sArg1);
- if(!sArg1) goto read2eol;
- Log("[CFG ] Load EDI Module '%s'\n", sArg1);
- Module_LoadFile(sArg1, "");
+ // Find the command name
+ for( j = 0; j < NUM_CONFIG_COMMANDS; j++ )
+ {
+ const char *args[N_MAX_ARGS];
+
+ if(strcmp(line->Parts[0], caConfigCommands[j].Name) != 0) continue;
+
+ Log_Debug("Config", "Command '%s', %i args passed", line->Parts[0], line->nParts-1);
+
+ // Check against minimum argument count
+ if( line->nParts - 1 < caConfigCommands[j].MinArgs ) {
+ Log_Warning("Config",
+ "Configuration command '%s' requires at least %i arguments, %i given",
+ caConfigCommands[j].Name, caConfigCommands[j].MinArgs, line->nParts-1
+ );
+ break;
+ }
+
+ // Check for extra arguments
+ if( line->nParts - 1 > caConfigCommands[j].MaxArgs ) {
+ Log_Warning("Config",
+ "Configuration command '%s' takes at most %i arguments, %i given",
+ caConfigCommands[j].Name, caConfigCommands[j].MaxArgs, line->nParts-1
+ );
+ break;
+ }
+
+ // Fill in defaults
+ for( k = caConfigCommands[j].MaxArgs-1; k > line->nParts - 1; k-- ) {
+ args[k] = caConfigCommands[j].OptDefaults[k];
+ }
+
+ // Convert arguments to integers
+ for( k = line->nParts-1; k--; )
+ {
+ if( k < 32 && (caConfigCommands[j].IntArgs & (1 << k)) ) {
+ args[k] = (const char *)(Uint)atoi(line->Parts[k+1]);
+ }
+ else {
+ args[k] = (char *)line->Parts[k+1];
+ }
+ LOG("args[%i] = %p", k, args[k]);
+ }
+ switch( (enum eConfigCommands) caConfigCommands[j].Index )
+ {
+ case CC_LOADMODULE:
+ result = Module_LoadFile( args[0], args[1] );
+ break;
+ case CC_SPAWN:
+ result = Proc_Spawn( args[0] );
+ break;
+ case CC_MOUNT:
+ result = VFS_Mount( args[0], args[1], args[2], args[3] );
+ break;
+ case CC_SYMLINK:
+ result = VFS_Symlink( args[0], args[1] );
+ break;
+ case CC_OPEN:
+ result = VFS_Open( args[0], (Uint)args[1] );
+ break;
+ case CC_CLOSE:
+ VFS_Close( (Uint)args[0] );
+ result = 0;
+ break;
+ case CC_MKDIR:
+ result = VFS_MkDir( args[0] );
+ break;
+ case CC_IOCTL:
+ result = VFS_IOCtl( (Uint)args[0], (Uint)args[1], (void *)args[2] );
+ break;
+ }
+ LOG("Config", "result = %i", result);
+ break;