summary refs log tree commit diff
path: root/mscan.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2017-05-23 15:25:28 +0200
committerLeah Neukirchen <leah@vuxu.org>2017-05-23 15:25:28 +0200
commit94854ad1852527b3ef03b323948c2fd6c63803ef (patch)
treee7bcf1bda0737a3229da8162bc87429b0c527d79 /mscan.c
parente8107b1889a620b6ba446953e698b30f1803b2cb (diff)
downloadmblaze-94854ad1852527b3ef03b323948c2fd6c63803ef.tar.gz
mblaze-94854ad1852527b3ef03b323948c2fd6c63803ef.tar.xz
mblaze-94854ad1852527b3ef03b323948c2fd6c63803ef.zip
mscan: spawn a pager for interactive use
Diffstat (limited to 'mscan.c')
-rw-r--r--mscan.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/mscan.c b/mscan.c
index 9264587..d981ace 100644
--- a/mscan.c
+++ b/mscan.c
@@ -488,6 +488,8 @@ oneline(char *file)
 int
 main(int argc, char *argv[])
 {
+	pid_t pid1 = -1;
+
 	int c;
 	while ((c = getopt(argc, argv, "If:n")) != -1)
 		switch(c) {
@@ -516,8 +518,21 @@ main(int argc, char *argv[])
 		replacement = 0xfffd;
 
 	struct winsize w;
-	if (ioctl(1, TIOCGWINSZ, &w) == 0)
+	if (ioctl(1, TIOCGWINSZ, &w) == 0) {
 		cols = w.ws_col;
+
+		char *pg;
+		pg = getenv("MBLAZE_PAGER");
+		if (!pg)
+			pg = getenv("PAGER");
+		if (pg && *pg && strcmp(pg, "cat") != 0) {
+			pid1 = pipeto(pg);
+			if (pid1 < 0)
+				fprintf(stderr,
+				    "mscan: spawning pager '%s': %s\n",
+				    pg, strerror(errno));
+		}
+	}
 	if (getenv("COLUMNS"))
 		cols = atoi(getenv("COLUMNS"));
 	if (cols <= 40)
@@ -550,5 +565,8 @@ main(int argc, char *argv[])
 		i = blaze822_loop(argc-optind, argv+optind, oneline);
 	fprintf(stderr, "%ld mails scanned\n", i);
 
+	if (pid1 > 0)
+		pipeclose(pid1);
+
 	return 0;
 }