#define CWD "cwd: "
#define CURSR " > "
#define EMPTY " "
+#define CONTROL(c) ((c) ^ 0x40)
-static int filtermode; /* Set to 1 to enter filter mode */
-static int mtimeorder; /* Set to 1 to sort by time modified */
-static int sizeorder; /* Set to 1 to sort by file size */
-static int bsizeorder; /* Set to 1 to sort by blocks used (disk usage) */
-static int idletimeout; /* Idle timeout in seconds, 0 to disable */
-static int showhidden; /* Set to 1 to show hidden files by default */
-static int showdetail = 1; /* Set to 0 to show fewer file info */
+/* Supported actions */
+enum action {
+ SEL_QUIT = 1,
+ SEL_CDQUIT,
+ SEL_BACK,
+ SEL_GOIN,
+ SEL_FLTR,
+ SEL_MFLTR,
+ SEL_SEARCH,
+ SEL_NEXT,
+ SEL_PREV,
+ SEL_PGDN,
+ SEL_PGUP,
+ SEL_HOME,
+ SEL_END,
+ SEL_CD,
+ SEL_CDHOME,
+ SEL_CDBEGIN,
+ SEL_CDLAST,
+ SEL_CDBM,
+ SEL_TOGGLEDOT,
+ SEL_DETAIL,
+ SEL_STATS,
+ SEL_MEDIA,
+ SEL_FMEDIA,
+ SEL_DFB,
+ SEL_FSIZE,
+ SEL_BSIZE,
+ SEL_MTIME,
+ SEL_REDRAW,
+ SEL_COPY,
+ SEL_HELP,
+ SEL_RUN,
+ SEL_RUNARG,
+};
+
+/* Associate a pressed key to an action */
+struct key {
+ int sym; /* Key pressed */
+ enum action act; /* Action */
+ char *run; /* Program to run */
+ char *env; /* Environment variable to run */
+};
+
+/* Extension pattern and mime combination */
+struct assoc {
+ char *regex; /* Regex to match on filename */
+ char *mime; /* File type */
+};
static struct assoc assocs[] = {
{ "\\.(c|cpp|h|log|md|py|sh|txt)$", "text" },
#endif
#include <ftw.h>
+#include "config.h"
+
#ifdef DEBUGMODE
static int DEBUG_FD;
#define DPRINTF_U(x)
#define DPRINTF_S(x)
#define DPRINTF_P(x)
-#endif /* DEBUG */
+#endif /* DEBUGMODE */
+/* Macro definitions */
#define VERSION "v1.1"
#define LEN(x) (sizeof(x) / sizeof(*(x)))
#undef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define ISODD(x) ((x) & 1)
-#define CONTROL(c) ((c) ^ 0x40)
#define TOUPPER(ch) \
(((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
#define MAX_CMD_LEN 5120
#define FILTER '/'
#define MAX_BM 10
-struct assoc {
- char *regex; /* Regex to match on filename */
- char *mime; /* File type */
-};
-
-/* Supported actions */
-enum action {
- SEL_QUIT = 1,
- SEL_CDQUIT,
- SEL_BACK,
- SEL_GOIN,
- SEL_FLTR,
- SEL_MFLTR,
- SEL_SEARCH,
- SEL_NEXT,
- SEL_PREV,
- SEL_PGDN,
- SEL_PGUP,
- SEL_HOME,
- SEL_END,
- SEL_CD,
- SEL_CDHOME,
- SEL_CDBEGIN,
- SEL_CDLAST,
- SEL_CDBM,
- SEL_TOGGLEDOT,
- SEL_DETAIL,
- SEL_STATS,
- SEL_MEDIA,
- SEL_FMEDIA,
- SEL_DFB,
- SEL_FSIZE,
- SEL_BSIZE,
- SEL_MTIME,
- SEL_REDRAW,
- SEL_COPY,
- SEL_HELP,
- SEL_RUN,
- SEL_RUNARG,
-};
-
-struct key {
- int sym; /* Key pressed */
- enum action act; /* Action */
- char *run; /* Program to run */
- char *env; /* Environment variable to run */
-};
-
-#include "config.h"
-
+/* Directory entry */
typedef struct entry {
char name[NAME_MAX];
mode_t mode;
off_t bsize;
} *pEntry;
+/* Bookmark */
typedef struct {
char *key;
char *loc;
extern int wget_wch(WINDOW *win, wint_t *wch);
/* Global context */
+static int filtermode; /* Set to 1 to enter filter mode */
+static int mtimeorder; /* Set to 1 to sort by time modified */
+static int sizeorder; /* Set to 1 to sort by file size */
+static int bsizeorder; /* Set to 1 to sort by blocks used (disk usage) */
+static int idletimeout; /* Idle timeout in seconds, 0 to disable */
+static int showhidden; /* Set to 1 to show hidden files by default */
+static int showdetail = 1; /* Set to 0 to show fewer file info */
+
static struct entry *dents;
static int ndents, cur, total_dents;
static int idle;
static char *desktop_manager;
static off_t blk_size;
static size_t fs_free;
-static int open_max;
+static unsigned int open_max;
static bm bookmark[MAX_BM];
static const double div_2_pow_10 = 1.0 / 1024.0;
-
+/* Utilities to open files, run actions */
static char *utils[] = {
#ifdef __APPLE__
"/usr/bin/open",
* '------
*/
+/* Forward declarations */
static void printmsg(char *);
static void printwarn(void);
static void printerr(int, char *);
static void redraw(char *path);
+/* Functions */
+
+/* Increase the limit on open file descriptors, if possible */
static rlim_t
max_openfds()
{
static void *
xmemrchr(const void *s, unsigned char ch, size_t n)
{
- static unsigned char *p;
-
if (!s || !n)
return NULL;
+ static unsigned char *p;
+
p = (unsigned char *)s + n - 1;
while (n) {
}
/*
- * Return number of dots of all chars in a string are dots, else 0
+ * Return number of dots if all chars in a string are dots, else 0
*/
static int
all_dots(const char *ptr)
return count;
}
+/* Initialize curses mode */
static void
initcurses(void)
{
timeout(1000); /* One second */
}
+/* Exit curses mode */
static void
exitcurses(void)
{
}
}
+/* Get program name from env var, else return fallback program */
static char *
xgetenv(char *name, char *fallback)
{