summary refs log tree commit diff
path: root/scoop.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--scoop.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/scoop.c b/scoop.c
index 5855e70..1f031e2 100644
--- a/scoop.c
+++ b/scoop.c
@@ -29,6 +29,7 @@ static const char *Inner = SQL(
 	SELECT
 		contexts.network,
 		contexts.name AS context,
+		// TODO: Replace with a strftime and option.
 		date(events.time) || 'T' || time(events.time) || 'Z' AS time,
 		events.type,
 		names.nick,
@@ -66,6 +67,11 @@ static const char *Outer = SQL(
 	ORDER BY time, event
 );
 
+static const char *Group = SQL(
+	SELECT * FROM results
+	ORDER BY network, context, time, event
+);
+
 typedef void Format(
 	const char *network, const char *context, const char *time, enum Type type,
 	const char *nick, const char *user, const char *target, const char *message
@@ -176,15 +182,17 @@ int main(int argc, char *argv[]) {
 	const char *target = NULL;
 	const char *search = NULL;
 	int limit = -1;
+	bool group = false;
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "D:N:T:c:d:h:l:n:pqst:u:v"))) {
+	while (0 < (opt = getopt(argc, argv, "D:N:T:c:d:gh:l:n:pqst:u:v"))) {
 		switch (opt) {
 			break; case 'D': date = optarg;
 			break; case 'N': network = optarg;
 			break; case 'T': target = optarg;
 			break; case 'c': context = optarg;
 			break; case 'd': path = optarg;
+			break; case 'g': group = true;
 			break; case 'h': host = optarg;
 			break; case 'l': limit = strtol(optarg, NULL, 0);
 			break; case 'n': nick = optarg;
@@ -244,13 +252,13 @@ int main(int argc, char *argv[]) {
 		snprintf(
 			sql, sizeof(sql),
 			"WITH results AS (%s AND %s %s) %s;",
-			Inner, Search, Limit, Outer
+			Inner, Search, Limit, (group ? Group : Outer)
 		);
 	} else {
 		snprintf(
 			sql, sizeof(sql),
 			"WITH results AS (%s %s) %s;",
-			Inner, Limit, Outer
+			Inner, Limit, (group ? Group : Outer)
 		);
 	}