about summary refs log tree commit diff stats
path: root/ignore.c
diff options
context:
space:
mode:
authorRory Bradford <roryrjb@gmail.com>2020-04-18 22:19:52 +0100
committerRory Bradford <roryrjb@gmail.com>2020-04-18 22:19:52 +0100
commit4120bca8530b87747b44efec0552b946b60d657e (patch)
tree48e8199baf2ee87d528b7154eef7f76913cf6a54 /ignore.c
parent0017f896237b0a9b379ba102acfa8dafd5ea87a1 (diff)
downloadrf-4120bca8530b87747b44efec0552b946b60d657e.tar.gz
Add wholename option
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
Diffstat (limited to 'ignore.c')
-rw-r--r--ignore.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/ignore.c b/ignore.c
new file mode 100644
index 0000000..b4cef61
--- /dev/null
+++ b/ignore.c
@@ -0,0 +1,67 @@
+
+#define _POSIX_C_SOURCE 200809L
+#define _XOPEN_SOURCE 600
+
+#include <ctype.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "ignore.h"
+
+static int total_size;
+
+struct ignores *init_ignores(char *path) {
+	total_size = IGNORE_SIZE;
+	struct ignores *ignores = calloc(sizeof(struct ignores), 1);
+	ignores->list = calloc(sizeof(char *), IGNORE_SIZE);
+	ignores->size = 0;
+
+	int i = 0;
+	FILE *ignore = fopen(path, "r");
+	char *line = NULL;
+	size_t llen = 0;
+	ssize_t r;
+
+	if (ignore != NULL) {
+		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++) {
+				char c = line[j];
+
+				if (isspace(c)) {
+					break;
+				}
+
+				l[k++] = c;
+			}
+
+			if (i + 1 > total_size) {
+				ignores->list = realloc(
+					ignores->list, sizeof(char *) * (total_size + IGNORE_SIZE));
+				total_size += IGNORE_SIZE;
+			}
+
+			ignores->list[i++] = l;
+		}
+
+		free(line);
+		fclose(ignore);
+	}
+
+	ignores->size = i;
+
+	return ignores;
+}
+
+void free_ignores(struct ignores *ignores) {
+	if (ignores->size > 0) {
+		for (int i = 0; i < ignores->size; i++) {
+			free(ignores->list[i]);
+		}
+	}
+
+	free(ignores->list);
+	free(ignores);
+}