Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
[linux] replace MSVC _strupr and _strlwr with custom toupr and tolwr
Browse files Browse the repository at this point in the history
  • Loading branch information
q4a committed May 17, 2022
1 parent 87cdb7d commit ae0f6f9
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
23 changes: 23 additions & 0 deletions src/libs/common/include/defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "math3d.h"
#include <cstdint>
#include <cstring>
#include <cctype>

namespace TOREMOVE
{
Expand Down Expand Up @@ -104,6 +105,28 @@ constexpr float PId4 = (PI / 4.0f);
#undef SQR
#endif

inline char *toupr(char *str)
{
char *result = str;
while (*str != '\0')
{
*str = toupper(*str);
str++;
}
return result;
}

inline char *tolwr(char *str)
{
char *result = str;
while (*str != '\0')
{
*str = tolower(*str);
str++;
}
return result;
}

inline uint32_t F2DW(float f)
{
return *reinterpret_cast<uint32_t *>(&f);
Expand Down
2 changes: 1 addition & 1 deletion src/libs/core/src/token.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void TOKEN::LowCase()
{
if (pTokenData[0] == 0)
return;
_strlwr(pTokenData);
tolwr(pTokenData);
}

const char *TOKEN::GetData()
Expand Down
8 changes: 4 additions & 4 deletions src/libs/renderer/src/s_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1351,7 +1351,7 @@ int32_t DX9RENDER::TextureCreate(const char *fname)
strcpy_s(_fname, fname);
}

_strupr(_fname);
toupr(_fname);

const uint32_t hf = hash_string(_fname);

Expand Down Expand Up @@ -2925,7 +2925,7 @@ int32_t DX9RENDER::LoadFont(const char *fontName)
strncpy_s(sDup, fontName, sizeof(sDup) - 1);
sDup[sizeof(sDup) - 1] = 0;
}
fontName = _strupr(sDup);
fontName = toupr(sDup);
const uint32_t hashVal = hash_string(fontName);

int32_t i;
Expand Down Expand Up @@ -2976,7 +2976,7 @@ bool DX9RENDER::UnloadFont(const char *fontName)
strncpy_s(sDup, fontName, sizeof(sDup) - 1);
sDup[sizeof(sDup) - 1] = 0;
}
fontName = _strupr(sDup);
fontName = toupr(sDup);
const uint32_t hashVal = hash_string(fontName);

for (int i = 0; i < nFontQuantity; i++)
Expand Down Expand Up @@ -3029,7 +3029,7 @@ bool DX9RENDER::SetCurFont(const char *fontName)
strncpy_s(sDup, fontName, sizeof(sDup) - 1);
sDup[sizeof(sDup) - 1] = 0;
}
fontName = _strupr(sDup);
fontName = toupr(sDup);
const uint32_t hashVal = hash_string(fontName);

for (int i = 0; i < nFontQuantity; i++)
Expand Down
2 changes: 1 addition & 1 deletion src/libs/ship/src/ship_lights.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void ShipLights::AddFlare(VAI_OBJBASE *pObject, bool bLight, MODEL *pModel, cons
if (!label.name)
return;
strcpy_s(str, label.name);
_strlwr(str);
tolwr(str);

aLights.push_back(ShipLight{});
ShipLight *pL = &aLights.back();
Expand Down
4 changes: 2 additions & 2 deletions src/libs/weather/src/stars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ void Astronomy::STARS::Init(ATTRIBUTES *pAP)
char str[2];
str[0] = pAS->GetThisName()[0];
str[1] = 0;
_strupr(str);
toupr(str);
Spectr[str[0]] = pAS->GetAttributeAsDword();
_strlwr(str);
tolwr(str);
Spectr[str[0]] = pAS->GetAttributeAsDword();
}
}
Expand Down

0 comments on commit ae0f6f9

Please sign in to comment.