///////////////////////////////////////////////////////////////////////////////
// LookupArgInfo
///////////////////////////////////////////////////////////////////////////////
bool cCmdLineParser::LookupArgInfo(int argId, TSTRING& arg, TSTRING& alias) const
{
    arg     = _T("");
    alias   = _T("");

    cHashTableIter<TSTRING, cArgInfo> iter(mArgTable);
    for(iter.SeekBegin(); ! iter.Done(); iter.Next())
    {
        if(iter.Val().mId == argId)
        {
            TSTRING str = iter.Key();
            if((str.length() > 0) && (str[0] == _T('-')))
            {
                // this is the alias!
                alias = (str.c_str() + 1);
            }
            else
            {
                // this is the arg...
                arg = str;
            }
        }
    }
    return ((! arg.empty()) || (! alias.empty()));
}
Example #2
0
	TSTRING Replace( const TSTRING& orignStr, const TSTRING& oldStr, const vector<TSTRING>&vc )
	{
		size_t pos = 0; 
		TSTRING tempStr = orignStr; 
		TSTRING::size_type newStrLen; 
		TSTRING::size_type oldStrLen = oldStr.length();
		int i=0;

		while(true) 
		{ 
			pos = tempStr.find(oldStr, pos); 
			if (pos == TSTRING::npos) break; 
			TSTRING s=vc.at(i);
			s = _T("\'")+s +_T("\'");
			newStrLen= s.length(); 

			tempStr.replace(pos, oldStrLen, s);         
			pos += newStrLen;
			i++;

		} 

		return tempStr; 

	}
