Example #1
0
static bool
IsFortranNumber (LPCTSTR pszChars, int nLength)
{
  if (nLength > 2 && pszChars[0] == '0' && pszChars[1] == 'x')
    {
      for (int I = 2; I < nLength; I++)
        {
          if (_istdigit (pszChars[I]) || (pszChars[I] >= 'A' && pszChars[I] <= 'F') ||
                (pszChars[I] >= 'a' && pszChars[I] <= 'f'))
            continue;
          return false;
        }
      return true;
    }
  if (!_istdigit (pszChars[0]))
    return false;
  for (int I = 1; I < nLength; I++)
    {
      if (!_istdigit (pszChars[I]) && pszChars[I] != '+' &&
            pszChars[I] != '-' && pszChars[I] != '.' && pszChars[I] != 'e' &&
            pszChars[I] != 'E')
        return false;
    }
  return true;
}
Example #2
0
static int compare_right(const TCHAR *a, const TCHAR *b)
{
	int bias = 0;

	/* The longest run of digits wins.  That aside, the greatest
	value wins, but we can't know that it will until we've scanned
	both numbers to know that they have the same magnitude, so we
	remember it in BIAS. */
	for (;; a++, b++) {
		if (!_istdigit(*a))
			return _istdigit(*b) ? -1 : bias;
		else if (!_istdigit(*b))
			return +1;
		else if (*a < *b) {
			if (!bias)
				bias = -1;
		} else if (*a > *b) {
			if (!bias)
				bias = +1;
		} else if (!*a && !*b)
			return bias;
	}

	return 0;
}
Example #3
0
static BOOL
IsSiodNumber (LPCTSTR pszChars, int nLength)
{
  if (nLength > 2 && pszChars[0] == '0' && pszChars[1] == 'x')
    {
      for (int I = 2; I < nLength; I++)
        {
          if (_istdigit (pszChars[I]) || (pszChars[I] >= 'A' && pszChars[I] <= 'F') ||
                (pszChars[I] >= 'a' && pszChars[I] <= 'f'))
            continue;
          return FALSE;
        }
      return TRUE;
    }
  if (!_istdigit (pszChars[0]))
    return FALSE;
  for (int I = 1; I < nLength; I++)
    {
      if (!_istdigit (pszChars[I]) && pszChars[I] != '+' &&
            pszChars[I] != '-' && pszChars[I] != '.' && pszChars[I] != 'e' &&
            pszChars[I] != 'E')
        return FALSE;
    }
  return TRUE;
}
Example #4
0
static int
wmic_ether_aton(const TCHAR *orig, A_UINT8 *eth)
{
   const TCHAR *bufp;
   int i;

   i = 0;
   for (bufp = orig; *bufp != '\0'; ++bufp) {
      unsigned int val;
      TCHAR c = *bufp++;

      if (_istdigit(c)) val = c - __T('0');
      else if (c >= __T('a') && c <= __T('f')) val = c - __T('a') + 10;
      else if (c >= __T('A') && c <= __T('F')) val = c - __T('A') + 10;
      else break;

      val <<= 4;
      c = *bufp++;
      if (_istdigit(c)) val |= c - __T('0');
      else if (c >= __T('a') && c <= __T('f')) val |= c - __T('a') + 10;
      else if (c >= __T('A') && c <= __T('F')) val |= c - __T('A') + 10;
      else break;

      eth[i] = (unsigned char) (val & 0377);
      if (++i == MAC_ADDR_LEN) {
         return 0;
      }
      if (*bufp != ':')
         break;
   }
   return(-1);
}
int KString::QSortFunctionNumeric(const void* p1, const void* p2)
{
	TCHAR	Buf[1024];
	size_t	szBufLen;
	int		v1, v2;
	size_t	i;

	const KString& String1 = *(KString*)p1;
	const KString& String2 = *(KString*)p2;

	// Fetching first value
	szBufLen = 0;
	for(i=0 ; i<String1.GetLength() ; i++)
		if(_istdigit(String1[i]))
			Buf[szBufLen++] = String1[i];

	Buf[szBufLen] = 0, v1 = _ttoi(Buf);

	// Fetching second value
	szBufLen = 0;
	for(i=0 ; i<String2.GetLength() ; i++)
		if(_istdigit(String2[i]))
			Buf[szBufLen++] = String2[i];

	Buf[szBufLen] = 0, v2 = _ttoi(Buf);

	// Comparing
	if(v1 < v2)
		return -1;

	if(v1 > v2)
		return 1;

	return QSortFunctionNoCase(p1, p2);
}
Example #6
0
void CNewWindowDlg::OnEditchangePort() 
{
	CString port;
	m_PortCombo.GetWindowText( port );

	port.TrimRight();
	port.TrimLeft();

	if( port.GetAt(0) == _T('\"'))
	{
		port.TrimRight(_T('\"'));
		port.TrimLeft(_T('\"'));
	}

	BOOL b = port.GetLength() > 0;
	m_bSamePort = b && port == GET_P4REGPTR()->GetP4Port();
	if (!m_bSamePort)
	{
		if (b)
		{
			b = _istdigit(port.GetAt(port.GetLength()-1)) && port.Find(_T(' ')) == -1;
			if (b && !_istdigit(port.GetAt(0)))
				b = port.Find(_T(':')) > 0;
		}
	}
	GetDlgItem(IDC_BROWSE_CLIENTS)->EnableWindow(b);
	GetDlgItem(IDC_BROWSE_USERS)->EnableWindow(b);
}
Example #7
0
int strnatcmp(const TCHAR *psz1, const TCHAR *psz2)
{
	int ai, bi;
	TCHAR ca, cb;
	int fractional, result;

	__try{
		TCHAR a [MAX_PATH];
		TCHAR b [MAX_PATH];
		memset(a, 0, MAX_PATH);
		memset(b, 0, MAX_PATH);
		_tcscpy_s(a, MAX_PATH, psz1);
		_tcscpy_s(b, MAX_PATH, psz2);
		_tcslwr_s(a, MAX_PATH);
		_tcslwr_s(b, MAX_PATH);
		ai = bi = 0;
		while (1) {
			ca = a[ai];
			cb = b[bi];

			/* skip over leading spaces or zeros */
			while (_is_meaningless_char(ca))
				ca = a[++ai];

			while (_is_meaningless_char(cb))
				cb = b[++bi];

			/* process run of digits */
			if (_istdigit(ca) && _istdigit(cb)) {
				fractional = (ca == '0' || cb == '0');

				if (fractional) {
					if ((result = compare_left(a + ai, b + bi)) != 0)
						return result;
				} else {
					if ((result = compare_right(a + ai, b + bi)) != 0)
						return result;
				}
			}

			if (!ca && !cb) {
				/* The strings compare the same.  Perhaps the caller
				will want to call strcmp to break the tie. */
				return 0;
			}

			if (ca < cb)
				return -1;
			else if (ca > cb)
				return +1;

			++ai;
			++bi;
		}
	}__except(EXCEPTION_EXECUTE_HANDLER){} 

	return 0;
}
Example #8
0
BOOL NMEAParser::NMEAChecksum(const TCHAR *String)
{
  if (!CheckSum) return TRUE;
  unsigned char CalcCheckSum = 0;
  unsigned char ReadCheckSum;
  int End;
  int i;
  TCHAR c1,c2;
  unsigned char v1 = 0,v2 = 0;
  TCHAR *pEnd;

  pEnd = _tcschr(String,_T('*'));
  if(pEnd == NULL)
    return FALSE;

  // Fix problem of EW micrologger missing a digit in checksum
  // now we have *XY 
  // line is terminating with 0a (\n) so count is 4 not 3!
  if(_tcslen(pEnd)<4) {
	// no checksum, only a * ?
	if (_tcslen(pEnd)==1) {
		return FALSE;
	}
	// try to recover the missing digit
	c1 = _T('0');
	c2 = pEnd[1];
  } else {
	c1 = pEnd[1], c2 = pEnd[2];
  }

  //  iswdigit('0'); // what's this for?

  if(_istdigit(c1))
    v1 = (unsigned char)(c1 - '0');
  if(_istdigit(c2))
    v2 = (unsigned char)(c2 - '0');
  if(_istalpha(c1))
    v1 = (unsigned char)(c1 - 'A' + 10);
  if(_istalpha(c2))
    v2 = (unsigned char)(c2 - 'A' + 10);

  ReadCheckSum = (unsigned char)((v1<<4) + v2);          

  End =(int)( pEnd - String);

  for(i=1;i<End;i++)
    {
      CalcCheckSum = (unsigned char)(CalcCheckSum ^ String[i]);
    }

  if(CalcCheckSum == ReadCheckSum)
    return TRUE;
  else
    return FALSE;
}
Example #9
0
BOOL CCmd_Describe::HandledCmdSpecificError(LPCTSTR errBuf, LPCTSTR errMsg)
{
	BOOL handledError=TRUE;
#ifndef UNICODE
	if (!StrNCmp(errBuf, NOTRANS, sizeof(NOTRANS)-1))
	{
		CString utf8;
		TCHAR *p = (TCHAR *)errBuf + sizeof(NOTRANS)-1;
		while (*p && *p != '\'')
		{
			TCHAR c1 = *p++;
			TCHAR c2 = *p++;
			if (_istdigit(c1))
				c1 &= 0x0F;
			else
				c1 = (c1 & 0x0F) + 9;
			if (_istdigit(c2))
				c2 &= 0x0F;
			else
				c2 = (c2 & 0x0F) + 9;
			TCHAR c3 = (c1 << 4) + c2;
			utf8.Insert(0x7FFFFFFF, c3);
		}

		// allocate widechar buffer and convert into it
		int lenw = MultiByteToWideChar(CP_UTF8, 0, utf8, -1, 0, 0);
		LPWSTR utf16 = (LPWSTR)::VirtualAlloc(NULL, lenw*sizeof(WCHAR), MEM_COMMIT, PAGE_READWRITE);
		MultiByteToWideChar(CP_UTF8, 0, utf8, -1, utf16, lenw);

		// allocate char buffer and convert back into it, using '?' for
		// unmappable characters
		int len = WideCharToMultiByte(CP_ACP, 0, utf16, -1, 0, 0, NULL, NULL);
		LPSTR buf = (LPSTR)::VirtualAlloc(NULL, len*sizeof(TCHAR), MEM_COMMIT, PAGE_READWRITE);
		WideCharToMultiByte(CP_ACP, 0, utf16, -1, buf, len, NULL, NULL);

		// append to description
		m_Description += buf;
		m_Description += g_CRLF;

		::VirtualFree(buf, 0, MEM_RELEASE);
		::VirtualFree(utf16, 0, MEM_RELEASE);
		handledError = FALSE;
	}
	else
#endif
	{
		m_FatalError = TRUE;
		TheApp()->StatusAdd( errMsg, SV_WARNING, true );	
	}
	return handledError;
}
Example #10
0
TxSkin::color TxSkin::parseColor( LPWSTR str )
{
	DWORD r = 0;
	DWORD g = 0;
	DWORD b = 0;
	DWORD a = 255;
	TCHAR strVal[50];
	LPTSTR curPos = str;
	while(curPos[0] && !_istdigit(curPos[0])) curPos++;
	int i=0;
	while(curPos[0] && _istdigit(curPos[0])) 
	{
		strVal[i] = curPos[0];
		i++;
		curPos++;
	}
	strVal[i] = 0;
	r = _ttoi(strVal);

	while(curPos[0] && !_istdigit(curPos[0])) curPos++;

	i=0;
	while(curPos[0] && _istdigit(curPos[0])) 
	{
		strVal[i] = curPos[0];
		i++;
		curPos++;
	}
	strVal[i] = 0;
	g = _ttoi(strVal);

	while(curPos[0] && !_istdigit(curPos[0])) curPos++;

	i=0;
	while(curPos[0] && _istdigit(curPos[0])) 
	{
		strVal[i] = curPos[0];
		i++;
		curPos++;
	}
	strVal[i] = 0;
	b = _ttoi(strVal);

	while(curPos[0] && !_istdigit(curPos[0])) curPos++;

	i=0;
	while(curPos[0] && _istdigit(curPos[0])) 
	{
		strVal[i] = curPos[0];
		i++;
		curPos++;
	}
	strVal[i] = 0;
	if(strVal[0])
	{
		a = _ttoi(strVal);
	}

	return TxSkin::color((BYTE) r, (BYTE) g, (BYTE) b, (BYTE) a);
}
Example #11
0
File: date.c Project: GYGit/reactos
static BOOL
ReadNumber (LPTSTR *s, LPWORD lpwValue)
{
    if (_istdigit (**s))
    {
        while (_istdigit (**s))
        {
            *lpwValue = *lpwValue * 10 + **s - _T('0');
            (*s)++;
        }
        return TRUE;
    }
    return FALSE;
}
Example #12
0
BOOL COXString::IsNumber()
{
	LPCTSTR pc = *this;
	BOOL bDigit = FALSE;

	// Skip white space characters
	while (_istspace(*pc))
		pc++;
	// Skip sign
	if ((*pc == _T('-')) || (*pc == _T('+')))
		pc++;
	// Skip digits
	while (_istdigit(*pc))
	{
		pc++;
		bDigit = TRUE;
	}
	// Skip decimal sign
	if (*pc == cDecimalCharacter)
		pc++;
	if (!bDigit && !_istdigit(*pc))
		return FALSE;
	// Skip digits
	while (_istdigit(*pc))
		pc++;
	// Skip exponent sign and rest
	if ((*pc == _T('E')) || (*pc == _T('e')) || (*pc == _T('D')) || (*pc == _T('d')))
	{
		pc++;
		// Skip sign
		if ((*pc == _T('-')) || (*pc == _T('+')))
			pc++;
		// Skip digits
		if (!_istdigit(*pc))
			// Exponent sign is not followed by digits
			return FALSE;
		while (_istdigit(*pc))
			pc++;
	}
	// Skip white space characters
	while (_istspace(*pc))
		pc++;

	// Pointer should not be behind the end of the string
	ASSERT(pc <= (((LPCTSTR)*this) + GetLength()));

	// Must be at the end of the string by now, otherwise the number is not valid
	return (*pc == _T('\0'));
}
Example #13
0
static bool
IsVerilogNumber (LPCTSTR pszChars, int nLength)
{
  if (!_istdigit (pszChars[0]))
    return false;
  for (int I = 1; I < nLength; I++)
    {
      if (_istdigit (pszChars[I]) || pszChars[I] == '.' || pszChars[I] == '\'' || 
            pszChars[I] == 'h' || (pszChars[I] >= 'A' && pszChars[I] <= 'F') ||
            (pszChars[I] >= 'a' && pszChars[I] <= 'f') || pszChars[I] == '_' ||
			pszChars[I] == 'x' || pszChars[I] == 'Z')
        continue;
      return false;
    }
  return true;
}
Example #14
0
CString CNumericEdit::GetNumericText(const CString& strText, bool bUseMathSymbols) const
{
	CString strNewText;
	bool bIsNegative = false;
	bool bHasDecimalPoint = false;

	for (int iPos = 0, nLen = strText.GetLength(); iPos < nLen; iPos++)
	{
		TCHAR c = strText[iPos];
		if (_istdigit(c))
		{
			strNewText += c;
		}
		else if (c == m_cNegativeSign)
		{
			bIsNegative = true;
		}
		else if (c == m_cDecimalPoint && !bHasDecimalPoint)
		{
			bHasDecimalPoint = true;
			strNewText += (bUseMathSymbols ? _T('.') : m_cDecimalPoint);
		}
	}

	if (bIsNegative)
	{
		;//strNewText.Insert(0, bUseMathSymbols ? '-' : m_cNegativeSign);
	}

	return strNewText;
}
Example #15
0
static int hex2bin( int c )
{
     /* Convert the hex digit represented by 'c' to an int. 'c'
      * must be one of: 0123456789abcdefABCDEF
      */
     return (_istdigit(c) ? (c)-_T('0') : ((_toupper(c))-_T('A'))+10)  & 0xf;
}
Example #16
0
//
// Skip a character or a picture group
//
void
TPXPictureValidator::ToGroupEnd(uint termCh, uint& i)
{
  int brkLevel = 0;
  int brcLevel = 0;

  do {
    if (i == termCh)
      return;
    switch (Pic[i]) {
      case _T('['): brkLevel++; break;
      case _T(']'): brkLevel--; break;
      case _T('{'): brcLevel++; break;
      case _T('}'): brcLevel--; break;
      case _T(';'): i++; break;
      case _T('*'):
        i++;
        while (_istdigit((tchar)Pic[i]))
          i++;
        ToGroupEnd(termCh, i);
        continue;
    }
    i += CharSize((LPCTSTR)Pic.c_str() + i) / sizeof(tchar);
  } while (brkLevel || brcLevel);
}
	Version::Version(const String& string)
	{
		String delim(Text("."));
		String part;
		SizeT start = 0;

		auto pos = string.Split(delim, part, start);
		while (-1 != pos)
		{
			SizeT value = 0;

			auto raw = part.GetBuffer();
			if (nullptr != raw)
			{
				while (*raw != Text('\0') && !_istdigit(*raw))
				{
					raw++;
				}
				value = _tcstoul(raw, NULL, 10);
			}

			m_parts.push_back(value);
			pos = string.Split(delim, part, start);
		}
	}
