Skip to content

Commit

Permalink
Use CMake to test for strncasecmp
Browse files Browse the repository at this point in the history
  • Loading branch information
LegalizeAdulthood committed Feb 25, 2024
1 parent b969f0e commit 68f9f6a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ project("${ID_PROJECT_NAME}"
HOMEPAGE_URL "https://LegalizeAdulthood.github.io/iterated-dynamics"
LANGUAGES CXX)

include(CheckSymbolExists)
include(CTest)
include(TestBigEndian)

Expand Down Expand Up @@ -62,10 +63,12 @@ add_subdirectory(win32)
add_subdirectory(hc)

test_big_endian(ID_BIG_ENDIAN)
check_symbol_exists(strncasecmp "strings.h" ID_HAVE_STRNCASECMP)
configure_file(headers/port_config.h.in include/port_config.h)
add_library(config INTERFACE)
target_sources(config INTERFACE
headers/port_config.h.in
headers/string_case_compare.h
"${CMAKE_CURRENT_BINARY_DIR}/include/port_config.h"
)
target_include_directories(config INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include")
Expand Down
1 change: 1 addition & 0 deletions common/realdos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "prompts2.h"
#include "realdos.h"
#include "rotate.h"
#include "string_case_compare.h"
#include "zoom.h"

#include <cassert>
Expand Down
2 changes: 2 additions & 0 deletions headers/port_config.h.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#pragma once

#cmakedefine01 ID_BIG_ENDIAN

#cmakedefine ID_HAVE_STRNCASECMP
22 changes: 22 additions & 0 deletions headers/string_case_compare.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#ifdef ID_HAVE_STRNCASECMP
#include <strings.h>

#else
#include <cctype>

// case independent version of std::strncmp
inline int strncasecmp(char const *s, char const *t, int ct)
{
for (; (std::tolower(*s) == std::tolower(*t)) && --ct ; s++, t++)
{
if (*s == '\0')
{
return 0;
}
}
return std::tolower(*s) - std::tolower(*t);
}

#endif
13 changes: 0 additions & 13 deletions win32/os_win32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,16 +816,3 @@ void init_failure(char const *message)
{
MessageBox(nullptr, message, "FractInt: Fatal Error", MB_OK);
}

// case independent version of std::strncmp
int strncasecmp(char const *s, char const *t, int ct)
{
for (; (std::tolower(*s) == std::tolower(*t)) && --ct ; s++, t++)
{
if (*s == '\0')
{
return 0;
}
}
return std::tolower(*s) - std::tolower(*t);
}

0 comments on commit 68f9f6a

Please sign in to comment.