/* Forward declarations */
static void redraw(char *path);
-static char * get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager);
+static char *get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager);
+int (*nftw_fn) (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
/* Functions */
* CRC8 source:
* https://barrgroup.com/Embedded-Systems/How-To/CRC-Calculation-C-Code
*/
-static void
-crc8init()
+static void crc8init()
{
uchar remainder, bit;
uint dividend;
}
}
-static uchar
-crc8fast(uchar const message[], size_t n)
+static uchar crc8fast(uchar const message[], size_t n)
{
static uchar data, remainder;
static size_t byte;
}
/* Messages show up at the bottom */
-static void
-printmsg(const char *msg)
+static void printmsg(const char *msg)
{
mvprintw(LINES - 1, 0, "%s\n", msg);
}
/* Kill curses and display error before exiting */
-static void
-printerr(int linenum)
+static void printerr(int linenum)
{
exitcurses();
fprintf(stderr, "line %d: (%d) %s\n", linenum, errno, strerror(errno));
}
/* Print prompt on the last line */
-static void
-printprompt(char *str)
+static void printprompt(char *str)
{
clearprompt();
printw(str);
}
/* Increase the limit on open file descriptors, if possible */
-static rlim_t
-max_openfds()
+static rlim_t max_openfds()
{
struct rlimit rl;
rlim_t limit = getrlimit(RLIMIT_NOFILE, &rl);
* Ubuntu: http://manpages.ubuntu.com/manpages/xenial/man3/malloc.3.html
* OS X: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man3/malloc.3.html
*/
-static void *
-xrealloc(void *pcur, size_t len)
+static void *xrealloc(void *pcur, size_t len)
{
static void *pmem;
* Always null ('\0') terminates if both src and dest are valid pointers.
* Returns the number of bytes copied including terminating null byte.
*/
-static size_t
-xstrlcpy(char *dest, const char *src, size_t n)
+static size_t xstrlcpy(char *dest, const char *src, size_t n)
{
static ulong *s, *d;
static size_t len, blocks;
* And we are NOT expecting a '/' at the end.
* Ideally 0 < n <= strlen(s).
*/
-static void *
-xmemrchr(uchar *s, uchar ch, size_t n)
+static void *xmemrchr(uchar *s, uchar ch, size_t n)
{
static uchar *ptr;
*
* Modified from the glibc (GNU LGPL) version.
*/
-static char *
-xdirname(const char *path)
+static char *xdirname(const char *path)
{
static char * const buf = g_buf, *last_slash, *runp;
return buf;
}
-static char *
-xbasename(char *path)
+static char *xbasename(char *path)
{
static char *base;
}
/* Writes buflen char(s) from buf to a file */
-static void
-writecp(const char *buf, const size_t buflen)
+static void writecp(const char *buf, const size_t buflen)
{
if (!g_cppath[0])
return;
printwarn();
}
-static bool
-appendfpath(const char *path, const size_t len)
+static bool appendfpath(const char *path, const size_t len)
{
if ((copybufpos >= copybuflen) || ((len + 3) > (copybuflen - copybufpos))) {
copybuflen += PATH_MAX;
return TRUE;
}
-static bool
-showcplist()
+static bool showcplist()
{
ssize_t len;
/*
* Return number of dots if all chars in a string are dots, else 0
*/
-static int
-all_dots(const char *path)
+static int all_dots(const char *path)
{
int count = 0;
}
/* Initialize curses mode */
-static void
-initcurses(void)
+static void initcurses(void)
{
if (initscr() == NULL) {
char *term = getenv("TERM");
* Spawns a child process. Behaviour can be controlled using flag.
* Limited to 2 arguments to a program, flag works on bit set.
*/
-static void
-spawn(const char *file, const char *arg1, const char *arg2, const char *dir, uchar flag)
+static void spawn(const char *file, const char *arg1, const char *arg2, const char *dir, uchar flag)
{
static char *shlvl;
static pid_t pid;
}
/* Get program name from env var, else return fallback program */
-static char *
-xgetenv(const char *name, char *fallback)
+static char *xgetenv(const char *name, char *fallback)
{
static char *value;
}
/* Check if a dir exists, IS a dir and is readable */
-static bool
-xdiraccess(const char *path)
+static bool xdiraccess(const char *path)
{
static DIR *dirp;
*
* If the absolute numeric values are same, we fallback to alphasort.
*/
-static int
-xstricmp(const char * const s1, const char * const s2)
+static int xstricmp(const char * const s1, const char * const s2)
{
static const char *c1, *c2;
}
/* Return the integer value of a char representing HEX */
-static char
-xchartohex(char c)
+static char xchartohex(char c)
{
if (c >= '0' && c <= '9')
return c - '0';
return c;
}
-static char *
-getmime(const char *file)
+static char *getmime(const char *file)
{
static regex_t regex;
static uint i;
return NULL;
}
-static int
-setfilter(regex_t *regex, char *filter)
+static int setfilter(regex_t *regex, char *filter)
{
static size_t len;
static int r;
return r;
}
-static void
-initfilter(int dot, char **ifilter)
+static void initfilter(int dot, char **ifilter)
{
*ifilter = dot ? "." : "^[^.]";
}
-static int
-visible(regex_t *regex, char *file)
+static int visible(regex_t *regex, char *file)
{
return regexec(regex, file, 0, NULL, 0) == 0;
}
-static int
-entrycmp(const void *va, const void *vb)
+static int entrycmp(const void *va, const void *vb)
{
static pEntry pa, pb;
* Also modifies the run and env pointers (used on SEL_{RUN,RUNARG}).
* The next keyboard input can be simulated by presel.
*/
-static int
-nextsel(char **run, char **env, int *presel)
+static int nextsel(char **run, char **env, int *presel)
{
static int c;
static uint i;
/*
* Move non-matching entries to the end
*/
-static int
-fill(struct entry **dents, int (*filter)(regex_t *, char *), regex_t *re)
+static int fill(struct entry **dents, int (*filter)(regex_t *, char *), regex_t *re)
{
static int count;
static struct entry _dent, *pdent1, *pdent2;
return ndents;
}
-static int
-matches(char *fltr)
+static int matches(char *fltr)
{
static regex_t re;
return 0;
}
-static int
-filterentries(char *path)
+static int filterentries(char *path)
{
static char ln[REGEX_MAX] __attribute__ ((aligned));
static wchar_t wln[REGEX_MAX] __attribute__ ((aligned));
}
/* Show a prompt with input string and return the changes */
-static char *
-xreadline(char *fname, char *prompt)
+static char *xreadline(char *fname, char *prompt)
{
int old_curs = curs_set(1);
size_t len, pos;
* Updates out with "dir/name or "/name"
* Returns the number of bytes copied including the terminating NULL byte
*/
-static size_t
-mkpath(char *dir, char *name, char *out, size_t n)
+static size_t mkpath(char *dir, char *name, char *out, size_t n)
{
static size_t len;
return (xstrlcpy(out + len, name, n - len) + len);
}
-static void
-parsebmstr()
+static void parsebmstr()
{
int i = 0;
char *bms = getenv("NNN_BMS");
* NULL is returned in case of no match, path resolution failure etc.
* buf would be modified, so check return value before access
*/
-static char *
-get_bm_loc(char *key, char *buf)
+static char *get_bm_loc(char *key, char *buf)
{
int r;
return NULL;
}
-static void
-resetdircolor(mode_t mode)
+static void resetdircolor(mode_t mode)
{
if (cfg.dircolor && !S_ISDIR(mode)) {
attroff(COLOR_PAIR(1) | A_BOLD);
* it doesn't touch str anymore). Only after that it starts modifying
* g_buf. This is a phased operation.
*/
-static char *
-unescape(const char *str, uint maxcols)
+static char *unescape(const char *str, uint maxcols)
{
static wchar_t wbuf[PATH_MAX] __attribute__ ((aligned));
static wchar_t *buf;
return g_buf;
}
-static char *
-coolsize(off_t size)
+static char *coolsize(off_t size)
{
static const char * const U = "BKMGTPEZY";
static char size_buf[12]; /* Buffer to hold human readable size */
return size_buf;
}
-static char *
-get_file_sym(mode_t mode)
+static char *get_file_sym(mode_t mode)
{
static char ind[2] = "\0\0";
return ind;
}
-static void
-printent(struct entry *ent, int sel, uint namecols)
+static void printent(struct entry *ent, int sel, uint namecols)
{
static char *pname;
printw("%s%s%s\n", CURSYM(sel), pname, get_file_sym(ent->mode));
}
-static void
-printent_long(struct entry *ent, int sel, uint namecols)
+static void printent_long(struct entry *ent, int sel, uint namecols)
{
static char buf[18], *pname;
static void (*printptr)(struct entry *ent, int sel, uint namecols) = &printent_long;
-static char
-get_fileind(mode_t mode, char *desc)
+static char get_fileind(mode_t mode, char *desc)
{
static char c;
}
/* Convert a mode field into "ls -l" type perms field. */
-static char *
-get_lsperms(mode_t mode, char *desc)
+static char *get_lsperms(mode_t mode, char *desc)
{
static const char * const rwx[] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
static char bits[11] = {'\0'};
*
* If pager is valid, returns NULL
*/
-static char *
-get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager)
+static char *get_output(char *buf, size_t bytes, char *file, char *arg1, char *arg2, int pager)
{
pid_t pid;
int pipefd[2];
return NULL;
}
-static char *
-xgetpwuid(uid_t uid)
+static char *xgetpwuid(uid_t uid)
{
struct passwd *pwd = getpwuid(uid);
return pwd->pw_name;
}
-static char *
-xgetgrgid(gid_t gid)
+static char *xgetgrgid(gid_t gid)
{
struct group *grp = getgrgid(gid);
/*
* Follows the stat(1) output closely
*/
-static int
-show_stats(char *fpath, char *fname, struct stat *sb)
+static int show_stats(char *fpath, char *fname, struct stat *sb)
{
char desc[DESCRIPTOR_LEN];
char *perms = get_lsperms(sb->st_mode, desc);
return 0;
}
-static size_t
-get_fs_info(const char *path, bool type)
+static size_t get_fs_info(const char *path, bool type)
{
static struct statvfs svb;
return svb.f_bavail << ffs(svb.f_frsize >> 1);
}
-static int
-show_mediainfo(char *fpath, char *arg)
+static int show_mediainfo(char *fpath, char *arg)
{
if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[cfg.metaviewer], NULL, 0))
return -1;
return 0;
}
-static int
-handle_archive(char *fpath, char *arg, char *dir)
+static int handle_archive(char *fpath, char *arg, char *dir)
{
if (!get_output(g_buf, MAX_CMD_LEN, "which", utils[ATOOL], NULL, 0))
return -1;
* the binary size by around a hundred bytes. This would only
* have increased as we keep adding new options.
*/
-static int
-show_help(char *path)
+static int show_help(char *path)
{
if (g_tmpfpath[0])
xstrlcpy(g_tmpfpath + g_tmpfplen - 1, "/.nnnXXXXXX", MAX_HOME_LEN - g_tmpfplen);
return 0;
}
-int (*nftw_fn) (const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
-
-static int
-sum_bsizes(const char *fpath, const struct stat *sb,
+static int sum_bsizes(const char *fpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf)
{
if (sb->st_blocks && (typeflag == FTW_F || typeflag == FTW_D))
return 0;
}
-static int
-sum_sizes(const char *fpath, const struct stat *sb,
+static int sum_sizes(const char *fpath, const struct stat *sb,
int typeflag, struct FTW *ftwbuf)
{
if (sb->st_size && (typeflag == FTW_F || typeflag == FTW_D))
return 0;
}
-static int
-dentfill(char *path, struct entry **dents,
+static int dentfill(char *path, struct entry **dents,
int (*filter)(regex_t *, char *), regex_t *re)
{
static DIR *dirp;
return n;
}
-static void
-dentfree(struct entry *dents)
+static void dentfree(struct entry *dents)
{
free(pnamebuf);
free(dents);
}
/* Return the position of the matching entry or 0 otherwise */
-static int
-dentfind(struct entry *dents, const char *fname, int n)
+static int dentfind(struct entry *dents, const char *fname, int n)
{
static int i;
return 0;
}
-static int
-populate(char *path, char *oldname, char *fltr)
+static int populate(char *path, char *oldname, char *fltr)
{
static regex_t re;
return 0;
}
-static void
-redraw(char *path)
+static void redraw(char *path)
{
static char buf[NAME_MAX + 65] __attribute__ ((aligned));
static size_t ncols;
}
}
-static void
-browse(char *ipath, char *ifilter)
+static void browse(char *ipath, char *ifilter)
{
static char path[PATH_MAX] __attribute__ ((aligned));
static char newpath[PATH_MAX] __attribute__ ((aligned));
}
}
-static void
-usage(void)
+static void usage(void)
{
fprintf(stdout,
"usage: nnn [-b key] [-c N] [-e] [-i] [-l]\n"
exit(0);
}
-int
-main(int argc, char *argv[])
+int main(int argc, char *argv[])
{
static char cwd[PATH_MAX] __attribute__ ((aligned));
char *ipath = NULL, *ifilter;