diff --git a/CMakeLists.txt b/CMakeLists.txt index e6be5b4e8..4879b4347 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -608,11 +608,12 @@ target_link_libraries(notcurses-input ############################################################################ # nctetris -file(GLOB TETRISSRC CONFIGURE_DEPENDS src/tetris/*.cpp) +file(GLOB TETRISSRC CONFIGURE_DEPENDS src/tetris/*.cpp src/compat/*.c) add_executable(nctetris ${TETRISSRC}) target_include_directories(nctetris BEFORE PRIVATE + src include "${CMAKE_REQUIRED_INCLUDES}" "${PROJECT_BINARY_DIR}/include" diff --git a/src/compat/compat.h b/src/compat/compat.h index bdda8788f..56aeac8fa 100644 --- a/src/compat/compat.h +++ b/src/compat/compat.h @@ -116,6 +116,26 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *request, struct timespec *remain); +static inline char* +notcurses_data_path(const char* f){ + char* datadir = notcurses_data_dir(); + if(datadir == NULL){ + return NULL; + } + const size_t dlen = strlen(datadir); + // cast is for benefit of c++ callers, sigh + char* path = (char*)malloc(dlen + 1 + strlen(f) + 1); + if(path == NULL){ + free(datadir); + return NULL; + } + strcpy(path, datadir); + free(datadir); + path[dlen] = path_separator(); + strcpy(path + dlen + 1, f); + return path; +} + #ifdef __cplusplus } #else diff --git a/src/demo/demo.c b/src/demo/demo.c index f8b0dadd2..99784d376 100644 --- a/src/demo/demo.c +++ b/src/demo/demo.c @@ -44,12 +44,7 @@ const demoresult* demoresult_lookup(int idx){ } char* find_data(const char* datum){ - const size_t dlen = strlen(datadir); - char* path = malloc(dlen + 1 + strlen(datum) + 1); - strcpy(path, datadir); - path[dlen] = path_separator(); - strcpy(path + dlen + 1, datum); - return path; + return notcurses_data_path(datum); } float delaymultiplier = 1; diff --git a/src/lib/in.c b/src/lib/in.c index f54baf2f4..f35edca2e 100644 --- a/src/lib/in.c +++ b/src/lib/in.c @@ -2275,8 +2275,8 @@ internal_get(inputctx* ictx, const struct timespec* ts, ncinput* ni){ sendsignal = true; }else{ logtrace("draining event readiness pipe %d\n", ictx->ivalid); - char c; #ifndef __MINGW64__ + char c; while(read(ictx->readypipes[0], &c, sizeof(c)) == 1){ // FIXME accelerate? } diff --git a/src/tetris/main.cpp b/src/tetris/main.cpp index 231717393..4f486cf45 100644 --- a/src/tetris/main.cpp +++ b/src/tetris/main.cpp @@ -11,19 +11,14 @@ #include #include #include +#include "compat/compat.h" #include "builddef.h" #include "version.h" std::mutex ncmtx; -#ifdef __MINGW64__ -#define PATHSEP "\\" -#else -#define PATHSEP "/" -#endif -const std::string BackgroundFile = NOTCURSES_SHARE PATHSEP "tetris-background.jpg"; -const std::string LogoFile = NOTCURSES_SHARE PATHSEP "notcurses.png"; -#undef PATHSEP +const std::string BackgroundFile = notcurses_data_path("tetris-background.jpg"); +const std::string LogoFile = notcurses_data_path("notcurses.png"); using namespace std::chrono_literals;