about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorRory Bradford <roryrjb@gmail.com>2022-06-02 13:00:52 +0100
committerRory Bradford <roryrjb@gmail.com>2022-06-02 13:00:52 +0100
commitfa0fe3da2bad35c79d9588d5fc6c3e554671533e (patch)
tree3c6f7d2333961274576c719b1c36b01e171a05a3
parent49f55d4b648021ba143bbf058242e4553d285fea (diff)
downloadrf-fa0fe3da2bad35c79d9588d5fc6c3e554671533e.tar.gz
Remove config
Signed-off-by: Rory Bradford <roryrjb@gmail.com>
-rw-r--r--Makefile8
-rw-r--r--config.c82
-rw-r--r--config.default30
-rw-r--r--config.h14
-rw-r--r--rf.1.scd7
-rw-r--r--rf.c96
-rw-r--r--rfconfig.5.scd43
7 files changed, 4 insertions, 276 deletions
diff --git a/Makefile b/Makefile
index a0505b3..21fe5e7 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 
 BIN = rf
 VERSION = 0.0.5
-OBJS = rf.o ignore.o config.o include/common/strl.o
+OBJS = rf.o ignore.o include/common/strl.o
 PREFIX = /usr/local
 INCLUDE += -Iinclude/common
 CFLAGS := -std=c99 -pedantic -O2 \
@@ -26,10 +26,7 @@ rf.1: rf.1.scd
 rfignore.5: rfignore.5.scd
 	scdoc < $< > $@
 
-rfconfig.5: rfconfig.5.scd
-	scdoc < $< > $@
-
-install: $(BIN) rf.1 rfignore.5 rfconfig.5
+install: $(BIN) rf.1 rfignore.5
 	mkdir -p \
 		$(DESTDIR)$(PREFIX)/bin \
 		$(DESTDIR)$(PREFIX)/man/man1 \
@@ -37,7 +34,6 @@ install: $(BIN) rf.1 rfignore.5 rfconfig.5
 	install -m755 $(BIN) $(DESTDIR)$(PREFIX)/bin/
 	install -m444 rf.1 $(DESTDIR)$(PREFIX)/man/man1/
 	install -m444 rfignore.5 $(DESTDIR)$(PREFIX)/man/man5/
-	install -m444 rfconfig.5 $(DESTDIR)$(PREFIX)/man/man5/
 
 clean:
 	@rm -vf $(BIN) *.1 *.5
diff --git a/config.c b/config.c
deleted file mode 100644
index 52e1b5e..0000000
--- a/config.c
+++ /dev/null
@@ -1,82 +0,0 @@
-#define _XOPEN_SOURCE 700
-
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-char config_key[KV_STRING_LIMIT] = {'\0'};
-char config_value[KV_STRING_LIMIT] = {'\0'};
-
-int config_get(size_t *llen, FILE *fp) {
-	int i = 0;
-	int k = 0;
-	int v = 0;
-	int len = 0;
-	int in_key = 1;
-	char *line = NULL;
-
-	memset(config_key, '\0', KV_STRING_LIMIT);
-	memset(config_value, '\0', KV_STRING_LIMIT);
-
-	if (getline(&line, llen, fp) < 0) {
-		free(line);
-		return -1;
-	}
-
-	len = strlen(line);
-
-	switch (line[0]) {
-	case '=':
-	case '#':
-		free(line);
-		return 0;
-
-	default:
-		if (isspace(line[0])) {
-			free(line);
-			return 0;
-		}
-	}
-
-	for (i = 0; i < len; i++) {
-		char c = line[i];
-
-		switch (c) {
-		case '=':
-			if (in_key == 1) {
-				in_key = 0;
-				break;
-			}
-
-			/* fallthrough */
-		default:
-			if (c != '\n') {
-				if (isspace(c)) {
-					/* if previous char was '=' then skip */
-					if (i > 0 && line[i - 1] == '=') {
-						break;
-					}
-
-					/* if next char is '=' then skip */
-					if (i + 1 < len && line[i + 1] == '=') {
-						break;
-					}
-				}
-
-				if (in_key) {
-					config_key[k++] = c;
-				} else {
-					config_value[v++] = c;
-				}
-			}
-
-			break;
-		}
-	}
-
-	free(line);
-
-	return 0;
-}
diff --git a/config.default b/config.default
deleted file mode 100644
index 1fe5d6c..0000000
--- a/config.default
+++ /dev/null
@@ -1,30 +0,0 @@
-# this is a default config file for rf
-# the options as presented here should match the default behaviour
-# of rf and should give you an overview of what is configurable
-
-# read symlinks (true or false)
-symlinks = false
-
-# match whole path by default (true or false)
-wholename = false
-
-# limit number of results (a positive integer)
-limit = 0
-
-# optionally specify an alternative wildcard character
-# (a single ascii character)
-# allows you to do something like:
-#   rf %.jpg
-# with a wildcard set to '%' so you don't have to worry about
-# shell expansion with the normal '*' character in certain situations
-#
-# wildcard =
-
-# by default if there are no matches just exit with 0 exit code
-# uncomment 'unmatched error' below to exit with a non-zero exit code
-# allowing you to do something like this:
-#   rf {pattern} || fallback
-#
-# unmatched error
-
-# vim: ft=conf
diff --git a/config.h b/config.h
deleted file mode 100644
index 22eeef6..0000000
--- a/config.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#ifndef RF_CONFIG_H
-#define RF_CONFIG_H
-
-#include <ctype.h>
-#include <stdio.h>
-
-#define KV_STRING_LIMIT 1024
-
-extern char config_key[KV_STRING_LIMIT];
-extern char config_value[KV_STRING_LIMIT];
-
-int config_get(size_t *len, FILE *fp);
-
-#endif
diff --git a/rf.1.scd b/rf.1.scd
index 0fb3c3c..6f12cd5 100644
--- a/rf.1.scd
+++ b/rf.1.scd
@@ -6,7 +6,7 @@ rf - a tiny and simple file finder
 
 # SYNOPSIS
 
