mirror of
https://github.com/jarun/nnn.git
synced 2024-11-24 11:51:27 +00:00
Use a single routine for common code
This commit is contained in:
parent
b3132d6398
commit
a44b23786f
55
src/nnn.c
55
src/nnn.c
|
@ -3421,6 +3421,24 @@ static char *unescape(const char *str, uint_t maxcols)
|
|||
}
|
||||
#endif
|
||||
|
||||
static off_t get_size(off_t size, off_t *pval, uint_t comp)
|
||||
{
|
||||
off_t rem = *pval;
|
||||
off_t quo = rem / 10;
|
||||
|
||||
if ((rem - (quo * 10)) >= 5) {
|
||||
rem = quo + 1;
|
||||
if (rem == comp) {
|
||||
++size;
|
||||
rem = 0;
|
||||
}
|
||||
} else
|
||||
rem = quo;
|
||||
|
||||
*pval = rem;
|
||||
return size;
|
||||
}
|
||||
|
||||
static char *coolsize(off_t size)
|
||||
{
|
||||
const char * const U = "BKMGTPEZY";
|
||||
|
@ -3437,38 +3455,14 @@ static char *coolsize(off_t size)
|
|||
|
||||
if (i == 1) {
|
||||
rem = (rem * 1000) >> 10;
|
||||
|
||||
rem /= 10;
|
||||
if (rem % 10 >= 5) {
|
||||
rem = (rem / 10) + 1;
|
||||
if (rem == 10) {
|
||||
++size;
|
||||
rem = 0;
|
||||
}
|
||||
} else
|
||||
rem /= 10;
|
||||
size = get_size(size, &rem, 10);
|
||||
} else if (i == 2) {
|
||||
rem = (rem * 1000) >> 10;
|
||||
|
||||
if (rem % 10 >= 5) {
|
||||
rem = (rem / 10) + 1;
|
||||
if (rem == 100) {
|
||||
++size;
|
||||
rem = 0;
|
||||
}
|
||||
} else
|
||||
rem /= 10;
|
||||
} else if (i > 0) {
|
||||
size = get_size(size, &rem, 100);
|
||||
} else if (i > 2) {
|
||||
rem = (rem * 10000) >> 10;
|
||||
|
||||
if (rem % 10 >= 5) {
|
||||
rem = (rem / 10) + 1;
|
||||
if (rem == 1000) {
|
||||
++size;
|
||||
rem = 0;
|
||||
}
|
||||
} else
|
||||
rem /= 10;
|
||||
size = get_size(size, &rem, 1000);
|
||||
}
|
||||
|
||||
if (i > 0 && i < 6 && rem) {
|
||||
|
@ -3718,7 +3712,6 @@ static void printent(const struct entry *ent, uint_t namecols, bool sel)
|
|||
attrs |= A_REVERSE;
|
||||
if (attrs)
|
||||
attron(attrs);
|
||||
|
||||
if (!ind)
|
||||
++namecols;
|
||||
|
||||
|
@ -5690,7 +5683,7 @@ static void draw_line(char *path, int ncols)
|
|||
}
|
||||
|
||||
move(2 + last - curscroll, 0);
|
||||
printptr(&pdents[last], ncols, false);
|
||||
printptr(&pdents[last], ncols, FALSE);
|
||||
|
||||
if (g_state.oldcolor && (pdents[cur].flags & DIR_OR_LINK_TO_DIR)) {
|
||||
if (!dir) {/* First file is not a directory */
|
||||
|
@ -5703,7 +5696,7 @@ static void draw_line(char *path, int ncols)
|
|||
}
|
||||
|
||||
move(2 + cur - curscroll, 0);
|
||||
printptr(&pdents[cur], ncols, true);
|
||||
printptr(&pdents[cur], ncols, TRUE);
|
||||
|
||||
/* Must reset e.g. no files in dir */
|
||||
if (dir)
|
||||
|
|
Loading…
Reference in a new issue