aboutsummaryrefslogtreecommitdiff
path: root/bb.h
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2020-12-30 22:47:49 -0800
committerBruce Hill <bruce@bruce-hill.com>2020-12-30 22:47:49 -0800
commit5371a49ce0eda4054cc4dcb73abea351482711c2 (patch)
tree7e0142fdd1ce742f49c1dcda51157941834faf7f /bb.h
parent18681fa449dc10e408128dbe50c482bfff0ead05 (diff)
Refactoring into multiple files better
Diffstat (limited to 'bb.h')
-rw-r--r--bb.h130
1 files changed, 5 insertions, 125 deletions
diff --git a/bb.h b/bb.h
index 946f323..e69d45e 100644
--- a/bb.h
+++ b/bb.h
@@ -5,21 +5,12 @@
*
* This file contains definitions and customization for `bb`.
*/
-#include <fcntl.h>
-#include <glob.h>
-#include <limits.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <termios.h>
-#include <unistd.h>
+#ifndef FILE_BB__H
+#define FILE_BB__H
#include "bterm.h"
+#include "entry.h"
+#include "columns.h"
// Macros:
#define BB_VERSION "0.27.0"
@@ -35,12 +26,9 @@
#define MAX_BINDINGS 1024
// Configurable options:
-#define BB_TIME_FMT " %T %D "
#define SCROLLOFF MIN(5, (winsize.ws_row-4)/2)
#define SORT_INDICATOR "↓"
#define RSORT_INDICATOR "↑"
-#define SELECTED_INDICATOR " \033[31;7m \033[0m"
-#define NOT_SELECTED_INDICATOR " "
// Colors (using ANSI escape sequences):
#define TITLE_COLOR "\033[37;1m"
#define NORMAL_COLOR "\033[37m"
@@ -53,9 +41,6 @@
#define MAX(a,b) ((a) < (b) ? (b) : (a))
#define MIN(a,b) ((a) > (b) ? (b) : (a))
-#define IS_SELECTED(p) (((p)->selected.atme) != NULL)
-#define IS_VIEWED(p) ((p)->index >= 0)
-#define IS_LOADED(p) ((p)->hash.atme != NULL)
#define LOWERCASE(c) ('A' <= (c) && (c) <= 'Z' ? ((c) + 'a' - 'A') : (c))
#define E_ISDIR(e) (S_ISDIR(S_ISLNK((e)->info.st_mode) ? (e)->linkedmode : (e)->info.st_mode))
#define ONSCREEN (winsize.ws_row - 3)
@@ -111,41 +96,6 @@ typedef struct {
char *description;
} binding_t;
-typedef enum {
- COL_NONE = 0,
- COL_NAME = 'n',
- COL_SIZE = 's',
- COL_PERM = 'p',
- COL_MTIME = 'm',
- COL_CTIME = 'c',
- COL_ATIME = 'a',
- COL_RANDOM = 'r',
- COL_SELECTED = '*',
-} column_e;
-
-/* entry_t uses intrusive linked lists. This means entries can only belong to
- * one list at a time, in this case the list of selected entries. 'atme' is an
- * indirect pointer to either the 'next' field of the previous list member, or
- * the variable that points to the first list member. In other words,
- * item->next->atme == &item->next and firstitem->atme == &firstitem.
- */
-typedef struct entry_s {
- struct {
- struct entry_s *next, **atme;
- } selected, hash;
- char *name, *linkname;
- struct stat info;
- mode_t linkedmode;
- int no_esc : 1;
- int link_no_esc : 1;
- int shufflepos;
- int index;
- char fullname[1];
- // ------- fullname must be last! --------------
- // When entries are allocated, extra space on the end is reserved to fill
- // in fullname.
-} entry_t;
-
typedef struct bb_s {
entry_t *hash[HASH_SIZE];
entry_t **files;
@@ -170,81 +120,11 @@ typedef struct proc_s {
} running;
} proc_t;
-static binding_t bindings[MAX_BINDINGS];
-
-#include "columns.h"
-
-// Functions
-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);
-static const char* color_of(mode_t mode);
-#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 fputs_escaped(FILE *f, const char *str, const char *color);
-static void handle_next_key_binding(bb_t *bb);
-static void init_term(void);
-static int is_simple_bbcmd(const char *s);
-static entry_t* load_entry(bb_t *bb, const char *path);
-static inline int matches_cmd(const char *str, const char *cmd);
-static void* memcheck(void *p);
-static char* normalize_path(const char *root, const char *path, char *pbuf);
-static int populate_files(bb_t *bb, const char *path);
-static void print_bindings(int fd);
-static void run_bbcmd(bb_t *bb, const char *cmd);
-static void render(bb_t *bb);
-static void restore_term(const struct termios *term);
-static int run_script(bb_t *bb, const char *cmd);
-static void set_columns(bb_t *bb, const char *cols);
-static void set_cursor(bb_t *bb, int i);
-static void set_globs(bb_t *bb, const char *globs);
-static void set_interleave(bb_t *bb, int interleave);
-static void set_selected(bb_t *bb, entry_t *e, int selected);
-static void set_scroll(bb_t *bb, int i);
-static void set_sort(bb_t *bb, const char *sort);
-static void set_title(bb_t *bb);
-static void sort_files(bb_t *bb);
-static char *trim(char *s);
-static int try_free_entry(entry_t *e);
-static void update_term_size(int sig);
-static int wait_for_process(proc_t **proc);
-
-// Constants
-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 - an itty bitty console TUI file browser\n";
-static const char *usage_str = "Usage: bb (-h/--help | -v/--version | -s | -d | -0 | +command)* [[--] directory]\n";
-
// Hack to get TinyCC (TCC) compilation to work:
// https://lists.nongnu.org/archive/html/tinycc-devel/2018-07/msg00000.html
#ifdef __TINYC__
void * __dso_handle __attribute((visibility("hidden"))) = &__dso_handle;
#endif
+#endif
// vim: ts=4 sw=0 et cino=L2,l1,(0,W4,m1