diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b1d94d..34c1616 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,4 +5,9 @@ set(CMAKE_C_STANDARD 11) add_executable(xls2txt xls2txt.c ole.c cp.c ummap.c ieee754.c) -target_link_libraries(xls2txt m) +# On macOS, libm is part of libSystem and does not need explicit linking +if (NOT APPLE) + target_link_libraries(xls2txt m) +endif() + +install(TARGETS xls2txt DESTINATION bin) diff --git a/scripts/pre-commit b/scripts/pre-commit index ea2f1ce..5d8923a 100755 --- a/scripts/pre-commit +++ b/scripts/pre-commit @@ -6,17 +6,17 @@ if ! type "xls2txt" >/dev/null; then fi convert_all_xls() { - for file in $(git diff --name-status --staged | grep '^A' | grep -Po '[^\t]*$' | grep '.xls'); do + for file in $(git diff --name-status --staged | grep '^A' | grep -o '\S*$' | grep '.xls'); do echo "Converting new file $(basename "$file" .xls).txt" xls2txt -A -f "${file}" >"$1/$(basename "$file" .xls).txt" done - for file in $(git diff --name-status --staged | grep '^M' | grep -Po '[^\t]*$' | grep '.xls'); do + for file in $(git diff --name-status --staged | grep '^M' | grep -o '\S*$' | grep '.xls'); do echo "Converting modified file $(basename "$file" .xls).txt" xls2txt -A -f "${file}" >"$1/$(basename "$file" .xls).txt" done - for file in $(git diff --name-status --staged | grep '^D' | grep -Po '[^\t]*$' | grep '.xls'); do + for file in $(git diff --name-status --staged | grep '^D' | grep -o '\S*$' | grep '.xls'); do echo "Removing deleted file $(basename "$file" .xls).txt" rm -f "$1/$(basename "$file" .xls).txt" done diff --git a/ummap.c b/ummap.c index 3d5e621..eb48f63 100644 --- a/ummap.c +++ b/ummap.c @@ -15,7 +15,8 @@ #include #include #include -#include // ffs +#include +#include // ffs (macOS: strings.h; Linux: string.h) #include "ummap.h" #pragma clang diagnostic push @@ -42,9 +43,8 @@ static void um_sig(int n, siginfo_t *i, void *c) { unsigned long o; if (i->si_code == SEGV_ACCERR -#ifdef __OpenBSD__ // XXX others too? - //#if #system(bsd) - || i->si_code == SEGV_MAPERR +#if defined(__OpenBSD__) || defined(__APPLE__) + || i->si_code == SEGV_MAPERR #endif ) { list_t *l; @@ -58,10 +58,22 @@ static void um_sig(int n, siginfo_t *i, void *c) { return; found: - if (um->handler(um, (char *) um->addr + (o & -um_page_sz)) >= 0) + if (um->handler(um, (char *) um->addr + (o & -um_page_sz)) >= 0) { + /* Re-arm SIGSEGV and SIGBUS if defined */ sigaction(SIGSEGV, &um_sa, 0); +#ifdef SIGBUS + sigaction(SIGBUS, &um_sa, 0); +#endif + } } +#ifdef SIGBUS +/* SIGBUS may be raised instead of SIGSEGV when defined */ +static void um_bus(int n, siginfo_t *i, void *c) { + um_sig(n, i, c); +} +#endif + int um_access_page(void *p) { #if 0 return (int)mmap( @@ -86,6 +98,13 @@ int um_map(struct ummap *um) { return -1; um->addr = p; v = sigaction(SIGSEGV, &um_sa, 0); +#ifdef SIGBUS + if (v >= 0) { + struct sigaction bus_sa = um_sa; + bus_sa.sa_sigaction = um_bus; + sigaction(SIGBUS, &bus_sa, 0); + } +#endif if (v >= 0) list_add(&maps, &um->list); else munmap(p, (size_t) um->size); return v;