diff options
author | June McEnroe <june@causal.agency> | 2019-12-05 15:51:18 -0500 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-12-05 15:51:18 -0500 |
commit | a75db3e11323c528d8fabb1812fd97a305467d2b (patch) | |
tree | b7a420240ce71f15d5bd4648599ac7a012d47761 | |
parent | Document what the generic format matches (diff) | |
download | litterbox-a75db3e11323c528d8fabb1812fd97a305467d2b.tar.gz litterbox-a75db3e11323c528d8fabb1812fd97a305467d2b.zip |
Add textual format to unscoop
Diffstat (limited to '')
-rw-r--r-- | unscoop.1 | 3 | ||||
-rw-r--r-- | unscoop.c | 66 |
2 files changed, 57 insertions, 12 deletions
diff --git a/unscoop.1 b/unscoop.1 index 0478481..0a9f0db 100644 --- a/unscoop.1 +++ b/unscoop.1 @@ -40,7 +40,8 @@ for the default database path. .It Fl f Ar format Set the input log format. The following formats are supported: -.Sy generic . +.Sy generic , +.Sy textual . .Pp The .Sy generic diff --git a/unscoop.c b/unscoop.c index d5494e0..2e62b57 100644 --- a/unscoop.c +++ b/unscoop.c @@ -31,9 +31,9 @@ #define ARRAY_LEN(a) (sizeof(a) / sizeof((a)[0])) struct Matcher { - enum Type type; const char *pattern; regex_t regex; + enum Type type; size_t time; size_t nick; size_t user; @@ -42,25 +42,68 @@ struct Matcher { size_t message; }; -#define WS "[[:blank:]]*" +#define WS "[[:blank:]]" #define PAT_TIME "[[]([^]]+)[]]" #define PAT_MODE "[!~&@%+ ]?" static struct Matcher Generic[] = { { - .type = Privmsg, - .pattern = "^" PAT_TIME WS "<" PAT_MODE "([^>]+)" ">" WS "(.+)", - .time = 1, .nick = 2, .message = 3, + "^" PAT_TIME WS "<" PAT_MODE "([^>]+)" ">" WS "(.+)", + .type = Privmsg, .time = 1, .nick = 2, .message = 3, + }, + { + "^" PAT_TIME WS "-" PAT_MODE "([^-]+)" "-" WS "(.+)", + .type = Notice, .time = 1, .nick = 2, .message = 3, + }, + { + "^" PAT_TIME WS "[*]" WS PAT_MODE "([^[:blank:]]+)" WS "(.+)", + .type = Action, .time = 1, .nick = 2, .message = 3, + }, +}; + +#define PAT_USERHOST "[(]([^@]+)@([^)]+)[)]" +#define PAT_MESSAGE "[(]([^)]+)[)]" + +static struct Matcher Textual[] = { + { + "^" PAT_TIME " <" PAT_MODE "([^>]+)> (.+)", + .type = Privmsg, .time = 1, .nick = 2, .message = 3, + }, + { + "^" PAT_TIME " -" PAT_MODE "([^-]+)- (.+)", + .type = Notice, .time = 1, .nick = 2, .message = 3, + }, + { + "^" PAT_TIME " • ([^:]+): (.+)", + .type = Action, .time = 1, .nick = 2, .message = 3, + }, + { + "^" PAT_TIME " ([^ ]+) " PAT_USERHOST " joined the channel", + .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 = 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, }, { - .type = Notice, - .pattern = "^" PAT_TIME WS "-" PAT_MODE "([^-]+)" "-" WS "(.+)", - .time = 1, .nick = 2, .message = 3, + "^" PAT_TIME " ([^ ]+) is now known as ([^ ]+)", + .type = Nick, .time = 1, .nick = 2, .target = 3, }, { - .type = Action, - .pattern = "^" PAT_TIME WS "[*]" WS PAT_MODE "([^[:blank:]]+)" WS "(.+)", - .time = 1, .nick = 2, .message = 3, + "^" PAT_TIME " ([^ ]+) changed the topic to (.+)", + .type = Topic, .time = 1, .nick = 2, .message = 3, }, }; @@ -70,6 +113,7 @@ static const struct Format { size_t len; } Formats[] = { { "generic", Generic, ARRAY_LEN(Generic) }, + { "textual", Textual, ARRAY_LEN(Textual) }, }; static const struct Format *formatParse(const char *name) { |