about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorRory Bradford <roryrjb@gmail.com>2020-08-02 12:32:14 +0100
committerRory Bradford <roryrjb@gmail.com>2020-08-02 12:32:14 +0100
commit69631ff66e5afa6993037b60e2db4348a2f7b718 (patch)
treecdf124689685d9eebf96bc73d7ad1156d82fb0be
parent4120bca8530b87747b44efec0552b946b60d657e (diff)
downloadrf-69631ff66e5afa6993037b60e2db4348a2f7b718.tar.gz
Various minor improvements
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
-rw-r--r--Makefile4
-rw-r--r--ignore.c2
-rw-r--r--ignore.h5
-rw-r--r--rf.c38
4 files changed, 23 insertions, 26 deletions
diff --git a/Makefile b/Makefile
index f499b2d..14a80e9 100644
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,8 @@ VERSION = 0.0.5
 OBJS = rf.o ignore.o
 PREFIX = /usr/local
 CC = cc
-CFLAGS = -std=c99 -O2 \
-	  -Wpedantic -Wall \
+CFLAGS = -std=c99 -pedantic -O2 \
+	  -Wall -Wextra -Wsign-compare \
 	  -fstack-protector-strong -fpie \
 	  -D_FORTIFY_SOURCE=2 \
 	  -DVERSION='"$(VERSION)"' \
diff --git a/ignore.c b/ignore.c
index b4cef61..d7b6428 100644
--- a/ignore.c
+++ b/ignore.c
@@ -27,7 +27,7 @@ struct ignores *init_ignores(char *path) {
 		while ((r = getline(&line, &llen, ignore)) != -1) {
 			char *l = calloc(sizeof(char *), strlen(line) - 1);
 
-			for (int j = 0, k = 0; j < strlen(line); j++) {
+			for (size_t j = 0, k = 0; j < strlen(line); j++) {
 				char c = line[j];
 
 				if (isspace(c)) {
diff --git a/ignore.h b/ignore.h
index 9ae5c6f..1bc3add 100644
--- a/ignore.h
+++ b/ignore.h
@@ -1,3 +1,6 @@
+#ifndef RF_IGNORE_H
+#define RF_IGNORE_H
+
 #define IGNORE_SIZE 100
 
 struct ignores {
@@ -8,3 +11,5 @@ struct ignores {
 struct ignores *init_ignores(char *path);
 
 void free_ignores(struct ignores *ignores);
+
+#endif
diff --git a/rf.c b/rf.c
index 5d412c3..b183ecd 100644
--- a/rf.c
+++ b/rf.c
@@ -78,13 +78,6 @@ static int excluded(char *name) {
 	return 0;
 }
 
-static void handle_result(
-	char *full_path, struct switches *switches, struct dirent *entry) {
-	if (is_child(entry->d_name) != 0) {
-		printf("%s\n", full_path);
-	}
-}
-
 /* return 1 if breaking early (e.g. reaching limit) otherwise return 0 */
 static int recurse_find(char **patterns, int *pattern_count, char *dirname,
 	struct switches *switches) {
@@ -123,38 +116,37 @@ static int recurse_find(char **patterns, int *pattern_count, char *dirname,
 				}
 			} else if (entry_stat.st_mode & S_IFREG) {
 				if (excluded(entry->d_name)) {
-					matched = 0;
 					continue;
 				}
 
 				for (; p < *pattern_count; p++) {
 					char *pattern = patterns[p];
 
-					if (switches->substring) {
-						if (strstr(
-								switches->wholename ? full_path : entry->d_name,
-								pattern) != NULL) {
-							matched = 1;
-						}
-					} else {
-						if (fnmatch(pattern,
-								switches->wholename ? full_path : entry->d_name,
-								0) == 0) {
-							matched = 1;
-						}
+					if (switches->substring &&
+						(strstr(switches->wholename ? full_path : entry->d_name,
+							 pattern) != NULL)) {
+						matched = 1;
+					} else if (fnmatch(pattern,
+								   switches->wholename ? full_path
+													   : entry->d_name,
+								   0) == 0) {
+						matched = 1;
 					}
 				}
 
 				if (switches->invert) {
-					if (matched)
+					if (matched) {
 						matched = 0;
-					else
+					} else {
 						matched = 1;
+					}
 				}
 			}
 
 			if (matched) {
-				handle_result(full_path, switches, entry);
+				if (is_child(entry->d_name) != 0) {
+					printf("%s\n", full_path);
+				}
 
 				if (switches->limit > 0 &&
 					++switches->count == switches->limit) {