Example #18
0
/*
 * set the exitflag to true
 */
INT CommandExit (LPTSTR param)
{
    if (!_tcsncmp (param, _T("/?"), 2))
    {
        ConOutResPaging(TRUE,STRING_EXIT_HELP);
        /* Just make sure */
        bExit = FALSE;
        /* Dont exit */
        return 0;
    }

    if (bc != NULL && _tcsnicmp(param,_T("/b"),2) == 0)
    {
        param += 2;
        while (_istspace (*param))
            param++;
        if (_istdigit(*param))
            nErrorLevel = _ttoi(param);
        ExitBatch();
    }
    else
    {
        bExit = TRUE;
    }

    return 0;
}
Example #19
0
bool Character::IsHexidimalDigit( TCHAR character )
{
	bool _smallLiteral = (character >= 'a')&&(character <= 'f');
	bool _capitalLiteral = (character >= 'A')&&(character <= 'F');

	return _smallLiteral || _capitalLiteral || _istdigit(character);
}
Example #20
0
BOOL COXString::IsInt()
{
	for (int nIndex = 0; nIndex < GetLength(); nIndex++)
		if (!_istdigit(GetAt(nIndex)))
			return FALSE;
	return TRUE;		
}
Example #21
0
BOOL InjectDllToOne(LPCTSTR szProc, int nMode, LPCTSTR szDllPath)
{
    int                     i = 0, nLen = (int)_tcslen(szProc);
	DWORD                   dwPID = 0;
	HANDLE                  hSnapShot = INVALID_HANDLE_VALUE;
	PROCESSENTRY32          pe;
    BOOL                    bMore = FALSE;

    // check if ProcName or PID
    for(i = 0; i < nLen; i++)
        if( !_istdigit(szProc[i]) )
            break;

    if( i == nLen )     // PID
    {
        dwPID = (DWORD)_tstol(szProc);
        
        if( nMode == INJECTION_MODE )
            InjectDll(dwPID, szDllPath);
        else
            EjectDll(dwPID, szDllPath);
    }
    else                // ProcName
    {
        // Get the snapshot of the system
	    pe.dwSize = sizeof(PROCESSENTRY32);
	    hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPALL, NULL);
        if( hSnapShot == INVALID_HANDLE_VALUE )
        {
            _tprintf(L"InjectDllToOne() : CreateToolhelp32Snapshot() failed!!! [%d]", 
                      GetLastError());
            return FALSE;
        }

	    // find process
	    bMore = Process32First(hSnapShot, &pe);
	    for( ; bMore; bMore = Process32Next(hSnapShot, &pe) )
	    {
		    dwPID = pe.th32ProcessID;

            // 시스템의 안정성을 위해서
            // PID 가 100 보다 작은 시스템 프로세스에 대해서는
            // DLL Injection 을 수행하지 않는다.
		    if( dwPID < 100 )
			    continue;

            if( !_tcsicmp(pe.szExeFile, szProc) )
            {
                if( nMode == INJECTION_MODE )
		            InjectDll(dwPID, szDllPath);
                else
                    EjectDll(dwPID, szDllPath);
            }
	    }

	    CloseHandle(hSnapShot);
    }

    return TRUE;
}
Example #22
0
BOOL SDateEdit::ProcessMask(TCHAR& nChar, int nEndPos)
{
    // check the key against the mask
    if (m_strMask[nEndPos] == _T('0') && _istdigit((TCHAR)nChar))
    {
        // Allow d/m/y and m/d/y

        if (nEndPos == 0 || nEndPos == 3)
        {
            if (nChar > '3')
                return FALSE;
        }
        if (nEndPos == 1 || nEndPos == 4)
        {
            if (m_strWindowText.GetAt(0) == _T('3'))
            {
                if (nChar > _T('1'))
                    return FALSE;
            }
        }

        return TRUE;
    }

    return FALSE;
}
Example #23
0
// symbol test
static bool isSymbolChar(_TCHAR i_c)
{
	if (i_c == _T('\0'))
		return false;
	if (_istlead(i_c) ||
		_istalpha(i_c) ||
		_istdigit(i_c) ||
		_istlead(i_c))
		return true;

#ifdef UNICODE
	if (0x80 <= i_c && _istgraph(i_c))
		return true;
#endif // UNICODE

	if (_istpunct(i_c))
		return !!_tcschr(_T("-+/?_\\"), i_c);

#ifdef UNICODE
	// check arrows
	if (_tcschr(_T("\x2190\x2191\x2192\x2193"), i_c)) {
		return true;
	}
#endif // UNICODE
	return _istgraph(i_c);
}
CString MakeOutputValue(const CString& value)
{
	CString outValue;
	if (value == "nil")
	{
		outValue = "nil";
	}
	else if (value == "[table]"  ||  value == "[function]"  ||  value == "[cfunction]"  ||  value == "[userdata]")
	{
		// Nothing.
	}
	else if (value[0] == '"')
	{
		// String.
		outValue = "\"" + value.Mid(1, value.GetLength() - 2) + "\"";
	}
	else
	{
		// Number?
		for (int i = 0; i < value.GetLength(); ++i)
		{
			TCHAR ch = value[i];
			if (!_istdigit(ch)  &&  ch != '.'  &&  ch != 'e'  &&  ch != '-')
			{
				// Invalid.
				return "";
			}
		}

		outValue.Format(_T("%f"), _tstof(value));
	}

	return outValue;
}
Example #25
0
BOOL CMaskData::IsValidInput(TCHAR chNewChar)
{
	BOOL bIsValidInput=FALSE;
	switch(m_eType)
	{
	// These are the input types. 
	case MaskDataTypeDIGIT             :
		bIsValidInput=_istdigit(chNewChar);
		break;
	case MaskDataTypeALPHANUMERIC      :
		bIsValidInput=_istalnum(chNewChar);
		break;
	case MaskDataTypeALPHABETIC        :
	case MaskDataTypeALPHAETICUPPER    :
	case MaskDataTypeALPHAETICLOWER    :
		bIsValidInput=_istalpha(chNewChar);
		break;
	case MaskDataTypeCHARACTER         :
		if((chNewChar >=  32) && (chNewChar <= 126))
			bIsValidInput=TRUE ;
		if((chNewChar >= 128) && (chNewChar <= 255))
			bIsValidInput=TRUE ;
		break;
	}
	return bIsValidInput;
}
Example #26
0
void Util::MakeValidUserName(CString& strName, BOOL bWPN, WORD wID)
{

	strName.Replace(" ", " "); // replace normal space with nonbreaking space
	
	CString strBase = strName;
	Util::BaseName(strBase);

	if(strBase.GetLength() > 36){

		//strBase = strBase.Left(39);
		strBase.Truncate(39);
		int nLen = strBase.GetLength()-1;
		while(nLen > 35){

			if(!_istdigit(strBase[nLen])){

				strBase.SetAt(nLen, (char)(rand()%9 + 48));
			}
			nLen--;
		}
	}

	// Verify the last 3 digits are numbers
	int nDigits = 0, i = strBase.GetLength() - 1;
	for(nDigits = 0; i > 0 && nDigits < 3; i--){

		if(_istdigit(strBase[i])) nDigits ++;
		else break;
	}
	while(nDigits < 3){

		strBase += Util::Formatint(rand() % 9);
		nDigits++;
	}


	if(bWPN){

		strName.Format("%s_%05d", strBase, wID);
	}

	else{

		strName.Format("%s_%05d", strBase, rand() % 99999);
	}
}
Example #27
0
///////////////////////////////////////////////////////////////////////////////////////////////
// Pendant zu wsprintf() für string-Parameter;
// im Unterschied zu Format() werden hier die übergebenen Parameter auf den Stack erwartet;
// der Hauptteil dieser Routine beschäftigt sich damit, die Zeichenanzahl für den char*-Puffer
// pTmp zu ermitteln, der dann nur noch an die Bibliotheksfunktion _vstprintf() übergeben wird
void FormatV (string& rStr, LPCTSTR lpszFormat, va_list argList)
{
	TX_ASSERT (TIsValidString(lpszFormat, false));

va_list argListSave = argList;

// make a guess at the maximum length of the resulting string
int nMaxLen = 0;

	for (LPCTSTR lpsz = lpszFormat; *lpsz != '\0'; lpsz = _tcsinc(lpsz))
	{
		// handle '%' character, but watch out for '%%'
		if (*lpsz != '%' || *(lpsz = _tcsinc(lpsz)) == '%')
		{
			nMaxLen += _tclen(lpsz);
			continue;
		}

	int nItemLen = 0;

	// handle '%' character with format
	int nWidth = 0;

		for (; *lpsz != '\0'; lpsz = _tcsinc(lpsz))
		{
			// check for valid flags
			if (*lpsz == '#')
				nMaxLen += 2;   // for '0x'
			else if (*lpsz == '*')
				nWidth = va_arg(argList, int);
			else if (*lpsz == '-' || *lpsz == '+' || *lpsz == '0' ||
				*lpsz == ' ')
				;
			else // hit non-flag character
				break;
		}
		// get width and skip it
		if (nWidth == 0)
		{
			// width indicated by
			nWidth = _ttoi(lpsz);
			for (; *lpsz != '\0' && _istdigit(*lpsz); lpsz = _tcsinc(lpsz))
				;
		}
		TX_ASSERT (nWidth >= 0);

	int nPrecision = 0;

		if (*lpsz == '.')
		{
			// skip past '.' separator (width.precision)
			lpsz = _tcsinc(lpsz);

			// get precision and skip it
			if (*lpsz == '*')
			{
				nPrecision = va_arg(argList, int);
				lpsz = _tcsinc(lpsz);
			}
Example #28
0
CString Util::GetBaseName(const CString strName, BOOL bNoAdd, BOOL bNoID)
{

	CString strBase;
	
	int n = strName.ReverseFind('_');

	if((n > 0) && (strName.GetLength() - n == 6)){

       strBase  = strName.Left(strName.GetLength() - 6);
	}
	else{

		strBase = strName;
	}
	if(bNoID){

		int nDigits = 0, i = strBase.GetLength() - 1;
		for(nDigits = 0; i > 0 && nDigits < 3; i--){

			if(_istdigit(strBase[i])) nDigits ++;
			else break;
		}
		if(nDigits <= 3){

			strBase = strBase.Left(strBase.GetLength()-nDigits);
			return strBase;
		}
	}
	if(bNoAdd) return strBase;

	// test if the last 3 characters of the basename are digits
	int nDigits = 0, i = strBase.GetLength() - 1;
	for(nDigits = 0; i > 0 && nDigits < 3; i--){

		if(_istdigit(strBase[i])) nDigits ++;
		else break;
	}
	while(nDigits < 3){

		strBase += Util::Formatint(rand() % 9);
		nDigits++;
	}
	
	return strBase;
}
Example #29
0
BOOL IsNumber(LPCTSTR pszText)
{
	for( int i = 0; i < lstrlen( pszText ); i++ )
		if( !_istdigit( pszText[ i ] ) )
			return false;

	return true;
}
Example #30
0
static int compare_left(const TCHAR *a, const TCHAR *b)
{
	/* Compare two left-aligned numbers: the first to have a
	different value wins. */
	for (;; a++, b++) {
		if (!_istdigit(*a))
			return !_istdigit(*b) - 1;
		else if (!_istdigit(*b))
			return +1;
		else if (*a < *b)
			return -1;
		else if (*a > *b)
			return +1;
	}

	return 0;
}