From 9bf55019250a471593e2ba36531de57a520e8b6a Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Fri, 6 Dec 2019 08:15:52 -0500 Subject: Handle optional regex groups --- unscoop.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'unscoop.c') diff --git a/unscoop.c b/unscoop.c index 2e62b57..9d5141c 100644 --- a/unscoop.c +++ b/unscoop.c @@ -62,7 +62,7 @@ static struct Matcher Generic[] = { }; #define PAT_USERHOST "[(]([^@]+)@([^)]+)[)]" -#define PAT_MESSAGE "[(]([^)]+)[)]" +#define PAT_MESSAGE "( [(]([^)]+)[)])?" static struct Matcher Textual[] = { { @@ -82,20 +82,16 @@ static struct Matcher Textual[] = { .type = Join, .time = 1, .nick = 2, .user = 3, .host = 4, }, { - "^" PAT_TIME " ([^ ]+) " PAT_USERHOST " left the channel$", - .type = Part, .time = 1, .nick = 2, .user = 3, .host = 4, + "^" PAT_TIME " ([^ ]+) " PAT_USERHOST " left the channel" PAT_MESSAGE, + .type = Part, .time = 1, .nick = 2, .user = 3, .host = 4, .message = 6, }, { - "^" PAT_TIME " ([^ ]+) " PAT_USERHOST " left the channel " PAT_MESSAGE, - .type = Part, .time = 1, .nick = 2, .user = 3, .host = 4, .message = 5, + "^" PAT_TIME " ([^ ]+) kicked ([^ ]+) from the channel" PAT_MESSAGE, + .type = Kick, .time = 1, .nick = 2, .target = 3, .message = 5, }, { - "^" PAT_TIME " ([^ ]+) kicked ([^ ]+) from the channel " PAT_MESSAGE, - .type = Kick, .time = 1, .nick = 2, .target = 3, .message = 4, - }, - { - "^" PAT_TIME " ([^ ]+) " PAT_USERHOST " left IRC " PAT_MESSAGE, - .type = Quit, .time = 1, .nick = 2, .user = 3, .host = 4, .message = 5, + "^" PAT_TIME " ([^ ]+) " PAT_USERHOST " left IRC" PAT_MESSAGE, + .type = Quit, .time = 1, .nick = 2, .user = 3, .host = 4, .message = 6, }, { "^" PAT_TIME " ([^ ]+) is now known as ([^ ]+)", @@ -125,7 +121,11 @@ static const struct Format *formatParse(const char *name) { static void bindMatch(sqlite3_stmt *stmt, int param, const char *str, regmatch_t match) { - dbBindText(stmt, param, &str[match.rm_so], match.rm_eo - match.rm_so); + if (match.rm_so < 0) { + dbBindText(stmt, param, NULL, -1); + } else { + dbBindText(stmt, param, &str[match.rm_so], match.rm_eo - match.rm_so); + } } int main(int argc, char *argv[]) { -- cgit 1.4.1