Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 3 additions & 3 deletions scripts/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 24 additions & 5 deletions ummap.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#include <sys/mman.h>
#include <unistd.h>
#include <signal.h>
#include <string.h> // ffs
#include <string.h>
#include <strings.h> // ffs (macOS: strings.h; Linux: string.h)
#include "ummap.h"

#pragma clang diagnostic push
Expand All @@ -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;
Expand All @@ -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(
Expand All @@ -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;
Expand Down