///////////////////////////////////////////////////////////////////////////////
// MakeFileError
///////////////////////////////////////////////////////////////////////////////
TSTRING cErrorUtil::MakeFileError( const TSTRING& msg, const TSTRING& fileName )
{
	TSTRING ret;
    ret = TSS_GetString( cCore, core::STR_ERR2_FILENAME );
    ret.append( fileName );
    ret.append( 1, _T('\n') );

    if ( msg.length() > 0 )
    {
        ret.append(msg);
    }
	
	return ret;
}
Example #4
0
bool cFSParserUtil::MapStringToProperty( const TSTRING& str, int& propIndex ) const
{
    bool fMappedChar = true; // assume we'll recognize this char
                             // and set false if we don't

    // for short names
    if( str.length() == 1 )
    {
        switch( str[0] )
        {
	        case 'p': propIndex = cFSPropSet::PROP_MODE;    break;
	        case 'i': propIndex = cFSPropSet::PROP_INODE;   break;
	        case 'n': propIndex = cFSPropSet::PROP_NLINK;   break;
	        case 'u': propIndex = cFSPropSet::PROP_UID;     break;
	        case 'g': propIndex = cFSPropSet::PROP_GID;     break;
	        case 's': propIndex = cFSPropSet::PROP_SIZE;    break;
	        case 't': propIndex = cFSPropSet::PROP_FILETYPE;break;
	        case 'd': propIndex = cFSPropSet::PROP_DEV;		break;
            case 'r': propIndex = cFSPropSet::PROP_RDEV;	break;                
	        case 'b': propIndex = cFSPropSet::PROP_BLOCKS;  break;
            case 'a': propIndex = cFSPropSet::PROP_ATIME;   break;
	        case 'm': propIndex = cFSPropSet::PROP_MTIME;   break;
	        case 'c': propIndex = cFSPropSet::PROP_CTIME;   break;
	        case 'C': propIndex = cFSPropSet::PROP_CRC32;   break;
	        case 'M': propIndex = cFSPropSet::PROP_MD5;		break;
	        case 'S': propIndex = cFSPropSet::PROP_SHA;		break;
	        case 'H': propIndex = cFSPropSet::PROP_HAVAL;   break;
	        case 'l': propIndex = cFSPropSet::PROP_GROWING_FILE; break;
            default:  fMappedChar = false;                  break;
        }
    }
    else
    {
        if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MODE ) ) )
            propIndex = cFSPropSet::PROP_MODE;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_INODE ) ) )
            propIndex = cFSPropSet::PROP_INODE;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_UID ) ) )
            propIndex = cFSPropSet::PROP_UID;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_GID ) ) )
            propIndex = cFSPropSet::PROP_GID;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_SIZE ) ) )
            propIndex = cFSPropSet::PROP_SIZE;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_FILETYPE ) ) )
            propIndex = cFSPropSet::PROP_FILETYPE;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_DEV ) ) )
            propIndex = cFSPropSet::PROP_DEV;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_RDEV ) ) )
            propIndex = cFSPropSet::PROP_RDEV;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_BLOCKS ) ) )
            propIndex = cFSPropSet::PROP_BLOCKS;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_ATIME ) ) )
            propIndex = cFSPropSet::PROP_ATIME;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MTIME ) ) )
            propIndex = cFSPropSet::PROP_MTIME;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_CTIME ) ) )
            propIndex = cFSPropSet::PROP_CTIME;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_CRC32 ) ) )
            propIndex = cFSPropSet::PROP_CRC32;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_MD5 ) ) )
            propIndex = cFSPropSet::PROP_MD5;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_SHA ) ) )
            propIndex = cFSPropSet::PROP_SHA;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_HAVAL ) ) )
            propIndex = cFSPropSet::PROP_HAVAL;
        else if( 0 == str.compare( TSS_GetString( cFS, fs::STR_PARSER_PROP_GROWING_FILE ) ) )
            propIndex = cFSPropSet::PROP_GROWING_FILE;
        else
            fMappedChar = false;
    }

    return( fMappedChar );
}
Example #5
0
	HRESULT SLog::splitFullPath(TSTRING szFullPath)
	{
		HRESULT retValue = S_OK;

		TSTRING szSlash = TSTRING(_T("/\\"));
		TSTRING szDot = TSTRING(_T("."));
		int iLastSlash, iLastDot;
		bool bBadPath = false;

		// Quick sanity check...
		if (szFullPath.empty())
		{
			retValue = ERROR_BAD_ARGUMENTS;
			goto EXIT;
		}

		// First, make sure we actually have strings...
		if (NULL == m_szLogFilePath)
			m_szLogFilePath = new TSTRING();

		if (NULL == m_szLogFileName)
			m_szLogFileName = new TSTRING();

		if (NULL == m_szLogFileExt)
			m_szLogFileExt = new TSTRING();

		// Make sure they're clear (remember, we may not have created them)
		m_szLogFilePath->clear();
		m_szLogFileName->clear();
		m_szLogFileExt->clear();

		// To peel apart the string, we need to find the last slash character
		iLastSlash = szFullPath.find_last_of(szSlash.c_str(), TNPOS);

		// Now, this could go either way; either we have no slash, in which case
		// this DOESN'T have a path, or we do and there's a path...
		if (iLastSlash == TNPOS)
		{
			// We didn't get a path...
			bBadPath = true;
		}
		else
		{
			// Get the path, if there is one...
			m_szLogFilePath->append(szFullPath.substr(0, (iLastSlash + 1)));

			// Does that path actually exist?
			WIN32_FILE_ATTRIBUTE_DATA dirData;
			if (!GetFileAttributesEx(m_szLogFilePath->c_str(),
				GetFileExInfoStandard,
				&dirData))
			{
				// We hit an error!
				DWORD dw;
				dw = GetLastError();
				retValue = HRESULT_FROM_WIN32(dw);
				bBadPath = true;
			}
			else if ((dirData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)
			{
				// The path isn't to a directory!
				retValue = ERROR_BAD_PATHNAME;
				bBadPath = true;
			}
		}

		if (bBadPath)
		{
			// We either got no path or a bad path, so let's
			// set it to the Current Directory...
			// First, get the size of buffer we're going to need
			int iDirSize = GetCurrentDirectory(0, NULL);

			// Next, declare the buffer and use it to get the current directory
			m_szLogFilePath->clear();
			TCHAR* szDirBuffer = new TCHAR[iDirSize];
			GetCurrentDirectory(iDirSize, szDirBuffer);
			m_szLogFilePath->append(szDirBuffer);
			m_szLogFilePath->append(_T("\\"));		// Have to add the trailing slash
		}

		// To peel apart the extension, we need to find the last dot character
		iLastDot = szFullPath.find_last_of(szDot.c_str(), TNPOS);

		// We may or may not have a dot; no dot, no extension
		if (iLastDot == TNPOS)
		{
			iLastDot = szFullPath.length();
			m_szLogFileExt->append(DEFAULT_EXT);
		}
		else
		{
			m_szLogFileExt->append(szFullPath.substr(iLastDot));
		}

		// With all that out of the way, we can get our file name
		m_szLogFileName->append(szFullPath.substr((iLastSlash + 1), ( iLastDot - iLastSlash - 1 )));

	EXIT:
		return retValue;
	}