about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-05-18 11:45:21 -0400
committerJune McEnroe <june@causal.agency>2021-05-18 11:45:21 -0400
commit7e8ddf1a023ee62ec4a057181658c4ea499cb107 (patch)
treecbb3139522342d6eea451232ebd10e5007fe979c
parentAdd znc format to unscoop (diff)
downloadlitterbox-7e8ddf1a023ee62ec4a057181658c4ea499cb107.tar.gz
litterbox-7e8ddf1a023ee62ec4a057181658c4ea499cb107.zip
Add scoop -i flag for case-insensitive regexp
-rw-r--r--scoop.112
-rw-r--r--scoop.c8
2 files changed, 16 insertions, 4 deletions
diff --git a/scoop.1 b/scoop.1
index 0298232..2b274bc 100644
--- a/scoop.1
+++ b/scoop.1
@@ -1,4 +1,4 @@
-.Dd May 17, 2021
+.Dd May 18, 2021
 .Dt SCOOP 1
 .Os
 .
@@ -8,7 +8,7 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl Lgpqrsv
+.Op Fl Lgipqrsv
 .Op Fl D Ar date
 .Op Fl F Ar format
 .Op Fl N Ar network
@@ -145,6 +145,11 @@ Implies
 Match events from users with the hostname
 .Ar host .
 .
+.It Fl i
+Use case-insensitive regular expression matching
+with
+.Fl m .
+.
 .It Fl l Ar limit
 Limit the number of events matched,
 ordered by most recently inserted.
@@ -157,6 +162,9 @@ matching the modern regular expression
 .Ar regexp .
 See
 .Xr re_format 7 .
+To match case-insensitively,
+use with
+.Fl i .
 .
 .It Fl n Ar nick
 Match events from users with the nickname
diff --git a/scoop.c b/scoop.c
index 6d06499..031e4e2 100644
--- a/scoop.c
+++ b/scoop.c
@@ -245,6 +245,7 @@ static void regexpFree(void *_regex) {
 	free(regex);
 }
 
+static int regexpFlags = REG_EXTENDED | REG_NOSUB;
 static void regexp(sqlite3_context *ctx, int n, sqlite3_value *args[]) {
 	assert(n == 2);
 	if (sqlite3_value_type(args[0]) == SQLITE_NULL) {
@@ -267,7 +268,7 @@ static void regexp(sqlite3_context *ctx, int n, sqlite3_value *args[]) {
 
 		int error = regcomp(
 			regex, (const char *)sqlite3_value_text(args[0]),
-			REG_EXTENDED | REG_NOSUB
+			regexpFlags
 		);
 		if (error) {
 			char msg[256];
@@ -368,7 +369,7 @@ int main(int argc, char *argv[]) {
 	struct Bind *binds = calloc(argc + 2, sizeof(*binds));
 	if (!binds) err(EX_OSERR, "calloc");
 
-	const char *Opts = "D:F:LN:ST:a:b:c:d:f:gh:l:m:n:pqrst:u:vw:";
+	const char *Opts = "D:F:LN:ST:a:b:c:d:f:gh:il:m:n:pqrst:u:vw:";
 	for (int opt; 0 < (opt = getopt(argc, argv, Opts));) {
 		switch (opt) {
 			break; case 'D': {
@@ -453,6 +454,9 @@ int main(int argc, char *argv[]) {
 				append(where, SQL(AND names.host = :host));
 				binds[n++] = Bind(":host", optarg, 0);
 			}
+			break; case 'i': {
+				regexpFlags |= REG_ICASE;
+			}
 			break; case 'l': {
 				limit = optarg;
 				sort = true;