summary refs log tree commit diff
path: root/scoop.c
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 /scoop.c
parentAdd znc format to unscoop (diff)
downloadlitterbox-7e8ddf1a023ee62ec4a057181658c4ea499cb107.tar.gz
litterbox-7e8ddf1a023ee62ec4a057181658c4ea499cb107.zip
Add scoop -i flag for case-insensitive regexp
Diffstat (limited to '')
-rw-r--r--scoop.c8
1 files changed, 6 insertions, 2 deletions
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;