typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned short ushort;
-typedef long long int ll;
+typedef long long ll;
/* STRUCTURES */
#ifdef KEY_RESIZE
do {
r = getch();
- if ( r == KEY_RESIZE) {
+ if (r == KEY_RESIZE) {
if (prompt) {
clearoldprompt();
xlines = LINES;
printprompt(prompt);
}
}
- } while ( r == KEY_RESIZE);
+ } while (r == KEY_RESIZE);
#else
r = getch();
#endif
return base ? base + 1 : path;
}
-static int create_tmp_file()
+static int create_tmp_file(void)
{
xstrlcpy(g_tmpfpath + g_tmpfplen - 1, messages[STR_TMPFILE], TMP_LEN_MAX - g_tmpfplen);
int fd = mkstemp(g_tmpfpath);
+
if (fd == -1) {
DPRINTF_S(strerror(errno));
}
+
return fd;
}
return;
FILE *fp = fopen(g_selpath, "w");
+
if (fp) {
if (fwrite(buf, 1, buflen, fp) != buflen)
printwarn(NULL);
dents[r].flags &= ~FILE_SELECTED;
}
-static void startselection()
+static void startselection(void)
{
if (!cfg.selmode) {
cfg.selmode = 1;
bool ret = FALSE;
int fd, lines = 0;
ssize_t count;
+ struct stat sb;
if (!selbufpos) {
DPRINTF_S("empty selection");
spawn(editor, g_tmpfpath, NULL, NULL, F_CLI);
- if ((fd = open(g_tmpfpath, O_RDONLY)) == -1) {
+ fd = open(g_tmpfpath, O_RDONLY);
+ if (fd == -1) {
DPRINTF_S("couldn't read tmp file");
unlink(g_tmpfpath);
return FALSE;
}
- struct stat sb;
fstat(fd, &sb);
if (sb.st_size > selbufpos) {
uint count = 0, lines = 0;
bool ret = FALSE;
char *cmd = (choice == 'c' ? cp : mv);
- const char formatcmd[] = "sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s";
- const char renamecmd[] =
- "sed 's|^\\([^#][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' %s | tr '\\n' '\\0' | xargs -0 -o -n2 %s";
+ static const char formatcmd[] = "sed -i 's|^\\(\\(.*/\\)\\(.*\\)$\\)|#\\1\\n\\3|' %s";
+ static const char renamecmd[] = "sed 's|^\\([^#][^/]\\?.*\\)$|%s/\\1|;s|^#\\(/.*\\)$|\\1|' %s | tr '\\n' '\\0' | xargs -0 -o -n2 %s";
char buf[sizeof(renamecmd) + sizeof(cmd) + (PATH_MAX << 1)];
- if ((fd = create_tmp_file()) == -1)
+ fd = create_tmp_file();
+ if (fd == -1)
return ret;
/* selsafe() returned TRUE for this to be called */
spawn(editor, g_tmpfpath, NULL, path, F_CLI);
- if ((fd = open(g_tmpfpath, O_RDONLY)) == -1)
+ fd = open(g_tmpfpath, O_RDONLY);
+ if (fd == -1)
goto finish;
lines = lines_in_file(fd, buf, sizeof(buf));
int fd1, fd2, i;
uint count = 0, lines = 0;
bool dir = FALSE, ret = FALSE;
- const char renamecmd[] = "paste -d'\n' %s %s | sed 'N; /^\\(.*\\)\\n\\1$/!p;d' | tr '\n' '\\0' | xargs -0 -n2 mv 2>/dev/null";
+ static const char renamecmd[] = "paste -d'\n' %s %s | sed 'N; /^\\(.*\\)\\n\\1$/!p;d' | tr '\n' '\\0' | xargs -0 -n2 mv 2>/dev/null";
char foriginal[TMP_LEN_MAX] = {0};
char buf[sizeof(renamecmd) + (PATH_MAX << 1)];
- if ((fd1 = create_tmp_file()) == -1)
+ fd1 = create_tmp_file();
+ if (fd1 == -1)
return ret;
xstrlcpy(foriginal, g_tmpfpath, strlen(g_tmpfpath)+1);
- if ((fd2 = create_tmp_file()) == -1) {
+ fd2 = create_tmp_file();
+ if (fd2 == -1) {
unlink(foriginal);
close(fd1);
return ret;
spawn(editor, g_tmpfpath, NULL, path, F_CLI);
/* Reopen file descriptor to get updated contents */
- if ((fd2 = open(g_tmpfpath, O_RDONLY)) == -1)
+ fd2 = open(g_tmpfpath, O_RDONLY);
+ if (fd2 == -1)
goto finish;
lines = lines_in_file(fd2, buf, sizeof(buf));
xstrlcpy(&bits[7], rwx[(mode & 7)], 4);
if (mode & S_ISUID)
- bits[3] = (mode & 0100) ? 's' : 'S'; /* user executable */
+ bits[3] = (mode & 0100) ? 's' : 'S'; /* user executable */
if (mode & S_ISGID)
- bits[6] = (mode & 0010) ? 's' : 'l'; /* group executable */
+ bits[6] = (mode & 0010) ? 's' : 'l'; /* group executable */
if (mode & S_ISVTX)
- bits[9] = (mode & 0001) ? 't' : 'T'; /* others executable */
+ bits[9] = (mode & 0001) ? 't' : 'T'; /* others executable */
return bits;
}
printwait("failed to write session data", presel);
}
-static bool load_session(const char *sname, char **path, char **lastdir, char **lastname, bool restore) {
+static bool load_session(const char *sname, char **path, char **lastdir, char **lastname, bool restore)
+{
char spath[PATH_MAX];
int i = 0;
session_header_t header;
g_buf[r - 1] = '\0';
DPRINTF_S(g_buf);
- if (!(fp = fdopen(fd, "w"))) {
+ fp = fdopen(fd, "w");
+ if (!fp) {
close(fd);
return FALSE;
}
*/
static bool unmount(char *name, char *newpath, int *presel, char *currentpath)
{
- static char cmd[] = "fusermount3"; /* Arch Linux utility */
+ char cmd[] = "fusermount3"; /* Arch Linux utility */
static bool found = FALSE;
char *tmp = name;
struct stat sb, psb;
char *tmp = utils[LOCKER];
if (!getutil(tmp))
- tmp = utils[CMATRIX];;
+ tmp = utils[CMATRIX];
spawn(tmp, NULL, NULL, NULL, F_NORMAL);
}
"9! ^] Shell C Execute entry\n"
"9R ^V Pick plugin :K xK Execute plugin K\n"
"cU Manage session = Launch\n"
- "cc SSHFS mount u Unmount\n"
+ "cc SSHFS mount u Unmount\n"
"b^P Prompt/run cmd L Lock\n"};
fd = create_tmp_file();
if (fd == -1)
return;
- if (!(fp = fdopen(fd, "w"))) {
+
+ fp = fdopen(fd, "w");
+ if (!fp) {
close(fd);
return;
}
unlink(g_tmpfpath);
}
-static bool plctrl_init()
+static bool plctrl_init(void)
{
snprintf(g_buf, CMD_LEN_MAX, "nnn-pipe.%d", getpid());
mkpath(g_tmpfpath, g_buf, g_pipepath);
static bool run_selected_plugin(char **path, const char *file, char *newpath, char *rundir, char *runfile, char **lastname, char **lastdir)
{
+ int fd;
+ size_t len;
+
if (!g_plinit) {
plctrl_init();
g_plinit = TRUE;
|| (strcmp(*path, plugindir) != 0))
return FALSE;
- int fd = open(g_pipepath, O_RDONLY | O_NONBLOCK);
+ fd = open(g_pipepath, O_RDONLY | O_NONBLOCK);
if (fd == -1)
return FALSE;
rundir[0] = '\0';
cfg.runplugin = 0;
- size_t len = read(fd, g_buf, PATH_MAX);
+ len = read(fd, g_buf, PATH_MAX);
g_buf[len] = '\0';
close(fd);
xstrlcpy(*path, g_buf + 1, PATH_MAX);
} else if (ctx >= 1 && ctx <= CTX_MAX) {
int r = ctx - 1;
+
g_ctx[r].c_cfg.ctxactive = 0;
savecurctx(&cfg, g_buf + 1, dents[cur].name, r);
*path = g_ctx[r].c_path;
for (count = 1; count < n; ++dentp, ++count)
/* Current filename starts at last filename start + length */
- (dentp + 1)->name = (char *)((size_t)dentp->name
- + dentp->nlen);
+ (dentp + 1)->name = (char *)((size_t)dentp->name + dentp->nlen);
}
}
/* Copy other fields */
dentp->t = cfg.mtime ? sb.st_mtime : sb.st_atime;
-#ifdef __sun
- if (0) { /* no d_type */
-#else
- if (!flags && dp->d_type == DT_LNK) { /* Do not add sizes for links */
-#endif
+#ifndef __sun
+ if (!flags && dp->d_type == DT_LNK) {
/* Do not add sizes for links */
dentp->mode = (sb.st_mode & ~S_IFMT) | S_IFLNK;
dentp->size = 0;
dentp->mode = sb.st_mode;
dentp->size = sb.st_size;
}
+#else
+ dentp->mode = sb.st_mode;
+ dentp->size = sb.st_size;
+#endif
dentp->flags = 0;
if (cfg.blkorder) {
cfg.dircolor = 1;
/* Print listing */
- for (i = curscroll; i < ndents && i < curscroll + onscreen; ++i) {
+ for (i = curscroll; i < ndents && i < curscroll + onscreen; ++i)
printptr(&dents[i], i == cur, ncols);
- }
/* Must reset e.g. no files in dir */
if (cfg.dircolor) {
struct stat sb;
char *path, *lastdir, *lastname, *dir, *tmp;
MEVENT event;
- struct timespec mousetimings[2] = {{.tv_sec = 0, .tv_nsec = 0}, {.tv_sec = 0, .tv_nsec = 0}};
+ struct timespec mousetimings[2] = {{.tv_sec = 0, .tv_nsec = 0}, {.tv_sec = 0, .tv_nsec = 0} };
bool currentmouse = 1;
atexit(dentfree);
/* If clicked after contexts, go to parent */
if (r >= CTX_MAX)
sel = SEL_BACK;
- else if (0 <= r && r < CTX_MAX && r != cfg.curctx) {
+ else if (r >= 0 && r < CTX_MAX && r != cfg.curctx) {
savecurctx(&cfg, path, dents[cur].name, r);
/* Reset the pointers */
}
/* Handle clicking on a file */
- if (2 <= event.y && event.y <= ndents + 1 && event.bstate == BUTTON1_PRESSED) {
+ if (event.y >= 2 && event.y <= ndents + 1 && event.bstate == BUTTON1_PRESSED) {
r = curscroll + (event.y - 2);
move_cursor(r, 1);
currentmouse ^= 1;
}
}
if (r != ndents)
- continue;;
+ continue;
goto nochange;
case '.':
cfg.showhidden ^= 1;
printwait(messages[NONE_SELECTED], &presel);
goto nochange;
case SEL_SELEDIT:
- if (!editselection()){
+ if (!editselection()) {
printwait(messages[OPERATION_FAILED], &presel);
goto nochange;
}
goto nochange;
}
- if (sel == SEL_PLUGKEY)
- {
+ if (sel == SEL_PLUGKEY) {
r = get_input("");
tmp = get_kv_val(plug, NULL, r, PLUGIN_MAX, FALSE);
if (!tmp)
return TRUE;
}
-static bool set_tmp_path()
+static bool set_tmp_path(void)
{
char *path;
if (optarg[0] == '-' && optarg[1] == '\0')
cfg.pickraw = 1;
else {
- int fd = open(optarg, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
+ int fd = open(optarg, O_WRONLY | O_CREAT, 0600);
if (fd == -1) {
xerror();
}
if (arg) { /* Open a bookmark directly */
- if (arg[1] || (initpath = get_kv_val(bookmark, NULL, *arg, BM_MAX, TRUE)) == NULL) {
+ if (!arg[1]) /* Bookmarks keys are single char */
+ initpath = get_kv_val(bookmark, NULL, *arg, BM_MAX, TRUE);
+
+ if (!initpath) {
fprintf(stderr, "%s\n", messages[STR_INVBM_KEY]);
return _FAILURE;
}