mirror of
https://github.com/jarun/nnn.git
synced 2025-03-18 20:39:45 +00:00
Re-structure header
This commit is contained in:
parent
370ed32a28
commit
2b248e4e1a
2 changed files with 76 additions and 64 deletions
57
config.def.h
57
config.def.h
|
@ -2,14 +2,57 @@
|
||||||
#define CWD "cwd: "
|
#define CWD "cwd: "
|
||||||
#define CURSR " > "
|
#define CURSR " > "
|
||||||
#define EMPTY " "
|
#define EMPTY " "
|
||||||
|
#define CONTROL(c) ((c) ^ 0x40)
|
||||||
|
|
||||||
static int filtermode; /* Set to 1 to enter filter mode */
|
/* Supported actions */
|
||||||
static int mtimeorder; /* Set to 1 to sort by time modified */
|
enum action {
|
||||||
static int sizeorder; /* Set to 1 to sort by file size */
|
SEL_QUIT = 1,
|
||||||
static int bsizeorder; /* Set to 1 to sort by blocks used (disk usage) */
|
SEL_CDQUIT,
|
||||||
static int idletimeout; /* Idle timeout in seconds, 0 to disable */
|
SEL_BACK,
|
||||||
static int showhidden; /* Set to 1 to show hidden files by default */
|
SEL_GOIN,
|
||||||
static int showdetail = 1; /* Set to 0 to show fewer file info */
|
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[] = {
|
static struct assoc assocs[] = {
|
||||||
{ "\\.(c|cpp|h|log|md|py|sh|txt)$", "text" },
|
{ "\\.(c|cpp|h|log|md|py|sh|txt)$", "text" },
|
||||||
|
|
83
nnn.c
83
nnn.c
|
@ -39,6 +39,8 @@
|
||||||
#endif
|
#endif
|
||||||
#include <ftw.h>
|
#include <ftw.h>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#ifdef DEBUGMODE
|
#ifdef DEBUGMODE
|
||||||
static int DEBUG_FD;
|
static int DEBUG_FD;
|
||||||
|
|
||||||
|
@ -89,14 +91,14 @@ static void disabledbg()
|
||||||
#define DPRINTF_U(x)
|
#define DPRINTF_U(x)
|
||||||
#define DPRINTF_S(x)
|
#define DPRINTF_S(x)
|
||||||
#define DPRINTF_P(x)
|
#define DPRINTF_P(x)
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUGMODE */
|
||||||
|
|
||||||
|
/* Macro definitions */
|
||||||
#define VERSION "v1.1"
|
#define VERSION "v1.1"
|
||||||
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
#define LEN(x) (sizeof(x) / sizeof(*(x)))
|
||||||
#undef MIN
|
#undef MIN
|
||||||
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
#define MIN(x, y) ((x) < (y) ? (x) : (y))
|
||||||
#define ISODD(x) ((x) & 1)
|
#define ISODD(x) ((x) & 1)
|
||||||
#define CONTROL(c) ((c) ^ 0x40)
|
|
||||||
#define TOUPPER(ch) \
|
#define TOUPPER(ch) \
|
||||||
(((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
|
(((ch) >= 'a' && (ch) <= 'z') ? ((ch) - 'a' + 'A') : (ch))
|
||||||
#define MAX_CMD_LEN 5120
|
#define MAX_CMD_LEN 5120
|
||||||
|
@ -104,56 +106,7 @@ static void disabledbg()
|
||||||
#define FILTER '/'
|
#define FILTER '/'
|
||||||
#define MAX_BM 10
|
#define MAX_BM 10
|
||||||
|
|
||||||
struct assoc {
|
/* Directory entry */
|
||||||
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"
|
|
||||||
|
|
||||||
typedef struct entry {
|
typedef struct entry {
|
||||||
char name[NAME_MAX];
|
char name[NAME_MAX];
|
||||||
mode_t mode;
|
mode_t mode;
|
||||||
|
@ -162,6 +115,7 @@ typedef struct entry {
|
||||||
off_t bsize;
|
off_t bsize;
|
||||||
} *pEntry;
|
} *pEntry;
|
||||||
|
|
||||||
|
/* Bookmark */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char *key;
|
char *key;
|
||||||
char *loc;
|
char *loc;
|
||||||
|
@ -179,6 +133,14 @@ extern void add_history(const char *string);
|
||||||
extern int wget_wch(WINDOW *win, wint_t *wch);
|
extern int wget_wch(WINDOW *win, wint_t *wch);
|
||||||
|
|
||||||
/* Global context */
|
/* 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 struct entry *dents;
|
||||||
static int ndents, cur, total_dents;
|
static int ndents, cur, total_dents;
|
||||||
static int idle;
|
static int idle;
|
||||||
|
@ -188,11 +150,11 @@ static char *editor;
|
||||||
static char *desktop_manager;
|
static char *desktop_manager;
|
||||||
static off_t blk_size;
|
static off_t blk_size;
|
||||||
static size_t fs_free;
|
static size_t fs_free;
|
||||||
static int open_max;
|
static unsigned int open_max;
|
||||||
static bm bookmark[MAX_BM];
|
static bm bookmark[MAX_BM];
|
||||||
static const double div_2_pow_10 = 1.0 / 1024.0;
|
static const double div_2_pow_10 = 1.0 / 1024.0;
|
||||||
|
|
||||||
|
/* Utilities to open files, run actions */
|
||||||
static char *utils[] = {
|
static char *utils[] = {
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
"/usr/bin/open",
|
"/usr/bin/open",
|
||||||
|
@ -222,11 +184,15 @@ static char g_buf[MAX_CMD_LEN];
|
||||||
* '------
|
* '------
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/* Forward declarations */
|
||||||
static void printmsg(char *);
|
static void printmsg(char *);
|
||||||
static void printwarn(void);
|
static void printwarn(void);
|
||||||
static void printerr(int, char *);
|
static void printerr(int, char *);
|
||||||
static void redraw(char *path);
|
static void redraw(char *path);
|
||||||
|
|
||||||
|
/* Functions */
|
||||||
|
|
||||||
|
/* Increase the limit on open file descriptors, if possible */
|
||||||
static rlim_t
|
static rlim_t
|
||||||
max_openfds()
|
max_openfds()
|
||||||
{
|
{
|
||||||
|
@ -266,11 +232,11 @@ xstrlcpy(char *dest, const char *src, size_t n)
|
||||||
static void *
|
static void *
|
||||||
xmemrchr(const void *s, unsigned char ch, size_t n)
|
xmemrchr(const void *s, unsigned char ch, size_t n)
|
||||||
{
|
{
|
||||||
static unsigned char *p;
|
|
||||||
|
|
||||||
if (!s || !n)
|
if (!s || !n)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
static unsigned char *p;
|
||||||
|
|
||||||
p = (unsigned char *)s + n - 1;
|
p = (unsigned char *)s + n - 1;
|
||||||
|
|
||||||
while (n) {
|
while (n) {
|
||||||
|
@ -351,7 +317,7 @@ xdirname(const char *path)
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 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
|
static int
|
||||||
all_dots(const char *ptr)
|
all_dots(const char *ptr)
|
||||||
|
@ -370,6 +336,7 @@ all_dots(const char *ptr)
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Initialize curses mode */
|
||||||
static void
|
static void
|
||||||
initcurses(void)
|
initcurses(void)
|
||||||
{
|
{
|
||||||
|
@ -393,6 +360,7 @@ initcurses(void)
|
||||||
timeout(1000); /* One second */
|
timeout(1000); /* One second */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Exit curses mode */
|
||||||
static void
|
static void
|
||||||
exitcurses(void)
|
exitcurses(void)
|
||||||
{
|
{
|
||||||
|
@ -452,6 +420,7 @@ spawn(char *file, char *arg1, char *arg2, char *dir, unsigned char flag)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Get program name from env var, else return fallback program */
|
||||||
static char *
|
static char *
|
||||||
xgetenv(char *name, char *fallback)
|
xgetenv(char *name, char *fallback)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue