Browse Source

Code reformat

master
Arun Prakash Jana 4 years ago
parent
commit
b1ff36eb05
No known key found for this signature in database GPG Key ID: A75979F35C080412
1 changed files with 83 additions and 68 deletions
  1. +83
    -68
      src/nnn.c

+ 83
- 68
src/nnn.c View File

@@ -3360,59 +3360,38 @@ static char *coolsize(off_t size)
return size_buf; return size_buf;
} }


static char get_ind(mode_t mode, bool perms, uchar *pair) /* Convert a mode field into "ls -l" type perms field. */
static char *get_lsperms(mode_t mode)
{ {
static const char * const rwx[] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
static char bits[11] = {'\0'};

switch (mode & S_IFMT) { switch (mode & S_IFMT) {
case S_IFREG: case S_IFREG:
if (perms) bits[0] = '-';
return '-'; break;
if (mode & 0100) {
*pair = C_EXE;
return '*';
}
*pair = C_FIL;
return '\0';
case S_IFDIR: case S_IFDIR:
if (perms) bits[0] = 'd';
return 'd'; break;
*pair = C_DIR;
return '/';
case S_IFLNK: case S_IFLNK:
return perms ? 'l' : '@'; bits[0] = 'l';
break;
case S_IFSOCK: case S_IFSOCK:
if (perms) bits[0] = 's';
return 's'; break;
*pair = C_SOC;
return '=';
case S_IFIFO: case S_IFIFO:
if (perms) bits[0] = 'p';
return 'p'; break;
*pair = C_PIP;
return '|';
case S_IFBLK: case S_IFBLK:
if (perms) bits[0] = 'b';
return 'b'; break;
*pair = C_BLK;
return '\0';
case S_IFCHR: case S_IFCHR:
if (perms) bits[0] = 'c';
return 'c'; break;
*pair = C_CHR;
return '\0';
default: default:
if (!perms) bits[0] = '?';
*pair = C_UND; break;
return '?';
} }
}

/* Convert a mode field into "ls -l" type perms field. */
static char *get_lsperms(mode_t mode)
{
static const char * const rwx[] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
static char bits[11] = {'\0'};

bits[0] = get_ind(mode, TRUE, NULL);


xstrsncpy(&bits[1], rwx[(mode >> 6) & 7], 4); xstrsncpy(&bits[1], rwx[(mode >> 6) & 7], 4);
xstrsncpy(&bits[4], rwx[(mode >> 3) & 7], 4); xstrsncpy(&bits[4], rwx[(mode >> 3) & 7], 4);
@@ -3439,30 +3418,63 @@ static void print_time(const time_t *timep)
static void printent(const struct entry *ent, uint namecols, bool sel) static void printent(const struct entry *ent, uint namecols, bool sel)
{ {
uchar pair = 0; uchar pair = 0;
char ind = get_ind(ent->mode, FALSE, &pair); char ind = '\0';
int attrs = sel ? A_REVERSE : 0; int attrs = sel ? A_REVERSE : 0;


if (g_state.ctxcolor) { switch (ent->mode & S_IFMT) {
if (ind == '@') { case S_IFREG:
if (ent->flags & DIR_OR_LINK_TO_DIR) if (ent->mode & 0100) {
ind = '/'; pair = C_EXE;
attrs |= A_DIM; ind = '*';
} else if (ent->flags & HARD_LINK) }
attrs |= A_DIM; if (ent->flags & HARD_LINK)
} else { pair = C_HRD;
if (ind == '@') { if (!ent->size)
if (ent->flags & DIR_OR_LINK_TO_DIR) {
ind = '/';
attrs |= A_BOLD;
}
pair = (ent->flags & SYM_ORPHAN) ? C_ORP : C_LNK;
} else if (!ent->size && (pair == C_FIL || pair == C_EXE))
pair = C_UND; pair = C_UND;
else if (pair == C_DIR) else if (!pair)
pair = C_FIL;
break;
case S_IFDIR:
pair = C_DIR;
attrs |= A_BOLD;
ind = '/';
break;
case S_IFLNK:
if (ent->flags & DIR_OR_LINK_TO_DIR) {
attrs |= A_BOLD; attrs |= A_BOLD;
else if (ent->flags & HARD_LINK) ind = '/';
pair = C_HRD; } else
else if (ent->flags & FILE_MISSING) ind = '@';

if (g_state.ctxcolor)
attrs |= A_DIM;
else
pair = (ent->flags & SYM_ORPHAN) ? C_ORP : C_LNK;
break;
case S_IFSOCK:
pair = C_SOC;
ind = '=';
break;
case S_IFIFO:
pair = C_PIP;
ind = '|';
break;
case S_IFBLK:
pair = C_BLK;
break;
case S_IFCHR:
pair = C_CHR;
break;
default:
pair = C_UND;
ind = '?';
break;
}

if (!g_state.ctxcolor) {
if (ent->flags & FILE_MISSING)
pair = C_MIS; pair = C_MIS;


if (pair && fcolors[pair]) if (pair && fcolors[pair])
@@ -3532,6 +3544,7 @@ static void printent_long(const struct entry *ent, uint namecols, bool sel)
pair = C_EXE; pair = C_EXE;
ind2 = '*'; ind2 = '*';
} }

if (ent->flags & HARD_LINK) { if (ent->flags & HARD_LINK) {
pair = C_HRD; pair = C_HRD;
ln = TRUE; ln = TRUE;
@@ -3589,17 +3602,19 @@ static void printent_long(const struct entry *ent, uint namecols, bool sel)
break; break;
} }


if (ent->flags & FILE_MISSING)
pair = C_MIS;

addstr(" "); addstr(" ");
if (!(ln && g_state.ctxcolor)) { if (!(ln && g_state.ctxcolor)) {
attroff(A_DIM); attroff(A_DIM);
attrs ^= A_DIM; attrs ^= A_DIM;


if (!g_state.ctxcolor && pair && fcolors[pair]) { if (!g_state.ctxcolor) {
attrs |= COLOR_PAIR(pair); if (ent->flags & FILE_MISSING)
attron(attrs); pair = C_MIS;

if (pair && fcolors[pair]) {
attrs |= COLOR_PAIR(pair);
attron(attrs);
}
} }
} }
#ifndef NOLOCALE #ifndef NOLOCALE


||||||
x
 
000:0
Loading…
Cancel
Save