Exemplo n.º 1
0
DBOOL CCredit::AddString(char* sString)
{
	// Sanity checks...

	if (!m_pClientDE) return(DFALSE);
	if (!sString) return(DFALSE);
	if (m_cStrings >= MAX_CREDIT_STRINGS) return(DFALSE);


	// Check if this is a special command string...

	if (_mbsnbcmp((const unsigned char*)sString, (const unsigned char*)">TIME:", 6) == 0)
	{
		if (_mbstrlen(sString) > 6)
		{
			m_fHoldTime = (float)atof(&sString[6]);
			return(DTRUE);
		}
	}


	// Create a new string via the engine...

	HSTRING hString = m_pClientDE->CreateString(sString);
	if (!hString) return(DFALSE);

	m_aStrings[m_cStrings++] = hString;


	// All done...

	return(DTRUE);
}
Exemplo n.º 2
0
int __cdecl _mbsnbcoll(
    const unsigned char *s1,
    const unsigned char *s2,
    size_t n
    )
{
#if !defined (_WIN32)
        return _mbsnbcmp(s1, s2, n);
#else  /* !defined (_WIN32) */
        int ret;

        if (n == 0)
            return 0;

        if (0 == (ret = __crtCompareStringA(__mblcid, 0,
                s1, n, s2, n, __mbcodepage)))
            return _NLSCMPERROR;

        return ret - 2;

#endif  /* !defined (_WIN32) */
}
Exemplo n.º 3
0
HSURFACE CTextHelper::CreateWrappedSurface (ILTClient* pClientDE, int nWidth, HLTFONT hFont, char* pString, HLTCOLOR foreColor, HLTCOLOR backColor, int nAlignment, LTBOOL bCropped, int nExtraX, int nExtraY)
{
	if (!pString || !pClientDE) return LTNULL;

	// check if we are supposed to do hard wrapping
	bool bHardTextWrap = false;
	{
		HSTRING hStr = pClientDE->FormatString(IDS_ENABLETEXTHARDWRAP);
		if (hStr)
		{
			const char* pComp = pClientDE->GetStringData(hStr);
			if (pComp != NULL)
			{
				if (stricmp(pComp,"TRUE") == 0) bHardTextWrap = true;
			}
			pClientDE->FreeString (hStr);
		}
	}

	// get period or other characters that are not supposed to be at start of a line
	char sPeriodChars[256] = ".";
	{
		HSTRING hStr = pClientDE->FormatString(IDS_EXCLULTLineSTARTCHARS);
		if (hStr)
		{
			const char* pComp = pClientDE->GetStringData(hStr);
			if (pComp != NULL)
			{
				_mbsncpy((unsigned char*)sPeriodChars, (const unsigned char*)pComp, 255);
				sPeriodChars[255] = '\0';
			}
			pClientDE->FreeString (hStr);
		}
	}

	char* pWorkingString = new char [strlen (pString) + 1];
	if (!pWorkingString) return LTNULL;

	CDynArray<uint32> surfaces (1, 2);		// cannot create a dynarray of HSURFACES - compiler error C2926
	uint32 nSurfaces = 0;

	char* ptr = (char*) pString;
	while (*ptr != '\0')
	{
		// copy what's left into the working string

		strcpy (pWorkingString, ptr);

		// create a string that will fit into the desired width

		LTBOOL bDone = LTFALSE;
		HSURFACE hSurface = LTNULL;
		while (!bDone)
		{
			// create a string surface from the working string to test

			HSTRING hString = pClientDE->CreateString (pWorkingString);
			if (!hString) break;

			hSurface = pClientDE->CreateSurfaceFromString (hFont, hString, foreColor, backColor, nExtraX, nExtraY);
			if (!hSurface)
			{
				pClientDE->FreeString (hString);
				break;
			}

			pClientDE->FreeString (hString);
			
			// get the dimensions of the surface

			uint32 nTestWidth = 0;
			uint32 nTestHeight = 0;
			pClientDE->GetSurfaceDims (hSurface, &nTestWidth, &nTestHeight);

			if (nTestWidth > (uint32)nWidth)
			{
				// string too long, remove some and try again

				char* pSpace;

				// remove by character if we are hard wrapping
				if (bHardTextWrap)
				{
					pSpace = pWorkingString;

					// find last hard in string pPrev
					char* pPrev = NULL;
					while (pSpace != NULL)
					{
						pPrev = pSpace;
						pSpace = (char*)_mbsinc ((const unsigned char*)pSpace);
						if (*pSpace == '\0') pSpace = NULL;
					}
					if (pPrev == NULL) pSpace = pWorkingString;
					else 
					{
						//decrement 1 character
						pSpace = (char*)_mbsdec ((const unsigned char*)pWorkingString, (const unsigned char*)pPrev);

						// check if we are on a period then we need to decrement 3 more
						if ((char*)_mbsspnp((const unsigned char*)pPrev, (const unsigned char*)sPeriodChars) != pPrev)
						{
							if (pSpace != NULL)	pSpace = (char*)_mbsdec ((const unsigned char*)pWorkingString, (const unsigned char*)pSpace);
							if (pSpace != NULL)	pSpace = (char*)_mbsdec ((const unsigned char*)pWorkingString, (const unsigned char*)pSpace);
						}
					}

				}

				// remove by word if hard wrap is not on
				else 
				{
					pSpace = (char*)_mbsrchr ((const unsigned char*)pWorkingString, ' ');
					if (!pSpace) pSpace = pWorkingString;

					while (_mbsnbcmp ((const unsigned char*)pSpace, (const unsigned char*)" ", 1) == 0 && pSpace != pWorkingString)
					{
						pSpace = (char*)_mbsdec ((const unsigned char*)pWorkingString, (const unsigned char*)pSpace);
						if (!pSpace) pSpace = pWorkingString;
					}
				}


				if (pSpace == pWorkingString)
				{
					bDone = LTTRUE;
				}
				else
				{
					pSpace = (char*)_mbsinc ((const unsigned char*)pSpace);
					*pSpace = '\0';
				}

				pClientDE->DeleteSurface (hSurface);
				hSurface = LTNULL;
			}
			else
			{
				// it fits!

				bDone = LTTRUE;
			}
		}
		
		// if we got here without bDone being TRUE, there was an error
		if (!bDone)
		{
			delete [] pWorkingString;
			for (uint32 i = 0; i < nSurfaces; i++)
			{
				pClientDE->DeleteSurface ((HSURFACE)surfaces[i]);
			}
			return LTNULL;
		}

		// if bDone is true but there's no surface, we couldn't make it fit
		// just create a surface from the string and it will get clipped later
		if (bDone && !hSurface)
		{
			HSTRING hString = pClientDE->CreateString (pWorkingString);
			hSurface = pClientDE->CreateSurfaceFromString (hFont, hString, foreColor, backColor, nExtraX, nExtraY);
			if (!hString || !hSurface)
			{
				if (hString) pClientDE->FreeString (hString);
				if (hSurface) pClientDE->DeleteSurface (hSurface);

				delete [] pWorkingString;
				for (uint32 i = 0; i < nSurfaces; i++)
				{
					pClientDE->DeleteSurface ((HSURFACE)surfaces[i]);
				}
				return LTNULL;
			}
			pClientDE->FreeString (hString);
		}

		// add this surface to the array

		surfaces[nSurfaces] = (uint32) hSurface;
		nSurfaces++;

		// increment ptr to next character in the string

		ptr += strlen (pWorkingString);
		
		char* pPrev = NULL;
		while (_mbsnbcmp ((const unsigned char*)ptr, (const unsigned char*)" ", 1) == 0 && *ptr)
		{
			pPrev = ptr;
			ptr = (char*)_mbsinc ((const unsigned char*)ptr);
			if (!ptr) 
			{
				ptr = pPrev;
				break;
			}
		}
	}

	delete [] pWorkingString;

	// ok, now we should have an array of surfaces that we can combine into one large one...

	if (!nSurfaces) return LTNULL;

	// crop the surfaces if they need to be cropped (leave a one-pixel border)

	if (bCropped)
	{
		for (uint32 i = 0; i < nSurfaces; i++)
		{
			HSURFACE hCropped = CropSurface (pClientDE, (HSURFACE)surfaces[i], LTNULL);
			if (hCropped)
			{
				pClientDE->DeleteSurface ((HSURFACE)surfaces[i]);
				surfaces[i] = (uint32) hCropped;
			}
		}
	}

	// get the final surface height

	uint32 nTotalHeight = 0;
	for (uint32 i = 0; i < nSurfaces; i++)
	{
		uint32 nSurfWidth = 0;
		uint32 nSurfHeight = 0;
		pClientDE->GetSurfaceDims ((HSURFACE)surfaces[i], &nSurfWidth, &nSurfHeight);

		nTotalHeight += nSurfHeight;
	}

	// create the final surface

	HSURFACE hFinalSurface = pClientDE->CreateSurface (nWidth, nTotalHeight);
	if (!hFinalSurface)
	{
		for (uint32 i = 0; i < nSurfaces; i++)
		{
			pClientDE->DeleteSurface ((HSURFACE)surfaces[i]);
		}
		return LTNULL;
	}
	pClientDE->FillRect ((HSURFACE)hFinalSurface, LTNULL, LTNULL);

	// draw the string surfaces onto final one

	int y = 0;
	for (int i = 0; i < nSurfaces; i++)
	{
		uint32 nSurfWidth = 0;
		uint32 nSurfHeight = 0;
		pClientDE->GetSurfaceDims ((HSURFACE)surfaces[i], &nSurfWidth, &nSurfHeight);

		int x = 0;
		switch (nAlignment)
		{
			case TH_ALIGN_CENTER:	x = ((int)nWidth - (int)nSurfWidth) / 2;	break;
			case TH_ALIGN_RIGHT:	x = (int)nWidth - (int)nSurfWidth;			break;
		}
		pClientDE->DrawSurfaceToSurface (hFinalSurface, (HSURFACE)surfaces[i], LTNULL, x, y);
		y += nSurfHeight;

		// delete this surface since we don't need it anymore

		pClientDE->DeleteSurface ((HSURFACE)surfaces[i]);
	}
	
	if (bCropped)
	{
		HSURFACE hCropped = CropSurface (pClientDE, hFinalSurface, backColor);
		if (hCropped)
		{
			pClientDE->DeleteSurface (hFinalSurface);
			return hCropped;
		}
	}

	return hFinalSurface;
}
Exemplo n.º 4
0
void CCredits::AddCredits()
{
	// Sanity checks...

	if (!m_pClientDE) return;


	// Set the static info...

	if (!CCredit::SetStaticInfo(m_pClientDE, GetMode(), IsClearingScreen()))
	{
		return;
	}


	// Get the credits text buffer...

	char* sName = NULL;

#ifdef _ADDON
	if (IsIntro()) sName = "INTRO_AO";
	else sName = "CREDITS_AO";
#else
	if (IsIntro()) sName = "INTRO";
	else sName = "CREDITS";
#endif

	void* hModule = NULL;
	m_pClientDE->GetEngineHook("cres_hinstance", &hModule);

	char* sBuf = CreditsWin_GetTextBuffer(sName, hModule);
	if (!sBuf) return;


	char sCredit[1024];
	int  i = 0;

	while (*sBuf)
	{

		if (*sBuf == '#' && *((char*)_mbsinc((const unsigned char*)sBuf)) == '#')
		{
			sCredit[i] = '\0';

			if (_mbsnbcmp((const unsigned char*)sCredit, (const unsigned char*)">END", 4) == 0)	// end?
			{
				return;
			}

			AddCredit(sCredit);
			i = 0;

			sBuf = (char*)_mbsinc((const unsigned char*)sBuf);
			sBuf = (char*)_mbsinc((const unsigned char*)sBuf);

			while (*sBuf != '\0' && ((*sBuf == '\n') || (*sBuf == '\r'))) sBuf++;
		}
		else
		{
			int nCount = _mbsnbcnt((const unsigned char*)sBuf,1);
			memcpy(&sCredit[i], sBuf, nCount);
			i += nCount;
			sBuf = (char*)_mbsinc((const unsigned char*)sBuf);
		}
	}
}
int test_implicit_compare_with_functions() {

  if (memcmp(A, "a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'memcmp' is called without explicitly comparing result
  // CHECK-FIXES: memcmp(A, "a", 1) != 0)

  if (wmemcmp(W, L"a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wmemcmp' is called without explicitly comparing result
  // CHECK-FIXES: wmemcmp(W, L"a", 1) != 0)

  if (memicmp(A, "a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'memicmp' is called without explicitly comparing result
  // CHECK-FIXES: memicmp(A, "a", 1) != 0)

  if (_memicmp(A, "a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_memicmp' is called without explicitly comparing result
  // CHECK-FIXES: _memicmp(A, "a", 1) != 0)

  if (_memicmp_l(A, "a", 1, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_memicmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _memicmp_l(A, "a", 1, locale) != 0)

  if (strcmp(A, "a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcmp' is called without explicitly comparing result
  // CHECK-FIXES: strcmp(A, "a") != 0)

  if (strncmp(A, "a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strncmp' is called without explicitly comparing result
  // CHECK-FIXES: strncmp(A, "a", 1) != 0)

  if (strcasecmp(A, "a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcasecmp' is called without explicitly comparing result
  // CHECK-FIXES: strcasecmp(A, "a") != 0)

  if (strncasecmp(A, "a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strncasecmp' is called without explicitly comparing result
  // CHECK-FIXES: strncasecmp(A, "a", 1) != 0)

  if (stricmp(A, "a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'stricmp' is called without explicitly comparing result
  // CHECK-FIXES: stricmp(A, "a") != 0)

  if (strcmpi(A, "a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strcmpi' is called without explicitly comparing result
  // CHECK-FIXES: strcmpi(A, "a") != 0)

  if (_stricmp(A, "a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_stricmp' is called without explicitly comparing result
  // CHECK-FIXES: _stricmp(A, "a") != 0)

  if (strnicmp(A, "a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'strnicmp' is called without explicitly comparing result
  // CHECK-FIXES: strnicmp(A, "a", 1) != 0)

  if (_strnicmp(A, "a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_strnicmp' is called without explicitly comparing result
  // CHECK-FIXES: _strnicmp(A, "a", 1) != 0)

  if (_stricmp_l(A, "a", locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_stricmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _stricmp_l(A, "a", locale) != 0)

  if (_strnicmp_l(A, "a", 1, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_strnicmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _strnicmp_l(A, "a", 1, locale) != 0)

  if (wcscmp(W, L"a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcscmp' is called without explicitly comparing result
  // CHECK-FIXES: wcscmp(W, L"a") != 0)

  if (wcsncmp(W, L"a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsncmp' is called without explicitly comparing result
  // CHECK-FIXES: wcsncmp(W, L"a", 1) != 0)

  if (wcscasecmp(W, L"a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcscasecmp' is called without explicitly comparing result
  // CHECK-FIXES: wcscasecmp(W, L"a") != 0)

  if (wcsicmp(W, L"a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsicmp' is called without explicitly comparing result
  // CHECK-FIXES: wcsicmp(W, L"a") != 0)

  if (_wcsicmp(W, L"a"))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsicmp' is called without explicitly comparing result
  // CHECK-FIXES: _wcsicmp(W, L"a") != 0)

  if (_wcsicmp_l(W, L"a", locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsicmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _wcsicmp_l(W, L"a", locale) != 0)

  if (wcsnicmp(W, L"a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function 'wcsnicmp' is called without explicitly comparing result
  // CHECK-FIXES: wcsnicmp(W, L"a", 1) != 0)

  if (_wcsnicmp(W, L"a", 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsnicmp' is called without explicitly comparing result
  // CHECK-FIXES: _wcsnicmp(W, L"a", 1) != 0)

  if (_wcsnicmp_l(W, L"a", 1, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_wcsnicmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _wcsnicmp_l(W, L"a", 1, locale) != 0)

  if (_mbscmp(U, V))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbscmp' is called without explicitly comparing result
  // CHECK-FIXES: _mbscmp(U, V) != 0)

  if (_mbsncmp(U, V, 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsncmp' is called without explicitly comparing result
  // CHECK-FIXES: _mbsncmp(U, V, 1) != 0)

  if (_mbsnbcmp(U, V, 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbcmp' is called without explicitly comparing result
  // CHECK-FIXES: _mbsnbcmp(U, V, 1) != 0)

  if (_mbsnbicmp(U, V, 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbicmp' is called without explicitly comparing result
  // CHECK-FIXES: _mbsnbicmp(U, V, 1) != 0)

  if (_mbsicmp(U, V))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsicmp' is called without explicitly comparing result
  // CHECK-FIXES: _mbsicmp(U, V) != 0)

  if (_mbsnicmp(U, V, 1))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnicmp' is called without explicitly comparing result
  // CHECK-FIXES: _mbsnicmp(U, V, 1) != 0)

  if (_mbscmp_l(U, V, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbscmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _mbscmp_l(U, V, locale) != 0)

  if (_mbsncmp_l(U, V, 1, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsncmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _mbsncmp_l(U, V, 1, locale) != 0)

  if (_mbsicmp_l(U, V, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsicmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _mbsicmp_l(U, V, locale) != 0)

  if (_mbsnicmp_l(U, V, 1, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnicmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _mbsnicmp_l(U, V, 1, locale) != 0)

  if (_mbsnbcmp_l(U, V, 1, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbcmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _mbsnbcmp_l(U, V, 1, locale) != 0)

  if (_mbsnbicmp_l(U, V, 1, locale))
    return 0;
  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: function '_mbsnbicmp_l' is called without explicitly comparing result
  // CHECK-FIXES: _mbsnbicmp_l(U, V, 1, locale) != 0)

  return 1;
}