commit 79e3f6e7b87ebaef39453c37bcf21777df98ee45
parent 1582b23258270fe22d14b59434a8ed8c81b5c39d
Author: Friedel Schön <[email protected]>
Date: Mon, 2 Sep 2024 23:13:54 +0200
extract defaults to config.h
Diffstat:
3 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/Makefile b/Makefile
@@ -6,7 +6,7 @@ PREFIX ?= /usr
all: textselect
-textselect.o: textselect.c arg.h
+textselect.o: textselect.c arg.h config.h
$(CC) -c $(CFLAGS) $(CPPFLAGS) -o $@ $<
textselect: textselect.o
diff --git a/config.h b/config.h
@@ -0,0 +1,5 @@
+/* default prefix for a selected line, can be overwritten by -s */
+static char selected[PREFIX] = "";
+
+/* default prefix for a unselected line, can be overwritten by -S */
+static char unselected[PREFIX] = "";
diff --git a/textselect.c b/textselect.c
@@ -29,10 +29,9 @@ struct line {
static char *argv0 = NULL;
static bool selected_invert = false;
static bool keep_empty = false;
+static int prefixlen = 0;
-static char selected[PREFIX] = "";
-static char unselected[PREFIX] = "";
-static int prefixlen = 0;
+#include "config.h"
static void die(const char *message) {
fprintf(stderr, "error: %s: %s\n", message, strerror(errno));
@@ -272,11 +271,11 @@ int main(int argc, char *argv[]) {
break;
case 's':
strncpy(selected, EARGF(usage(1)), sizeof(selected));
- selected[sizeof(selected)-1] = '\0';
+ selected[sizeof(selected) - 1] = '\0';
break;
case 'S':
strncpy(unselected, EARGF(usage(1)), sizeof(unselected));
- unselected[sizeof(unselected)-1] = '\0';
+ unselected[sizeof(unselected) - 1] = '\0';
break;
default:
fprintf(stderr, "error: unknown option '-%c'\n", OPT);