-*rf* [*-d* _directory_] [*-c* _config_] [*-lsvw*] [*pattern* _..._]
+*rf* [*-d* _directory_] [*pattern* _..._]
 
 # DESCRIPTION
 
@@ -18,9 +18,6 @@ substring) patterns, while respecting any ignore rules in *rfignore* files.
 *-d* directory
 	Search from specified directory, otherwise defaults to current working directory.
 
-*-c* config
-	Override config file location.
-
 *-l* count
 	Limit to specified matches count.
 
@@ -35,7 +32,7 @@ substring) patterns, while respecting any ignore rules in *rfignore* files.
 
 # SEE ALSO
 
-*rfignore*(5), *rfconfig*(5)
+*rfignore*(5)
 
 # COPYRIGHT
 
diff --git a/rf.c b/rf.c
index 02e33dc..a8fe80e 100644
--- a/rf.c
+++ b/rf.c
@@ -16,18 +16,15 @@
 #include <sys/types.h>
 #include <unistd.h>
 
-#include "config.h"
 #include "ignore.h"
 #include "include/common/common.h"
 
 #define IGNORE "ignore"
-#define CONFIG "config"
 #define RFIGNORE ".rfignore"
 
 extern char *__progname;
 
 struct ignores *global_ignores;
-struct ignores *config_ignores;
 struct ignores *local_ignores;
 
 struct switches {
@@ -72,16 +69,6 @@ static int excluded(const char *name) {
 		}
 	}
 
