Skip to content

Commit

Permalink
Add support for Mac (without readline, only cli)
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoltán Kovács authored and Zoltán Kovács committed Jan 4, 2025
1 parent 31c54ea commit 8752ea1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,24 @@ jobs:
cd qt/build-pbrst
CC=clang CXX=clang++ cmake -DPBRST=ON -G "MinGW Makefiles" ..
mingw32-make
mac:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- name: prerequisites
run: brew install cmake boost
- name: Build SWORD
run: |
curl -O https://www.crosswire.org/ftpmirror/pub/sword/source/v1.9/sword-1.9.0.tar.gz
tar xzf sword-1.9.0.tar.gz
cd sword-1.9.0
./configure
make
make install
- name: Build bibref
run: |
mkdir build
cd build
cmake ..
make install || true
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost CONFIG COMPONENTS system filesystem)

if(!APPLE) # readline seems to have trouble on MacOS
# One needs readline >= 8.0 to make this work:
pkg_check_modules (readline REQUIRED readline)
endif()

include_directories(${sword_INCLUDE_DIRS})

Expand Down Expand Up @@ -60,6 +62,12 @@ target_link_libraries(bibref
${sword_LIBRARIES} ${Boost_LIBRARIES} ${readline_LIBRARIES}
)

if(APPLE)
target_link_libraries(bibref
-L/usr/local/lib # for sword, it is assumed to be here (via configure/make install)
)
endif()

install(
CODE " set(ENV{SWORD_PATH} \"$ENV{HOME}/.sword\") "
# Download and install LXX and SBLGNT via CrossWire...
Expand Down
16 changes: 12 additions & 4 deletions cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ extern "C" char* brst_scan_string(char *string);
using namespace std;

#ifndef __EMSCRIPTEN__
#ifndef __APPLE__
#include <readline/readline.h>
#include <readline/history.h>
#endif
#endif
#include <boost/algorithm/string/trim.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/split.hpp>
Expand Down Expand Up @@ -132,6 +134,7 @@ void info(const string& message) {
}

#ifndef __EMSCRIPTEN__
#ifndef __APPLE__
// readline related code was taken mostly from https://eli.thegreenplace.net/2016/basics-of-using-the-readline-library/
char* completion_generator(const char* text, int state) {
// This function is called with state=0 the first time; subsequent calls are
Expand Down Expand Up @@ -174,6 +177,7 @@ char** completer(const char* text, int start, int end) {
return rl_completion_matches(text, completion_generator);
}
#endif
#endif

int maxresults;
bool sql;
Expand Down Expand Up @@ -938,7 +942,9 @@ void cli(const char *input_prepend, const char *output_prepend, bool addbooks, b
output_prepend_set = new char[4]; // FIXME: this is hardcoded.
strcpy(output_prepend_set, output_prepend);
#ifndef __EMSCRIPTEN__
#ifndef __APPLE__
rl_attempted_completion_function = completer; // Initialize readline.
#endif
#endif
info("This is bibref " BIBREF_VERSION ", nice to meet you.");
showAvailableBibles();
Expand All @@ -955,6 +961,7 @@ void cli(const char *input_prepend, const char *output_prepend, bool addbooks, b

#ifndef __EMSCRIPTEN__
#ifndef __MINGW32__
#ifndef __APPLE__
// Load the readline history...
char* bufline;
struct passwd *pw = getpwuid(getuid());
Expand All @@ -963,8 +970,9 @@ void cli(const char *input_prepend, const char *output_prepend, bool addbooks, b
read_history(histfile);
#endif
#endif
#endif

#if defined(__EMSCRIPTEN__) || defined(__MINGW32__)
#if defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__APPLE__)
#define MAX_LINE_LENGTH 1024
char bufline[MAX_LINE_LENGTH + 1];
#endif
Expand All @@ -975,13 +983,13 @@ void cli(const char *input_prepend, const char *output_prepend, bool addbooks, b
bool multiline = false;
// The main input/output loop...
while (
#if !defined(__EMSCRIPTEN__) && !defined(__MINGW32__)
#if !defined(__EMSCRIPTEN__) && !defined(__MINGW32__) && !defined(__APPLE__)
(bufline = readline(input_prepend)) != nullptr
#else
(getline(cin, line) && (strcpy(bufline, line.c_str())))
#endif
) {
#if !defined(__EMSCRIPTEN__) && !defined(__MINGW32__)
#if !defined(__EMSCRIPTEN__) && !defined(__MINGW32__) && !defined(__APPLE__)
if (strlen(bufline) > 0) {
add_history(bufline);
write_history(histfile);
Expand All @@ -1003,7 +1011,7 @@ void cli(const char *input_prepend, const char *output_prepend, bool addbooks, b
cli_process(buf); // Process the input.
buf[0] = '\0';
} else strcat(buf, "\n");
#if !(defined(__EMSCRIPTEN__) || defined(__MINGW32__))
#if !(defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__APPLE__))
// readline malloc's a new buffer every time.
free(bufline);
#endif
Expand Down

0 comments on commit 8752ea1

Please sign in to comment.