コード例 #1
0
ファイル: MainProcess.cpp プロジェクト: CommunicoPublic/iris
//
// Find file in specified list of directories
//
INT_32 MainProcess::FindFile(const STLW::vector<STLW::string>  & vDirectories,
                             const STLW::string                & sFilename,
                             STLW::string                      & sFullpath)
{
	STLW::vector<STLW::string>::const_iterator itvDirectories = vDirectories.begin();
	while (itvDirectories != vDirectories.end())
	{
		sFullpath.erase();
		const STLW::string & sDir(*itvDirectories);
		if (sDir.size())
		{
			sFullpath.assign(sDir);
			if (sDir[sDir.size() - 1] != '/') { sFullpath.append(1, '/'); }
		}

		sFullpath.append(sFilename);

		const INT_64 iFileHandle = File::Open(sFullpath.c_str(), OpenMode::READ);
		if (iFileHandle != -1)
		{
			File::Close(iFileHandle);
			return 0;
		}

		++itvDirectories;
	}
return -1;
}
コード例 #2
0
ファイル: FastCGIMain.cpp プロジェクト: CommunicoPublic/cas
//
// Get parameters
//
static INT_32 GetParams(const INT_32    iArgc,
                        CHAR_P        * aArgv,
                        STLW::string  & sGlobalConfigFile,
                        STLW::string  & sConfigFile,
                        STLW::string  & sModuleName,
                        bool          & bDebugInfo,
                        bool          & bPrintHelp,
                        bool          & bPrintVersion,
                        bool          & bPrintCompileInfo,
                        bool          & bDaemonize)
{
	bDebugInfo = bPrintHelp = bPrintVersion = bPrintCompileInfo = false;
	bDaemonize = true;
	sConfigFile.erase();

	UINT_32 iArgNum = 1;
	CCHAR_P szArgValue;
	for(;;)
	{
		INT_32 iOption = GetOpt(oOptions, iArgNum, iArgc, aArgv, szArgValue);
		if (iOption == -1) { break; }
		switch (iOption)
		{
			case 'g':
				sGlobalConfigFile = szArgValue;
				break;
			case 'f':
				sConfigFile = szArgValue;
				break;
			case 'm':
				sModuleName = szArgValue;
				break;
			case 'd':
				bDebugInfo = true;
				break;
			case 'h':
				bPrintHelp = true;
				break;
			case 'v':
				bPrintVersion = true;
				break;
			case 'V':
				bPrintCompileInfo = true;
				break;
			case 'F':
				bDaemonize = false;
				break;
			case '?':
				fprintf(stderr, "Unknown option `%s` or option with missed argument\n", aArgv[iArgNum]);
				return EX_CONFIG;
				break;
		}
	}

	if (sConfigFile.empty())
	{
		// Check environment
		CCHAR_P szConfigFile = getenv(ENV_CONFIG_FILE);
		if (szConfigFile != NULL && *szConfigFile != '\0') { sConfigFile = szConfigFile; }

		if (sConfigFile.empty()) { sConfigFile.assign(DEFAULT_CONFIG_FILE); }
	}

	if (sGlobalConfigFile.empty())
	{
		CCHAR_P szConfigFile = getenv("CAS_GLOBAL_CONFIG");
		if (szConfigFile != NULL)
		{
			fprintf(stderr, "Global config not given, using %s from ENVIRONMENT\n", szConfigFile);
			sGlobalConfigFile = szConfigFile;
		}
	}

return EX_OK;
}