Exemplo n.º 1
0
// case insensitive compare
// return 0 if match, return <0 or >0 if first case insentive mismatch character
//      has lower value in s1 or in s2, respectively
int CIstrcmp(const char *s1, const char *s2)
{
    unsigned char *us1 = (unsigned char *)s1;
    unsigned char *us2 = (unsigned char *)s2;

    while(ConvertToLower(*us1) == ConvertToLower(*us2++))
    {   // they are equal, so still matching

        // if matching at the end, then found a match
        if(*us1 == '\0') return (0);

        // otherwise on to next character
        us1++;
    }

    // found mismatch
    us2--;
    return (int)(ConvertToLower(*us1) - ConvertToLower(*us2));
}
Exemplo n.º 2
0
double CSVReader::GetValueWithDefault(const std::string& valueName, double def)
{
	double ans;
	semTake(m_lock,WAIT_FOREVER);
	if (KeyExists(valueName)) {
		ans = (*m_map.find(ConvertToLower(valueName))).second;
	} else {
		printf("USING DEFAULT OF %f FOR %s\n", def, valueName.c_str());
		ans = def;
	}
	semGive(m_lock);
	return ans;
}
Exemplo n.º 3
0
bool CPasswordLookupHash::LookupPassword(BYTE* szPasswordIn, LONG nLengthIn, BYTE* szPasswordOut)
{
    if(!IsTablesBuilt() || !szPasswordIn || !szPasswordOut)
        return false;

    if(nLengthIn > MAX_PASSWORD_SIZE)
        nLengthIn = MAX_PASSWORD_SIZE;

    if(nLengthIn < 1)
        return false;

    ConvertToLower(szPasswordIn, nLengthIn);

    LONG nChunkLength = MAX_PASSWORD_SIZE/nLengthIn;

    LONG nChunks = MAX_PASSWORD_SIZE/nChunkLength;

    LONG nOddLastBlock=0;

    if(nChunks*nChunkLength != MAX_PASSWORD_SIZE)
    {
        nOddLastBlock = MAX_PASSWORD_SIZE - ((nChunks*nChunkLength) % MAX_PASSWORD_SIZE);

        if((nOddLastBlock+(nChunks*nChunkLength)) != MAX_PASSWORD_SIZE)
            return false; //Overflow? This should never happen. Testing logic ...
    }

    LPBYTE pCurrentPos=szPasswordOut;
    int nPos=0;
    for(int i=0; i<nChunks; i++)
    {
        GetPasswordChunk(szPasswordIn[nPos++], nChunkLength, pCurrentPos);

        if(nPos >= nLengthIn)
            nPos = 0;

        pCurrentPos = pCurrentPos + nChunkLength;
    }

    if(nOddLastBlock)
    {
        GetPasswordChunk(szPasswordIn[nPos++], nOddLastBlock, pCurrentPos);
    }

    return true;
}
Exemplo n.º 4
0
void CSVReader::FillMap()
{
	std::string key;
	std::string valueString;
	
	std::ifstream infile (m_filePath.c_str());
	
	if (infile.is_open()) {	
		while (!infile.eof()) {
			std::string inKey;
			//Get the key name
			getline (infile, inKey, ',');
			key = ConvertToLower(inKey);
			
			// get the value string
			getline(infile, valueString);
			
			// Handle weird new line situations
			if(infile.eof())
				break;
			
			// Convert value string to a number
			double value = 0.0;
			if (from_string<double>(value, valueString, std::dec)) {
				m_map[key] = value;
				//TEMPORARY DISABLE
//				printf("RobotConfig:: Reading in Data Key %s Number %.2f %f\n", key.c_str(), value, (*m_map.find(key)).second);
			} else {
				//ensure we're always reading the right values
				assert(0);
				fprintf(stderr, "ERROR: Reading Key %s of Value %s failed\n", key.c_str(), valueString.c_str());
			}
		}
		infile.close();
	} else {
		fprintf(stderr, "ERROR: Unable to open config file %s \n", m_filePath.c_str()); 	
	}
}
Exemplo n.º 5
0
bool CSVReader::KeyExists(const std::string& key) const
{
	return (m_map.count(ConvertToLower(key)) > 0);
}