mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Remove redundant variables, function calls
This commit is contained in:
parent
95cdb78c6c
commit
7727b745ed
64
nnn.c
64
nnn.c
|
@ -11,6 +11,7 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
|
#include <libgen.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#ifdef __gnu_hurd__
|
#ifdef __gnu_hurd__
|
||||||
#define PATH_MAX 4096
|
#define PATH_MAX 4096
|
||||||
|
@ -176,7 +177,6 @@ static char g_buf[MAX_CMD_LEN];
|
||||||
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 int dentfind(struct entry *dents, int n, char *path);
|
|
||||||
static void redraw(char *path);
|
static void redraw(char *path);
|
||||||
|
|
||||||
static rlim_t
|
static rlim_t
|
||||||
|
@ -225,7 +225,7 @@ xmemrchr(const void *s, int c, size_t n)
|
||||||
|
|
||||||
p = (unsigned char *)s + n - 1;
|
p = (unsigned char *)s + n - 1;
|
||||||
|
|
||||||
while(n--)
|
while (n--)
|
||||||
if ((*p--) == ch)
|
if ((*p--) == ch)
|
||||||
return ++p;
|
return ++p;
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ xstricmp(char *s1, char *s2)
|
||||||
c1++;
|
c1++;
|
||||||
if (*c1 == '-' || *c1 == '+')
|
if (*c1 == '-' || *c1 == '+')
|
||||||
c1++;
|
c1++;
|
||||||
while(*c1 >= '0' && *c1 <= '9')
|
while (*c1 >= '0' && *c1 <= '9')
|
||||||
c1++;
|
c1++;
|
||||||
|
|
||||||
c2 = s2;
|
c2 = s2;
|
||||||
|
@ -617,6 +617,7 @@ nextsel(char **run, char **env, int *ch)
|
||||||
*env = bindings[i].env;
|
*env = bindings[i].env;
|
||||||
return bindings[i].act;
|
return bindings[i].act;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -871,22 +872,20 @@ coolsize(off_t size)
|
||||||
static const char *size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
|
static const char *size_units[] = {"B", "K", "M", "G", "T", "P", "E", "Z", "Y"};
|
||||||
static char size_buf[12]; /* Buffer to hold human readable size */
|
static char size_buf[12]; /* Buffer to hold human readable size */
|
||||||
static int i;
|
static int i;
|
||||||
static off_t fsize, tmp;
|
static off_t tmp;
|
||||||
static long double rem;
|
static long double rem;
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
fsize = size;
|
|
||||||
rem = 0;
|
rem = 0;
|
||||||
|
|
||||||
while (fsize > 1024) {
|
while (size > 1024) {
|
||||||
tmp = fsize;
|
tmp = size;
|
||||||
//fsize *= div_2_pow_10;
|
size >>= 10;
|
||||||
fsize >>= 10;
|
rem = tmp - (size << 10);
|
||||||
rem = tmp - (fsize << 10);
|
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(size_buf, 12, "%.*Lf%s", i, fsize + rem * div_2_pow_10, size_units[i]);
|
snprintf(size_buf, 12, "%.*Lf%s", i, size + rem * div_2_pow_10, size_units[i]);
|
||||||
return size_buf;
|
return size_buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1259,7 +1258,7 @@ show_help(void)
|
||||||
static int
|
static int
|
||||||
sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
|
sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
|
||||||
{
|
{
|
||||||
if(typeflag == FTW_F || typeflag == FTW_D)
|
if (typeflag == FTW_F || typeflag == FTW_D)
|
||||||
blk_size += sb->st_blocks;
|
blk_size += sb->st_blocks;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1306,9 +1305,8 @@ dentfill(char *path, struct entry **dents,
|
||||||
static DIR *dirp;
|
static DIR *dirp;
|
||||||
static struct dirent *dp;
|
static struct dirent *dp;
|
||||||
static struct stat sb;
|
static struct stat sb;
|
||||||
static struct statvfs svb;
|
static int n;
|
||||||
static int r, n;
|
n = 0;
|
||||||
r = n = 0;
|
|
||||||
|
|
||||||
dirp = opendir(path);
|
dirp = opendir(path);
|
||||||
if (dirp == NULL)
|
if (dirp == NULL)
|
||||||
|
@ -1333,8 +1331,7 @@ dentfill(char *path, struct entry **dents,
|
||||||
xstrlcpy((*dents)[n].name, dp->d_name, NAME_MAX);
|
xstrlcpy((*dents)[n].name, dp->d_name, NAME_MAX);
|
||||||
/* Get mode flags */
|
/* Get mode flags */
|
||||||
mkpath(path, dp->d_name, newpath, PATH_MAX);
|
mkpath(path, dp->d_name, newpath, PATH_MAX);
|
||||||
r = lstat(newpath, &sb);
|
if (lstat(newpath, &sb) == -1) {
|
||||||
if (r == -1) {
|
|
||||||
if (*dents)
|
if (*dents)
|
||||||
free(*dents);
|
free(*dents);
|
||||||
printerr(1, "lstat");
|
printerr(1, "lstat");
|
||||||
|
@ -1359,20 +1356,20 @@ dentfill(char *path, struct entry **dents,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bsizeorder) {
|
if (bsizeorder) {
|
||||||
r = statvfs(path, &svb);
|
static struct statvfs svb;
|
||||||
if (r == -1)
|
if (statvfs(path, &svb) == -1)
|
||||||
fs_free = 0;
|
fs_free = 0;
|
||||||
else
|
else
|
||||||
fs_free = svb.f_bavail << getorder(svb.f_bsize);
|
fs_free = svb.f_bavail << getorder(svb.f_bsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Should never be null */
|
/* Should never be null */
|
||||||
r = closedir(dirp);
|
if (closedir(dirp) == -1) {
|
||||||
if (r == -1) {
|
|
||||||
if (*dents)
|
if (*dents)
|
||||||
free(*dents);
|
free(*dents);
|
||||||
printerr(1, "closedir");
|
printerr(1, "closedir");
|
||||||
}
|
}
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1392,14 +1389,7 @@ dentfind(struct entry *dents, int n, char *path)
|
||||||
static int i;
|
static int i;
|
||||||
static char *p;
|
static char *p;
|
||||||
|
|
||||||
p = xmemrchr(path, '/', strlen(path));
|
p = basename(path);
|
||||||
if (!p)
|
|
||||||
p = path;
|
|
||||||
else
|
|
||||||
/* We are assuming an entry with actual
|
|
||||||
name ending in '/' will not appear */
|
|
||||||
p++;
|
|
||||||
|
|
||||||
DPRINTF_S(p);
|
DPRINTF_S(p);
|
||||||
|
|
||||||
for (i = 0; i < n; i++)
|
for (i = 0; i < n; i++)
|
||||||
|
@ -1413,15 +1403,13 @@ static int
|
||||||
populate(char *path, char *oldpath, char *fltr)
|
populate(char *path, char *oldpath, char *fltr)
|
||||||
{
|
{
|
||||||
static regex_t re;
|
static regex_t re;
|
||||||
static int r;
|
|
||||||
|
|
||||||
/* Can fail when permissions change while browsing */
|
/* Can fail when permissions change while browsing */
|
||||||
if (canopendir(path) == 0)
|
if (canopendir(path) == 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* Search filter */
|
/* Search filter */
|
||||||
r = setfilter(&re, fltr);
|
if (setfilter(&re, fltr) != 0)
|
||||||
if (r != 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ndents = dentfill(path, &dents, visible, &re);
|
ndents = dentfill(path, &dents, visible, &re);
|
||||||
|
@ -1437,8 +1425,7 @@ static void
|
||||||
redraw(char *path)
|
redraw(char *path)
|
||||||
{
|
{
|
||||||
static char cwd[PATH_MAX];
|
static char cwd[PATH_MAX];
|
||||||
static int nlines, odd;
|
static int nlines, i;
|
||||||
static int i;
|
|
||||||
static size_t ncols;
|
static size_t ncols;
|
||||||
|
|
||||||
nlines = MIN(LINES - 4, ndents);
|
nlines = MIN(LINES - 4, ndents);
|
||||||
|
@ -1469,7 +1456,6 @@ redraw(char *path)
|
||||||
printw(CWD "%s\n\n", cwd);
|
printw(CWD "%s\n\n", cwd);
|
||||||
|
|
||||||
/* Print listing */
|
/* Print listing */
|
||||||
odd = ISODD(nlines);
|
|
||||||
if (cur < (nlines >> 1)) {
|
if (cur < (nlines >> 1)) {
|
||||||
for (i = 0; i < nlines; i++)
|
for (i = 0; i < nlines; i++)
|
||||||
printptr(&dents[i], i == cur);
|
printptr(&dents[i], i == cur);
|
||||||
|
@ -1477,6 +1463,8 @@ redraw(char *path)
|
||||||
for (i = ndents - nlines; i < ndents; i++)
|
for (i = ndents - nlines; i < ndents; i++)
|
||||||
printptr(&dents[i], i == cur);
|
printptr(&dents[i], i == cur);
|
||||||
} else {
|
} else {
|
||||||
|
static int odd;
|
||||||
|
odd = ISODD(nlines);
|
||||||
nlines >>= 1;
|
nlines >>= 1;
|
||||||
for (i = cur - nlines; i < cur + nlines + odd; i++)
|
for (i = cur - nlines; i < cur + nlines + odd; i++)
|
||||||
printptr(&dents[i], i == cur);
|
printptr(&dents[i], i == cur);
|
||||||
|
@ -1564,17 +1552,19 @@ nochange:
|
||||||
fprintf(fp, "cd \"%s\"", path);
|
fprintf(fp, "cd \"%s\"", path);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Fall through to exit */
|
||||||
}
|
}
|
||||||
case SEL_QUIT:
|
case SEL_QUIT:
|
||||||
dentfree(dents);
|
dentfree(dents);
|
||||||
return;
|
return;
|
||||||
case SEL_BACK:
|
case SEL_BACK:
|
||||||
/* There is no going back */
|
/* There is no going back */
|
||||||
if (strcmp(path, "/") == 0 ||
|
if (path[0] == '/' && path[1] == '\0') {
|
||||||
strchr(path, '/') == NULL) {
|
|
||||||
printmsg("You are at /");
|
printmsg("You are at /");
|
||||||
goto nochange;
|
goto nochange;
|
||||||
}
|
}
|
||||||
|
|
||||||
dir = xdirname(path);
|
dir = xdirname(path);
|
||||||
if (canopendir(dir) == 0) {
|
if (canopendir(dir) == 0) {
|
||||||
printwarn();
|
printwarn();
|
||||||
|
|
Loading…
Reference in a new issue