Use a single routine for common code

This commit is contained in:
Arun Prakash Jana 2021-04-07 09:17:36 +05:30
parent b3132d6398
commit a44b23786f
No known key found for this signature in database
GPG key ID: A75979F35C080412

View file

@ -3421,6 +3421,24 @@ static char *unescape(const char *str, uint_t maxcols)
} }
#endif #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) static char *coolsize(off_t size)
{ {
const char * const U = "BKMGTPEZY"; const char * const U = "BKMGTPEZY";
@ -3437,38 +3455,14 @@ static char *coolsize(off_t size)
if (i == 1) { if (i == 1) {
rem = (rem * 1000) >> 10; rem = (rem * 1000) >> 10;
rem /= 10;
if (rem % 10 >= 5) {
rem = (rem / 10) + 1;
if (rem == 10) {
++size;
rem = 0;
}
} else
rem /= 10; rem /= 10;
size = get_size(size, &rem, 10);
} else if (i == 2) { } else if (i == 2) {
rem = (rem * 1000) >> 10; rem = (rem * 1000) >> 10;
size = get_size(size, &rem, 100);
if (rem % 10 >= 5) { } else if (i > 2) {
rem = (rem / 10) + 1;
if (rem == 100) {
++size;
rem = 0;
}
} else
rem /= 10;
} else if (i > 0) {
rem = (rem * 10000) >> 10; rem = (rem * 10000) >> 10;
size = get_size(size, &rem, 1000);
if (rem % 10 >= 5) {
rem = (rem / 10) + 1;
if (rem == 1000) {
++size;
rem = 0;
}
} else
rem /= 10;
} }
if (i > 0 && i < 6 && rem) { 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; attrs |= A_REVERSE;
if (attrs) if (attrs)
attron(attrs); attron(attrs);
if (!ind) if (!ind)
++namecols; ++namecols;
@ -5690,7 +5683,7 @@ static void draw_line(char *path, int ncols)
} }
move(2 + last - curscroll, 0); 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 (g_state.oldcolor && (pdents[cur].flags & DIR_OR_LINK_TO_DIR)) {
if (!dir) {/* First file is not a directory */ 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); move(2 + cur - curscroll, 0);
printptr(&pdents[cur], ncols, true); printptr(&pdents[cur], ncols, TRUE);
/* Must reset e.g. no files in dir */ /* Must reset e.g. no files in dir */
if (dir) if (dir)