From 06ff2c55da3d2ce110c91f0ca344ac7e58b25914 Mon Sep 17 00:00:00 2001 From: Anna Arad <4895022+annagrram@users.noreply.github.com> Date: Sun, 13 Oct 2019 16:40:06 +0300 Subject: [PATCH] Remove -Wno-unused-parameter and do cleanup (#357) --- Makefile | 2 +- src/nnn.c | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 136da5f..2c1a391 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,7 @@ else LDLIBS_CURSES ?= -lncurses endif -CFLAGS += -Wall -Wextra -Wno-unused-parameter +CFLAGS += -Wall -Wextra CFLAGS += $(CFLAGS_OPTIMIZATION) CFLAGS += $(CFLAGS_CURSES) diff --git a/src/nnn.c b/src/nnn.c index 5d42802..4a9f0c2 100644 --- a/src/nnn.c +++ b/src/nnn.c @@ -200,6 +200,11 @@ typedef struct { char *val; } kv; +typedef struct { + const regex_t *regex; + const char *str; +} fltrexp_t; + /* * Settings * NOTE: update default values if changing order @@ -477,6 +482,8 @@ static bool getutil(char *util); static void sigint_handler(int sig) { + (void) sig; + interrupted = TRUE; } @@ -1548,17 +1555,17 @@ static int setfilter(regex_t *regex, const char *filter) return r; } -static int visible_re(regex_t *regex, const char *fname, const char *fltr) +static int visible_re(const fltrexp_t *fltrexp, const char *fname) { - return regexec(regex, fname, 0, NULL, 0) == 0; + return regexec(fltrexp->regex, fname, 0, NULL, 0) == 0; } -static int visible_str(regex_t *regex, const char *fname, const char *fltr) +static int visible_str(const fltrexp_t *fltrexp, const char *fname) { - return strcasestr(fname, fltr) != NULL; + return strcasestr(fname, fltrexp->str) != NULL; } -static int (*filterfn)(regex_t *regex, const char *fname, const char *fltr) = &visible_re; +static int (*filterfn)(const fltrexp_t *fltr, const char *fname) = &visible_re; static int entrycmp(const void *va, const void *vb) { @@ -1704,9 +1711,10 @@ static inline void swap_ent(int id1, int id2) static int fill(const char *fltr, regex_t *re) { int count = 0; + fltrexp_t fltrexp = { .regex = re, .str = fltr }; for (; count < ndents; ++count) { - if (filterfn(re, dents[count].name, fltr) == 0) { + if (filterfn(&fltrexp, dents[count].name) == 0) { if (count != --ndents) { swap_ent(count, ndents); --count; @@ -2650,7 +2658,7 @@ static void pipetofd(char *cmd, int fd) /* * Follows the stat(1) output closely */ -static bool show_stats(const char *fpath, const char *fname, const struct stat *sb) +static bool show_stats(const char *fpath, const struct stat *sb) { int fd; char *p, *begin = g_buf; @@ -3048,6 +3056,9 @@ static void show_help(const char *path) static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { + (void) fpath; + (void) ftwbuf; + if (sb->st_blocks && (typeflag == FTW_F || typeflag == FTW_D)) ent_blocks += sb->st_blocks; @@ -3057,6 +3068,9 @@ static int sum_bsizes(const char *fpath, const struct stat *sb, int typeflag, st static int sum_sizes(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) { + (void) fpath; + (void) ftwbuf; + if (sb->st_size && (typeflag == FTW_F || typeflag == FTW_D)) ent_blocks += sb->st_size; @@ -4126,7 +4140,7 @@ nochange: break; mkpath(path, dents[cur].name, newpath); - if (lstat(newpath, &sb) == -1 || !show_stats(newpath, dents[cur].name, &sb)) { + if (lstat(newpath, &sb) == -1 || !show_stats(newpath, &sb)) { printwarn(&presel); goto nochange; }