static SampleSourceType _sampleSourceGuess(const CharString sampleSourceName) { File sourceFile = NULL; CharString sourceFileExtension = NULL; SampleSourceType result = SAMPLE_SOURCE_TYPE_PCM; if (sampleSourceName == NULL || charStringIsEmpty(sampleSourceName)) { result = SAMPLE_SOURCE_TYPE_SILENCE; } else { // Look for stdin/stdout if (strlen(sampleSourceName->data) == 1 && sampleSourceName->data[0] == '-') { result = SAMPLE_SOURCE_TYPE_PCM; } else { sourceFile = newFileWithPath(sampleSourceName); sourceFileExtension = fileGetExtension(sourceFile); freeFile(sourceFile); // If there is no file extension, then automatically assume raw PCM data. Deal with it! if (charStringIsEmpty(sourceFileExtension)) { result = SAMPLE_SOURCE_TYPE_PCM; } // Possible file extensions for raw PCM data else if (charStringIsEqualToCString(sourceFileExtension, "pcm", true) || charStringIsEqualToCString(sourceFileExtension, "raw", true) || charStringIsEqualToCString(sourceFileExtension, "dat", true)) { result = SAMPLE_SOURCE_TYPE_PCM; } #if USE_AUDIOFILE else if (charStringIsEqualToCString(sourceFileExtension, "aif", true) || charStringIsEqualToCString(sourceFileExtension, "aiff", true)) { result = SAMPLE_SOURCE_TYPE_AIFF; } #endif #if USE_FLAC else if (charStringIsEqualToCString(sourceFileExtension, "flac", true)) { result = SAMPLE_SOURCE_TYPE_FLAC; } #endif else if (charStringIsEqualToCString(sourceFileExtension, "wav", true) || charStringIsEqualToCString(sourceFileExtension, "wave", true)) { result = SAMPLE_SOURCE_TYPE_WAVE; } else { logCritical("Sample source '%s' does not match any supported type", sampleSourceName->data); result = SAMPLE_SOURCE_TYPE_INVALID; } } } freeCharString(sourceFileExtension); return result; }
bool CArchonProcess::Boot (const SProcessDesc &Config) // Boot // // Boots the process. We take ownership of all engines. { try { int i; // Get our current process location CString sExecutableFilespec = fileGetExecutableFilespec(); CString sExecutablePath = fileGetPath(sExecutableFilespec); // LATER: Hard-coded for now m_sArcology = STR_DEFAULT_ARCOLOGY; // Set some options m_bArcologyPrime = ((Config.dwFlags & PROCESS_FLAG_ARCOLOGY_PRIME) != 0); m_bCentralModule = ((Config.dwFlags & PROCESS_FLAG_CENTRAL_MODULE) != 0); m_bConsoleMode = ((Config.dwFlags & PROCESS_FLAG_CONSOLE_MODE) != 0); m_bDebugger = ((Config.dwFlags & PROCESS_FLAG_DEBUG) != 0); m_sMachineName = Config.sMachineName; // Set the name if (m_bCentralModule) m_sName = STR_CENTRAL_MODULE; else { // Get a module name by taking just the filename (without extension) fileGetExtension(fileGetFilename(sExecutableFilespec), &m_sName); } m_iState = stateNone; // Initialize the black box so that we can record boot errors. // (But only if we're the central module on arcology prime). if (m_bCentralModule && m_bArcologyPrime) { m_BlackBox.Boot(sExecutablePath); if (Config.dwFlags & PROCESS_FLAG_CONSOLE_OUTPUT) m_BlackBox.SetConsoleOutput(true); LogBlackBox(STR_ARCHON_BOOT); } else if (m_bConsoleMode) { m_BlackBox.SetConsoleOutput(true); } // Validate options if (m_sMachineName.IsEmpty() && !m_bConsoleMode) { LogBlackBox(ERR_NO_MACHINE_NAME); m_iState = stateBootError; return false; } // Get version information if (!fileGetVersionInfo(NULL_STR, &m_Version)) { LogBlackBox(ERR_UNABLE_TO_GET_VERSION); m_iState = stateBootError; return false; } // Log version information if (m_bCentralModule || m_bConsoleMode) { LogBlackBox(strPattern("%s %s", m_Version.sProductName, m_Version.sProductVersion)); LogBlackBox(m_Version.sCopyright); } // Boot Foundation, including Winsock CString sError; if (!CFoundation::Boot(0, &sError)) { LogBlackBox(sError); m_iState = stateBootError; return false; } // Init some stuff m_dwLastGarbageCollect = sysGetTickCount(); m_QuitEvent.Create(); m_RunEvent.Create(); m_PauseEvent.Create(); m_QuitSignalEvent.Create(); // If we're the Central Module, then claim a mutex so that no one // else tries it. if (m_bCentralModule) { if (m_bArcologyPrime) m_CentralModuleSem.Create(STR_ARCOLOGY_PRIME_SEMAPHORE, 1); else m_CentralModuleSem.Create(STR_CENTRAL_MODULE_SEMAPHORE, 1); if (!m_CentralModuleSem.TryIncrement()) { LogBlackBox(ERR_NOT_CENTRAL_MODULE); m_iState = stateBootError; return false; } } // Boot some stuff m_MnemosynthDb.Boot(this); m_Transporter.Boot(this); // Boot some threads m_ImportThread.Boot(this, m_sName, m_RunEvent, m_PauseEvent, m_QuitEvent); // Remember the Exarch engine, if we have it. m_pExarch = Config.pExarch; // Add the list of engines DWORD dwEngineID = 0; // Add the mnemosynth engine (if not in console mode) if (!m_bConsoleMode) { SEngine *pEngine = m_Engines.Insert(); pEngine->pEngine = new CMnemosynthEngine(&m_MnemosynthDb); pEngine->pEngine->Boot(this, dwEngineID++); } // Add user provided engines for (i = 0; i < Config.Engines.GetCount(); i++) { SEngine *pEngine = m_Engines.Insert(); pEngine->pEngine = Config.Engines[i].pEngine; // Allow the engine to add its ports pEngine->pEngine->Boot(this, dwEngineID++); } // After this point we cannot create or destroy any engines. // // Get all engine's command port (in case we need it). // It is OK if an engine does not have a command port; that just means // that it doesn't want any messages from us. for (i = 0; i < m_Engines.GetCount(); i++) m_Engines[i].pCommand = Bind(GenerateAddress(strPattern("%s.command", m_Engines[i].pEngine->GetName()))); // Publish this module's virtual ports to Mnemosynth m_Transporter.PublishToMnemosynth(); // Done return true; } catch (...) { LogBlackBox(ERR_CRASH_WHILE_BOOTING); m_iState = stateBootError; return false; } }
void ParseCommandLine (int argc, char *argv[], SOptions *retOptions) { int i; // Initialize *retOptions = SOptions(); // Parse for (i = 1; i < argc; i++) { char *pPos = argv[i]; if (*pPos == '/') { pPos++; switch (*pPos) { case '?': retOptions->bHelp = true; break; case '1': retOptions->bV1Auth = true; break; case '!': retOptions->bV1Auth = true; retOptions->bV1AuthOld = true; break; case 'h': case 'H': pPos++; if (*pPos != ':') break; pPos++; retOptions->sHexeDocument = CString(pPos); retOptions->bNoConnect = true; break; case 'l': case 'L': retOptions->bTopLevel = true; retOptions->bNoConnect = true; break; case 'n': case 'N': retOptions->bNoLogo = true; break; case 'r': case 'R': { pPos++; if (*pPos != ':') break; pPos++; retOptions->sScriptFile = CString(pPos); retOptions->bNoConnect = true; break; } case 's': case 'S': { pPos++; if (*pPos != ':') break; pPos++; retOptions->sServer = CString(pPos); break; } case 't': case 'T': retOptions->bTiming = true; break; case 'z': case 'Z': retOptions->bNoConnect = true; break; } } else { if (retOptions->sSingleCommand.IsEmpty()) retOptions->sSingleCommand = CString(pPos); else retOptions->sSingleCommand = strPattern("%s %s", retOptions->sSingleCommand, CString(pPos)); } } // If the only argument is a PEM file, then remember that if (argc == 2 && strEqualsNoCase(fileGetExtension(retOptions->sSingleCommand), EXTENSION_PEM)) { retOptions->bPEMFile = true; retOptions->bNoConnect = true; } // Set some defaults if (retOptions->sServer.IsEmpty()) retOptions->sServer = STR_LOCALHOST; }