summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2020-04-05 11:02:41 -0400
committerJune McEnroe <june@causal.agency>2020-04-05 11:02:41 -0400
commit5cd7060e8d9e1f18924c5f19e2be715a9ee7ff98 (patch)
tree79bbc660d00a4fc9a96038751fbbeb87a29c74d5
parentAdd Ban and Unban event types (diff)
downloadlitterbox-5cd7060e8d9e1f18924c5f19e2be715a9ee7ff98.tar.gz
litterbox-5cd7060e8d9e1f18924c5f19e2be715a9ee7ff98.zip
Add unscoop -n flag for checking regexps
-rw-r--r--unscoop.18
-rw-r--r--unscoop.c17
2 files changed, 16 insertions, 9 deletions
diff --git a/unscoop.1 b/unscoop.1
index 1954f97..6757304 100644
--- a/unscoop.1
+++ b/unscoop.1
@@ -1,4 +1,4 @@
-.Dd January 4, 2020
+.Dd April  5, 2020
 .Dt UNSCOOP 1
 .Os
 .
@@ -8,7 +8,7 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl v
+.Op Fl nv
 .Op Fl N Ar network
 .Op Fl c Ar context
 .Op Fl d Ar path
@@ -87,6 +87,10 @@ The network and context must be set with
 and
 .Fl c .
 .
+.It Fl n
+Do not import any files.
+Compile regular expressions and exit.
+.
 .It Fl v
 Print SQL
 .Sy INSERT
diff --git a/unscoop.c b/unscoop.c
index 6e7b362..eabb594 100644
--- a/unscoop.c
+++ b/unscoop.c
@@ -299,24 +299,33 @@ static void dedupEvents(sqlite3 *db) {
 }
 
 int main(int argc, char *argv[]) {
+	bool test = false;
 	char *path = NULL;
 	bool dedup = false;
 	const char *network = NULL;
 	const char *context = NULL;
 	const struct Format *format = &Formats[0];
 
-	for (int opt; 0 < (opt = getopt(argc, argv, "DN:c:d:f:v"));) {
+	for (int opt; 0 < (opt = getopt(argc, argv, "DN:c:d:f:nv"));) {
 		switch (opt) {
 			break; case 'D': dedup = true;
 			break; case 'N': network = optarg;
 			break; case 'c': context = optarg;
 			break; case 'd': path = optarg;
 			break; case 'f': format = formatParse(optarg);
+			break; case 'n': test = true;
 			break; case 'v': verbose = true;
 			break; default:  return EX_USAGE;
 		}
 	}
 
+	regex_t pathRegex = compile(format->pattern);
+	regex_t regex[format->len];
+	for (size_t i = 0; i < format->len; ++i) {
+		regex[i] = compile(format->matchers[i].pattern);
+	}
+	if (test) return EX_OK;
+
 	dbFind(path, SQLITE_OPEN_READWRITE);
 	if (dbVersion() != DatabaseVersion) {
 		errx(EX_CONFIG, "database out of date; migrate with litterbox -m");
@@ -328,12 +337,6 @@ int main(int argc, char *argv[]) {
 		return EX_OK;
 	}
 
-	regex_t pathRegex = compile(format->pattern);
-	regex_t regex[format->len];
-	for (size_t i = 0; i < format->len; ++i) {
-		regex[i] = compile(format->matchers[i].pattern);
-	}
-
 	sqlite3_stmt *insertContext = NULL;
 	const char *InsertContext = SQL(
 		INSERT OR IGNORE INTO contexts (network, name, query)