static STLW::string GetBaseDir(const STLW::string & szTemplateName, STLW::string & sNormalizedFileName)
{
	STLW::string sResult;
	CHAR_8      szPath[MAX_PATH];
	CHAR_P      szFile = NULL;
	DWORD       dwLen  = ::GetFullPathNameA(szTemplateName.c_str(), MAX_PATH, szPath, &szFile);

	if (szFile == NULL) { return ""; }

	sNormalizedFileName.assign(szPath, dwLen);
	sResult.assign(szPath, szFile);

return sResult;
}
示例#2
0
//
// 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;
}
static STLW::string GetBaseDir(const STLW::string & szTemplateName, STLW::string & sNormalizedFileName)
{
	if (szTemplateName.length() == 0) { return ""; }

	STLW::vector<STLW::string> vCurrentDir;

	CCHAR_P sBegin = szTemplateName.c_str();
	CCHAR_P szEnd  = szTemplateName.c_str() + szTemplateName.length();

	CCHAR_P sIter = sBegin;
	while (sIter != szEnd)
	{
		if (*sIter == '/')
		{
			if (sIter != sBegin)
			{
				STLW::string sTMP(sBegin, sIter);

				if      (sTMP == "/." || sTMP == "/") { ;; }
				else if (sTMP == "/..")
				{
					STLW::vector<STLW::string>::iterator itEnd = vCurrentDir.end();
					if (vCurrentDir.begin() == itEnd) { return ""; }
					vCurrentDir.erase(--itEnd);
				}
				else
				{
					vCurrentDir.push_back(sTMP);
				}
			}
			sBegin = sIter;
		}
		++sIter;
	}

	STLW::string sTMP(sBegin, sIter);
	if (sTMP == "/") { return ""; }

	STLW::string sResult;
	for (UINT_32 iI = 0; iI < vCurrentDir.size(); ++iI) { sResult.append(vCurrentDir[iI]); }

	sNormalizedFileName.assign(sResult);
	sNormalizedFileName.append(sTMP);

	sResult.append("/");

return sResult;
}
示例#4
0
//
// 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;
}