-	if (config_ignores != NULL) {
-		for (int i = 0; i < config_ignores->size; i++) {
-			int res = fnmatch(config_ignores->list[i], name, 0);
-
-			if (res == 0) {
-				return 1;
-			}
-		}
-	}
-
 	if (local_ignores != NULL) {
 		for (int i = 0; i < local_ignores->size; i++) {
 			int res = fnmatch(local_ignores->list[i], name, 0);
@@ -199,9 +186,7 @@ int main(int argc, char **argv) {
 	int exit_code = EXIT_SUCCESS;
 	int ch;
 	char *remainder;
-	size_t len = 0;
 	const char *root = ".";
-	FILE *fp;
 	char cwd[MAXPATHLEN];
 	int unmatched_error = 0;
 	char wildcard = 0;
@@ -211,7 +196,6 @@ int main(int argc, char **argv) {
 		exit(EXIT_FAILURE);
 	}
 
-	char *xdg_config_home = getenv("XDG_CONFIG_HOME");
 	char *home = getenv("HOME");
 
 	while ((ch = getopt(argc, argv, "d:l:svw")) > -1) {
@@ -252,75 +236,7 @@ int main(int argc, char **argv) {
 		}
 	}
 
-	char config_file[xdg_config_home
-						 ? (strlen(xdg_config_home) + strlen("ignore") + 3)
-						 : (strlen(cwd) + strlen(".rfignore") + 1)];
-
-	if (xdg_config_home) {
-		const char *pattern = "%s/rf/%s";
-		int len = (strlen(pattern) + strlen(xdg_config_home) + strlen(CONFIG));
-		snprintf(config_file, len, pattern, xdg_config_home, CONFIG);
-	} else {
-		const char *pattern = "%s/.config/rf/%s";
-		int len = (strlen(pattern) + strlen(home) + strlen(CONFIG));
-		snprintf(config_file, len, pattern, home, CONFIG);
-	}
-
-	fp = fopen(config_file, "r");
-
-	if (fp != NULL) {
-		while ((config_get(&len, fp)) != -1) {
-			if (strlen(config_key) && strlen(config_value)) {
-				if (strcmp(config_key, "symlinks") == 0) {
-					if (strcmp(config_value, "true") == 0) {
-						read_links = 1;
-					} else if (strcmp(config_value, "false") == 0) {
-						read_links = 0;
-					} else {
-						fprintf(stderr,
-							"'%s' is not a valid value for property: %s.\n",
-							config_value, config_key);
-						exit(EXIT_FAILURE);
-					}
-				} else if (strcmp(config_key, "wholename") == 0) {
-					if (strcmp(config_value, "true") == 0) {
-						switches.wholename = 1;
-					} else if (strcmp(config_value, "false") == 0) {
-						/* default */
-					} else {
-						fprintf(stderr,
-							"'%s' is not a valid value for property: %s.\n",
-							config_value, config_key);
-						exit(EXIT_FAILURE);
-					}
-				} else if (strcmp(config_key, "limit") == 0) {
-					int limit = strtol(config_value, &remainder, 10);
-
-					if (limit < 0) {
-						fprintf(stderr, "Warning: Invalid limit, ignoring.");
-					} else {
-						switches.limit = limit;
-					}
-				} else if (strcmp(config_key, "unmatched error") == 0) {
-					unmatched_error = 1;
-				} else if (strcmp(config_key, "wildcard") == 0) {
-					wildcard = config_value[0];
-				}
-			} else if (strlen(config_key)) {
-				fprintf(stderr,
-					"Warning: Ignoring empty config property '%s'.\n",
-					config_key);
-			}
-		}
-
-		fclose(fp);
-	}
-
 	char global_ignore_path[(strlen(home) + strlen(".rfignore") + 1)];
-	char config_ignore_path[xdg_config_home
-								? (strlen(xdg_config_home) + strlen("ignore") +
-									  3)
-								: (strlen(cwd) + strlen(".rfignore") + 1)];
 	char local_ignore_path[strlen(cwd) + strlen(".rfignore") + 1];
 
 	const char *pattern = "%s/%s";
@@ -331,18 +247,7 @@ int main(int argc, char **argv) {
 		(strlen(pattern) + strlen(cwd) + strlen(RFIGNORE)), pattern, cwd,
 		RFIGNORE);
 
-	if (xdg_config_home) {
-		const char *pattern = "%s/rf/%s";
-		int len = (strlen(pattern) + strlen(xdg_config_home) + strlen(IGNORE));
-		snprintf(config_ignore_path, len, pattern, xdg_config_home, IGNORE);
-	} else {
-		const char *pattern = "%s/.config/rf/%s";
-		int len = (strlen(pattern) + strlen(home) + strlen(IGNORE));
-		snprintf(config_ignore_path, len, pattern, home, IGNORE);
-	}
-
 	global_ignores = init_ignores(global_ignore_path);
-	config_ignores = init_ignores(config_ignore_path);
 	local_ignores = init_ignores(local_ignore_path);
 
 	if (optind < argc) {
@@ -378,7 +283,6 @@ int main(int argc, char **argv) {
 
 bail:
 	free_ignores(global_ignores);
-	free_ignores(config_ignores);
 	free_ignores(local_ignores);
 
 	exit(exit_code);
diff --git a/rfconfig.5.scd b/rfconfig.5.scd
deleted file mode 100644
index 64d021c..0000000
--- a/rfconfig.5.scd
+++ /dev/null
@@ -1,43 +0,0 @@
-rfconfig(5)
-
-# NAME
-
-rfconfig - configure rf behaviour
-
-# SYNOPSIS
-
-$XDG_CONFIG_HOME/rf/config
-
-# DESCRIPTION
-
-An *rfconfig* file is used to override default behaviour and configure options.
-
-# FORMAT
-
-The config file format is very simple. Comments are only available for a whole
-line and start with #. Any lines that begin with a space are ignored.
-Each valid config line consists of a key value pair with the key and value
-separated by an = character and optionally a single space either side.
-Additional spaces will become part of either the key and/or value.
-
-# OPTIONS
-
-*symlinks*
-	Read symlinks (value: "true" or "false")
-
-*wholename*
-	Match whole path (value "true" or "false")
-
-*limit*
-	Limit amount of results (value: a positive integer)
-
-*wildcard*
-	Define a custom wildcard character, used in place of \*
-	(value: a single ascii character)
-
-*unmatched error*
-	Exit with non-zero exit code if there were no matches
-
-# COPYRIGHT
-
-Copyright © 2019 - 2021 Rory Bradford <roryrjb@gmail.com>.