From ed55fbd9d551215e38d85f729456367826f008dc Mon Sep 17 00:00:00 2001 From: Arun Prakash Jana Date: Mon, 5 Apr 2021 21:49:14 +0530 Subject: [PATCH] Compact switch cases --- src/nnn.c | 55 +++++++++++++++++++------------------------------------ 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/src/nnn.c b/src/nnn.c index b9dd483b..73f1acab 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -3601,19 +3601,13 @@ static void print_time(const time_t *timep) static char get_detail_ind(const struct entry *ent) { switch (ent->mode & S_IFMT) { - case S_IFDIR: - case S_IFREG: - return ' '; - case S_IFLNK: - return '@'; - case S_IFSOCK: - return '='; - case S_IFIFO: - return '|'; - case S_IFBLK: - return 'b'; - case S_IFCHR: - return 'c'; + case S_IFDIR: // fallthrough + case S_IFREG: return ' '; + case S_IFLNK: return '@'; + case S_IFSOCK: return '='; + case S_IFIFO: return '|'; + case S_IFBLK: return 'b'; + case S_IFCHR: return 'c'; } return '?'; } @@ -3621,19 +3615,13 @@ static char get_detail_ind(const struct entry *ent) static char get_name_ind(const struct entry *ent) { switch (ent->mode & S_IFMT) { - case S_IFREG: - return (ent->mode & 0100) ? '*' : '\0'; - case S_IFDIR: - return '/'; - case S_IFLNK: - return (ent->flags & DIR_OR_LINK_TO_DIR) ? '/' : '@'; - case S_IFSOCK: - return '='; - case S_IFIFO: - return '|'; - case S_IFBLK: - case S_IFCHR: - return '\0'; + case S_IFREG: return (ent->mode & 0100) ? '*' : '\0'; + case S_IFDIR: return '/'; + case S_IFLNK: return (ent->flags & DIR_OR_LINK_TO_DIR) ? '/' : '@'; + case S_IFSOCK: return '='; + case S_IFIFO: return '|'; + case S_IFBLK: // fallthrough + case S_IFCHR: return '\0'; } return '?'; } @@ -3653,16 +3641,11 @@ static uchar_t get_color_pair(const struct entry *ent, bool detailed) if (!g_state.oldcolor || detailed) return (ent->flags & SYM_ORPHAN) ? C_ORP : C_LNK; return 0; - case S_IFDIR: - return (!g_state.oldcolor && g_state.dirctx) ? cfg.curctx + 1 : C_DIR; - case S_IFSOCK: - return C_SOC; - case S_IFIFO: - return C_PIP; - case S_IFBLK: - return C_BLK; - case S_IFCHR: - return C_CHR; + case S_IFDIR: return (!g_state.oldcolor && g_state.dirctx) ? cfg.curctx + 1 : C_DIR; + case S_IFSOCK: return C_SOC; + case S_IFIFO: return C_PIP; + case S_IFBLK: return C_BLK; + case S_IFCHR: return C_CHR; } return C_UND; }