aboutsummaryrefslogtreecommitdiff
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
parente8107b1889a620b6ba446953e698b30f1803b2cb (diff)
downloadmblaze-94854ad1852527b3ef03b323948c2fd6c63803ef.tar.gz
mscan: spawn a pager for interactive use
-rw-r--r--Makefile1
-rw-r--r--man/mscan.114
-rw-r--r--mscan.c20
3 files changed, 33 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index dc9f33e..8310ad5 100644
--- a/Makefile
+++ b/Makefile
@@ -25,6 +25,7 @@ maddr magrep mexport mflag mgenmid mhdr mlist mpick mscan msed mseq mshow msort
maddr magrep mhdr mpick mscan mshow : rfc2047.o
magrep mshow : rfc2045.o
mshow : filter.o safe_u8putstr.o rfc2231.o pipeto.o
+mscan : pipeto.o
msort : mystrverscmp.o
mmime : slurp.o
diff --git a/man/mscan.1 b/man/mscan.1
index d241d82..79e0982 100644
--- a/man/mscan.1
+++ b/man/mscan.1
@@ -22,7 +22,8 @@ If no
are passed,
.Nm
reads file names from standard input,
-or uses the mails in the current sequence when used interactively.
+or uses the mails in the current sequence when used interactively
+(using a pager).
.Pp
By default,
.Ar format
@@ -166,6 +167,17 @@ You are in
You are in
.Sq Li "Resent-To:" .
.El
+.Sh ENVIRONMENT
+.Bl -tag -width MBLAZE_PAGER
+.It Ev MBLAZE_PAGER
+Any non-empty value of the environment variable
+.Ev MBLAZE_PAGER
+is used instead of the standard pagination program, specified in
+.Ev PAGER .
+When empty or set to
+.Sq Ic cat ,
+no pager is spawned.
+.El
.Sh EXIT STATUS
.Ex -std
.Sh SEE ALSO
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;
}