From 3827d74a9e89ff22654b4c0fb895fe2d33fc9209 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Wed, 28 Apr 2021 18:02:20 -0400 Subject: Match multiple types with -t --- scoop.1 | 7 ++++--- scoop.c | 12 ++++++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/scoop.1 b/scoop.1 index 1a66040..693c033 100644 --- a/scoop.1 +++ b/scoop.1 @@ -1,4 +1,4 @@ -.Dd April 27, 2021 +.Dd April 28, 2021 .Dt SCOOP 1 .Os . @@ -174,9 +174,10 @@ Sort the results from oldest to newest. By default events are output in the order they appear in the database. . -.It Fl t Ar type +.It Fl t Ar types Match events of -.Ar type . +the comma-separated list of +.Ar types . The types are .Cm privmsg , .Cm notice , diff --git a/scoop.c b/scoop.c index 6c2957b..f1c0ed2 100644 --- a/scoop.c +++ b/scoop.c @@ -344,6 +344,14 @@ static enum Type parseType(const char *input) { errx(EX_USAGE, "no such type %s", input); } +static int parseTypes(char *list) { + int mask = 0; + while (list) { + mask |= 1 << parseType(strsep(&list, ",")); + } + return mask; +} + int main(int argc, char *argv[]) { bool tty = isatty(STDOUT_FILENO); @@ -466,8 +474,8 @@ int main(int argc, char *argv[]) { sort = true; } break; case 't': { - append(where, SQL(AND events.type = :type)); - binds[n++] = Bind(":type", NULL, parseType(optarg)); + append(where, SQL(AND (1 << events.type) & :types)); + binds[n++] = Bind(":types", NULL, parseTypes(optarg)); } break; case 'u': { append(where, SQL(AND names.user = :user)); -- cgit 1.4.1