aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2021-07-06 11:43:37 -0700
committerBruce Hill <bruce@bruce-hill.com>2021-07-06 11:43:37 -0700
commit9073236736f59291da586a9af64970a647e574ce (patch)
tree6e58be7393c79981fe339ea3068630f123156a6c
parent641452dc964c6807aef17ca47e02da798152dc04 (diff)
Cross-platform compatibility changes
-rw-r--r--Makefile36
-rw-r--r--bb.c45
2 files changed, 25 insertions, 56 deletions
diff --git a/Makefile b/Makefile
index abf059f..d6ca58b 100644
--- a/Makefile
+++ b/Makefile
@@ -3,22 +3,24 @@ PREFIX=
CC=cc
G=
O=-O2
-CFLAGS=-std=c99 -Werror -D_XOPEN_SOURCE=700 -D_GNU_SOURCE -D_POSIX_C_SOURCE=200809L
-CWARN=-Wall -Wpedantic -Wextra \
- -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
- -Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
- -Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \
- -Wduplicated-cond -Wexpansion-to-defined -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral \
- -Wformat-security -Wformat-signedness -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
- -Wlogical-op -Wlong-long -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
- -Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned -Wpointer-arith \
- -Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \
- -Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wswitch-default -Wswitch-enum \
- -Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \
- -Wunused-const-variable -Wunused-local-typedefs -Wunused-macros -Wvariadic-macros -Wvector-operation-performance \
- -Wvla -Wwrite-strings
+CFLAGS=-std=c99 -Werror -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L
+CWARN=-Wall -Wextra
+# -Wpedantic -Wsign-conversion -Wtype-limits -Wunused-result \
+# -Wsign-conversion -Wtype-limits -Wunused-result -Wnull-dereference \
+# -Waggregate-return -Walloc-zero -Walloca -Warith-conversion -Wcast-align -Wcast-align=strict \
+# -Wdangling-else -Wdate-time -Wdisabled-optimization -Wdouble-promotion -Wduplicated-branches \
+# -Wduplicated-cond -Wexpansion-to-defined -Wfloat-conversion -Wfloat-equal -Wformat-nonliteral \
+# -Wformat-security -Wformat-signedness -Wframe-address -Winline -Winvalid-pch -Wjump-misses-init \
+# -Wlogical-op -Wlong-long -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-noreturn \
+# -Wnull-dereference -Woverlength-strings -Wpacked -Wpacked-not-aligned -Wpointer-arith \
+# -Wredundant-decls -Wshadow -Wshadow=compatible-local -Wshadow=global -Wshadow=local \
+# -Wsign-conversion -Wstack-protector -Wsuggest-attribute=const -Wswitch-default -Wswitch-enum \
+# -Wsync-nand -Wtrampolines -Wundef -Wunused -Wunused-but-set-variable \
+# -Wunused-const-variable -Wunused-local-typedefs -Wunused-macros -Wvariadic-macros -Wvector-operation-performance \
+# -Wvla -Wwrite-strings
#CFLAGS += -fsanitize=address -fno-omit-frame-pointer
CFLAGS += '-DBB_NAME="$(NAME)"'
+OSFLAGS != case $$(uname -s) in *BSD|Darwin) echo '-D_BSD_SOURCE';; Linux) echo '-D_GNU_SOURCE';; *) echo '-D_DEFAULT_SOURCE';; esac
CFILES=draw.c terminal.c
OBJFILES=$(CFILES:.c=.o)
@@ -29,10 +31,10 @@ clean:
rm -f $(NAME) $(OBJFILES)
%.o: %.c %.h types.h utils.h
- $(CC) -c $(CFLAGS) $(CWARN) $(G) $(O) -o $@ $<
+ $(CC) -c $(CFLAGS) $(OSFLAGS) $(CWARN) $(G) $(O) -o $@ $<
$(NAME): $(OBJFILES) bb.c
- $(CC) $(CFLAGS) $(CWARN) $(G) $(O) -o $@ $(OBJFILES) bb.c
+ $(CC) $(CFLAGS) $(OSFLAGS) $(CWARN) $(G) $(O) -o $@ $(OBJFILES) bb.c
install: $(NAME)
@prefix="$(PREFIX)"; \
@@ -42,7 +44,7 @@ install: $(NAME)
fi; \
[ ! "$$prefix" ] && prefix="/usr/local"; \
[ ! "$$sysconfdir" ] && sysconfdir=/etc; \
- mkdir -pv -m 755 "$$prefix/man/man1" "$$prefix/bin" "$$sysconfdir/$(NAME)" \
+ mkdir -p -m 755 "$$prefix/man/man1" "$$prefix/bin" "$$sysconfdir/$(NAME)" \
&& cp -rv scripts/* "$$sysconfdir/$(NAME)/" \
&& cp -v bb.1 "$$prefix/man/man1/$(NAME).1" \
&& cp -v bbcmd.1 "$$prefix/man/man1/bbcmd.1" \
diff --git a/bb.c b/bb.c
index 2772933..e35f612 100644
--- a/bb.c
+++ b/bb.c
@@ -40,11 +40,7 @@ void bb_browse(bb_t *bb, const char *initial_path);
static void check_cmdfile(bb_t *bb);
static void cleanup(void);
static void cleanup_and_raise(int sig);
-#ifdef __APPLE__
-static int compare_files(void *v, const void *v1, const void *v2);
-#else
-static int compare_files(const void *v1, const void *v2, void *v);
-#endif
+static int compare_files(const void *v1, const void *v2);
__attribute__((format(printf,2,3)))
void flash_warn(bb_t *bb, const char *fmt, ...);
static void handle_next_key_binding(bb_t *bb);
@@ -77,27 +73,6 @@ static int wait_for_process(proc_t **proc);
static const char *T_ENTER_BBMODE = T_OFF(T_SHOW_CURSOR ";" T_WRAP) T_ON(T_ALT_SCREEN ";" T_MOUSE_XY ";" T_MOUSE_CELL ";" T_MOUSE_SGR);
static const char *T_LEAVE_BBMODE = T_OFF(T_MOUSE_XY ";" T_MOUSE_CELL ";" T_MOUSE_SGR ";" T_ALT_SCREEN) T_ON(T_SHOW_CURSOR ";" T_WRAP);
static const char *T_LEAVE_BBMODE_PARTIAL = T_OFF(T_MOUSE_XY ";" T_MOUSE_CELL ";" T_MOUSE_SGR) T_ON(T_WRAP);
-static const struct termios default_termios = {
- .c_iflag = ICRNL,
- .c_oflag = OPOST | ONLCR | NL0 | CR0 | TAB0 | BS0 | VT0 | FF0,
- .c_lflag = ISIG | ICANON | IEXTEN | ECHO | ECHOE | ECHOK | ECHOCTL | ECHOKE,
- .c_cflag = CS8 | CREAD,
- .c_cc[VINTR] = '',
- .c_cc[VQUIT] = '',
- .c_cc[VERASE] = 127,
- .c_cc[VKILL] = '',
- .c_cc[VEOF] = '',
- .c_cc[VSTART] = '',
- .c_cc[VSTOP] = '',
- .c_cc[VSUSP] = '',
- .c_cc[VREPRINT] = '',
- .c_cc[VWERASE] = '',
- .c_cc[VLNEXT] = '',
- .c_cc[VDISCARD] = '',
- .c_cc[VMIN] = 1,
- .c_cc[VTIME] = 0,
-};
-
static const char *description_str = BB_NAME" - an itty bitty console TUI file browser\n";
static const char *usage_str = "Usage: "BB_NAME" (-h/--help | -v/--version | -s | -d | -0 | +command)* [[--] directory]\n";
@@ -190,15 +165,11 @@ static void cleanup(void)
// Used for sorting, this function compares files according to the sorting-related options,
// like bb->sort
//
-#ifdef __APPLE__
-static int compare_files(void *v, const void *v1, const void *v2)
-#else
-static int compare_files(const void *v1, const void *v2, void *v)
-#endif
+static int compare_files(const void *v1, const void *v2)
{
#define COMPARE(a, b) if ((a) != (b)) { return sign*((a) < (b) ? 1 : -1); }
#define COMPARE_TIME(t1, t2) COMPARE((t1).tv_sec, (t2).tv_sec) COMPARE((t1).tv_nsec, (t2).tv_nsec)
- bb_t *bb = (bb_t*)v;
+ bb_t *bb = current_bb;
const entry_t *e1 = *((const entry_t**)v1), *e2 = *((const entry_t**)v2);
int sign = 1;
@@ -320,7 +291,7 @@ static void handle_next_key_binding(bb_t *bb)
} else {
move_cursor(tty_out, 0, winsize.ws_row-1);
fputs("\033[K", tty_out);
- restore_term(&default_termios);
+ restore_term(&orig_termios);
run_script(bb, binding->script);
init_term();
set_title(bb);
@@ -712,7 +683,7 @@ static void run_bbcmd(bb_t *bb, const char *cmd)
if (!child) return;
move_cursor(tty_out, 0, winsize.ws_row-1);
fputs("\033[K", tty_out);
- restore_term(&default_termios);
+ restore_term(&orig_termios);
signal(SIGTTOU, SIG_IGN);
if (tcsetpgrp(fileno(tty_out), child->pid))
clean_err("Couldn't set pgrp");
@@ -1022,11 +993,7 @@ static int try_free_entry(entry_t *e)
//
static void sort_files(bb_t *bb)
{
-#ifdef __APPLE__
- qsort_r(bb->files, (size_t)bb->nfiles, sizeof(entry_t*), bb, compare_files);
-#else
- qsort_r(bb->files, (size_t)bb->nfiles, sizeof(entry_t*), compare_files, bb);
-#endif
+ qsort(bb->files, (size_t)bb->nfiles, sizeof(entry_t*), compare_files);
for (int i = 0; i < bb->nfiles; i++)
bb->files[i]->index = i;
bb->dirty = 1;