Skip to content

Commit

Permalink
Merge pull request H-uru#1378 from dgelessus/remove_headspin_wstring_…
Browse files Browse the repository at this point in the history
…functions

Remove last uses of `hsStringToWString` and `hsWStringToString`
  • Loading branch information
zrax committed Apr 11, 2023
2 parents 355c126 + f5a8927 commit 9ddcdfa
Show file tree
Hide file tree
Showing 8 changed files with 4 additions and 66 deletions.
40 changes: 0 additions & 40 deletions Sources/Plasma/CoreLib/HeadSpin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ You can contact Cyan Worlds, Inc. by email [email protected]
*==LICENSE==*/
#include "HeadSpin.h"
#include "hsWindows.h"
#include <wchar.h>

#ifdef _MSC_VER
# include <crtdbg.h>
Expand Down Expand Up @@ -437,42 +436,3 @@ char* hsStrcpy(char* dst, const char* src)

return dst;
}

//// IStringToWString /////////////////////////////////////////////////////////
// Converts a char * string to a wchar_t * string

wchar_t *hsStringToWString( const char *str )
{
// convert the char string to a wchar_t string
size_t len = strlen(str);
wchar_t *wideString = new wchar_t[len+1];
for (size_t i = 0; i < len; i++)
wideString[i] = btowc(str[i]);
wideString[len] = L'\0';
return wideString;
}

//// IWStringToString /////////////////////////////////////////////////////////
// Converts a wchar_t * string to a char * string

char *hsWStringToString( const wchar_t *str )
{
// convert the wchar_t string to a char string
size_t len = wcslen(str);
char *sStr = new char[len+1];

for (size_t i = 0; i < len; i++)
{
char temp = wctob(str[i]);
if (temp == EOF)
{
sStr[i] = '\0';
i = len;
}
else
sStr[i] = temp;
}
sStr[len] = '\0';

return sStr;
}
14 changes: 0 additions & 14 deletions Sources/Plasma/CoreLib/HeadSpin.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,14 @@ inline char *hsStrncpy(char *strDest, const char *strSource, size_t count)
return temp;
}

wchar_t *hsStringToWString( const char *str );
char *hsWStringToString( const wchar_t *str );

// Use "correct" non-standard string functions based on the
// selected compiler / library
#if HS_BUILD_FOR_WIN32
# define stricmp _stricmp
# define strnicmp _strnicmp
# define wcsicmp _wcsicmp
# define wcsnicmp _wcsnicmp
# define strdup _strdup
# define wcsdup _wcsdup
#else
# define stricmp strcasecmp
# define strnicmp strncasecmp
# define wcsicmp wcscasecmp
# define wcsnicmp wcsncasecmp
#endif

enum { // Kind of MessageBox...passed to hsMessageBox
Expand Down Expand Up @@ -336,17 +327,12 @@ int hsMessageBoxWithOwner(hsWindowHndl owner, const wchar_t* message, const wcha
#if HS_BUILD_FOR_WIN32
// This is for Windows
# define snprintf _snprintf
# define swprintf _snwprintf

# ifndef fileno
# define fileno(__F) _fileno(__F)
# endif

# define hsWFopen(name, mode) _wfopen(name, mode)
#else
// This is for Unix, Linux, OSX, etc.
# define hsWFopen(name, mode) fopen(hsWStringToString(name), hsWStringToString(mode))

# include <limits.h>
# define MAX_PATH PATH_MAX
#endif
Expand Down
2 changes: 1 addition & 1 deletion Sources/Plasma/FeatureLib/pfGameGUIMgr/pfGUIMenuItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void pfGUIMenuItem::IUpdate()
else
{
fDynTextMap->SetJustify( plDynamicTextMap::kRightJustify );
fDynTextMap->DrawString( x + fDynTextMap->GetVisibleWidth() - 2, y, ">>" );
fDynTextMap->DrawString(x + fDynTextMap->GetVisibleWidth() - 2, y, L">>");
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,13 +487,6 @@ void plDynamicTextMap::SetTextColor( hsColorRGBA &color, bool blockRGB )

//// DrawString ///////////////////////////////////////////////////////////////

void plDynamicTextMap::DrawString( uint16_t x, uint16_t y, const char *text )
{
wchar_t *wText = hsStringToWString(text);
DrawString(x,y,wText);
delete [] wText;
}

void plDynamicTextMap::DrawString( uint16_t x, uint16_t y, const wchar_t *text )
{
if( !IIsValid() )
Expand Down
1 change: 0 additions & 1 deletion Sources/Plasma/PubUtilLib/plGImage/plDynamicTextMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ class plDynamicTextMap : public plMipmap
void SetTextColor( hsColorRGBA &color, bool blockRGB = false );
void SetJustify( Justify j );

void DrawString( uint16_t x, uint16_t y, const char *text );
void DrawString( uint16_t x, uint16_t y, const wchar_t *text );
void DrawClippedString( int16_t x, int16_t y, const ST::string &text, uint16_t width, uint16_t height );
void DrawClippedString( int16_t x, int16_t y, const wchar_t *text, uint16_t width, uint16_t height );
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tools/MaxExport/plExportDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ plExportDlgImp::plExportDlgImp()
BOOL WritePrivateProfileIntW(LPCWSTR lpAppName, LPCWSTR lpKeyName, int val, LPCWSTR lpFileName)
{
wchar_t buf[12];
swprintf(buf, 12, L"%d", val);
_snwprintf(buf, 12, L"%d", val);

return WritePrivateProfileStringW(lpAppName, lpKeyName, buf, lpFileName);
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tools/MaxMain/plMaxCFGFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ bool plMaxConfig::AssetManInterfaceDisabled()
uint32_t len = GetPrivateProfileStringW(L"AssetMan", L"Disable", L"", configstr, MAX_PATH,
plugDir.WideString().data());

if (wcscmp(configstr, L"1") == 0 || wcsicmp(configstr, L"true") == 0)
if (wcscmp(configstr, L"1") == 0 || _wcsicmp(configstr, L"true") == 0)
disabled = true;
else
disabled = false;
Expand Down
2 changes: 1 addition & 1 deletion Sources/Tools/MaxMain/plMaxMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void plCreateMenu()

// Update the menu version
wchar_t buf[12];
swprintf(buf, std::size(buf), L"%d", kMenuVersion);
_snwprintf(buf, std::size(buf), L"%d", kMenuVersion);
WritePrivateProfileStringW(L"Menu", L"Version", buf, plMaxConfig::GetPluginIni().WideString().data());
}

Expand Down

0 comments on commit 9ddcdfa

Please sign in to comment.