#define CURSR " > "
#define EMPTY " "
-int mtimeorder = 0; /* Set to 1 to sort by time modified */
-int sizeorder = 0; /* Set to 1 to sort by file size */
-int idletimeout = 0; /* Screensaver timeout in seconds, 0 to disable */
-int showhidden = 0; /* Set to 1 to show hidden files by default */
-int showdetail = 0; /* Set to show additional file info */
-char *idlecmd = "rain"; /* The screensaver program */
+static int mtimeorder = 0; /* Set to 1 to sort by time modified */
+static int sizeorder = 0; /* Set to 1 to sort by file size */
+static int idletimeout = 0; /* Screensaver timeout in seconds, 0 to disable */
+static int showhidden = 0; /* Set to 1 to show hidden files by default */
+static int showdetail = 0; /* Set to show additional file info */
+static char *idlecmd = "rain"; /* The screensaver program */
struct assoc assocs[] = {
//{ "\\.(avi|mp4|mkv|mp3|ogg|flac|mov)$", "mpv" },
struct key bindings[] = {
/* Quit */
- { 'q', SEL_QUIT },
+ { 'q', SEL_QUIT, "\0", "\0" },
/* Back */
- { KEY_BACKSPACE, SEL_BACK },
- { KEY_LEFT, SEL_BACK },
- { 'h', SEL_BACK },
- { CONTROL('H'), SEL_BACK },
+ { KEY_BACKSPACE, SEL_BACK, "\0", "\0" },
+ { KEY_LEFT, SEL_BACK, "\0", "\0" },
+ { 'h', SEL_BACK, "\0", "\0" },
+ { CONTROL('H'), SEL_BACK, "\0", "\0" },
/* Inside */
- { KEY_ENTER, SEL_GOIN },
- { '\r', SEL_GOIN },
- { KEY_RIGHT, SEL_GOIN },
- { 'l', SEL_GOIN },
+ { KEY_ENTER, SEL_GOIN, "\0", "\0" },
+ { '\r', SEL_GOIN, "\0", "\0" },
+ { KEY_RIGHT, SEL_GOIN, "\0", "\0" },
+ { 'l', SEL_GOIN, "\0", "\0" },
/* Filter */
- { '/', SEL_FLTR },
- { '&', SEL_FLTR },
+ { '/', SEL_FLTR, "\0", "\0" },
+ { '&', SEL_FLTR, "\0", "\0" },
/* Next */
- { 'j', SEL_NEXT },
- { KEY_DOWN, SEL_NEXT },
- { CONTROL('N'), SEL_NEXT },
+ { 'j', SEL_NEXT, "\0", "\0" },
+ { KEY_DOWN, SEL_NEXT, "\0", "\0" },
+ { CONTROL('N'), SEL_NEXT, "\0", "\0" },
/* Previous */
- { 'k', SEL_PREV },
- { KEY_UP, SEL_PREV },
- { CONTROL('P'), SEL_PREV },
+ { 'k', SEL_PREV, "\0", "\0" },
+ { KEY_UP, SEL_PREV, "\0", "\0" },
+ { CONTROL('P'), SEL_PREV, "\0", "\0" },
/* Page down */
- { KEY_NPAGE, SEL_PGDN },
- { CONTROL('D'), SEL_PGDN },
+ { KEY_NPAGE, SEL_PGDN, "\0", "\0" },
+ { CONTROL('D'), SEL_PGDN, "\0", "\0" },
/* Page up */
- { KEY_PPAGE, SEL_PGUP },
- { CONTROL('U'), SEL_PGUP },
+ { KEY_PPAGE, SEL_PGUP, "\0", "\0" },
+ { CONTROL('U'), SEL_PGUP, "\0", "\0" },
/* Home */
- { KEY_HOME, SEL_HOME },
- { CONTROL('A'), SEL_HOME },
- { '^', SEL_HOME },
+ { KEY_HOME, SEL_HOME, "\0", "\0" },
+ { CONTROL('A'), SEL_HOME, "\0", "\0" },
+ { '^', SEL_HOME, "\0", "\0" },
/* End */
- { KEY_END, SEL_END },
- { CONTROL('E'), SEL_END },
- { '$', SEL_END },
+ { KEY_END, SEL_END, "\0", "\0" },
+ { CONTROL('E'), SEL_END, "\0", "\0" },
+ { '$', SEL_END, "\0", "\0" },
/* Change dir */
- { 'c', SEL_CD },
- { '~', SEL_CDHOME },
+ { 'c', SEL_CD, "\0", "\0" },
+ { '~', SEL_CDHOME, "\0", "\0" },
/* Toggle hide .dot files */
- { '.', SEL_TOGGLEDOT },
+ { '.', SEL_TOGGLEDOT, "\0", "\0" },
/* Detailed listing */
- { 'd', SEL_DETAIL },
+ { 'd', SEL_DETAIL, "\0", "\0" },
/* Toggle sort by size */
- { 's', SEL_FSIZE },
+ { 's', SEL_FSIZE, "\0", "\0" },
/* Toggle sort by time */
- { 't', SEL_MTIME },
- { CONTROL('L'), SEL_REDRAW },
+ { 't', SEL_MTIME, "\0", "\0" },
+ { CONTROL('L'), SEL_REDRAW, "\0", "\0" },
/* Copy currently selected file path */
- { CONTROL('K'), SEL_COPY },
+ { CONTROL('K'), SEL_COPY, "\0", "\0" },
/* Run command */
- { 'z', SEL_RUN, "top" },
- { '!', SEL_RUN, "sh", "SHELL" },
+ { 'z', SEL_RUN, "top", "\0" },
+ { '!', SEL_RUN, "sh", "SHELL" },
/* Run command with argument */
- { 'e', SEL_RUNARG, "vi", "EDITOR" },
- { 'p', SEL_RUNARG, "less", "PAGER" },
+ { 'e', SEL_RUNARG, "vi", "EDITOR" },
+ { 'p', SEL_RUNARG, "less", "PAGER" },
};
} *pEntry;
/* Global context */
-struct entry *dents;
-int ndents, cur;
-int idle;
-char *opener = NULL;
-char *fallback_opener = NULL;
-char *copier = NULL;
-const char* size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
+static struct entry *dents;
+static int ndents, cur;
+static int idle;
+static char *opener = NULL;
+static char *fallback_opener = NULL;
+static char *copier = NULL;
+static const char* size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
/*
* Layout:
* '------
*/
-void printmsg(char *);
-void printwarn(void);
-void printerr(int, char *);
+static void printmsg(char *);
+static void printwarn(void);
+static void printerr(int, char *);
#undef dprintf
-int
+static int
dprintf(int fd, const char *fmt, ...)
{
char buf[BUFSIZ];
return r;
}
-void *
-xmalloc(size_t size)
-{
- void *p;
-
- p = malloc(size);
- if (p == NULL)
- printerr(1, "malloc");
- return p;
-}
-
-void *
+static void *
xrealloc(void *p, size_t size)
{
p = realloc(p, size);
return p;
}
-char *
-xstrdup(const char *s)
-{
- char *p;
-
- p = strdup(s);
- if (p == NULL)
- printerr(1, "strdup");
- return p;
-}
-
/* Some implementations of dirname(3) may modify `path' and some
* return a pointer inside `path'. */
-char *
+static char *
xdirname(const char *path)
{
static char out[PATH_MAX];
return out;
}
-void
+static void
spawn(char *file, char *arg, char *dir)
{
pid_t pid;
}
}
-char *
+static char *
xgetenv(char *name, char *fallback)
{
char *value;
return value && value[0] ? value : fallback;
}
-int
+static int
xstricmp(const char *s1, const char *s2)
{
while (*s2 != 0 && TOUPPER(*s1) == TOUPPER(*s2))
return (int) (TOUPPER(*s1) - TOUPPER(*s2));
}
-char *
+static char *
openwith(char *file)
{
regex_t regex;
char *bin = NULL;
- int i;
+ unsigned int i;
for (i = 0; i < LEN(assocs); i++) {
if (regcomp(®ex, assocs[i].regex,
return bin;
}
-int
+static int
setfilter(regex_t *regex, char *filter)
{
char errbuf[LINE_MAX];
return r;
}
-void
+static void
initfilter(int dot, char **ifilter)
{
*ifilter = dot ? "." : "^[^.]";
}
-int
+static int
visible(regex_t *regex, char *file)
{
return regexec(regex, file, 0, NULL, 0) == 0;
}
-int
+static int
entrycmp(const void *va, const void *vb)
{
if (mtimeorder)
return xstricmp(((pEntry)va)->name, ((pEntry)vb)->name);
}
-void
+static void
initcurses(void)
{
if (initscr() == NULL) {
timeout(1000); /* One second */
}
-void
+static void
exitcurses(void)
{
endwin(); /* Restore terminal */
}
/* Messages show up at the bottom */
-void
+static void
printmsg(char *msg)
{
move(LINES - 1, 0);
}
/* Display warning as a message */
-void
+static void
printwarn(void)
{
printmsg(strerror(errno));
}
/* Kill curses and display error before exiting */
-void
+static void
printerr(int ret, char *prefix)
{
exitcurses();
}
/* Clear the last line */
-void
+static void
clearprompt(void)
{
printmsg("");
}
/* Print prompt on the last line */
-void
+static void
printprompt(char *str)
{
clearprompt();
/* Returns SEL_* if key is bound and 0 otherwise.
* Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}) */
-int
+static int
nextsel(char **run, char **env)
{
- int c, i;
+ int c;
+ unsigned int i;
c = getch();
if (c == -1)
return 0;
}
-char *
+static char *
readln(void)
{
static char ln[LINE_MAX];
return ln[0] ? ln : NULL;
}
-int
+static int
canopendir(char *path)
{
DIR *dirp;
return 1;
}
-char *
+static char *
mkpath(char *dir, char *name, char *out, size_t n)
{
/* Handle absolute path */
return out;
}
-void
+static void
printent(struct entry *ent, int active)
{
if (S_ISDIR(ent->mode))
printw("%s%s\n", active ? CURSR : EMPTY, ent->name);
}
-void (*printptr)(struct entry *ent, int active) = &printent;
+static void (*printptr)(struct entry *ent, int active) = &printent;
-char*
+static char*
coolsize(off_t size)
{
static char size_buf[12]; /* Buffer to hold human readable size */
return size_buf;
}
-void
+static void
printent_long(struct entry *ent, int active)
{
static char buf[18];
- const static struct tm *p;
+ static const struct tm *p;
p = localtime(&ent->t);
strftime(buf, 18, "%b %d %H:%M %Y", p);
attroff(A_REVERSE);
}
-int
+static int
dentfill(char *path, struct entry **dents,
int (*filter)(regex_t *, char *), regex_t *re)
{
return n;
}
-void
+static void
dentfree(struct entry *dents)
{
free(dents);
}
/* Return the position of the matching entry or 0 otherwise */
-int
+static int
dentfind(struct entry *dents, int n, char *cwd, char *path)
{
char tmp[PATH_MAX];
return 0;
}
-int
+static int
populate(char *path, char *oldpath, char *fltr)
{
regex_t re;
return 0;
}
-void
+static void
redraw(char *path)
{
static char cwd[PATH_MAX];
}
}
-void
+static void
browse(char *ipath, char *ifilter)
{
static char path[PATH_MAX], oldpath[PATH_MAX], newpath[PATH_MAX];
}
}
-void
+static void
usage(void)
{
fprintf(stderr, "usage: nnn [-d] [dir]\n");