#endif
#define MIN_DISPLAY_COLS ((CTX_MAX * 2) + 2) /* Two chars for [ and ] */
-#define LONG_SIZE sizeof(ulong)
#define ARCHIVE_CMD_LEN 16
#define BLK_SHIFT_512 9
#define CAPACITY 1
/* TYPE DEFINITIONS */
-typedef unsigned long ulong;
-typedef unsigned int uint;
-typedef unsigned char uchar;
-typedef unsigned short ushort;
-typedef long long ll;
-typedef unsigned long long ull;
+typedef unsigned int uint_t;
+typedef unsigned char uchar_t;
+typedef unsigned short ushort_t;
+typedef unsigned long long ulong_t;
/* STRUCTURES */
uid_t uid;
gid_t gid;
#endif
- ushort nlen; /* Length of file name */
- uchar flags; /* Flags specific to the file */
+ ushort_t nlen; /* Length of file name */
+ uchar_t flags; /* Flags specific to the file */
} *pEntry;
/* Key-value pairs from env */
* NOTE: update default values if changing order
*/
typedef struct {
- uint filtermode : 1; /* Set to enter filter mode */
- uint timeorder : 1; /* Set to sort by time */
- uint sizeorder : 1; /* Set to sort by file size */
- uint apparentsz : 1; /* Set to sort by apparent size (disk usage) */
- uint blkorder : 1; /* Set to sort by blocks used (disk usage) */
- uint extnorder : 1; /* Order by extension */
- uint showhidden : 1; /* Set to show hidden files */
- uint reserved0 : 1;
- uint showdetail : 1; /* Clear to show lesser file info */
- uint ctxactive : 1; /* Context active or not */
- uint reverse : 1; /* Reverse sort */
- uint version : 1; /* Version sort */
- uint reserved1 : 1;
+ uint_t filtermode : 1; /* Set to enter filter mode */
+ uint_t timeorder : 1; /* Set to sort by time */
+ uint_t sizeorder : 1; /* Set to sort by file size */
+ uint_t apparentsz : 1; /* Set to sort by apparent size (disk usage) */
+ uint_t blkorder : 1; /* Set to sort by blocks used (disk usage) */
+ uint_t extnorder : 1; /* Order by extension */
+ uint_t showhidden : 1; /* Set to show hidden files */
+ uint_t reserved0 : 1;
+ uint_t showdetail : 1; /* Clear to show lesser file info */
+ uint_t ctxactive : 1; /* Context active or not */
+ uint_t reverse : 1; /* Reverse sort */
+ uint_t version : 1; /* Version sort */
+ uint_t reserved1 : 1;
/* The following settings are global */
- uint curctx : 3; /* Current context number */
- uint prefersel : 1; /* Prefer selection over current, if exists */
- uint reserved2 : 1;
- uint nonavopen : 1; /* Open file on right arrow or `l` */
- uint autoselect : 1; /* Auto-select dir in type-to-nav mode */
- uint cursormode : 1; /* Move hardware cursor with selection */
- uint useeditor : 1; /* Use VISUAL to open text files */
- uint reserved3 : 3;
- uint regex : 1; /* Use regex filters */
- uint x11 : 1; /* Copy to system clipboard and show notis */
- uint timetype : 2; /* Time sort type (0: access, 1: change, 2: modification) */
- uint cliopener : 1; /* All-CLI app opener */
- uint waitedit : 1; /* For ops that can't be detached, used EDITOR */
- uint rollover : 1; /* Roll over at edges */
+ uint_t curctx : 3; /* Current context number */
+ uint_t prefersel : 1; /* Prefer selection over current, if exists */
+ uint_t reserved2 : 1;
+ uint_t nonavopen : 1; /* Open file on right arrow or `l` */
+ uint_t autoselect : 1; /* Auto-select dir in type-to-nav mode */
+ uint_t cursormode : 1; /* Move hardware cursor with selection */
+ uint_t useeditor : 1; /* Use VISUAL to open text files */
+ uint_t reserved3 : 3;
+ uint_t regex : 1; /* Use regex filters */
+ uint_t x11 : 1; /* Copy to system clipboard and show notis */
+ uint_t timetype : 2; /* Time sort type (0: access, 1: change, 2: modification) */
+ uint_t cliopener : 1; /* All-CLI app opener */
+ uint_t waitedit : 1; /* For ops that can't be detached, used EDITOR */
+ uint_t rollover : 1; /* Roll over at edges */
} settings;
/* Non-persistent program-internal states */
typedef struct {
- uint pluginit : 1; /* Plugin framework initialized */
- uint interrupt : 1; /* Program received an interrupt */
- uint rangesel : 1; /* Range selection on */
- uint move : 1; /* Move operation */
- uint autonext : 1; /* Auto-proceed on open */
- uint fortune : 1; /* Show fortune messages in help */
- uint trash : 2; /* Use trash to delete files 1: trash-cli, 2: gio trash */
- uint forcequit : 1; /* Do not prompt on quit */
- uint autofifo : 1; /* Auto-create NNN_FIFO */
- uint initfile : 1; /* Positional arg is a file */
- uint dircolor : 1; /* Current status of dir color */
- uint picker : 1; /* Write selection to user-specified file */
- uint pickraw : 1; /* Write selection to stdout before exit */
- uint runplugin : 1; /* Choose plugin mode */
- uint runctx : 2; /* The context in which plugin is to be run */
- uint selmode : 1; /* Set when selecting files */
- uint oldcolor : 1; /* Use older colorscheme */
- uint stayonsel : 1; /* Disable auto-proceed on select */
- uint dirctx : 1; /* Show dirs in context color */
- uint uidgid : 1; /* Show owner and group info */
- uint reserved : 10; /* Adjust when adding/removing a field */
+ uint_t pluginit : 1; /* Plugin framework initialized */
+ uint_t interrupt : 1; /* Program received an interrupt */
+ uint_t rangesel : 1; /* Range selection on */
+ uint_t move : 1; /* Move operation */
+ uint_t autonext : 1; /* Auto-proceed on open */
+ uint_t fortune : 1; /* Show fortune messages in help */
+ uint_t trash : 2; /* Use trash to delete files 1: trash-cli, 2: gio trash */
+ uint_t forcequit : 1; /* Do not prompt on quit */
+ uint_t autofifo : 1; /* Auto-create NNN_FIFO */
+ uint_t initfile : 1; /* Positional arg is a file */
+ uint_t dircolor : 1; /* Current status of dir color */
+ uint_t picker : 1; /* Write selection to user-specified file */
+ uint_t pickraw : 1; /* Write selection to stdout before exit */
+ uint_t runplugin : 1; /* Choose plugin mode */
+ uint_t runctx : 2; /* The context in which plugin is to be run */
+ uint_t selmode : 1; /* Set when selecting files */
+ uint_t oldcolor : 1; /* Use older colorscheme */
+ uint_t stayonsel : 1; /* Disable auto-proceed on select */
+ uint_t dirctx : 1; /* Show dirs in context color */
+ uint_t uidgid : 1; /* Show owner and group info */
+ uint_t reserved : 10; /* Adjust when adding/removing a field */
} runstate;
/* Contexts or workspaces */
char c_name[NAME_MAX + 1]; /* Current file name */
char c_fltr[REGEX_MAX]; /* Current filter */
settings c_cfg; /* Current configuration */
- uint color; /* Color code for directories */
+ uint_t color; /* Color code for directories */
} context;
#ifndef NOSSN
#ifndef NOFIFO
static int fifofd = -1;
#endif
-static uint idletimeout, selbufpos, lastappendpos, selbuflen;
-static ushort xlines, xcols;
-static ushort idle;
-static uchar maxbm, maxplug;
+static uint_t idletimeout, selbufpos, lastappendpos, selbuflen;
+static ushort_t xlines, xcols;
+static ushort_t idle;
+static uchar_t maxbm, maxplug;
static char *bmstr;
static char *pluginstr;
static char *opener;
#ifndef NOFIFO
static char *fifopath;
#endif
-static ull *ihashbmp;
+static unsigned long long *ihashbmp;
static struct entry *pdents;
static blkcnt_t ent_blocks;
static blkcnt_t dir_blocks;
-static ulong num_files;
+static ulong_t num_files;
static kv *bookmark;
static kv *plug;
-static uchar tmpfplen;
-static uchar blk_shift = BLK_SHIFT_512;
+static uchar_t tmpfplen;
+static uchar_t blk_shift = BLK_SHIFT_512;
#ifndef NOMOUSE
static int middle_click_key;
#endif
static char mv[] = "mv -i";
#endif
+/* Archive commands */
+const char *archive_cmd[] = {"atool -a", "bsdtar -acvf", "zip -r", "tar -acvf"};
+
/* Tokens used for path creation */
#define TOK_SSN 0
#define TOK_MNT 1
#ifdef ICONS_ENABLED
/* 0-9, A-Z, OTHER = 36. */
-static ushort icon_positions[37];
+static ushort_t icon_positions[37];
#endif
static char gcolors[] = "c1e2272e006033f7c6d6abc4";
-static uint fcolors[C_UND + 1] = {0};
+static uint_t fcolors[C_UND + 1] = {0};
/* Event handling */
#ifdef LINUX_INOTIFY
#define EVENT_SIZE (sizeof(struct inotify_event))
#define EVENT_BUF_LEN (EVENT_SIZE * NUM_EVENT_SLOTS)
static int inotify_fd, inotify_wd = -1;
-static uint INOTIFY_MASK = /* IN_ATTRIB | */ IN_CREATE | IN_DELETE | IN_DELETE_SELF
+static uint_t INOTIFY_MASK = /* IN_ATTRIB | */ IN_CREATE | IN_DELETE | IN_DELETE_SELF
| IN_MODIFY | IN_MOVE_SELF | IN_MOVED_FROM | IN_MOVED_TO;
#elif defined(BSD_KQUEUE)
#define NUM_EVENT_SLOTS 1
#define NUM_EVENT_FDS 1
static int kq, event_fd = -1;
static struct kevent events_to_monitor[NUM_EVENT_FDS];
-static uint KQUEUE_FFLAGS = NOTE_DELETE | NOTE_EXTEND | NOTE_LINK
+static uint_t KQUEUE_FFLAGS = NOTE_DELETE | NOTE_EXTEND | NOTE_LINK
| NOTE_RENAME | NOTE_REVOKE | NOTE_WRITE;
static struct timespec gtimeout;
#elif defined(HAIKU_NM)
#define xerror() perror(xitoa(__LINE__))
#ifdef TOURBIN_QSORT
-#define ENTLESS(i,j) (entrycmpfn(pdents + (i), pdents + (j)) < 0)
-#define ENTSWAP(i,j) (swap_ent((i),(j)))
+#define ENTLESS(i, j) (entrycmpfn(pdents + (i), pdents + (j)) < 0)
+#define ENTSWAP(i, j) (swap_ent((i), (j)))
#define ENTSORT(pdents, ndents, entrycmpfn) QSORT((ndents), ENTLESS, ENTSWAP)
#else
#define ENTSORT(pdents, ndents, entrycmpfn) qsort((pdents), (ndents), sizeof(*(pdents)), (entrycmpfn))
/* Forward declarations */
static void redraw(char *path);
-static int spawn(char *file, char *arg1, char *arg2, uchar flag);
+static int spawn(char *file, char *arg1, char *arg2, uchar_t flag);
static int (*nftw_fn)(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf);
static void move_cursor(int target, int ignore_scrolloff);
static char *load_input(int fd, const char *path);
exit(EXIT_SUCCESS);
}
-static char *xitoa(uint val)
+static char *xitoa(uint_t val)
{
static char ascbuf[32] = {0};
int i = 30;
- uint rem;
+ uint_t rem;
if (!val)
return "0";
}
/* Return the integer value of a char representing HEX */
-static uchar xchartohex(uchar c)
+static uchar_t xchartohex(uchar_t c)
{
if (xisdigit(c))
return c - '0';
/*
* Source: https://elixir.bootlin.com/linux/latest/source/arch/alpha/include/asm/bitops.h
*/
-static bool test_set_bit(uint nr)
+static bool test_set_bit(uint_t nr)
{
nr &= HASH_BITS;
- ull *m = ((ull *)ihashbmp) + (nr >> 6);
+ unsigned long long *m = ((unsigned long long *)ihashbmp) + (nr >> 6);
if (*m & (1 << (nr & 63)))
return FALSE;
return TRUE;
}
-#if 0
-static bool test_clear_bit(uint nr)
-{
- nr &= HASH_BITS;
-
- ull *m = ((ull *) ihashbmp) + (nr >> 6);
-
- if (!(*m & (1 << (nr & 63))))
- return FALSE;
-
- *m &= ~(1 << (nr & 63));
- return TRUE;
-}
-#endif
-
/* Increase the limit on open file descriptors, if possible */
static rlim_t max_openfds(void)
{
* And we are NOT expecting a '/' at the end.
* Ideally 0 < n <= xstrlen(s).
*/
-static void *xmemrchr(uchar *restrict s, uchar ch, size_t n)
+static void *xmemrchr(uchar_t *restrict s, uchar_t ch, size_t n)
{
#if defined(__GLIBC__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
return memrchr(s, ch, n);
if (!s || !n)
return NULL;
- uchar *ptr = s + n;
+ uchar_t *ptr = s + n;
- do
+ do {
if (*--ptr == ch)
return ptr;
- while (s != ptr);
+ } while (s != ptr);
return NULL;
#endif
/* A very simplified implementation, changes path */
static char *xdirname(char *path)
{
- char *base = xmemrchr((uchar *)path, '/', xstrlen(path));
+ char *base = xmemrchr((uchar_t *)path, '/', xstrlen(path));
if (base == path)
path[1] = '\0';
static char *xbasename(char *path)
{
- char *base = xmemrchr((uchar *)path, '/', xstrlen(path)); // NOLINT
+ char *base = xmemrchr((uchar_t *)path, '/', xstrlen(path)); // NOLINT
return base ? base + 1 : path;
}
static char *xextension(const char *fname, size_t len)
{
- return xmemrchr((uchar *)fname, '.', len);
+ return xmemrchr((uchar_t *)fname, '.', len);
}
static inline bool getutil(char *util)
/* Shorten prefix */
prefix[y - prefix] = '\0';
- sep = xmemrchr((uchar *)prefix, '/', y - prefix);
+ sep = xmemrchr((uchar_t *)prefix, '/', y - prefix);
if (sep != prefix)
*sep = '\0';
else /* Just '/' */
* no separator (fd .): this needs an additional char for '/'
*/
char *resolved_path = malloc(src_size + (*path == '/' ? 0 : cwd_size) + 2);
+
if (!resolved_path)
return NULL;
if (next - src == 2 && src[0] == '.' && src[1] == '.') {
if (dst - resolved_path) {
- dst = xmemrchr((uchar *)resolved_path, '/', dst - resolved_path);
+ dst = xmemrchr((uchar_t *)resolved_path, '/', dst - resolved_path);
*dst = '\0';
}
} else if (next - src == 1 && src[0] == '.') {
}
/* Write selected file paths to fd, linefeed separated */
-static size_t seltofile(int fd, uint *pcount)
+static size_t seltofile(int fd, uint_t *pcount)
{
- uint lastpos, count = 0;
+ uint_t lastpos, count = 0;
char *pbuf = pselbuf;
size_t pos = 0;
ssize_t len, prefixlen = 0, initlen = 0;
if (!f_colors || !*f_colors)
f_colors = gcolors;
- for (uchar id = C_BLK; *f_colors && id <= C_UND; ++id) {
+ for (uchar_t id = C_BLK; *f_colors && id <= C_UND; ++id) {
fcolors[id] = xchartohex(*f_colors) << 4;
if (*++f_colors) {
fcolors[id] += xchartohex(*f_colors);
char *colors = getenv(env_cfg[NNN_COLORS]);
if (colors || !getenv("NO_COLOR")) {
- uint *pcode;
+ uint_t *pcode;
bool ext = FALSE;
start_color();
}
/* Get and set the context colors */
- for (uchar i = 0; i < CTX_MAX; ++i) {
+ for (uchar_t i = 0; i < CTX_MAX; ++i) {
pcode = &g_ctx[i].color;
if (colors && *colors) {
#ifdef ICONS_ENABLED
if (!g_state.oldcolor) {
- uchar icolors[256] = {0};
+ uchar_t icolors[256] = {0};
char c;
memset(icon_positions, 0x7f, sizeof(icon_positions));
- for (uint i = 0; i < sizeof(icons_ext)/sizeof(struct icon_pair); ++i) {
+ for (uint_t i = 0; i < sizeof(icons_ext)/sizeof(struct icon_pair); ++i) {
c = TOUPPER(icons_ext[i].match[0]);
if (c >= 'A' && c <= 'Z') {
if (icon_positions[c - 'A' + 10] == 0x7f7f)
return count;
}
-static pid_t xfork(uchar flag)
+static pid_t xfork(uchar_t flag)
{
int status;
pid_t p = fork();
return p;
}
-static int join(pid_t p, uchar flag)
+static int join(pid_t p, uchar_t flag)
{
int status = 0xFFFF;
* Spawns a child process. Behaviour can be controlled using flag.
* Limited to 2 arguments to a program, flag works on bit set.
*/
-static int spawn(char *file, char *arg1, char *arg2, uchar flag)
+static int spawn(char *file, char *arg1, char *arg2, uchar_t flag)
{
pid_t pid;
int status = 0, retstatus = 0xFFFF;
#ifndef NORL
fflush(stdout);
#endif
- while (getchar() != '\n');
+ while (getchar() != '\n') {};
}
if (flag & F_NORMAL)
}
/* Checks if an env variable is set to 1 */
-static inline uint xgetenv_val(const char *name)
+static inline uint_t xgetenv_val(const char *name)
{
char *str = getenv(name);
return (access(fpath, F_OK) == -1); /* File is removed */
}
-static uint lines_in_file(int fd, char *buf, size_t buflen)
+static uint_t lines_in_file(int fd, char *buf, size_t buflen)
{
ssize_t len;
- uint count = 0;
+ uint_t count = 0;
while ((len = read(fd, buf, buflen)) > 0)
while (len)
static bool cpmv_rename(int choice, const char *path)
{
int fd;
- uint count = 0, lines = 0;
+ uint_t count = 0, lines = 0;
bool ret = FALSE;
char *cmd = (choice == 'c' ? cp : mv);
char buf[sizeof(patterns[P_CPMVRNM]) + sizeof(cmd) + (PATH_MAX << 1)];
static bool batch_rename(void)
{
int fd1, fd2;
- uint count = 0, lines = 0;
+ uint_t count = 0, lines = 0;
bool dir = FALSE, ret = FALSE;
char foriginal[TMP_LEN_MAX] = {0};
static const char batchrenamecmd[] = "paste -d'\n' %s %s | "SED" 'N; /^\\(.*\\)\\n\\1$/!p;d' | "
static void get_archive_cmd(char *cmd, const char *archive)
{
- uchar i = 3;
- const char *arcmd[] = {"atool -a", "bsdtar -acvf", "zip -r", "tar -acvf"};
+ uchar_t i = 3;
if (getutil(utils[UTIL_ATOOL]))
i = 0;
i = 2;
// else tar
- xstrsncpy(cmd, arcmd[i], ARCHIVE_CMD_LEN);
+ xstrsncpy(cmd, archive_cmd[i], ARCHIVE_CMD_LEN);
}
static void archive_selection(const char *cmd, const char *archive, const char *curpath)
{
char *p1, *p2;
- ll v1 = strtoll(s1, &p1, 10);
- ll v2 = strtoll(s2, &p2, 10);
+ long long v1 = strtoll(s1, &p1, 10);
+ long long v2 = strtoll(s2, &p2, 10);
/* Check if at least 1 string is numeric */
if (s1 != p1 || s2 != p2) {
*/
static int xstrverscasecmp(const char * const s1, const char * const s2)
{
- const uchar *p1 = (const uchar *)s1;
- const uchar *p2 = (const uchar *)s2;
+ const uchar_t *p1 = (const uchar_t *)s1;
+ const uchar_t *p2 = (const uchar_t *)s2;
int state, diff;
- uchar c1, c2;
+ uchar_t c1, c2;
/*
* Symbol(s) 0 [1-9] others
static int handle_alt_key(wint_t *wch)
{
timeout(0);
+
int r = get_wch(wch);
+
if (r == ERR)
*wch = ESC;
cleartimeout();
return SEL_QUIT;
#endif
int c = presel;
- uint i;
+ uint_t i;
bool escaped = FALSE;
if (c == 0 || c == MSGWAIT) {
int r, total = ndents, len;
char *pln = g_ctx[cfg.curctx].c_fltr + 1;
- DPRINTF_S(__FUNCTION__);
+ DPRINTF_S(__func__);
if (ndents && (ln[0] == FILTER || ln[0] == RFILTER) && *pln) {
if (matches(pln) != -1) {
/* toggle string or regex filter */
if (*ch == FILTER) {
ln[0] = (ln[0] == FILTER) ? RFILTER : FILTER;
- wln[0] = (uchar)ln[0];
+ wln[0] = (uchar_t)ln[0];
cfg.regex ^= 1;
filterfn = cfg.regex ? &visible_re : &visible_str;
showfilter(ln);
return count;
}
-static bool parsekvpair(kv **arr, char **envcpy, const uchar id, uchar *items)
+static bool parsekvpair(kv **arr, char **envcpy, const uchar_t id, uchar_t *items)
{
bool new = TRUE;
- const uchar INCR = 8;
- uint i = 0;
+ const uchar_t INCR = 8;
+ uint_t i = 0;
kv *kvarr = NULL;
char *ptr = getenv(env_cfg[id]);
}
memset(kvarr + i, 0, sizeof(kv) * INCR);
}
- kvarr[i].key = (uchar)*ptr;
+ kvarr[i].key = (uchar_t)*ptr;
if (*++ptr != ':' || *++ptr == '\0' || *ptr == ';')
return FALSE;
kvarr[i].off = ptr - *envcpy;
* 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_kv_val(kv *kvarr, char *buf, int key, uchar max, uchar id)
+static char *get_kv_val(kv *kvarr, char *buf, int key, uchar_t max, uchar_t id)
{
char *val;
* Max supported str length: NAME_MAX;
*/
#ifndef NOLOCALE
-static wchar_t *unescape(const char *str, uint maxcols)
+static wchar_t *unescape(const char *str, uint_t maxcols)
{
wchar_t * const wbuf = (wchar_t *)g_buf;
wchar_t *buf = wbuf;
wbuf[lencount] = L'\0';
} else {
- do /* We do not expect a NULL string */
+ do { /* We do not expect a NULL string */
if (*buf <= '\x1f' || *buf == '\x7f')
*buf = '\?';
- while (*++buf);
+ } while (*++buf);
}
return wbuf;
}
#else
-static char *unescape(const char *str, uint maxcols)
+static char *unescape(const char *str, uint_t maxcols)
{
ssize_t len = (ssize_t)xstrsncpy(g_buf, str, maxcols);
}
#ifdef ICONS_ENABLED
-static const struct icon_pair * get_icon(const struct entry *ent){
- ushort i = 0;
+static const struct icon_pair *get_icon(const struct entry *ent)
+{
+ ushort_t i = 0;
for (; i < sizeof(icons_name)/sizeof(struct icon_pair); ++i)
if (strcasecmp(ent->name, icons_name[i].match) == 0)
else
i = 36; /* OTHER */
- for (ushort j = icon_positions[i]; j < sizeof(icons_ext)/sizeof(struct icon_pair) &&
+ for (ushort_t j = icon_positions[i]; j < sizeof(icons_ext)/sizeof(struct icon_pair) &&
icons_ext[j].match[0] == icons_ext[icon_positions[i]].match[0]; ++j)
if (strcasecmp(tmp, icons_ext[j].match) == 0)
return &icons_ext[j];
t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min);
}
-static void printent(const struct entry *ent, uint namecols, bool sel)
+static void printent(const struct entry *ent, uint_t namecols, bool sel)
{
- uchar pair = 0;
+ uchar_t pair = 0;
char ind = '\0';
int attrs = 0;
addch('\n');
}
-static void printent_long(const struct entry *ent, uint namecols, bool sel)
+static void printent_long(const struct entry *ent, uint_t namecols, bool sel)
{
bool ln = FALSE;
char ind1 = '\0', ind2 = '\0';
- uchar pair = 0;
+ uchar_t pair = 0;
int attrs = sel ? (A_REVERSE | (g_state.oldcolor ? A_DIM : COLOR_PAIR(C_MIS)))
: (g_state.oldcolor ? A_DIM : COLOR_PAIR(C_MIS));
- uint len;
+ uint_t len;
char *size;
- char selgap[]=" ";
+ char selgap[] = " ";
if (ent->flags & FILE_SELECTED)
selgap[1] = '+';
}
size = coolsize(cfg.blkorder ? ent->blocks << blk_shift : ent->size);
- len = 10 - (uint)xstrlen(size);
+ len = 10 - (uint_t)xstrlen(size);
while (--len)
addch(' ');
addstr(size);
addch('\n');
}
-static void (*printptr)(const struct entry *ent, uint namecols, bool sel) = &printent;
+static void (*printptr)(const struct entry *ent, uint_t namecols, bool sel) = &printent;
static void savecurctx(settings *curcfg, char *path, char *curname, int r /* next context num */)
{
for (i = 0; i < CTX_MAX; ++i)
if ((fwrite(&g_ctx[i].c_cfg, sizeof(settings), 1, fsession) != 1)
- || (fwrite(&g_ctx[i].color, sizeof(uint), 1, fsession) != 1)
+ || (fwrite(&g_ctx[i].color, sizeof(uint_t), 1, fsession) != 1)
|| (header.nameln[i] > 0
&& fwrite(g_ctx[i].c_name, header.nameln[i], 1, fsession) != 1)
|| (header.lastln[i] > 0
for (; i < CTX_MAX; ++i)
if ((fread(&g_ctx[i].c_cfg, sizeof(settings), 1, fsession) != 1)
- || (fread(&g_ctx[i].color, sizeof(uint), 1, fsession) != 1)
+ || (fread(&g_ctx[i].color, sizeof(uint_t), 1, fsession) != 1)
|| (header.nameln[i] > 0
&& fread(g_ctx[i].c_name, header.nameln[i], 1, fsession) != 1)
|| (header.lastln[i] > 0
}
#endif
-static uchar get_free_ctx(void)
+static uchar_t get_free_ctx(void)
{
- uchar r = cfg.curctx;
+ uchar_t r = cfg.curctx;
do
r = (r + 1) & ~CTX_MAX;
static bool remote_mount(char *newpath)
{
- uchar flag = F_CLI;
+ uchar_t flag = F_CLI;
int opt;
char *tmp, *env;
bool r = getutil(utils[UTIL_RCLONE]), s = getutil(utils[UTIL_SSHFS]);
if (!div) { /* Convert "host" to "host:" */
size_t len = xstrlen(tmp);
+
tmp[len] = ':';
tmp[len + 1] = '\0';
} else
spawn(xgetenv("NNN_LOCKER", utils[UTIL_LOCKER]), NULL, NULL, F_CLI);
}
-static void printkv(kv *kvarr, FILE *fp, uchar max, uchar id)
+static void printkv(kv *kvarr, FILE *fp, uchar_t max, uchar_t id)
{
char *val = (id == NNN_BMS) ? bmstr : pluginstr;
- for (uchar i = 0; i < max && kvarr[i].key; ++i) {
+ for (uchar_t i = 0; i < max && kvarr[i].key; ++i)
fprintf(fp, " %c: %s\n", (char)kvarr[i].key, val + kvarr[i].off);
- }
}
-static void printkeys(kv *kvarr, char *buf, uchar max)
+static void printkeys(kv *kvarr, char *buf, uchar_t max)
{
- uchar i = 0;
+ uchar_t i = 0;
for (; i < max && kvarr[i].key; ++i) {
buf[i << 1] = ' ';
fprintf(fp, "\n");
}
- for (uchar i = NNN_OPENER; i <= NNN_TRASH; ++i) {
+ for (uchar_t i = NNN_OPENER; i <= NNN_TRASH; ++i) {
start = getenv(env_cfg[i]);
if (start)
fprintf(fp, "%s: %s\n", env_cfg[i], start);
unlink(g_tmpfpath);
}
-static bool run_cmd_as_plugin(const char *file, char *runfile, uchar flags)
+static bool run_cmd_as_plugin(const char *file, char *runfile, uchar_t flags)
{
size_t len;
return EXIT_SUCCESS;
}
-static void rmlistpath()
+static void rmlistpath(void)
{
if (listpath) {
- DPRINTF_S(__FUNCTION__);
+ DPRINTF_S(__func__);
DPRINTF_S(listpath);
spawn("rm -rf", listpath, NULL, F_NOTRACE | F_MULTI);
/* Do not free if program was started in list mode */
static ssize_t read_nointr(int fd, void *buf, size_t count)
{
ssize_t len;
- do{
+
+ do
len = read(fd, buf, count);
- } while (len == -1 && errno == EINTR);
+ while (len == -1 && errno == EINTR);
+
return len;
}
static bool run_selected_plugin(char **path, const char *file, char *runfile, char **lastname, char **lastdir)
{
bool cmd_as_plugin = FALSE;
- uchar flags = 0;
+ uchar_t flags = 0;
if (!g_state.pluginit) {
plctrl_init();
}
int rfd;
- do {
+
+ do
rfd = open(g_pipepath, O_RDONLY);
- } while (rfd == -1 && errno == EINTR);
+ while (rfd == -1 && errno == EINTR);
readpipe(rfd, path, lastname, lastdir);
close(rfd);
return TRUE;
}
-static bool plugscript(const char *plugin, uchar flags)
+static bool plugscript(const char *plugin, uchar_t flags)
{
mkpath(plgpath, plugin, g_buf);
if (!access(g_buf, X_OK)) {
static int sum_bsize(const char *UNUSED(fpath), const struct stat *sb, int typeflag, struct FTW *UNUSED(ftwbuf))
{
if (sb->st_blocks
- && ((typeflag == FTW_F && (sb->st_nlink <= 1 || test_set_bit((uint)sb->st_ino)))
+ && ((typeflag == FTW_F && (sb->st_nlink <= 1 || test_set_bit((uint_t)sb->st_ino)))
|| typeflag == FTW_D))
ent_blocks += sb->st_blocks;
static int sum_asize(const char *UNUSED(fpath), const struct stat *sb, int typeflag, struct FTW *UNUSED(ftwbuf))
{
if (sb->st_size
- && ((typeflag == FTW_F && (sb->st_nlink <= 1 || test_set_bit((uint)sb->st_ino)))
+ && ((typeflag == FTW_F && (sb->st_nlink <= 1 || test_set_bit((uint_t)sb->st_ino)))
|| typeflag == FTW_D))
ent_blocks += sb->st_size;
static blkcnt_t dirwalk(char *path, struct stat *psb)
{
- static uint open_max;
+ static uint_t open_max;
/* Increase current open file descriptor limit */
if (!open_max)
static int dentfill(char *path, struct entry **ppdents)
{
- uchar entflags = 0;
+ uchar_t entflags = 0;
int n = 0, flags = 0;
- ulong num_saved;
+ ulong_t num_saved;
struct dirent *dp;
char *namep, *pnb, *buf = NULL;
struct entry *dentp;
struct stat sb_path, sb;
DIR *dirp = opendir(path);
- DPRINTF_S(__FUNCTION__);
+ DPRINTF_S(__func__);
if (!dirp)
return 0;
}
} else {
/* Do not recount hard links */
- if (sb.st_nlink <= 1 || test_set_bit((uint)sb.st_ino))
+ if (sb.st_nlink <= 1 || test_set_bit((uint_t)sb.st_ino))
dir_blocks += (cfg.apparentsz ? sb.st_size : sb.st_blocks);
++num_files;
}
} else {
dentp->blocks = (cfg.apparentsz ? sb.st_size : sb.st_blocks);
/* Do not recount hard links */
- if (sb.st_nlink <= 1 || test_set_bit((uint)sb.st_ino))
+ if (sb.st_nlink <= 1 || test_set_bit((uint_t)sb.st_ino))
dir_blocks += dentp->blocks;
++num_files;
}
default: /* case SEL_FIRST */
{
int c = get_input(messages[MSG_FIRST]);
+
if (!c)
break;
if (cfg.reverse)
entrycmpfn = &reventrycmp;
- } else if ( r == CONTROL('T')) {
+ } else if (r == CONTROL('T')) {
/* Cycling order: clear -> size -> time -> clear */
if (cfg.timeorder)
r = 's';
printw("%cu:%s free:%s files:%lu %lldB %s\n",
(cfg.apparentsz ? 'a' : 'd'), buf, coolsize(get_fs_info(path, FREE)),
- num_files, (ll)pent->blocks << blk_shift, ptr);
+ num_files, (long long)pent->blocks << blk_shift, ptr);
} else { /* light or detail mode */
char sort[] = "\0\0\0\0\0";
return draw_line(path, ncols);
}
- DPRINTF_S(__FUNCTION__);
+ DPRINTF_S(__func__);
/* Clear screen */
erase();
if ((i + MIN_DISPLAY_COLS) <= ncols)
addnstr(path, ncols - MIN_DISPLAY_COLS);
else {
- char *base = xmemrchr((uchar *)path, '/', i);
+ char *base = xmemrchr((uchar_t *)path, '/', i);
i = 0;
enum action sel;
struct stat sb;
int r = -1, presel, selstartid = 0, selendid = 0;
- const uchar opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOWAIT));
+ const uchar_t opener_flags = (cfg.cliopener ? F_CLI : (F_NOTRACE | F_NOWAIT));
bool watch = FALSE;
#ifndef NOMOUSE
case SEL_QUITERR:
if (sel == SEL_QUITCTX) {
int ctx = cfg.curctx;
+
for (r = (ctx + 1) & ~CTX_MAX;
(r != ctx) && !g_ctx[r].c_cfg.ctxactive;
r = ((r + 1) & ~CTX_MAX)) {
xstrsncpy(tmp, paths[i] + len, xstrlen(paths[i]) - len + 1);
/* Get the dir containing the path */
- slash = xmemrchr((uchar *)tmp, '/', xstrlen(paths[i]) - len);
+ slash = xmemrchr((uchar_t *)tmp, '/', xstrlen(paths[i]) - len);
if (slash)
*slash = '\0';
if (total_read % chunk)
++chunk_count;
-
- if (!(input = xrealloc(input, (chunk_count + 1) * chunk)))
+ input = xrealloc(input, (chunk_count + 1) * chunk);
+ if (!input)
return NULL;
}
continue;
}
- if (!(paths[i] = abspath(paths[i], cwd))) {
+ paths[i] = abspath(paths[i], cwd);
+ if (!paths[i]) {
entries = i; // free from the previous entry
goto malloc_2;
int key;
bool bitmap[KEY_MAX] = {FALSE};
- for (ulong i = 0; i < sizeof(bindings) / sizeof(struct key); ++i) {
+ for (ulong_t i = 0; i < sizeof(bindings) / sizeof(struct key); ++i) {
key = bindings[i].sym;
if (bitmap[key])
/* Set selection file path */
if (!g_state.picker) {
char *env_sel = xgetenv(env_cfg[NNN_SEL], NULL);
+
selpath = env_sel ? xstrdup(env_sel)
: (char *)malloc(len + 3); /* Length of "/.config/nnn/.selection" */
static bool set_tmp_path(void)
{
- char *tmp = "/tmp";
- char *path = xdiraccess(tmp) ? tmp : getenv("TMPDIR");
+ char *tmp = "/tmp";
+ char *path = xdiraccess(tmp) ? tmp : getenv("TMPDIR");
- if (!path) {
- fprintf(stderr, "set TMPDIR\n");
- return FALSE;
- }
+ if (!path) {
+ fprintf(stderr, "set TMPDIR\n");
+ return FALSE;
+ }
- tmpfplen = (uchar)xstrsncpy(g_tmpfpath, path, TMP_LEN_MAX);
+ tmpfplen = (uchar_t)xstrsncpy(g_tmpfpath, path, TMP_LEN_MAX);
DPRINTF_S(g_tmpfpath);
DPRINTF_U(tmpfplen);
- return TRUE;
+ return TRUE;
}
static void cleanup(void)
#ifndef NOMOUSE
mmask_t mask;
char *middle_click_env = xgetenv(env_cfg[NNN_MCLICK], "\0");
+
if (middle_click_env[0] == '^' && middle_click_env[1])
middle_click_key = CONTROL(middle_click_env[1]);
else
- middle_click_key = (uchar)middle_click_env[0];
+ middle_click_key = (uchar_t)middle_click_env[0];
#endif
- const char* const env_opts = xgetenv(env_cfg[NNN_OPTS], NULL);
+
+ const char * const env_opts = xgetenv(env_cfg[NNN_OPTS], NULL);
int env_opts_id = env_opts ? (int)xstrlen(env_opts) : -1;
#ifndef NORL
bool rlhist = FALSE;
break;
case 'P':
if (env_opts_id < 0 && !optarg[1])
- pkey = (uchar)optarg[0];
+ pkey = (uchar_t)optarg[0];
break;
case 'Q':
g_state.forcequit = 1;
break;
case 'T':
if (env_opts_id < 0)
- sort = (uchar)optarg[0];
+ sort = (uchar_t)optarg[0];
break;
case 'u':
cfg.prefersel = 1;